Skip to content

Commit

Permalink
refactor: update relation types in entity class
Browse files Browse the repository at this point in the history
  • Loading branch information
kuizuo committed Nov 24, 2023
1 parent 3d2e649 commit 6279f5e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 19 deletions.
5 changes: 3 additions & 2 deletions apps/api/src/modules/auth/entities/access-token.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ManyToOne,
OneToOne,
PrimaryGeneratedColumn,
Relation,
} from 'typeorm'

import { RefreshTokenEntity } from './refresh-token.entity'
Expand Down Expand Up @@ -47,7 +48,7 @@ export class AccessTokenEntity extends BaseEntity {
cascade: true,
},
)
refreshToken!: RefreshTokenEntity
refreshToken!: Relation<RefreshTokenEntity>

/**
* @description 所属用户
Expand All @@ -56,5 +57,5 @@ export class AccessTokenEntity extends BaseEntity {
@ManyToOne(() => UserEntity, user => user.accessTokens, {
onDelete: 'CASCADE',
})
user!: UserEntity
user!: Relation<UserEntity>
}
3 changes: 2 additions & 1 deletion apps/api/src/modules/auth/entities/refresh-token.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
JoinColumn,
OneToOne,
PrimaryGeneratedColumn,
Relation,
} from 'typeorm'

import { AccessTokenEntity } from './access-token.entity'
Expand Down Expand Up @@ -47,5 +48,5 @@ export class RefreshTokenEntity extends BaseEntity {
},
)
@JoinColumn()
accessToken!: AccessTokenEntity
accessToken!: Relation<AccessTokenEntity>
}
5 changes: 3 additions & 2 deletions apps/api/src/modules/system/dept/dept.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Column,
Entity,
OneToMany,
Relation,
Tree,
TreeChildren,
TreeParent,
Expand All @@ -26,8 +27,8 @@ export class DeptEntity extends AbstractEntity {
children!: DeptEntity[]

@TreeParent({ onDelete: 'SET NULL' })
parent?: DeptEntity | null
parent?: DeptEntity

@OneToMany(() => UserEntity, user => user.dept)
users: UserEntity[]
users: Relation<UserEntity[]>
}
4 changes: 2 additions & 2 deletions apps/api/src/modules/system/log/entities/login-log.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm'
import { Column, Entity, JoinColumn, ManyToOne, Relation } from 'typeorm'

import { UserEntity } from '../../../user/entities/user.entity'
import { AbstractEntity } from '@/common/entity/abstract.entity'
Expand Down Expand Up @@ -28,5 +28,5 @@ export class LoginLogEntity extends AbstractEntity {

@ManyToOne(() => UserEntity)
@JoinColumn()
user: UserEntity
user: Relation<UserEntity>
}
4 changes: 2 additions & 2 deletions apps/api/src/modules/system/log/entities/task-log.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm'
import { Column, Entity, JoinColumn, ManyToOne, Relation } from 'typeorm'

import { TaskEntity } from '../../task/task.entity'
import { AbstractEntity } from '@/common/entity/abstract.entity'
Expand All @@ -20,5 +20,5 @@ export class TaskLogEntity extends AbstractEntity {

@ManyToOne(() => TaskEntity)
@JoinColumn()
task: TaskEntity
task: Relation<TaskEntity>
}
4 changes: 2 additions & 2 deletions apps/api/src/modules/system/menu/menu.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, ManyToMany } from 'typeorm'
import { Column, Entity, ManyToMany, Relation } from 'typeorm'

import { RoleEntity } from '../role/role.entity'
import { AbstractEntity } from '@/common/entity/abstract.entity'
Expand Down Expand Up @@ -42,5 +42,5 @@ export class MenuEntity extends AbstractEntity {
status: number

@ManyToMany(() => RoleEntity, role => role.menus)
roles: RoleEntity[]
roles: Relation<RoleEntity[]>
}
6 changes: 3 additions & 3 deletions apps/api/src/modules/system/role/role.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'
import { Column, Entity, JoinTable, ManyToMany } from 'typeorm'
import { Column, Entity, JoinTable, ManyToMany, Relation } from 'typeorm'

import { UserEntity } from '../../user/entities/user.entity'
import { MenuEntity } from '../menu/menu.entity'
Expand All @@ -24,9 +24,9 @@ export class RoleEntity extends AbstractEntity {
status: number

@ManyToMany(() => UserEntity, user => user.roles)
users: UserEntity[]
users: Relation<UserEntity[]>

@ManyToMany(() => MenuEntity, menu => menu.roles, {})
@JoinTable()
menus: MenuEntity[]
menus: Relation<MenuEntity[]>
}
4 changes: 2 additions & 2 deletions apps/api/src/modules/todo/todo.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm'
import { Column, Entity, JoinColumn, ManyToOne, Relation } from 'typeorm'

import { AbstractEntity } from '@/common/entity/abstract.entity'
import { UserEntity } from '@/modules/user/entities/user.entity'
Expand All @@ -16,5 +16,5 @@ export class TodoEntity extends AbstractEntity {

@ManyToOne(() => UserEntity)
@JoinColumn()
user: UserEntity
user: Relation<UserEntity>
}
7 changes: 4 additions & 3 deletions apps/api/src/modules/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ManyToMany,
ManyToOne,
OneToMany,
Relation,
} from 'typeorm'

import { AbstractEntity } from '@/common/entity/abstract.entity'
Expand Down Expand Up @@ -51,14 +52,14 @@ export class UserEntity extends AbstractEntity {

@ManyToMany(() => RoleEntity, role => role.users)
@JoinTable()
roles: RoleEntity[]
roles: Relation<RoleEntity[]>

@ManyToOne(() => DeptEntity, dept => dept.users)
@JoinColumn()
dept: DeptEntity
dept: Relation<DeptEntity>

@OneToMany(() => AccessTokenEntity, accessToken => accessToken.user, {
cascade: true,
})
accessTokens: AccessTokenEntity[]
accessTokens: Relation<AccessTokenEntity[]>
}

0 comments on commit 6279f5e

Please sign in to comment.