wip
This commit is contained in:
@@ -14,10 +14,10 @@ export interface LeagueScheduleDTO {
|
||||
raceStartTime: string;
|
||||
timezoneId: string;
|
||||
recurrenceStrategy: 'weekly' | 'everyNWeeks' | 'monthlyNthWeekday';
|
||||
intervalWeeks?: number;
|
||||
weekdays?: Weekday[];
|
||||
monthlyOrdinal?: 1 | 2 | 3 | 4;
|
||||
monthlyWeekday?: Weekday;
|
||||
intervalWeeks?: number | undefined;
|
||||
weekdays?: Weekday[] | undefined;
|
||||
monthlyOrdinal?: 1 | 2 | 3 | 4 | undefined;
|
||||
monthlyWeekday?: Weekday | undefined;
|
||||
plannedRounds: number;
|
||||
}
|
||||
|
||||
@@ -54,24 +54,26 @@ export function leagueTimingsToScheduleDTO(
|
||||
|
||||
export function scheduleDTOToSeasonSchedule(dto: LeagueScheduleDTO): SeasonSchedule {
|
||||
if (!dto.seasonStartDate) {
|
||||
throw new RacingApplicationError('seasonStartDate is required');
|
||||
throw new BusinessRuleViolationError('seasonStartDate is required');
|
||||
}
|
||||
if (!dto.raceStartTime) {
|
||||
throw new RacingApplicationError('raceStartTime is required');
|
||||
throw new BusinessRuleViolationError('raceStartTime is required');
|
||||
}
|
||||
if (!dto.timezoneId) {
|
||||
throw new RacingApplicationError('timezoneId is required');
|
||||
throw new BusinessRuleViolationError('timezoneId is required');
|
||||
}
|
||||
if (!dto.recurrenceStrategy) {
|
||||
throw new RacingApplicationError('recurrenceStrategy is required');
|
||||
throw new BusinessRuleViolationError('recurrenceStrategy is required');
|
||||
}
|
||||
if (!Number.isInteger(dto.plannedRounds) || dto.plannedRounds <= 0) {
|
||||
throw new RacingApplicationError('plannedRounds must be a positive integer');
|
||||
throw new BusinessRuleViolationError('plannedRounds must be a positive integer');
|
||||
}
|
||||
|
||||
const startDate = new Date(dto.seasonStartDate);
|
||||
if (Number.isNaN(startDate.getTime())) {
|
||||
throw new RacingApplicationError(`seasonStartDate must be a valid date, got "${dto.seasonStartDate}"`);
|
||||
throw new BusinessRuleViolationError(
|
||||
`seasonStartDate must be a valid date, got "${dto.seasonStartDate}"`,
|
||||
);
|
||||
}
|
||||
|
||||
const timeOfDay = RaceTimeOfDay.fromString(dto.raceStartTime);
|
||||
@@ -81,15 +83,17 @@ export function scheduleDTOToSeasonSchedule(dto: LeagueScheduleDTO): SeasonSched
|
||||
|
||||
if (dto.recurrenceStrategy === 'weekly') {
|
||||
if (!dto.weekdays || dto.weekdays.length === 0) {
|
||||
throw new RacingApplicationError('weekdays are required for weekly recurrence');
|
||||
throw new BusinessRuleViolationError('weekdays are required for weekly recurrence');
|
||||
}
|
||||
recurrence = RecurrenceStrategyFactory.weekly(new WeekdaySet(dto.weekdays));
|
||||
} else if (dto.recurrenceStrategy === 'everyNWeeks') {
|
||||
if (!dto.weekdays || dto.weekdays.length === 0) {
|
||||
throw new RacingApplicationError('weekdays are required for everyNWeeks recurrence');
|
||||
throw new BusinessRuleViolationError('weekdays are required for everyNWeeks recurrence');
|
||||
}
|
||||
if (dto.intervalWeeks == null) {
|
||||
throw new RacingApplicationError('intervalWeeks is required for everyNWeeks recurrence');
|
||||
throw new BusinessRuleViolationError(
|
||||
'intervalWeeks is required for everyNWeeks recurrence',
|
||||
);
|
||||
}
|
||||
recurrence = RecurrenceStrategyFactory.everyNWeeks(
|
||||
dto.intervalWeeks,
|
||||
@@ -97,12 +101,14 @@ export function scheduleDTOToSeasonSchedule(dto: LeagueScheduleDTO): SeasonSched
|
||||
);
|
||||
} else if (dto.recurrenceStrategy === 'monthlyNthWeekday') {
|
||||
if (!dto.monthlyOrdinal || !dto.monthlyWeekday) {
|
||||
throw new RacingApplicationError('monthlyOrdinal and monthlyWeekday are required for monthlyNthWeekday');
|
||||
throw new BusinessRuleViolationError(
|
||||
'monthlyOrdinal and monthlyWeekday are required for monthlyNthWeekday',
|
||||
);
|
||||
}
|
||||
const pattern = new MonthlyRecurrencePattern(dto.monthlyOrdinal, dto.monthlyWeekday);
|
||||
recurrence = RecurrenceStrategyFactory.monthlyNthWeekday(pattern);
|
||||
} else {
|
||||
throw new RacingApplicationError(`Unknown recurrenceStrategy "${dto.recurrenceStrategy}"`);
|
||||
throw new BusinessRuleViolationError(`Unknown recurrenceStrategy "${dto.recurrenceStrategy}"`);
|
||||
}
|
||||
|
||||
return new SeasonSchedule({
|
||||
|
||||
Reference in New Issue
Block a user