diff --git a/api/src/modules/calculations/data.repository.ts b/api/src/modules/calculations/data.repository.ts index 1c8da641..2f321a9f 100644 --- a/api/src/modules/calculations/data.repository.ts +++ b/api/src/modules/calculations/data.repository.ts @@ -18,6 +18,7 @@ import { ConvervationActivityDefaults, RestorationActivityDefaults, } from '@shared/dtos/custom-projects/activity-types-defaults'; +import { Country } from '@shared/entities/country.entity'; /** * Additional data that is required to perform calculations, which is not overridable by the user. Better naming and clustering of concepts would be great @@ -81,11 +82,16 @@ export class DataRepository extends Repository { activity, ); + const country = await this.manager + .getRepository(Country) + .findOne({ where: { code: countryCode } }); + return { additionalBaseData, baseSize, baseIncrease, additionalAssumptions, + country, }; } diff --git a/api/src/modules/custom-projects/custom-projects.service.ts b/api/src/modules/custom-projects/custom-projects.service.ts index fad558f1..e68daf65 100644 --- a/api/src/modules/custom-projects/custom-projects.service.ts +++ b/api/src/modules/custom-projects/custom-projects.service.ts @@ -20,6 +20,7 @@ import { EventBus } from '@nestjs/cqrs'; import { SaveCustomProjectEvent } from '@api/modules/custom-projects/events/save-custom-project.event'; import { FetchSpecification } from 'nestjs-base-service'; import { GetActivityTypesDefaults } from '@shared/dtos/custom-projects/get-activity-types-defaults.dto'; +import { Country } from '@shared/entities/country.entity'; @Injectable() export class CustomProjectsService extends AppBaseService< @@ -48,6 +49,7 @@ export class CustomProjectsService extends AppBaseService< baseIncrease, baseSize, additionalAssumptions, + country, } = await this.dataRepository.getDataForCalculation({ countryCode, ecosystem, @@ -68,6 +70,7 @@ export class CustomProjectsService extends AppBaseService< const customProject = this.customProjectFactory.createProject( dto, + country, projectInput, costOutput, ); diff --git a/api/src/modules/custom-projects/input-factory/custom-project.factory.ts b/api/src/modules/custom-projects/input-factory/custom-project.factory.ts index 5589163a..cb5d94a3 100644 --- a/api/src/modules/custom-projects/input-factory/custom-project.factory.ts +++ b/api/src/modules/custom-projects/input-factory/custom-project.factory.ts @@ -98,13 +98,17 @@ export class CustomProjectFactory { createProject( dto: CreateCustomProjectDto, + country: Country, input: ProjectInput, output: CostOutput, ): CustomProject { const { costPlans, summary, costDetails, yearlyBreakdown } = output; const customProject = new CustomProject(); customProject.projectName = dto.projectName; - customProject.country = { code: dto.countryCode } as Country; + customProject.country = { + code: country.code, + name: country.name, + } as Country; customProject.totalCostNPV = costPlans.totalCapexNPV + costPlans.totalOpexNPV; customProject.totalCost = costPlans.totalCapex + costPlans.totalOpex; @@ -133,6 +137,22 @@ export class CustomProjectFactory { opex: costPlans.totalOpexNPV, }, }, + leftover: { + total: { + total: costPlans.totalCapex + costPlans.totalOpex, + leftover: + costPlans.totalCapex + + costPlans.totalOpex - + costPlans.totalCapexNPV - + costPlans.totalOpexNPV, + opex: costPlans.totalOpex, + }, + npv: { + total: costPlans.totalCapexNPV + costPlans.totalOpexNPV, + leftover: costPlans.totalCapexNPV + costPlans.totalOpexNPV, + opex: costPlans.totalOpexNPV, + }, + }, summary, costDetails, yearlyBreakdown, diff --git a/shared/dtos/custom-projects/custom-project-output.dto.ts b/shared/dtos/custom-projects/custom-project-output.dto.ts index 2649e9d6..3a47f890 100644 --- a/shared/dtos/custom-projects/custom-project-output.dto.ts +++ b/shared/dtos/custom-projects/custom-project-output.dto.ts @@ -93,6 +93,18 @@ export class ConservationProjectOutput { opex: number; }; }; + leftover: { + total: { + total: number; + leftover: number; + opex: number; + }; + npv: { + total: number; + leftover: number; + opex: number; + }; + }; summary: CustomProjectSummary; costDetails: { total: CustomProjectCostDetails;