import { revalidatePath } from "next/cache"; import { serverAuth } from "@/lib/pb"; export const dynamic = "force-dynamic"; // DELETE /api/purchases/:id/invoices/:invoiceId — remove a supplier invoice from a PO. export async function DELETE( _req: Request, { params }: { params: Promise<{ id: string; invoiceId: string }> }, ) { const { id, invoiceId } = await params; try { const pb = await serverAuth(); const inv = await pb.collection("purchase_invoices").getOne(invoiceId).catch(() => null); if (!inv || inv.purchase !== id) { return Response.json({ ok: false, error: "Invoice not found on that purchase order" }, { status: 404 }); } await pb.collection("purchase_invoices").delete(invoiceId); revalidatePath("/running/purchases"); return Response.json({ ok: true }); } catch (e: any) { return Response.json({ ok: false, error: e?.message || "Could not delete the invoice" }, { status: 500 }); } }