diff --git a/api/src/modules/projects/projects-map.repository.ts b/api/src/modules/projects/projects-map.repository.ts index a268710e..903302c5 100644 --- a/api/src/modules/projects/projects-map.repository.ts +++ b/api/src/modules/projects/projects-map.repository.ts @@ -83,6 +83,22 @@ export class ProjectsMapRepository extends Repository { const { costRange, abatementPotentialRange, costRangeSelector } = otherFilters; + if (projectSizeFilter) { + for (const projectSize of projectSizeFilter) { + queryBuilder.andWhere('p.project_size_filter = :projectSizeFilter', { + projectSizeFilter: projectSize, + }); + } + } + + if (priceType) { + for (const type of priceType) { + queryBuilder.andWhere('p.price_type = :priceType', { + priceType: type, + }); + } + } + if (costRangeSelector === 'npv') { queryBuilder.addSelect('SUM(p.total_cost_npv)', 'total_cost'); } else { diff --git a/api/test/integration/project-map/project-map.spec.ts b/api/test/integration/project-map/project-map.spec.ts index a9c0690e..eaba2526 100644 --- a/api/test/integration/project-map/project-map.spec.ts +++ b/api/test/integration/project-map/project-map.spec.ts @@ -1,6 +1,10 @@ import { TestManager } from '../../utils/test-manager'; import { HttpStatus } from '@nestjs/common'; -import { Project } from '@shared/entities/projects.entity'; +import { + Project, + PROJECT_PRICE_TYPE, + PROJECT_SIZE_FILTER, +} from '@shared/entities/projects.entity'; import { Country } from '@shared/entities/country.entity'; import { projectsContract } from '@shared/contracts/projects.contract'; import { ECOSYSTEM } from '@shared/entities/ecosystem.enum'; @@ -222,4 +226,70 @@ describe('Project Map', () => { countries[1].name, ); }); + + test('Should return the geometries of the countries filtered by priceType', async () => { + const countries = await testManager + .getDataSource() + .getRepository(Country) + .find({ take: 2 }); + + await Promise.all([ + testManager.mocks().createProject({ + priceType: PROJECT_PRICE_TYPE.MARKET_PRICE, + countryCode: countries[0].code, + }), + testManager.mocks().createProject({ + priceType: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE, + countryCode: countries[1].code, + }), + ]); + + const response = await testManager + .request() + .get(projectsContract.getProjectsMap.path) + .query({ + filter: { priceType: [PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE] }, + }); + + expect(response.status).toBe(HttpStatus.OK); + expect(response.body.features).toHaveLength(1); + expect(response.body.features[0].properties.country).toBe( + countries[1].name, + ); + }); + + test('Should return the geometries of the countries filtered by projectSizeFilter', async () => { + const countries = await testManager + .getDataSource() + .getRepository(Country) + .find({ take: 2 }); + + await Promise.all([ + testManager.mocks().createProject({ + projectSizeFilter: PROJECT_SIZE_FILTER.MEDIUM, + priceType: PROJECT_PRICE_TYPE.MARKET_PRICE, + countryCode: countries[0].code, + }), + testManager.mocks().createProject({ + projectSizeFilter: PROJECT_SIZE_FILTER.SMALL, + priceType: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE, + countryCode: countries[1].code, + }), + ]); + + const response = await testManager + .request() + .get(projectsContract.getProjectsMap.path) + .query({ + filter: { + projectSizeFilter: [PROJECT_SIZE_FILTER.SMALL], + }, + }); + + expect(response.status).toBe(HttpStatus.OK); + expect(response.body.features).toHaveLength(1); + expect(response.body.features[0].properties.country).toBe( + countries[1].name, + ); + }); });