view data fixes
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-24 12:14:08 +01:00
parent dde77e717a
commit 046852703f
94 changed files with 1333 additions and 4885 deletions

View File

@@ -1,27 +1,82 @@
import type { RaceProtestDTO } from '@/lib/types/generated/RaceProtestDTO';
import type { ProtestDetailViewData } from '@/lib/view-data/ProtestDetailViewData';
/**
* 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";
export class ProtestDetailViewDataBuilder implements ViewDataBuilder<any, any> {
build(input: any): any {
return ProtestDetailViewDataBuilder.build(input);
}
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;
static build(apiDto: RaceProtestDTO): ProtestDetailViewData {
return {
protestId: apiDto.id,
leagueId: (apiDto as any).leagueId || '',
leagueId: apiDto.leagueId,
status: apiDto.status,
submittedAt: (apiDto as any).submittedAt || apiDto.filedAt,
submittedAt: apiDto.submittedAt,
incident: {
lap: (apiDto.incident as any)?.lap || 0,
description: (apiDto.incident as any)?.description || '',
lap: apiDto.incident.lap,
description: apiDto.incident.description,
},
protestingDriver: (apiDto as any).protestingDriver || { id: apiDto.protestingDriverId, name: 'Unknown' },
accusedDriver: (apiDto as any).accusedDriver || { id: apiDto.accusedDriverId, name: 'Unknown' },
race: (apiDto as any).race || { id: '', name: '', scheduledAt: '' },
penaltyTypes: (apiDto as any).penaltyTypes || [],
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>;