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

fix: boolean filters isTaxed and multiOwners #1043

Merged
merged 4 commits into from
Dec 18, 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
26 changes: 17 additions & 9 deletions frontend/src/mocks/handlers/housing-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,27 @@ export const housingHandlers: RequestHandler[] = [
});
}
),
http.post<Record<string, never>, HousingPayload, HousingCountDTO>(
http.get<Record<string, never>, HousingPayload, HousingCountDTO>(
`${config.apiEndpoint}/api/housing/count`,
async ({ request }) => {
const payload = await request.json();
const url = new URL(request.url);
const queryParams = url.searchParams;
const campaignIds =
queryParams.get('campaignIds')?.split(',') ?? undefined;
const housingKinds =
queryParams.get('housingKinds')?.split(',') ?? undefined;
const status = queryParams.get('status')
? [Number(queryParams.get('status'))]
: undefined;
const statuses =
status ??
queryParams.get('statusList')?.split(',').map(Number) ??
undefined;

const subset: HousingDTO[] = fp.pipe(
filterByCampaign(payload.filters?.campaignIds),
filterByHousingKind(payload.filters?.housingKinds),
filterByStatus(
payload.filters?.status
? [payload.filters.status]
: payload.filters?.statusList
)
filterByCampaign(campaignIds),
filterByHousingKind(housingKinds),
filterByStatus(statuses)
)(data.housings);

const owners: number = fp.uniqBy(
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/services/housing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ export const housingApi = zlvApi.injectEndpoints({
countHousing: builder.query<HousingCount, HousingFilters>({
query: (filters) => ({
url: 'housing/count',
method: 'POST',
body: { filters }
method: 'GET',
params: {
...filters
}
}),
providesTags: (result, errors, args) => [
{
Expand Down
20 changes: 18 additions & 2 deletions server/src/controllers/housingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,24 @@ async function list(
async function count(request: Request, response: Response): Promise<void> {
logger.trace('Count housing');

const { establishmentId, role } = (request as AuthenticatedRequest).auth;
const filters = <HousingFiltersApi>request.body.filters ?? {};
const { auth, query } = request as AuthenticatedRequest;

const { establishmentId, role } = auth;

const filters: HousingFiltersApi = {
...query,
multiOwners: query?.multiOwners?.map((value: boolean) =>
value ? 'true' : 'false'
),
roomsCounts: query?.roomsCounts?.map((value: string) =>
value.toString()
),
isTaxedValues: query?.isTaxedValues?.map((value: boolean) =>
value ? 'true' : 'false'
),
energyConsumption:
query?.energyConsumption as unknown as EnergyConsumptionGradesApi[],
};

const count = await housingRepository.count({
...filters,
Expand Down
10 changes: 7 additions & 3 deletions server/src/routers/protected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ router.get(
}),
housingController.list
);
// TODO: replace by POST /housing
router.post(
'/housing',
housingController.createValidators,
validator.validate,
housingController.create
);
// TODO: replace by GET /housing/count
router.post('/housing/count', housingController.count);
router.get('/housing/count',
validatorNext.validate({
query: schemas.housingFilters
.concat(sortApi.sortSchema)
.concat(paginationSchema)
}),
housingController.count);
router.get(
'/housing/:id',
housingController.getValidators,
Expand Down
Loading