diff --git a/apps/api/src/app/order/create-order.dto.ts b/apps/api/src/app/order/create-order.dto.ts index 888c6bacd..33e6f9cc8 100644 --- a/apps/api/src/app/order/create-order.dto.ts +++ b/apps/api/src/app/order/create-order.dto.ts @@ -5,6 +5,7 @@ import { Tag, Type } from '@prisma/client'; +import { Transform, TransformFnParams } from 'class-transformer'; import { IsArray, IsEnum, @@ -13,29 +14,33 @@ import { IsOptional, IsString } from 'class-validator'; +import { isString } from 'lodash'; export class CreateOrderDto { - @IsString() @IsOptional() + @IsString() accountId?: string; - @IsEnum(AssetClass, { each: true }) @IsOptional() + @IsEnum(AssetClass, { each: true }) assetClass?: AssetClass; - @IsEnum(AssetSubClass, { each: true }) @IsOptional() + @IsEnum(AssetSubClass, { each: true }) assetSubClass?: AssetSubClass; - @IsString() @IsOptional() + @IsString() + @Transform(({ value }: TransformFnParams) => + isString(value) ? value.trim() : value + ) comment?: string; @IsString() currency: string; - @IsEnum(DataSource, { each: true }) @IsOptional() + @IsEnum(DataSource, { each: true }) dataSource?: DataSource; @IsISO8601() diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 5c85c9891..b66b40866 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -21,7 +21,7 @@ import { } from '@prisma/client'; import Big from 'big.js'; import { endOfToday, isAfter } from 'date-fns'; -import { groupBy } from 'lodash'; +import { groupBy, isString } from 'lodash'; import { v4 as uuidv4 } from 'uuid'; import { Activity } from './interfaces/activities.interface'; @@ -143,6 +143,11 @@ export class OrderService { delete data.accountId; delete data.assetClass; delete data.assetSubClass; + + if (!data.comment) { + delete data.comment; + } + delete data.currency; delete data.dataSource; delete data.symbol; @@ -316,6 +321,10 @@ export class OrderService { delete data.Account; } + if (!data.comment) { + data.comment = null; + } + const tags = data.tags ?? []; let isDraft = false; diff --git a/apps/api/src/app/order/update-order.dto.ts b/apps/api/src/app/order/update-order.dto.ts index f4c7ba0cd..7c709ea7c 100644 --- a/apps/api/src/app/order/update-order.dto.ts +++ b/apps/api/src/app/order/update-order.dto.ts @@ -5,6 +5,7 @@ import { Tag, Type } from '@prisma/client'; +import { Transform, TransformFnParams } from 'class-transformer'; import { IsArray, IsEnum, @@ -13,6 +14,7 @@ import { IsOptional, IsString } from 'class-validator'; +import { isString } from 'lodash'; export class UpdateOrderDto { @IsOptional() @@ -27,8 +29,11 @@ export class UpdateOrderDto { @IsOptional() assetSubClass?: AssetSubClass; - @IsString() @IsOptional() + @IsString() + @Transform(({ value }: TransformFnParams) => + isString(value) ? value.trim() : value + ) comment?: string; @IsString()