view models

This commit is contained in:
2025-12-18 00:08:47 +01:00
parent f7a56a92ce
commit 7c449af311
56 changed files with 2594 additions and 206 deletions

View File

@@ -1,19 +1,20 @@
import { LeagueStandingsDto, StandingEntryDto, DriverDto, LeagueMembership } from '../dtos';
import { LeagueStandingDTO } from '../types/generated/LeagueStandingDTO';
import { StandingEntryViewModel } from './StandingEntryViewModel';
export class LeagueStandingsViewModel implements LeagueStandingsDto {
export class LeagueStandingsViewModel {
standings: StandingEntryViewModel[];
drivers: DriverDto[];
memberships: LeagueMembership[];
constructor(dto: LeagueStandingsDto & { standings: StandingEntryDto[] }, currentUserId: string, previousStandings?: StandingEntryDto[]) {
constructor(dto: { standings: LeagueStandingDTO[] }, currentUserId: string, previousStandings?: LeagueStandingDTO[]) {
const leaderPoints = dto.standings[0]?.points || 0;
this.standings = dto.standings.map((entry, index) => {
const nextPoints = dto.standings[index + 1]?.points || entry.points;
const previousPosition = previousStandings?.find(p => p.driverId === entry.driverId)?.position;
return new StandingEntryViewModel(entry, leaderPoints, nextPoints, currentUserId, previousPosition);
});
this.drivers = dto.drivers;
this.memberships = dto.memberships;
}
// Note: The generated DTO doesn't have these fields
// These will need to be added when the OpenAPI spec is updated
drivers: any[] = [];
memberships: any[] = [];
}