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:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user