Files
gridpilot.gg/apps/website/lib/view-models/PrizeViewModel.ts
2025-12-18 13:48:35 +01:00

70 lines
1.7 KiB
TypeScript

import type { PrizeDto } from '../types/generated';
export class PrizeViewModel {
id: string;
leagueId: string;
seasonId: string;
position: number;
name: string;
amount: number;
type: string;
description?: string;
awarded: boolean;
awardedTo?: string;
awardedAt?: Date;
createdAt: Date;
constructor(dto: PrizeDto) {
Object.assign(this, dto);
}
/** UI-specific: Formatted amount */
get formattedAmount(): string {
return `${this.amount.toFixed(2)}`; // Assuming EUR
}
/** UI-specific: Position display */
get positionDisplay(): string {
switch (this.position) {
case 1: return '1st Place';
case 2: return '2nd Place';
case 3: return '3rd Place';
default: return `${this.position}th Place`;
}
}
/** UI-specific: Type display */
get typeDisplay(): string {
switch (this.type) {
case 'cash': return 'Cash Prize';
case 'merchandise': return 'Merchandise';
case 'other': return 'Other';
default: return this.type;
}
}
/** UI-specific: Status display */
get statusDisplay(): string {
return this.awarded ? 'Awarded' : 'Available';
}
/** UI-specific: Status color */
get statusColor(): string {
return this.awarded ? 'green' : 'blue';
}
/** UI-specific: Prize description */
get prizeDescription(): string {
return `${this.name} - ${this.formattedAmount}`;
}
/** UI-specific: Formatted awarded date */
get formattedAwardedAt(): string {
return this.awardedAt ? this.awardedAt.toLocaleString() : 'Not awarded';
}
/** UI-specific: Formatted created date */
get formattedCreatedAt(): string {
return this.createdAt.toLocaleString();
}
}