Skip to content

Commit

Permalink
fix(medusa): Update typescript types to reflect oas and return types (#…
Browse files Browse the repository at this point in the history
…3344)

* update typescript types to reflect oas and return types

* add changeset

---------

Co-authored-by: Oliver Windall Juhl <[email protected]>
  • Loading branch information
pKorsholm and olivermrbl authored Feb 28, 2023
1 parent 589d1c0 commit 8424236
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-deers-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

Update types to reflect actual return-type
9 changes: 5 additions & 4 deletions packages/medusa/src/api/routes/admin/inventory-items/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,12 @@ export type AdminInventoryItemsListRes = PaginatedResponse & {
* description: The number of items per page
*/
export type AdminInventoryItemsListWithVariantsAndLocationLevelsRes =
Partial<InventoryItemDTO> & {
location_levels?: InventoryLevelDTO[]
variants?: ProductVariant[]
PaginatedResponse & {
inventory_items: (Partial<InventoryItemDTO> & {
location_levels?: InventoryLevelDTO[]
variants?: ProductVariant[]
})[]
}

/**
* @schema AdminInventoryItemsLocationLevelsRes
* type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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] ?? [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getVariantsByInventoryItemId = async (
inventoryItems: InventoryItemDTO[],
productVariantInventoryService: ProductVariantInventoryService,
productVariantService: ProductVariantService
): Promise<Record<string, InventoryItemsWithVariants>> => {
): Promise<Record<string, ProductVariant[]>> => {
const variantInventory = await productVariantInventoryService.listByItem(
inventoryItems.map((item) => item.id)
)
Expand Down

0 comments on commit 8424236

Please sign in to comment.