api client refactor
This commit is contained in:
38
apps/website/lib/view-models/PaymentViewModel.ts
Normal file
38
apps/website/lib/view-models/PaymentViewModel.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { PaymentDto } from '../dtos';
|
||||
|
||||
export class PaymentViewModel implements PaymentDto {
|
||||
id: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
|
||||
constructor(dto: PaymentDto) {
|
||||
Object.assign(this, dto);
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted amount */
|
||||
get formattedAmount(): string {
|
||||
return `${this.currency} ${this.amount.toFixed(2)}`;
|
||||
}
|
||||
|
||||
/** UI-specific: Status color */
|
||||
get statusColor(): string {
|
||||
switch (this.status) {
|
||||
case 'completed': return 'green';
|
||||
case 'pending': return 'yellow';
|
||||
case 'failed': return 'red';
|
||||
default: return 'gray';
|
||||
}
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted created date */
|
||||
get formattedCreatedAt(): string {
|
||||
return new Date(this.createdAt).toLocaleString();
|
||||
}
|
||||
|
||||
/** UI-specific: Status display */
|
||||
get statusDisplay(): string {
|
||||
return this.status.charAt(0).toUpperCase() + this.status.slice(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user