view data fixes

This commit is contained in:
2026-01-23 15:30:23 +01:00
parent e22033be38
commit f8099f04bc
213 changed files with 3466 additions and 3003 deletions

View File

@@ -1,59 +1,44 @@
import type { PrizeDTO } from '@/lib/types/generated/PrizeDTO';
import { ViewModel } from "../contracts/view-models/ViewModel";
import { CurrencyDisplay } from "../display-objects/CurrencyDisplay";
import { FinishDisplay } from "../display-objects/FinishDisplay";
import { DateDisplay } from "../display-objects/DateDisplay";
import { PrizeTypeDisplay } from "../display-objects/PrizeTypeDisplay";
import type { PrizeViewData } from "../view-data/PrizeViewData";
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;
private readonly data: PrizeViewData;
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);
constructor(data: PrizeViewData) {
super();
this.data = data;
}
get id(): string { return this.data.id; }
get leagueId(): string { return this.data.leagueId; }
get seasonId(): string { return this.data.seasonId; }
get position(): number { return this.data.position; }
get name(): string { return this.data.name; }
get amount(): number { return this.data.amount; }
get type(): string { return this.data.type; }
get description(): string | undefined { return this.data.description; }
get awarded(): boolean { return this.data.awarded; }
get awardedTo(): string | undefined { return this.data.awardedTo; }
get awardedAt(): string | undefined { return this.data.awardedAt; }
get createdAt(): string { return this.data.createdAt; }
/** UI-specific: Formatted amount */
get formattedAmount(): string {
return `${this.amount.toFixed(2)}`; // Assuming EUR
return CurrencyDisplay.format(this.amount, '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`;
}
return FinishDisplay.format(this.position);
}
/** 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;
}
return PrizeTypeDisplay.format(this.type);
}
/** UI-specific: Status display */
@@ -73,11 +58,11 @@ export class PrizeViewModel extends ViewModel {
/** UI-specific: Formatted awarded date */
get formattedAwardedAt(): string {
return this.awardedAt ? this.awardedAt.toLocaleString() : 'Not awarded';
return this.awardedAt ? DateDisplay.formatShort(this.awardedAt) : 'Not awarded';
}
/** UI-specific: Formatted created date */
get formattedCreatedAt(): string {
return this.createdAt.toLocaleString();
return DateDisplay.formatShort(this.createdAt);
}
}