Skip to content

Commit 12cf24a

Browse files
authored
fix(medusa): deleting location level (medusajs#11630)
* fix: deleting inventory level * refactor: use query
1 parent c250de7 commit 12cf24a

File tree

1 file changed

+14
-13
lines changed
  • packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]

1 file changed

+14
-13
lines changed

Diff for: packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
ContainerRegistrationKeys,
33
MedusaError,
4-
remoteQueryObjectFromString,
54
} from "@medusajs/framework/utils"
65
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
76

@@ -19,20 +18,22 @@ export const DELETE = async (
1918
) => {
2019
const { id, location_id } = req.params
2120

22-
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
21+
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
2322

24-
// TODO: We probably want to move this logic to the workflow
25-
const [{ id: levelId, reserved_quantity: reservedQuantity }] =
26-
await remoteQuery(
27-
remoteQueryObjectFromString({
28-
entryPoint: "inventory_level",
29-
variables: {
30-
inventory_item_id: id,
31-
location_id,
32-
},
33-
fields: ["id", "reserved_quantity"],
34-
})
23+
const result = await query.graph({
24+
entity: "inventory_level",
25+
filters: { inventory_item_id: id, location_id },
26+
fields: ["id", "reserved_quantity"],
27+
})
28+
29+
if (!result.data.length) {
30+
throw new MedusaError(
31+
MedusaError.Types.NOT_FOUND,
32+
`Inventory Level for Item ${id} at Location ${location_id} not found`
3533
)
34+
}
35+
36+
const { id: levelId, reserved_quantity: reservedQuantity } = result.data[0]
3637

3738
if (reservedQuantity > 0) {
3839
throw new MedusaError(

0 commit comments

Comments
 (0)