This commit is contained in:
2025-12-12 21:39:48 +01:00
parent ddbd99b747
commit cae81b1088
49 changed files with 777 additions and 269 deletions

View File

@@ -16,7 +16,7 @@ export interface PrizeProps {
seasonId: string;
position: number;
amount: Money;
driverId?: string;
driverId: string;
status: PrizeStatus;
createdAt: Date;
awardedAt: Date | undefined;
@@ -29,7 +29,7 @@ export class Prize implements IEntity<string> {
readonly seasonId: string;
readonly position: number;
readonly amount: Money;
readonly driverId: string | undefined;
readonly driverId: string;
readonly status: PrizeStatus;
readonly createdAt: Date;
readonly awardedAt: Date | undefined;
@@ -49,14 +49,26 @@ export class Prize implements IEntity<string> {
this.description = props.description;
}
static create(props: Omit<PrizeProps, 'createdAt' | 'status'> & {
static create(props: Omit<PrizeProps, 'createdAt' | 'status' | 'driverId' | 'awardedAt' | 'paidAt' | 'description'> & {
createdAt?: Date;
status?: PrizeStatus;
driverId?: string;
awardedAt?: Date;
paidAt?: Date;
description?: string;
}): Prize {
this.validate(props);
const fullProps: Omit<PrizeProps, 'createdAt' | 'status'> = {
...props,
driverId: props.driverId ?? '',
awardedAt: props.awardedAt,
paidAt: props.paidAt,
description: props.description,
};
this.validate(fullProps);
return new Prize({
...props,
...fullProps,
createdAt: props.createdAt ?? new Date(),
status: props.status ?? 'pending',
});
@@ -112,7 +124,7 @@ export class Prize implements IEntity<string> {
throw new RacingDomainInvariantError('Only awarded prizes can be marked as paid');
}
if (!this.driverId) {
if (!this.driverId || this.driverId.trim() === '') {
throw new RacingDomainInvariantError('Prize must have a driver to be paid');
}

View File

@@ -66,7 +66,7 @@ export function calculateRaceDates(config: ScheduleConfig): ScheduleResult {
const spacing = totalPossible / rounds;
for (let i = 0; i < rounds; i++) {
const index = Math.min(Math.floor(i * spacing), totalPossible - 1);
dates.push(allPossibleDays[index]);
dates.push(allPossibleDays[index]!);
}
} else {
// Not enough days - use all available
@@ -74,7 +74,7 @@ export function calculateRaceDates(config: ScheduleConfig): ScheduleResult {
}
const seasonDurationWeeks = dates.length > 1
? Math.ceil((dates[dates.length - 1].getTime() - dates[0].getTime()) / (7 * 24 * 60 * 60 * 1000))
? Math.ceil((dates[dates.length - 1]!.getTime() - dates[0]!.getTime()) / (7 * 24 * 60 * 60 * 1000))
: 0;
return { raceDates: dates, seasonDurationWeeks };
@@ -125,7 +125,7 @@ export function calculateRaceDates(config: ScheduleConfig): ScheduleResult {
}
const seasonDurationWeeks = dates.length > 1
? Math.ceil((dates[dates.length - 1].getTime() - dates[0].getTime()) / (7 * 24 * 60 * 60 * 1000))
? Math.ceil((dates[dates.length - 1]!.getTime() - dates[0]!.getTime()) / (7 * 24 * 60 * 60 * 1000))
: 0;
return { raceDates: dates, seasonDurationWeeks };