makearmy-app/app/api/options/material_opacity/route.ts

13 lines
619 B
TypeScript
Raw Normal View History

2025-09-28 14:54:52 -04:00
import { NextRequest } from "next/server";
import { dFetchJSON, applyQFilter, json, Option } from "../_lib";
2025-09-28 11:15:37 -04:00
2025-09-28 14:54:52 -04:00
type Row = { id: number | string; opacity?: string | null };
2025-09-28 11:15:37 -04:00
export async function GET(req: NextRequest) {
2025-09-28 14:54:52 -04:00
const q = new URL(req.url).searchParams.get("q");
// Ensure role can read id,opacity on this collection.
const { data } = await dFetchJSON<{ data: Row[] }>(req, "/items/material_opacity?fields=id,opacity&limit=1000&sort=opacity");
const options: Option[] = data.map((r) => ({ id: r.id, label: r.opacity ?? String(r.id) }));
return json(applyQFilter(options, q, (o) => o.label));
2025-09-28 11:15:37 -04:00
}