45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
/**
|
|
* Team Rankings View Data Builder
|
|
*
|
|
* Transforms API DTO to ViewData for templates.
|
|
*/
|
|
|
|
import type { GetTeamsLeaderboardOutputDTO } from '@/lib/types/generated/GetTeamsLeaderboardOutputDTO';
|
|
import type { TeamRankingsViewData } from '@/lib/view-data/TeamRankingsViewData';
|
|
import type { LeaderboardTeamItem } from '@/lib/view-data/LeaderboardTeamItem';
|
|
|
|
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
|
|
|
|
export class TeamRankingsViewDataBuilder {
|
|
/**
|
|
* Transform API DTO to ViewData
|
|
*
|
|
* @param apiDto - The DTO from the service
|
|
* @returns ViewData for the team rankings page
|
|
*/
|
|
public static build(apiDto: GetTeamsLeaderboardOutputDTO): TeamRankingsViewData {
|
|
const allTeams: LeaderboardTeamItem[] = (apiDto.teams || []).map((t, index) => ({
|
|
id: t.id,
|
|
name: t.name,
|
|
tag: t.tag,
|
|
memberCount: t.memberCount,
|
|
category: (t as unknown as { specialization: string }).specialization, // Mapping specialization to category as per LeaderboardTeamItem
|
|
totalWins: t.totalWins ?? 0,
|
|
totalRaces: t.totalRaces ?? 0,
|
|
logoUrl: t.logoUrl || '',
|
|
position: index + 1,
|
|
isRecruiting: t.isRecruiting,
|
|
performanceLevel: t.performanceLevel || 'N/A',
|
|
rating: t.rating ?? 0,
|
|
}));
|
|
|
|
return {
|
|
teams: allTeams,
|
|
podium: allTeams.slice(0, 3),
|
|
recruitingCount: apiDto.recruitingCount || 0,
|
|
};
|
|
}
|
|
}
|
|
|
|
TeamRankingsViewDataBuilder satisfies ViewDataBuilder<GetTeamsLeaderboardOutputDTO, TeamRankingsViewData>;
|