35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
'use client';
|
|
|
|
import type { DashboardOverviewDTO } from '@/lib/types/generated/DashboardOverviewDTO';
|
|
import type { HomeViewData } from '@/lib/view-data/HomeViewData';
|
|
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
|
|
import { DashboardDateDisplay } from '@/lib/display-objects/DashboardDateDisplay';
|
|
|
|
export class HomeViewDataBuilder {
|
|
/**
|
|
* Build HomeViewData from DashboardOverviewDTO
|
|
*
|
|
* @param apiDto - The API DTO
|
|
* @returns HomeViewData
|
|
*/
|
|
public static build(apiDto: DashboardOverviewDTO): HomeViewData {
|
|
return {
|
|
isAlpha: true,
|
|
upcomingRaces: (apiDto.upcomingRaces || []).map(race => ({
|
|
id: race.id,
|
|
track: race.track,
|
|
car: race.car,
|
|
formattedDate: DashboardDateDisplay.format(new Date(race.scheduledAt)).date,
|
|
})),
|
|
topLeagues: (apiDto.leagueStandingsSummaries || []).map(league => ({
|
|
id: league.leagueId,
|
|
name: league.leagueName,
|
|
description: '',
|
|
})),
|
|
teams: [],
|
|
};
|
|
}
|
|
}
|
|
|
|
HomeViewDataBuilder satisfies ViewDataBuilder<DashboardOverviewDTO, HomeViewData>;
|