This commit is contained in:
2025-12-11 21:06:25 +01:00
parent c49ea2598d
commit ec3ddc3a5c
227 changed files with 3496 additions and 2083 deletions

View File

@@ -1,59 +1,60 @@
import type {
IRaceProtestsPresenter,
RaceProtestViewModel,
RaceProtestsResultDTO,
RaceProtestsViewModel,
} from '@gridpilot/racing/application/presenters/IRaceProtestsPresenter';
import type { ProtestStatus, ProtestIncident } from '@gridpilot/racing/domain/entities/Protest';
export class RaceProtestsPresenter implements IRaceProtestsPresenter {
private viewModel: RaceProtestsViewModel | null = null;
present(
protests: Array<{
id: string;
raceId: string;
protestingDriverId: string;
accusedDriverId: string;
incident: ProtestIncident;
comment?: string;
proofVideoUrl?: string;
status: ProtestStatus;
reviewedBy?: string;
decisionNotes?: string;
filedAt: Date;
reviewedAt?: Date;
}>,
driverMap: Map<string, string>
): RaceProtestsViewModel {
const protestViewModels: RaceProtestViewModel[] = protests.map(protest => ({
id: protest.id,
raceId: protest.raceId,
protestingDriverId: protest.protestingDriverId,
protestingDriverName: driverMap.get(protest.protestingDriverId) || 'Unknown',
accusedDriverId: protest.accusedDriverId,
accusedDriverName: driverMap.get(protest.accusedDriverId) || 'Unknown',
incident: protest.incident,
comment: protest.comment,
proofVideoUrl: protest.proofVideoUrl,
status: protest.status,
reviewedBy: protest.reviewedBy,
reviewedByName: protest.reviewedBy ? driverMap.get(protest.reviewedBy) : undefined,
decisionNotes: protest.decisionNotes,
filedAt: protest.filedAt.toISOString(),
reviewedAt: protest.reviewedAt?.toISOString(),
}));
reset(): void {
this.viewModel = null;
}
present(dto: RaceProtestsResultDTO): void {
const { protests, driverMap } = dto;
const protestViewModels: RaceProtestViewModel[] = protests.map((protest) => {
const base: RaceProtestViewModel = {
id: protest.id,
raceId: protest.raceId,
protestingDriverId: protest.protestingDriverId,
protestingDriverName: driverMap.get(protest.protestingDriverId) || 'Unknown',
accusedDriverId: protest.accusedDriverId,
accusedDriverName: driverMap.get(protest.accusedDriverId) || 'Unknown',
incident: protest.incident,
filedAt: protest.filedAt.toISOString(),
status: protest.status,
};
const comment = protest.comment;
const proofVideoUrl = protest.proofVideoUrl;
const reviewedBy = protest.reviewedBy;
const reviewedByName =
protest.reviewedBy !== undefined
? driverMap.get(protest.reviewedBy) ?? 'Unknown'
: undefined;
const decisionNotes = protest.decisionNotes;
const reviewedAt = protest.reviewedAt?.toISOString();
return {
...base,
...(comment !== undefined ? { comment } : {}),
...(proofVideoUrl !== undefined ? { proofVideoUrl } : {}),
...(reviewedBy !== undefined ? { reviewedBy } : {}),
...(reviewedByName !== undefined ? { reviewedByName } : {}),
...(decisionNotes !== undefined ? { decisionNotes } : {}),
...(reviewedAt !== undefined ? { reviewedAt } : {}),
};
});
this.viewModel = {
protests: protestViewModels,
};
return this.viewModel;
}
getViewModel(): RaceProtestsViewModel {
if (!this.viewModel) {
throw new Error('Presenter has not been called yet');
}
getViewModel(): RaceProtestsViewModel | null {
return this.viewModel;
}
}