60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import type {
|
|
IRacePenaltiesPresenter,
|
|
RacePenaltyViewModel,
|
|
RacePenaltiesViewModel,
|
|
} from '@gridpilot/racing/application/presenters/IRacePenaltiesPresenter';
|
|
import type { PenaltyType, PenaltyStatus } from '@gridpilot/racing/domain/entities/Penalty';
|
|
|
|
export class RacePenaltiesPresenter implements IRacePenaltiesPresenter {
|
|
private viewModel: RacePenaltiesViewModel | null = null;
|
|
|
|
present(
|
|
penalties: Array<{
|
|
id: string;
|
|
raceId: string;
|
|
driverId: string;
|
|
type: PenaltyType;
|
|
value?: number;
|
|
reason: string;
|
|
protestId?: string;
|
|
issuedBy: string;
|
|
status: PenaltyStatus;
|
|
issuedAt: Date;
|
|
appliedAt?: Date;
|
|
notes?: string;
|
|
getDescription(): string;
|
|
}>,
|
|
driverMap: Map<string, string>
|
|
): RacePenaltiesViewModel {
|
|
const penaltyViewModels: RacePenaltyViewModel[] = penalties.map(penalty => ({
|
|
id: penalty.id,
|
|
raceId: penalty.raceId,
|
|
driverId: penalty.driverId,
|
|
driverName: driverMap.get(penalty.driverId) || 'Unknown',
|
|
type: penalty.type,
|
|
value: penalty.value,
|
|
reason: penalty.reason,
|
|
protestId: penalty.protestId,
|
|
issuedBy: penalty.issuedBy,
|
|
issuedByName: driverMap.get(penalty.issuedBy) || 'Unknown',
|
|
status: penalty.status,
|
|
description: penalty.getDescription(),
|
|
issuedAt: penalty.issuedAt.toISOString(),
|
|
appliedAt: penalty.appliedAt?.toISOString(),
|
|
notes: penalty.notes,
|
|
}));
|
|
|
|
this.viewModel = {
|
|
penalties: penaltyViewModels,
|
|
};
|
|
|
|
return this.viewModel;
|
|
}
|
|
|
|
getViewModel(): RacePenaltiesViewModel {
|
|
if (!this.viewModel) {
|
|
throw new Error('Presenter has not been called yet');
|
|
}
|
|
return this.viewModel;
|
|
}
|
|
} |