From b09b351ab65fa226e0a863aeea58c530f1893674 Mon Sep 17 00:00:00 2001 From: Philip Korsholm Date: Tue, 28 Feb 2023 14:30:19 +0100 Subject: [PATCH 1/2] update typescript types to reflect oas and return types --- .../api/routes/admin/inventory-items/index.ts | 9 +++++---- .../inventory-items/list-inventory-items.ts | 20 +++++++------------ .../inventory-items/utils/join-variants.ts | 2 +- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/packages/medusa/src/api/routes/admin/inventory-items/index.ts b/packages/medusa/src/api/routes/admin/inventory-items/index.ts index 4b61c251e3f7e..1e60be2b2145e 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/index.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/index.ts @@ -230,11 +230,12 @@ export type AdminInventoryItemsListRes = PaginatedResponse & { * description: The number of items per page */ export type AdminInventoryItemsListWithVariantsAndLocationLevelsRes = - Partial & { - location_levels?: InventoryLevelDTO[] - variants?: ProductVariant[] + PaginatedResponse & { + inventory_items: (Partial & { + location_levels?: InventoryLevelDTO[] + variants?: ProductVariant[] + })[] } - /** * @schema AdminInventoryItemsLocationLevelsRes * type: object diff --git a/packages/medusa/src/api/routes/admin/inventory-items/list-inventory-items.ts b/packages/medusa/src/api/routes/admin/inventory-items/list-inventory-items.ts index 03c3c549f34fe..5febc94ae6783 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/list-inventory-items.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/list-inventory-items.ts @@ -3,10 +3,7 @@ import { IsBoolean, IsOptional, IsString } from "class-validator" import { Transform } from "class-transformer" import { IsType } from "../../../../utils/validators/is-type" import { getLevelsByInventoryItemId } from "./utils/join-levels" -import { - getVariantsByInventoryItemId, - InventoryItemsWithVariants, -} from "./utils/join-variants" +import { getVariantsByInventoryItemId } from "./utils/join-variants" import { ProductVariantInventoryService, ProductVariantService, @@ -128,17 +125,14 @@ export default async (req: Request, res: Response) => { inventoryService ) - const variantsByInventoryItemId: InventoryItemsWithVariants = - await getVariantsByInventoryItemId( - inventoryItems, - productVariantInventoryService, - productVariantService - ) + const variantsByInventoryItemId = await getVariantsByInventoryItemId( + inventoryItems, + productVariantInventoryService, + productVariantService + ) const inventoryItemsWithVariantsAndLocationLevels = inventoryItems.map( - ( - inventoryItem - ): AdminInventoryItemsListWithVariantsAndLocationLevelsRes => { + (inventoryItem) => { return { ...inventoryItem, variants: variantsByInventoryItemId[inventoryItem.id] ?? [], diff --git a/packages/medusa/src/api/routes/admin/inventory-items/utils/join-variants.ts b/packages/medusa/src/api/routes/admin/inventory-items/utils/join-variants.ts index 827c9be2e5158..c2a1fe27757e9 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/utils/join-variants.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/utils/join-variants.ts @@ -13,7 +13,7 @@ export const getVariantsByInventoryItemId = async ( inventoryItems: InventoryItemDTO[], productVariantInventoryService: ProductVariantInventoryService, productVariantService: ProductVariantService -): Promise> => { +): Promise> => { const variantInventory = await productVariantInventoryService.listByItem( inventoryItems.map((item) => item.id) ) From 78475254791d7e8e9a1e75961f4905d967d1ad9b Mon Sep 17 00:00:00 2001 From: Philip Korsholm Date: Tue, 28 Feb 2023 14:31:53 +0100 Subject: [PATCH 2/2] add changeset --- .changeset/quiet-deers-shake.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/quiet-deers-shake.md diff --git a/.changeset/quiet-deers-shake.md b/.changeset/quiet-deers-shake.md new file mode 100644 index 0000000000000..414e04ef81654 --- /dev/null +++ b/.changeset/quiet-deers-shake.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +Update types to reflect actual return-type