feat: v0.8.0 — player-actions API: accept/dispatch/buy/sell/refuel endpoints (tick-first, full-snapshot responses), spawn coverage rule, test create-contract hook
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { buyPlane, performAction } from '@/lib/game/actions';
|
||||
|
||||
// POST /api/market/buy-plane (v0.8.0) — body { model: string }. Buys a catalog
|
||||
// aircraft at full price; it arrives 'available' with a full tank at the home base
|
||||
// (EDDF). 400 missing/non-string model or unknown catalog model; 409 insufficient
|
||||
// funds. On success returns the full state snapshot (new plane + reduced cash).
|
||||
|
||||
export async function POST(req: Request) {
|
||||
let body: unknown;
|
||||
try {
|
||||
const text = await req.text();
|
||||
body = text ? JSON.parse(text) : {};
|
||||
} catch {
|
||||
return Response.json({ error: 'invalid JSON body' }, { status: 400 });
|
||||
}
|
||||
if (typeof body !== 'object' || body === null || Array.isArray(body)) {
|
||||
return Response.json({ error: 'body must be a JSON object' }, { status: 400 });
|
||||
}
|
||||
const input = body as Record<string, unknown>;
|
||||
for (const key of Object.keys(input)) {
|
||||
if (key !== 'model') {
|
||||
return Response.json({ error: `unknown field "${key}"` }, { status: 400 });
|
||||
}
|
||||
}
|
||||
if (typeof input.model !== 'string' || input.model.length === 0) {
|
||||
return Response.json({ error: 'model must be a non-empty string' }, { status: 400 });
|
||||
}
|
||||
|
||||
const model = input.model;
|
||||
return performAction((inst) => buyPlane(inst, model));
|
||||
}
|
||||
Reference in New Issue
Block a user