Files
workparking/app/api/leads/[id]/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

43 lines
1.0 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";
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 }
);
}
}