view data fixes
This commit is contained in:
@@ -1,22 +1,44 @@
|
||||
/**
|
||||
* 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 implements ViewDataBuilder<any, any> {
|
||||
build(input: any): any {
|
||||
return TeamRankingsViewDataBuilder.build(input);
|
||||
}
|
||||
|
||||
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 = apiDto.teams.map(t => ({
|
||||
...t,
|
||||
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,
|
||||
recruitingCount: apiDto.recruitingCount || 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
TeamRankingsViewDataBuilder satisfies ViewDataBuilder<GetTeamsLeaderboardOutputDTO, TeamRankingsViewData>;
|
||||
|
||||
Reference in New Issue
Block a user