This commit is contained in:
2025-12-17 00:33:13 +01:00
parent 8c67081953
commit f01e01e50c
186 changed files with 9242 additions and 1342 deletions

View File

@@ -5,24 +5,28 @@
import { RacingDomainValidationError } from '../errors/RacingDomainError';
import type { IEntity } from '@core/shared/domain';
import { RaceIncidents, type IncidentRecord } from '../value-objects/RaceIncidents';
import { RaceId } from './RaceId';
import { DriverId } from './DriverId';
import { Position } from './result/Position';
import { LapTime } from './result/LapTime';
export class ResultWithIncidents implements IEntity<string> {
readonly id: string;
readonly raceId: string;
readonly driverId: string;
readonly position: number;
readonly fastestLap: number;
readonly raceId: RaceId;
readonly driverId: DriverId;
readonly position: Position;
readonly fastestLap: LapTime;
readonly incidents: RaceIncidents;
readonly startPosition: number;
readonly startPosition: Position;
private constructor(props: {
id: string;
raceId: string;
driverId: string;
position: number;
fastestLap: number;
raceId: RaceId;
driverId: DriverId;
position: Position;
fastestLap: LapTime;
incidents: RaceIncidents;
startPosition: number;
startPosition: Position;
}) {
this.id = props.id;
this.raceId = props.raceId;
@@ -45,8 +49,21 @@ export class ResultWithIncidents implements IEntity<string> {
incidents: RaceIncidents;
startPosition: number;
}): ResultWithIncidents {
ResultWithIncidents.validate(props);
return new ResultWithIncidents(props);
this.validate(props);
const raceId = RaceId.create(props.raceId);
const driverId = DriverId.create(props.driverId);
const position = Position.create(props.position);
const fastestLap = LapTime.create(props.fastestLap);
const startPosition = Position.create(props.startPosition);
return new ResultWithIncidents({
id: props.id,
raceId,
driverId,
position,
fastestLap,
incidents: props.incidents,
startPosition,
});
}
/**
@@ -109,14 +126,14 @@ export class ResultWithIncidents implements IEntity<string> {
* Calculate positions gained/lost
*/
getPositionChange(): number {
return this.startPosition - this.position;
return this.startPosition.toNumber() - this.position.toNumber();
}
/**
* Check if driver finished on podium
*/
isPodium(): boolean {
return this.position <= 3;
return this.position.toNumber() <= 3;
}
/**