feat: add equipment handler

This commit is contained in:
achmad
2026-05-29 16:41:50 +07:00
parent ee09d4037c
commit a1129f6e6d
+22
View File
@@ -0,0 +1,22 @@
import { route, HandlerContext, HttpError } from '@/lib/router';
import { getDb } from '@/lib/db';
route('player/:steamId/equipment', ['GET'], (ctx: HandlerContext) => {
const db = getDb();
const row = db.prepare('SELECT equipment FROM equipment WHERE steam_id = ?').get(ctx.params.steamId) as any;
return { equipment: row ? JSON.parse(row.equipment) : {} };
});
route('player/:steamId/equipment', ['PUT'], (ctx: HandlerContext) => {
const { equipment } = ctx.body as any;
const db = getDb();
db.prepare(`
INSERT INTO equipment (steam_id, equipment, updated_at) VALUES (?, ?, datetime('now'))
ON CONFLICT(steam_id) DO UPDATE SET equipment = ?, updated_at = datetime('now')
`).run(ctx.params.steamId, JSON.stringify(equipment || {}), JSON.stringify(equipment || {}));
return { success: true };
});
route('player/:steamId/equipment/drop', ['POST'], (ctx: HandlerContext) => {
return { success: true };
});