Files
medusa-store/packages/medusa/src/api/admin/inventory-items/middlewares.ts
T
Harminder VirkandAdrien de Peretti 48e00169d2 breaking: move shared HTTP utils to the framework (#9402)
Fixes: FRMW-2728, FRMW-2729

After this PR gets merged the following middleware will be exported from the `@medusajs/framework/http` import path.

- applyParamsAsFilters
- clearFiltersByKey
- applyDefaultFilters
- setContext
- getQueryConfig
- httpCompression
- maybeApplyLinkFilter
- refetchEntities
- unlessPath
- validateBody
- validateQuery

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2024-10-03 09:42:00 +00:00

130 lines
3.4 KiB
TypeScript

import * as QueryConfig from "./query-config"
import { MiddlewareRoute, unlessPath } from "@medusajs/framework/http"
import {
validateAndTransformBody,
validateAndTransformQuery,
} from "@medusajs/framework"
import {
AdminCreateInventoryItem,
AdminCreateInventoryLocationLevel,
AdminGetInventoryItemParams,
AdminGetInventoryItemsParams,
AdminGetInventoryLocationLevelParams,
AdminGetInventoryLocationLevelsParams,
AdminUpdateInventoryItem,
AdminUpdateInventoryLocationLevel,
} from "./validators"
import { createBatchBody } from "../../utils/validators"
export const adminInventoryRoutesMiddlewares: MiddlewareRoute[] = [
{
method: ["GET"],
matcher: "/admin/inventory-items",
middlewares: [
validateAndTransformQuery(
AdminGetInventoryItemsParams,
QueryConfig.listTransformQueryConfig
),
],
},
{
method: ["GET"],
matcher: "/admin/inventory-items/:id",
middlewares: [
validateAndTransformQuery(
AdminGetInventoryItemParams,
QueryConfig.retrieveTransformQueryConfig
),
],
},
{
method: ["POST"],
matcher: "/admin/inventory-items",
middlewares: [
validateAndTransformBody(AdminCreateInventoryItem),
validateAndTransformQuery(
AdminGetInventoryItemParams,
QueryConfig.retrieveTransformQueryConfig
),
],
},
{
method: ["POST"],
matcher: "/admin/inventory-items/:id",
middlewares: [
validateAndTransformBody(AdminUpdateInventoryItem),
validateAndTransformQuery(
AdminGetInventoryItemParams,
QueryConfig.retrieveTransformQueryConfig
),
],
},
{
method: ["GET"],
matcher: "/admin/inventory-items/:id/location-levels",
middlewares: [
validateAndTransformQuery(
AdminGetInventoryLocationLevelsParams,
QueryConfig.listLocationLevelsTransformQueryConfig
),
],
},
{
method: ["POST"],
matcher: "/admin/inventory-items/:id/location-levels",
middlewares: [
validateAndTransformBody(AdminCreateInventoryLocationLevel),
validateAndTransformQuery(
AdminGetInventoryItemParams,
QueryConfig.retrieveTransformQueryConfig
),
],
},
{
method: ["POST"],
matcher: "/admin/inventory-items/:id/location-levels/batch",
middlewares: [
validateAndTransformBody(
createBatchBody(
AdminCreateInventoryLocationLevel,
AdminUpdateInventoryLocationLevel
)
),
validateAndTransformQuery(
AdminGetInventoryLocationLevelParams,
QueryConfig.retrieveLocationLevelsTransformQueryConfig
),
],
},
{
method: ["DELETE"],
matcher: "/admin/inventory-items/:id/location-levels/:location_id",
middlewares: [
unlessPath(
/.*\/location-levels\/batch/,
validateAndTransformQuery(
AdminGetInventoryItemParams,
QueryConfig.retrieveTransformQueryConfig
)
),
],
},
{
method: ["POST"],
matcher: "/admin/inventory-items/:id/location-levels/:location_id",
middlewares: [
unlessPath(
/.*\/location-levels\/batch/,
validateAndTransformBody(AdminUpdateInventoryLocationLevel)
),
unlessPath(
/.*\/location-levels\/batch/,
validateAndTransformQuery(
AdminGetInventoryItemParams,
QueryConfig.retrieveTransformQueryConfig
)
),
],
},
]