Fix force-manual-pick resetting next team's timer to initial time
When a commissioner forced a manual pick, the next team's timer was being reset to the initial time (2 minutes) instead of carrying forward their existing time bank balance. This aligns force-manual-pick with the behavior of regular user picks and force-autopick: the picking team gets their increment added, and the next team's timer is left untouched so their bank carries forward. https://claude.ai/code/session_01X7gwWmafUSEvVHcV7Raz5p
This commit is contained in:
parent
34da0594d1
commit
853cd3756b
1 changed files with 3 additions and 58 deletions
|
|
@ -178,65 +178,10 @@ export async function action(args: any) {
|
|||
console.error("Socket.IO timer-update error:", error);
|
||||
}
|
||||
|
||||
// Initialize timer for the next team BEFORE updating pick number (prevents race condition)
|
||||
if (!isDraftComplete) {
|
||||
// Calculate which team is next using snake draft logic
|
||||
const nextRound = Math.ceil(nextPickNumber / totalTeams);
|
||||
const isNextRoundEven = nextRound % 2 === 0;
|
||||
let nextPickInRound = ((nextPickNumber - 1) % totalTeams) + 1;
|
||||
// Next team's timer is unchanged — their bank carries forward as-is.
|
||||
// The timer server loop will start counting down from their existing balance.
|
||||
|
||||
// Apply snake draft reversal for even rounds
|
||||
if (isNextRoundEven) {
|
||||
nextPickInRound = totalTeams - nextPickInRound + 1;
|
||||
}
|
||||
|
||||
const nextDraftSlot = draftSlots.find((slot) => slot.draftOrder === nextPickInRound);
|
||||
|
||||
if (nextDraftSlot) {
|
||||
const nextTeamId = nextDraftSlot.teamId;
|
||||
const initialTime = season.draftInitialTime || 120;
|
||||
|
||||
// Check if timer already exists for next team
|
||||
const nextTimer = await db.query.draftTimers.findFirst({
|
||||
where: and(
|
||||
eq(schema.draftTimers.seasonId, seasonId),
|
||||
eq(schema.draftTimers.teamId, nextTeamId)
|
||||
),
|
||||
});
|
||||
|
||||
if (nextTimer) {
|
||||
// Update existing timer
|
||||
await db
|
||||
.update(schema.draftTimers)
|
||||
.set({
|
||||
timeRemaining: initialTime,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(schema.draftTimers.id, nextTimer.id));
|
||||
} else {
|
||||
// Create new timer if it doesn't exist
|
||||
await db.insert(schema.draftTimers).values({
|
||||
seasonId,
|
||||
teamId: nextTeamId,
|
||||
timeRemaining: initialTime,
|
||||
});
|
||||
}
|
||||
|
||||
// Emit timer update for next team
|
||||
try {
|
||||
getSocketIO().to(`draft-${seasonId}`).emit("timer-update", {
|
||||
seasonId,
|
||||
teamId: nextTeamId,
|
||||
timeRemaining: initialTime,
|
||||
currentPickNumber: nextPickNumber,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Socket.IO next timer-update error:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update season's current pick number (AFTER initializing next timer to prevent race condition)
|
||||
// Update season's current pick number
|
||||
await db
|
||||
.update(schema.seasons)
|
||||
.set({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue