fix(medusa, medusa-react): Typing of optional fields on multiple product endpoints (#2771)
This commit is contained in:
committed by
GitHub
parent
3464617553
commit
c2c38dd091
6
.changeset/three-coins-swim.md
Normal file
6
.changeset/three-coins-swim.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
"medusa-react": patch
|
||||
---
|
||||
|
||||
Adds appropriate optional type to several endpoint fields related to products. Also fixes the use of wrong payload type for `useAdminUpdateVariant` hook in `medusa-react`.
|
||||
@@ -1,9 +1,9 @@
|
||||
import { adminProductKeys } from "./queries"
|
||||
import {
|
||||
AdminPostProductsProductOptionsOption,
|
||||
AdminPostProductsProductOptionsReq,
|
||||
AdminPostProductsProductReq,
|
||||
AdminPostProductsProductVariantsReq,
|
||||
AdminPostProductsProductVariantsVariantReq,
|
||||
AdminPostProductsReq,
|
||||
AdminProductsDeleteOptionRes,
|
||||
AdminProductsDeleteRes,
|
||||
@@ -14,6 +14,7 @@ import { Response } from "@medusajs/medusa-js"
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { buildOptions } from "../../utils/buildOptions"
|
||||
import { adminProductKeys } from "./queries"
|
||||
|
||||
export const useAdminCreateProduct = (
|
||||
options?: UseMutationOptions<
|
||||
@@ -96,7 +97,7 @@ export const useAdminUpdateVariant = (
|
||||
options?: UseMutationOptions<
|
||||
Response<AdminProductsRes>,
|
||||
Error,
|
||||
AdminPostProductsProductVariantsReq & { variant_id: string }
|
||||
AdminPostProductsProductVariantsVariantReq & { variant_id: string }
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
@@ -106,7 +107,7 @@ export const useAdminUpdateVariant = (
|
||||
({
|
||||
variant_id,
|
||||
...payload
|
||||
}: AdminPostProductsProductVariantsReq & { variant_id: string }) =>
|
||||
}: AdminPostProductsProductVariantsVariantReq & { variant_id: string }) =>
|
||||
client.admin.products.updateVariant(productId, variant_id, payload),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import {
|
||||
CreateProductVariantInput,
|
||||
ProductVariantPricesCreateReq,
|
||||
} from "../../../../types/product-variant"
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
@@ -12,6 +8,7 @@ import {
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
import {
|
||||
PricingService,
|
||||
ProductService,
|
||||
@@ -23,13 +20,16 @@ import {
|
||||
ProductTagReq,
|
||||
ProductTypeReq,
|
||||
} from "../../../../types/product"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
import {
|
||||
CreateProductVariantInput,
|
||||
ProductVariantPricesCreateReq,
|
||||
} from "../../../../types/product-variant"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import { ProductStatus } from "../../../../models"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { Type } from "class-transformer"
|
||||
import { EntityManager } from "typeorm"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { ProductStatus } from "../../../../models"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
|
||||
/**
|
||||
@@ -413,7 +413,7 @@ class ProductVariantReq {
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
inventory_quantity = 0
|
||||
inventory_quantity?: number = 0
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
|
||||
@@ -7,13 +7,16 @@ import {
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import { ProductService, ProductVariantService } from "../../../../services"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
import { ProductService, ProductVariantService } from "../../../../services"
|
||||
|
||||
import { ProductVariantPricesCreateReq } from "../../../../types/product-variant"
|
||||
import { Type } from "class-transformer"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
import {
|
||||
CreateProductVariantInput,
|
||||
ProductVariantPricesCreateReq,
|
||||
} from "../../../../types/product-variant"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
|
||||
/**
|
||||
* @oas [post] /products/{id}/variants
|
||||
@@ -217,7 +220,7 @@ export default async (req, res) => {
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
return await productVariantService
|
||||
.withTransaction(transactionManager)
|
||||
.create(id, validated)
|
||||
.create(id, validated as CreateProductVariantInput)
|
||||
})
|
||||
|
||||
const product = await productService.retrieve(id, {
|
||||
@@ -262,7 +265,7 @@ export class AdminPostProductsProductVariantsReq {
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
inventory_quantity = 0
|
||||
inventory_quantity?: number = 0
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@@ -313,5 +316,5 @@ export class AdminPostProductsProductVariantsReq {
|
||||
@Type(() => ProductVariantOptionReq)
|
||||
@ValidateNested({ each: true })
|
||||
@IsArray()
|
||||
options: ProductVariantOptionReq[] = []
|
||||
options?: ProductVariantOptionReq[] = []
|
||||
}
|
||||
|
||||
@@ -11,20 +11,20 @@ import {
|
||||
ValidateIf,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
import { PricingService, ProductService } from "../../../../services"
|
||||
import {
|
||||
ProductSalesChannelReq,
|
||||
ProductTagReq,
|
||||
ProductTypeReq,
|
||||
} from "../../../../types/product"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
|
||||
import { Type } from "class-transformer"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { ProductStatus } from "../../../../models"
|
||||
import { ProductVariantPricesUpdateReq } from "../../../../types/product-variant"
|
||||
import SalesChannelFeatureFlag from "../../../../loaders/feature-flags/sales-channels"
|
||||
import { Type } from "class-transformer"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
|
||||
/**
|
||||
@@ -390,7 +390,7 @@ class ProductVariantReq {
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ProductVariantPricesUpdateReq)
|
||||
prices: ProductVariantPricesUpdateReq[]
|
||||
prices?: ProductVariantPricesUpdateReq[]
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => ProductVariantOptionReq)
|
||||
@@ -418,7 +418,7 @@ export class AdminPostProductsProductReq {
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
images: string[]
|
||||
images?: string[]
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@@ -454,7 +454,7 @@ export class AdminPostProductsProductReq {
|
||||
ValidateNested({ each: true }),
|
||||
IsArray(),
|
||||
])
|
||||
sales_channels: ProductSalesChannelReq[] | null
|
||||
sales_channels?: ProductSalesChannelReq[] | null
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => ProductVariantReq)
|
||||
|
||||
@@ -7,18 +7,18 @@ import {
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
import {
|
||||
PricingService,
|
||||
ProductService,
|
||||
ProductVariantService,
|
||||
} from "../../../../services"
|
||||
import { defaultAdminProductFields, defaultAdminProductRelations } from "."
|
||||
|
||||
import { Type } from "class-transformer"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||
import { ProductVariantPricesUpdateReq } from "../../../../types/product-variant"
|
||||
import { Type } from "class-transformer"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [post] /products/{id}/variants/{variant_id}
|
||||
@@ -269,7 +269,7 @@ export class AdminPostProductsProductVariantsVariantReq {
|
||||
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
inventory_quantity: number
|
||||
inventory_quantity?: number
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
@@ -315,11 +315,11 @@ export class AdminPostProductsProductVariantsVariantReq {
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ProductVariantPricesUpdateReq)
|
||||
prices: ProductVariantPricesUpdateReq[]
|
||||
prices?: ProductVariantPricesUpdateReq[]
|
||||
|
||||
@Type(() => ProductVariantOptionReq)
|
||||
@ValidateNested({ each: true })
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
options: ProductVariantOptionReq[] = []
|
||||
options?: ProductVariantOptionReq[] = []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user