view data fixes
This commit is contained in:
@@ -1,24 +1,15 @@
|
||||
'use client';
|
||||
|
||||
import type { LeagueScheduleViewData } from '@/lib/view-data/LeagueScheduleViewData';
|
||||
import type { LeagueScheduleDTO } from '@/lib/types/generated/LeagueScheduleDTO';
|
||||
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
export class LeagueScheduleViewDataBuilder {
|
||||
public static build(apiDto: LeagueScheduleDTO, currentDriverId?: string, isAdmin: boolean = false): LeagueScheduleViewData {
|
||||
const now = new Date();
|
||||
|
||||
return {
|
||||
leagueId: (apiDto as any).leagueId || '',
|
||||
leagueId: apiDto.leagueId || '',
|
||||
races: apiDto.races.map((race) => {
|
||||
const scheduledAt = new Date(race.date);
|
||||
const isPast = scheduledAt.getTime() <= now.getTime();
|
||||
@@ -33,7 +24,7 @@ export class LeagueScheduleViewDataBuilder implements ViewDataBuilder<LeagueSche
|
||||
sessionType: race.sessionType || 'race',
|
||||
isPast,
|
||||
isUpcoming,
|
||||
status: (race.status as any) || (isPast ? 'completed' : 'scheduled'),
|
||||
status: race.status || (isPast ? 'completed' : 'scheduled'),
|
||||
// Registration info (would come from API in real implementation)
|
||||
isUserRegistered: false,
|
||||
canRegister: isUpcoming,
|
||||
@@ -46,4 +37,6 @@ export class LeagueScheduleViewDataBuilder implements ViewDataBuilder<LeagueSche
|
||||
isAdmin,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LeagueScheduleViewDataBuilder satisfies ViewDataBuilder<LeagueScheduleDTO, LeagueScheduleViewData>;
|
||||
Reference in New Issue
Block a user