84 lines
2.2 KiB
TypeScript
84 lines
2.2 KiB
TypeScript
import type { PrizeDTO } from '@/lib/types/generated/PrizeDTO';
|
|
|
|
import { ViewModel } from "../contracts/view-models/ViewModel";
|
|
|
|
export class PrizeViewModel extends ViewModel {
|
|
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) {
|
|
this.id = dto.id;
|
|
this.leagueId = dto.leagueId;
|
|
this.seasonId = dto.seasonId;
|
|
this.position = dto.position;
|
|
this.name = dto.name;
|
|
this.amount = dto.amount;
|
|
this.type = dto.type;
|
|
this.description = dto.description;
|
|
this.awarded = dto.awarded;
|
|
this.awardedTo = dto.awardedTo;
|
|
this.awardedAt = dto.awardedAt ? new Date(dto.awardedAt) : undefined;
|
|
this.createdAt = new Date(dto.createdAt);
|
|
}
|
|
|
|
/** 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();
|
|
}
|
|
}
|