fix(medusa): Only add ordering select if not already present (#3319)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/inventory": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
List inventory items based on locations
|
||||||
@@ -278,7 +278,61 @@ describe("Inventory Items endpoints", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("List inventory items", async () => {
|
describe("List inventory items", () => {
|
||||||
|
it("Lists inventory items with location", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/products/test-product/variants`,
|
||||||
|
{
|
||||||
|
title: "Test Variant w. inventory 2",
|
||||||
|
sku: "MY_SKU1",
|
||||||
|
material: "material",
|
||||||
|
origin_country: "UK",
|
||||||
|
manage_inventory: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
option_id: "test-product-option",
|
||||||
|
value: "M",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
prices: [{ currency_code: "usd", amount: 200 }],
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const inventoryItemId = inventoryItems[0].id
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/inventory-items/${inventoryItemId}/location-levels`,
|
||||||
|
{
|
||||||
|
location_id: location3Id,
|
||||||
|
stocked_quantity: 5,
|
||||||
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const unfilteredResponse = await api.get(
|
||||||
|
`/admin/inventory-items`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
expect(unfilteredResponse.data.inventory_items).toHaveLength(2)
|
||||||
|
|
||||||
|
const response = await api.get(
|
||||||
|
`/admin/inventory-items?location_id=${location3Id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.data.inventory_items).toHaveLength(1)
|
||||||
|
expect(response.data.inventory_items[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: inventoryItemId,
|
||||||
|
sku: "MY_SKU",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Lists inventory items", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
const inventoryItemId = inventoryItems[0].id
|
const inventoryItemId = inventoryItems[0].id
|
||||||
|
|
||||||
@@ -363,6 +417,7 @@ describe("Inventory Items endpoints", () => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it("When deleting an inventory item it removes the product variants associated to it", async () => {
|
it("When deleting an inventory item it removes the product variants associated to it", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|||||||
@@ -16,12 +16,16 @@ export function getListQuery(
|
|||||||
const inventoryItemRepository = manager.getRepository(InventoryItem)
|
const inventoryItemRepository = manager.getRepository(InventoryItem)
|
||||||
|
|
||||||
const { q, ...selectorRest } = selector
|
const { q, ...selectorRest } = selector
|
||||||
const query = buildQuery(selectorRest, config) as ExtendedFindConfig<InventoryItem> & {
|
const query = buildQuery(
|
||||||
where: FindOptionsWhere<InventoryItem & {
|
selectorRest,
|
||||||
|
config
|
||||||
|
) as ExtendedFindConfig<InventoryItem> & {
|
||||||
|
where: FindOptionsWhere<
|
||||||
|
InventoryItem & {
|
||||||
location_id?: string
|
location_id?: string
|
||||||
}>
|
|
||||||
}
|
}
|
||||||
|
>
|
||||||
|
}
|
||||||
|
|
||||||
const queryBuilder = inventoryItemRepository.createQueryBuilder("inv_item")
|
const queryBuilder = inventoryItemRepository.createQueryBuilder("inv_item")
|
||||||
|
|
||||||
@@ -65,7 +69,9 @@ export function getListQuery(
|
|||||||
const toSelect: string[] = []
|
const toSelect: string[] = []
|
||||||
const parsed = Object.entries(query.order).reduce((acc, [k, v]) => {
|
const parsed = Object.entries(query.order).reduce((acc, [k, v]) => {
|
||||||
const key = `inv_item.${k}`
|
const key = `inv_item.${k}`
|
||||||
|
if (!query.select?.[k]) {
|
||||||
toSelect.push(key)
|
toSelect.push(key)
|
||||||
|
}
|
||||||
acc[key] = v
|
acc[key] = v
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
|
|||||||
Reference in New Issue
Block a user