From ce369e66e324e55ff0244fa6e0047865fbeeec94 Mon Sep 17 00:00:00 2001 From: voyagerxyx Date: Mon, 22 Sep 2025 14:57:41 -0400 Subject: [PATCH] hopefully last lens route fix --- app/api/options/lens/route.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/app/api/options/lens/route.ts b/app/api/options/lens/route.ts index 060d053e..b5fcc97e 100644 --- a/app/api/options/lens/route.ts +++ b/app/api/options/lens/route.ts @@ -2,13 +2,7 @@ import { NextResponse } from "next/server"; import { directusFetch } from "@/lib/directus"; -/** - * Lens options: - * - Fiber / UV / CO2 Galvo -> laser_scan_lens (field_size, focal_length) - * - CO2 Gantry -> laser_focus_lens (focal_length) - * Returns [{ id, label }] using submission_id if present, otherwise id. - */ - +/** Map target to the correct lens collection */ function collectionForTarget( target?: string ): "laser_scan_lens" | "laser_focus_lens" | null { @@ -34,11 +28,11 @@ export async function GET(req: Request) { const coll = collectionForTarget(target); if (!coll) return NextResponse.json({ data: [] }); - // Important: don't request fields that don't exist. + // IMPORTANT: only request fields that exist on each collection. const fields = coll === "laser_scan_lens" - ? "submission_id,id,field_size,focal_length" - : "submission_id,id,focal_length"; + ? "id,field_size,focal_length" + : "id,focal_length"; const url = `/items/${coll}?fields=${encodeURIComponent( fields @@ -48,7 +42,7 @@ export async function GET(req: Request) { const list = Array.isArray(data) ? data : []; const items = list.map((x) => { - const id = String(x?.submission_id ?? x?.id); + const id = String(x?.id); const fieldSize = x?.field_size !== null && x?.field_size !== undefined @@ -58,11 +52,14 @@ export async function GET(req: Request) { const fnum = Number(x?.focal_length); const focalTxt = Number.isFinite(fnum) ? `F${fnum} mm` : ""; - // Label: field_size first, then focal length (requested order). - let label = [fieldSize, focalTxt].filter(Boolean).join(" — "); + // Requested order: field_size first, then focal length + let label = + coll === "laser_scan_lens" + ? [fieldSize, focalTxt].filter(Boolean).join(" — ") + : focalTxt || id; + if (!label) label = id; - // Sort numerically by focal length when available, else alpha by label. const sortKey: number | string = Number.isFinite(fnum) ? fnum : label.toLowerCase();