Skip to content

Commit

Permalink
fix: Apply partialProjectName search to the /project/map endpoint and…
Browse files Browse the repository at this point in the history
… refactor other filters
  • Loading branch information
alepefe committed Dec 10, 2024
1 parent a7a428c commit 79e7891
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
33 changes: 21 additions & 12 deletions api/src/modules/projects/projects-map.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,32 @@ export class ProjectsMapRepository extends Repository<Project> {
projectSizeFilter,
priceType,
} = filters;
const { costRange, abatementPotentialRange, costRangeSelector } =
otherFilters;
const {
costRange,
abatementPotentialRange,
costRangeSelector,
partialProjectName,
} = otherFilters;

if (partialProjectName) {
queryBuilder.andWhere('p.project_name ILIKE :partialProjectName', {
partialProjectName: `%${partialProjectName}%`,
});
}

if (projectSizeFilter) {
for (const projectSize of projectSizeFilter) {
queryBuilder.andWhere('p.project_size_filter = :projectSizeFilter', {
projectSizeFilter: projectSize,
});
}
queryBuilder.andWhere(
'p.project_size_filter IN (:...projectSizeFilter)',
{
projectSizeFilter,
},
);
}

if (priceType) {
for (const type of priceType) {
queryBuilder.andWhere('p.price_type = :priceType', {
priceType: type,
});
}
queryBuilder.andWhere('p.price_type IN (:...priceType)', {
priceType,
});
}

if (costRangeSelector === 'npv') {
Expand Down
1 change: 1 addition & 0 deletions api/src/modules/projects/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class ProjectsController {
costRange: query.costRange,
abatementPotentialRange: query.abatementPotentialRange,
costRangeSelector: query.costRangeSelector,
partialProjectName: query.partialProjectName,
};
const data = await this.projectMapRepository.getProjectsMap(
filter as unknown as ProjectFilters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function ProjectsLayer() {
costRange: filters.costRange,
abatementPotentialRange: filters.abatementPotentialRange,
costRangeSelector: filters.costRangeSelector,
partialProjectName: filters.keyword,
},
},
{
Expand Down
4 changes: 1 addition & 3 deletions shared/contracts/projects.contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ export const projectsContract = contract.router({
responses: {
200: contract.type<ProjectMap>(),
},
// TODO: we need to define filters, they should probably match filters for Projects. Or we might want to pass only project ids, which
// would be already filtered
//query: z.object({ countryCodes: z.string().array().optional() }).optional(),
query: getProjectsQuerySchema.pick({
filter: true,
costRange: true,
abatementPotentialRange: true,
costRangeSelector: true,
partialProjectName: true,
}),
},
});
1 change: 1 addition & 0 deletions shared/dtos/projects/projects-map.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export type OtherProjectFilters = {
costRange?: number[];
abatementPotentialRange?: number[];
costRangeSelector?: "total" | "npv";
partialProjectName?: string;
};

0 comments on commit 79e7891

Please sign in to comment.