26 lines
951 B
TypeScript
26 lines
951 B
TypeScript
/**
|
|
* POST /api/admin/credit { handle, amount }
|
|
* Manually adds VOID credits to a handle (operator use only).
|
|
*/
|
|
|
|
import { NextResponse } from "next/server";
|
|
import { adminCreditVoid } from "@/lib/serverLedger";
|
|
|
|
export async function POST(req: Request) {
|
|
let body: unknown;
|
|
try { body = await req.json(); } catch {
|
|
return NextResponse.json({ ok: false, error: "Invalid JSON" }, { status: 400 });
|
|
}
|
|
|
|
const { handle, amount } = (body as Record<string, unknown>) ?? {};
|
|
if (typeof handle !== "string" || !handle.trim())
|
|
return NextResponse.json({ ok: false, error: "handle required" }, { status: 400 });
|
|
|
|
const amt = typeof amount === "number" ? Math.floor(amount) : 0;
|
|
if (amt <= 0)
|
|
return NextResponse.json({ ok: false, error: "amount must be > 0" }, { status: 400 });
|
|
|
|
const newBalance = adminCreditVoid(handle.trim(), amt);
|
|
return NextResponse.json({ ok: true, handle: handle.trim().toLowerCase(), newBalance });
|
|
}
|