import { getAlertById, closeAlert, reopenAlert } from "@/lib/db"; export async function GET( _req: Request, { params }: { params: Promise<{ id: string }> } ) { const { id } = await params; const alert = getAlertById(Number(id)); if (!alert) { return Response.json({ error: "Alert not found" }, { status: 404 }); } return Response.json(alert); } export async function PATCH( req: Request, { params }: { params: Promise<{ id: string }> } ) { const { id } = await params; const numId = Number(id); let body: { status: string }; try { body = await req.json(); } catch { return Response.json({ error: "Invalid JSON" }, { status: 400 }); } if (body.status === "closed") { const updated = closeAlert(numId); if (!updated) return Response.json({ error: "Alert not found" }, { status: 404 }); return Response.json(updated); } if (body.status === "open") { const updated = reopenAlert(numId); if (!updated) return Response.json({ error: "Alert not found" }, { status: 404 }); return Response.json(updated); } return Response.json({ error: "status must be 'open' or 'closed'" }, { status: 400 }); }