view data fixes
This commit is contained in:
@@ -1,63 +1,27 @@
|
||||
import { RaceDTO } from '@/lib/types/generated/RaceDTO';
|
||||
import { RacesPageDataRaceDTO } from '@/lib/types/generated/RacesPageDataRaceDTO';
|
||||
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
import { RaceViewData } from "../view-data/RaceViewData";
|
||||
|
||||
export class RaceViewModel extends ViewModel {
|
||||
constructor(
|
||||
private readonly dto: RaceDTO | RacesPageDataRaceDTO,
|
||||
private readonly _status?: string,
|
||||
private readonly _registeredCount?: number,
|
||||
private readonly _strengthOfField?: number
|
||||
) {}
|
||||
private readonly data: RaceViewData;
|
||||
|
||||
get id(): string {
|
||||
return this.dto.id;
|
||||
constructor(data: RaceViewData) {
|
||||
super();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
get id(): string { return this.data.id; }
|
||||
get name(): string { return this.data.name; }
|
||||
get date(): string { return this.data.date; }
|
||||
get scheduledAt(): string { return this.data.date; }
|
||||
get track(): string { return this.data.track; }
|
||||
get car(): string { return this.data.car; }
|
||||
get status(): string | undefined { return this.data.status; }
|
||||
get registeredCount(): number | undefined { return this.data.registeredCount; }
|
||||
get strengthOfField(): number | undefined { return this.data.strengthOfField; }
|
||||
|
||||
/** UI-specific: Formatted date */
|
||||
get formattedDate(): string {
|
||||
// Client-only formatting
|
||||
return new Date(this.date).toLocaleDateString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user