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:
parent
ad16f9d046
commit
8e422c6503
2 changed files with 3 additions and 3 deletions
|
|
@ -50,8 +50,8 @@ export async function getTeamDraftPicks(teamId: string) {
|
|||
.orderBy(schema.draftPicks.pickNumber);
|
||||
}
|
||||
|
||||
export async function isParticipantDrafted(seasonId: string, participantId: string) {
|
||||
const db = database();
|
||||
export async function isParticipantDrafted(seasonId: string, participantId: string, providedDb?: ReturnType<typeof database>) {
|
||||
const db = providedDb || database();
|
||||
const [pick] = await db
|
||||
.select()
|
||||
.from(schema.draftPicks)
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ export async function autoPickForTeam(
|
|||
|
||||
const sportId = participant.sportsSeason.sport.id;
|
||||
const isEligible = eligibility.eligibleSportIds.has(sportId);
|
||||
const isDrafted = await isParticipantDrafted(seasonId, item.participantId);
|
||||
const isDrafted = await isParticipantDrafted(seasonId, item.participantId, db);
|
||||
|
||||
if (isDrafted) {
|
||||
console.log(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue