add crm auth, email, status update and search
All checks were successful
Auto Deploy / deploy (push) Successful in 1m7s
All checks were successful
Auto Deploy / deploy (push) Successful in 1m7s
This commit is contained in:
43
app/api/leads/[id]/route.ts
Normal file
43
app/api/leads/[id]/route.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
const allowedStatuses = [
|
||||
"NEW",
|
||||
"IN_PROGRESS",
|
||||
"CALL_SCHEDULED",
|
||||
"WON",
|
||||
"LOST",
|
||||
] as const;
|
||||
|
||||
type LeadStatus = (typeof allowedStatuses)[number];
|
||||
|
||||
type PatchPayload = {
|
||||
status?: LeadStatus;
|
||||
};
|
||||
|
||||
export async function PATCH(
|
||||
request: Request,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await context.params;
|
||||
const body = (await request.json()) as PatchPayload;
|
||||
|
||||
if (!body.status || !allowedStatuses.includes(body.status)) {
|
||||
return NextResponse.json({ error: "Некорректный статус" }, { status: 400 });
|
||||
}
|
||||
|
||||
const lead = await prisma.lead.update({
|
||||
where: { id },
|
||||
data: { status: body.status },
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, lead });
|
||||
} catch (error) {
|
||||
console.error("PATCH /api/leads/[id] error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Не удалось обновить статус" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user