Fix sports season page 404 when sports season is linked to multiple leagues (#10)

The loader was grabbing seasonSports[0] blindly instead of filtering by
the current league, causing a 404 when the first linked fantasy season
belonged to a different league.

https://claude.ai/code/session_01Mq6BqFhiYFuJyDcc8ueVJc

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Chris Parsons 2026-02-20 11:35:35 -08:00 committed by GitHub
parent 83994b7a74
commit 3323522782
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,10 +8,8 @@ import {
findUserByClerkId,
} from "~/models";
import { getDraftPicks } from "~/models/draft-pick";
import { findSportsSeasonById } from "~/models/sports-season";
import { getSeasonResults } from "~/models/participant-season-result";
import { getQPStandings } from "~/models/qualifying-points";
import { findSeasonById } from "~/models/season";
import { database } from "~/database/context";
import * as schema from "~/database/schema";
import { eq } from "drizzle-orm";
@ -64,19 +62,17 @@ export async function loader(args: Route.LoaderArgs) {
// Get the fantasy season for this league (to get teams and draft picks)
// We need to find which season in this league includes this sports season
const seasonSport = sportsSeason.seasonSports?.[0];
// Filter by leagueId since a sports season can be linked to multiple leagues
const seasonSport = sportsSeason.seasonSports?.find(
(ss) => ss.season.leagueId === leagueId
);
if (!seasonSport) {
throw new Response("This sports season is not linked to this league", {
status: 404,
});
}
const season = await findSeasonById(seasonSport.seasonId);
if (!season || season.leagueId !== leagueId) {
throw new Response("This sports season is not linked to this league", {
status: 404,
});
}
const season = seasonSport.season;
// Fetch teams and draft picks to determine ownership
const teams = await findTeamsBySeasonId(season.id);