diff --git a/app/routes/leagues/$leagueId.sports-seasons.$sportsSeasonId.server.ts b/app/routes/leagues/$leagueId.sports-seasons.$sportsSeasonId.server.ts index 31eaaaf..27bf6ee 100644 --- a/app/routes/leagues/$leagueId.sports-seasons.$sportsSeasonId.server.ts +++ b/app/routes/leagues/$leagueId.sports-seasons.$sportsSeasonId.server.ts @@ -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);