permission
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Permission } from './permission.entity';
|
||||
import { RolePermission } from './rolePermission.entity';
|
||||
import { ulid } from 'ulid';
|
||||
import { Admin } from 'src/modules/admin/entities/admin.entity';
|
||||
|
||||
@Entity({ tableName: 'roles' })
|
||||
export class Role extends BaseEntity {
|
||||
export class Role {
|
||||
[OptionalProps]?: 'createdAt' | 'deletedAt' | 'admins';
|
||||
|
||||
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
|
||||
id: string = ulid()
|
||||
|
||||
@@ -21,5 +23,13 @@ export class Role extends BaseEntity {
|
||||
@ManyToMany({ entity: () => Permission, pivotEntity: () => RolePermission, inversedBy: p => p.roles })
|
||||
permissions = new Collection<Permission>(this);
|
||||
|
||||
@OneToMany(() => Admin, (admin) => admin.role)
|
||||
admins: Admin
|
||||
|
||||
@Property({ defaultRaw: 'now()', columnType: 'timestamptz' })
|
||||
createdAt: Date = new Date();
|
||||
|
||||
@Property({ nullable: true, columnType: 'timestamptz' })
|
||||
deletedAt?: Date;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user