dxGet fix for rigs

This commit is contained in:
makearmy 2025-09-29 20:46:41 -04:00
parent 719680c8dc
commit e252a84862
2 changed files with 11 additions and 22 deletions

View file

@ -1,4 +1,4 @@
// app/api/my/rigs/route.ts
// app/api/rigs/route.ts
import { NextResponse } from "next/server";
import { dxGET, dxPOST, dxDELETE } from "@/lib/directus";
import { requireBearer } from "@/app/api/_lib/auth";
@ -43,9 +43,8 @@ export async function GET(req: Request) {
`&sort=-date_updated` +
`&limit=${limit}`;
// ⬇️ dxGET already returns the unwrapped `data`
// dxGET already returns the unwrapped `data` array
const rows = await dxGET<any[]>(path, bearer);
return NextResponse.json(rows ?? []);
} catch (e: any) {
return bad(e?.message || "Failed to load rigs", e?.status || 500);
@ -58,7 +57,7 @@ export async function POST(req: Request) {
const body = await req.json().catch(() => ({}));
const name = (body?.name || "").trim();
const rig_type = body?.rig_type; // id
const rig_type = body?.rig_type; // id
const laser_source = body?.laser_source; // submission_id
const laser_scan_lens = body?.laser_scan_lens || null;
const laser_focus_lens = body?.laser_focus_lens || null;
@ -69,7 +68,7 @@ export async function POST(req: Request) {
if (!rig_type) return bad("Missing: rig_type");
if (!laser_source) return bad("Missing: laser_source");
// Derive owner from authd user; ignore any spoofed owner in body
// set owner from the authenticated user
const me = await dxGET<{ id: string }>("/users/me?fields=id", bearer);
const payload: any = {
@ -102,7 +101,7 @@ export async function DELETE(req: Request) {
const id = url.searchParams.get("id");
if (!id) return bad("Missing: id");
// Hard-guard: ensure the rig belongs to the current user
// ensure the rig belongs to the current user
const me = await dxGET<{ id: string }>("/users/me?fields=id", bearer);
const rig = await dxGET<any>(
`/items/user_rigs/${encodeURIComponent(id)}?fields=id,owner`,