admin.entity.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { Column, Entity } from 'typeorm';
  2. import { BaseModel } from '../../frame/BaseModel';
  3. import * as bcrypt from 'bcryptjs';
  4. // 管理员
  5. @Entity('admin')
  6. export class Admin extends BaseModel {
  7. @Column({ type: 'character varying', nullable: true, comment: '管理员名称' })
  8. nick_name: string;
  9. @Column({ type: 'character varying', comment: '账号', unique: true })
  10. account: string;
  11. @Column({
  12. type: 'character varying',
  13. select: false,
  14. comment: '密码',
  15. transformer: {
  16. from: value => value,
  17. // to:进入数据库,需要加密
  18. to: value => {
  19. const salt = bcrypt.genSaltSync(10);
  20. const hash = bcrypt.hashSync(value, salt);
  21. return hash;
  22. },
  23. },
  24. })
  25. password: string; //TODO:需要重新加密
  26. @Column({ type: 'jsonb', nullable: true, comment: '角色id数组' })
  27. role: string[];
  28. @Column({ type: 'integer', nullable: true, comment: '部门id' })
  29. dept: number;
  30. @Column({ type: 'character varying', default: '0', comment: '是否使用: 0:使用;1:禁用' })
  31. is_use: string;
  32. @Column({ type: 'character varying', default: '1', comment: '是否是超级管理员: 0:是;1否' })
  33. is_super: string;
  34. }