|
|
import { |
|
|
Entity, |
|
|
PrimaryGeneratedColumn, |
|
|
Column, |
|
|
CreateDateColumn, |
|
|
ManyToOne, |
|
|
Index, |
|
|
} from 'typeorm'; |
|
|
import { Wallet } from './Wallet'; |
|
|
import { Agent } from './Agent'; |
|
|
import { User } from './User'; |
|
|
|
|
|
export enum TransactionType { |
|
|
PURCHASE = 'purchase', |
|
|
CHARGE = 'charge', |
|
|
REFUND = 'refund', |
|
|
FREE = 'free', |
|
|
ADMIN_TEST = 'admin_test', |
|
|
} |
|
|
|
|
|
export enum TransactionStatus { |
|
|
PENDING = 'pending', |
|
|
COMPLETED = 'completed', |
|
|
FAILED = 'failed', |
|
|
} |
|
|
|
|
|
@Entity('transactions') |
|
|
@Index(['walletId', 'createdAt']) |
|
|
@Index(['userId', 'agentId']) |
|
|
export class Transaction { |
|
|
@PrimaryGeneratedColumn('uuid') |
|
|
id: string; |
|
|
|
|
|
@ManyToOne(() => Wallet, (wallet) => wallet.transactions) |
|
|
wallet: Wallet; |
|
|
|
|
|
@Column() |
|
|
walletId: string; |
|
|
|
|
|
@ManyToOne(() => User, { nullable: true }) |
|
|
user: User; |
|
|
|
|
|
@Column({ nullable: true }) |
|
|
userId?: string; |
|
|
|
|
|
@ManyToOne(() => Agent, { nullable: true }) |
|
|
agent: Agent; |
|
|
|
|
|
@Column({ nullable: true }) |
|
|
agentId?: string; |
|
|
|
|
|
@Column({ |
|
|
type: 'enum', |
|
|
enum: TransactionType, |
|
|
}) |
|
|
type: TransactionType; |
|
|
|
|
|
@Column({ |
|
|
type: 'enum', |
|
|
enum: TransactionStatus, |
|
|
default: TransactionStatus.PENDING, |
|
|
}) |
|
|
status: TransactionStatus; |
|
|
|
|
|
@Column('decimal', { precision: 15, scale: 2 }) |
|
|
amount: number; |
|
|
|
|
|
@Column('decimal', { precision: 15, scale: 2, nullable: true }) |
|
|
balanceAfter: number; |
|
|
|
|
|
@Column({ nullable: true }) |
|
|
description?: string; |
|
|
|
|
|
@Column({ nullable: true, unique: true }) |
|
|
paymentReference?: string; |
|
|
|
|
|
@Column('jsonb', { nullable: true }) |
|
|
metadata?: Record<string, any>; |
|
|
|
|
|
@CreateDateColumn() |
|
|
createdAt: Date; |
|
|
} |
|
|
|