Skip to content

Commit

Permalink
fix: keep gt0 filter
Browse files Browse the repository at this point in the history
  • Loading branch information
loicguillois committed Jan 21, 2025
1 parent 21b7235 commit 63a5a4a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/src/controllers/campaignController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ async function resetHousingWithoutCampaigns(establishmentId: string) {
.find({
filters: {
establishmentIds: [establishmentId],
campaignsCounts: ['0'],
statusList: [HousingStatusApi.Waiting]
},
pagination: { paginate: false }
Expand Down
1 change: 1 addition & 0 deletions server/src/models/HousingFiltersApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface HousingFiltersApi
housingCounts?: string[];
// TODO: type there based on housing repository values
vacancyRates?: string[];
campaignsCounts?: string[];
campaignIds?: Array<string | null>;
ownerIds?: string[];
localities?: string[];
Expand Down
10 changes: 9 additions & 1 deletion server/src/repositories/housingRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,15 @@ function filteredQuery(opts: FilteredQueryOptions) {
}
});
}

if (filters.campaignsCounts?.length) {
queryBuilder.where(function (whereBuilder: any) {
if (filters.campaignsCounts?.includes('0')) {
whereBuilder.orWhereRaw(
`cardinality(${campaignsTable}.campaign_ids) = 0`
);
}
});
}
if (filters.ownerIds?.length) {
queryBuilder.whereIn(`${ownerTable}.id`, filters.ownerIds);
}
Expand Down

0 comments on commit 63a5a4a

Please sign in to comment.