racing typeorm

This commit is contained in:
2025-12-29 00:24:56 +01:00
parent 2f6657f56d
commit 9e17d0752a
55 changed files with 3528 additions and 22 deletions

View File

@@ -157,6 +157,58 @@ export class Race implements IEntity<string> {
});
}
static rehydrate(props: {
id: string;
leagueId: string;
scheduledAt: Date;
track: string;
trackId?: string;
car: string;
carId?: string;
sessionType: SessionType;
status: RaceStatus;
strengthOfField?: number;
registeredCount?: number;
maxParticipants?: number;
}): Race {
let registeredCount: ParticipantCount | undefined;
let maxParticipants: MaxParticipants | undefined;
if (props.registeredCount !== undefined) {
registeredCount = ParticipantCount.create(props.registeredCount);
}
if (props.maxParticipants !== undefined) {
maxParticipants = MaxParticipants.create(props.maxParticipants);
if (registeredCount && !maxParticipants.canAccommodate(registeredCount.toNumber())) {
throw new RacingDomainValidationError(
`Registered count (${registeredCount.toNumber()}) exceeds max participants (${maxParticipants.toNumber()})`,
);
}
}
let strengthOfField: StrengthOfField | undefined;
if (props.strengthOfField !== undefined) {
strengthOfField = StrengthOfField.create(props.strengthOfField);
}
return new Race({
id: props.id,
leagueId: props.leagueId,
scheduledAt: props.scheduledAt,
track: props.track,
...(props.trackId !== undefined ? { trackId: props.trackId } : {}),
car: props.car,
...(props.carId !== undefined ? { carId: props.carId } : {}),
sessionType: props.sessionType,
status: props.status,
...(strengthOfField !== undefined ? { strengthOfField } : {}),
...(registeredCount !== undefined ? { registeredCount } : {}),
...(maxParticipants !== undefined ? { maxParticipants } : {}),
});
}
/**
* Start the race (move from scheduled to running)
*/