view data fixes
This commit is contained in:
@@ -1,36 +1,27 @@
|
||||
import { RaceResultDTO } from '@/lib/types/generated/RaceResultDTO';
|
||||
import { RaceResultsDetailDTO } from '@/lib/types/generated/RaceResultsDetailDTO';
|
||||
import { RaceResultViewModel } from './RaceResultViewModel';
|
||||
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
import { RaceResultViewModel } from './RaceResultViewModel';
|
||||
import type { RaceResultsDetailViewData } from "../view-data/RaceResultsDetailViewData";
|
||||
|
||||
export class RaceResultsDetailViewModel extends ViewModel {
|
||||
raceId: string;
|
||||
track: string;
|
||||
currentUserId: string;
|
||||
private readonly data: RaceResultsDetailViewData;
|
||||
readonly results: RaceResultViewModel[];
|
||||
|
||||
constructor(dto: RaceResultsDetailDTO & { results?: RaceResultDTO[] }, currentUserId: string) {
|
||||
constructor(data: RaceResultsDetailViewData) {
|
||||
super();
|
||||
this.raceId = dto.raceId;
|
||||
this.track = dto.track;
|
||||
this.currentUserId = currentUserId;
|
||||
|
||||
// Map results if provided
|
||||
if (dto.results) {
|
||||
this.results = dto.results.map(r => new RaceResultViewModel(r));
|
||||
}
|
||||
this.data = data;
|
||||
this.results = data.results.map(r => new RaceResultViewModel(r));
|
||||
}
|
||||
|
||||
// Note: The generated DTO is incomplete
|
||||
// These fields will need to be added when the OpenAPI spec is updated
|
||||
results: RaceResultViewModel[] = [];
|
||||
league?: { id: string; name: string };
|
||||
race?: { id: string; track: string; scheduledAt: string };
|
||||
drivers: { id: string; name: string }[] = [];
|
||||
pointsSystem: Record<number, number> = {};
|
||||
fastestLapTime: number = 0;
|
||||
penalties: { driverId: string; type: string; value?: number }[] = [];
|
||||
currentDriverId: string = '';
|
||||
get raceId(): string { return this.data.raceId; }
|
||||
get track(): string { return this.data.track; }
|
||||
get currentUserId(): string { return this.data.currentUserId; }
|
||||
get league() { return this.data.league; }
|
||||
get race() { return this.data.race; }
|
||||
get drivers() { return this.data.drivers; }
|
||||
get pointsSystem() { return this.data.pointsSystem; }
|
||||
get fastestLapTime(): number { return this.data.fastestLapTime; }
|
||||
get penalties() { return this.data.penalties; }
|
||||
get currentDriverId(): string { return this.data.currentDriverId; }
|
||||
|
||||
/** UI-specific: Results sorted by position */
|
||||
get resultsByPosition(): RaceResultViewModel[] {
|
||||
@@ -63,4 +54,4 @@ export class RaceResultsDetailViewModel extends ViewModel {
|
||||
averageIncidents: total > 0 ? totalIncidents / total : 0
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user