refactor(routes): update route layer to use renamed schema exports
- Update model import from ~/models/participant to ~/models/season-participant - Rename schema.participants to schema.seasonParticipants - Rename schema.participantResults to schema.seasonParticipantResults - Rename db.query.participants to db.query.seasonParticipants - Update 9 route files and 1 test file Affected files: - admin.sports-seasons.$id.events.$eventId.bracket.server.ts - admin.sports-seasons.$id.participants.tsx - api/draft.force-manual-pick.ts - api/draft.make-pick.ts - api/draft.replace-pick.ts - api/seasons.$seasonId.draft.ts - leagues/$leagueId.draft-board.$seasonId.tsx - leagues/$leagueId.sports-seasons.$sportsSeasonId.server.ts - admin/__tests__/sports-seasons-participants.test.ts Error count reduced from 499 to 453 (46 errors fixed). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
fd99cab61b
commit
0dc962135c
9 changed files with 31 additions and 31 deletions
|
|
@ -595,9 +595,9 @@ export async function action({ request, params }: Route.ActionArgs) {
|
||||||
// the "never un-finalize" guard in upsertParticipantResult.
|
// the "never un-finalize" guard in upsertParticipantResult.
|
||||||
const db = database();
|
const db = database();
|
||||||
await db
|
await db
|
||||||
.delete(schema.participantResults)
|
.delete(schema.seasonParticipantResults)
|
||||||
.where(
|
.where(
|
||||||
eq(schema.participantResults.sportsSeasonId, event.sportsSeasonId)
|
eq(schema.seasonParticipantResults.sportsSeasonId, event.sportsSeasonId)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Replay each completed match in bracket order (earlier rounds first).
|
// Replay each completed match in bracket order (earlier rounds first).
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
createParticipant,
|
createParticipant,
|
||||||
deleteParticipant,
|
deleteParticipant,
|
||||||
updateParticipant,
|
updateParticipant,
|
||||||
} from "~/models/participant";
|
} from "~/models/season-participant";
|
||||||
import { Button } from "~/components/ui/button";
|
import { Button } from "~/components/ui/button";
|
||||||
import { Input } from "~/components/ui/input";
|
import { Input } from "~/components/ui/input";
|
||||||
import { Label } from "~/components/ui/label";
|
import { Label } from "~/components/ui/label";
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||||
|
|
||||||
vi.mock("~/models/participant", () => ({
|
vi.mock("~/models/season-participant", () => ({
|
||||||
findParticipantsBySportsSeasonId: vi.fn(),
|
findParticipantsBySportsSeasonId: vi.fn(),
|
||||||
findParticipantByName: vi.fn(),
|
findParticipantByName: vi.fn(),
|
||||||
createParticipant: vi.fn(),
|
createParticipant: vi.fn(),
|
||||||
|
|
@ -19,7 +19,7 @@ vi.mock("~/lib/logger", () => ({
|
||||||
import {
|
import {
|
||||||
findParticipantByName,
|
findParticipantByName,
|
||||||
updateParticipant,
|
updateParticipant,
|
||||||
} from "~/models/participant";
|
} from "~/models/season-participant";
|
||||||
import { action } from "~/routes/admin.sports-seasons.$id.participants";
|
import { action } from "~/routes/admin.sports-seasons.$id.participants";
|
||||||
|
|
||||||
const mockParams = { id: "season-1" };
|
const mockParams = { id: "season-1" };
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,8 @@ export async function action(args: ActionFunctionArgs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get participant details
|
// Get participant details
|
||||||
const participant = await db.query.participants.findFirst({
|
const participant = await db.query.seasonParticipants.findFirst({
|
||||||
where: eq(schema.participants.id, participantId),
|
where: eq(schema.seasonParticipants.id, participantId),
|
||||||
with: {
|
with: {
|
||||||
sportsSeason: {
|
sportsSeason: {
|
||||||
with: {
|
with: {
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,8 @@ export async function action(args: ActionFunctionArgs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get participant details
|
// Get participant details
|
||||||
const participant = await db.query.participants.findFirst({
|
const participant = await db.query.seasonParticipants.findFirst({
|
||||||
where: eq(schema.participants.id, participantId),
|
where: eq(schema.seasonParticipants.id, participantId),
|
||||||
with: {
|
with: {
|
||||||
sportsSeason: {
|
sportsSeason: {
|
||||||
with: {
|
with: {
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,8 @@ export async function action(args: ActionFunctionArgs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const participant = await db.query.participants.findFirst({
|
const participant = await db.query.seasonParticipants.findFirst({
|
||||||
where: eq(schema.participants.id, participantId),
|
where: eq(schema.seasonParticipants.id, participantId),
|
||||||
with: {
|
with: {
|
||||||
sportsSeason: { with: { sport: true } },
|
sportsSeason: { with: { sport: true } },
|
||||||
},
|
},
|
||||||
|
|
@ -128,8 +128,8 @@ export async function action(args: ActionFunctionArgs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch old participant name for the audit log (before overwriting the pick)
|
// Fetch old participant name for the audit log (before overwriting the pick)
|
||||||
const oldParticipant = await db.query.participants.findFirst({
|
const oldParticipant = await db.query.seasonParticipants.findFirst({
|
||||||
where: eq(schema.participants.id, oldParticipantId),
|
where: eq(schema.seasonParticipants.id, oldParticipantId),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update the pick in-place
|
// Update the pick in-place
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,13 @@ export async function loader({ params }: LoaderFunctionArgs) {
|
||||||
round: schema.draftPicks.round,
|
round: schema.draftPicks.round,
|
||||||
teamName: schema.teams.name,
|
teamName: schema.teams.name,
|
||||||
teamOwnerId: schema.teams.ownerId,
|
teamOwnerId: schema.teams.ownerId,
|
||||||
participantName: schema.participants.name,
|
participantName: schema.seasonParticipants.name,
|
||||||
sport: schema.sports.name,
|
sport: schema.sports.name,
|
||||||
})
|
})
|
||||||
.from(schema.draftPicks)
|
.from(schema.draftPicks)
|
||||||
.innerJoin(schema.teams, eq(schema.draftPicks.teamId, schema.teams.id))
|
.innerJoin(schema.teams, eq(schema.draftPicks.teamId, schema.teams.id))
|
||||||
.innerJoin(schema.participants, eq(schema.draftPicks.participantId, schema.participants.id))
|
.innerJoin(schema.seasonParticipants, eq(schema.draftPicks.participantId, schema.seasonParticipants.id))
|
||||||
.innerJoin(schema.sportsSeasons, eq(schema.participants.sportsSeasonId, schema.sportsSeasons.id))
|
.innerJoin(schema.sportsSeasons, eq(schema.seasonParticipants.sportsSeasonId, schema.sportsSeasons.id))
|
||||||
.innerJoin(schema.sports, eq(schema.sportsSeasons.sportId, schema.sports.id))
|
.innerJoin(schema.sports, eq(schema.sportsSeasons.sportId, schema.sports.id))
|
||||||
.where(eq(schema.draftPicks.seasonId, seasonId))
|
.where(eq(schema.draftPicks.seasonId, seasonId))
|
||||||
.orderBy(schema.draftPicks.pickNumber);
|
.orderBy(schema.draftPicks.pickNumber);
|
||||||
|
|
|
||||||
|
|
@ -76,19 +76,19 @@ export async function loader(args: Route.LoaderArgs) {
|
||||||
round: schema.draftPicks.round,
|
round: schema.draftPicks.round,
|
||||||
pickInRound: schema.draftPicks.pickInRound,
|
pickInRound: schema.draftPicks.pickInRound,
|
||||||
team: schema.teams,
|
team: schema.teams,
|
||||||
participant: schema.participants,
|
participant: schema.seasonParticipants,
|
||||||
sport: schema.sports,
|
sport: schema.sports,
|
||||||
scoringPattern: schema.sportsSeasons.scoringPattern,
|
scoringPattern: schema.sportsSeasons.scoringPattern,
|
||||||
})
|
})
|
||||||
.from(schema.draftPicks)
|
.from(schema.draftPicks)
|
||||||
.innerJoin(schema.teams, eq(schema.draftPicks.teamId, schema.teams.id))
|
.innerJoin(schema.teams, eq(schema.draftPicks.teamId, schema.teams.id))
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
schema.participants,
|
schema.seasonParticipants,
|
||||||
eq(schema.draftPicks.participantId, schema.participants.id)
|
eq(schema.draftPicks.participantId, schema.seasonParticipants.id)
|
||||||
)
|
)
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
schema.sportsSeasons,
|
schema.sportsSeasons,
|
||||||
eq(schema.participants.sportsSeasonId, schema.sportsSeasons.id)
|
eq(schema.seasonParticipants.sportsSeasonId, schema.sportsSeasons.id)
|
||||||
)
|
)
|
||||||
.innerJoin(schema.sports, eq(schema.sportsSeasons.sportId, schema.sports.id))
|
.innerJoin(schema.sports, eq(schema.sportsSeasons.sportId, schema.sports.id))
|
||||||
.where(eq(schema.draftPicks.seasonId, seasonId))
|
.where(eq(schema.draftPicks.seasonId, seasonId))
|
||||||
|
|
@ -104,13 +104,13 @@ export async function loader(args: Route.LoaderArgs) {
|
||||||
|
|
||||||
const results = await db
|
const results = await db
|
||||||
.select({
|
.select({
|
||||||
participantId: schema.participantResults.participantId,
|
participantId: schema.seasonParticipantResults.participantId,
|
||||||
sportsSeasonId: schema.participantResults.sportsSeasonId,
|
sportsSeasonId: schema.seasonParticipantResults.sportsSeasonId,
|
||||||
finalPosition: schema.participantResults.finalPosition,
|
finalPosition: schema.seasonParticipantResults.finalPosition,
|
||||||
isPartialScore: schema.participantResults.isPartialScore,
|
isPartialScore: schema.seasonParticipantResults.isPartialScore,
|
||||||
})
|
})
|
||||||
.from(schema.participantResults)
|
.from(schema.seasonParticipantResults)
|
||||||
.where(inArray(schema.participantResults.participantId, participantIds));
|
.where(inArray(schema.seasonParticipantResults.participantId, participantIds));
|
||||||
|
|
||||||
const resultByParticipant = new Map(results.map((r) => [r.participantId, r]));
|
const resultByParticipant = new Map(results.map((r) => [r.participantId, r]));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -233,15 +233,15 @@ export async function loader(args: Route.LoaderArgs) {
|
||||||
|
|
||||||
// Fetch group-stage losers and all participant results for bracket scoring
|
// Fetch group-stage losers and all participant results for bracket scoring
|
||||||
const [eliminatedResults, allResults] = await Promise.all([
|
const [eliminatedResults, allResults] = await Promise.all([
|
||||||
db.query.participantResults.findMany({
|
db.query.seasonParticipantResults.findMany({
|
||||||
where: and(
|
where: and(
|
||||||
eq(schema.participantResults.sportsSeasonId, sportsSeasonId),
|
eq(schema.seasonParticipantResults.sportsSeasonId, sportsSeasonId),
|
||||||
eq(schema.participantResults.finalPosition, 0)
|
eq(schema.seasonParticipantResults.finalPosition, 0)
|
||||||
),
|
),
|
||||||
with: { participant: true },
|
with: { participant: true },
|
||||||
}),
|
}),
|
||||||
db.query.participantResults.findMany({
|
db.query.seasonParticipantResults.findMany({
|
||||||
where: eq(schema.participantResults.sportsSeasonId, sportsSeasonId),
|
where: eq(schema.seasonParticipantResults.sportsSeasonId, sportsSeasonId),
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue