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:
@@ -19,8 +19,12 @@ route('player/:steamId/card-levels', ['PUT'], (ctx: HandlerContext) => {
|
|||||||
|
|
||||||
route('player/:steamId/decks', ['GET'], (ctx: HandlerContext) => {
|
route('player/:steamId/decks', ['GET'], (ctx: HandlerContext) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const decks = db.prepare('SELECT * FROM decks WHERE steam_id = ? ORDER BY deck_index').all(ctx.params.steamId);
|
const rows = db.prepare('SELECT * FROM decks WHERE steam_id = ? ORDER BY deck_index').all(ctx.params.steamId) as any[];
|
||||||
return decks.map((d: any) => ({ ...d, cards: JSON.parse(d.cards || '[]') }));
|
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) => {
|
route('player/:steamId/decks/:index', ['GET'], (ctx: HandlerContext) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user