inmemory to postgres
This commit is contained in:
@@ -114,6 +114,46 @@ export class Penalty implements IEntity<string> {
|
||||
return new Penalty(penaltyProps);
|
||||
}
|
||||
|
||||
static rehydrate(props: {
|
||||
id: string;
|
||||
leagueId: string;
|
||||
raceId: string;
|
||||
driverId: string;
|
||||
type: string;
|
||||
value?: number;
|
||||
reason: string;
|
||||
protestId?: string;
|
||||
issuedBy: string;
|
||||
status: string;
|
||||
issuedAt: Date;
|
||||
appliedAt?: Date;
|
||||
notes?: string;
|
||||
}): Penalty {
|
||||
const penaltyType = PenaltyType.create(props.type);
|
||||
|
||||
if (penaltyTypeRequiresValue(penaltyType.toString())) {
|
||||
if (props.value === undefined || props.value <= 0) {
|
||||
throw new RacingDomainValidationError(`${penaltyType.toString()} requires a positive value`);
|
||||
}
|
||||
}
|
||||
|
||||
return new Penalty({
|
||||
id: PenaltyId.create(props.id),
|
||||
leagueId: LeagueId.create(props.leagueId),
|
||||
raceId: RaceId.create(props.raceId),
|
||||
driverId: DriverId.create(props.driverId),
|
||||
type: penaltyType,
|
||||
...(props.value !== undefined ? { value: PenaltyValue.create(props.value) } : {}),
|
||||
reason: PenaltyReason.create(props.reason),
|
||||
...(props.protestId !== undefined ? { protestId: ProtestId.create(props.protestId) } : {}),
|
||||
issuedBy: StewardId.create(props.issuedBy),
|
||||
status: PenaltyStatus.create(props.status),
|
||||
issuedAt: IssuedAt.create(props.issuedAt),
|
||||
...(props.appliedAt !== undefined ? { appliedAt: AppliedAt.create(props.appliedAt) } : {}),
|
||||
...(props.notes !== undefined ? { notes: PenaltyNotes.create(props.notes) } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
get id(): string { return this.props.id.toString(); }
|
||||
get leagueId(): string { return this.props.leagueId.toString(); }
|
||||
get raceId(): string { return this.props.raceId.toString(); }
|
||||
|
||||
Reference in New Issue
Block a user