From 6a6081635db5e271b8029eb9c5031afc1a54cf12 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Tue, 24 Jan 2023 14:45:45 -0500 Subject: [PATCH] fix space search bug --- helpers/functions.sqlFilters.js | 6 ++++++ helpers/functions.sqlFilters.ts | 8 ++++++++ helpers/lotOccupancyDB/getPastLotOccupancyOccupants.js | 5 ++++- helpers/lotOccupancyDB/getPastLotOccupancyOccupants.ts | 6 +++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/helpers/functions.sqlFilters.js b/helpers/functions.sqlFilters.js index 9effeab7..b14b4126 100644 --- a/helpers/functions.sqlFilters.js +++ b/helpers/functions.sqlFilters.js @@ -17,6 +17,9 @@ export function getLotNameWhereClause(lotName = '', lotNameSearchType, lotsTable default: { const lotNamePieces = lotName.toLowerCase().split(' '); for (const lotNamePiece of lotNamePieces) { + if (lotNamePiece === '') { + continue; + } sqlWhereClause += ' and instr(lower(' + lotsTableAlias + '.lotName), ?)'; sqlParameters.push(lotNamePiece); @@ -70,6 +73,9 @@ export function getOccupantNameWhereClause(occupantName = '', tableAlias = 'o') if (occupantName !== '') { const occupantNamePieces = occupantName.toLowerCase().split(' '); for (const occupantNamePiece of occupantNamePieces) { + if (occupantNamePiece === '') { + continue; + } sqlWhereClause += ` and instr(lower(${tableAlias}.occupantName), ?)`; sqlParameters.push(occupantNamePiece); } diff --git a/helpers/functions.sqlFilters.ts b/helpers/functions.sqlFilters.ts index 042ff36a..6aa7145e 100644 --- a/helpers/functions.sqlFilters.ts +++ b/helpers/functions.sqlFilters.ts @@ -30,6 +30,10 @@ export function getLotNameWhereClause( default: { const lotNamePieces = lotName.toLowerCase().split(' ') for (const lotNamePiece of lotNamePieces) { + if (lotNamePiece === '') { + continue + } + sqlWhereClause += ' and instr(lower(' + lotsTableAlias + '.lotName), ?)' sqlParameters.push(lotNamePiece) @@ -100,6 +104,10 @@ export function getOccupantNameWhereClause( if (occupantName !== '') { const occupantNamePieces = occupantName.toLowerCase().split(' ') for (const occupantNamePiece of occupantNamePieces) { + if (occupantNamePiece === '') { + continue + } + sqlWhereClause += ` and instr(lower(${tableAlias}.occupantName), ?)` sqlParameters.push(occupantNamePiece) } diff --git a/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.js b/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.js index 458909bc..b8213f40 100644 --- a/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.js +++ b/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.js @@ -3,9 +3,12 @@ export async function getPastLotOccupancyOccupants(filters, options) { const database = await acquireConnection(); let sqlWhereClause = ' where o.recordDelete_timeMillis is null and l.recordDelete_timeMillis is null'; const sqlParameters = []; - if (filters.searchFilter) { + if (filters.searchFilter !== '') { const searchFilterPieces = filters.searchFilter.split(' '); for (const searchFilterPiece of searchFilterPieces) { + if (searchFilterPiece === '') { + continue; + } sqlWhereClause += " and (o.occupantName like '%' || ? || '%'" + " or o.occupantAddress1 like '%' || ? || '%'" + diff --git a/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.ts b/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.ts index 64910e5f..a33bd0ba 100644 --- a/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.ts +++ b/helpers/lotOccupancyDB/getPastLotOccupancyOccupants.ts @@ -21,10 +21,14 @@ export async function getPastLotOccupancyOccupants( const sqlParameters: unknown[] = [] - if (filters.searchFilter) { + if (filters.searchFilter !== '') { const searchFilterPieces = filters.searchFilter.split(' ') for (const searchFilterPiece of searchFilterPieces) { + if (searchFilterPiece === '') { + continue + } + sqlWhereClause += " and (o.occupantName like '%' || ? || '%'" + " or o.occupantAddress1 like '%' || ? || '%'" +