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