import { ApiHideProperty } from '@nestjs/swagger'; import { Exclude } from 'class-transformer'; import pinyin from 'pinyin'; import { BeforeInsert, BeforeUpdate, Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, Relation } from 'typeorm'; import { SkDomain } from '~/common/decorators/domain.decorator'; import { CommonEntity } from '~/common/entity/common.entity'; import { AccessTokenEntity } from '~/modules/auth/entities/access-token.entity'; import { DeptEntity } from '~/modules/system/dept/dept.entity'; import { RoleEntity } from '~/modules/system/role/role.entity'; @Entity({ name: 'sys_user' }) export class UserEntity extends CommonEntity { @Column({ unique: true }) username: string; @Exclude() @Column() password: string; @Column({ length: 32 }) psalt: string; @Column({ nullable: true }) nickname: string; @ApiHideProperty() @Column({ name: 'name_pinyin', type: 'varchar', length: 255, nullable: true, comment: '产品名称的拼音' }) namePinyin: string; @BeforeInsert() @BeforeUpdate() updateNamePinyin() { this.namePinyin = pinyin(this.nickname, { style: pinyin.STYLE_NORMAL, heteronym: false }).join(''); } @Column({ name: 'avatar', nullable: true }) avatar: string; @Column({ nullable: true }) qq: string; @Column({ nullable: true }) email: string; @Column({ nullable: true }) phone: string; @Column({ nullable: true }) remark: string; @Column({ type: 'tinyint', nullable: true, default: 1 }) status: number; @Column({ type: 'int', default: 1, comment: '所属域' }) domain: SkDomain; @ManyToMany(() => RoleEntity, role => role.users) @JoinTable({ name: 'sys_user_roles', joinColumn: { name: 'user_id', referencedColumnName: 'id' }, inverseJoinColumn: { name: 'role_id', referencedColumnName: 'id' } }) roles: Relation; @ManyToOne(() => DeptEntity, dept => dept.users) @JoinColumn({ name: 'dept_id' }) dept: Relation; @OneToMany(() => AccessTokenEntity, accessToken => accessToken.user, { cascade: true }) accessTokens: Relation; }