see comments

This commit is contained in:
Rajpreet0 2026-09-29 13:46:50 +02:00
parent 0d1eb75127
commit c7c7c47ad7
9 changed files with 65 additions and 18 deletions

View file

@ -15,8 +15,13 @@ export async function GET(request: NextRequest) {
const parsed = IdsSchema.safeParse(request.nextUrl.searchParams.getAll("id"))
if (!parsed.success) return Response.json({ error: "Ungültige Auswahl." }, { status: 400 })
const invoices = await getInvoicesForPdf(parsed.data)
const requestedIds = [...new Set(parsed.data)]
const invoices = await getInvoicesForPdf(requestedIds)
if (invoices.length === 0) return Response.json({ error: "Keine Rechnungen gefunden." }, { status: 404 })
// RLS filtert unerlaubte/stornierte Rechnungen stillschweigend raus – dann lieber gar nichts liefern als ein unvollständiges ZIP.
if (invoices.length !== requestedIds.length) {
return Response.json({ error: "Nicht alle ausgewählten Rechnungen sind verfügbar." }, { status: 404 })
}
if (invoices.length === 1) {
const pdf = await renderInvoicePdf(invoices[0])