Skip to content

Commit

Permalink
filter map by restoration activity
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Dec 11, 2024
1 parent cca33c8 commit 906ad7e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
13 changes: 8 additions & 5 deletions api/src/modules/projects/projects-map.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ProjectsMapRepository extends Repository<Project> {
totalCost,
abatementPotential,
activity,
activitySubtype,
restorationActivity,
ecosystem,
projectSizeFilter,
priceType,
Expand Down Expand Up @@ -136,10 +136,13 @@ export class ProjectsMapRepository extends Repository<Project> {
activity,
});
}
if (activitySubtype?.length) {
queryBuilder.andWhere('p.activitySubtype IN (:...activitySubtype)', {
activitySubtype,
});
if (restorationActivity?.length) {
queryBuilder.andWhere(
'p.restorationActivity IN (:...restorationActivity)',
{
restorationActivity,
},
);
}

if (ecosystem) {
Expand Down
45 changes: 44 additions & 1 deletion api/test/integration/project-map/project-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);
});
});
7 changes: 5 additions & 2 deletions shared/dtos/projects/projects-map.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof ProjectGeoPropertiesSchema>;
Expand All @@ -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;
Expand Down

0 comments on commit 906ad7e

Please sign in to comment.