16 lines
884 B
TypeScript
16 lines
884 B
TypeScript
import { NextRequest } from "next/server";
|
|
import { dFetchJSON, applyQFilter, json, Option } from "../_lib";
|
|
|
|
type Row = { id: number | string; name?: string | null; focal_length?: number | string | null; field_size?: number | string | null };
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const q = new URL(req.url).searchParams.get("q");
|
|
const { data } = await dFetchJSON<{ data: Row[] }>(req, "/items/laser_scan_lens?fields=id,name,focal_length,field_size&limit=1000&sort=name");
|
|
const options: Option[] = data.map((r) => {
|
|
const fl = r.focal_length != null ? `${r.focal_length}` : "";
|
|
const fs = r.field_size != null ? `${r.field_size}` : "";
|
|
const composed = r.name ?? [fl && `${fl} mm`, fs && `${fs} mm`].filter(Boolean).join(" — ") || String(r.id);
|
|
return { id: r.id, label: composed };
|
|
});
|
|
return json(applyQFilter(options, q, (o) => o.label));
|
|
}
|