fix space search bug

deepsource-autofix-76c6eb20
Dan Gowans 2023-01-24 14:45:45 -05:00
parent 19232ff1b6
commit 6a6081635d
4 changed files with 23 additions and 2 deletions

View File

@ -17,6 +17,9 @@ export function getLotNameWhereClause(lotName = '', lotNameSearchType, lotsTable
default: { default: {
const lotNamePieces = lotName.toLowerCase().split(' '); const lotNamePieces = lotName.toLowerCase().split(' ');
for (const lotNamePiece of lotNamePieces) { for (const lotNamePiece of lotNamePieces) {
if (lotNamePiece === '') {
continue;
}
sqlWhereClause += sqlWhereClause +=
' and instr(lower(' + lotsTableAlias + '.lotName), ?)'; ' and instr(lower(' + lotsTableAlias + '.lotName), ?)';
sqlParameters.push(lotNamePiece); sqlParameters.push(lotNamePiece);
@ -70,6 +73,9 @@ export function getOccupantNameWhereClause(occupantName = '', tableAlias = 'o')
if (occupantName !== '') { if (occupantName !== '') {
const occupantNamePieces = occupantName.toLowerCase().split(' '); const occupantNamePieces = occupantName.toLowerCase().split(' ');
for (const occupantNamePiece of occupantNamePieces) { for (const occupantNamePiece of occupantNamePieces) {
if (occupantNamePiece === '') {
continue;
}
sqlWhereClause += ` and instr(lower(${tableAlias}.occupantName), ?)`; sqlWhereClause += ` and instr(lower(${tableAlias}.occupantName), ?)`;
sqlParameters.push(occupantNamePiece); sqlParameters.push(occupantNamePiece);
} }

View File

@ -30,6 +30,10 @@ export function getLotNameWhereClause(
default: { default: {
const lotNamePieces = lotName.toLowerCase().split(' ') const lotNamePieces = lotName.toLowerCase().split(' ')
for (const lotNamePiece of lotNamePieces) { for (const lotNamePiece of lotNamePieces) {
if (lotNamePiece === '') {
continue
}
sqlWhereClause += sqlWhereClause +=
' and instr(lower(' + lotsTableAlias + '.lotName), ?)' ' and instr(lower(' + lotsTableAlias + '.lotName), ?)'
sqlParameters.push(lotNamePiece) sqlParameters.push(lotNamePiece)
@ -100,6 +104,10 @@ export function getOccupantNameWhereClause(
if (occupantName !== '') { if (occupantName !== '') {
const occupantNamePieces = occupantName.toLowerCase().split(' ') const occupantNamePieces = occupantName.toLowerCase().split(' ')
for (const occupantNamePiece of occupantNamePieces) { for (const occupantNamePiece of occupantNamePieces) {
if (occupantNamePiece === '') {
continue
}
sqlWhereClause += ` and instr(lower(${tableAlias}.occupantName), ?)` sqlWhereClause += ` and instr(lower(${tableAlias}.occupantName), ?)`
sqlParameters.push(occupantNamePiece) sqlParameters.push(occupantNamePiece)
} }

View File

@ -3,9 +3,12 @@ export async function getPastLotOccupancyOccupants(filters, options) {
const database = await acquireConnection(); const database = await acquireConnection();
let sqlWhereClause = ' where o.recordDelete_timeMillis is null and l.recordDelete_timeMillis is null'; let sqlWhereClause = ' where o.recordDelete_timeMillis is null and l.recordDelete_timeMillis is null';
const sqlParameters = []; const sqlParameters = [];
if (filters.searchFilter) { if (filters.searchFilter !== '') {
const searchFilterPieces = filters.searchFilter.split(' '); const searchFilterPieces = filters.searchFilter.split(' ');
for (const searchFilterPiece of searchFilterPieces) { for (const searchFilterPiece of searchFilterPieces) {
if (searchFilterPiece === '') {
continue;
}
sqlWhereClause += sqlWhereClause +=
" and (o.occupantName like '%' || ? || '%'" + " and (o.occupantName like '%' || ? || '%'" +
" or o.occupantAddress1 like '%' || ? || '%'" + " or o.occupantAddress1 like '%' || ? || '%'" +

View File

@ -21,10 +21,14 @@ export async function getPastLotOccupancyOccupants(
const sqlParameters: unknown[] = [] const sqlParameters: unknown[] = []
if (filters.searchFilter) { if (filters.searchFilter !== '') {
const searchFilterPieces = filters.searchFilter.split(' ') const searchFilterPieces = filters.searchFilter.split(' ')
for (const searchFilterPiece of searchFilterPieces) { for (const searchFilterPiece of searchFilterPieces) {
if (searchFilterPiece === '') {
continue
}
sqlWhereClause += sqlWhereClause +=
" and (o.occupantName like '%' || ? || '%'" + " and (o.occupantName like '%' || ? || '%'" +
" or o.occupantAddress1 like '%' || ? || '%'" + " or o.occupantAddress1 like '%' || ? || '%'" +