This commit is contained in:
2025-12-11 21:06:25 +01:00
parent c49ea2598d
commit ec3ddc3a5c
227 changed files with 3496 additions and 2083 deletions

View File

@@ -1,38 +1,44 @@
import type { Standing } from '@gridpilot/racing/domain/entities/Standing';
import type {
ILeagueStandingsPresenter,
StandingItemViewModel,
LeagueStandingsResultDTO,
LeagueStandingsViewModel,
StandingItemViewModel,
} from '@gridpilot/racing/application/presenters/ILeagueStandingsPresenter';
export class LeagueStandingsPresenter implements ILeagueStandingsPresenter {
private viewModel: LeagueStandingsViewModel | null = null;
present(standings: Standing[]): LeagueStandingsViewModel {
const standingItems: StandingItemViewModel[] = standings.map((standing) => ({
id: standing.id,
leagueId: standing.leagueId,
seasonId: standing.seasonId,
driverId: standing.driverId,
position: standing.position,
points: standing.points,
wins: standing.wins,
podiums: standing.podiums,
racesCompleted: standing.racesCompleted,
}));
this.viewModel = {
leagueId: standings[0]?.leagueId ?? '',
standings: standingItems,
};
return this.viewModel;
reset(): void {
this.viewModel = null;
}
getViewModel(): LeagueStandingsViewModel {
if (!this.viewModel) {
throw new Error('Presenter has not been called yet');
}
present(dto: LeagueStandingsResultDTO): void {
const standingItems: StandingItemViewModel[] = dto.standings.map((standing) => {
const raw = standing as unknown as {
seasonId?: string;
podiums?: number;
};
return {
id: standing.id,
leagueId: standing.leagueId,
seasonId: raw.seasonId ?? '',
driverId: standing.driverId,
position: standing.position,
points: standing.points,
wins: standing.wins,
podiums: raw.podiums ?? 0,
racesCompleted: standing.racesCompleted,
};
});
this.viewModel = {
leagueId: dto.standings[0]?.leagueId ?? '',
standings: standingItems,
};
}
getViewModel(): LeagueStandingsViewModel | null {
return this.viewModel;
}
}