Files
gridpilot.gg/apps/website/lib/view-models/PaymentViewModel.ts
2026-01-12 01:01:49 +01:00

66 lines
1.7 KiB
TypeScript

import type { PaymentDTO } from '@/lib/types/generated/PaymentDTO';
export class PaymentViewModel {
id!: string;
type!: string;
amount!: number;
platformFee!: number;
netAmount!: number;
payerId!: string;
payerType!: string;
leagueId!: string;
seasonId?: string;
status!: string;
createdAt!: Date;
completedAt?: Date;
constructor(dto: PaymentDTO) {
Object.assign(this, dto);
}
/** UI-specific: Formatted amount */
get formattedAmount(): string {
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 */
get statusColor(): string {
switch (this.status) {
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 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);
}
}