diff --git a/app/api/my/rigs/[id]/route.ts b/app/api/my/rigs/[id]/route.ts index 9401b4ab..fa630313 100644 --- a/app/api/my/rigs/[id]/route.ts +++ b/app/api/my/rigs/[id]/route.ts @@ -2,47 +2,60 @@ import { NextRequest, NextResponse } from "next/server"; import { cookies } from "next/headers"; import { directusFetch } from "@/lib/directus"; -const BASE_COLLECTION = "user_rigs"; +const BASE_COLLECTION = "rigs"; // change if your collection name differs async function bearerFromCookies() { - // In Next 15, types may represent `cookies()` as async—await it to satisfy TS. + // Some Next 15 type defs model cookies() as async—await to satisfy TS in all envs. const store = await cookies(); const at = store.get("ma_at")?.value; if (!at) throw new Error("Not authenticated"); return `Bearer ${at}`; } -export async function PATCH(req: NextRequest, ctx: { params: { id: string } }) { +export async function PATCH(req: NextRequest, { params }: any) { try { const auth = await bearerFromCookies(); const body = await req.json(); + const id = params?.id; + if (!id) return NextResponse.json({ error: "Missing id" }, { status: 400 }); - const data = await directusFetch<{ data: any }>(`/items/${BASE_COLLECTION}/${ctx.params.id}`, { - method: "PATCH", - headers: { - "Content-Type": "application/json", - Authorization: auth, // overrides submit token in helper - }, - body: JSON.stringify(body), - }); + const data = await directusFetch<{ data: any }>( + `/items/${BASE_COLLECTION}/${id}`, + { + method: "PATCH", + headers: { + "Content-Type": "application/json", + Authorization: auth, // overrides helper's default token + }, + body: JSON.stringify(body), + } + ); return NextResponse.json({ ok: true, data: data.data }); } catch (err: any) { - return NextResponse.json({ error: err?.message || "Update failed" }, { status: 400 }); + return NextResponse.json( + { error: err?.message || "Update failed" }, + { status: 400 } + ); } } -export async function DELETE(_req: NextRequest, ctx: { params: { id: string } }) { +export async function DELETE(_req: NextRequest, { params }: any) { try { const auth = await bearerFromCookies(); + const id = params?.id; + if (!id) return NextResponse.json({ error: "Missing id" }, { status: 400 }); - await directusFetch(`/items/${BASE_COLLECTION}/${ctx.params.id}`, { + await directusFetch(`/items/${BASE_COLLECTION}/${id}`, { method: "DELETE", headers: { Authorization: auth }, }); return NextResponse.json({ ok: true }); } catch (err: any) { - return NextResponse.json({ error: err?.message || "Delete failed" }, { status: 400 }); + return NextResponse.json( + { error: err?.message || "Delete failed" }, + { status: 400 } + ); } }