feat(medusa): Add location id filtering to list location levels (#4066)
**What** - add capabilities for filtering locations by id when listing locations for an inventory item
This commit is contained in:
1 parent
2d9cb9b17f
commit
4fb443c0ea
5 files changed
+100
-24
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/client-types": patch
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(medusa,client-types): add location_id filtering to list-location levels
|
||||||
@@ -362,6 +362,41 @@ describe("Inventory Items endpoints", () => {
|
|||||||
expect(variantInventoryRes.status).toEqual(200)
|
expect(variantInventoryRes.status).toEqual(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("lists location levels based on id param constraint", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
const inventoryItemId = inventoryItems[0].id
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/inventory-items/${inventoryItemId}/location-levels`,
|
||||||
|
{
|
||||||
|
location_id: location2Id,
|
||||||
|
stocked_quantity: 10,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/inventory-items/${inventoryItemId}/location-levels`,
|
||||||
|
{
|
||||||
|
location_id: location3Id,
|
||||||
|
stocked_quantity: 5,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const result = await api.get(
|
||||||
|
`/admin/inventory-items/${inventoryItemId}/location-levels?location_id[]=${location2Id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(result.status).toEqual(200)
|
||||||
|
expect(result.data.inventory_item.location_levels).toHaveLength(1)
|
||||||
|
expect(result.data.inventory_item.location_levels[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
stocked_quantity: 10,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
describe("List inventory items", () => {
|
describe("List inventory items", () => {
|
||||||
it("Lists inventory items with location", async () => {
|
it("Lists inventory items with location", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|||||||
+4
@@ -4,6 +4,10 @@
|
|||||||
import { SetRelation, Merge } from "../core/ModelUtils"
|
import { SetRelation, Merge } from "../core/ModelUtils"
|
||||||
|
|
||||||
export interface AdminGetInventoryItemsItemLocationLevelsParams {
|
export interface AdminGetInventoryItemsItemLocationLevelsParams {
|
||||||
|
/**
|
||||||
|
* Locations ids to search for.
|
||||||
|
*/
|
||||||
|
location_id?: Array<string>
|
||||||
/**
|
/**
|
||||||
* Comma separated list of relations to include in the results.
|
* Comma separated list of relations to include in the results.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,24 +1,5 @@
|
|||||||
import { InventoryItemDTO, InventoryLevelDTO } from "@medusajs/types"
|
|
||||||
import { Router } from "express"
|
|
||||||
import "reflect-metadata"
|
import "reflect-metadata"
|
||||||
import { ProductVariant } from "../../../../models"
|
|
||||||
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
|
||||||
import middlewares, {
|
|
||||||
transformBody,
|
|
||||||
transformQuery,
|
|
||||||
} from "../../../middlewares"
|
|
||||||
import { checkRegisteredModules } from "../../../middlewares/check-registered-modules"
|
|
||||||
import {
|
|
||||||
AdminPostInventoryItemsParams,
|
|
||||||
AdminPostInventoryItemsReq,
|
|
||||||
} from "./create-inventory-item"
|
|
||||||
import {
|
|
||||||
AdminPostInventoryItemsItemLocationLevelsParams,
|
|
||||||
AdminPostInventoryItemsItemLocationLevelsReq,
|
|
||||||
} from "./create-location-level"
|
|
||||||
import { AdminGetInventoryItemsItemParams } from "./get-inventory-item"
|
|
||||||
import { AdminGetInventoryItemsParams } from "./list-inventory-items"
|
|
||||||
import { AdminGetInventoryItemsItemLocationLevelsParams } from "./list-location-levels"
|
|
||||||
import {
|
import {
|
||||||
AdminPostInventoryItemsInventoryItemParams,
|
AdminPostInventoryItemsInventoryItemParams,
|
||||||
AdminPostInventoryItemsInventoryItemReq,
|
AdminPostInventoryItemsInventoryItemReq,
|
||||||
@@ -27,6 +8,27 @@ import {
|
|||||||
AdminPostInventoryItemsItemLocationLevelsLevelParams,
|
AdminPostInventoryItemsItemLocationLevelsLevelParams,
|
||||||
AdminPostInventoryItemsItemLocationLevelsLevelReq,
|
AdminPostInventoryItemsItemLocationLevelsLevelReq,
|
||||||
} from "./update-location-level"
|
} from "./update-location-level"
|
||||||
|
import {
|
||||||
|
AdminPostInventoryItemsItemLocationLevelsParams,
|
||||||
|
AdminPostInventoryItemsItemLocationLevelsReq,
|
||||||
|
} from "./create-location-level"
|
||||||
|
import {
|
||||||
|
AdminPostInventoryItemsParams,
|
||||||
|
AdminPostInventoryItemsReq,
|
||||||
|
} from "./create-inventory-item"
|
||||||
|
import { DeleteResponse, PaginatedResponse } from "../../../../types/common"
|
||||||
|
import { InventoryItemDTO, InventoryLevelDTO } from "@medusajs/types"
|
||||||
|
import middlewares, {
|
||||||
|
transformBody,
|
||||||
|
transformQuery,
|
||||||
|
} from "../../../middlewares"
|
||||||
|
|
||||||
|
import { AdminGetInventoryItemsItemLocationLevelsParams } from "./list-location-levels"
|
||||||
|
import { AdminGetInventoryItemsItemParams } from "./get-inventory-item"
|
||||||
|
import { AdminGetInventoryItemsParams } from "./list-inventory-items"
|
||||||
|
import { ProductVariant } from "../../../../models"
|
||||||
|
import { Router } from "express"
|
||||||
|
import { checkRegisteredModules } from "../../../middlewares/check-registered-modules"
|
||||||
|
|
||||||
const route = Router()
|
const route = Router()
|
||||||
|
|
||||||
@@ -91,8 +93,8 @@ export default (app) => {
|
|||||||
route.get(
|
route.get(
|
||||||
"/:id/location-levels",
|
"/:id/location-levels",
|
||||||
transformQuery(AdminGetInventoryItemsItemLocationLevelsParams, {
|
transformQuery(AdminGetInventoryItemsItemLocationLevelsParams, {
|
||||||
defaultFields: defaultAdminInventoryItemFields,
|
defaultFields: defaultAdminLocationLevelFields,
|
||||||
defaultRelations: defaultAdminInventoryItemRelations,
|
defaultRelations: [],
|
||||||
isList: false,
|
isList: false,
|
||||||
}),
|
}),
|
||||||
middlewares.wrap(require("./list-location-levels").default)
|
middlewares.wrap(require("./list-location-levels").default)
|
||||||
@@ -144,6 +146,18 @@ export const defaultAdminInventoryItemFields: (keyof InventoryItemDTO)[] = [
|
|||||||
"updated_at",
|
"updated_at",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const defaultAdminLocationLevelFields: (keyof InventoryLevelDTO)[] = [
|
||||||
|
"id",
|
||||||
|
"inventory_item_id",
|
||||||
|
"location_id",
|
||||||
|
"stocked_quantity",
|
||||||
|
"reserved_quantity",
|
||||||
|
"incoming_quantity",
|
||||||
|
"metadata",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
]
|
||||||
|
|
||||||
export const defaultAdminInventoryItemRelations = []
|
export const defaultAdminInventoryItemRelations = []
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { IInventoryService } from "@medusajs/types"
|
import { IsOptional, IsString } from "class-validator"
|
||||||
import { Request, Response } from "express"
|
import { Request, Response } from "express"
|
||||||
|
|
||||||
import { FindParams } from "../../../../types/common"
|
import { FindParams } from "../../../../types/common"
|
||||||
|
import { IInventoryService } from "@medusajs/types"
|
||||||
|
import { IsType } from "../../../../utils/validators/is-type"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /admin/inventory-items/{id}/location-levels
|
* @oas [get] /admin/inventory-items/{id}/location-levels
|
||||||
@@ -10,6 +13,15 @@ import { FindParams } from "../../../../types/common"
|
|||||||
* x-authenticated: true
|
* x-authenticated: true
|
||||||
* parameters:
|
* parameters:
|
||||||
* - (path) id=* {string} The ID of the Inventory Item.
|
* - (path) id=* {string} The ID of the Inventory Item.
|
||||||
|
* - in: query
|
||||||
|
* name: location_id
|
||||||
|
* style: form
|
||||||
|
* explode: false
|
||||||
|
* description: Locations ids to search for.
|
||||||
|
* schema:
|
||||||
|
* type: array
|
||||||
|
* items:
|
||||||
|
* type: string
|
||||||
* - (query) expand {string} Comma separated list of relations to include in the results.
|
* - (query) expand {string} Comma separated list of relations to include in the results.
|
||||||
* - (query) fields {string} Comma separated list of fields to include in the results.
|
* - (query) fields {string} Comma separated list of fields to include in the results.
|
||||||
* x-codegen:
|
* x-codegen:
|
||||||
@@ -65,6 +77,7 @@ export default async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
const [levels] = await inventoryService.listInventoryLevels(
|
const [levels] = await inventoryService.listInventoryLevels(
|
||||||
{
|
{
|
||||||
|
...req.filterableFields,
|
||||||
inventory_item_id: id,
|
inventory_item_id: id,
|
||||||
},
|
},
|
||||||
req.retrieveConfig
|
req.retrieveConfig
|
||||||
@@ -79,4 +92,8 @@ export default async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
export class AdminGetInventoryItemsItemLocationLevelsParams extends FindParams {}
|
export class AdminGetInventoryItemsItemLocationLevelsParams extends FindParams {
|
||||||
|
@IsOptional()
|
||||||
|
@IsString({ each: true })
|
||||||
|
location_id?: string[]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user