83 lines
2.1 KiB
TypeScript
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>;
|