39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import type { LeagueScheduleDTO } from '@/lib/types/generated/LeagueScheduleDTO';
|
|
import type { LeagueSeasonSummaryDTO } from '@/lib/types/generated/LeagueSeasonSummaryDTO';
|
|
import type { LeagueScheduleViewData, ScheduleRaceData } from '@/lib/view-data/LeagueScheduleViewData';
|
|
|
|
/**
|
|
* LeagueScheduleViewDataBuilder
|
|
*
|
|
* Transforms API DTOs into LeagueScheduleViewData for server-side rendering.
|
|
* Deterministic; side-effect free; no HTTP calls.
|
|
*/
|
|
export class LeagueScheduleViewDataBuilder {
|
|
static build(input: {
|
|
schedule: LeagueScheduleDTO;
|
|
seasons: LeagueSeasonSummaryDTO[];
|
|
leagueId: string;
|
|
}): LeagueScheduleViewData {
|
|
const { schedule, seasons, leagueId } = input;
|
|
|
|
// Transform races - using available fields from RaceDTO
|
|
const races: ScheduleRaceData[] = (schedule.races || []).map(race => ({
|
|
id: race.id,
|
|
name: race.name,
|
|
track: race.leagueName || 'Unknown Track',
|
|
car: 'Unknown Car',
|
|
scheduledAt: race.date,
|
|
status: 'scheduled',
|
|
}));
|
|
|
|
return {
|
|
leagueId,
|
|
races,
|
|
seasons: seasons.map(s => ({
|
|
seasonId: s.seasonId,
|
|
name: s.name,
|
|
status: s.status,
|
|
})),
|
|
};
|
|
}
|
|
} |