39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { NumberFormatter } from '@/lib/formatters/NumberFormatter';
|
|
import { RatingFormatter } from '@/lib/formatters/RatingFormatter';
|
|
import type { GetAllTeamsOutputDTO } from '@/lib/types/generated/GetAllTeamsOutputDTO';
|
|
import type { TeamListItemDTO } from '@/lib/types/generated/TeamListItemDTO';
|
|
import type { TeamSummaryData, TeamsViewData } from '@/lib/view-data/TeamsViewData';
|
|
|
|
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
|
|
|
|
export class TeamsViewDataBuilder {
|
|
/**
|
|
* Transform API DTO to ViewData
|
|
*
|
|
* @param apiDto - The DTO from the service
|
|
* @returns ViewData for the teams page
|
|
*/
|
|
public static build(apiDto: GetAllTeamsOutputDTO): TeamsViewData {
|
|
const teams: TeamSummaryData[] = (apiDto.teams || []).map((team: TeamListItemDTO): TeamSummaryData => ({
|
|
teamId: team.id,
|
|
teamName: team.name,
|
|
memberCount: team.memberCount,
|
|
logoUrl: team.logoUrl || '',
|
|
ratingLabel: RatingFormatter.format(team.rating),
|
|
ratingValue: team.rating || 0,
|
|
winsLabel: NumberFormatter.format(team.totalWins || 0),
|
|
racesLabel: NumberFormatter.format(team.totalRaces || 0),
|
|
region: team.region || '',
|
|
isRecruiting: team.isRecruiting,
|
|
category: team.category || '',
|
|
performanceLevel: team.performanceLevel || '',
|
|
description: team.description || '',
|
|
countryCode: team.region || '', // Assuming region contains country code for now
|
|
}));
|
|
|
|
return { teams };
|
|
}
|
|
}
|
|
|
|
TeamsViewDataBuilder satisfies ViewDataBuilder<GetAllTeamsOutputDTO, TeamsViewData>;
|