73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import type { LeagueAdminProtestsDTO } from '@/lib/types/generated/LeagueAdminProtestsDTO';
|
|
import type { RaceStewardingViewData } from '@/lib/view-data/RaceStewardingViewData';
|
|
|
|
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
|
|
|
|
export class RaceStewardingViewDataBuilder implements ViewDataBuilder<any, any> {
|
|
build(input: any): any {
|
|
return RaceStewardingViewDataBuilder.build(input);
|
|
}
|
|
|
|
static build(apiDto: LeagueAdminProtestsDTO): RaceStewardingViewData {
|
|
if (!apiDto) {
|
|
return {
|
|
race: null,
|
|
league: null,
|
|
protests: [],
|
|
penalties: [],
|
|
driverMap: {},
|
|
};
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const dto = apiDto as any;
|
|
|
|
const race = dto.race ? {
|
|
id: dto.race.id,
|
|
track: dto.race.track || '',
|
|
scheduledAt: dto.race.scheduledAt,
|
|
status: dto.race.status || 'scheduled',
|
|
} : null;
|
|
|
|
const league = dto.league ? {
|
|
id: dto.league.id,
|
|
name: dto.league.name || '',
|
|
} : null;
|
|
|
|
const protests = [
|
|
...(dto.pendingProtests || []),
|
|
...(dto.resolvedProtests || []),
|
|
].map((p: any) => ({
|
|
id: p.id,
|
|
protestingDriverId: p.protestingDriverId,
|
|
accusedDriverId: p.accusedDriverId,
|
|
incident: {
|
|
lap: p.incident?.lap || 0,
|
|
description: p.incident?.description || '',
|
|
},
|
|
filedAt: p.filedAt,
|
|
status: p.status,
|
|
proofVideoUrl: p.proofVideoUrl,
|
|
decisionNotes: p.decisionNotes,
|
|
}));
|
|
|
|
const penalties = (dto.penalties || []).map((p: any) => ({
|
|
id: p.id,
|
|
driverId: p.driverId,
|
|
type: p.type,
|
|
value: p.value || 0,
|
|
reason: p.reason || '',
|
|
notes: p.notes,
|
|
}));
|
|
|
|
const driverMap = dto.driverMap || {};
|
|
|
|
return {
|
|
race,
|
|
league,
|
|
protests,
|
|
penalties,
|
|
driverMap,
|
|
};
|
|
}
|
|
} |