view data fixes
This commit is contained in:
@@ -1,24 +1,29 @@
|
||||
import { RaceResultDTO } from '@/lib/types/generated/RaceResultDTO';
|
||||
import { FinishDisplay } from '../display-objects/FinishDisplay';
|
||||
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
import { FinishDisplay } from '../display-objects/FinishDisplay';
|
||||
import { DurationDisplay } from '../display-objects/DurationDisplay';
|
||||
import type { RaceResultViewData } from "../view-data/RaceResultViewData";
|
||||
|
||||
export class RaceResultViewModel extends ViewModel {
|
||||
driverId!: string;
|
||||
driverName!: string;
|
||||
avatarUrl!: string;
|
||||
position!: number;
|
||||
startPosition!: number;
|
||||
incidents!: number;
|
||||
fastestLap!: number;
|
||||
positionChange!: number;
|
||||
isPodium!: boolean;
|
||||
isClean!: boolean;
|
||||
private readonly data: RaceResultViewData;
|
||||
|
||||
constructor(dto: RaceResultDTO) {
|
||||
Object.assign(this, dto);
|
||||
constructor(data: RaceResultViewData) {
|
||||
super();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
get driverId(): string { return this.data.driverId; }
|
||||
get driverName(): string { return this.data.driverName; }
|
||||
get avatarUrl(): string { return this.data.avatarUrl; }
|
||||
get position(): number { return this.data.position; }
|
||||
get startPosition(): number { return this.data.startPosition; }
|
||||
get incidents(): number { return this.data.incidents; }
|
||||
get fastestLap(): number { return this.data.fastestLap; }
|
||||
get positionChange(): number { return this.data.positionChange; }
|
||||
get isPodium(): boolean { return this.data.isPodium; }
|
||||
get isClean(): boolean { return this.data.isClean; }
|
||||
get id(): string { return this.data.id; }
|
||||
get raceId(): string { return this.data.raceId; }
|
||||
|
||||
/** UI-specific: Display for position change */
|
||||
get positionChangeDisplay(): string {
|
||||
if (this.positionChange > 0) return `+${this.positionChange}`;
|
||||
@@ -58,10 +63,7 @@ export class RaceResultViewModel extends ViewModel {
|
||||
/** UI-specific: Formatted lap time */
|
||||
get lapTimeFormatted(): string {
|
||||
if (this.fastestLap <= 0) return '--:--.---';
|
||||
const minutes = Math.floor(this.fastestLap / 60);
|
||||
const seconds = Math.floor(this.fastestLap % 60);
|
||||
const milliseconds = Math.floor((this.fastestLap % 1) * 1000);
|
||||
return `${minutes}:${seconds.toString().padStart(2, '0')}.${milliseconds.toString().padStart(3, '0')}`;
|
||||
return DurationDisplay.formatSeconds(this.fastestLap);
|
||||
}
|
||||
|
||||
/** Required by ResultsTable */
|
||||
@@ -87,9 +89,4 @@ export class RaceResultViewModel extends ViewModel {
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Note: The generated DTO doesn't have id or raceId
|
||||
// These will need to be added when the OpenAPI spec is updated
|
||||
id: string = '';
|
||||
raceId: string = '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user