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

Add cast from enum to string before lowercasing in filtered query #264

Merged
merged 3 commits into from
Jul 26, 2021
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format

(_Note:_ it our intention to improve our release process going forward by using [Semantic Versioning](https://semver.org/spec/v2.0.0.html).)

## Detroit Team M8
- Added:
- Made `addFilters()` more generic ([#257](https://github.com/CityOfDetroit/bloom/pull/257))
- Fixed lowercaseing issue in query built by `addFilters()` ([#264](https://github.com/CityOfDetroit/bloom/pull/264))

## Detroit Team M7
- Added:
- Debug flags for public and partner site ([#195](https://github.com/CityOfDetroit/bloom/pull/195))
Expand Down
2 changes: 1 addition & 1 deletion backend/core/src/listings/listings.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("ListingsService", () => {

expect(listings.items).toEqual(mockListingsDto)
expect(mockQueryBuilder.andWhere).toHaveBeenCalledWith(
"LOWER(property.neighborhood) = LOWER(:neighborhood_0)",
"LOWER(CAST(property.neighborhood as text)) = LOWER(:neighborhood_0)",
{
neighborhood_0: expectedNeighborhood,
}
Expand Down
2 changes: 1 addition & 1 deletion backend/core/src/shared/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function addFilters<FilterParams, FilterFieldMap>(
// Each WHERE param must be unique across the entire QueryBuilder
const whereParameterName = `${filterType}_${i}`
qb.andWhere(
`LOWER(${filterTypeToFieldMap[filterType.toLowerCase()]}) ${
`LOWER(CAST(${filterTypeToFieldMap[filterType.toLowerCase()]} as text)) ${
comparisonsForCurrentFilter[i]
} LOWER(:${whereParameterName})`,
{
Expand Down