user module

This commit is contained in:
2026-01-13 19:59:06 +03:30
parent 6522acff5f
commit d630cb844a
62 changed files with 1137 additions and 3040 deletions
@@ -0,0 +1,24 @@
import { Entity, Property, ManyToOne, Index, Enum } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from './user.entity';
import { CreditTransactionType } from '../interface/credit';
@Entity({ tableName: 'credit_transactions' })
@Index({ properties: ['user'] })
export class CreditTransaction extends BaseEntity {
@ManyToOne(() => User)
user!: User;
@Property()
orderId: string
@Property({ type: 'decimal', precision: 10, scale: 0 })
amount!: number;
@Property({ type: 'decimal', precision: 10, scale: 0 })
balance!: number;
@Enum(() => CreditTransaction)
type!: CreditTransactionType;
}
@@ -1,30 +0,0 @@
import { Entity, Property, ManyToOne, Index, Enum } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
import { User } from './user.entity';
import { PointTransactionReason } from '../interface/point';
import { PointTransactionType } from '../interface/point';
@Entity({ tableName: 'point_transactions' })
@Index({ properties: ['user', 'restaurant'] }) // Composite index for most common query: find wallet by user and restaurant
@Index({ properties: ['user'] }) // Index for queries finding all wallets for a user
@Index({ properties: ['restaurant'] }) // Index for queries finding all wallets for a restaurant
export class PointTransaction extends BaseEntity {
@ManyToOne(() => User)
user!: User;
@ManyToOne(() => User)
restaurant!: Restaurant;
@Property({ type: 'decimal', precision: 10, scale: 0 })
amount!: number;
@Property({ type: 'decimal', precision: 10, scale: 0 })
balance!: number;
@Enum(() => PointTransaction)
type!: PointTransactionType;
@Enum(() => PointTransactionReason)
reason!: PointTransactionReason;
}
+8 -12
View File
@@ -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],
@@ -1,29 +0,0 @@
import { Entity, Index, Property, ManyToOne, Enum } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from './user.entity';
import { WalletTransactionReason, WalletTransactionType } from '../interface/wallet';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
@Entity({ tableName: 'wallet_transactions' })
@Index({ properties: ['user', 'restaurant'] })
@Index({ properties: ['user'] })
@Index({ properties: ['restaurant'] })
export class WalletTransaction extends BaseEntity {
@ManyToOne(() => User)
user!: User;
@ManyToOne(() => Restaurant)
restaurant!: Restaurant;
@Property({ type: 'decimal', precision: 10, scale: 0 })
amount!: number;
@Property({ type: 'decimal', precision: 10, scale: 0 })
balance!: number;
@Enum(() => WalletTransactionType)
type!: WalletTransactionType;
@Enum(() => WalletTransactionReason)
reason!: WalletTransactionReason;
}