From 285704daab421ea82ba4fb0b60293db89eb7ca77 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Thu, 19 Jan 2023 14:31:40 -0500 Subject: [PATCH] linting --- app.ts | 4 +-- handlers/maps-get/edit.js | 2 +- handlers/maps-get/edit.ts | 2 +- handlers/maps-get/view.js | 2 +- handlers/maps-get/view.ts | 2 +- helpers/functions.api.js | 2 +- helpers/functions.api.ts | 2 +- helpers/lotOccupancyDB/addLot.js | 2 +- helpers/lotOccupancyDB/addLot.ts | 2 +- helpers/lotOccupancyDB/addLotOccupancy.js | 4 +-- helpers/lotOccupancyDB/addLotOccupancy.ts | 6 ++-- .../lotOccupancyDB/addLotOccupancyOccupant.js | 2 +- .../lotOccupancyDB/addLotOccupancyOccupant.ts | 2 +- .../addLotOccupancyTransaction.js | 2 +- .../addLotOccupancyTransaction.ts | 2 +- helpers/lotOccupancyDB/addRecord.ts | 2 -- helpers/lotOccupancyDB/addWorkOrderLot.js | 20 +++++------ helpers/lotOccupancyDB/addWorkOrderLot.ts | 36 +++++++++---------- .../addWorkOrderLotOccupancy.js | 20 +++++------ .../addWorkOrderLotOccupancy.ts | 36 +++++++++---------- .../lotOccupancyDB/addWorkOrderMilestone.ts | 2 -- helpers/lotOccupancyDB/getFeeCategories.js | 4 +-- helpers/lotOccupancyDB/getFeeCategories.ts | 10 ++++-- helpers/lotOccupancyDB/getFees.ts | 2 -- helpers/lotOccupancyDB/getLot.js | 2 +- helpers/lotOccupancyDB/getLot.ts | 2 +- helpers/lotOccupancyDB/getLotOccupancies.js | 18 +++++----- helpers/lotOccupancyDB/getLotOccupancies.ts | 28 ++++++++------- helpers/lotOccupancyDB/getLotOccupancy.js | 2 +- helpers/lotOccupancyDB/getLotOccupancy.ts | 2 +- .../lotOccupancyDB/getLotOccupancyFields.js | 4 +-- .../lotOccupancyDB/getLotOccupancyFields.ts | 4 +-- .../lotOccupancyDB/getLotStatusSummary.d.ts | 2 +- helpers/lotOccupancyDB/getLotStatusSummary.js | 2 +- helpers/lotOccupancyDB/getLotStatusSummary.ts | 4 +-- helpers/lotOccupancyDB/getLotTypeSummary.d.ts | 2 +- helpers/lotOccupancyDB/getLotTypeSummary.js | 2 +- helpers/lotOccupancyDB/getLotTypeSummary.ts | 4 +-- 38 files changed, 124 insertions(+), 124 deletions(-) diff --git a/app.ts b/app.ts index 9b8a4002..26be59d0 100644 --- a/app.ts +++ b/app.ts @@ -1,5 +1,5 @@ import createError from 'http-errors' -import express from 'express' +import express, { RequestHandler } from 'express' import compression from 'compression' import path from 'node:path' @@ -233,7 +233,7 @@ app.get(urlPrefix + '/', sessionChecker, (_request, response) => { 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 + '/maps', sessionChecker, routerMaps) diff --git a/handlers/maps-get/edit.js b/handlers/maps-get/edit.js index d691cde4..17b8346d 100644 --- a/handlers/maps-get/edit.js +++ b/handlers/maps-get/edit.js @@ -5,7 +5,7 @@ import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummar import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSummary.js'; export async function handler(request, response) { const map = await getMap(request.params.mapId); - if (!map) { + if (map === undefined) { response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + '/maps/?error=mapIdNotFound'); return; diff --git a/handlers/maps-get/edit.ts b/handlers/maps-get/edit.ts index c994140b..c67adb96 100644 --- a/handlers/maps-get/edit.ts +++ b/handlers/maps-get/edit.ts @@ -14,7 +14,7 @@ export async function handler( ): Promise { const map = await getMap(request.params.mapId) - if (!map) { + if (map === undefined) { response.redirect( configFunctions.getProperty('reverseProxy.urlPrefix') + '/maps/?error=mapIdNotFound' diff --git a/handlers/maps-get/view.js b/handlers/maps-get/view.js index e7c1cd7f..cf82491e 100644 --- a/handlers/maps-get/view.js +++ b/handlers/maps-get/view.js @@ -4,7 +4,7 @@ import { getLotStatusSummary } from '../../helpers/lotOccupancyDB/getLotStatusSu import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummary.js'; export async function handler(request, response) { const map = await getMap(request.params.mapId); - if (!map) { + if (map === undefined) { response.redirect(configFunctions.getProperty('reverseProxy.urlPrefix') + '/maps/?error=mapIdNotFound'); return; diff --git a/handlers/maps-get/view.ts b/handlers/maps-get/view.ts index ce2d2fc5..50c5c40c 100644 --- a/handlers/maps-get/view.ts +++ b/handlers/maps-get/view.ts @@ -9,7 +9,7 @@ import { getLotTypeSummary } from '../../helpers/lotOccupancyDB/getLotTypeSummar export async function handler(request: Request, response: Response): Promise { const map = await getMap(request.params.mapId) - if (!map) { + if (map === undefined) { response.redirect( configFunctions.getProperty('reverseProxy.urlPrefix') + '/maps/?error=mapIdNotFound' diff --git a/helpers/functions.api.js b/helpers/functions.api.js index 03d93cd0..1ebb75f3 100644 --- a/helpers/functions.api.js +++ b/helpers/functions.api.js @@ -23,7 +23,7 @@ async function saveApiKeys() { } } function generateApiKey(apiKeyPrefix) { - return `${apiKeyPrefix}-${uuidv4()}-${Date.now()}`; + return `${apiKeyPrefix}-${uuidv4()}-${Date.now().toString()}`; } export async function regenerateApiKey(userName) { apiKeys[userName] = generateApiKey(userName); diff --git a/helpers/functions.api.ts b/helpers/functions.api.ts index 664188e0..3db257a3 100644 --- a/helpers/functions.api.ts +++ b/helpers/functions.api.ts @@ -29,7 +29,7 @@ async function saveApiKeys(): Promise { } function generateApiKey(apiKeyPrefix: string): string { - return `${apiKeyPrefix}-${uuidv4()}-${Date.now()}` + return `${apiKeyPrefix}-${uuidv4()}-${Date.now().toString()}` } export async function regenerateApiKey(userName: string): Promise { diff --git a/helpers/lotOccupancyDB/addLot.js b/helpers/lotOccupancyDB/addLot.js index 7fed3a9b..e6790c31 100644 --- a/helpers/lotOccupancyDB/addLot.js +++ b/helpers/lotOccupancyDB/addLot.js @@ -16,7 +16,7 @@ export async function addLot(lotForm, requestSession) { const lotTypeFieldIds = (lotForm.lotTypeFieldIds ?? '').split(','); for (const lotTypeFieldId of lotTypeFieldIds) { const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId]; - if (lotFieldValue && lotFieldValue !== '') { + if ((lotFieldValue ?? '') !== '') { await addOrUpdateLotField({ lotId, lotTypeFieldId, diff --git a/helpers/lotOccupancyDB/addLot.ts b/helpers/lotOccupancyDB/addLot.ts index 7e3838a7..b9c784dc 100644 --- a/helpers/lotOccupancyDB/addLot.ts +++ b/helpers/lotOccupancyDB/addLot.ts @@ -58,7 +58,7 @@ export async function addLot( for (const lotTypeFieldId of lotTypeFieldIds) { const lotFieldValue = lotForm['lotFieldValue_' + lotTypeFieldId] as string - if (lotFieldValue && lotFieldValue !== '') { + if ((lotFieldValue ?? '') !== '') { await addOrUpdateLotField( { lotId, diff --git a/helpers/lotOccupancyDB/addLotOccupancy.js b/helpers/lotOccupancyDB/addLotOccupancy.js index 14a34de5..2547a817 100644 --- a/helpers/lotOccupancyDB/addLotOccupancy.js +++ b/helpers/lotOccupancyDB/addLotOccupancy.js @@ -23,7 +23,7 @@ export async function addLotOccupancy(lotOccupancyForm, requestSession, connecte const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds ?? '').split(','); for (const occupancyTypeFieldId of occupancyTypeFieldIds) { const lotOccupancyFieldValue = lotOccupancyForm['lotOccupancyFieldValue_' + occupancyTypeFieldId]; - if (lotOccupancyFieldValue && lotOccupancyFieldValue !== '') { + if ((lotOccupancyFieldValue ?? '') !== '') { await addOrUpdateLotOccupancyField({ lotOccupancyId, occupancyTypeFieldId, @@ -31,7 +31,7 @@ export async function addLotOccupancy(lotOccupancyForm, requestSession, connecte }, requestSession, database); } } - if (lotOccupancyForm.lotOccupantTypeId) { + if ((lotOccupancyForm.lotOccupantTypeId ?? '') !== '') { await addLotOccupancyOccupant({ lotOccupancyId, lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId, diff --git a/helpers/lotOccupancyDB/addLotOccupancy.ts b/helpers/lotOccupancyDB/addLotOccupancy.ts index 67366169..99116af5 100644 --- a/helpers/lotOccupancyDB/addLotOccupancy.ts +++ b/helpers/lotOccupancyDB/addLotOccupancy.ts @@ -83,7 +83,7 @@ export async function addLotOccupancy( 'lotOccupancyFieldValue_' + occupancyTypeFieldId ] as string - if (lotOccupancyFieldValue && lotOccupancyFieldValue !== '') { + if ((lotOccupancyFieldValue ?? '') !== '') { await addOrUpdateLotOccupancyField( { lotOccupancyId, @@ -96,11 +96,11 @@ export async function addLotOccupancy( } } - if (lotOccupancyForm.lotOccupantTypeId) { + if ((lotOccupancyForm.lotOccupantTypeId ?? '') !== '') { await addLotOccupancyOccupant( { lotOccupancyId, - lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId, + lotOccupantTypeId: lotOccupancyForm.lotOccupantTypeId!, occupantName: lotOccupancyForm.occupantName!, occupantAddress1: lotOccupancyForm.occupantAddress1!, occupantAddress2: lotOccupancyForm.occupantAddress2!, diff --git a/helpers/lotOccupancyDB/addLotOccupancyOccupant.js b/helpers/lotOccupancyDB/addLotOccupancyOccupant.js index 63d09e33..06503b1a 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyOccupant.js +++ b/helpers/lotOccupancyDB/addLotOccupancyOccupant.js @@ -9,7 +9,7 @@ export async function addLotOccupancyOccupant(lotOccupancyOccupantForm, requestS order by lotOccupantIndex desc limit 1`) .get(lotOccupancyOccupantForm.lotOccupancyId); - if (maxIndexResult) { + if (maxIndexResult !== undefined) { lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1; } const rightNowMillis = Date.now(); diff --git a/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts b/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts index 40355eb9..56ff03e9 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts +++ b/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts @@ -36,7 +36,7 @@ export async function addLotOccupancyOccupant( ) .get(lotOccupancyOccupantForm.lotOccupancyId) - if (maxIndexResult) { + if (maxIndexResult !== undefined) { lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1 } diff --git a/helpers/lotOccupancyDB/addLotOccupancyTransaction.js b/helpers/lotOccupancyDB/addLotOccupancyTransaction.js index ffa8a9a8..10da63c6 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyTransaction.js +++ b/helpers/lotOccupancyDB/addLotOccupancyTransaction.js @@ -10,7 +10,7 @@ export async function addLotOccupancyTransaction(lotOccupancyTransactionForm, re order by transactionIndex desc limit 1`) .get(lotOccupancyTransactionForm.lotOccupancyId); - if (maxIndexResult) { + if (maxIndexResult !== undefined) { transactionIndex = maxIndexResult.transactionIndex + 1; } const rightNow = new Date(); diff --git a/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts b/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts index 10a19a64..3aae315e 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts +++ b/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts @@ -36,7 +36,7 @@ export async function addLotOccupancyTransaction( ) .get(lotOccupancyTransactionForm.lotOccupancyId) - if (maxIndexResult) { + if (maxIndexResult !== undefined) { transactionIndex = maxIndexResult.transactionIndex + 1 } diff --git a/helpers/lotOccupancyDB/addRecord.ts b/helpers/lotOccupancyDB/addRecord.ts index 94247933..35a4993c 100644 --- a/helpers/lotOccupancyDB/addRecord.ts +++ b/helpers/lotOccupancyDB/addRecord.ts @@ -1,5 +1,3 @@ -import sqlite from 'better-sqlite3' - import { acquireConnection } from './pool.js' import type * as recordTypes from '../../types/recordTypes' diff --git a/helpers/lotOccupancyDB/addWorkOrderLot.js b/helpers/lotOccupancyDB/addWorkOrderLot.js index fda51708..fd3a4dac 100644 --- a/helpers/lotOccupancyDB/addWorkOrderLot.js +++ b/helpers/lotOccupancyDB/addWorkOrderLot.js @@ -8,7 +8,16 @@ export async function addWorkOrderLot(workOrderLotForm, requestSession) { where workOrderId = ? and 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) { database .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); } } - 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(); return true; } diff --git a/helpers/lotOccupancyDB/addWorkOrderLot.ts b/helpers/lotOccupancyDB/addWorkOrderLot.ts index dafc6685..8d038831 100644 --- a/helpers/lotOccupancyDB/addWorkOrderLot.ts +++ b/helpers/lotOccupancyDB/addWorkOrderLot.ts @@ -24,7 +24,24 @@ export async function addWorkOrderLot( ) .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) { database .prepare( @@ -47,23 +64,6 @@ export async function addWorkOrderLot( 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() diff --git a/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.js b/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.js index dc9d9c84..952bc190 100644 --- a/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.js +++ b/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.js @@ -8,7 +8,16 @@ export async function addWorkOrderLotOccupancy(workOrderLotOccupancyForm, reques where workOrderId = ? and 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) { database .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); } } - 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) { database.release(); } diff --git a/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.ts b/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.ts index d7ffd8e6..927879f6 100644 --- a/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.ts +++ b/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.ts @@ -29,7 +29,24 @@ export async function addWorkOrderLotOccupancy( 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) { database .prepare( @@ -52,23 +69,6 @@ export async function addWorkOrderLotOccupancy( 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) { diff --git a/helpers/lotOccupancyDB/addWorkOrderMilestone.ts b/helpers/lotOccupancyDB/addWorkOrderMilestone.ts index 40151b8e..92de0ab1 100644 --- a/helpers/lotOccupancyDB/addWorkOrderMilestone.ts +++ b/helpers/lotOccupancyDB/addWorkOrderMilestone.ts @@ -1,7 +1,5 @@ /* eslint-disable @typescript-eslint/indent */ -import sqlite from 'better-sqlite3' - import { acquireConnection } from './pool.js' import { diff --git a/helpers/lotOccupancyDB/getFeeCategories.js b/helpers/lotOccupancyDB/getFeeCategories.js index 162332aa..25f72415 100644 --- a/helpers/lotOccupancyDB/getFeeCategories.js +++ b/helpers/lotOccupancyDB/getFeeCategories.js @@ -6,7 +6,7 @@ export async function getFeeCategories(filters, options) { const database = await acquireConnection(); let sqlWhereClause = ' where recordDelete_timeMillis is null'; const sqlParameters = []; - if (filters.occupancyTypeId) { + if ((filters.occupancyTypeId ?? '') !== '') { sqlWhereClause += ' and feeCategoryId in (' + 'select feeCategoryId from Fees' + @@ -14,7 +14,7 @@ export async function getFeeCategories(filters, options) { ' and (occupancyTypeId is null or occupancyTypeId = ?))'; sqlParameters.push(filters.occupancyTypeId); } - if (filters.lotTypeId) { + if ((filters.lotTypeId ?? '') !== '') { sqlWhereClause += ' and feeCategoryId in (' + 'select feeCategoryId from Fees' + diff --git a/helpers/lotOccupancyDB/getFeeCategories.ts b/helpers/lotOccupancyDB/getFeeCategories.ts index e11344cb..73d813d8 100644 --- a/helpers/lotOccupancyDB/getFeeCategories.ts +++ b/helpers/lotOccupancyDB/getFeeCategories.ts @@ -27,7 +27,7 @@ export async function getFeeCategories( const sqlParameters: unknown[] = [] - if (filters.occupancyTypeId) { + if ((filters.occupancyTypeId ?? '') !== '') { sqlWhereClause += ' and feeCategoryId in (' + 'select feeCategoryId from Fees' + @@ -37,7 +37,7 @@ export async function getFeeCategories( sqlParameters.push(filters.occupancyTypeId) } - if (filters.lotTypeId) { + if ((filters.lotTypeId ?? '') !== '') { sqlWhereClause += ' and feeCategoryId in (' + 'select feeCategoryId from Fees' + @@ -76,7 +76,11 @@ export async function getFeeCategories( expectedOrderNumber += 1 - feeCategory.fees = await getFees(feeCategory.feeCategoryId, filters, database) + feeCategory.fees = await getFees( + feeCategory.feeCategoryId, + filters, + database + ) } } diff --git a/helpers/lotOccupancyDB/getFees.ts b/helpers/lotOccupancyDB/getFees.ts index 7e988ac7..de67997f 100644 --- a/helpers/lotOccupancyDB/getFees.ts +++ b/helpers/lotOccupancyDB/getFees.ts @@ -1,5 +1,3 @@ -import sqlite from 'better-sqlite3' - import { acquireConnection } from './pool.js' import type { PoolConnection } from 'better-sqlite-pool' diff --git a/helpers/lotOccupancyDB/getLot.js b/helpers/lotOccupancyDB/getLot.js index bdcc52e5..2a36fc37 100644 --- a/helpers/lotOccupancyDB/getLot.js +++ b/helpers/lotOccupancyDB/getLot.js @@ -13,7 +13,7 @@ const baseSQL = `select l.lotId, l.lotTypeId, t.lotType, l.lotName, l.lotStatusI async function _getLot(sql, lotIdOrLotName) { const database = await acquireConnection(); const lot = database.prepare(sql).get(lotIdOrLotName); - if (lot) { + if (lot !== undefined) { const lotOccupancies = await getLotOccupancies({ lotId: lot.lotId }, { diff --git a/helpers/lotOccupancyDB/getLot.ts b/helpers/lotOccupancyDB/getLot.ts index cbca2105..2ea4023a 100644 --- a/helpers/lotOccupancyDB/getLot.ts +++ b/helpers/lotOccupancyDB/getLot.ts @@ -25,7 +25,7 @@ async function _getLot( const lot: recordTypes.Lot = database.prepare(sql).get(lotIdOrLotName) - if (lot) { + if (lot !== undefined) { const lotOccupancies = await getLotOccupancies( { lotId: lot.lotId diff --git a/helpers/lotOccupancyDB/getLotOccupancies.js b/helpers/lotOccupancyDB/getLotOccupancies.js index e5547b0c..f45c3c29 100644 --- a/helpers/lotOccupancyDB/getLotOccupancies.js +++ b/helpers/lotOccupancyDB/getLotOccupancies.js @@ -7,7 +7,7 @@ import { getLotNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWher function buildWhereClause(filters) { let sqlWhereClause = ' where o.recordDelete_timeMillis is null'; const sqlParameters = []; - if (filters.lotId) { + if ((filters.lotId ?? '') !== '') { sqlWhereClause += ' and o.lotId = ?'; sqlParameters.push(filters.lotId); } @@ -22,36 +22,36 @@ function buildWhereClause(filters) { ')'; sqlParameters.push(...occupantNameFilters.sqlParameters); } - if (filters.occupancyTypeId) { + if ((filters.occupancyTypeId ?? '') !== '') { sqlWhereClause += ' and o.occupancyTypeId = ?'; sqlParameters.push(filters.occupancyTypeId); } const occupancyTimeFilters = getOccupancyTimeWhereClause(filters.occupancyTime ?? '', 'o'); sqlWhereClause += occupancyTimeFilters.sqlWhereClause; sqlParameters.push(...occupancyTimeFilters.sqlParameters); - if (filters.occupancyStartDateString) { + if ((filters.occupancyStartDateString ?? '') !== '') { sqlWhereClause += ' and o.occupancyStartDate = ?'; sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString)); } - if (filters.occupancyEffectiveDateString) { + if ((filters.occupancyEffectiveDateString ?? '') !== '') { sqlWhereClause += ' and (o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?))'; sqlParameters.push(dateStringToInteger(filters.occupancyEffectiveDateString), dateStringToInteger(filters.occupancyEffectiveDateString)); } - if (filters.mapId) { + if ((filters.mapId ?? '') !== '') { sqlWhereClause += ' and l.mapId = ?'; sqlParameters.push(filters.mapId); } - if (filters.lotTypeId) { + if ((filters.lotTypeId ?? '') !== '') { sqlWhereClause += ' and l.lotTypeId = ?'; sqlParameters.push(filters.lotTypeId); } - if (filters.workOrderId) { + if ((filters.workOrderId ?? '') !== '') { sqlWhereClause += ' and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)'; sqlParameters.push(filters.workOrderId); } - if (filters.notWorkOrderId) { + if ((filters.notWorkOrderId ?? '') !== '') { sqlWhereClause += ' and o.lotOccupancyId not in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)'; sqlParameters.push(filters.notWorkOrderId); @@ -98,7 +98,7 @@ export async function getLotOccupancies(filters, options, connectedDatabase) { } for (const lotOccupancy of lotOccupancies) { const occupancyType = await getOccupancyTypeById(lotOccupancy.occupancyTypeId); - if (occupancyType) { + if (occupancyType !== undefined) { lotOccupancy.printEJS = (occupancyType.occupancyTypePrints ?? []).includes('*') ? configFunctions.getProperty('settings.lotOccupancy.prints')[0] : occupancyType.occupancyTypePrints[0]; diff --git a/helpers/lotOccupancyDB/getLotOccupancies.ts b/helpers/lotOccupancyDB/getLotOccupancies.ts index 9bcc5c49..ed789cbe 100644 --- a/helpers/lotOccupancyDB/getLotOccupancies.ts +++ b/helpers/lotOccupancyDB/getLotOccupancies.ts @@ -48,7 +48,7 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): { let sqlWhereClause = ' where o.recordDelete_timeMillis is null' const sqlParameters: unknown[] = [] - if (filters.lotId) { + if ((filters.lotId ?? '') !== '') { sqlWhereClause += ' and o.lotId = ?' sqlParameters.push(filters.lotId) } @@ -73,7 +73,7 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): { sqlParameters.push(...occupantNameFilters.sqlParameters) } - if (filters.occupancyTypeId) { + if ((filters.occupancyTypeId ?? '') !== '') { sqlWhereClause += ' and o.occupancyTypeId = ?' sqlParameters.push(filters.occupancyTypeId) } @@ -85,37 +85,37 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): { sqlWhereClause += occupancyTimeFilters.sqlWhereClause sqlParameters.push(...occupancyTimeFilters.sqlParameters) - if (filters.occupancyStartDateString) { + if ((filters.occupancyStartDateString ?? '') !== '') { sqlWhereClause += ' and o.occupancyStartDate = ?' - sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString)) + sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString!)) } - if (filters.occupancyEffectiveDateString) { + if ((filters.occupancyEffectiveDateString ?? '') !== '') { sqlWhereClause += ' and (o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?))' sqlParameters.push( - dateStringToInteger(filters.occupancyEffectiveDateString), - dateStringToInteger(filters.occupancyEffectiveDateString) + dateStringToInteger(filters.occupancyEffectiveDateString!), + dateStringToInteger(filters.occupancyEffectiveDateString!) ) } - if (filters.mapId) { + if ((filters.mapId ?? '') !== '') { sqlWhereClause += ' and l.mapId = ?' sqlParameters.push(filters.mapId) } - if (filters.lotTypeId) { + if ((filters.lotTypeId ?? '') !== '') { sqlWhereClause += ' and l.lotTypeId = ?' sqlParameters.push(filters.lotTypeId) } - if (filters.workOrderId) { + if ((filters.workOrderId ?? '') !== '') { sqlWhereClause += ' and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)' sqlParameters.push(filters.workOrderId) } - if (filters.notWorkOrderId) { + if ((filters.notWorkOrderId ?? '') !== '') { sqlWhereClause += ' and o.lotOccupancyId not in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)' sqlParameters.push(filters.notWorkOrderId) @@ -180,9 +180,11 @@ export async function getLotOccupancies( } 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('*') diff --git a/helpers/lotOccupancyDB/getLotOccupancy.js b/helpers/lotOccupancyDB/getLotOccupancy.js index dd610f30..45839a14 100644 --- a/helpers/lotOccupancyDB/getLotOccupancy.js +++ b/helpers/lotOccupancyDB/getLotOccupancy.js @@ -24,7 +24,7 @@ export async function getLotOccupancy(lotOccupancyId, connectedDatabase) { where o.recordDelete_timeMillis is null and o.lotOccupancyId = ?`) .get(lotOccupancyId); - if (lotOccupancy) { + if (lotOccupancy !== undefined) { lotOccupancy.lotOccupancyFields = await getLotOccupancyFields(lotOccupancyId, database); lotOccupancy.lotOccupancyOccupants = await getLotOccupancyOccupants(lotOccupancyId, database); lotOccupancy.lotOccupancyComments = await getLotOccupancyComments(lotOccupancyId, database); diff --git a/helpers/lotOccupancyDB/getLotOccupancy.ts b/helpers/lotOccupancyDB/getLotOccupancy.ts index 7756b6c3..04333ae2 100644 --- a/helpers/lotOccupancyDB/getLotOccupancy.ts +++ b/helpers/lotOccupancyDB/getLotOccupancy.ts @@ -38,7 +38,7 @@ export async function getLotOccupancy( ) .get(lotOccupancyId) - if (lotOccupancy) { + if (lotOccupancy !== undefined) { lotOccupancy.lotOccupancyFields = await getLotOccupancyFields( lotOccupancyId, database diff --git a/helpers/lotOccupancyDB/getLotOccupancyFields.js b/helpers/lotOccupancyDB/getLotOccupancyFields.js index 6527a114..f2868fe5 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFields.js +++ b/helpers/lotOccupancyDB/getLotOccupancyFields.js @@ -21,8 +21,8 @@ export async function getLotOccupancyFields(lotOccupancyId, connectedDatabase) { from OccupancyTypeFields f left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId where f.recordDelete_timeMillis is null and ( - f.occupancyTypeId is null - or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)) + f.occupancyTypeId is null + 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) order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField`) .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId); diff --git a/helpers/lotOccupancyDB/getLotOccupancyFields.ts b/helpers/lotOccupancyDB/getLotOccupancyFields.ts index 11f810db..cd19ecf9 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFields.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyFields.ts @@ -30,8 +30,8 @@ export async function getLotOccupancyFields( from OccupancyTypeFields f left join OccupancyTypes t on f.occupancyTypeId = t.occupancyTypeId where f.recordDelete_timeMillis is null and ( - f.occupancyTypeId is null - or f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)) + f.occupancyTypeId is null + 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) order by occupancyTypeOrderNumber, f.orderNumber, f.occupancyTypeField` ) diff --git a/helpers/lotOccupancyDB/getLotStatusSummary.d.ts b/helpers/lotOccupancyDB/getLotStatusSummary.d.ts index 28ecc9ad..c51780b6 100644 --- a/helpers/lotOccupancyDB/getLotStatusSummary.d.ts +++ b/helpers/lotOccupancyDB/getLotStatusSummary.d.ts @@ -5,5 +5,5 @@ interface GetFilters { interface LotStatusSummary extends recordTypes.LotStatus { lotCount: number; } -export declare function getLotStatusSummary(filters?: GetFilters): Promise; +export declare function getLotStatusSummary(filters: GetFilters): Promise; export default getLotStatusSummary; diff --git a/helpers/lotOccupancyDB/getLotStatusSummary.js b/helpers/lotOccupancyDB/getLotStatusSummary.js index 53c12a52..0c6e968c 100644 --- a/helpers/lotOccupancyDB/getLotStatusSummary.js +++ b/helpers/lotOccupancyDB/getLotStatusSummary.js @@ -3,7 +3,7 @@ export async function getLotStatusSummary(filters) { const database = await acquireConnection(); let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; const sqlParameters = []; - if (filters?.mapId) { + if ((filters.mapId ?? '') !== '') { sqlWhereClause += ' and l.mapId = ?'; sqlParameters.push(filters.mapId); } diff --git a/helpers/lotOccupancyDB/getLotStatusSummary.ts b/helpers/lotOccupancyDB/getLotStatusSummary.ts index b22ad8ad..7c309bb6 100644 --- a/helpers/lotOccupancyDB/getLotStatusSummary.ts +++ b/helpers/lotOccupancyDB/getLotStatusSummary.ts @@ -11,14 +11,14 @@ interface LotStatusSummary extends recordTypes.LotStatus { } export async function getLotStatusSummary( - filters?: GetFilters + filters: GetFilters ): Promise { const database = await acquireConnection() let sqlWhereClause = ' where l.recordDelete_timeMillis is null' const sqlParameters: unknown[] = [] - if (filters?.mapId) { + if ((filters.mapId ?? '') !== '') { sqlWhereClause += ' and l.mapId = ?' sqlParameters.push(filters.mapId) } diff --git a/helpers/lotOccupancyDB/getLotTypeSummary.d.ts b/helpers/lotOccupancyDB/getLotTypeSummary.d.ts index bce06551..d40095a7 100644 --- a/helpers/lotOccupancyDB/getLotTypeSummary.d.ts +++ b/helpers/lotOccupancyDB/getLotTypeSummary.d.ts @@ -5,5 +5,5 @@ interface GetFilters { interface LotTypeSummary extends recordTypes.LotType { lotCount: number; } -export declare function getLotTypeSummary(filters?: GetFilters): Promise; +export declare function getLotTypeSummary(filters: GetFilters): Promise; export default getLotTypeSummary; diff --git a/helpers/lotOccupancyDB/getLotTypeSummary.js b/helpers/lotOccupancyDB/getLotTypeSummary.js index 98bba10b..eda091fe 100644 --- a/helpers/lotOccupancyDB/getLotTypeSummary.js +++ b/helpers/lotOccupancyDB/getLotTypeSummary.js @@ -3,7 +3,7 @@ export async function getLotTypeSummary(filters) { const database = await acquireConnection(); let sqlWhereClause = ' where l.recordDelete_timeMillis is null'; const sqlParameters = []; - if (filters?.mapId) { + if ((filters.mapId ?? '') !== '') { sqlWhereClause += ' and l.mapId = ?'; sqlParameters.push(filters.mapId); } diff --git a/helpers/lotOccupancyDB/getLotTypeSummary.ts b/helpers/lotOccupancyDB/getLotTypeSummary.ts index cbda8080..3c81e7dd 100644 --- a/helpers/lotOccupancyDB/getLotTypeSummary.ts +++ b/helpers/lotOccupancyDB/getLotTypeSummary.ts @@ -11,14 +11,14 @@ interface LotTypeSummary extends recordTypes.LotType { } export async function getLotTypeSummary( - filters?: GetFilters + filters: GetFilters ): Promise { const database = await acquireConnection() let sqlWhereClause = ' where l.recordDelete_timeMillis is null' const sqlParameters: unknown[] = [] - if (filters?.mapId) { + if ((filters.mapId ?? '') !== '') { sqlWhereClause += ' and l.mapId = ?' sqlParameters.push(filters.mapId) }