Alle UI-Labels, Dateinamen, API-Bezeichner und package.json auf OnyvaLeads umgestellt. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { prisma } from "@/lib/db";
|
|
import * as XLSX from "xlsx";
|
|
|
|
export async function GET(
|
|
req: NextRequest,
|
|
{ params }: { params: Promise<{ jobId: string }> }
|
|
) {
|
|
try {
|
|
const { jobId } = await params;
|
|
const job = await prisma.job.findUnique({
|
|
where: { id: jobId },
|
|
include: { results: { orderBy: { createdAt: "asc" } } },
|
|
});
|
|
|
|
if (!job) return NextResponse.json({ error: "Job not found" }, { status: 404 });
|
|
|
|
const rows = job.results.map(r => ({
|
|
"Unternehmen": r.companyName || "",
|
|
"Domain": r.domain || "",
|
|
"Kontaktname": r.contactName || "",
|
|
"Position": r.contactTitle || "",
|
|
"E-Mail": r.email || "",
|
|
}));
|
|
|
|
const ws = XLSX.utils.json_to_sheet(rows);
|
|
const wb = XLSX.utils.book_new();
|
|
XLSX.utils.book_append_sheet(wb, ws, "Leads");
|
|
const arr = XLSX.write(wb, { type: "array", bookType: "xlsx" });
|
|
|
|
return new NextResponse(new Uint8Array(arr), {
|
|
headers: {
|
|
"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
"Content-Disposition": `attachment; filename="onyva-leads-${job.type}-${jobId.slice(0, 8)}.xlsx"`,
|
|
},
|
|
});
|
|
} catch (err) {
|
|
console.error("GET /api/export/[jobId] error:", err);
|
|
return NextResponse.json({ error: "Failed to export" }, { status: 500 });
|
|
}
|
|
}
|