fix: add missing chat_wheel and arcade_pity handlers
Game client saves/loads chat_wheel and arcade_pity data via GET/PUT but backend had no routes, causing silent data loss on restart (same pattern as the purchases bug). Added schema columns, migrations, and routes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,8 @@ function initSchema(db: Database.Database) {
|
||||
dust_currency INTEGER DEFAULT 0,
|
||||
arcade_pack_credits TEXT DEFAULT '{"standard":0,"premium":0}',
|
||||
sounds_wheel TEXT DEFAULT '{}',
|
||||
chat_wheel TEXT DEFAULT '{}',
|
||||
arcade_pity TEXT DEFAULT '{}',
|
||||
created_at TEXT DEFAULT (datetime('now')),
|
||||
updated_at TEXT DEFAULT (datetime('now'))
|
||||
);
|
||||
@@ -209,4 +211,8 @@ function initSchema(db: Database.Database) {
|
||||
updated_at TEXT DEFAULT (datetime('now'))
|
||||
);
|
||||
`);
|
||||
|
||||
// Migrations for columns added after initial schema
|
||||
try { db.exec("ALTER TABLE players ADD COLUMN chat_wheel TEXT DEFAULT '{}'"); } catch {}
|
||||
try { db.exec("ALTER TABLE players ADD COLUMN arcade_pity TEXT DEFAULT '{}'"); } catch {}
|
||||
}
|
||||
|
||||
@@ -154,6 +154,40 @@ route('player/:steamId/sounds_wheel', ['PUT'], (ctx: HandlerContext) => {
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
// GET /player/:steamId/chat_wheel — Get chat wheel
|
||||
route('player/:steamId/chat_wheel', ['GET'], (ctx: HandlerContext) => {
|
||||
const db = getDb();
|
||||
const player = db.prepare('SELECT chat_wheel FROM players WHERE steam_id = ?').get(ctx.params.steamId) as any;
|
||||
if (!player) throw new HttpError(404, 'Player not found');
|
||||
return { chat_wheel: JSON.parse(player.chat_wheel || '{}') };
|
||||
});
|
||||
|
||||
// PUT /player/:steamId/chat_wheel — Save chat wheel
|
||||
route('player/:steamId/chat_wheel', ['PUT'], (ctx: HandlerContext) => {
|
||||
const { chat_wheel } = ctx.body as any;
|
||||
const db = getDb();
|
||||
db.prepare("UPDATE players SET chat_wheel = ?, updated_at = datetime('now') WHERE steam_id = ?")
|
||||
.run(JSON.stringify(chat_wheel || {}), ctx.params.steamId);
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
// GET /player/:steamId/arcade_pity — Get arcade pity data
|
||||
route('player/:steamId/arcade_pity', ['GET'], (ctx: HandlerContext) => {
|
||||
const db = getDb();
|
||||
const player = db.prepare('SELECT arcade_pity FROM players WHERE steam_id = ?').get(ctx.params.steamId) as any;
|
||||
if (!player) throw new HttpError(404, 'Player not found');
|
||||
return { arcade_pity: JSON.parse(player.arcade_pity || '{}') };
|
||||
});
|
||||
|
||||
// PUT /player/:steamId/arcade_pity — Save arcade pity data
|
||||
route('player/:steamId/arcade_pity', ['PUT'], (ctx: HandlerContext) => {
|
||||
const { arcade_pity } = ctx.body as any;
|
||||
const db = getDb();
|
||||
db.prepare("UPDATE players SET arcade_pity = ?, updated_at = datetime('now') WHERE steam_id = ?")
|
||||
.run(JSON.stringify(arcade_pity || {}), ctx.params.steamId);
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
// POST /player/:steamId/deal-purchase — Buy a deal/offer
|
||||
route('player/:steamId/deal-purchase', ['POST'], (ctx: HandlerContext) => {
|
||||
const { deal_key } = ctx.body as any;
|
||||
|
||||
Reference in New Issue
Block a user