move static data
This commit is contained in:
@@ -1,19 +1,15 @@
|
||||
import { ApplyPenaltyCommandDTO } from '../../types/generated/ApplyPenaltyCommandDTO';
|
||||
|
||||
export type PenaltyType = 'time_penalty' | 'grid_penalty' | 'points_deduction' | 'disqualification' | 'warning' | 'license_points';
|
||||
|
||||
export interface ProtestDecisionData {
|
||||
decision: 'uphold' | 'dismiss' | null;
|
||||
penaltyType: PenaltyType;
|
||||
penaltyValue: number;
|
||||
penaltyType: string;
|
||||
penaltyValue?: number;
|
||||
stewardNotes: string;
|
||||
}
|
||||
|
||||
const DEFAULT_PROTEST_REASON = 'Protest upheld';
|
||||
|
||||
export class ProtestDecisionCommandModel {
|
||||
decision: 'uphold' | 'dismiss' | null = null;
|
||||
penaltyType: PenaltyType = 'time_penalty';
|
||||
penaltyType: string = 'time_penalty';
|
||||
penaltyValue: number = 5;
|
||||
stewardNotes: string = '';
|
||||
|
||||
@@ -39,27 +35,37 @@ export class ProtestDecisionCommandModel {
|
||||
this.stewardNotes = '';
|
||||
}
|
||||
|
||||
toApplyPenaltyCommand(raceId: string, driverId: string, stewardId: string, protestId: string): ApplyPenaltyCommandDTO {
|
||||
const reason = this.decision === 'uphold'
|
||||
? DEFAULT_PROTEST_REASON
|
||||
: 'Protest dismissed';
|
||||
toApplyPenaltyCommand(
|
||||
raceId: string,
|
||||
driverId: string,
|
||||
stewardId: string,
|
||||
protestId: string,
|
||||
options?: {
|
||||
requiresValue?: boolean;
|
||||
defaultUpheldReason?: string;
|
||||
defaultDismissedReason?: string;
|
||||
},
|
||||
): ApplyPenaltyCommandDTO {
|
||||
const reason =
|
||||
this.decision === 'uphold'
|
||||
? (options?.defaultUpheldReason ?? 'Protest upheld')
|
||||
: (options?.defaultDismissedReason ?? 'Protest dismissed');
|
||||
|
||||
return {
|
||||
const base: ApplyPenaltyCommandDTO = {
|
||||
raceId,
|
||||
driverId,
|
||||
stewardId,
|
||||
enum: this.penaltyType, // Use penaltyType as enum
|
||||
enum: this.penaltyType,
|
||||
type: this.penaltyType,
|
||||
value: this.getPenaltyValue(),
|
||||
reason,
|
||||
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;
|
||||
if (options?.requiresValue) {
|
||||
return { ...base, value: this.penaltyValue };
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user