From fc4740f1c16854f8268dd95759b6f31cad30074b Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 2 Jul 2026 09:52:54 +0330 Subject: [PATCH] transform string to number --- src/main.ts | 7 ++++++- src/modules/products/dto/create-product.dto.ts | 13 +++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main.ts b/src/main.ts index 77c1815..5b9100b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,7 +26,12 @@ async function bootstrap() { await app.register(fastifyCookie); await app.register(multipart); - app.useGlobalPipes(new ValidationPipe()); + app.useGlobalPipes( + new ValidationPipe({ + transform: true, + whitelist: true, + }), + ); app.useGlobalInterceptors( new ResponseInterceptor(), diff --git a/src/modules/products/dto/create-product.dto.ts b/src/modules/products/dto/create-product.dto.ts index d7adf2b..8448993 100644 --- a/src/modules/products/dto/create-product.dto.ts +++ b/src/modules/products/dto/create-product.dto.ts @@ -3,6 +3,7 @@ import { ArrayMinSize, IsArray, IsBoolean, + IsDefined, IsEnum, IsInt, IsNotEmpty, @@ -118,12 +119,12 @@ export class CreateProductDto { @ApiPropertyOptional({ example: 1 }) order?: number; - @IsOptional() + @IsDefined() @IsNumber({ maxDecimalPlaces: 3 }) @Min(0.001) @Type(() => Number) - @ApiPropertyOptional({ description: 'Maximum quantity per order; omit or null for unlimited', example: 5 }) - maxPurchaseQuantity?: number | null; + @ApiProperty({ description: 'Maximum quantity per order', example: 5 }) + maxPurchaseQuantity: number; @IsOptional() @IsNumber({ maxDecimalPlaces: 3 }) @@ -142,11 +143,11 @@ export class CreateProductDto { @ApiPropertyOptional({ example: PurchaseUnit.NUMBER }) purchaseUnit?: PurchaseUnit; - @IsOptional() + @IsDefined() @IsNumber({ maxDecimalPlaces: 3 }) @Min(0.001) @Type(() => Number) - @ApiPropertyOptional({ description: 'Minimum quantity per order; omit or null for unlimited', example: 0.5 }) - minPurchaseQuantity?: number | null; + @ApiProperty({ description: 'Minimum quantity per order', example: 0.5 }) + minPurchaseQuantity: number; }