diff --git a/app/routes/api/draft.rollback.ts b/app/routes/api/draft.rollback.ts index 1d7e5d9..b9e4823 100644 --- a/app/routes/api/draft.rollback.ts +++ b/app/routes/api/draft.rollback.ts @@ -75,20 +75,20 @@ export async function action(args: any) { ) ); - // Clear all timers and create a fresh one for the team now on the clock + // Clear all timers and recreate them for every team so no team is left without a timer await db .delete(schema.draftTimers) .where(eq(schema.draftTimers.seasonId, seasonId)); const initialTime = season.draftInitialTime || 120; - if (rollbackSlot) { - await db.insert(schema.draftTimers).values({ + await db.insert(schema.draftTimers).values( + draftSlots.map((slot) => ({ seasonId, - teamId: rollbackSlot.teamId, + teamId: slot.teamId, timeRemaining: initialTime, - }); - } + })) + ); // Update season: reset pick number and unpause await db diff --git a/server/timer.ts b/server/timer.ts index 1f91b3f..33e7702 100644 --- a/server/timer.ts +++ b/server/timer.ts @@ -111,7 +111,27 @@ async function updateDraftTimers(): Promise { }); if (!timer) { - console.warn(`[Timer] No timer found for team ${currentTeamId} in season ${season.id}`); + console.warn( + `[Timer] No timer found for team ${currentTeamId} in season ${season.id}, creating with initial time` + ); + const initialTime = season.draftInitialTime || 120; + await db + .insert(schema.draftTimers) + .values({ + seasonId: season.id, + teamId: currentTeamId, + timeRemaining: initialTime, + }); + + // Emit timer update so clients are aware of the new timer + io.to(`draft-${season.id}`).emit("timer-update", { + seasonId: season.id, + teamId: currentTeamId, + timeRemaining: initialTime, + currentPickNumber, + }); + + // Continue processing with the newly created timer on the next tick continue; }