diff --git a/app/routes/api/draft.adjust-time-bank.ts b/app/routes/api/draft.adjust-time-bank.ts index 9109fbd..78246e9 100644 --- a/app/routes/api/draft.adjust-time-bank.ts +++ b/app/routes/api/draft.adjust-time-bank.ts @@ -61,17 +61,26 @@ export async function action(args: any) { ) ); + let newTime: number; + if (!currentTimer) { - return Response.json({ error: "Timer not found for this team" }, { status: 404 }); + if (adjustment <= 0) { + return Response.json({ error: "Timer not found for this team" }, { status: 404 }); + } + newTime = adjustment; + await db.insert(schema.draftTimers).values({ + seasonId, + teamId, + timeRemaining: newTime, + }); + } else { + newTime = Math.max(0, currentTimer.timeRemaining + adjustment); + await db + .update(schema.draftTimers) + .set({ timeRemaining: newTime, updatedAt: new Date() }) + .where(eq(schema.draftTimers.id, currentTimer.id)); } - const newTime = Math.max(0, currentTimer.timeRemaining + adjustment); - - await db - .update(schema.draftTimers) - .set({ timeRemaining: newTime, updatedAt: new Date() }) - .where(eq(schema.draftTimers.id, currentTimer.id)); - try { getSocketIO() .to(`draft-${seasonId}`)