Files
kamilkrzywda 179fad450d
CI / build + unit + e2e (pull_request) Successful in 8m2s
Package weight, payload capacity and per-kg payout (ISS-045)
Packages carry a real weightKg (unit weight x count with +/-30% jitter),
plane capacity becomes maxPayloadKg instead of 6 slots, load validation
sums cargo weight against the payload, and the payout gains a per-kg part.
Loadout display shows tonnage; OpenAPI swaps CatalogEntry.capacity for
maxPayloadKg and adds PackageState.weightKg.
2026-09-20 12:42:03 +00:00

36 lines
1.4 KiB
TypeScript

import { loadPackage, performAction } from '@/lib/game/actions';
// POST /api/packages/:id/load (v0.12.0) — body { planeId: string }. Loads an OPEN
// package onto a GROUNDED plane at the package's origin with enough payload room
// for its weight (v0.27.0). 400 missing/non-string planeId or unknown fields; 404
// unknown package/plane id; 409 wrong package status, plane flying, plane not at
// the origin, no payload room. On success returns the full state snapshot
// (package now "loaded" on that plane).
export async function POST(req: Request, ctx: { params: Promise<{ id: string }> }) {
const { id } = await ctx.params;
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 !== 'planeId') {
return Response.json({ error: `unknown field "${key}"` }, { status: 400 });
}
}
if (typeof input.planeId !== 'string' || input.planeId.length === 0) {
return Response.json({ error: 'planeId must be a non-empty string' }, { status: 400 });
}
const planeId = input.planeId;
return performAction((inst) => loadPackage(inst, id, planeId));
}