From 5c4b7eaa270efe7f74b635e664baa0da3ce1c840 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Wed, 12 Nov 2025 03:34:44 +0000 Subject: [PATCH] Nexus Admin - Dispute Resolution Endpoint cgen-07f4232d4af9498e89a7201b372ea4f9 --- api/admin/nexus/disputes/[id].ts | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 api/admin/nexus/disputes/[id].ts diff --git a/api/admin/nexus/disputes/[id].ts b/api/admin/nexus/disputes/[id].ts new file mode 100644 index 00000000..ce968b51 --- /dev/null +++ b/api/admin/nexus/disputes/[id].ts @@ -0,0 +1,46 @@ +import { createClient } from "@supabase/supabase-js"; + +const supabase = createClient( + process.env.VITE_SUPABASE_URL!, + process.env.SUPABASE_SERVICE_ROLE! +); + +export default async function handler(req: any, res: any) { + const { id } = req.query; + + if (req.method === "PUT") { + try { + const { status, resolution_notes } = req.body; + + if (!["open", "reviewing", "resolved", "escalated"].includes(status)) { + return res.status(400).json({ error: "Invalid status" }); + } + + const updateData: any = { + status, + resolution_notes, + resolved_by: req.user?.id, // Assumes middleware sets req.user + }; + + if (status === "resolved" || status === "escalated") { + updateData.resolved_at = new Date().toISOString(); + } + + const { data, error } = await supabase + .from("nexus_disputes") + .update(updateData) + .eq("id", id) + .select(); + + if (error) throw error; + + res.status(200).json(data); + } catch (error: any) { + res + .status(500) + .json({ error: error.message || "Failed to update dispute" }); + } + } else { + res.status(405).json({ error: "Method not allowed" }); + } +}