refactor(nestjs): validation schema dtos

This commit is contained in:
Ahmed Bouhuolia
2025-05-25 23:39:54 +02:00
parent 2b3f98d8fe
commit 24bf3dd06d
24 changed files with 247 additions and 135 deletions

View File

@@ -1,10 +1,12 @@
import { ToNumber } from '@/common/decorators/Validators';
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
IsArray,
IsBoolean,
IsDate,
IsDateString,
IsInt,
IsISO4217CurrencyCode,
IsNotEmpty,
IsNumber,
IsOptional,
@@ -23,10 +25,12 @@ export class ExpenseCategoryDto {
@IsNotEmpty()
index: number;
@IsInt()
@IsNotEmpty()
@ToNumber()
@IsInt()
expenseAccountId: number;
@ToNumber()
@IsNumber()
@IsOptional()
amount?: number;
@@ -40,6 +44,7 @@ export class ExpenseCategoryDto {
@IsOptional()
landedCost?: boolean;
@ToNumber()
@IsInt()
@IsOptional()
projectId?: number;
@@ -55,7 +60,7 @@ export class CommandExpenseDto {
})
referenceNo?: string;
@IsDate()
@IsDateString()
@IsNotEmpty()
@ApiProperty({
description: 'The payment date of the expense',
@@ -63,8 +68,9 @@ export class CommandExpenseDto {
})
paymentDate: Date;
@IsInt()
@IsNotEmpty()
@ToNumber()
@IsInt()
@ApiProperty({
description: 'The payment account id of the expense',
example: 1,
@@ -80,31 +86,22 @@ export class CommandExpenseDto {
})
description?: string;
@ToNumber()
@IsNumber()
@IsOptional()
@ApiProperty({
description: 'The exchange rate of the expense',
example: 1,
})
@ApiProperty({ description: 'The exchange rate of the expense', example: 1 })
exchangeRate?: number;
@IsString()
@MaxLength(3)
@IsOptional()
@IsISO4217CurrencyCode()
@ApiProperty({
description: 'The currency code of the expense',
example: 'USD',
})
currencyCode?: string;
@IsNumber()
@IsOptional()
@ApiProperty({
description: 'The exchange rate of the expense',
example: 1,
})
exchange_rate?: number;
@IsBoolean()
@IsOptional()
@ApiProperty({
@@ -113,14 +110,16 @@ export class CommandExpenseDto {
})
publish?: boolean;
@IsInt()
@IsOptional()
@ToNumber()
@IsInt()
@ApiProperty({
description: 'The payee id of the expense',
example: 1,
})
payeeId?: number;
@ToNumber()
@IsInt()
@IsOptional()
@ApiProperty({