racing typeorm
This commit is contained in:
@@ -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)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user