dxGet fix for rigs
This commit is contained in:
parent
719680c8dc
commit
e252a84862
2 changed files with 11 additions and 22 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// app/api/my/rigs/route.ts
|
||||
// app/api/rigs/route.ts
|
||||
import { NextResponse } from "next/server";
|
||||
import { dxGET, dxPOST, dxDELETE } from "@/lib/directus";
|
||||
import { requireBearer } from "@/app/api/_lib/auth";
|
||||
|
|
@ -43,9 +43,8 @@ export async function GET(req: Request) {
|
|||
`&sort=-date_updated` +
|
||||
`&limit=${limit}`;
|
||||
|
||||
// ⬇️ dxGET already returns the unwrapped `data`
|
||||
// dxGET already returns the unwrapped `data` array
|
||||
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);
|
||||
|
|
@ -58,7 +57,7 @@ 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 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;
|
||||
|
|
@ -69,7 +68,7 @@ export async function POST(req: Request) {
|
|||
if (!rig_type) return bad("Missing: rig_type");
|
||||
if (!laser_source) return bad("Missing: laser_source");
|
||||
|
||||
// Derive owner from auth’d user; ignore any spoofed owner in body
|
||||
// set owner from the authenticated user
|
||||
const me = await dxGET<{ id: string }>("/users/me?fields=id", bearer);
|
||||
|
||||
const payload: any = {
|
||||
|
|
@ -102,7 +101,7 @@ export async function DELETE(req: Request) {
|
|||
const id = url.searchParams.get("id");
|
||||
if (!id) return bad("Missing: id");
|
||||
|
||||
// Hard-guard: ensure the rig belongs to the current user
|
||||
// ensure the rig belongs to the current user
|
||||
const me = await dxGET<{ id: string }>("/users/me?fields=id", bearer);
|
||||
const rig = await dxGET<any>(
|
||||
`/items/user_rigs/${encodeURIComponent(id)}?fields=id,owner`,
|
||||
|
|
|
|||
|
|
@ -69,32 +69,22 @@ export default function RigsListClient() {
|
|||
{[
|
||||
r.laser_source.make,
|
||||
r.laser_source.model,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" ") || r.laser_source.submission_id}
|
||||
].filter(Boolean).join(" ") || r.laser_source.submission_id}
|
||||
.{" "}
|
||||
</>
|
||||
) : null}
|
||||
{r.laser_focus_lens?.name ? (
|
||||
<>Focus Lens: {r.laser_focus_lens.name}. </>
|
||||
) : null}
|
||||
{r.laser_focus_lens?.name ? <>Focus Lens: {r.laser_focus_lens.name}. </> : null}
|
||||
{r.laser_scan_lens ? (
|
||||
<>
|
||||
Scan Lens:{" "}
|
||||
{[
|
||||
r.laser_scan_lens.field_size &&
|
||||
`${r.laser_scan_lens.field_size}mm`,
|
||||
r.laser_scan_lens.focal_length &&
|
||||
`${r.laser_scan_lens.focal_length}mm`,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" / ")}
|
||||
r.laser_scan_lens.field_size && `${r.laser_scan_lens.field_size}mm`,
|
||||
r.laser_scan_lens.focal_length && `${r.laser_scan_lens.focal_length}mm`,
|
||||
].filter(Boolean).join(" / ")}
|
||||
.{" "}
|
||||
</>
|
||||
) : null}
|
||||
{r.laser_software?.name ? (
|
||||
<>Software: {r.laser_software.name}. </>
|
||||
) : null}
|
||||
{r.laser_software?.name ? <>Software: {r.laser_software.name}. </> : null}
|
||||
</div>
|
||||
{r.notes ? <div className="text-sm mt-2">{r.notes}</div> : null}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue