role module
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import { Cascade, Collection, Entity, OneToMany, Property } from '@mikro-orm/core';
|
||||
import { Entity, OneToOne, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { AdminRole } from './adminRole.entity';
|
||||
import { normalizePhone } from '../../util/phone.util';
|
||||
import { Role } from 'src/modules/roles/entities/role.entity';
|
||||
import { ulid } from 'ulid';
|
||||
|
||||
@Entity({ tableName: 'admins' })
|
||||
export class Admin extends BaseEntity {
|
||||
|
||||
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
|
||||
id: string = ulid()
|
||||
|
||||
@Property({ nullable: true })
|
||||
firstName?: string;
|
||||
|
||||
@@ -22,10 +27,6 @@ export class Admin extends BaseEntity {
|
||||
this._phone = normalizePhone(value);
|
||||
}
|
||||
|
||||
// Add the new role property
|
||||
@OneToMany(() => AdminRole, adminRole => adminRole.admin, {
|
||||
cascade: [Cascade.ALL],
|
||||
orphanRemoval: true,
|
||||
})
|
||||
roles = new Collection<AdminRole>(this);
|
||||
@OneToOne(() => Role)
|
||||
role: Role
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user