Files
gridpilot.gg/apps/website/lib/builders/view-data/LeaderboardsViewDataBuilder.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

48 lines
1.7 KiB
TypeScript

import { ViewData } from '@/lib/contracts/view-data/ViewData';
import type { DriverLeaderboardItemDTO } from '@/lib/types/generated/DriverLeaderboardItemDTO';
import type { GetTeamsLeaderboardOutputDTO } from '@/lib/types/generated/GetTeamsLeaderboardOutputDTO';
import type { LeaderboardsViewData } from '@/lib/view-data/LeaderboardsViewData';
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
export class LeaderboardsViewDataBuilder implements ViewDataBuilder<any, any> {
build(input: any): any {
return LeaderboardsViewDataBuilder.build(input);
}
static build(
static build(
apiDto: { drivers: { drivers: DriverLeaderboardItemDTO[] }; teams: GetTeamsLeaderboardOutputDTO }
): LeaderboardsViewData {
return {
drivers: apiDto.drivers.drivers.map(driver => ({
id: driver.id,
name: driver.name,
rating: driver.rating,
skillLevel: driver.skillLevel,
nationality: driver.nationality,
wins: driver.wins,
podiums: driver.podiums,
racesCompleted: driver.racesCompleted,
rank: driver.rank,
avatarUrl: driver.avatarUrl || '',
position: driver.rank,
})),
teams: apiDto.teams.topTeams.map((team, index) => ({
id: team.id,
name: team.name,
tag: team.tag,
memberCount: team.memberCount,
category: undefined,
totalWins: team.totalWins || 0,
totalRaces: team.totalRaces || 0,
logoUrl: team.logoUrl || '',
position: index + 1,
isRecruiting: team.isRecruiting,
performanceLevel: team.performanceLevel || 'N/A',
rating: team.rating || 0,
})),
};
}
}