chore: query inventory items by location id (#7524)
what: - allows querying inventory items by the correct location_id
This commit is contained in:
1 parent
a40b6aef6d
commit
f0b9d5534e
3 files changed
+15
-7
No files matched your search
@@ -1,8 +1,8 @@
|
|||||||
|
import { IInventoryServiceNext, IStockLocationService } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
remoteQueryObjectFromString,
|
remoteQueryObjectFromString,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { IInventoryServiceNext, IStockLocationService } from "@medusajs/types"
|
|
||||||
|
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { createAdminUser } from "../../../helpers/create-admin-user"
|
import { createAdminUser } from "../../../helpers/create-admin-user"
|
||||||
@@ -751,7 +751,10 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
const response = await api.get(`/admin/inventory-items`, adminHeaders)
|
const response = await api.get(
|
||||||
|
`/admin/inventory-items?location_levels[location_id]=${location1}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
expect(response.data.inventory_items).toHaveLength(1)
|
expect(response.data.inventory_items).toHaveLength(1)
|
||||||
expect(response.data.inventory_items[0]).toEqual(
|
expect(response.data.inventory_items[0]).toEqual(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
import { OptionalBooleanValidator } from "../../utils/common-validators"
|
||||||
import {
|
import {
|
||||||
createFindParams,
|
createFindParams,
|
||||||
createOperatorMap,
|
createOperatorMap,
|
||||||
createSelectParams,
|
createSelectParams,
|
||||||
} from "../../utils/validators"
|
} from "../../utils/validators"
|
||||||
import { OptionalBooleanValidator } from "../../utils/common-validators"
|
|
||||||
|
|
||||||
export type AdminGetInventoryItemParamsType = z.infer<
|
export type AdminGetInventoryItemParamsType = z.infer<
|
||||||
typeof AdminGetInventoryItemParams
|
typeof AdminGetInventoryItemParams
|
||||||
@@ -17,11 +17,11 @@ export type AdminGetInventoryItemsParamsType = z.infer<
|
|||||||
export const AdminGetInventoryItemsParams = createFindParams({
|
export const AdminGetInventoryItemsParams = createFindParams({
|
||||||
limit: 20,
|
limit: 20,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
}).merge(
|
})
|
||||||
|
.merge(
|
||||||
z.object({
|
z.object({
|
||||||
q: z.string().optional(),
|
q: z.string().optional(),
|
||||||
id: z.union([z.string(), z.array(z.string())]).optional(),
|
id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||||
location_id: z.union([z.string(), z.array(z.string())]).optional(),
|
|
||||||
sku: z.union([z.string(), z.array(z.string())]).optional(),
|
sku: z.union([z.string(), z.array(z.string())]).optional(),
|
||||||
origin_country: z.union([z.string(), z.array(z.string())]).optional(),
|
origin_country: z.union([z.string(), z.array(z.string())]).optional(),
|
||||||
mid_code: z.union([z.string(), z.array(z.string())]).optional(),
|
mid_code: z.union([z.string(), z.array(z.string())]).optional(),
|
||||||
@@ -32,10 +32,16 @@ export const AdminGetInventoryItemsParams = createFindParams({
|
|||||||
length: createOperatorMap(z.number(), parseFloat).optional(),
|
length: createOperatorMap(z.number(), parseFloat).optional(),
|
||||||
height: createOperatorMap(z.number(), parseFloat).optional(),
|
height: createOperatorMap(z.number(), parseFloat).optional(),
|
||||||
width: createOperatorMap(z.number(), parseFloat).optional(),
|
width: createOperatorMap(z.number(), parseFloat).optional(),
|
||||||
|
location_levels: z
|
||||||
|
.object({
|
||||||
|
location_id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
$and: z.lazy(() => AdminGetInventoryItemsParams.array()).optional(),
|
$and: z.lazy(() => AdminGetInventoryItemsParams.array()).optional(),
|
||||||
$or: z.lazy(() => AdminGetInventoryItemsParams.array()).optional(),
|
$or: z.lazy(() => AdminGetInventoryItemsParams.array()).optional(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
.strict()
|
||||||
|
|
||||||
export type AdminGetInventoryLocationLevelParamsType = z.infer<
|
export type AdminGetInventoryLocationLevelParamsType = z.infer<
|
||||||
typeof AdminGetInventoryLocationLevelParams
|
typeof AdminGetInventoryLocationLevelParams
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ export function validateAndTransformQuery<TEntity extends BaseEntity>(
|
|||||||
try {
|
try {
|
||||||
const allowed = (req.allowed ?? queryConfig.allowed ?? []) as string[]
|
const allowed = (req.allowed ?? queryConfig.allowed ?? []) as string[]
|
||||||
delete req.allowed
|
delete req.allowed
|
||||||
|
|
||||||
const query = normalizeQuery(req)
|
const query = normalizeQuery(req)
|
||||||
const validated = await zodValidator(zodSchema, query)
|
const validated = await zodValidator(zodSchema, query)
|
||||||
const cnf = queryConfig.isList
|
const cnf = queryConfig.isList
|
||||||
|
|||||||
Reference in new issue
Block a user