* Create timer when adding time to a team with no existing timer When a commissioner tries to add time to a team that has no draft timer, instead of returning a 404 error, create a new timer record with the specified amount of time. Removing time still returns a 404 if no timer exists (nothing to remove from). https://claude.ai/code/session_016VpJKZZFNQQqzfmLu8pHoc * 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 --------- Co-authored-by: Claude <noreply@anthropic.com>
46 lines
1.4 KiB
TypeScript
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));
|
|
}
|