This commit is contained in:
2025-12-11 13:50:38 +01:00
parent e4c1be628d
commit c7e5de40d6
212 changed files with 2965 additions and 763 deletions

View File

@@ -1,19 +1,28 @@
import type { Weekday } from './Weekday';
import { weekdayToIndex } from './Weekday';
import { RacingDomainValidationError } from '../errors/RacingDomainError';
export class WeekdaySet {
import type { IValueObject } from '@gridpilot/shared/domain';
export interface WeekdaySetProps {
days: Weekday[];
}
export class WeekdaySet implements IValueObject<WeekdaySetProps> {
private readonly days: Weekday[];
constructor(days: Weekday[]) {
if (!Array.isArray(days) || days.length === 0) {
throw new RacingDomainValidationError('WeekdaySet requires at least one weekday');
}
const unique = Array.from(new Set(days));
this.days = unique.sort((a, b) => weekdayToIndex(a) - weekdayToIndex(b));
}
get props(): WeekdaySetProps {
return { days: [...this.days] };
}
getAll(): Weekday[] {
return [...this.days];
}
@@ -21,4 +30,11 @@ export class WeekdaySet {
includes(day: Weekday): boolean {
return this.days.includes(day);
}
equals(other: IValueObject<WeekdaySetProps>): boolean {
const a = this.props.days;
const b = other.props.days;
if (a.length !== b.length) return false;
return a.every((day, index) => day === b[index]);
}
}