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

@@ -175,6 +175,55 @@ export class Season implements IEntity<string> {
});
}
static rehydrate(props: {
id: string;
leagueId: string;
gameId: string;
name: string;
year?: number;
order?: number;
status: SeasonStatus;
startDate?: Date;
endDate?: Date;
schedule?: SeasonSchedule;
schedulePublished: boolean;
scoringConfig?: SeasonScoringConfig;
dropPolicy?: SeasonDropPolicy;
stewardingConfig?: SeasonStewardingConfig;
maxDrivers?: number;
participantCount: number;
}): Season {
const participantCount = ParticipantCount.create(props.participantCount);
if (props.maxDrivers !== undefined) {
const maxParticipants = MaxParticipants.create(props.maxDrivers);
if (!maxParticipants.canAccommodate(participantCount.toNumber())) {
throw new RacingDomainValidationError(
`Participant count (${participantCount.toNumber()}) exceeds season capacity (${maxParticipants.toNumber()})`,
);
}
}
return new Season({
id: props.id,
leagueId: props.leagueId,
gameId: props.gameId,
name: props.name,
...(props.year !== undefined ? { year: props.year } : {}),
...(props.order !== undefined ? { order: props.order } : {}),
status: props.status,
...(props.startDate !== undefined ? { startDate: props.startDate } : {}),
...(props.endDate !== undefined ? { endDate: props.endDate } : {}),
...(props.schedule !== undefined ? { schedule: props.schedule } : {}),
schedulePublished: props.schedulePublished,
...(props.scoringConfig !== undefined ? { scoringConfig: props.scoringConfig } : {}),
...(props.dropPolicy !== undefined ? { dropPolicy: props.dropPolicy } : {}),
...(props.stewardingConfig !== undefined ? { stewardingConfig: props.stewardingConfig } : {}),
...(props.maxDrivers !== undefined ? { maxDrivers: props.maxDrivers } : {}),
participantCount,
});
}
/**
* Validate stewarding configuration
*/