role module

This commit is contained in:
2026-01-13 23:28:33 +03:30
parent d630cb844a
commit d046dc21ac
17 changed files with 171 additions and 442 deletions
+9 -8
View File
@@ -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
}