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:
parent
83994b7a74
commit
3323522782
1 changed files with 5 additions and 9 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue