streamline components

This commit is contained in:
2026-01-07 14:16:02 +01:00
parent 94d60527f4
commit 3b3971e653
16 changed files with 685 additions and 667 deletions

View File

@@ -7,6 +7,25 @@ import type { ApplyPenaltyCommandDTO } from '../../types/generated/ApplyPenaltyC
import type { RequestProtestDefenseCommandDTO } from '../../types/generated/RequestProtestDefenseCommandDTO';
import type { ReviewProtestCommandDTO } from '../../types/generated/ReviewProtestCommandDTO';
import type { DriverDTO } from '../../types/generated/DriverDTO';
import type { FileProtestCommandDTO } from '../../types/generated/FileProtestCommandDTO';
import type { ProtestIncidentDTO } from '../../types/generated/ProtestIncidentDTO';
export interface ProtestParticipant {
id: string;
name: string;
}
export interface FileProtestInput {
raceId: string;
leagueId?: string;
protestingDriverId: string;
accusedDriverId: string;
lap: string;
timeInRace?: string;
description: string;
comment?: string;
proofVideoUrl?: string;
}
/**
* Protest Service
@@ -104,4 +123,44 @@ export class ProtestService {
const dto = await this.apiClient.getRaceProtests(raceId);
return dto.protests;
}
/**
* Validate file protest input
* @throws Error with descriptive message if validation fails
*/
validateFileProtestInput(input: FileProtestInput): void {
if (!input.accusedDriverId) {
throw new Error('Please select the driver you are protesting against.');
}
if (!input.lap || parseInt(input.lap, 10) < 0) {
throw new Error('Please enter a valid lap number.');
}
if (!input.description.trim()) {
throw new Error('Please describe what happened.');
}
}
/**
* Construct file protest command from input
*/
constructFileProtestCommand(input: FileProtestInput): FileProtestCommandDTO {
this.validateFileProtestInput(input);
const incident: ProtestIncidentDTO = {
lap: parseInt(input.lap, 10),
description: input.description.trim(),
...(input.timeInRace ? { timeInRace: parseInt(input.timeInRace, 10) } : {}),
};
const command: FileProtestCommandDTO = {
raceId: input.raceId,
protestingDriverId: input.protestingDriverId,
accusedDriverId: input.accusedDriverId,
incident,
...(input.comment?.trim() ? { comment: input.comment.trim() } : {}),
...(input.proofVideoUrl?.trim() ? { proofVideoUrl: input.proofVideoUrl.trim() } : {}),
};
return command;
}
}