39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { Cascade, Entity, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core';
|
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
|
import { normalizePhone } from '../../util/phone.util';
|
|
import { Role } from 'src/modules/roles/entities/role.entity';
|
|
import { ulid } from 'ulid';
|
|
import { NotificationPreference } from 'src/modules/notification/entities/notification-preference.entity';
|
|
|
|
@Entity({ tableName: 'admins' })
|
|
export class Admin extends BaseEntity {
|
|
|
|
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
|
|
id: string = ulid()
|
|
|
|
@Property({ nullable: true })
|
|
firstName?: string;
|
|
|
|
@Property({ nullable: true })
|
|
lastName?: string;
|
|
|
|
private _phone!: string;
|
|
|
|
@Property({ unique: true })
|
|
get phone(): string {
|
|
return this._phone;
|
|
}
|
|
|
|
set phone(value: string) {
|
|
this._phone = normalizePhone(value);
|
|
}
|
|
|
|
@ManyToOne(() => Role)
|
|
role: Role
|
|
|
|
// @OneToOne(() => NotificationPreference, pref => pref.admin, {
|
|
|
|
// })
|
|
// notificationPreference!: NotificationPreference;
|
|
}
|