fix(medusa, medusa-react): Typing of optional fields on multiple product endpoints (#2771)
This commit is contained in:
@@ -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