oa_based/src/modules/user/user.entity.ts

97 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-04-09 15:24:54 +08:00
import { ApiHideProperty } from '@nestjs/swagger';
2024-02-28 17:02:46 +08:00
import { Exclude } from 'class-transformer';
2024-04-09 15:24:54 +08:00
import pinyin from 'pinyin';
2024-02-28 08:32:35 +08:00
import {
2024-04-09 15:24:54 +08:00
BeforeInsert,
BeforeUpdate,
2024-02-28 08:32:35 +08:00
Column,
Entity,
JoinColumn,
JoinTable,
ManyToMany,
ManyToOne,
OneToMany,
2024-02-29 09:29:03 +08:00
Relation
2024-02-28 17:02:46 +08:00
} from 'typeorm';
2024-04-16 14:06:02 +08:00
import { SkDomain } from '~/common/decorators/domain.decorator';
2024-02-28 08:32:35 +08:00
2024-02-28 17:02:46 +08:00
import { CommonEntity } from '~/common/entity/common.entity';
2024-02-28 08:32:35 +08:00
2024-02-28 17:02:46 +08:00
import { AccessTokenEntity } from '~/modules/auth/entities/access-token.entity';
2024-02-28 08:32:35 +08:00
2024-02-28 17:02:46 +08:00
import { DeptEntity } from '~/modules/system/dept/dept.entity';
import { RoleEntity } from '~/modules/system/role/role.entity';
2024-02-28 08:32:35 +08:00
@Entity({ name: 'sys_user' })
export class UserEntity extends CommonEntity {
@Column({ unique: true })
2024-02-28 17:02:46 +08:00
username: string;
2024-02-28 08:32:35 +08:00
@Exclude()
@Column()
2024-02-28 17:02:46 +08:00
password: string;
2024-02-28 08:32:35 +08:00
@Column({ length: 32 })
2024-02-28 17:02:46 +08:00
psalt: string;
2024-02-28 08:32:35 +08:00
@Column({ nullable: true })
2024-02-28 17:02:46 +08:00
nickname: string;
2024-02-28 08:32:35 +08:00
2024-04-09 15:24:54 +08:00
@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('');
}
2024-02-28 08:32:35 +08:00
@Column({ name: 'avatar', nullable: true })
2024-02-28 17:02:46 +08:00
avatar: string;
2024-02-28 08:32:35 +08:00
@Column({ nullable: true })
2024-02-28 17:02:46 +08:00
qq: string;
2024-02-28 08:32:35 +08:00
@Column({ nullable: true })
2024-02-28 17:02:46 +08:00
email: string;
2024-02-28 08:32:35 +08:00
@Column({ nullable: true })
2024-02-28 17:02:46 +08:00
phone: string;
2024-02-28 08:32:35 +08:00
@Column({ nullable: true })
2024-02-28 17:02:46 +08:00
remark: string;
2024-02-28 08:32:35 +08:00
@Column({ type: 'tinyint', nullable: true, default: 1 })
2024-02-28 17:02:46 +08:00
status: number;
2024-02-28 08:32:35 +08:00
2024-04-16 14:06:02 +08:00
@Column({ type: 'int', default: 1, comment: '所属域' })
domain: SkDomain;
2024-02-28 08:32:35 +08:00
@ManyToMany(() => RoleEntity, role => role.users)
@JoinTable({
name: 'sys_user_roles',
joinColumn: { name: 'user_id', referencedColumnName: 'id' },
2024-02-29 09:29:03 +08:00
inverseJoinColumn: { name: 'role_id', referencedColumnName: 'id' }
2024-02-28 08:32:35 +08:00
})
2024-02-28 17:02:46 +08:00
roles: Relation<RoleEntity[]>;
2024-02-28 08:32:35 +08:00
@ManyToOne(() => DeptEntity, dept => dept.users)
@JoinColumn({ name: 'dept_id' })
2024-02-28 17:02:46 +08:00
dept: Relation<DeptEntity>;
2024-02-28 08:32:35 +08:00
@OneToMany(() => AccessTokenEntity, accessToken => accessToken.user, {
2024-02-29 09:29:03 +08:00
cascade: true
2024-02-28 08:32:35 +08:00
})
2024-02-28 17:02:46 +08:00
accessTokens: Relation<AccessTokenEntity[]>;
2024-02-28 08:32:35 +08:00
}