Files
gridpilot.gg/apps/website/lib/view-models/RaceViewModel.ts
2025-12-25 00:19:36 +01:00

57 lines
1.3 KiB
TypeScript

import { RaceDTO } from '../types/generated/RaceDTO';
import { RacesPageDataRaceDTO } from '../types/generated/RacesPageDataRaceDTO';
export class RaceViewModel {
constructor(
private readonly dto: RaceDTO | RacesPageDataRaceDTO,
private readonly _status?: string,
private readonly _registeredCount?: number,
private readonly _strengthOfField?: number
) {}
get id(): string {
return this.dto.id;
}
get name(): string {
if ('name' in this.dto) {
return this.dto.name;
}
return '';
}
get date(): string {
if ('date' in this.dto) {
return this.dto.date;
}
if ('scheduledAt' in this.dto) {
return this.dto.scheduledAt;
}
return '';
}
get track(): string {
return (this.dto as any).track || '';
}
get car(): string {
return (this.dto as any).car || '';
}
get status(): string | undefined {
return this._status || (this.dto as any).status;
}
get registeredCount(): number | undefined {
return this._registeredCount;
}
get strengthOfField(): number | undefined {
return this._strengthOfField || (this.dto as any).strengthOfField;
}
/** UI-specific: Formatted date */
get formattedDate(): string {
return new Date(this.date).toLocaleDateString();
}
}