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) <noreply@anthropic.com>
This commit is contained in:
achmad
2026-05-30 03:54:04 +07:00
parent e50b0fa46d
commit 2ca87af1b5
+6 -2
View File
@@ -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<string, any> = {};
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) => {