user.entity.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
  2. import { RoleMt } from './role.entity';
  3. import { DeleteStatus, DisabledStatus } from '@d8d/shared-types';
  4. import { File } from '@d8d/file-module';
  5. @Entity({ name: 'users_mt' })
  6. export class UserEntityMt {
  7. @PrimaryGeneratedColumn({ unsigned: true, comment: '用户ID' })
  8. id!: number;
  9. @Column({ name: 'tenant_id', type: 'int', unsigned: true, comment: '租户ID' })
  10. tenantId!: number;
  11. @Column({ name: 'username', type: 'varchar', length: 255, comment: '用户名' })
  12. username!: string;
  13. @Column({ name: 'password', type: 'varchar', length: 255, comment: '密码' })
  14. password!: string;
  15. @Column({ name: 'phone', type: 'varchar', length: 255, nullable: true, comment: '手机号' })
  16. phone!: string | null;
  17. @Column({ name: 'email', type: 'varchar', length: 255, nullable: true, comment: '邮箱' })
  18. email!: string | null;
  19. @Column({ name: 'nickname', type: 'varchar', length: 255, nullable: true, comment: '昵称' })
  20. nickname!: string | null;
  21. @Column({ name: 'name', type: 'varchar', length: 255, nullable: true, comment: '真实姓名' })
  22. name!: string | null;
  23. @Column({ name: 'avatar_file_id', type: 'int', unsigned: true, nullable: true, comment: '头像文件ID' })
  24. avatarFileId!: number | null;
  25. @ManyToOne('File', { nullable: true })
  26. @JoinColumn({ name: 'avatar_file_id', referencedColumnName: 'id' })
  27. avatarFile!: File | null;
  28. @Column({ name: 'is_disabled', type: 'int', default: DisabledStatus.ENABLED, comment: '是否禁用(0:启用,1:禁用)' })
  29. isDisabled!: DisabledStatus;
  30. @Column({ name: 'is_deleted', type: 'int', default: DeleteStatus.NOT_DELETED, comment: '是否删除(0:未删除,1:已删除)' })
  31. isDeleted!: DeleteStatus;
  32. @Column({ name: 'openid', type: 'varchar', length: 255, nullable: true, unique: true, comment: '微信小程序openid' })
  33. openid!: string | null;
  34. @Column({ name: 'unionid', type: 'varchar', length: 255, nullable: true, comment: '微信unionid' })
  35. unionid!: string | null;
  36. @Column({ name: 'registration_source', type: 'varchar', length: 20, default: 'web', comment: '注册来源: web, miniapp' })
  37. registrationSource!: string;
  38. @ManyToMany(() => RoleMt)
  39. @JoinTable()
  40. roles!: RoleMt[];
  41. @CreateDateColumn({ name: 'created_at', type: 'timestamp' })
  42. createdAt!: Date;
  43. @UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
  44. updatedAt!: Date;
  45. constructor(partial?: Partial<UserEntityMt>) {
  46. Object.assign(this, partial);
  47. }
  48. }
  49. export { UserEntityMt as UserMt };