diff --git a/api/src/modules/projects/projects-map.repository.ts b/api/src/modules/projects/projects-map.repository.ts index 82dfccc3..cc8e4559 100644 --- a/api/src/modules/projects/projects-map.repository.ts +++ b/api/src/modules/projects/projects-map.repository.ts @@ -75,7 +75,7 @@ export class ProjectsMapRepository extends Repository { totalCost, abatementPotential, activity, - activitySubtype, + restorationActivity, ecosystem, projectSizeFilter, priceType, @@ -136,10 +136,13 @@ export class ProjectsMapRepository extends Repository { activity, }); } - if (activitySubtype?.length) { - queryBuilder.andWhere('p.activitySubtype IN (:...activitySubtype)', { - activitySubtype, - }); + if (restorationActivity?.length) { + queryBuilder.andWhere( + 'p.restorationActivity IN (:...restorationActivity)', + { + restorationActivity, + }, + ); } if (ecosystem) { diff --git a/api/test/integration/project-map/project-map.spec.ts b/api/test/integration/project-map/project-map.spec.ts index 576233be..261bef8d 100644 --- a/api/test/integration/project-map/project-map.spec.ts +++ b/api/test/integration/project-map/project-map.spec.ts @@ -8,7 +8,7 @@ import { import { Country } from '@shared/entities/country.entity'; import { projectsContract } from '@shared/contracts/projects.contract'; import { ECOSYSTEM } from '@shared/entities/ecosystem.enum'; -import { partial } from 'lodash'; +import { RESTORATION_ACTIVITY_SUBTYPE } from '@shared/entities/activity.enum'; describe('Project Map', () => { let testManager: TestManager; @@ -328,4 +328,47 @@ describe('Project Map', () => { countries[0].name, ); }); + + test('Should return the geometries of the countries filtered by restoration activity subtype', async () => { + const countries = await testManager + .getDataSource() + .getRepository(Country) + .find({ take: 3 }); + + await Promise.all([ + testManager.mocks().createProject({ + restorationActivity: RESTORATION_ACTIVITY_SUBTYPE.PLANTING, + countryCode: countries[0].code, + }), + testManager.mocks().createProject({ + restorationActivity: RESTORATION_ACTIVITY_SUBTYPE.HYBRID, + countryCode: countries[1].code, + }), + testManager.mocks().createProject({ + restorationActivity: RESTORATION_ACTIVITY_SUBTYPE.HYDROLOGY, + countryCode: countries[2].code, + }), + ]); + + const response = await testManager + .request() + .get(projectsContract.getProjectsMap.path) + .query({ + filter: { + restorationActivity: [ + RESTORATION_ACTIVITY_SUBTYPE.HYBRID, + RESTORATION_ACTIVITY_SUBTYPE.HYDROLOGY, + ], + }, + }); + + expect(response.status).toBe(HttpStatus.OK); + expect(response.body.features).toHaveLength(2); + expect(response.body.features[0].properties.country).toBe( + countries[1].name, + ); + expect(response.body.features[1].properties.country).toBe( + countries[2].name, + ); + }); }); diff --git a/shared/dtos/projects/projects-map.dto.ts b/shared/dtos/projects/projects-map.dto.ts index 65571685..776211e3 100644 --- a/shared/dtos/projects/projects-map.dto.ts +++ b/shared/dtos/projects/projects-map.dto.ts @@ -5,7 +5,10 @@ import { PROJECT_PRICE_TYPE, PROJECT_SIZE_FILTER, } from "@shared/entities/projects.entity"; -import { ACTIVITY } from "@shared/entities/activity.enum"; +import { + ACTIVITY, + RESTORATION_ACTIVITY_SUBTYPE, +} from "@shared/entities/activity.enum"; import { ECOSYSTEM } from "@shared/entities/ecosystem.enum"; export type ProjectGeoProperties = z.infer; @@ -17,7 +20,7 @@ export type ProjectFilters = { totalCost?: number[]; abatementPotential?: number[]; activity?: ACTIVITY; - activitySubtype?: string[]; + restorationActivity?: RESTORATION_ACTIVITY_SUBTYPE[]; ecosystem?: ECOSYSTEM; projectSizeFilter?: PROJECT_SIZE_FILTER; priceType?: PROJECT_PRICE_TYPE;