feat: LeadVault - zentrale Lead-Datenbank mit CRM-Funktionen

- Prisma-Schema: Lead + LeadEvent Modelle (Migration 20260320)
- lib/services/leadVault.ts: sinkLeadsToVault mit Deduplizierung
- Auto-Sync: alle 4 Pipelines schreiben Leads in LeadVault
- GET /api/leads: Filter, Sortierung, Pagination (Server-side)
- PATCH/DELETE /api/leads/[id]: Status, Priorität, Tags, Notizen
- POST /api/leads/bulk: Bulk-Aktionen für mehrere Leads
- GET /api/leads/stats: Statistiken + 7-Tage-Sparkline
- POST /api/leads/quick-serp: SERP-Capture ohne Enrichment
- GET /api/leads/export: CSV-Export mit allen Feldern
- app/leadvault/page.tsx: vollständige UI mit Stats, Quick SERP,
  Filter-Leiste, sortierbare Tabelle, Bulk-Aktionen, Side Panel
- Sidebar: LeadVault-Eintrag mit Live-Badge (neue Leads)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Timo Uttenweiler
2026-03-20 17:33:12 +01:00
parent 6711633a5d
commit 042fbeb672
16 changed files with 1800 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { getApiKey } from "@/lib/utils/apiKey";
import { sinkLeadsToVault } from "@/lib/services/leadVault";
import {
submitBulkPersonSearch,
getBulkSearchStatus,
@@ -150,6 +151,23 @@ async function runLinkedInEnrich(
where: { id: enrichJobId },
data: { status: "complete", emailsFound },
});
// Sync final state to LeadVault
const finalResults = await prisma.leadResult.findMany({ where: { jobId: enrichJobId } });
await sinkLeadsToVault(
finalResults.map(r => ({
domain: r.domain,
companyName: r.companyName,
contactName: r.contactName,
contactTitle: r.contactTitle,
email: r.email,
linkedinUrl: r.linkedinUrl,
emailConfidence: r.confidence,
})),
"linkedin",
undefined,
enrichJobId,
);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
await prisma.job.update({