view data fixes
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
import { Driver, Penalty, Protest, RaceStewardingViewData } from '@/lib/view-data/RaceStewardingViewData';
|
||||
import type { LeagueAdminProtestsDTO } from '@/lib/types/generated/LeagueAdminProtestsDTO';
|
||||
import type { RaceStewardingViewData } from '@/lib/view-data/RaceStewardingViewData';
|
||||
|
||||
/**
|
||||
* Race Stewarding View Data Builder
|
||||
*
|
||||
* Transforms API DTO into ViewData for the race stewarding template.
|
||||
* Deterministic, side-effect free.
|
||||
*/
|
||||
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
|
||||
|
||||
export class RaceStewardingViewDataBuilder implements ViewDataBuilder<any, any> {
|
||||
@@ -13,19 +8,14 @@ export class RaceStewardingViewDataBuilder implements ViewDataBuilder<any, any>
|
||||
return RaceStewardingViewDataBuilder.build(input);
|
||||
}
|
||||
|
||||
static build(
|
||||
static build(apiDto: unknown): RaceStewardingViewData {
|
||||
static build(apiDto: LeagueAdminProtestsDTO): RaceStewardingViewData {
|
||||
if (!apiDto) {
|
||||
return {
|
||||
race: null,
|
||||
league: null,
|
||||
pendingProtests: [],
|
||||
resolvedProtests: [],
|
||||
protests: [],
|
||||
penalties: [],
|
||||
driverMap: {},
|
||||
pendingCount: 0,
|
||||
resolvedCount: 0,
|
||||
penaltiesCount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -34,15 +24,20 @@ export class RaceStewardingViewDataBuilder implements ViewDataBuilder<any, any>
|
||||
|
||||
const race = dto.race ? {
|
||||
id: dto.race.id,
|
||||
track: dto.race.track,
|
||||
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 pendingProtests: Protest[] = (dto.pendingProtests || []).map((p: any) => ({
|
||||
const protests = [
|
||||
...(dto.pendingProtests || []),
|
||||
...(dto.resolvedProtests || []),
|
||||
].map((p: any) => ({
|
||||
id: p.id,
|
||||
protestingDriverId: p.protestingDriverId,
|
||||
accusedDriverId: p.accusedDriverId,
|
||||
@@ -56,21 +51,7 @@ export class RaceStewardingViewDataBuilder implements ViewDataBuilder<any, any>
|
||||
decisionNotes: p.decisionNotes,
|
||||
}));
|
||||
|
||||
const resolvedProtests: Protest[] = (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: Penalty[] = (dto.penalties || []).map((p: any) => ({
|
||||
const penalties = (dto.penalties || []).map((p: any) => ({
|
||||
id: p.id,
|
||||
driverId: p.driverId,
|
||||
type: p.type,
|
||||
@@ -79,18 +60,14 @@ export class RaceStewardingViewDataBuilder implements ViewDataBuilder<any, any>
|
||||
notes: p.notes,
|
||||
}));
|
||||
|
||||
const driverMap: Record<string, Driver> = dto.driverMap || {};
|
||||
const driverMap = dto.driverMap || {};
|
||||
|
||||
return {
|
||||
race,
|
||||
league,
|
||||
pendingProtests,
|
||||
resolvedProtests,
|
||||
protests,
|
||||
penalties,
|
||||
driverMap,
|
||||
pendingCount: dto.pendingCount || pendingProtests.length,
|
||||
resolvedCount: dto.resolvedCount || resolvedProtests.length,
|
||||
penaltiesCount: dto.penaltiesCount || penalties.length,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user