diff --git a/src/modules/products/dto/product-response.dto.ts b/src/modules/products/dto/product-response.dto.ts index 1bb1366..51c5ca8 100644 --- a/src/modules/products/dto/product-response.dto.ts +++ b/src/modules/products/dto/product-response.dto.ts @@ -1,4 +1,4 @@ -import { Expose, Type } from 'class-transformer'; +import { Expose, Type, Transform } from 'class-transformer'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; export class CategoryInProductResponseDto { @@ -38,6 +38,7 @@ export class ProductResponseDto { @ApiProperty({ description: 'Product price' }) @Expose() + @Transform(({ value }) => parseFloat(value)) price: number; @ApiPropertyOptional({ description: 'Product image URL' }) @@ -50,6 +51,7 @@ export class ProductResponseDto { @ApiProperty({ description: 'Stock quantity' }) @Expose() + @Transform(({ value }) => parseInt(value, 10)) stockQuantity: number; @ApiProperty({ description: 'Availability status' }) diff --git a/src/modules/transactions/dto/transaction-response.dto.ts b/src/modules/transactions/dto/transaction-response.dto.ts index d9b17eb..e275268 100644 --- a/src/modules/transactions/dto/transaction-response.dto.ts +++ b/src/modules/transactions/dto/transaction-response.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { Exclude, Expose, Type } from 'class-transformer'; +import { Exclude, Expose, Type, Transform } from 'class-transformer'; @Exclude() export class TransactionItemResponseDto { @@ -17,14 +17,17 @@ export class TransactionItemResponseDto { @Expose() @ApiProperty({ description: 'Product price at transaction time' }) + @Transform(({ value }) => parseFloat(value)) price: number; @Expose() @ApiProperty({ description: 'Quantity purchased' }) + @Transform(({ value }) => parseInt(value, 10)) quantity: number; @Expose() @ApiProperty({ description: 'Line total (price * quantity)' }) + @Transform(({ value }) => parseFloat(value)) lineTotal: number; } @@ -36,18 +39,22 @@ export class TransactionResponseDto { @Expose() @ApiProperty({ description: 'Subtotal before tax and discount' }) + @Transform(({ value }) => parseFloat(value)) subtotal: number; @Expose() @ApiProperty({ description: 'Tax amount' }) + @Transform(({ value }) => parseFloat(value)) tax: number; @Expose() @ApiProperty({ description: 'Discount amount' }) + @Transform(({ value }) => parseFloat(value)) discount: number; @Expose() @ApiProperty({ description: 'Total amount (subtotal + tax - discount)' }) + @Transform(({ value }) => parseFloat(value)) total: number; @Expose()