Files
gridpilot.gg/apps/website/lib/builders/view-data/LeaguesViewDataBuilder.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.9 KiB
TypeScript

import type { AllLeaguesWithCapacityAndScoringDTO } from '@/lib/types/generated/AllLeaguesWithCapacityAndScoringDTO';
import type { LeaguesViewData } from '@/lib/view-data/LeaguesViewData';
/**
* LeaguesViewDataBuilder
*
* Transforms AllLeaguesWithCapacityAndScoringDTO (API DTO) into LeaguesViewData for server-side rendering.
* Deterministic; side-effect free; no HTTP calls.
*/
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
export class LeaguesViewDataBuilder implements ViewDataBuilder<any, any> {
build(input: any): any {
return LeaguesViewDataBuilder.build(input);
}
static build(
static build(apiDto: AllLeaguesWithCapacityAndScoringDTO): LeaguesViewData {
return {
leagues: apiDto.leagues.map((league) => ({
id: league.id,
name: league.name,
description: league.description || null,
logoUrl: league.logoUrl || null,
ownerId: league.ownerId,
createdAt: league.createdAt,
maxDrivers: league.settings.maxDrivers,
usedDriverSlots: league.usedSlots,
activeDriversCount: (league as any).activeDriversCount,
nextRaceAt: (league as any).nextRaceAt,
maxTeams: undefined, // Not provided in DTO
usedTeamSlots: undefined, // Not provided in DTO
structureSummary: league.settings.qualifyingFormat || '',
timingSummary: league.timingSummary || '',
category: league.category || null,
scoring: league.scoring ? {
gameId: league.scoring.gameId,
gameName: league.scoring.gameName,
primaryChampionshipType: league.scoring.primaryChampionshipType,
scoringPresetId: league.scoring.scoringPresetId,
scoringPresetName: league.scoring.scoringPresetName,
dropPolicySummary: league.scoring.dropPolicySummary,
scoringPatternSummary: league.scoring.scoringPatternSummary,
} : undefined,
})),
};
}
}