23 lines
834 B
TypeScript
Executable File
23 lines
834 B
TypeScript
Executable File
// role.entity.ts
|
|
import { Collection, Entity, ManyToMany, OneToMany, OneToOne, Property } from '@mikro-orm/core';
|
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
|
import { Admin } from './admin.entity';
|
|
import { Permission } from './permission.entity';
|
|
import { Restaurant } from '../../../modules/restaurants/entities/restaurant.entity';
|
|
import { RolePermission } from './rolePermission.entity';
|
|
|
|
@Entity()
|
|
export class Role extends BaseEntity {
|
|
@Property()
|
|
name!: string;
|
|
|
|
@ManyToMany({ entity: () => Permission, pivotEntity: () => RolePermission, inversedBy: p => p.roles })
|
|
permissions = new Collection<Permission>(this);
|
|
|
|
@OneToMany(() => Admin, admin => admin.role)
|
|
admins = new Collection<Admin>(this);
|
|
|
|
@OneToOne(() => Restaurant, { owner: true, nullable: true })
|
|
restaurant?: Restaurant;
|
|
}
|