role module
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
import { Collection, Entity, Index, ManyToMany, OneToMany, ManyToOne, Property } from '@mikro-orm/core';
|
||||
import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Permission } from './permission.entity';
|
||||
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
|
||||
import { RolePermission } from './rolePermission.entity';
|
||||
import { AdminRole } from 'src/modules/admin/entities/adminRole.entity';
|
||||
import { Admin } from 'src/modules/admin/entities/admin.entity';
|
||||
import { ulid } from 'ulid';
|
||||
|
||||
@Entity({ tableName: 'roles' })
|
||||
@Index({ properties: ['restaurant'] })
|
||||
export class Role extends BaseEntity {
|
||||
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
|
||||
id: string = ulid()
|
||||
|
||||
@Property({ unique: true })
|
||||
name: string;
|
||||
|
||||
@Property()
|
||||
name!: string;
|
||||
title: string;
|
||||
|
||||
@Property({ default: false })
|
||||
isSystem: boolean = false;
|
||||
@@ -17,9 +22,6 @@ export class Role extends BaseEntity {
|
||||
@ManyToMany({ entity: () => Permission, pivotEntity: () => RolePermission, inversedBy: p => p.roles })
|
||||
permissions = new Collection<Permission>(this);
|
||||
|
||||
@ManyToOne(() => Restaurant, { nullable: true })
|
||||
restaurant?: Restaurant;
|
||||
|
||||
@OneToMany(() => AdminRole, adminRole => adminRole.role)
|
||||
admins = new Collection<AdminRole>(this);
|
||||
@OneToMany(() => Admin, admin => admin.role)
|
||||
admins = new Collection<Admin>(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user