user.entity.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { Column, Entity } from 'typeorm';
  2. import { BaseModel } from '../../frame/BaseModel';
  3. import * as bcrypt from 'bcryptjs';
  4. @Entity('user')
  5. export class User extends BaseModel {
  6. @Column({ type: 'character varying', nullable: true, comment: '昵称' })
  7. nick_name: string;
  8. @Column({ type: 'character varying', comment: '账号', unique: true })
  9. account: string;
  10. @Column({
  11. type: 'character varying',
  12. select: false,
  13. comment: '密码',
  14. transformer: {
  15. from: value => value,
  16. // to:进入数据库,需要加密
  17. to: value => {
  18. const salt = bcrypt.genSaltSync(10);
  19. const hash = bcrypt.hashSync(value, salt);
  20. return hash;
  21. },
  22. },
  23. })
  24. password: string; //TODO:需要重新加密
  25. @Column({ type: 'character varying', comment: '性别' })
  26. gender: string;
  27. @Column({ type: 'character varying', nullable: true, comment: '手机号' })
  28. phone: string;
  29. @Column({ type: 'character varying', nullable: true, comment: '电子邮箱' })
  30. email: string;
  31. @Column({ type: 'jsonb', nullable: true, comment: '角色id数组' })
  32. role: number[];
  33. @Column({ type: 'character varying', default: '1', comment: '状态: 0:未审核;1:已审核' })
  34. status: string;
  35. }