diff --git a/api/src/modules/import/dtos/excel-projects.dto.ts b/api/src/modules/import/dtos/excel-projects.dto.ts index 0420af2e..9734ff92 100644 --- a/api/src/modules/import/dtos/excel-projects.dto.ts +++ b/api/src/modules/import/dtos/excel-projects.dto.ts @@ -20,6 +20,6 @@ export type ExcelProjects = { total_cost: number; cost_per_tco2e_npv: number; cost_per_tco2e: number; - initial_price_assumption: string; + initial_price_assumption: number; price_type: PROJECT_PRICE_TYPE; }; diff --git a/api/src/modules/projects/projects-scorecard.service.ts b/api/src/modules/projects/projects-scorecard.service.ts index c1bc2fe0..64b8bcad 100644 --- a/api/src/modules/projects/projects-scorecard.service.ts +++ b/api/src/modules/projects/projects-scorecard.service.ts @@ -5,10 +5,6 @@ import { Repository, SelectQueryBuilder } from 'typeorm'; import { z } from 'zod'; import { getProjectsQuerySchema } from '@shared/contracts/projects.contract'; import { ProjectScorecardView } from '@shared/entities/project-scorecard.view'; -import { - OtherProjectFilters, - ProjectFilters, -} from '@shared/dtos/projects/projects-map.dto'; export type ProjectFetchSpecificacion = z.infer; diff --git a/api/src/modules/projects/projects.controller.ts b/api/src/modules/projects/projects.controller.ts index dfd5af4a..bca8cb3b 100644 --- a/api/src/modules/projects/projects.controller.ts +++ b/api/src/modules/projects/projects.controller.ts @@ -90,4 +90,15 @@ export class ProjectsController { }, ); } + + @TsRestHandler(projectsContract.getProjectWithScorecard) + async getProjectWithScorecard(): ControllerResponse { + return tsRestHandler( + projectsContract.getProjectWithScorecard, + async ({ params: { id }, query }) => { + const data = await this.projectsScorecardService.getById(id, query); + return { body: { data }, status: HttpStatus.OK }; + }, + ); + } } diff --git a/api/test/integration/projects/projects.spec.ts b/api/test/integration/projects/projects.spec.ts index 9a0bd379..6da9b7cf 100644 --- a/api/test/integration/projects/projects.spec.ts +++ b/api/test/integration/projects/projects.spec.ts @@ -324,39 +324,39 @@ describe('Projects', () => { }); }); - test('Should return a list of filtered projects with maximum values', async () => { - await testManager.mocks().createProject({ - id: 'e934e9fe-a79c-40a5-8254-8817851764ad', - projectName: 'PROJ_ABC', - totalCost: 100, - totalCostNPV: 50, - abatementPotential: 10, - }); - await testManager.mocks().createProject({ - id: 'e934e9fe-a79c-40a5-8254-8817851764ae', - projectName: 'PROJ_DEF', - totalCost: 200, - totalCostNPV: 100, - abatementPotential: 20, - }); - - const response = await testManager - .request() - .get(projectsContract.getProjects.path) - .query({ - withMaximums: true, - partialProjectName: 'PROJ', + describe('Filters for Projects', () => { + test('Should return a list of filtered projects with maximum values', async () => { + await testManager.mocks().createProject({ + id: 'e934e9fe-a79c-40a5-8254-8817851764ad', + projectName: 'PROJ_ABC', + totalCost: 100, + totalCostNPV: 50, + abatementPotential: 10, + }); + await testManager.mocks().createProject({ + id: 'e934e9fe-a79c-40a5-8254-8817851764ae', + projectName: 'PROJ_DEF', + totalCost: 200, + totalCostNPV: 100, + abatementPotential: 20, }); - expect(response.status).toBe(HttpStatus.OK); - expect(response.body.data).toHaveLength(2); - expect(response.body.maximums).toEqual({ - maxAbatementPotential: 20, - maxTotalCost: 300, + const response = await testManager + .request() + .get(projectsContract.getProjects.path) + .query({ + withMaximums: true, + partialProjectName: 'PROJ', + }); + + expect(response.status).toBe(HttpStatus.OK); + expect(response.body.data).toHaveLength(2); + expect(response.body.maximums).toEqual({ + maxAbatementPotential: 20, + maxTotalCost: 300, + }); }); - }); - describe('Filters for Projects', () => { test('Should get a list of countries there are projects in', async () => { const fiveCountriesWithNoGeometry = countriesInDb .slice(0, 5) @@ -377,4 +377,44 @@ describe('Projects', () => { ); }); }); + + describe('Get Project', () => { + test('Should return a project', async () => { + const project = await testManager.mocks().createProject(); + const response = await testManager + .request() + .get(projectsContract.getProject.path.replace(':id', project.id)); + + expect(response.status).toBe(HttpStatus.OK); + expect(response.body.data.projectName).toBe(project.projectName); + }); + + test('Should return a 400 if project does not exist', async () => { + const response = await testManager + .request() + .get(projectsContract.getProject.path.replace(':id', '123')); + + expect(response.status).toBe(HttpStatus.BAD_REQUEST); + }); + + test('Should return a project with scorecard', async () => { + const project = await testManager.mocks().createProject(); + await testManager.mocks().createProjectScorecard({ + id: project.id, + }); + + const response = await testManager + .request() + .get( + projectsContract.getProjectWithScorecard.path.replace( + ':id', + project.id, + ), + ); + + expect(response.status).toBe(HttpStatus.OK); + expect(response.body.data.feasibilityAnalysisNPV).toBeDefined(); + expect(response.body.data.socialFeasibility).toBeDefined(); + }); + }); });