import { addComment } from "@/lib/db"; export async function POST( req: Request, { params }: { params: Promise<{ id: string }> } ) { const { id } = await params; let body: { body: string }; try { body = await req.json(); } catch { return Response.json({ error: "Invalid JSON" }, { status: 400 }); } if (!body.body?.trim()) { return Response.json({ error: "Comment body is required" }, { status: 400 }); } const comment = addComment(Number(id), body.body.trim()); if (!comment) { return Response.json({ error: "Alert not found" }, { status: 404 }); } return Response.json(comment, { status: 201 }); }