From 77e30981c351f6a7a2f112f88ba9c152d4f47515 Mon Sep 17 00:00:00 2001 From: makearmy Date: Sat, 27 Sep 2025 10:54:01 -0400 Subject: [PATCH] added rig_type route --- app/api/options/rig_type/route.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/api/options/rig_type/route.ts diff --git a/app/api/options/rig_type/route.ts b/app/api/options/rig_type/route.ts new file mode 100644 index 00000000..5b22cff2 --- /dev/null +++ b/app/api/options/rig_type/route.ts @@ -0,0 +1,29 @@ +// app/api/options/rig_type/route.ts +import { NextRequest, NextResponse } from "next/server"; +import { directusFetch } from "@/lib/directus"; + +/** + * Returns [{ id, label }] from the Directus collection `user_rig_type`, + * sorted by the `sort` field. Keeping this dedicated route avoids + * depending on the generic [collection] mapping. + */ +export async function GET(_req: NextRequest) { + try { + const res = await directusFetch<{ data: { id: number | string; name: string }[] }>( + `/items/user_rig_type?fields=id,name&sort=sort` + ); + + const items = (res?.data ?? []).map(({ id, name }) => ({ + id, + label: name, + })); + + return NextResponse.json({ data: items }, { status: 200 }); + } catch (e: any) { + // Surface useful error text in case permissions are off + return NextResponse.json( + { error: e?.message || "Failed to load rig types" }, + { status: 500 } + ); + } +}