30 lines
1.0 KiB
TypeScript
Executable File
30 lines
1.0 KiB
TypeScript
Executable File
// role.entity.ts
|
|
import { Collection, Entity, ManyToMany, OneToMany, ManyToOne, 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';
|
|
import { AdminRole } from './adminRole.entity';
|
|
|
|
@Entity({ tableName: 'roles' })
|
|
export class Role extends BaseEntity {
|
|
@Property()
|
|
name!: string;
|
|
|
|
@Property()
|
|
title!: 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);
|
|
|
|
@ManyToOne(() => Restaurant, { nullable: true })
|
|
restaurant?: Restaurant;
|
|
|
|
@OneToMany(() => AdminRole, adminRoleRestaurant => adminRoleRestaurant.role)
|
|
adminRoles = new Collection<AdminRole>(this);
|
|
}
|