import { NextResponse, type NextRequest } from "next/server"; import { callMobileApi } from "@/app/lib/server/mobileApi"; import { getToken } from "@/app/lib/server/session"; import { errorResponse, unauthorized, badRequest } from "@/app/lib/server/apiRoute"; import type { BankRow } from "@/app/lib/types"; // GET/POST -> /api/admin/reference/bank (add-admin-bank-reference). Forwards the admin JWT from // the bb_admin session cookie. GET is a pure read, so a Next.js prefetch can never mutate // anything. Downstream 404/409/422 messages pass through verbatim so the Bank tab can show the // reason inline and keep its dialog open. export async function GET(req: NextRequest) { const token = await getToken(); if (!token) return unauthorized(); const countryCode = new URL(req.url).searchParams.get("countryCode"); if (!countryCode) return badRequest("countryCode is required."); const result = await callMobileApi( `/api/admin/reference/bank?countryCode=${encodeURIComponent(countryCode)}`, { token }, ); if (!result.ok) return errorResponse(result); return NextResponse.json(result.data); } export async function POST(req: NextRequest) { const token = await getToken(); if (!token) return unauthorized(); const body = await req.json().catch(() => ({})); const { code, name, countryCode } = body as Partial; if (!code || !name || !countryCode) { return badRequest("code, name and countryCode are required."); } const result = await callMobileApi("/api/admin/reference/bank", { method: "POST", body, token, }); if (!result.ok) return errorResponse(result); return NextResponse.json(result.data); }