website refactor
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { RaceStewardingViewData, Protest, Penalty, Driver } from '@/lib/view-data/races/RaceStewardingViewData';
|
||||
|
||||
/**
|
||||
* Race Stewarding View Data Builder
|
||||
*
|
||||
* Transforms API DTO into ViewData for the race stewarding template.
|
||||
* Deterministic, side-effect free.
|
||||
*/
|
||||
export class RaceStewardingViewDataBuilder {
|
||||
static build(apiDto: any): RaceStewardingViewData {
|
||||
if (!apiDto) {
|
||||
return {
|
||||
race: null,
|
||||
league: null,
|
||||
pendingProtests: [],
|
||||
resolvedProtests: [],
|
||||
penalties: [],
|
||||
driverMap: {},
|
||||
pendingCount: 0,
|
||||
resolvedCount: 0,
|
||||
penaltiesCount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const race = apiDto.race ? {
|
||||
id: apiDto.race.id,
|
||||
track: apiDto.race.track,
|
||||
scheduledAt: apiDto.race.scheduledAt,
|
||||
} : null;
|
||||
|
||||
const league = apiDto.league ? {
|
||||
id: apiDto.league.id,
|
||||
} : null;
|
||||
|
||||
const pendingProtests: Protest[] = (apiDto.pendingProtests || []).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 resolvedProtests: Protest[] = (apiDto.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: Penalty[] = (apiDto.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: Record<string, Driver> = apiDto.driverMap || {};
|
||||
|
||||
return {
|
||||
race,
|
||||
league,
|
||||
pendingProtests,
|
||||
resolvedProtests,
|
||||
penalties,
|
||||
driverMap,
|
||||
pendingCount: apiDto.pendingCount || pendingProtests.length,
|
||||
resolvedCount: apiDto.resolvedCount || resolvedProtests.length,
|
||||
penaltiesCount: apiDto.penaltiesCount || penalties.length,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user