31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
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;
|
|
}
|