dxGet fix for rigs
This commit is contained in:
parent
e252a84862
commit
74f100acf0
1 changed files with 8 additions and 8 deletions
|
|
@ -37,14 +37,14 @@ export async function GET(req: Request) {
|
|||
"date_updated",
|
||||
].join(",");
|
||||
|
||||
// ✅ filter on the relation's id
|
||||
const path =
|
||||
`/items/user_rigs?filter[owner][_eq]=${encodeURIComponent(me.id)}` +
|
||||
`/items/user_rigs?filter[owner][id][_eq]=${encodeURIComponent(me.id)}` +
|
||||
`&fields=${encodeURIComponent(fields)}` +
|
||||
`&sort=-date_updated` +
|
||||
`&limit=${limit}`;
|
||||
|
||||
// dxGET already returns the unwrapped `data` array
|
||||
const rows = await dxGET<any[]>(path, bearer);
|
||||
const rows = await dxGET<any[]>(path, bearer); // dxGET returns unwrapped `data`
|
||||
return NextResponse.json(rows ?? []);
|
||||
} catch (e: any) {
|
||||
return bad(e?.message || "Failed to load rigs", e?.status || 500);
|
||||
|
|
@ -101,13 +101,13 @@ export async function DELETE(req: Request) {
|
|||
const id = url.searchParams.get("id");
|
||||
if (!id) return bad("Missing: id");
|
||||
|
||||
// ensure the rig belongs to the current user
|
||||
// ✅ fetch owner.id for a precise comparison
|
||||
const me = await dxGET<{ id: string }>("/users/me?fields=id", bearer);
|
||||
const rig = await dxGET<any>(
|
||||
`/items/user_rigs/${encodeURIComponent(id)}?fields=id,owner`,
|
||||
bearer
|
||||
const rig = await dxGET<{ id: string; owner?: { id?: string } }>(
|
||||
`/items/user_rigs/${encodeURIComponent(id)}?fields=id,owner.id`,
|
||||
bearer
|
||||
);
|
||||
if (!rig || String(rig.owner) !== String(me.id)) {
|
||||
if (!rig || String(rig.owner?.id) !== String(me.id)) {
|
||||
return bad("Not your rig", 403);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue