добавлена форма заявки тестовая, тестовая сттраница crm база данных
Some checks failed
Auto Deploy / deploy (push) Failing after 45s
Some checks failed
Auto Deploy / deploy (push) Failing after 45s
This commit is contained in:
58
app/api/leads/route.ts
Normal file
58
app/api/leads/route.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
type LeadPayload = {
|
||||
company?: string;
|
||||
phone?: 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 message = body.message?.trim() || "";
|
||||
|
||||
if (!company || !phone) {
|
||||
return NextResponse.json(
|
||||
{ error: "Компания и телефон обязательны" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const lead = await prisma.lead.create({
|
||||
data: {
|
||||
company,
|
||||
phone,
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const leads = await prisma.lead.findMany({
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return NextResponse.json(leads);
|
||||
} catch (error) {
|
||||
console.error("GET /api/leads error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Не удалось получить заявки" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user