move static data
This commit is contained in:
@@ -11,7 +11,7 @@ import { PenaltyId } from './PenaltyId';
|
||||
import { LeagueId } from '../LeagueId';
|
||||
import { RaceId } from '../RaceId';
|
||||
import { DriverId } from '../DriverId';
|
||||
import { PenaltyType } from './PenaltyType';
|
||||
import { PenaltyType, type PenaltyTypeValue } from './PenaltyType';
|
||||
import { PenaltyValue } from './PenaltyValue';
|
||||
import { PenaltyReason } from './PenaltyReason';
|
||||
import { ProtestId } from '../ProtestId';
|
||||
@@ -47,6 +47,19 @@ export interface PenaltyProps {
|
||||
notes?: PenaltyNotes;
|
||||
}
|
||||
|
||||
export const PENALTY_TYPES_REQUIRING_VALUE: PenaltyTypeValue[] = [
|
||||
'time_penalty',
|
||||
'grid_penalty',
|
||||
'points_deduction',
|
||||
'license_points',
|
||||
'fine',
|
||||
'race_ban',
|
||||
];
|
||||
|
||||
export function penaltyTypeRequiresValue(type: PenaltyTypeValue): boolean {
|
||||
return PENALTY_TYPES_REQUIRING_VALUE.includes(type);
|
||||
}
|
||||
|
||||
export class Penalty implements IEntity<string> {
|
||||
private constructor(private readonly props: PenaltyProps) {}
|
||||
|
||||
@@ -73,10 +86,12 @@ export class Penalty implements IEntity<string> {
|
||||
if (!props.reason?.trim()) throw new RacingDomainValidationError('Penalty reason is required');
|
||||
if (!props.issuedBy) throw new RacingDomainValidationError('Penalty must be issued by a steward');
|
||||
|
||||
const penaltyType = PenaltyType.create(props.type);
|
||||
|
||||
// Validate value based on type
|
||||
if (['time_penalty', 'grid_penalty', 'points_deduction', 'license_points', 'fine', 'race_ban'].includes(props.type)) {
|
||||
if (penaltyTypeRequiresValue(penaltyType.toString())) {
|
||||
if (props.value === undefined || props.value <= 0) {
|
||||
throw new RacingDomainValidationError(`${props.type} requires a positive value`);
|
||||
throw new RacingDomainValidationError(`${penaltyType.toString()} requires a positive value`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +100,7 @@ export class Penalty implements IEntity<string> {
|
||||
leagueId: LeagueId.create(props.leagueId),
|
||||
raceId: RaceId.create(props.raceId),
|
||||
driverId: DriverId.create(props.driverId),
|
||||
type: PenaltyType.create(props.type),
|
||||
type: penaltyType,
|
||||
reason: PenaltyReason.create(props.reason),
|
||||
issuedBy: StewardId.create(props.issuedBy),
|
||||
status: PenaltyStatus.create(props.status || 'pending'),
|
||||
|
||||
Reference in New Issue
Block a user