view models
This commit is contained in:
@@ -1,19 +1,31 @@
|
||||
import { PaymentDTO } from '../types/generated/PaymentDto';
|
||||
import type { PaymentDto } from '../types/generated';
|
||||
|
||||
export class PaymentViewModel implements PaymentDTO {
|
||||
export class PaymentViewModel {
|
||||
id: string;
|
||||
type: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
platformFee: number;
|
||||
netAmount: number;
|
||||
payerId: string;
|
||||
payerType: string;
|
||||
leagueId: string;
|
||||
seasonId?: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
createdAt: Date;
|
||||
completedAt?: Date;
|
||||
|
||||
constructor(dto: PaymentDTO) {
|
||||
constructor(dto: PaymentDto) {
|
||||
Object.assign(this, dto);
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted amount */
|
||||
get formattedAmount(): string {
|
||||
return `${this.currency} ${this.amount.toFixed(2)}`;
|
||||
return `€${this.amount.toFixed(2)}`; // Assuming EUR currency
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted net amount */
|
||||
get formattedNetAmount(): string {
|
||||
return `€${this.netAmount.toFixed(2)}`;
|
||||
}
|
||||
|
||||
/** UI-specific: Status color */
|
||||
@@ -22,17 +34,33 @@ export class PaymentViewModel implements PaymentDTO {
|
||||
case 'completed': return 'green';
|
||||
case 'pending': return 'yellow';
|
||||
case 'failed': return 'red';
|
||||
case 'refunded': return 'orange';
|
||||
default: return 'gray';
|
||||
}
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted created date */
|
||||
get formattedCreatedAt(): string {
|
||||
return new Date(this.createdAt).toLocaleString();
|
||||
return this.createdAt.toLocaleString();
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted completed date */
|
||||
get formattedCompletedAt(): string {
|
||||
return this.completedAt ? this.completedAt.toLocaleString() : 'Not completed';
|
||||
}
|
||||
|
||||
/** UI-specific: Status display */
|
||||
get statusDisplay(): string {
|
||||
return this.status.charAt(0).toUpperCase() + this.status.slice(1);
|
||||
}
|
||||
|
||||
/** UI-specific: Type display */
|
||||
get typeDisplay(): string {
|
||||
return this.type.replace('_', ' ').replace(/\b\w/g, l => l.toUpperCase());
|
||||
}
|
||||
|
||||
/** UI-specific: Payer type display */
|
||||
get payerTypeDisplay(): string {
|
||||
return this.payerType.charAt(0).toUpperCase() + this.payerType.slice(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user