From 12cf24a0dec43f33eb1a974c506c9f90356b3959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frane=20Poli=C4=87?= <16856471+fPolic@users.noreply.github.com> Date: Thu, 27 Feb 2025 14:07:33 +0100 Subject: [PATCH] fix(medusa): deleting location level (#11630) * fix: deleting inventory level * refactor: use query --- .../location-levels/[location_id]/route.ts | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts b/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts index 7a2c58f1b6..04fc92fc9e 100644 --- a/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts +++ b/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts @@ -1,7 +1,6 @@ import { ContainerRegistrationKeys, MedusaError, - remoteQueryObjectFromString, } from "@medusajs/framework/utils" import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http" @@ -19,20 +18,22 @@ export const DELETE = async ( ) => { const { id, location_id } = req.params - const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY) + const query = req.scope.resolve(ContainerRegistrationKeys.QUERY) - // TODO: We probably want to move this logic to the workflow - const [{ id: levelId, reserved_quantity: reservedQuantity }] = - await remoteQuery( - remoteQueryObjectFromString({ - entryPoint: "inventory_level", - variables: { - inventory_item_id: id, - location_id, - }, - fields: ["id", "reserved_quantity"], - }) + const result = await query.graph({ + entity: "inventory_level", + filters: { inventory_item_id: id, location_id }, + fields: ["id", "reserved_quantity"], + }) + + if (!result.data.length) { + throw new MedusaError( + MedusaError.Types.NOT_FOUND, + `Inventory Level for Item ${id} at Location ${location_id} not found` ) + } + + const { id: levelId, reserved_quantity: reservedQuantity } = result.data[0] if (reservedQuantity > 0) { throw new MedusaError(