racing typeorm
This commit is contained in:
@@ -18,6 +18,13 @@ export interface LeagueScoringConfigProps {
|
||||
championships: ChampionshipConfig[];
|
||||
}
|
||||
|
||||
export interface LeagueScoringConfigRehydrateProps {
|
||||
id: string;
|
||||
seasonId: string;
|
||||
scoringPresetId?: string;
|
||||
championships: ChampionshipConfig[];
|
||||
}
|
||||
|
||||
export class LeagueScoringConfig implements IEntity<LeagueScoringConfigId> {
|
||||
readonly id: LeagueScoringConfigId;
|
||||
readonly seasonId: SeasonId;
|
||||
@@ -53,6 +60,25 @@ export class LeagueScoringConfig implements IEntity<LeagueScoringConfigId> {
|
||||
});
|
||||
}
|
||||
|
||||
static rehydrate(props: LeagueScoringConfigRehydrateProps): LeagueScoringConfig {
|
||||
this.validate(props);
|
||||
|
||||
if (!props.id || props.id.trim().length === 0) {
|
||||
throw new RacingDomainValidationError('Scoring config ID is required');
|
||||
}
|
||||
|
||||
const id = LeagueScoringConfigId.create(props.id);
|
||||
const seasonId = SeasonId.create(props.seasonId);
|
||||
const scoringPresetId = props.scoringPresetId ? ScoringPresetId.create(props.scoringPresetId) : undefined;
|
||||
|
||||
return new LeagueScoringConfig({
|
||||
id,
|
||||
seasonId,
|
||||
...(scoringPresetId ? { scoringPresetId } : {}),
|
||||
championships: props.championships,
|
||||
});
|
||||
}
|
||||
|
||||
private static validate(props: LeagueScoringConfigProps): void {
|
||||
if (!props.seasonId || props.seasonId.trim().length === 0) {
|
||||
throw new RacingDomainValidationError('Season ID is required');
|
||||
|
||||
Reference in New Issue
Block a user