- Schema: companyType, topics, salesScore, salesReason, offerPackage, approved, approvedAt, SearchHistory table - /api/search-history: GET (by mode) + POST (save query) - /api/ai-search: stadtwerke/industrie/custom prompts with history dedup - /api/enrich-leads: website scraping + GPT-4o-mini enrichment (fire-and-forget after each job) - /api/generate-email: personalized outreach via GPT-4o - Suche page: 3 mode tabs (Stadtwerke/Industrie/Freie Suche), Alle-Bundesländer queue button, AiSearchModal gets searchMode + history - Leadspeicher: Bewertung dots column, Paket badge column, Freigeben toggle button, email generator in SidePanel, approved-only export option - Leads API: approvedOnly + companyType filters, new fields in PATCH Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { prisma } from "@/lib/db";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(req.url);
|
|
const mode = searchParams.get("mode") || "";
|
|
|
|
const where = mode ? { searchMode: mode } : {};
|
|
|
|
const history = await prisma.searchHistory.findMany({
|
|
where,
|
|
orderBy: { executedAt: "desc" },
|
|
take: 50,
|
|
select: { query: true, region: true, searchMode: true, executedAt: true },
|
|
});
|
|
|
|
return NextResponse.json(history);
|
|
} catch (err) {
|
|
console.error("GET /api/search-history error:", err);
|
|
return NextResponse.json({ error: "Failed to fetch search history" }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function POST(req: NextRequest) {
|
|
try {
|
|
const body = await req.json() as { query: string; region: string; searchMode: string };
|
|
const { query, region, searchMode } = body;
|
|
|
|
if (!query?.trim() || !searchMode?.trim()) {
|
|
return NextResponse.json({ error: "query und searchMode sind erforderlich" }, { status: 400 });
|
|
}
|
|
|
|
const entry = await prisma.searchHistory.create({
|
|
data: {
|
|
query: query.trim(),
|
|
region: (region || "").trim(),
|
|
searchMode: searchMode.trim(),
|
|
},
|
|
});
|
|
|
|
return NextResponse.json(entry);
|
|
} catch (err) {
|
|
console.error("POST /api/search-history error:", err);
|
|
return NextResponse.json({ error: "Failed to save search history" }, { status: 500 });
|
|
}
|
|
}
|