Files
negareh-api/src/modules/user/entities/user.entity.ts
T
2026-02-22 12:50:49 +03:30

54 lines
1.4 KiB
TypeScript

import { Entity, Index, Property, OneToMany, Collection, PrimaryKey, OptionalProps } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { LearningProgress } from '../../learnings/entities/learning-progress.entity';
import { Criticism } from '../../criticisms/entities/criticism.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(() => LearningProgress, (lp) => lp.user)
learningProgress = new Collection<LearningProgress>(this);
@OneToMany(() => Criticism, (c) => c.user)
criticisms = new Collection<Criticism>(this);
// @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
}