user module
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { Entity, Index, Property, OneToMany, Collection, Cascade } from '@mikro-orm/core';
|
||||
import { Entity, Index, Property, OneToMany, Collection, Cascade, PrimaryKey } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { UserAddress } from './user-address.entity';
|
||||
import { Order } from 'src/modules/order/entities/order.entity';
|
||||
import { normalizePhone } from '../../util/phone.util';
|
||||
import { ulid } from 'ulid';
|
||||
|
||||
@Entity({ tableName: 'users' })
|
||||
@Index({ properties: ['isActive'] })
|
||||
export class User extends BaseEntity {
|
||||
@OneToMany(() => Order, order => order.user)
|
||||
orders = new Collection<Order>(this);
|
||||
|
||||
@PrimaryKey({ type: 'string', columnType: 'char(26)' })
|
||||
id: string = ulid();
|
||||
|
||||
@Property()
|
||||
firstName!: string;
|
||||
|
||||
@@ -27,14 +30,6 @@ export class User extends BaseEntity {
|
||||
this._phone = normalizePhone(value);
|
||||
}
|
||||
|
||||
@Property({ default: null, type: 'date', nullable: true })
|
||||
birthDate?: Date;
|
||||
|
||||
@Property({ default: null, type: 'date', nullable: true })
|
||||
marriageDate?: Date;
|
||||
|
||||
@Property({ nullable: true })
|
||||
referrer?: string;
|
||||
|
||||
@Property({ default: true })
|
||||
isActive?: boolean = true;
|
||||
@@ -42,8 +37,9 @@ export class User extends BaseEntity {
|
||||
@Property({ default: true, nullable: true })
|
||||
gender?: boolean;
|
||||
|
||||
@Property({ nullable: true })
|
||||
avatarUrl?: string;
|
||||
|
||||
@Property({ default: 0 })
|
||||
maxCredit: number;
|
||||
|
||||
@OneToMany(() => UserAddress, address => address.user, {
|
||||
cascade: [Cascade.ALL],
|
||||
|
||||
Reference in New Issue
Block a user