fix occupantname filter

deepsource-autofix-76c6eb20
Dan Gowans 2022-12-28 16:14:03 -05:00
parent 586450d6f8
commit bd70eaa955
6 changed files with 15 additions and 14 deletions

View File

@ -69,10 +69,7 @@ export const 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) {
sqlWhereClause += sqlWhereClause += " and instr(lower(" + tableAlias + ".occupantName), ?)";
" and " +
tableAlias +
".lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants where recordDelete_timeMillis is null and instr(lower(occupantName), ?))";
sqlParameters.push(occupantNamePiece); sqlParameters.push(occupantNamePiece);
} }
} }

View File

@ -91,10 +91,7 @@ export const getOccupantNameWhereClause = (occupantName: string, 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) {
sqlWhereClause += sqlWhereClause += " and instr(lower(" + tableAlias + ".occupantName), ?)";
" and " +
tableAlias +
".lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants where recordDelete_timeMillis is null and instr(lower(occupantName), ?))";
sqlParameters.push(occupantNamePiece); sqlParameters.push(occupantNamePiece);
} }
} }

View File

@ -16,8 +16,10 @@ const buildWhereClause = (filters) => {
sqlWhereClause += lotNameFilters.sqlWhereClause; sqlWhereClause += lotNameFilters.sqlWhereClause;
sqlParameters.push(...lotNameFilters.sqlParameters); sqlParameters.push(...lotNameFilters.sqlParameters);
const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, "o"); const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, "o");
sqlWhereClause += occupantNameFilters.sqlWhereClause; if (occupantNameFilters.sqlParameters.length > 0) {
sqlWhereClause += " and o.lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null" + occupantNameFilters.sqlWhereClause + ")";
sqlParameters.push(...occupantNameFilters.sqlParameters); sqlParameters.push(...occupantNameFilters.sqlParameters);
}
if (filters.occupancyTypeId) { if (filters.occupancyTypeId) {
sqlWhereClause += " and o.occupancyTypeId = ?"; sqlWhereClause += " and o.occupancyTypeId = ?";
sqlParameters.push(filters.occupancyTypeId); sqlParameters.push(filters.occupancyTypeId);

View File

@ -4,8 +4,7 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { import {
dateIntegerToString, dateIntegerToString,
dateStringToInteger, dateStringToInteger
dateToInteger
} from "@cityssm/expressjs-server-js/dateTimeFns.js"; } from "@cityssm/expressjs-server-js/dateTimeFns.js";
import * as configFunctions from "../functions.config.js"; import * as configFunctions from "../functions.config.js";
@ -53,8 +52,10 @@ const buildWhereClause = (
sqlParameters.push(...lotNameFilters.sqlParameters); sqlParameters.push(...lotNameFilters.sqlParameters);
const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, "o"); const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, "o");
sqlWhereClause += occupantNameFilters.sqlWhereClause; if (occupantNameFilters.sqlParameters.length > 0) {
sqlWhereClause += " and o.lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null" + occupantNameFilters.sqlWhereClause + ")";
sqlParameters.push(...occupantNameFilters.sqlParameters); sqlParameters.push(...occupantNameFilters.sqlParameters);
}
if (filters.occupancyTypeId) { if (filters.occupancyTypeId) {
sqlWhereClause += " and o.occupancyTypeId = ?"; sqlWhereClause += " and o.occupancyTypeId = ?";

View File

@ -31,7 +31,9 @@ const buildWhereClause = (filters) => {
" and w.workOrderId in (" + " and w.workOrderId in (" +
"select workOrderId from WorkOrderLotOccupancies o" + "select workOrderId from WorkOrderLotOccupancies o" +
" where recordDelete_timeMillis is null" + " where recordDelete_timeMillis is null" +
" and o.lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null" +
occupantNameFilters.sqlWhereClause + occupantNameFilters.sqlWhereClause +
")" +
")"; ")";
sqlParameters.push(...occupantNameFilters.sqlParameters); sqlParameters.push(...occupantNameFilters.sqlParameters);
} }

View File

@ -62,7 +62,9 @@ const buildWhereClause = (
" and w.workOrderId in (" + " and w.workOrderId in (" +
"select workOrderId from WorkOrderLotOccupancies o" + "select workOrderId from WorkOrderLotOccupancies o" +
" where recordDelete_timeMillis is null" + " where recordDelete_timeMillis is null" +
" and o.lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null" +
occupantNameFilters.sqlWhereClause + occupantNameFilters.sqlWhereClause +
")" +
")"; ")";
sqlParameters.push(...occupantNameFilters.sqlParameters); sqlParameters.push(...occupantNameFilters.sqlParameters);
} }