Files
gridpilot.gg/apps/api/src/modules/league/presenters/LeagueStandingsPresenter.ts
2025-12-16 11:52:26 +01:00

27 lines
921 B
TypeScript

import { ILeagueStandingsPresenter, LeagueStandingsResultDTO, LeagueStandingsViewModel } from '@core/racing/application/presenters/ILeagueStandingsPresenter';
export class LeagueStandingsPresenter implements ILeagueStandingsPresenter {
private result: LeagueStandingsViewModel | null = null;
reset() {
this.result = null;
}
present(dto: LeagueStandingsResultDTO) {
const driverMap = new Map(dto.drivers.map(d => [d.id, { id: d.id, name: d.name }]));
const standings = dto.standings
.sort((a, b) => a.position - b.position)
.map(standing => ({
driverId: standing.driverId,
driver: driverMap.get(standing.driverId)!,
points: standing.points,
rank: standing.position,
}));
this.result = { standings };
}
getViewModel(): LeagueStandingsViewModel {
if (!this.result) throw new Error('Presenter not presented');
return this.result;
}
}