This commit is contained in:
2025-12-11 11:25:22 +01:00
parent 6a427eab57
commit e4c1be628d
86 changed files with 1222 additions and 736 deletions

View File

@@ -5,6 +5,8 @@
* Immutable entity with factory methods and domain validation.
*/
import { RacingDomainValidationError, RacingDomainInvariantError } from '../errors/RacingDomainError';
export type SessionType = 'practice' | 'qualifying' | 'race';
export type RaceStatus = 'scheduled' | 'running' | 'completed' | 'cancelled';
@@ -96,23 +98,23 @@ export class Race {
car: string;
}): void {
if (!props.id || props.id.trim().length === 0) {
throw new Error('Race ID is required');
throw new RacingDomainValidationError('Race ID is required');
}
if (!props.leagueId || props.leagueId.trim().length === 0) {
throw new Error('League ID is required');
throw new RacingDomainValidationError('League ID is required');
}
if (!props.scheduledAt || !(props.scheduledAt instanceof Date)) {
throw new Error('Valid scheduled date is required');
throw new RacingDomainValidationError('Valid scheduled date is required');
}
if (!props.track || props.track.trim().length === 0) {
throw new Error('Track is required');
throw new RacingDomainValidationError('Track is required');
}
if (!props.car || props.car.trim().length === 0) {
throw new Error('Car is required');
throw new RacingDomainValidationError('Car is required');
}
}
@@ -121,7 +123,7 @@ export class Race {
*/
start(): Race {
if (this.status !== 'scheduled') {
throw new Error('Only scheduled races can be started');
throw new RacingDomainInvariantError('Only scheduled races can be started');
}
return new Race({
@@ -135,11 +137,11 @@ export class Race {
*/
complete(): Race {
if (this.status === 'completed') {
throw new Error('Race is already completed');
throw new RacingDomainInvariantError('Race is already completed');
}
if (this.status === 'cancelled') {
throw new Error('Cannot complete a cancelled race');
throw new RacingDomainInvariantError('Cannot complete a cancelled race');
}
return new Race({
@@ -153,11 +155,11 @@ export class Race {
*/
cancel(): Race {
if (this.status === 'completed') {
throw new Error('Cannot cancel a completed race');
throw new RacingDomainInvariantError('Cannot cancel a completed race');
}
if (this.status === 'cancelled') {
throw new Error('Race is already cancelled');
throw new RacingDomainInvariantError('Race is already cancelled');
}
return new Race({