49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import type { LeagueScheduleViewData } from '@/lib/view-data/LeagueScheduleViewData';
|
|
import type { LeagueScheduleDTO } from '@/lib/types/generated/LeagueScheduleDTO';
|
|
|
|
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
|
|
|
|
export interface LeagueScheduleInputDTO {
|
|
apiDto: LeagueScheduleDTO;
|
|
currentDriverId?: string;
|
|
isAdmin?: boolean;
|
|
}
|
|
|
|
export class LeagueScheduleViewDataBuilder implements ViewDataBuilder<LeagueScheduleInputDTO, LeagueScheduleViewData> {
|
|
build(input: LeagueScheduleInputDTO): LeagueScheduleViewData {
|
|
return LeagueScheduleViewDataBuilder.build(input.apiDto, input.currentDriverId, input.isAdmin);
|
|
}
|
|
|
|
public static build(apiDto: LeagueScheduleDTO, currentDriverId?: string, isAdmin: boolean = false): LeagueScheduleViewData {
|
|
const now = new Date();
|
|
|
|
return {
|
|
leagueId: (apiDto as any).leagueId || '',
|
|
races: apiDto.races.map((race) => {
|
|
const scheduledAt = new Date(race.date);
|
|
const isPast = scheduledAt.getTime() <= now.getTime();
|
|
const isUpcoming = !isPast;
|
|
|
|
return {
|
|
id: race.id,
|
|
name: race.name,
|
|
scheduledAt: race.date,
|
|
track: race.track || '',
|
|
car: race.car || '',
|
|
sessionType: race.sessionType || 'race',
|
|
isPast,
|
|
isUpcoming,
|
|
status: (race.status as any) || (isPast ? 'completed' : 'scheduled'),
|
|
// Registration info (would come from API in real implementation)
|
|
isUserRegistered: false,
|
|
canRegister: isUpcoming,
|
|
// Admin info
|
|
canEdit: isAdmin,
|
|
canReschedule: isAdmin,
|
|
};
|
|
}),
|
|
currentDriverId,
|
|
isAdmin,
|
|
};
|
|
}
|
|
} |