fix: Pass database instance to isParticipantDrafted in timer context

The timer system runs outside the request context and uses its own database
  connection. This fix allows isParticipantDrafted to accept an optional db
  parameter so it works in both request handlers and timer contexts.

  Fixes: DatabaseContext not set error during autopick
This commit is contained in:
Chris Parsons 2025-10-28 23:40:29 -07:00
parent ad16f9d046
commit 8e422c6503
2 changed files with 3 additions and 3 deletions

View file

@ -50,8 +50,8 @@ export async function getTeamDraftPicks(teamId: string) {
.orderBy(schema.draftPicks.pickNumber); .orderBy(schema.draftPicks.pickNumber);
} }
export async function isParticipantDrafted(seasonId: string, participantId: string) { export async function isParticipantDrafted(seasonId: string, participantId: string, providedDb?: ReturnType<typeof database>) {
const db = database(); const db = providedDb || database();
const [pick] = await db const [pick] = await db
.select() .select()
.from(schema.draftPicks) .from(schema.draftPicks)

View file

@ -135,7 +135,7 @@ export async function autoPickForTeam(
const sportId = participant.sportsSeason.sport.id; const sportId = participant.sportsSeason.sport.id;
const isEligible = eligibility.eligibleSportIds.has(sportId); const isEligible = eligibility.eligibleSportIds.has(sportId);
const isDrafted = await isParticipantDrafted(seasonId, item.participantId); const isDrafted = await isParticipantDrafted(seasonId, item.participantId, db);
if (isDrafted) { if (isDrafted) {
console.log( console.log(