added rig_type route
This commit is contained in:
parent
a2ec2fa52c
commit
77e30981c3
1 changed files with 29 additions and 0 deletions
29
app/api/options/rig_type/route.ts
Normal file
29
app/api/options/rig_type/route.ts
Normal 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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue