added rig_type route

This commit is contained in:
makearmy 2025-09-27 10:54:01 -04:00
parent a2ec2fa52c
commit 77e30981c3

View file

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