Feat(core-flows, medusa, types): Add delete location level api-v2 endpoint (#6727)

* add delete inventory level endpoint

* add changeset

* rename step

* rename step
This commit is contained in:
Philip Korsholm
2024-03-19 10:06:37 +01:00
committed by GitHub
parent 390bc3e72f
commit c20eb15cd9
9 changed files with 178 additions and 13 deletions
@@ -0,0 +1,47 @@
import {
ContainerRegistrationKeys,
MedusaError,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { MedusaRequest, MedusaResponse } from "../../../../../../types/routing"
import { deleteInventoryLevelsWorkflow } from "@medusajs/core-flows"
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
const { id, location_id } = req.params
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const [{ id: levelId, reserved_quantity: reservedQuantity }] =
await remoteQuery(
remoteQueryObjectFromString({
entryPoint: "inventory_level",
variables: {
inventory_item_id: id,
location_id,
},
fields: ["id", "reserved_quantity"],
})
)
if (reservedQuantity > 0) {
throw new MedusaError(
MedusaError.Types.NOT_ALLOWED,
`Cannot remove Inventory Level ${id} at Location ${location_id} because there are reservations at location`
)
}
const deleteInventoryLevelWorkflow = deleteInventoryLevelsWorkflow(req.scope)
await deleteInventoryLevelWorkflow.run({
input: {
ids: [levelId],
},
})
res.status(200).json({
id: levelId,
object: "inventory-level",
deleted: true,
})
}
@@ -1,19 +1,18 @@
import { InventoryNext } from "@medusajs/types"
// eslint-disable-next-line max-len
export const defaultAdminLocationLevelFields: (keyof InventoryNext.InventoryLevelDTO)[] =
[
"id",
"inventory_item_id",
"location_id",
"stocked_quantity",
"reserved_quantity",
"incoming_quantity",
"available_quantity",
"metadata",
"created_at",
"updated_at",
]
export const defaultAdminLocationLevelFields = [
"id",
"inventory_item_id",
"location_id",
"stocked_quantity",
"reserved_quantity",
"incoming_quantity",
"available_quantity",
"metadata",
"created_at",
"updated_at",
]
export const defaultAdminInventoryItemFields = [
"id",