dxGet fix for rigs
This commit is contained in:
parent
387c70bf56
commit
719680c8dc
1 changed files with 11 additions and 6 deletions
|
|
@ -13,8 +13,10 @@ export async function GET(req: Request) {
|
|||
try {
|
||||
const bearer = requireBearer(req);
|
||||
const me = await dxGET<{ id: string }>("/users/me?fields=id", bearer);
|
||||
|
||||
const q = new URL(req.url).searchParams;
|
||||
const limit = Math.min(parseInt(q.get("limit") || "50", 10), 100);
|
||||
|
||||
const fields = [
|
||||
"id",
|
||||
"name",
|
||||
|
|
@ -37,10 +39,14 @@ export async function GET(req: Request) {
|
|||
|
||||
const path =
|
||||
`/items/user_rigs?filter[owner][_eq]=${encodeURIComponent(me.id)}` +
|
||||
`&fields=${encodeURIComponent(fields)}&sort=-date_updated&limit=${limit}`;
|
||||
`&fields=${encodeURIComponent(fields)}` +
|
||||
`&sort=-date_updated` +
|
||||
`&limit=${limit}`;
|
||||
|
||||
const res = await dxGET<any>(path, bearer);
|
||||
return NextResponse.json(res?.data ?? []);
|
||||
// ⬇️ dxGET already returns the unwrapped `data`
|
||||
const rows = await dxGET<any[]>(path, bearer);
|
||||
|
||||
return NextResponse.json(rows ?? []);
|
||||
} catch (e: any) {
|
||||
return bad(e?.message || "Failed to load rigs", e?.status || 500);
|
||||
}
|
||||
|
|
@ -52,8 +58,8 @@ export async function POST(req: Request) {
|
|||
const body = await req.json().catch(() => ({}));
|
||||
|
||||
const name = (body?.name || "").trim();
|
||||
const rig_type = body?.rig_type; // id
|
||||
const laser_source = body?.laser_source; // submission_id
|
||||
const rig_type = body?.rig_type; // id
|
||||
const laser_source = body?.laser_source; // submission_id
|
||||
const laser_scan_lens = body?.laser_scan_lens || null;
|
||||
const laser_focus_lens = body?.laser_focus_lens || null;
|
||||
const laser_software = body?.laser_software || null;
|
||||
|
|
@ -66,7 +72,6 @@ export async function POST(req: Request) {
|
|||
// Derive owner from auth’d user; ignore any spoofed owner in body
|
||||
const me = await dxGET<{ id: string }>("/users/me?fields=id", bearer);
|
||||
|
||||
// Only set one lens m2o depending on rig type on the client; server tolerates both null.
|
||||
const payload: any = {
|
||||
owner: me.id,
|
||||
name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue