fix(medusa): Update typescript types to reflect oas and return types (#3344)

* update typescript types to reflect oas and return types

* add changeset

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Philip Korsholm
2023-02-28 19:19:24 +01:00
committed by GitHub
co-authored by Oliver Windall Juhl
parent 589d1c09b0
commit 8424236799
4 changed files with 18 additions and 18 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
Update types to reflect actual return-type
@@ -230,11 +230,12 @@ export type AdminInventoryItemsListRes = PaginatedResponse & {
* description: The number of items per page * description: The number of items per page
*/ */
export type AdminInventoryItemsListWithVariantsAndLocationLevelsRes = export type AdminInventoryItemsListWithVariantsAndLocationLevelsRes =
Partial<InventoryItemDTO> & { PaginatedResponse & {
location_levels?: InventoryLevelDTO[] inventory_items: (Partial<InventoryItemDTO> & {
variants?: ProductVariant[] location_levels?: InventoryLevelDTO[]
variants?: ProductVariant[]
})[]
} }
/** /**
* @schema AdminInventoryItemsLocationLevelsRes * @schema AdminInventoryItemsLocationLevelsRes
* type: object * type: object
@@ -3,10 +3,7 @@ import { IsBoolean, IsOptional, IsString } from "class-validator"
import { Transform } from "class-transformer" import { Transform } from "class-transformer"
import { IsType } from "../../../../utils/validators/is-type" import { IsType } from "../../../../utils/validators/is-type"
import { getLevelsByInventoryItemId } from "./utils/join-levels" import { getLevelsByInventoryItemId } from "./utils/join-levels"
import { import { getVariantsByInventoryItemId } from "./utils/join-variants"
getVariantsByInventoryItemId,
InventoryItemsWithVariants,
} from "./utils/join-variants"
import { import {
ProductVariantInventoryService, ProductVariantInventoryService,
ProductVariantService, ProductVariantService,
@@ -128,17 +125,14 @@ export default async (req: Request, res: Response) => {
inventoryService inventoryService
) )
const variantsByInventoryItemId: InventoryItemsWithVariants = const variantsByInventoryItemId = await getVariantsByInventoryItemId(
await getVariantsByInventoryItemId( inventoryItems,
inventoryItems, productVariantInventoryService,
productVariantInventoryService, productVariantService
productVariantService )
)
const inventoryItemsWithVariantsAndLocationLevels = inventoryItems.map( const inventoryItemsWithVariantsAndLocationLevels = inventoryItems.map(
( (inventoryItem) => {
inventoryItem
): AdminInventoryItemsListWithVariantsAndLocationLevelsRes => {
return { return {
...inventoryItem, ...inventoryItem,
variants: variantsByInventoryItemId[inventoryItem.id] ?? [], variants: variantsByInventoryItemId[inventoryItem.id] ?? [],
@@ -13,7 +13,7 @@ export const getVariantsByInventoryItemId = async (
inventoryItems: InventoryItemDTO[], inventoryItems: InventoryItemDTO[],
productVariantInventoryService: ProductVariantInventoryService, productVariantInventoryService: ProductVariantInventoryService,
productVariantService: ProductVariantService productVariantService: ProductVariantService
): Promise<Record<string, InventoryItemsWithVariants>> => { ): Promise<Record<string, ProductVariant[]>> => {
const variantInventory = await productVariantInventoryService.listByItem( const variantInventory = await productVariantInventoryService.listByItem(
inventoryItems.map((item) => item.id) inventoryItems.map((item) => item.id)
) )