deepsource-autofix-76c6eb20
Dan Gowans 2023-01-19 14:31:40 -05:00
parent 5276c7e962
commit 285704daab
38 changed files with 124 additions and 124 deletions

4
app.ts
View File

@ -1,5 +1,5 @@
import createError from 'http-errors' import createError from 'http-errors'
import express from 'express' import express, { RequestHandler } from 'express'
import compression from 'compression' import compression from 'compression'
import path from 'node:path' import path from 'node:path'
@ -233,7 +233,7 @@ app.get(urlPrefix + '/', sessionChecker, (_request, response) => {
app.use(urlPrefix + '/dashboard', sessionChecker, routerDashboard) app.use(urlPrefix + '/dashboard', sessionChecker, routerDashboard)
app.use(urlPrefix + '/api/:apiKey', apiGetHandler, routerApi) app.use(urlPrefix + '/api/:apiKey', apiGetHandler as RequestHandler, routerApi)
app.use(urlPrefix + '/print', sessionChecker, routerPrint) app.use(urlPrefix + '/print', sessionChecker, routerPrint)
app.use(urlPrefix + '/maps', sessionChecker, routerMaps) app.use(urlPrefix + '/maps', sessionChecker, routerMaps)

View File

@ -5,7 +5,7 @@ import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummar
import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js'; import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js';
export async function handler(request, response) { export async function handler(request, response) {
const map = await getMap(request.params.mapId); const map = await getMap(request.params.mapId);
if (!map) { if (map === undefined) {
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
'/maps/?error=mapIdNotFound'); '/maps/?error=mapIdNotFound');
return; return;

View File

@ -14,7 +14,7 @@ export async function handler(
): Promise<void> { ): Promise<void> {
const map = await getMap(request.params.mapId) const map = await getMap(request.params.mapId)
if (!map) { if (map === undefined) {
response.redirect( response.redirect(
configFunctions.getProperty('reverseProxy.urlPrefix') + configFunctions.getProperty('reverseProxy.urlPrefix') +
'/maps/?error=mapIdNotFound' '/maps/?error=mapIdNotFound'

View File

@ -4,7 +4,7 @@ import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSu
import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js'; import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js';
export async function handler(request, response) { export async function handler(request, response) {
const map = await getMap(request.params.mapId); const map = await getMap(request.params.mapId);
if (!map) { if (map === undefined) {
response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') +
'/maps/?error=mapIdNotFound'); '/maps/?error=mapIdNotFound');
return; return;

View File

@ -9,7 +9,7 @@ import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummar
export async function handler(request: Request, response: Response): Promise<void> { export async function handler(request: Request, response: Response): Promise<void> {
const map = await getMap(request.params.mapId) const map = await getMap(request.params.mapId)
if (!map) { if (map === undefined) {
response.redirect( response.redirect(
configFunctions.getProperty('reverseProxy.urlPrefix') + configFunctions.getProperty('reverseProxy.urlPrefix') +
'/maps/?error=mapIdNotFound' '/maps/?error=mapIdNotFound'

View File

@ -23,7 +23,7 @@ async function saveApiKeys() {
} }
} }
function generateApiKey(apiKeyPrefix) { function generateApiKey(apiKeyPrefix) {
return `${apiKeyPrefix}-${uuidv4()}-${Date.now()}`; return `${apiKeyPrefix}-${uuidv4()}-${Date.now().toString()}`;
} }
export async function regenerateApiKey(userName) { export async function regenerateApiKey(userName) {
apiKeys[userName] = generateApiKey(userName); apiKeys[userName] = generateApiKey(userName);

View File

@ -29,7 +29,7 @@ async function saveApiKeys(): Promise<void> {
} }
function generateApiKey(apiKeyPrefix: string): string { function generateApiKey(apiKeyPrefix: string): string {
return `${apiKeyPrefix}-${uuidv4()}-${Date.now()}` return `${apiKeyPrefix}-${uuidv4()}-${Date.now().toString()}`
} }
export async function regenerateApiKey(userName: string): Promise<void> { export async function regenerateApiKey(userName: string): Promise<void> {

View File

@ -16,7 +16,7 @@ export async function addLot(lotForm, requestSession) {
const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(','); const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(',');
for (const lotTypeFieldId of lotTypeFieldIds) { for (const lotTypeFieldId of lotTypeFieldIds) {
const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId]; const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId];
if (lotFieldValue && lotFieldValue !== '') { if ((lotFieldValue ?? '') !== '') {
await addOrUpdateLotField({ await addOrUpdateLotField({
lotId, lotId,
lotTypeFieldId, lotTypeFieldId,

View File

@ -58,7 +58,7 @@ export async function addLot(
for (const lotTypeFieldId of lotTypeFieldIds) { for (const lotTypeFieldId of lotTypeFieldIds) {
const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId] as string const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId] as string
if (lotFieldValue && lotFieldValue !== '') { if ((lotFieldValue ?? '') !== '') {
await addOrUpdateLotField( await addOrUpdateLotField(
{ {
lotId, lotId,

View File

@ -23,7 +23,7 @@ export async function addLotOccupancy(lotOccupancyForm, requestSession, connecte
const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds ?? '').split(','); const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds ?? '').split(',');
for (const occupancyTypeFieldId of occupancyTypeFieldIds) { for (const occupancyTypeFieldId of occupancyTypeFieldIds) {
const lotOccupancyFieldValue = lotOccupancyForm['lotOccupancyFieldValue_' + occupancyTypeFieldId]; const lotOccupancyFieldValue = lotOccupancyForm['lotOccupancyFieldValue_' + occupancyTypeFieldId];
if (lotOccupancyFieldValue && lotOccupancyFieldValue !== '') { if ((lotOccupancyFieldValue ?? '') !== '') {
await addOrUpdateLotOccupancyField({ await addOrUpdateLotOccupancyField({
lotOccupancyId, lotOccupancyId,
occupancyTypeFieldId, occupancyTypeFieldId,
@ -31,7 +31,7 @@ export async function addLotOccupancy(lotOccupancyForm, requestSession, connecte
}, requestSession, database); }, requestSession, database);
} }
} }
if (lotOccupancyForm.lotOccupantTypeId) { if ((lotOccupancyForm.lotOccupantTypeId ?? '') !== '') {
await addLotOccupancyOccupant({ await addLotOccupancyOccupant({
lotOccupancyId, lotOccupancyId,
lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId, lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId,

View File

@ -83,7 +83,7 @@ export async function addLotOccupancy(
'lotOccupancyFieldValue_' + occupancyTypeFieldId 'lotOccupancyFieldValue_' + occupancyTypeFieldId
] as string ] as string
if (lotOccupancyFieldValue && lotOccupancyFieldValue !== '') { if ((lotOccupancyFieldValue ?? '') !== '') {
await addOrUpdateLotOccupancyField( await addOrUpdateLotOccupancyField(
{ {
lotOccupancyId, lotOccupancyId,
@ -96,11 +96,11 @@ export async function addLotOccupancy(
} }
} }
if (lotOccupancyForm.lotOccupantTypeId) { if ((lotOccupancyForm.lotOccupantTypeId ?? '') !== '') {
await addLotOccupancyOccupant( await addLotOccupancyOccupant(
{ {
lotOccupancyId, lotOccupancyId,
lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId, lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId!,
occupantName: lotOccupancyForm.occupantName!, occupantName: lotOccupancyForm.occupantName!,
occupantAddress1: lotOccupancyForm.occupantAddress1!, occupantAddress1: lotOccupancyForm.occupantAddress1!,
occupantAddress2: lotOccupancyForm.occupantAddress2!, occupantAddress2: lotOccupancyForm.occupantAddress2!,

View File

@ -9,7 +9,7 @@ export async function addLotOccupancyOccupant(lotOccupancyOccupantForm, requestS
order by lotOccupantIndex desc order by lotOccupantIndex desc
limit 1`) limit 1`)
.get(lotOccupancyOccupantForm.lotOccupancyId); .get(lotOccupancyOccupantForm.lotOccupancyId);
if (maxIndexResult) { if (maxIndexResult !== undefined) {
lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1; lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1;
} }
const rightNowMillis = Date.now(); const rightNowMillis = Date.now();

View File

@ -36,7 +36,7 @@ export async function addLotOccupancyOccupant(
) )
.get(lotOccupancyOccupantForm.lotOccupancyId) .get(lotOccupancyOccupantForm.lotOccupancyId)
if (maxIndexResult) { if (maxIndexResult !== undefined) {
lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1 lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1
} }

View File

@ -10,7 +10,7 @@ export async function addLotOccupancyTransaction(lotOccupancyTransactionForm, re
order by transactionIndex desc order by transactionIndex desc
limit 1`) limit 1`)
.get(lotOccupancyTransactionForm.lotOccupancyId); .get(lotOccupancyTransactionForm.lotOccupancyId);
if (maxIndexResult) { if (maxIndexResult !== undefined) {
transactionIndex = maxIndexResult.transactionIndex + 1; transactionIndex = maxIndexResult.transactionIndex + 1;
} }
const rightNow = new Date(); const rightNow = new Date();

View File

@ -36,7 +36,7 @@ export async function addLotOccupancyTransaction(
) )
.get(lotOccupancyTransactionForm.lotOccupancyId) .get(lotOccupancyTransactionForm.lotOccupancyId)
if (maxIndexResult) { if (maxIndexResult !== undefined) {
transactionIndex = maxIndexResult.transactionIndex + 1 transactionIndex = maxIndexResult.transactionIndex + 1
} }

View File

@ -1,5 +1,3 @@
import sqlite from 'better-sqlite3'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
import type * as recordTypes from '../../types/recordTypes' import type * as recordTypes from '../../types/recordTypes'

View File

@ -8,7 +8,16 @@ export async function addWorkOrderLot(workOrderLotForm, requestSession) {
where workOrderId = ? where workOrderId = ?
and lotId = ?`) and lotId = ?`)
.get(workOrderLotForm.workOrderId, workOrderLotForm.lotId); .get(workOrderLotForm.workOrderId, workOrderLotForm.lotId);
if (row) { if (row === undefined) {
database
.prepare(`insert into WorkOrderLots (
workOrderId, lotId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`)
.run(workOrderLotForm.workOrderId, workOrderLotForm.lotId, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
}
else {
if (row.recordDelete_timeMillis) { if (row.recordDelete_timeMillis) {
database database
.prepare(`update WorkOrderLots .prepare(`update WorkOrderLots
@ -23,15 +32,6 @@ export async function addWorkOrderLot(workOrderLotForm, requestSession) {
.run(requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis, workOrderLotForm.workOrderId, workOrderLotForm.lotId); .run(requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis, workOrderLotForm.workOrderId, workOrderLotForm.lotId);
} }
} }
else {
database
.prepare(`insert into WorkOrderLots (
workOrderId, lotId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`)
.run(workOrderLotForm.workOrderId, workOrderLotForm.lotId, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
}
database.release(); database.release();
return true; return true;
} }

View File

@ -24,7 +24,24 @@ export async function addWorkOrderLot(
) )
.get(workOrderLotForm.workOrderId, workOrderLotForm.lotId) .get(workOrderLotForm.workOrderId, workOrderLotForm.lotId)
if (row) { if (row === undefined) {
database
.prepare(
`insert into WorkOrderLots (
workOrderId, lotId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`
)
.run(
workOrderLotForm.workOrderId,
workOrderLotForm.lotId,
requestSession.user!.userName,
rightNowMillis,
requestSession.user!.userName,
rightNowMillis
)
} else {
if (row.recordDelete_timeMillis) { if (row.recordDelete_timeMillis) {
database database
.prepare( .prepare(
@ -47,23 +64,6 @@ export async function addWorkOrderLot(
workOrderLotForm.lotId workOrderLotForm.lotId
) )
} }
} else {
database
.prepare(
`insert into WorkOrderLots (
workOrderId, lotId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`
)
.run(
workOrderLotForm.workOrderId,
workOrderLotForm.lotId,
requestSession.user!.userName,
rightNowMillis,
requestSession.user!.userName,
rightNowMillis
)
} }
database.release() database.release()

View File

@ -8,7 +8,16 @@ export async function addWorkOrderLotOccupancy(workOrderLotOccupancyForm, reques
where workOrderId = ? where workOrderId = ?
and lotOccupancyId = ?`) and lotOccupancyId = ?`)
.get(workOrderLotOccupancyForm.workOrderId, workOrderLotOccupancyForm.lotOccupancyId); .get(workOrderLotOccupancyForm.workOrderId, workOrderLotOccupancyForm.lotOccupancyId);
if (row) { if (row === undefined) {
database
.prepare(`insert into WorkOrderLotOccupancies (
workOrderId, lotOccupancyId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`)
.run(workOrderLotOccupancyForm.workOrderId, workOrderLotOccupancyForm.lotOccupancyId, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
}
else {
if (row.recordDelete_timeMillis) { if (row.recordDelete_timeMillis) {
database database
.prepare(`update WorkOrderLotOccupancies .prepare(`update WorkOrderLotOccupancies
@ -23,15 +32,6 @@ export async function addWorkOrderLotOccupancy(workOrderLotOccupancyForm, reques
.run(requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis, workOrderLotOccupancyForm.workOrderId, workOrderLotOccupancyForm.lotOccupancyId); .run(requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis, workOrderLotOccupancyForm.workOrderId, workOrderLotOccupancyForm.lotOccupancyId);
} }
} }
else {
database
.prepare(`insert into WorkOrderLotOccupancies (
workOrderId, lotOccupancyId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`)
.run(workOrderLotOccupancyForm.workOrderId, workOrderLotOccupancyForm.lotOccupancyId, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
}
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {
database.release(); database.release();
} }

View File

@ -29,7 +29,24 @@ export async function addWorkOrderLotOccupancy(
workOrderLotOccupancyForm.lotOccupancyId workOrderLotOccupancyForm.lotOccupancyId
) )
if (row) { if (row === undefined) {
database
.prepare(
`insert into WorkOrderLotOccupancies (
workOrderId, lotOccupancyId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`
)
.run(
workOrderLotOccupancyForm.workOrderId,
workOrderLotOccupancyForm.lotOccupancyId,
requestSession.user!.userName,
rightNowMillis,
requestSession.user!.userName,
rightNowMillis
)
} else {
if (row.recordDelete_timeMillis) { if (row.recordDelete_timeMillis) {
database database
.prepare( .prepare(
@ -52,23 +69,6 @@ export async function addWorkOrderLotOccupancy(
workOrderLotOccupancyForm.lotOccupancyId workOrderLotOccupancyForm.lotOccupancyId
) )
} }
} else {
database
.prepare(
`insert into WorkOrderLotOccupancies (
workOrderId, lotOccupancyId,
recordCreate_userName, recordCreate_timeMillis,
recordUpdate_userName, recordUpdate_timeMillis)
values (?, ?, ?, ?, ?, ?)`
)
.run(
workOrderLotOccupancyForm.workOrderId,
workOrderLotOccupancyForm.lotOccupancyId,
requestSession.user!.userName,
rightNowMillis,
requestSession.user!.userName,
rightNowMillis
)
} }
if (connectedDatabase === undefined) { if (connectedDatabase === undefined) {

View File

@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/indent */ /* eslint-disable @typescript-eslint/indent */
import sqlite from 'better-sqlite3'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
import { import {

View File

@ -6,7 +6,7 @@ export async function getFeeCategories(filters, options) {
const database = await acquireConnection(); const database = await acquireConnection();
let sqlWhereClause = ' where recordDelete_timeMillis is null'; let sqlWhereClause = ' where recordDelete_timeMillis is null';
const sqlParameters = []; const sqlParameters = [];
if (filters.occupancyTypeId) { if ((filters.occupancyTypeId ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and feeCategoryId in (' + ' and feeCategoryId in (' +
'select feeCategoryId from Fees' + 'select feeCategoryId from Fees' +
@ -14,7 +14,7 @@ export async function getFeeCategories(filters, options) {
' and (occupancyTypeId is null or occupancyTypeId = ?))'; ' and (occupancyTypeId is null or occupancyTypeId = ?))';
sqlParameters.push(filters.occupancyTypeId); sqlParameters.push(filters.occupancyTypeId);
} }
if (filters.lotTypeId) { if ((filters.lotTypeId ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and feeCategoryId in (' + ' and feeCategoryId in (' +
'select feeCategoryId from Fees' + 'select feeCategoryId from Fees' +

View File

@ -27,7 +27,7 @@ export async function getFeeCategories(
const sqlParameters: unknown[] = [] const sqlParameters: unknown[] = []
if (filters.occupancyTypeId) { if ((filters.occupancyTypeId ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and feeCategoryId in (' + ' and feeCategoryId in (' +
'select feeCategoryId from Fees' + 'select feeCategoryId from Fees' +
@ -37,7 +37,7 @@ export async function getFeeCategories(
sqlParameters.push(filters.occupancyTypeId) sqlParameters.push(filters.occupancyTypeId)
} }
if (filters.lotTypeId) { if ((filters.lotTypeId ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and feeCategoryId in (' + ' and feeCategoryId in (' +
'select feeCategoryId from Fees' + 'select feeCategoryId from Fees' +
@ -76,7 +76,11 @@ export async function getFeeCategories(
expectedOrderNumber += 1 expectedOrderNumber += 1
feeCategory.fees = await getFees(feeCategory.feeCategoryId, filters, database) feeCategory.fees = await getFees(
feeCategory.feeCategoryId,
filters,
database
)
} }
} }

View File

@ -1,5 +1,3 @@
import sqlite from 'better-sqlite3'
import { acquireConnection } from './pool.js' import { acquireConnection } from './pool.js'
import type { PoolConnection } from 'better-sqlite-pool' import type { PoolConnection } from 'better-sqlite-pool'

View File

@ -13,7 +13,7 @@ const baseSQL = `select l.lotId, l.lotTypeId, t.lotType, l.lotName, l.lotStatusI
async function _getLot(sql, lotIdOrLotName) { async function _getLot(sql, lotIdOrLotName) {
const database = await acquireConnection(); const database = await acquireConnection();
const lot = database.prepare(sql).get(lotIdOrLotName); const lot = database.prepare(sql).get(lotIdOrLotName);
if (lot) { if (lot !== undefined) {
const lotOccupancies = await getLotOccupancies({ const lotOccupancies = await getLotOccupancies({
lotId: lot.lotId lotId: lot.lotId
}, { }, {

View File

@ -25,7 +25,7 @@ async function _getLot(
const lot: recordTypes.Lot = database.prepare(sql).get(lotIdOrLotName) const lot: recordTypes.Lot = database.prepare(sql).get(lotIdOrLotName)
if (lot) { if (lot !== undefined) {
const lotOccupancies = await getLotOccupancies( const lotOccupancies = await getLotOccupancies(
{ {
lotId: lot.lotId lotId: lot.lotId

View File

@ -7,7 +7,7 @@ import { getLotNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWher
function buildWhereClause(filters) { function buildWhereClause(filters) {
let sqlWhereClause = ' where o.recordDelete_timeMillis is null'; let sqlWhereClause = ' where o.recordDelete_timeMillis is null';
const sqlParameters = []; const sqlParameters = [];
if (filters.lotId) { if ((filters.lotId ?? '') !== '') {
sqlWhereClause += ' and o.lotId = ?'; sqlWhereClause += ' and o.lotId = ?';
sqlParameters.push(filters.lotId); sqlParameters.push(filters.lotId);
} }
@ -22,36 +22,36 @@ function buildWhereClause(filters) {
')'; ')';
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);
} }
const occupancyTimeFilters = getOccupancyTimeWhereClause(filters.occupancyTime ?? '', 'o'); const occupancyTimeFilters = getOccupancyTimeWhereClause(filters.occupancyTime ?? '', 'o');
sqlWhereClause += occupancyTimeFilters.sqlWhereClause; sqlWhereClause += occupancyTimeFilters.sqlWhereClause;
sqlParameters.push(...occupancyTimeFilters.sqlParameters); sqlParameters.push(...occupancyTimeFilters.sqlParameters);
if (filters.occupancyStartDateString) { if ((filters.occupancyStartDateString ?? '') !== '') {
sqlWhereClause += ' and o.occupancyStartDate = ?'; sqlWhereClause += ' and o.occupancyStartDate = ?';
sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString)); sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString));
} }
if (filters.occupancyEffectiveDateString) { if ((filters.occupancyEffectiveDateString ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and (o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?))'; ' and (o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?))';
sqlParameters.push(dateStringToInteger(filters.occupancyEffectiveDateString), dateStringToInteger(filters.occupancyEffectiveDateString)); sqlParameters.push(dateStringToInteger(filters.occupancyEffectiveDateString), dateStringToInteger(filters.occupancyEffectiveDateString));
} }
if (filters.mapId) { if ((filters.mapId ?? '') !== '') {
sqlWhereClause += ' and l.mapId = ?'; sqlWhereClause += ' and l.mapId = ?';
sqlParameters.push(filters.mapId); sqlParameters.push(filters.mapId);
} }
if (filters.lotTypeId) { if ((filters.lotTypeId ?? '') !== '') {
sqlWhereClause += ' and l.lotTypeId = ?'; sqlWhereClause += ' and l.lotTypeId = ?';
sqlParameters.push(filters.lotTypeId); sqlParameters.push(filters.lotTypeId);
} }
if (filters.workOrderId) { if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)'; ' and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)';
sqlParameters.push(filters.workOrderId); sqlParameters.push(filters.workOrderId);
} }
if (filters.notWorkOrderId) { if ((filters.notWorkOrderId ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and o.lotOccupancyId not in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)'; ' and o.lotOccupancyId not in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)';
sqlParameters.push(filters.notWorkOrderId); sqlParameters.push(filters.notWorkOrderId);
@ -98,7 +98,7 @@ export async function getLotOccupancies(filters, options, connectedDatabase) {
} }
for (const lotOccupancy of lotOccupancies) { for (const lotOccupancy of lotOccupancies) {
const occupancyType = await getOccupancyTypeById(lotOccupancy.occupancyTypeId); const occupancyType = await getOccupancyTypeById(lotOccupancy.occupancyTypeId);
if (occupancyType) { if (occupancyType !== undefined) {
lotOccupancy.printEJS = (occupancyType.occupancyTypePrints ?? []).includes('*') lotOccupancy.printEJS = (occupancyType.occupancyTypePrints ?? []).includes('*')
? configFunctions.getProperty('settings.lotOccupancy.prints')[0] ? configFunctions.getProperty('settings.lotOccupancy.prints')[0]
: occupancyType.occupancyTypePrints[0]; : occupancyType.occupancyTypePrints[0];

View File

@ -48,7 +48,7 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): {
let sqlWhereClause = ' where o.recordDelete_timeMillis is null' let sqlWhereClause = ' where o.recordDelete_timeMillis is null'
const sqlParameters: unknown[] = [] const sqlParameters: unknown[] = []
if (filters.lotId) { if ((filters.lotId ?? '') !== '') {
sqlWhereClause += ' and o.lotId = ?' sqlWhereClause += ' and o.lotId = ?'
sqlParameters.push(filters.lotId) sqlParameters.push(filters.lotId)
} }
@ -73,7 +73,7 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): {
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)
} }
@ -85,37 +85,37 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): {
sqlWhereClause += occupancyTimeFilters.sqlWhereClause sqlWhereClause += occupancyTimeFilters.sqlWhereClause
sqlParameters.push(...occupancyTimeFilters.sqlParameters) sqlParameters.push(...occupancyTimeFilters.sqlParameters)
if (filters.occupancyStartDateString) { if ((filters.occupancyStartDateString ?? '') !== '') {
sqlWhereClause += ' and o.occupancyStartDate = ?' sqlWhereClause += ' and o.occupancyStartDate = ?'
sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString)) sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString!))
} }
if (filters.occupancyEffectiveDateString) { if ((filters.occupancyEffectiveDateString ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and (o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?))' ' and (o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?))'
sqlParameters.push( sqlParameters.push(
dateStringToInteger(filters.occupancyEffectiveDateString), dateStringToInteger(filters.occupancyEffectiveDateString!),
dateStringToInteger(filters.occupancyEffectiveDateString) dateStringToInteger(filters.occupancyEffectiveDateString!)
) )
} }
if (filters.mapId) { if ((filters.mapId ?? '') !== '') {
sqlWhereClause += ' and l.mapId = ?' sqlWhereClause += ' and l.mapId = ?'
sqlParameters.push(filters.mapId) sqlParameters.push(filters.mapId)
} }
if (filters.lotTypeId) { if ((filters.lotTypeId ?? '') !== '') {
sqlWhereClause += ' and l.lotTypeId = ?' sqlWhereClause += ' and l.lotTypeId = ?'
sqlParameters.push(filters.lotTypeId) sqlParameters.push(filters.lotTypeId)
} }
if (filters.workOrderId) { if ((filters.workOrderId ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)' ' and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)'
sqlParameters.push(filters.workOrderId) sqlParameters.push(filters.workOrderId)
} }
if (filters.notWorkOrderId) { if ((filters.notWorkOrderId ?? '') !== '') {
sqlWhereClause += sqlWhereClause +=
' and o.lotOccupancyId not in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)' ' and o.lotOccupancyId not in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)'
sqlParameters.push(filters.notWorkOrderId) sqlParameters.push(filters.notWorkOrderId)
@ -180,9 +180,11 @@ export async function getLotOccupancies(
} }
for (const lotOccupancy of lotOccupancies) { for (const lotOccupancy of lotOccupancies) {
const occupancyType = await getOccupancyTypeById(lotOccupancy.occupancyTypeId!) const occupancyType = await getOccupancyTypeById(
lotOccupancy.occupancyTypeId!
)
if (occupancyType) { if (occupancyType !== undefined) {
lotOccupancy.printEJS = ( lotOccupancy.printEJS = (
occupancyType.occupancyTypePrints ?? [] occupancyType.occupancyTypePrints ?? []
).includes('*') ).includes('*')

View File

@ -24,7 +24,7 @@ export async function getLotOccupancy(lotOccupancyId, connectedDatabase) {
where o.recordDelete_timeMillis is null where o.recordDelete_timeMillis is null
and o.lotOccupancyId = ?`) and o.lotOccupancyId = ?`)
.get(lotOccupancyId); .get(lotOccupancyId);
if (lotOccupancy) { if (lotOccupancy !== undefined) {
lotOccupancy.lotOccupancyFields = await getLotOccupancyFields(lotOccupancyId, database); lotOccupancy.lotOccupancyFields = await getLotOccupancyFields(lotOccupancyId, database);
lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants(lotOccupancyId, database); lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants(lotOccupancyId, database);
lotOccupancy.lotOccupancyComments = await getLotOccupancyComments(lotOccupancyId, database); lotOccupancy.lotOccupancyComments = await getLotOccupancyComments(lotOccupancyId, database);

View File

@ -38,7 +38,7 @@ export async function getLotOccupancy(
) )
.get(lotOccupancyId) .get(lotOccupancyId)
if (lotOccupancy) { if (lotOccupancy !== undefined) {
lotOccupancy.lotOccupancyFields = await getLotOccupancyFields( lotOccupancy.lotOccupancyFields = await getLotOccupancyFields(
lotOccupancyId, lotOccupancyId,
database database

View File

@ -21,8 +21,8 @@ export async function getLotOccupancyFields(lotOccupancyId, connectedDatabase) {
from OccupancyTypeFields f from OccupancyTypeFields f
left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId
where f.recordDelete_timeMillis is null and ( where f.recordDelete_timeMillis is null and (
f.occupancyTypeId is null f.occupancyTypeId is null
or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)) or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?))
and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null) and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null)
order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField`) order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField`)
.all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId); .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId);

View File

@ -30,8 +30,8 @@ export async function getLotOccupancyFields(
from OccupancyTypeFields f from OccupancyTypeFields f
left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId
where f.recordDelete_timeMillis is null and ( where f.recordDelete_timeMillis is null and (
f.occupancyTypeId is null f.occupancyTypeId is null
or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)) or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?))
and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null) and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null)
order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField` order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField`
) )

View File

@ -5,5 +5,5 @@ interface GetFilters {
interface LotStatusSummary extends recordTypes.LotStatus { interface LotStatusSummary extends recordTypes.LotStatus {
lotCount: number; lotCount: number;
} }
export declare function getLotStatusSummary(filters?: GetFilters): Promise<LotStatusSummary[]>; export declare function getLotStatusSummary(filters: GetFilters): Promise<LotStatusSummary[]>;
export default getLotStatusSummary; export default getLotStatusSummary;

View File

@ -3,7 +3,7 @@ export async function getLotStatusSummary(filters) {
const database = await acquireConnection(); const database = await acquireConnection();
let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; let sqlWhereClause = ' where l.recordDelete_timeMillis is null';
const sqlParameters = []; const sqlParameters = [];
if (filters?.mapId) { if ((filters.mapId ?? '') !== '') {
sqlWhereClause += ' and l.mapId = ?'; sqlWhereClause += ' and l.mapId = ?';
sqlParameters.push(filters.mapId); sqlParameters.push(filters.mapId);
} }

View File

@ -11,14 +11,14 @@ interface LotStatusSummary extends recordTypes.LotStatus {
} }
export async function getLotStatusSummary( export async function getLotStatusSummary(
filters?: GetFilters filters: GetFilters
): Promise<LotStatusSummary[]> { ): Promise<LotStatusSummary[]> {
const database = await acquireConnection() const database = await acquireConnection()
let sqlWhereClause = ' where l.recordDelete_timeMillis is null' let sqlWhereClause = ' where l.recordDelete_timeMillis is null'
const sqlParameters: unknown[] = [] const sqlParameters: unknown[] = []
if (filters?.mapId) { if ((filters.mapId ?? '') !== '') {
sqlWhereClause += ' and l.mapId = ?' sqlWhereClause += ' and l.mapId = ?'
sqlParameters.push(filters.mapId) sqlParameters.push(filters.mapId)
} }

View File

@ -5,5 +5,5 @@ interface GetFilters {
interface LotTypeSummary extends recordTypes.LotType { interface LotTypeSummary extends recordTypes.LotType {
lotCount: number; lotCount: number;
} }
export declare function getLotTypeSummary(filters?: GetFilters): Promise<LotTypeSummary[]>; export declare function getLotTypeSummary(filters: GetFilters): Promise<LotTypeSummary[]>;
export default getLotTypeSummary; export default getLotTypeSummary;

View File

@ -3,7 +3,7 @@ export async function getLotTypeSummary(filters) {
const database = await acquireConnection(); const database = await acquireConnection();
let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; let sqlWhereClause = ' where l.recordDelete_timeMillis is null';
const sqlParameters = []; const sqlParameters = [];
if (filters?.mapId) { if ((filters.mapId ?? '') !== '') {
sqlWhereClause += ' and l.mapId = ?'; sqlWhereClause += ' and l.mapId = ?';
sqlParameters.push(filters.mapId); sqlParameters.push(filters.mapId);
} }

View File

@ -11,14 +11,14 @@ interface LotTypeSummary extends recordTypes.LotType {
} }
export async function getLotTypeSummary( export async function getLotTypeSummary(
filters?: GetFilters filters: GetFilters
): Promise<LotTypeSummary[]> { ): Promise<LotTypeSummary[]> {
const database = await acquireConnection() const database = await acquireConnection()
let sqlWhereClause = ' where l.recordDelete_timeMillis is null' let sqlWhereClause = ' where l.recordDelete_timeMillis is null'
const sqlParameters: unknown[] = [] const sqlParameters: unknown[] = []
if (filters?.mapId) { if ((filters.mapId ?? '') !== '') {
sqlWhereClause += ' and l.mapId = ?' sqlWhereClause += ' and l.mapId = ?'
sqlParameters.push(filters.mapId) sqlParameters.push(filters.mapId)
} }