Files
Atlas/app/api/bookings/[id]/confirmation-pdf/route.ts
Julia Wehden 08effe4e80
Some checks failed
Preview Deploy / deploy (push) Failing after 1m49s
fix: Build-Fehler behoben (Import + Buffer Type)
2026-03-20 10:52:06 +01:00

55 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import { prisma } from '@/lib/prisma';
import { lexofficeService } from '@/lib/lexoffice';
export async function GET(
request: NextRequest,
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session || session.user.role !== 'ADMIN') {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const bookingId = params.id;
const booking = await prisma.booking.findUnique({
where: { id: bookingId },
select: {
id: true,
bookingNumber: true,
lexofficeConfirmationId: true,
},
});
if (!booking) {
return NextResponse.json({ error: 'Buchung nicht gefunden' }, { status: 404 });
}
if (!booking.lexofficeConfirmationId) {
return NextResponse.json({ error: 'Keine Auftragsbestätigung vorhanden' }, { status: 404 });
}
const pdfBuffer = await lexofficeService.getInvoicePDF(booking.lexofficeConfirmationId);
return new NextResponse(new Uint8Array(pdfBuffer), {
status: 200,
headers: {
'Content-Type': 'application/pdf',
'Content-Disposition': `attachment; filename="Auftragsbestaetigung_${booking.bookingNumber}.pdf"`,
},
});
} catch (error: any) {
console.error('❌ PDF-Download Fehler:', error);
return NextResponse.json(
{ error: error.message || 'PDF-Download fehlgeschlagen' },
{ status: 500 }
);
}
}