brackt/app/models/draft-timer.ts
Claude 63ca959958
Fix silent timer failures and missing seasonId filter in timer model
- draft.make-pick.ts: create a timer with the increment amount instead of
  logging a warning and silently skipping when no timer exists for the
  picking team
- draft.force-manual-pick.ts: same fix for the commissioner force-pick path;
  also unconditionally emit the timer-update socket event so clients always
  see the updated time
- models/draft-timer.ts: add seasonId parameter to getTeamTimer and
  updateTeamTimer so they cannot match the wrong season's timer when a team
  participates in multiple seasons

https://claude.ai/code/session_016VpJKZZFNQQqzfmLu8pHoc
2026-02-23 01:23:54 +00:00

46 lines
1.4 KiB
TypeScript

import { database } from "~/database/context";
import * as schema from "~/database/schema";
import { eq, and } from "drizzle-orm";
export async function initializeDraftTimers(seasonId: string, teams: { id: string }[], initialTime: number) {
const timerData = teams.map((team) => ({
seasonId,
teamId: team.id,
timeRemaining: initialTime,
}));
const db = database();
await db.insert(schema.draftTimers).values(timerData);
}
export async function getTeamTimer(seasonId: string, teamId: string) {
const db = database();
const [timer] = await db
.select()
.from(schema.draftTimers)
.where(and(eq(schema.draftTimers.seasonId, seasonId), eq(schema.draftTimers.teamId, teamId)));
return timer;
}
export async function getSeasonTimers(seasonId: string) {
const db = database();
return await db
.select()
.from(schema.draftTimers)
.where(eq(schema.draftTimers.seasonId, seasonId));
}
export async function updateTeamTimer(seasonId: string, teamId: string, timeRemaining: number) {
const db = database();
const [timer] = await db
.update(schema.draftTimers)
.set({ timeRemaining, updatedAt: new Date() })
.where(and(eq(schema.draftTimers.seasonId, seasonId), eq(schema.draftTimers.teamId, teamId)))
.returning();
return timer;
}
export async function deleteSeasonTimers(seasonId: string) {
const db = database();
await db.delete(schema.draftTimers).where(eq(schema.draftTimers.seasonId, seasonId));
}