diff --git a/backend/src/lib/db.ts b/backend/src/lib/db.ts index f2542f3..c89eeac 100644 --- a/backend/src/lib/db.ts +++ b/backend/src/lib/db.ts @@ -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 {} } diff --git a/backend/src/lib/handlers/player.ts b/backend/src/lib/handlers/player.ts index 9af115d..6b949b0 100644 --- a/backend/src/lib/handlers/player.ts +++ b/backend/src/lib/handlers/player.ts @@ -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;