* Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
import { database } from "~/database/context";
|
|
import * as schema from "~/database/schema";
|
|
import { eq } from "drizzle-orm";
|
|
|
|
/**
|
|
* Check if a season is complete
|
|
* A season is considered complete if:
|
|
* 1. The season status is "completed"
|
|
* OR
|
|
* 2. All participants in all sports seasons have final results
|
|
*/
|
|
export async function isSeasonComplete(
|
|
seasonId: string,
|
|
providedDb?: ReturnType<typeof database>
|
|
): Promise<boolean> {
|
|
const db = providedDb || database();
|
|
|
|
// Check season status first (simplest check)
|
|
const season = await db.query.seasons.findFirst({
|
|
where: eq(schema.seasons.id, seasonId),
|
|
});
|
|
|
|
if (!season) {
|
|
return false;
|
|
}
|
|
|
|
if (season.status === "completed") {
|
|
return true;
|
|
}
|
|
|
|
// If status is not completed, check if all participants have results
|
|
// Get all sports seasons for this season
|
|
const seasonSports = await db.query.seasonSports.findMany({
|
|
where: eq(schema.seasonSports.seasonId, seasonId),
|
|
});
|
|
|
|
if (seasonSports.length === 0) {
|
|
return false;
|
|
}
|
|
|
|
// Get all draft picks for this season with participant info
|
|
const allPicks = await db.query.draftPicks.findMany({
|
|
where: eq(schema.draftPicks.seasonId, seasonId),
|
|
with: {
|
|
participant: {
|
|
with: {
|
|
results: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
// Check if all drafted participants have results
|
|
for (const pick of allPicks) {
|
|
// If any drafted participant doesn't have a result, season is not complete
|
|
if (!pick.participant.results || pick.participant.results.length === 0) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the completion percentage of a season
|
|
* Returns a value between 0 and 100
|
|
*/
|
|
export async function getSeasonCompletionPercentage(
|
|
seasonId: string,
|
|
providedDb?: ReturnType<typeof database>
|
|
): Promise<number> {
|
|
const db = providedDb || database();
|
|
|
|
// Get all draft picks for this season with participant results
|
|
const allPicks = await db.query.draftPicks.findMany({
|
|
where: eq(schema.draftPicks.seasonId, seasonId),
|
|
with: {
|
|
participant: {
|
|
with: {
|
|
results: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (allPicks.length === 0) {
|
|
return 0;
|
|
}
|
|
|
|
// Count how many have results
|
|
const completedCount = allPicks.filter(
|
|
(pick) => pick.participant.results && pick.participant.results.length > 0
|
|
).length;
|
|
|
|
return Math.round((completedCount / allPicks.length) * 100);
|
|
}
|