From 2ca87af1b5ba8d3d4ea7acfb0654a76b682d4096 Mon Sep 17 00:00:00 2001 From: achmad Date: Sat, 30 May 2026 03:54:04 +0700 Subject: [PATCH] fix: return decks as map keyed by deck_index Game client Lua expects GET /decks to return a map of {deck_index: {name, cards}} not a flat array. Array format caused self.decks to be set to wrong structure, breaking deck lookups and triggering phantom deck creation on every interaction. Co-Authored-By: Claude Opus 4.8 (1M context) --- backend/src/lib/handlers/cards.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/lib/handlers/cards.ts b/backend/src/lib/handlers/cards.ts index 11dd13f..40e60a2 100644 --- a/backend/src/lib/handlers/cards.ts +++ b/backend/src/lib/handlers/cards.ts @@ -19,8 +19,12 @@ route('player/:steamId/card-levels', ['PUT'], (ctx: HandlerContext) => { route('player/:steamId/decks', ['GET'], (ctx: HandlerContext) => { const db = getDb(); - const decks = db.prepare('SELECT * FROM decks WHERE steam_id = ? ORDER BY deck_index').all(ctx.params.steamId); - return decks.map((d: any) => ({ ...d, cards: JSON.parse(d.cards || '[]') })); + const rows = db.prepare('SELECT * FROM decks WHERE steam_id = ? ORDER BY deck_index').all(ctx.params.steamId) as any[]; + const decks: Record = {}; + for (const r of rows) { + decks[r.deck_index] = { name: r.name, cards: JSON.parse(r.cards || '[]') }; + } + return { decks }; }); route('player/:steamId/decks/:index', ['GET'], (ctx: HandlerContext) => {