view data fixes

This commit is contained in:
2026-01-23 15:30:23 +01:00
parent e22033be38
commit f8099f04bc
213 changed files with 3466 additions and 3003 deletions

View File

@@ -1,62 +1,48 @@
import { LeagueStandingDTO } from '@/lib/types/generated/LeagueStandingDTO';
import { ViewModel } from "../contracts/view-models/ViewModel";
import { FinishDisplay } from "../display-objects/FinishDisplay";
import type { StandingEntryViewData } from "../view-data/StandingEntryViewData";
export class StandingEntryViewModel extends ViewModel {
driverId: string;
position: number;
points: number;
wins: number;
podiums: number;
races: number;
private readonly data: StandingEntryViewData;
private leaderPoints: number;
private nextPoints: number;
private currentUserId: string;
private previousPosition?: number;
constructor(dto: LeagueStandingDTO, leaderPoints: number, nextPoints: number, currentUserId: string, previousPosition?: number) {
this.driverId = dto.driverId;
this.position = dto.position;
this.points = dto.points;
this.wins = dto.wins ?? 0;
this.podiums = dto.podiums ?? 0;
this.races = dto.races ?? 0;
this.leaderPoints = leaderPoints;
this.nextPoints = nextPoints;
this.currentUserId = currentUserId;
this.previousPosition = previousPosition;
constructor(data: StandingEntryViewData) {
super();
this.data = data;
}
get driverId(): string { return this.data.driverId; }
get position(): number { return this.data.position; }
get points(): number { return this.data.points; }
get wins(): number { return this.data.wins; }
get podiums(): number { return this.data.podiums; }
get races(): number { return this.data.races; }
get driver(): any { return this.data.driver; }
/** UI-specific: Badge for position display */
get positionBadge(): string {
return this.position.toString();
return FinishDisplay.format(this.position);
}
// Note: The generated DTO is incomplete
// These fields will need to be added when the OpenAPI spec is updated
driver?: any;
/** UI-specific: Points difference to leader */
get pointsGapToLeader(): number {
return this.points - this.leaderPoints;
return this.points - this.data.leaderPoints;
}
/** UI-specific: Points difference to next position */
get pointsGapToNext(): number {
return this.points - this.nextPoints;
return this.points - this.data.nextPoints;
}
/** UI-specific: Whether this entry is the current user */
get isCurrentUser(): boolean {
return this.driverId === this.currentUserId;
return this.driverId === this.data.currentUserId;
}
/** UI-specific: Trend compared to previous */
get trend(): 'up' | 'down' | 'same' {
if (!this.previousPosition) return 'same';
if (this.position < this.previousPosition) return 'up';
if (this.position > this.previousPosition) return 'down';
if (!this.data.previousPosition) return 'same';
if (this.position < this.data.previousPosition) return 'up';
if (this.position > this.data.previousPosition) return 'down';
return 'same';
}