Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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