reduce duplication in sql filters
parent
ab7b5e6867
commit
d6229dd5de
|
|
@ -0,0 +1,15 @@
|
||||||
|
declare type LotNameSearchType = "startsWith" | "endsWith" | "";
|
||||||
|
export declare const getLotNameWhereClause: (lotName: string, lotNameSearchType: LotNameSearchType, lotsTableAlias?: string) => {
|
||||||
|
sqlWhereClause: string;
|
||||||
|
sqlParameters: any[];
|
||||||
|
};
|
||||||
|
declare type OccupancyTime = "" | "current" | "past" | "future";
|
||||||
|
export declare const getOccupancyTimeWhereClause: (occupancyTime: OccupancyTime, lotOccupanciesTableAlias?: string) => {
|
||||||
|
sqlWhereClause: string;
|
||||||
|
sqlParameters: any[];
|
||||||
|
};
|
||||||
|
export declare const getOccupantNameWhereClause: (occupantName: string, tableAlias?: string) => {
|
||||||
|
sqlWhereClause: string;
|
||||||
|
sqlParameters: any[];
|
||||||
|
};
|
||||||
|
export {};
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||||
|
export const getLotNameWhereClause = (lotName, lotNameSearchType, lotsTableAlias = "l") => {
|
||||||
|
let sqlWhereClause = "";
|
||||||
|
const sqlParameters = [];
|
||||||
|
if (lotName) {
|
||||||
|
switch (lotNameSearchType) {
|
||||||
|
case "startsWith": {
|
||||||
|
sqlWhereClause += " and " + lotsTableAlias + ".lotName like ? || '%'";
|
||||||
|
sqlParameters.push(lotName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "endsWith": {
|
||||||
|
sqlWhereClause += " and " + lotsTableAlias + ".lotName like '%' || ?";
|
||||||
|
sqlParameters.push(lotName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
const lotNamePieces = lotName.toLowerCase().split(" ");
|
||||||
|
for (const lotNamePiece of lotNamePieces) {
|
||||||
|
sqlWhereClause += " and instr(lower(" + lotsTableAlias + ".lotName), ?)";
|
||||||
|
sqlParameters.push(lotNamePiece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
sqlWhereClause,
|
||||||
|
sqlParameters
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export const getOccupancyTimeWhereClause = (occupancyTime, lotOccupanciesTableAlias = "o") => {
|
||||||
|
let sqlWhereClause = "";
|
||||||
|
const sqlParameters = [];
|
||||||
|
if (occupancyTime) {
|
||||||
|
const currentDateString = dateToInteger(new Date());
|
||||||
|
switch (occupancyTime) {
|
||||||
|
case "current": {
|
||||||
|
sqlWhereClause +=
|
||||||
|
" and " +
|
||||||
|
lotOccupanciesTableAlias +
|
||||||
|
".occupancyStartDate <= ? and (" +
|
||||||
|
lotOccupanciesTableAlias +
|
||||||
|
".occupancyEndDate is null or " +
|
||||||
|
lotOccupanciesTableAlias +
|
||||||
|
".occupancyEndDate >= ?)";
|
||||||
|
sqlParameters.push(currentDateString, currentDateString);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "past": {
|
||||||
|
sqlWhereClause += " and " + lotOccupanciesTableAlias + ".occupancyEndDate < ?";
|
||||||
|
sqlParameters.push(currentDateString);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "future": {
|
||||||
|
sqlWhereClause += " and " + lotOccupanciesTableAlias + ".occupancyStartDate > ?";
|
||||||
|
sqlParameters.push(currentDateString);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
sqlWhereClause,
|
||||||
|
sqlParameters
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export const getOccupantNameWhereClause = (occupantName, tableAlias = "o") => {
|
||||||
|
let sqlWhereClause = "";
|
||||||
|
const sqlParameters = [];
|
||||||
|
if (occupantName) {
|
||||||
|
const occupantNamePieces = occupantName.toLowerCase().split(" ");
|
||||||
|
for (const occupantNamePiece of occupantNamePieces) {
|
||||||
|
sqlWhereClause +=
|
||||||
|
" and " +
|
||||||
|
tableAlias +
|
||||||
|
".lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants where recordDelete_timeMillis is null and instr(lower(occupantName), ?))";
|
||||||
|
sqlParameters.push(occupantNamePiece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
sqlWhereClause,
|
||||||
|
sqlParameters
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,106 @@
|
||||||
|
import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||||
|
|
||||||
|
type LotNameSearchType = "startsWith" | "endsWith" | "";
|
||||||
|
|
||||||
|
export const getLotNameWhereClause = (
|
||||||
|
lotName: string,
|
||||||
|
lotNameSearchType: LotNameSearchType,
|
||||||
|
lotsTableAlias = "l"
|
||||||
|
) => {
|
||||||
|
let sqlWhereClause = "";
|
||||||
|
const sqlParameters = [];
|
||||||
|
|
||||||
|
if (lotName) {
|
||||||
|
switch (lotNameSearchType) {
|
||||||
|
case "startsWith": {
|
||||||
|
sqlWhereClause += " and " + lotsTableAlias + ".lotName like ? || '%'";
|
||||||
|
sqlParameters.push(lotName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "endsWith": {
|
||||||
|
sqlWhereClause += " and " + lotsTableAlias + ".lotName like '%' || ?";
|
||||||
|
sqlParameters.push(lotName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
const lotNamePieces = lotName.toLowerCase().split(" ");
|
||||||
|
for (const lotNamePiece of lotNamePieces) {
|
||||||
|
sqlWhereClause += " and instr(lower(" + lotsTableAlias + ".lotName), ?)";
|
||||||
|
sqlParameters.push(lotNamePiece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
sqlWhereClause,
|
||||||
|
sqlParameters
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
type OccupancyTime = "" | "current" | "past" | "future";
|
||||||
|
|
||||||
|
export const getOccupancyTimeWhereClause = (
|
||||||
|
occupancyTime: OccupancyTime,
|
||||||
|
lotOccupanciesTableAlias = "o"
|
||||||
|
) => {
|
||||||
|
let sqlWhereClause = "";
|
||||||
|
const sqlParameters = [];
|
||||||
|
|
||||||
|
if (occupancyTime) {
|
||||||
|
const currentDateString = dateToInteger(new Date());
|
||||||
|
|
||||||
|
switch (occupancyTime) {
|
||||||
|
case "current": {
|
||||||
|
sqlWhereClause +=
|
||||||
|
" and " +
|
||||||
|
lotOccupanciesTableAlias +
|
||||||
|
".occupancyStartDate <= ? and (" +
|
||||||
|
lotOccupanciesTableAlias +
|
||||||
|
".occupancyEndDate is null or " +
|
||||||
|
lotOccupanciesTableAlias +
|
||||||
|
".occupancyEndDate >= ?)";
|
||||||
|
sqlParameters.push(currentDateString, currentDateString);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "past": {
|
||||||
|
sqlWhereClause += " and " + lotOccupanciesTableAlias + ".occupancyEndDate < ?";
|
||||||
|
sqlParameters.push(currentDateString);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "future": {
|
||||||
|
sqlWhereClause += " and " + lotOccupanciesTableAlias + ".occupancyStartDate > ?";
|
||||||
|
sqlParameters.push(currentDateString);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
sqlWhereClause,
|
||||||
|
sqlParameters
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getOccupantNameWhereClause = (occupantName: string, tableAlias = "o") => {
|
||||||
|
let sqlWhereClause = "";
|
||||||
|
const sqlParameters = [];
|
||||||
|
|
||||||
|
if (occupantName) {
|
||||||
|
const occupantNamePieces = occupantName.toLowerCase().split(" ");
|
||||||
|
for (const occupantNamePiece of occupantNamePieces) {
|
||||||
|
sqlWhereClause +=
|
||||||
|
" and " +
|
||||||
|
tableAlias +
|
||||||
|
".lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants where recordDelete_timeMillis is null and instr(lower(occupantName), ?))";
|
||||||
|
sqlParameters.push(occupantNamePiece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
sqlWhereClause,
|
||||||
|
sqlParameters
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import sqlite from "better-sqlite3";
|
import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { dateIntegerToString, dateStringToInteger, dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateIntegerToString, dateStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from "../functions.config.js";
|
||||||
import { getOccupancyTypeById } from "../functions.cache.js";
|
import { getOccupancyTypeById } from "../functions.cache.js";
|
||||||
import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js";
|
import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js";
|
||||||
|
import { getLotNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from "../functions.sqlFilters.js";
|
||||||
const buildWhereClause = (filters) => {
|
const buildWhereClause = (filters) => {
|
||||||
let sqlWhereClause = " where o.recordDelete_timeMillis is null";
|
let sqlWhereClause = " where o.recordDelete_timeMillis is null";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
|
|
@ -11,56 +12,19 @@ const buildWhereClause = (filters) => {
|
||||||
sqlWhereClause += " and o.lotId = ?";
|
sqlWhereClause += " and o.lotId = ?";
|
||||||
sqlParameters.push(filters.lotId);
|
sqlParameters.push(filters.lotId);
|
||||||
}
|
}
|
||||||
if (filters.lotName) {
|
const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType, "l");
|
||||||
if (filters.lotNameSearchType === "startsWith") {
|
sqlWhereClause += lotNameFilters.sqlWhereClause;
|
||||||
sqlWhereClause += " and l.lotName like ? || '%'";
|
sqlParameters.push(...lotNameFilters.sqlParameters);
|
||||||
sqlParameters.push(filters.lotName);
|
const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, "o");
|
||||||
}
|
sqlWhereClause += occupantNameFilters.sqlWhereClause;
|
||||||
else if (filters.lotNameSearchType === "endsWith") {
|
sqlParameters.push(...occupantNameFilters.sqlParameters);
|
||||||
sqlWhereClause += " and l.lotName like '%' || ?";
|
|
||||||
sqlParameters.push(filters.lotName);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const lotNamePieces = filters.lotName.toLowerCase().split(" ");
|
|
||||||
for (const lotNamePiece of lotNamePieces) {
|
|
||||||
sqlWhereClause += " and instr(lower(l.lotName), ?)";
|
|
||||||
sqlParameters.push(lotNamePiece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (filters.occupantName) {
|
|
||||||
const occupantNamePieces = filters.occupantName.toLowerCase().split(" ");
|
|
||||||
for (const occupantNamePiece of occupantNamePieces) {
|
|
||||||
sqlWhereClause +=
|
|
||||||
" and o.lotOccupancyId in (select oo.lotOccupancyId from LotOccupancyOccupants oo where oo.recordDelete_timeMillis is null and instr(lower(oo.occupantName), ?))";
|
|
||||||
sqlParameters.push(occupantNamePiece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (filters.occupancyTypeId) {
|
if (filters.occupancyTypeId) {
|
||||||
sqlWhereClause += " and o.occupancyTypeId = ?";
|
sqlWhereClause += " and o.occupancyTypeId = ?";
|
||||||
sqlParameters.push(filters.occupancyTypeId);
|
sqlParameters.push(filters.occupancyTypeId);
|
||||||
}
|
}
|
||||||
if (filters.occupancyTime) {
|
const occupancyTimeFilters = getOccupancyTimeWhereClause(filters.occupancyTime, "o");
|
||||||
const currentDateString = dateToInteger(new Date());
|
sqlWhereClause += occupancyTimeFilters.sqlWhereClause;
|
||||||
switch (filters.occupancyTime) {
|
sqlParameters.push(...occupancyTimeFilters.sqlParameters);
|
||||||
case "current": {
|
|
||||||
sqlWhereClause +=
|
|
||||||
" and o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)";
|
|
||||||
sqlParameters.push(currentDateString, currentDateString);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "past": {
|
|
||||||
sqlWhereClause += " and o.occupancyEndDate < ?";
|
|
||||||
sqlParameters.push(currentDateString);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "future": {
|
|
||||||
sqlWhereClause += " and o.occupancyStartDate > ?";
|
|
||||||
sqlParameters.push(currentDateString);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (filters.occupancyStartDateString) {
|
if (filters.occupancyStartDateString) {
|
||||||
sqlWhereClause += " and o.occupancyStartDate = ?";
|
sqlWhereClause += " and o.occupancyStartDate = ?";
|
||||||
sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString));
|
sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString));
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import { getOccupancyTypeById } from "../functions.cache.js";
|
||||||
import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js";
|
import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
import { getLotNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from "../functions.sqlFilters.js";
|
||||||
|
|
||||||
interface GetLotOccupanciesFilters {
|
interface GetLotOccupanciesFilters {
|
||||||
lotId?: number | string;
|
lotId?: number | string;
|
||||||
|
|
@ -47,60 +48,22 @@ const buildWhereClause = (
|
||||||
sqlParameters.push(filters.lotId);
|
sqlParameters.push(filters.lotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filters.lotName) {
|
const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType, "l");
|
||||||
if (filters.lotNameSearchType === "startsWith") {
|
sqlWhereClause += lotNameFilters.sqlWhereClause;
|
||||||
sqlWhereClause += " and l.lotName like ? || '%'";
|
sqlParameters.push(...lotNameFilters.sqlParameters);
|
||||||
sqlParameters.push(filters.lotName);
|
|
||||||
} else if (filters.lotNameSearchType === "endsWith") {
|
|
||||||
sqlWhereClause += " and l.lotName like '%' || ?";
|
|
||||||
sqlParameters.push(filters.lotName);
|
|
||||||
} else {
|
|
||||||
const lotNamePieces = filters.lotName.toLowerCase().split(" ");
|
|
||||||
for (const lotNamePiece of lotNamePieces) {
|
|
||||||
sqlWhereClause += " and instr(lower(l.lotName), ?)";
|
|
||||||
sqlParameters.push(lotNamePiece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filters.occupantName) {
|
const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, "o");
|
||||||
const occupantNamePieces = filters.occupantName.toLowerCase().split(" ");
|
sqlWhereClause += occupantNameFilters.sqlWhereClause;
|
||||||
for (const occupantNamePiece of occupantNamePieces) {
|
sqlParameters.push(...occupantNameFilters.sqlParameters);
|
||||||
sqlWhereClause +=
|
|
||||||
" and o.lotOccupancyId in (select oo.lotOccupancyId from LotOccupancyOccupants oo where oo.recordDelete_timeMillis is null and instr(lower(oo.occupantName), ?))";
|
|
||||||
sqlParameters.push(occupantNamePiece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filters.occupancyTypeId) {
|
if (filters.occupancyTypeId) {
|
||||||
sqlWhereClause += " and o.occupancyTypeId = ?";
|
sqlWhereClause += " and o.occupancyTypeId = ?";
|
||||||
sqlParameters.push(filters.occupancyTypeId);
|
sqlParameters.push(filters.occupancyTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filters.occupancyTime) {
|
const occupancyTimeFilters = getOccupancyTimeWhereClause(filters.occupancyTime, "o");
|
||||||
const currentDateString = dateToInteger(new Date());
|
sqlWhereClause += occupancyTimeFilters.sqlWhereClause;
|
||||||
|
sqlParameters.push(...occupancyTimeFilters.sqlParameters);
|
||||||
switch (filters.occupancyTime) {
|
|
||||||
case "current": {
|
|
||||||
sqlWhereClause +=
|
|
||||||
" and o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)";
|
|
||||||
sqlParameters.push(currentDateString, currentDateString);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "past": {
|
|
||||||
sqlWhereClause += " and o.occupancyEndDate < ?";
|
|
||||||
sqlParameters.push(currentDateString);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "future": {
|
|
||||||
sqlWhereClause += " and o.occupancyStartDate > ?";
|
|
||||||
sqlParameters.push(currentDateString);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filters.occupancyStartDateString) {
|
if (filters.occupancyStartDateString) {
|
||||||
sqlWhereClause += " and o.occupancyStartDate = ?";
|
sqlWhereClause += " and o.occupancyStartDate = ?";
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,13 @@ import sqlite from "better-sqlite3";
|
||||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from "../functions.config.js";
|
||||||
|
import { getLotNameWhereClause } from "../functions.sqlFilters.js";
|
||||||
const buildWhereClause = (filters) => {
|
const buildWhereClause = (filters) => {
|
||||||
let sqlWhereClause = " where l.recordDelete_timeMillis is null";
|
let sqlWhereClause = " where l.recordDelete_timeMillis is null";
|
||||||
const sqlParameters = [];
|
const sqlParameters = [];
|
||||||
if (filters.lotName) {
|
const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType, "l");
|
||||||
if (filters.lotNameSearchType === "startsWith") {
|
sqlWhereClause += lotNameFilters.sqlWhereClause;
|
||||||
sqlWhereClause += " and l.lotName like ? || '%'";
|
sqlParameters.push(...lotNameFilters.sqlParameters);
|
||||||
sqlParameters.push(filters.lotName);
|
|
||||||
}
|
|
||||||
else if (filters.lotNameSearchType === "endsWith") {
|
|
||||||
sqlWhereClause += " and l.lotName like '%' || ?";
|
|
||||||
sqlParameters.push(filters.lotName);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const lotNamePieces = filters.lotName.toLowerCase().split(" ");
|
|
||||||
for (const lotNamePiece of lotNamePieces) {
|
|
||||||
sqlWhereClause += " and instr(lower(l.lotName), ?)";
|
|
||||||
sqlParameters.push(lotNamePiece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (filters.mapId) {
|
if (filters.mapId) {
|
||||||
sqlWhereClause += " and l.mapId = ?";
|
sqlWhereClause += " and l.mapId = ?";
|
||||||
sqlParameters.push(filters.mapId);
|
sqlParameters.push(filters.mapId);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js";
|
||||||
import * as configFunctions from "../functions.config.js";
|
import * as configFunctions from "../functions.config.js";
|
||||||
|
|
||||||
import type * as recordTypes from "../../types/recordTypes";
|
import type * as recordTypes from "../../types/recordTypes";
|
||||||
|
import { getLotNameWhereClause } from "../functions.sqlFilters.js";
|
||||||
|
|
||||||
interface GetLotsFilters {
|
interface GetLotsFilters {
|
||||||
lotNameSearchType?: "" | "startsWith" | "endsWith";
|
lotNameSearchType?: "" | "startsWith" | "endsWith";
|
||||||
|
|
@ -27,22 +28,9 @@ const buildWhereClause = (filters: GetLotsFilters): { sqlWhereClause: string; sq
|
||||||
let sqlWhereClause = " where l.recordDelete_timeMillis is null";
|
let sqlWhereClause = " where l.recordDelete_timeMillis is null";
|
||||||
const sqlParameters: unknown[] = [];
|
const sqlParameters: unknown[] = [];
|
||||||
|
|
||||||
if (filters.lotName) {
|
const lotNameFilters = getLotNameWhereClause(filters.lotName, filters.lotNameSearchType, "l");
|
||||||
if (filters.lotNameSearchType === "startsWith") {
|
sqlWhereClause += lotNameFilters.sqlWhereClause;
|
||||||
sqlWhereClause += " and l.lotName like ? || '%'";
|
sqlParameters.push(...lotNameFilters.sqlParameters);
|
||||||
sqlParameters.push(filters.lotName);
|
|
||||||
} else if (filters.lotNameSearchType === "endsWith") {
|
|
||||||
sqlWhereClause += " and l.lotName like '%' || ?";
|
|
||||||
sqlParameters.push(filters.lotName);
|
|
||||||
} else {
|
|
||||||
const lotNamePieces = filters.lotName.toLowerCase().split(" ");
|
|
||||||
for (const lotNamePiece of lotNamePieces) {
|
|
||||||
sqlWhereClause += " and instr(lower(l.lotName), ?)";
|
|
||||||
sqlParameters.push(lotNamePiece);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (filters.mapId) {
|
if (filters.mapId) {
|
||||||
sqlWhereClause += " and l.mapId = ?";
|
sqlWhereClause += " and l.mapId = ?";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue