Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
44 lines
1.8 KiB
TypeScript
44 lines
1.8 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.
|
|
*/
|
|
export class LeaguesViewDataBuilder {
|
|
static build(apiDto: AllLeaguesWithCapacityAndScoringDTO): LeaguesViewData {
|
|
if (!apiDto || !Array.isArray(apiDto.leagues)) {
|
|
return { leagues: [] };
|
|
}
|
|
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,
|
|
})),
|
|
};
|
|
}
|
|
} |