fix data flow issues
This commit is contained in:
@@ -1,39 +1,45 @@
|
||||
import { TransactionDto } from '../types/generated/TransactionDto';
|
||||
|
||||
// TODO: Use generated TransactionDto when it includes all required fields
|
||||
export type FullTransactionDto = TransactionDto & {
|
||||
amount: number;
|
||||
description: string;
|
||||
createdAt: string;
|
||||
type: 'deposit' | 'withdrawal';
|
||||
};
|
||||
|
||||
export class WalletTransactionViewModel {
|
||||
id: string;
|
||||
walletId: string;
|
||||
amount: number;
|
||||
type: 'sponsorship' | 'membership' | 'withdrawal' | 'prize';
|
||||
description: string;
|
||||
createdAt: string;
|
||||
type: 'deposit' | 'withdrawal';
|
||||
amount: number;
|
||||
fee: number;
|
||||
netAmount: number;
|
||||
date: Date;
|
||||
status: 'completed' | 'pending' | 'failed';
|
||||
reference?: string;
|
||||
|
||||
constructor(dto: FullTransactionDto) {
|
||||
constructor(dto: {
|
||||
id: string;
|
||||
type: 'sponsorship' | 'membership' | 'withdrawal' | 'prize';
|
||||
description: string;
|
||||
amount: number;
|
||||
fee: number;
|
||||
netAmount: number;
|
||||
date: Date;
|
||||
status: 'completed' | 'pending' | 'failed';
|
||||
reference?: string;
|
||||
}) {
|
||||
this.id = dto.id;
|
||||
this.walletId = dto.walletId;
|
||||
this.amount = dto.amount;
|
||||
this.description = dto.description;
|
||||
this.createdAt = dto.createdAt;
|
||||
this.type = dto.type;
|
||||
this.description = dto.description;
|
||||
this.amount = dto.amount;
|
||||
this.fee = dto.fee;
|
||||
this.netAmount = dto.netAmount;
|
||||
this.date = dto.date;
|
||||
this.status = dto.status;
|
||||
this.reference = dto.reference;
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted amount with sign */
|
||||
get formattedAmount(): string {
|
||||
const sign = this.type === 'deposit' ? '+' : '-';
|
||||
return `${sign}$${this.amount.toFixed(2)}`;
|
||||
const sign = this.amount > 0 ? '+' : '';
|
||||
return `${sign}$${Math.abs(this.amount).toFixed(2)}`;
|
||||
}
|
||||
|
||||
/** UI-specific: Amount color */
|
||||
get amountColor(): string {
|
||||
return this.type === 'deposit' ? 'green' : 'red';
|
||||
return this.amount > 0 ? 'green' : 'red';
|
||||
}
|
||||
|
||||
/** UI-specific: Type display */
|
||||
@@ -41,13 +47,13 @@ export class WalletTransactionViewModel {
|
||||
return this.type.charAt(0).toUpperCase() + this.type.slice(1);
|
||||
}
|
||||
|
||||
/** UI-specific: Amount color */
|
||||
get amountColor(): string {
|
||||
return this.type === 'deposit' ? 'green' : 'red';
|
||||
/** UI-specific: Formatted date */
|
||||
get formattedDate(): string {
|
||||
return this.date.toLocaleDateString();
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted created date */
|
||||
get formattedCreatedAt(): string {
|
||||
return new Date(this.createdAt).toLocaleString();
|
||||
/** UI-specific: Is incoming */
|
||||
get isIncoming(): boolean {
|
||||
return this.amount > 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user