Files
gridpilot.gg/apps/website/lib/view-models/RaceViewModel.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

64 lines
1.5 KiB
TypeScript

import { RaceDTO } from '@/lib/types/generated/RaceDTO';
import { RacesPageDataRaceDTO } from '@/lib/types/generated/RacesPageDataRaceDTO';
import { ViewModel } from "../contracts/view-models/ViewModel";
export class RaceViewModel extends ViewModel {
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 scheduledAt(): string {
return this.date;
}
get track(): string {
return 'track' in this.dto ? this.dto.track || '' : '';
}
get car(): string {
return 'car' in this.dto ? this.dto.car || '' : '';
}
get status(): string | undefined {
return this._status || ('status' in this.dto ? this.dto.status : undefined);
}
get registeredCount(): number | undefined {
return this._registeredCount;
}
get strengthOfField(): number | undefined {
return this._strengthOfField || ('strengthOfField' in this.dto ? this.dto.strengthOfField : undefined);
}
/** UI-specific: Formatted date */
get formattedDate(): string {
return new Date(this.date).toLocaleDateString();
}
}