27 lines
845 B
TypeScript
Executable File
27 lines
845 B
TypeScript
Executable File
import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core';
|
|
import { Permission } from './permission.entity';
|
|
import { RolePermission } from './rolePermission.entity';
|
|
import { Admin } from 'src/modules/admin/entities/admin.entity';
|
|
import { BaseEntity } from 'src/common/entities/base.entity';
|
|
|
|
@Entity({ tableName: 'roles' })
|
|
export class Role extends BaseEntity {
|
|
[OptionalProps]?: 'createdAt' | 'deletedAt' | 'admins';
|
|
|
|
@Property({ unique: true })
|
|
name: string;
|
|
|
|
@Property()
|
|
title: string;
|
|
|
|
@Property({ default: false })
|
|
isSystem: boolean = false;
|
|
|
|
@ManyToMany({ entity: () => Permission, pivotEntity: () => RolePermission, inversedBy: p => p.roles })
|
|
permissions = new Collection<Permission>(this);
|
|
|
|
@OneToMany(() => Admin, (admin) => admin.role)
|
|
admins: Admin
|
|
|
|
}
|