fix(medusa): deleting location level (#11630)
* fix: deleting inventory level * refactor: use query
This commit is contained in:
+14
-13
@@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
remoteQueryObjectFromString,
|
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||||
|
|
||||||
@@ -19,20 +18,22 @@ export const DELETE = async (
|
|||||||
) => {
|
) => {
|
||||||
const { id, location_id } = req.params
|
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 result = await query.graph({
|
||||||
const [{ id: levelId, reserved_quantity: reservedQuantity }] =
|
entity: "inventory_level",
|
||||||
await remoteQuery(
|
filters: { inventory_item_id: id, location_id },
|
||||||
remoteQueryObjectFromString({
|
fields: ["id", "reserved_quantity"],
|
||||||
entryPoint: "inventory_level",
|
})
|
||||||
variables: {
|
|
||||||
inventory_item_id: id,
|
if (!result.data.length) {
|
||||||
location_id,
|
throw new MedusaError(
|
||||||
},
|
MedusaError.Types.NOT_FOUND,
|
||||||
fields: ["id", "reserved_quantity"],
|
`Inventory Level for Item ${id} at Location ${location_id} not found`
|
||||||
})
|
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id: levelId, reserved_quantity: reservedQuantity } = result.data[0]
|
||||||
|
|
||||||
if (reservedQuantity > 0) {
|
if (reservedQuantity > 0) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
|
|||||||
Reference in New Issue
Block a user