1import { guard } from "./rate-limit";
2import { db } from "@/lib/db";
3
4// POST /api/invoices — create a draft invoice for a customer
5export async function POST(req: Request) {
6 const blocked = await guard(req);
7 if (blocked) return blocked;
8
9 const body = await req.json();
10 if (!body.customerId) {
11 return Response.json({ error: "customerId is required" }, { status: 400 });
12 }
13
14 const invoice = await db.invoice.create({
15 data: {
16 customerId: body.customerId,
17 currency: body.currency ?? "EUR",
18 lines: body.lines ?? [],
19 status: "draft",
20 },
21 });
22
23 return Response.json(invoice, { status: 201 });
24}