Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: #517 error #857

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
32 changes: 32 additions & 0 deletions src/__tests__/i517.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Entity, Column, JoinTable, ManyToMany } from 'typeorm'

import { PrimaryGeneratedColumn } from 'typeorm'

@Entity('user')
export class UserEntity {
@PrimaryGeneratedColumn('uuid')
id: string

@Column()
username: string

@JoinTable()
@ManyToMany(() => RoleEntity, (roleEntity) => roleEntity.users, {
cascade: true,
})
roles: RoleEntity[]
}

@Entity('role')
export class RoleEntity {
@PrimaryGeneratedColumn('uuid')
id: string

@Column({
unique: true,
})
name: string

@ManyToMany(() => UserEntity, (user) => user.roles)
users: UserEntity[]
}
55 changes: 54 additions & 1 deletion src/paginate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { ToyShopAddressEntity } from './__tests__/toy-shop-address.entity'
import * as process from 'process'
import { CatHairEntity } from './__tests__/cat-hair.entity'
import { RoleEntity, UserEntity } from './__tests__/i517.entity'

const isoStringToDate = (isoString) => new Date(isoString)

Expand All @@ -40,6 +41,10 @@
let catHomes: CatHomeEntity[]
let catHomePillows: CatHomePillowEntity[]
let catHairs: CatHairEntity[] = []
let userEntityRepo: Repository<UserEntity>
let roleEntityRepo: Repository<RoleEntity>
let users: UserEntity[]

Check warning on line 46 in src/paginate.spec.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'users' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 46 in src/paginate.spec.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'users' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 46 in src/paginate.spec.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'users' is assigned a value but never used. Allowed unused vars must match /^_/u
let roles: RoleEntity[]

beforeAll(async () => {
dataSource = new DataSource({
Expand All @@ -65,6 +70,8 @@
CatHomeEntity,
CatHomePillowEntity,
ToyShopEntity,
UserEntity,
RoleEntity,
process.env.DB === 'postgres' ? CatHairEntity : undefined,
],
})
Expand All @@ -75,7 +82,24 @@
catHomePillowRepo = dataSource.getRepository(CatHomePillowEntity)
toyShopRepo = dataSource.getRepository(ToyShopEntity)
toyShopAddressRepository = dataSource.getRepository(ToyShopAddressEntity)

userEntityRepo = dataSource.getRepository(UserEntity)
roleEntityRepo = dataSource.getRepository(RoleEntity)
roles = await roleEntityRepo.save([
{
name: 'SUPER_ADMIN',
},
{
name: 'NORMAL_USER',
},
])
users = await userEntityRepo.save([
userEntityRepo.create({
username: 'admin',
// password: 'admin',
// phone: '12345678901',
roles: [roles[0]],
}),
])
cats = await catRepo.save([
catRepo.create({
name: 'Milo',
Expand Down Expand Up @@ -2434,6 +2458,35 @@
expect(result.data[0].toys).toHaveLength(1)
})

it('#517 error', async () => {
const PAGINATE_USER_CONFIG: PaginateConfig<UserEntity> = {
relations: ['roles'],
select: ['roles', 'id'], // id and roles will cause error
sortableColumns: ['username'],
}
const res = await paginate<UserEntity>({ path: '' }, userEntityRepo, PAGINATE_USER_CONFIG)
expect(res.data.length).toBe(1)
})

it('#517 error only select id', async () => {
const PAGINATE_USER_CONFIG: PaginateConfig<UserEntity> = {
select: ['id'],
sortableColumns: ['username'],
}
const res = await paginate<UserEntity>({ path: '' }, userEntityRepo, PAGINATE_USER_CONFIG)
expect(res.data.length).toBe(1)
})

it('#517 error only select roles', async () => {
const PAGINATE_USER_CONFIG: PaginateConfig<UserEntity> = {
relations: ['roles'],
select: ['roles'],
sortableColumns: ['username'],
}
const res = await paginate<UserEntity>({ path: '' }, userEntityRepo, PAGINATE_USER_CONFIG)
expect(res.data.length).toBe(1)
})

it('should search nested relations', async () => {
const config: PaginateConfig<CatEntity> = {
relations: { home: { pillows: true } },
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"incremental": true,
"skipLibCheck": true // https://stackoverflow.com/questions/55680391/typescript-error-ts2403-subsequent-variable-declarations-must-have-the-same-typ
},
"include": ["src"]
"include": ["src", "src/__tests__/517.entity.ts"]
}
Loading