62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { RaceDTO } from '@/lib/types/generated/RaceDTO';
|
|
import { RacesPageDataRaceDTO } from '@/lib/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 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();
|
|
}
|
|
}
|