refactor page to use services

This commit is contained in:
2025-12-18 15:58:09 +01:00
parent f54fa5de5b
commit fc386db06a
45 changed files with 2254 additions and 1292 deletions

View File

@@ -0,0 +1,58 @@
import { ApplyPenaltyCommandDTO } from '../../types';
export type PenaltyType = 'time_penalty' | 'grid_penalty' | 'points_deduction' | 'disqualification' | 'warning' | 'license_points';
export interface ProtestDecisionData {
decision: 'uphold' | 'dismiss' | null;
penaltyType: PenaltyType;
penaltyValue: number;
stewardNotes: string;
}
export class ProtestDecisionCommandModel {
decision: 'uphold' | 'dismiss' | null = null;
penaltyType: PenaltyType = 'time_penalty';
penaltyValue: number = 5;
stewardNotes: string = '';
constructor(initial: Partial<ProtestDecisionData> = {}) {
this.decision = initial.decision ?? null;
this.penaltyType = initial.penaltyType ?? 'time_penalty';
this.penaltyValue = initial.penaltyValue ?? 5;
this.stewardNotes = initial.stewardNotes ?? '';
}
get isValid(): boolean {
return this.decision !== null && this.stewardNotes.trim().length > 0;
}
get canSubmit(): boolean {
return this.isValid;
}
reset(): void {
this.decision = null;
this.penaltyType = 'time_penalty';
this.penaltyValue = 5;
this.stewardNotes = '';
}
toApplyPenaltyCommand(raceId: string, driverId: string, stewardId: string, protestId: string): ApplyPenaltyCommandDTO {
return {
raceId,
driverId,
stewardId,
type: this.penaltyType,
value: this.getPenaltyValue(),
reason: 'Protest upheld', // TODO: Make this configurable
protestId,
notes: this.stewardNotes,
};
}
private getPenaltyValue(): number {
// Some penalties don't require a value
const penaltiesWithoutValue: PenaltyType[] = ['disqualification', 'warning'];
return penaltiesWithoutValue.includes(this.penaltyType) ? 0 : this.penaltyValue;
}
}