1
1
import {
2
2
ContainerRegistrationKeys ,
3
3
MedusaError ,
4
- remoteQueryObjectFromString ,
5
4
} from "@medusajs/framework/utils"
6
5
import { MedusaRequest , MedusaResponse } from "@medusajs/framework/http"
7
6
@@ -19,20 +18,22 @@ export const DELETE = async (
19
18
) => {
20
19
const { id, location_id } = req . params
21
20
22
- const remoteQuery = req . scope . resolve ( ContainerRegistrationKeys . REMOTE_QUERY )
21
+ const query = req . scope . resolve ( ContainerRegistrationKeys . QUERY )
23
22
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`
35
33
)
34
+ }
35
+
36
+ const { id : levelId , reserved_quantity : reservedQuantity } = result . data [ 0 ]
36
37
37
38
if ( reservedQuantity > 0 ) {
38
39
throw new MedusaError (
0 commit comments