feat(medusa): Add get inventory item endpoint (#6704)

* initial get-inventory-item

* add exception throw test

* remove console log

* add changeset

* remove unused import
This commit is contained in:
Philip Korsholm
2024-03-15 16:00:27 +01:00
committed by GitHub
parent 3188e703b3
commit 56a6ec0227
4 changed files with 149 additions and 70 deletions
@@ -0,0 +1,37 @@
import {
ContainerRegistrationKeys,
MedusaError,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
const { id } = req.params
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const query = remoteQueryObjectFromString({
entryPoint: "inventory",
variables: {
filters: { id },
skip: 0,
take: 1,
},
fields: req.retrieveConfig.select as string[],
})
const { rows } = await remoteQuery(query)
const [inventory_item] = rows
if (!inventory_item) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Inventory item with id: ${id} was not found`
)
}
res.status(200).json({
inventory_item,
})
}
@@ -27,6 +27,16 @@ export const adminInventoryRoutesMiddlewares: MiddlewareRoute[] = [
),
],
},
{
method: ["GET"],
matcher: "/admin/inventory-items/:id",
middlewares: [
transformQuery(
AdminGetInventoryItemsItemParams,
QueryConfig.retrieveTransformQueryConfig
),
],
},
{
method: ["POST"],
matcher: "/admin/inventory-items/:id/location-levels",