route.ts.diff
TypeScriptPull request
--- a/app/api/invoices/export/route.ts
+++ b/app/api/invoices/export/route.ts
@@ -0,0 +1,17 @@
+import { NextRequest } from "next/server";
+import { db } from "@/lib/db";
+
+export async function GET(req: NextRequest) {
+ const userId = req.nextUrl.searchParams.get("userId");
+ const invoices = await db.invoice.findMany({
+ where: { ownerId: userId ?? undefined },
+ });
+ const rows = invoices.map((i) => [i.id, i.amountMinor, i.issuedAt.toISOString()].join(","));
+ return new Response(["id,amount,issued", ...rows].join("\n"), {
+ headers: { "Content-Type": "text/csv" },
+ });
+}