fix: return fightId from ranked queue on duplicate join, fix calculateTier call

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 09:29:55 +00:00
co-authored by Claude Opus 4.6
parent e31d49898b
commit f9e5c1c329
2 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -536,7 +536,7 @@ describe('fight lifecycle', () => {
// Elo + tier calculation
calculateElo(eloA, eloB)
calculateTier(eloA, f % 50, f % 20)
calculateTier(eloA, f % 50)
}
const elapsed = performance.now() - start
+5 -3
View File
@@ -1,7 +1,7 @@
import { logger } from '../lib/logger.js'
import { db, schema } from '../db/index.js'
import { eq, sql } from 'drizzle-orm'
import { runFightAsync, isInFight } from './orchestrator.js'
import { runFightAsync, isInFight, getActiveFightId } from './orchestrator.js'
import { checkPaymentStatus, refundEntry, consumePaymentForQueue, linkPaymentsToFight, releasePayment } from './payments.js'
interface RankedQueueEntry {
@@ -61,10 +61,12 @@ export async function joinRankedQueue(botId: string, paymentId: string): Promise
throw new Error(`Cooldown active. Wait ${waitSec}s.`)
}
// Check if already in a fight
// Check if already in a fight — return fightId so frontend can redirect
if (isInFight(botId)) {
releasePayment(paymentId)
throw new Error('Bot is already in a fight.')
const err = new Error('Bot is already in a fight.')
;(err as any).fightId = getActiveFightId(botId)
throw err
}
// Load bot