role.entity.ts 795 B

123456789101112131415161718192021222324252627282930313233
  1. import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';
  2. // 定义 Permission 类型
  3. export type Permission = string;
  4. @Entity({ name: 'roles' })
  5. export class Role {
  6. @PrimaryGeneratedColumn()
  7. id!: number;
  8. @Column({ type: 'varchar', length: 50 })
  9. name!: string;
  10. @Column({ type: 'text', nullable: true })
  11. description!: string | null;
  12. @Column({ type: 'simple-array', nullable: false })
  13. permissions: Permission[] = [];
  14. @CreateDateColumn({ name: 'created_at', type: 'timestamp' })
  15. createdAt!: Date;
  16. @UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
  17. updatedAt!: Date;
  18. constructor(partial?: Partial<Role>) {
  19. Object.assign(this, partial);
  20. if (!this.permissions) {
  21. this.permissions = [];
  22. }
  23. }
  24. }