Files
workparking/app/api/leads/route.ts
deonisii 4f67bca4be
All checks were successful
Auto Deploy / deploy (push) Successful in 1m7s
add crm auth, email, status update and search
2026-04-17 21:29:14 +03:00

45 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
type LeadPayload = {
company?: string;
phone?: string;
email?: string;
message?: string;
};
export async function POST(request: Request) {
try {
const body = (await request.json()) as LeadPayload;
const company = body.company?.trim();
const phone = body.phone?.trim();
const email = body.email?.trim().toLowerCase();
const message = body.message?.trim() || "";
if (!company || !phone || !email) {
return NextResponse.json(
{ error: "Компания, телефон и email обязательны" },
{ status: 400 }
);
}
const lead = await prisma.lead.create({
data: {
company,
phone,
email,
message,
source: "website",
},
});
return NextResponse.json({ success: true, leadId: lead.id }, { status: 201 });
} catch (error) {
console.error("POST /api/leads error:", error);
return NextResponse.json(
{ error: "Не удалось сохранить заявку" },
{ status: 500 }
);
}
}