view models

This commit is contained in:
2025-12-18 00:08:47 +01:00
parent f7a56a92ce
commit 7c449af311
56 changed files with 2594 additions and 206 deletions

View File

@@ -1,16 +1,24 @@
import { WalletTransactionDto } from '../dtos';
import { TransactionDto } from '../types/generated/TransactionDto';
export class WalletTransactionViewModel implements WalletTransactionDto {
export class WalletTransactionViewModel implements TransactionDto {
id: string;
type: 'deposit' | 'withdrawal';
walletId: string;
amount: number;
description?: string;
description: string;
createdAt: string;
constructor(dto: WalletTransactionDto) {
Object.assign(this, dto);
constructor(dto: TransactionDto) {
this.id = dto.id;
this.walletId = dto.walletId;
this.amount = dto.amount;
this.description = dto.description;
this.createdAt = dto.createdAt;
}
// Note: The generated DTO doesn't have type field
// This will need to be added when the OpenAPI spec is updated
type: 'deposit' | 'withdrawal' = 'deposit';
/** UI-specific: Formatted amount with sign */
get formattedAmount(): string {
const sign = this.type === 'deposit' ? '+' : '-';
@@ -27,6 +35,11 @@ export class WalletTransactionViewModel implements WalletTransactionDto {
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 created date */
get formattedCreatedAt(): string {
return new Date(this.createdAt).toLocaleString();