46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { Entity, Index, Property, OneToMany, Collection, Cascade, PrimaryKey, OptionalProps } from '@mikro-orm/core';
|
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
|
import { Order } from 'src/modules/order/entities/order.entity';
|
|
import { normalizePhone } from '../../util/phone.util';
|
|
import { ulid } from 'ulid';
|
|
|
|
@Entity({ tableName: 'users' })
|
|
export class User extends BaseEntity {
|
|
[OptionalProps]?: 'createdAt' | 'deletedAt'
|
|
|
|
@OneToMany(() => Order, order => order.user)
|
|
orders = new Collection<Order>(this);
|
|
|
|
|
|
@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);
|
|
}
|
|
|
|
|
|
@Property({ default: true })
|
|
isActive?: boolean = true;
|
|
|
|
@Property({ default: true, nullable: true })
|
|
gender?: boolean;
|
|
|
|
|
|
@Property({ default: 0 })
|
|
maxCredit: number;
|
|
|
|
@Property({ type: 'string', nullable: true })
|
|
addresse?: string
|
|
}
|