import { NextResponse, type NextRequest } from "next/server"; import { callMobileApi } from "@/app/lib/server/mobileApi"; import { getToken } from "@/app/lib/server/session"; import { badRequest, errorResponse, unauthorized } from "@/app/lib/server/apiRoute"; import type { AdminTopupRow } from "@/app/lib/types"; // POST -> /api/admin/topup/reverse { uuid, reason } (BO_WALLET gated upstream; a mutation, never a GET). export async function POST(req: NextRequest) { const token = await getToken(); if (!token) return unauthorized(); let body: unknown; try { body = await req.json(); } catch { return badRequest("Invalid request body"); } const { uuid, reason } = (body ?? {}) as { uuid?: unknown; reason?: unknown }; // uuid is a Snowflake id carried as a string (it exceeds JS's safe-integer range). if (typeof uuid !== "string" || !/^\d+$/.test(uuid)) { return badRequest("Parameter \"uuid\" is required"); } if (typeof reason !== "string" || !reason.trim()) { return badRequest("A reversal reason is required"); } const result = await callMobileApi("/api/admin/topup/reverse", { method: "POST", body: { uuid, reason: reason.trim() }, token, }); if (!result.ok) return errorResponse(result); return NextResponse.json(result.data); }