From e7b6b7e80bc4773b32194b6238031e7cd65f7501 Mon Sep 17 00:00:00 2001 From: alexeh Date: Mon, 18 Nov 2024 08:09:58 +0100 Subject: [PATCH] add otherCommunityCashFlow to cost inputs + validate nested properties in create custom project --- api/src/modules/calculations/data.repository.ts | 1 + .../custom-projects/dto/create-custom-project-dto.ts | 9 ++++++--- .../custom-projects/dto/project-cost-inputs.dto.ts | 10 +++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/api/src/modules/calculations/data.repository.ts b/api/src/modules/calculations/data.repository.ts index f1c4442b..e2622b56 100644 --- a/api/src/modules/calculations/data.repository.ts +++ b/api/src/modules/calculations/data.repository.ts @@ -96,6 +96,7 @@ export class DataRepository extends Repository { 'financingCost', 'implementationLaborPlanting', 'implementationLaborHydrology', + 'otherCommunityCashFlow', ], }); if (!costInputs) { diff --git a/api/src/modules/custom-projects/dto/create-custom-project-dto.ts b/api/src/modules/custom-projects/dto/create-custom-project-dto.ts index 11664705..592a1085 100644 --- a/api/src/modules/custom-projects/dto/create-custom-project-dto.ts +++ b/api/src/modules/custom-projects/dto/create-custom-project-dto.ts @@ -6,6 +6,7 @@ import { IsString, Length, Validate, + ValidateNested, } from 'class-validator'; import { ACTIVITY } from '@shared/entities/activity.enum'; import { ECOSYSTEM } from '@shared/entities/ecosystem.enum'; @@ -14,7 +15,7 @@ import { RestorationProjectParamsDto } from '@api/modules/custom-projects/dto/re import { CustomProjectAssumptionsDto } from '@api/modules/custom-projects/dto/project-assumptions.dto'; import { CostInputs } from '@api/modules/custom-projects/dto/project-cost-inputs.dto'; import { ProjectParamsValidator } from '@api/modules/custom-projects/validation/project-params.validator'; -import { Transform } from 'class-transformer'; +import { Transform, Type } from 'class-transformer'; export enum CARBON_REVENUES_TO_COVER { OPEX = 'Opex', @@ -44,16 +45,18 @@ export class CreateCustomProjectDto { @IsEnum(CARBON_REVENUES_TO_COVER) carbonRevenuesToCover: CARBON_REVENUES_TO_COVER; - @IsOptional() + @ValidateNested() + @Type(() => CustomProjectAssumptionsDto) @IsNotEmpty({ message: 'Assumptions are required to create a custom project', }) assumptions: CustomProjectAssumptionsDto; - @IsOptional() @IsNotEmpty({ message: 'Cost inputs are required to create a custom project', }) + @ValidateNested() + @Type(() => CostInputs) costInputs: CostInputs; @IsNotEmpty() diff --git a/api/src/modules/custom-projects/dto/project-cost-inputs.dto.ts b/api/src/modules/custom-projects/dto/project-cost-inputs.dto.ts index 02db2ca3..352e3534 100644 --- a/api/src/modules/custom-projects/dto/project-cost-inputs.dto.ts +++ b/api/src/modules/custom-projects/dto/project-cost-inputs.dto.ts @@ -1,4 +1,9 @@ -import { IsNumber } from 'class-validator'; +import { IsEnum, IsNumber } from 'class-validator'; + +export enum PROJECT_DEVELOPMENT_TYPE { + DEVELOPMENT = 'Development', + NON_DEVELOPMENT = 'Non-Development', +} export class CostInputs { @IsNumber() @@ -48,4 +53,7 @@ export class CostInputs { @IsNumber() implementationLabor: number; + + @IsEnum(PROJECT_DEVELOPMENT_TYPE) + otherCommunityCashFlow: PROJECT_DEVELOPMENT_TYPE | string; }