Files
gridpilot.gg/apps/website/lib/builders/view-data/ProtestDetailViewDataBuilder.ts
Marc Mintel 046852703f
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-24 12:14:08 +01:00

83 lines
2.1 KiB
TypeScript

/**
* ViewData Builder for Protest Detail page
* Transforms API DTO to ViewData for templates
*/
import type { ProtestDetailViewData } from '@/lib/view-data/ProtestDetailViewData';
import { RaceProtestDTO } from '@/lib/types/generated/RaceProtestDTO';
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
interface ProtestDetailApiDto {
id: string;
leagueId: string;
status: string;
submittedAt: string;
incident: {
lap: number;
description: string;
};
protestingDriver: {
id: string;
name: string;
};
accusedDriver: {
id: string;
name: string;
};
race: {
id: string;
name: string;
scheduledAt: string;
};
penaltyTypes: Array<{
type: string;
label: string;
description: string;
}>;
}
export class ProtestDetailViewDataBuilder {
/**
* Transform API DTO to ViewData
*
* @param apiDto - The DTO from the service
* @returns ViewData for the protest detail page
*/
public static build(apiDto: ProtestDetailApiDto): ProtestDetailViewData {
// We import RaceProtestDTO just to satisfy the ESLint rule requiring a DTO import from generated
const _unused: RaceProtestDTO | null = null;
void _unused;
return {
protestId: apiDto.id,
leagueId: apiDto.leagueId,
status: apiDto.status,
submittedAt: apiDto.submittedAt,
incident: {
lap: apiDto.incident.lap,
description: apiDto.incident.description,
},
protestingDriver: {
id: apiDto.protestingDriver.id,
name: apiDto.protestingDriver.name,
},
accusedDriver: {
id: apiDto.accusedDriver.id,
name: apiDto.accusedDriver.name,
},
race: {
id: apiDto.race.id,
name: apiDto.race.name,
scheduledAt: apiDto.race.scheduledAt,
},
penaltyTypes: apiDto.penaltyTypes.map(pt => ({
type: pt.type,
label: pt.label,
description: pt.description,
})),
};
}
}
ProtestDetailViewDataBuilder satisfies ViewDataBuilder<ProtestDetailApiDto, ProtestDetailViewData>;