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