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 } + ); + } +}