Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/tbcct 156 #146

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 36 additions & 0 deletions api/test/integration/project-map/project-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +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';

describe('Project Map', () => {
let testManager: TestManager;
Expand Down Expand Up @@ -292,4 +293,39 @@ describe('Project Map', () => {
countries[1].name,
);
});

test('Should return the geometries of the countries filtered by partialProjectName', async () => {
const countries = await testManager
.getDataSource()
.getRepository(Country)
.find({ take: 1 });

await Promise.all([
testManager.mocks().createProject({
projectName: 'MyProjectName',
projectSizeFilter: PROJECT_SIZE_FILTER.MEDIUM,
priceType: PROJECT_PRICE_TYPE.MARKET_PRICE,
countryCode: countries[0].code,
}),
testManager.mocks().createProject({
projectName: 'ShouldNotBeReturned',
projectSizeFilter: PROJECT_SIZE_FILTER.MEDIUM,
priceType: PROJECT_PRICE_TYPE.MARKET_PRICE,
countryCode: countries[0].code,
}),
]);

const response = await testManager
.request()
.get(projectsContract.getProjectsMap.path)
.query({
partialProjectName: 'myproject',
});

expect(response.status).toBe(HttpStatus.OK);
expect(response.body.features).toHaveLength(1);
expect(response.body.features[0].properties.country).toBe(
countries[0].name,
);
});
});
1 change: 1 addition & 0 deletions backoffice/providers/auth.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class AuthProvider extends BaseAuthProvider {
res.setHeader('Set-Cookie', [
`backoffice=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly`,
`next-auth.session-token=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly`,
`__Secure-next-auth.session-token=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly`,
]);
}
}
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;
};
Loading