Feat(core-flows, medusa): delete inventory item (#6708)

* initial get-inventory-item

* add exception throw test

* remove console log

* add changeset

* remove inventory item

* add changeset

* fix pr feedback

* use links

* use modules instead of property names
This commit is contained in:
Philip Korsholm
2024-03-19 10:40:18 +01:00
committed by GitHub
parent c20eb15cd9
commit 62d5803b20
9 changed files with 270 additions and 127 deletions
@@ -5,6 +5,8 @@ import {
} from "@medusajs/utils"
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
import { deleteInventoryItemWorkflow } from "@medusajs/core-flows"
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
const { id } = req.params
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
@@ -35,3 +37,23 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
inventory_item,
})
}
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
const id = req.params.id
const deleteInventoryItems = deleteInventoryItemWorkflow(req.scope)
const { errors } = await deleteInventoryItems.run({
input: [id],
throwOnError: false,
})
if (Array.isArray(errors) && errors[0]) {
throw errors[0].error
}
res.status(200).json({
id,
object: "inventory_item",
deleted: true,
})
}