routing fixes
This commit is contained in:
parent
0ee9686fb1
commit
44a690f4d2
20 changed files with 769 additions and 962 deletions
|
|
@ -1,26 +1,11 @@
|
|||
export const dynamic = "force-dynamic";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { NextRequest } from "next/server";
|
||||
import { dFetchJSON, applyQFilter, json, Option } from "../_lib";
|
||||
|
||||
const BASE = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
|
||||
const PATH = `/items/laser_focus_lens?fields=id,name&sort=name`;
|
||||
type Row = { id: number | string; name?: string | null };
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const userAt = req.cookies.get("ma_at")?.value;
|
||||
if (!userAt) return NextResponse.json({ error: "Not authenticated" }, { status: 401 });
|
||||
|
||||
const res = await fetch(`${BASE}${PATH}`, {
|
||||
headers: { Accept: "application/json", Authorization: `Bearer ${userAt}` },
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const txt = await res.text();
|
||||
if (!res.ok) return NextResponse.json({ error: txt || res.statusText }, { status: res.status });
|
||||
|
||||
const j = txt ? JSON.parse(txt) : { data: [] };
|
||||
const data = (j.data ?? []).map(({ id, name }: any) => ({ id, name }));
|
||||
return NextResponse.json({ data });
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e?.message || "Failed to load focus lenses" }, { status: 500 });
|
||||
}
|
||||
const q = new URL(req.url).searchParams.get("q");
|
||||
const { data } = await dFetchJSON<{ data: Row[] }>(req, "/items/laser_focus_lens?fields=id,name&limit=1000&sort=name");
|
||||
const options: Option[] = data.map((r) => ({ id: r.id, label: r.name ?? String(r.id) }));
|
||||
return json(applyQFilter(options, q, (o) => o.label));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue