website refactor
This commit is contained in:
@@ -41,7 +41,7 @@ export class GetLeagueScheduleUseCase {
|
||||
private async resolveSeasonForSchedule(params: {
|
||||
leagueId: string;
|
||||
requestedSeasonId?: string;
|
||||
}): Promise<Result<Season, ApplicationErrorCode<GetLeagueScheduleErrorCode, { message: string }>>> {
|
||||
}): Promise<Result<Season | null, ApplicationErrorCode<GetLeagueScheduleErrorCode, { message: string }>>> {
|
||||
if (params.requestedSeasonId) {
|
||||
const season = await this.seasonRepository.findById(params.requestedSeasonId);
|
||||
if (!season || season.leagueId !== params.leagueId) {
|
||||
@@ -56,10 +56,8 @@ export class GetLeagueScheduleUseCase {
|
||||
const seasons = await this.seasonRepository.findByLeagueId(params.leagueId);
|
||||
const activeSeason = seasons.find((s: Season) => s.status.isActive()) ?? seasons[0];
|
||||
if (!activeSeason) {
|
||||
return Result.err({
|
||||
code: 'SEASON_NOT_FOUND',
|
||||
details: { message: 'No seasons found for league' },
|
||||
});
|
||||
// Return null instead of error - this allows showing all races for the league
|
||||
return Result.ok(null);
|
||||
}
|
||||
|
||||
return Result.ok(activeSeason);
|
||||
@@ -134,7 +132,9 @@ export class GetLeagueScheduleUseCase {
|
||||
const season = seasonResult.unwrap();
|
||||
|
||||
const races = await this.raceRepository.findByLeagueId(leagueId);
|
||||
const seasonRaces = this.filterRacesBySeasonWindow(season, races);
|
||||
|
||||
// If no season exists, show all races for the league
|
||||
const seasonRaces = season ? this.filterRacesBySeasonWindow(season, races) : races;
|
||||
|
||||
const scheduledRaces: LeagueScheduledRace[] = seasonRaces.map(race => ({
|
||||
race,
|
||||
@@ -142,8 +142,8 @@ export class GetLeagueScheduleUseCase {
|
||||
|
||||
const result: GetLeagueScheduleResult = {
|
||||
league,
|
||||
seasonId: season.id,
|
||||
published: season.schedulePublished ?? false,
|
||||
seasonId: season?.id ?? 'no-season',
|
||||
published: season?.schedulePublished ?? false,
|
||||
races: scheduledRaces,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user