Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
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
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
'use client';
|
|
|
|
import type { AllLeaguesWithCapacityAndScoringDTO } from '@/lib/types/generated/AllLeaguesWithCapacityAndScoringDTO';
|
|
import type { LeaguesViewData } from '@/lib/view-data/LeaguesViewData';
|
|
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
|
|
|
|
export class LeaguesViewDataBuilder {
|
|
public 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 || 0,
|
|
usedDriverSlots: league.usedSlots,
|
|
activeDriversCount: undefined,
|
|
nextRaceAt: undefined,
|
|
maxTeams: undefined,
|
|
usedTeamSlots: undefined,
|
|
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,
|
|
})),
|
|
};
|
|
}
|
|
}
|
|
|
|
LeaguesViewDataBuilder satisfies ViewDataBuilder<AllLeaguesWithCapacityAndScoringDTO, LeaguesViewData>; |