From 15e6fc3d66579f1c2f8dd68aa96d1ac573d9c51f Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Mon, 24 Jun 2024 11:35:16 -0400 Subject: [PATCH] reduce wildcard imports --- bin/www.js | 12 ++-- bin/www.ts | 14 ++--- bin/wwwProcess.js | 6 +- bin/wwwProcess.ts | 6 +- cypress/e2e/02-update/maps.cy.js | 12 ++-- cypress/e2e/02-update/maps.cy.ts | 12 ++-- data/databasePaths.js | 4 +- data/databasePaths.ts | 7 ++- database/cleanupDatabase.js | 4 +- database/cleanupDatabase.ts | 4 +- database/getLotOccupancies.d.ts | 3 +- database/getLotOccupancies.js | 4 +- database/getLotOccupancies.ts | 15 +++-- database/getLotOccupancyTransactions.js | 4 +- database/getLotOccupancyTransactions.ts | 4 +- database/getLots.js | 4 +- database/getLots.ts | 4 +- database/getNextLotId.js | 4 +- database/getNextLotId.ts | 4 +- database/getNextWorkOrderNumber.js | 10 ++-- database/getNextWorkOrderNumber.ts | 12 ++-- database/getOccupancyTypePrints.js | 4 +- database/getOccupancyTypePrints.ts | 6 +- database/getPreviousLotId.js | 4 +- database/getPreviousLotId.ts | 4 +- database/getReportData.js | 10 ++-- database/getReportData.ts | 16 ++---- handlers/admin-get/lotTypes.js | 4 +- handlers/admin-get/lotTypes.ts | 4 +- handlers/admin-get/ntfyStartup.js | 7 +-- handlers/admin-get/ntfyStartup.ts | 9 +-- handlers/admin-get/occupancyTypes.js | 6 +- handlers/admin-get/occupancyTypes.ts | 8 +-- handlers/api-get/milestoneICS.js | 54 +++++++++--------- handlers/api-get/milestoneICS.ts | 73 +++++++++++-------------- handlers/lotOccupancies-get/edit.js | 6 +- handlers/lotOccupancies-get/edit.ts | 12 ++-- handlers/lotOccupancies-get/new.js | 4 +- handlers/lotOccupancies-get/new.ts | 12 +--- handlers/lotOccupancies-get/search.js | 4 +- handlers/lotOccupancies-get/search.ts | 5 +- handlers/lotOccupancies-get/view.js | 6 +- handlers/lotOccupancies-get/view.ts | 7 +-- handlers/lots-get/edit.js | 11 ++-- handlers/lots-get/edit.ts | 12 ++-- handlers/lots-get/new.js | 10 ++-- handlers/lots-get/new.ts | 11 ++-- handlers/lots-get/next.js | 6 +- handlers/lots-get/next.ts | 7 +-- handlers/lots-get/previous.js | 6 +- handlers/lots-get/previous.ts | 7 +-- handlers/lots-get/search.js | 6 +- handlers/lots-get/search.ts | 7 +-- handlers/lots-get/view.js | 5 +- handlers/lots-get/view.ts | 6 +- handlers/maps-get/edit.js | 4 +- handlers/maps-get/edit.ts | 7 +-- handlers/maps-get/new.js | 8 +-- handlers/maps-get/new.ts | 9 ++- handlers/maps-get/next.js | 6 +- handlers/maps-get/next.ts | 7 +-- handlers/maps-get/previous.js | 6 +- handlers/maps-get/previous.ts | 7 +-- handlers/maps-get/search.js | 4 +- handlers/maps-get/search.ts | 10 ++-- handlers/maps-get/view.js | 4 +- handlers/maps-get/view.ts | 5 +- handlers/print-get/pdf.d.ts | 3 +- handlers/print-get/pdf.js | 3 +- handlers/print-get/pdf.ts | 3 +- handlers/print-get/screen.js | 14 ++--- handlers/print-get/screen.ts | 19 +++---- handlers/workOrders-get/edit.js | 8 +-- handlers/workOrders-get/edit.ts | 13 ++--- handlers/workOrders-get/view.js | 4 +- handlers/workOrders-get/view.ts | 7 +-- helpers/functions.authentication.js | 8 +-- helpers/functions.authentication.ts | 9 ++- helpers/functions.cache.js | 4 +- helpers/functions.cache.ts | 4 +- helpers/functions.dynamicsGP.js | 16 +++--- helpers/functions.dynamicsGP.ts | 29 ++++------ routes/login.js | 20 ++----- routes/login.ts | 38 ++++++------- routes/lotOccupancies.js | 4 +- routes/lotOccupancies.ts | 4 +- 86 files changed, 364 insertions(+), 431 deletions(-) diff --git a/bin/www.js b/bin/www.js index 01cbb8dc..450b4bc8 100644 --- a/bin/www.js +++ b/bin/www.js @@ -5,11 +5,11 @@ import { fileURLToPath } from 'node:url'; import ntfyPublish from '@cityssm/ntfy-publish'; import Debug from 'debug'; import exitHook from 'exit-hook'; -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; const debug = Debug(`lot-occupancy-system:www:${process.pid}`); const directoryName = dirname(fileURLToPath(import.meta.url)); -const processCount = Math.min(configFunctions.getConfigProperty('application.maximumProcesses'), os.cpus().length); -process.title = `${configFunctions.getConfigProperty('application.applicationName')} (Primary)`; +const processCount = Math.min(getConfigProperty('application.maximumProcesses'), os.cpus().length); +process.title = `${getConfigProperty('application.applicationName')} (Primary)`; debug(`Primary pid: ${process.pid}`); debug(`Primary title: ${process.title}`); debug(`Launching ${processCount} processes`); @@ -37,19 +37,19 @@ cluster.on('exit', (worker) => { debug('Starting another worker'); cluster.fork(); }); -const ntfyStartupConfig = configFunctions.getConfigProperty('application.ntfyStartup'); +const ntfyStartupConfig = getConfigProperty('application.ntfyStartup'); if (ntfyStartupConfig !== undefined) { const topic = ntfyStartupConfig.topic; const server = ntfyStartupConfig.server; const ntfyStartupMessage = { topic, - title: configFunctions.getConfigProperty('application.applicationName'), + title: getConfigProperty('application.applicationName'), message: 'Application Started', tags: ['arrow_up'] }; const ntfyShutdownMessage = { topic, - title: configFunctions.getConfigProperty('application.applicationName'), + title: getConfigProperty('application.applicationName'), message: 'Application Shut Down', tags: ['arrow_down'] }; diff --git a/bin/www.ts b/bin/www.ts index 516edcdd..e0a6eed9 100644 --- a/bin/www.ts +++ b/bin/www.ts @@ -7,7 +7,7 @@ import ntfyPublish, { type NtfyMessageOptions } from '@cityssm/ntfy-publish' import Debug from 'debug' import exitHook from 'exit-hook' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import type { WorkerMessage } from '../types/applicationTypes.js' const debug = Debug(`lot-occupancy-system:www:${process.pid}`) @@ -15,13 +15,11 @@ const debug = Debug(`lot-occupancy-system:www:${process.pid}`) const directoryName = dirname(fileURLToPath(import.meta.url)) const processCount = Math.min( - configFunctions.getConfigProperty('application.maximumProcesses'), + getConfigProperty('application.maximumProcesses'), os.cpus().length ) -process.title = `${configFunctions.getConfigProperty( - 'application.applicationName' -)} (Primary)` +process.title = `${getConfigProperty('application.applicationName')} (Primary)` debug(`Primary pid: ${process.pid}`) debug(`Primary title: ${process.title}`) @@ -59,7 +57,7 @@ cluster.on('exit', (worker) => { cluster.fork() }) -const ntfyStartupConfig = configFunctions.getConfigProperty('application.ntfyStartup') +const ntfyStartupConfig = getConfigProperty('application.ntfyStartup') if (ntfyStartupConfig !== undefined) { const topic = ntfyStartupConfig.topic @@ -67,14 +65,14 @@ if (ntfyStartupConfig !== undefined) { const ntfyStartupMessage: NtfyMessageOptions = { topic, - title: configFunctions.getConfigProperty('application.applicationName'), + title: getConfigProperty('application.applicationName'), message: 'Application Started', tags: ['arrow_up'] } const ntfyShutdownMessage: NtfyMessageOptions = { topic, - title: configFunctions.getConfigProperty('application.applicationName'), + title: getConfigProperty('application.applicationName'), message: 'Application Shut Down', tags: ['arrow_down'] } diff --git a/bin/wwwProcess.js b/bin/wwwProcess.js index 0a81b204..92668ecf 100644 --- a/bin/wwwProcess.js +++ b/bin/wwwProcess.js @@ -2,7 +2,7 @@ import http from 'node:http'; import Debug from 'debug'; import exitHook from 'exit-hook'; import { app } from '../app.js'; -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; const debug = Debug(`lot-occupancy-system:wwwProcess:${process.pid}`); function onError(error) { if (error.syscall !== 'listen') { @@ -29,8 +29,8 @@ function onListening(server) { debug(`HTTP Listening on ${bind}`); } } -process.title = `${configFunctions.getConfigProperty('application.applicationName')} (Worker)`; -const httpPort = configFunctions.getConfigProperty('application.httpPort'); +process.title = `${getConfigProperty('application.applicationName')} (Worker)`; +const httpPort = getConfigProperty('application.httpPort'); const httpServer = http.createServer(app); httpServer.listen(httpPort); httpServer.on('error', onError); diff --git a/bin/wwwProcess.ts b/bin/wwwProcess.ts index d60d5255..196e91fa 100644 --- a/bin/wwwProcess.ts +++ b/bin/wwwProcess.ts @@ -7,7 +7,7 @@ import Debug from 'debug' import exitHook from 'exit-hook' import { app } from '../app.js' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' const debug = Debug(`lot-occupancy-system:wwwProcess:${process.pid}`) @@ -58,11 +58,11 @@ function onListening(server: http.Server): void { * Initialize HTTP */ -process.title = `${configFunctions.getConfigProperty( +process.title = `${getConfigProperty( 'application.applicationName' )} (Worker)` -const httpPort = configFunctions.getConfigProperty('application.httpPort') +const httpPort = getConfigProperty('application.httpPort') const httpServer = http.createServer(app) diff --git a/cypress/e2e/02-update/maps.cy.js b/cypress/e2e/02-update/maps.cy.js index 04833df9..a566a0f2 100644 --- a/cypress/e2e/02-update/maps.cy.js +++ b/cypress/e2e/02-update/maps.cy.js @@ -1,6 +1,6 @@ -import * as configFunctions from '../../../helpers/functions.config.js'; +import { getConfigProperty } from '../../../helpers/functions.config.js'; import { testUpdate } from '../../../test/_globals.js'; -import { logout, login } from '../../support/index.js'; +import { login, logout } from '../../support/index.js'; describe('Update - Maps', () => { beforeEach('Loads page', () => { logout(); @@ -37,8 +37,8 @@ describe('Update - Maps', () => { .type(mapJSON.mapLongitude.toString()); }); cy.log('Ensure the default city and province are used'); - cy.get("input[name='mapCity']").should('have.value', configFunctions.getConfigProperty('settings.map.mapCityDefault')); - cy.get("input[name='mapProvince']").should('have.value', configFunctions.getConfigProperty('settings.map.mapProvinceDefault')); + cy.get("input[name='mapCity']").should('have.value', getConfigProperty('settings.map.mapCityDefault')); + cy.get("input[name='mapProvince']").should('have.value', getConfigProperty('settings.map.mapProvinceDefault')); cy.log('Submit the form'); cy.get('#form--map').submit(); cy.wait(1000); @@ -50,8 +50,8 @@ describe('Update - Maps', () => { cy.get("textarea[name='mapDescription']").should('have.value', mapJSON.mapDescription); cy.get("input[name='mapAddress1']").should('have.value', mapJSON.mapAddress1); cy.get("input[name='mapAddress2']").should('have.value', mapJSON.mapAddress2); - cy.get("input[name='mapCity']").should('have.value', configFunctions.getConfigProperty('settings.map.mapCityDefault')); - cy.get("input[name='mapProvince']").should('have.value', configFunctions.getConfigProperty('settings.map.mapProvinceDefault')); + cy.get("input[name='mapCity']").should('have.value', getConfigProperty('settings.map.mapCityDefault')); + cy.get("input[name='mapProvince']").should('have.value', getConfigProperty('settings.map.mapProvinceDefault')); cy.get("input[name='mapPostalCode']").should('have.value', mapJSON.mapPostalCode); cy.get("input[name='mapPhoneNumber']").should('have.value', mapJSON.mapPhoneNumber); cy.get("input[name='mapLatitude']").should('have.value', mapJSON.mapLatitude.toString()); diff --git a/cypress/e2e/02-update/maps.cy.ts b/cypress/e2e/02-update/maps.cy.ts index 64bb8ee8..6085d360 100644 --- a/cypress/e2e/02-update/maps.cy.ts +++ b/cypress/e2e/02-update/maps.cy.ts @@ -1,10 +1,10 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import * as configFunctions from '../../../helpers/functions.config.js' +import { getConfigProperty } from '../../../helpers/functions.config.js' import { testUpdate } from '../../../test/_globals.js' import type { MapRecord } from '../../../types/recordTypes.js' -import { logout, login } from '../../support/index.js' +import { login, logout } from '../../support/index.js' describe('Update - Maps', () => { beforeEach('Loads page', () => { @@ -56,12 +56,12 @@ describe('Update - Maps', () => { cy.get("input[name='mapCity']").should( 'have.value', - configFunctions.getConfigProperty('settings.map.mapCityDefault') + getConfigProperty('settings.map.mapCityDefault') ) cy.get("input[name='mapProvince']").should( 'have.value', - configFunctions.getConfigProperty('settings.map.mapProvinceDefault') + getConfigProperty('settings.map.mapProvinceDefault') ) cy.log('Submit the form') @@ -93,11 +93,11 @@ describe('Update - Maps', () => { cy.get("input[name='mapCity']").should( 'have.value', - configFunctions.getConfigProperty('settings.map.mapCityDefault') + getConfigProperty('settings.map.mapCityDefault') ) cy.get("input[name='mapProvince']").should( 'have.value', - configFunctions.getConfigProperty('settings.map.mapProvinceDefault') + getConfigProperty('settings.map.mapProvinceDefault') ) cy.get("input[name='mapPostalCode']").should( diff --git a/data/databasePaths.js b/data/databasePaths.js index 16868e19..c37d1262 100644 --- a/data/databasePaths.js +++ b/data/databasePaths.js @@ -1,7 +1,7 @@ -import * as configFunctions from '../helpers/functions.config.js'; import Debug from 'debug'; +import { getConfigProperty } from '../helpers/functions.config.js'; const debug = Debug('lot-occupancy-system:databasePaths'); -export const useTestDatabases = configFunctions.getConfigProperty('application.useTestDatabases') || +export const useTestDatabases = getConfigProperty('application.useTestDatabases') || process.env.TEST_DATABASES === 'true'; if (useTestDatabases) { debug('Using "-testing" databases.'); diff --git a/data/databasePaths.ts b/data/databasePaths.ts index 367ef156..093de9a8 100644 --- a/data/databasePaths.ts +++ b/data/databasePaths.ts @@ -1,12 +1,13 @@ -import * as configFunctions from '../helpers/functions.config.js' - import Debug from 'debug' + +import { getConfigProperty } from '../helpers/functions.config.js' + const debug = Debug('lot-occupancy-system:databasePaths') // Determine if test databases should be used export const useTestDatabases = - configFunctions.getConfigProperty('application.useTestDatabases') || + getConfigProperty('application.useTestDatabases') || process.env.TEST_DATABASES === 'true' if (useTestDatabases) { diff --git a/database/cleanupDatabase.js b/database/cleanupDatabase.js index 28e9f606..e101ed07 100644 --- a/database/cleanupDatabase.js +++ b/database/cleanupDatabase.js @@ -1,10 +1,10 @@ -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; import { acquireConnection } from './pool.js'; export default async function cleanupDatabase(user) { const database = await acquireConnection(); const rightNowMillis = Date.now(); const recordDeleteTimeMillisMin = rightNowMillis - - configFunctions.getConfigProperty('settings.adminCleanup.recordDeleteAgeDays') * + getConfigProperty('settings.adminCleanup.recordDeleteAgeDays') * 86_400 * 1000; let inactivatedRecordCount = 0; diff --git a/database/cleanupDatabase.ts b/database/cleanupDatabase.ts index e24dcaa2..8e851401 100644 --- a/database/cleanupDatabase.ts +++ b/database/cleanupDatabase.ts @@ -1,4 +1,4 @@ -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import { acquireConnection } from './pool.js' @@ -10,7 +10,7 @@ export default async function cleanupDatabase( const rightNowMillis = Date.now() const recordDeleteTimeMillisMin = rightNowMillis - - configFunctions.getConfigProperty('settings.adminCleanup.recordDeleteAgeDays') * + getConfigProperty('settings.adminCleanup.recordDeleteAgeDays') * 86_400 * 1000 diff --git a/database/getLotOccupancies.d.ts b/database/getLotOccupancies.d.ts index 2f932477..a3d4332c 100644 --- a/database/getLotOccupancies.d.ts +++ b/database/getLotOccupancies.d.ts @@ -1,9 +1,10 @@ +import { DateString } from '@cityssm/utils-datetime'; import type { PoolConnection } from 'better-sqlite-pool'; import type { LotOccupancy } from '../types/recordTypes.js'; interface GetLotOccupanciesFilters { lotId?: number | string; occupancyTime?: '' | 'past' | 'current' | 'future'; - occupancyStartDateString?: string; + occupancyStartDateString?: DateString; occupancyEffectiveDateString?: string; occupantName?: string; occupancyTypeId?: number | string; diff --git a/database/getLotOccupancies.js b/database/getLotOccupancies.js index 2ccc0629..80c1cf70 100644 --- a/database/getLotOccupancies.js +++ b/database/getLotOccupancies.js @@ -1,6 +1,6 @@ import { dateIntegerToString, dateStringToInteger } from '@cityssm/utils-datetime'; import { getOccupancyTypeById } from '../helpers/functions.cache.js'; -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; import { getLotNameWhereClause, getOccupancyTimeWhereClause, getOccupantNameWhereClause } from '../helpers/functions.sqlFilters.js'; import { getLotOccupancyFees } from './getLotOccupancyFees.js'; import { getLotOccupancyOccupants } from './getLotOccupancyOccupants.js'; @@ -116,7 +116,7 @@ export async function getLotOccupancies(filters, options, connectedDatabase) { const occupancyType = await getOccupancyTypeById(lotOccupancy.occupancyTypeId); if (occupancyType !== undefined) { lotOccupancy.printEJS = (occupancyType.occupancyTypePrints ?? []).includes('*') - ? configFunctions.getConfigProperty('settings.lotOccupancy.prints')[0] + ? getConfigProperty('settings.lotOccupancy.prints')[0] : occupancyType.occupancyTypePrints[0]; } await addInclusions(lotOccupancy, options, database); diff --git a/database/getLotOccupancies.ts b/database/getLotOccupancies.ts index 316ccc0b..7b9ca534 100644 --- a/database/getLotOccupancies.ts +++ b/database/getLotOccupancies.ts @@ -1,11 +1,12 @@ import { + DateString, dateIntegerToString, dateStringToInteger } from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' import { getOccupancyTypeById } from '../helpers/functions.cache.js' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import { getLotNameWhereClause, getOccupancyTimeWhereClause, @@ -21,7 +22,7 @@ import { acquireConnection } from './pool.js' interface GetLotOccupanciesFilters { lotId?: number | string occupancyTime?: '' | 'past' | 'current' | 'future' - occupancyStartDateString?: string + occupancyStartDateString?: DateString occupancyEffectiveDateString?: string occupantName?: string occupancyTypeId?: number | string @@ -87,7 +88,9 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): { if ((filters.occupancyStartDateString ?? '') !== '') { sqlWhereClause += ' and o.occupancyStartDate = ?' - sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString!)) + sqlParameters.push( + dateStringToInteger(filters.occupancyStartDateString as DateString) + ) } if ((filters.occupancyEffectiveDateString ?? '') !== '') { @@ -96,8 +99,8 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): { or (o.occupancyStartDate <= ? and o.occupancyEndDate >= ?) )` sqlParameters.push( - dateStringToInteger(filters.occupancyEffectiveDateString!), - dateStringToInteger(filters.occupancyEffectiveDateString!) + dateStringToInteger(filters.occupancyEffectiveDateString as DateString), + dateStringToInteger(filters.occupancyEffectiveDateString as DateString) ) } @@ -222,7 +225,7 @@ export async function getLotOccupancies( lotOccupancy.printEJS = ( occupancyType.occupancyTypePrints ?? [] ).includes('*') - ? configFunctions.getConfigProperty('settings.lotOccupancy.prints')[0] + ? getConfigProperty('settings.lotOccupancy.prints')[0] : occupancyType.occupancyTypePrints![0] } diff --git a/database/getLotOccupancyTransactions.js b/database/getLotOccupancyTransactions.js index f77145ec..8c658173 100644 --- a/database/getLotOccupancyTransactions.js +++ b/database/getLotOccupancyTransactions.js @@ -1,5 +1,5 @@ import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetime'; -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; import * as gpFunctions from '../helpers/functions.dynamicsGP.js'; import { acquireConnection } from './pool.js'; export async function getLotOccupancyTransactions(lotOccupancyId, options, connectedDatabase) { @@ -20,7 +20,7 @@ export async function getLotOccupancyTransactions(lotOccupancyId, options, conne database.release(); } if ((options?.includeIntegrations ?? false) && - configFunctions.getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { + getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { for (const transaction of lotOccupancyTransactions) { if ((transaction.externalReceiptNumber ?? '') !== '') { const gpDocument = await gpFunctions.getDynamicsGPDocument(transaction.externalReceiptNumber ?? ''); diff --git a/database/getLotOccupancyTransactions.ts b/database/getLotOccupancyTransactions.ts index 82f7cded..8a97c184 100644 --- a/database/getLotOccupancyTransactions.ts +++ b/database/getLotOccupancyTransactions.ts @@ -4,7 +4,7 @@ import { } from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import * as gpFunctions from '../helpers/functions.dynamicsGP.js' import type { LotOccupancyTransaction } from '../types/recordTypes.js' @@ -41,7 +41,7 @@ export async function getLotOccupancyTransactions( if ( (options?.includeIntegrations ?? false) && - configFunctions.getConfigProperty('settings.dynamicsGP.integrationIsEnabled') + getConfigProperty('settings.dynamicsGP.integrationIsEnabled') ) { for (const transaction of lotOccupancyTransactions) { if ((transaction.externalReceiptNumber ?? '') !== '') { diff --git a/database/getLots.js b/database/getLots.js index 2e113392..cc32766f 100644 --- a/database/getLots.js +++ b/database/getLots.js @@ -1,5 +1,5 @@ import { dateToInteger } from '@cityssm/utils-datetime'; -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; import { getLotNameWhereClause } from '../helpers/functions.sqlFilters.js'; import { acquireConnection } from './pool.js'; function buildWhereClause(filters) { @@ -61,7 +61,7 @@ export async function getLots(filters, options, connectedDatabase) { let lots = []; if (options.limit === -1 || count > 0) { const includeLotOccupancyCount = options.includeLotOccupancyCount ?? true; - database.function('userFn_lotNameSortName', configFunctions.getConfigProperty('settings.lot.lotNameSortNameFunction')); + database.function('userFn_lotNameSortName', getConfigProperty('settings.lot.lotNameSortNameFunction')); if (includeLotOccupancyCount) { sqlParameters.unshift(currentDate, currentDate); } diff --git a/database/getLots.ts b/database/getLots.ts index 7a018298..6153dac6 100644 --- a/database/getLots.ts +++ b/database/getLots.ts @@ -1,7 +1,7 @@ import { dateToInteger } from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import { getLotNameWhereClause } from '../helpers/functions.sqlFilters.js' import type { Lot } from '../types/recordTypes.js' @@ -113,7 +113,7 @@ export async function getLots( database.function( 'userFn_lotNameSortName', - configFunctions.getConfigProperty('settings.lot.lotNameSortNameFunction') + getConfigProperty('settings.lot.lotNameSortNameFunction') ) if (includeLotOccupancyCount) { diff --git a/database/getNextLotId.js b/database/getNextLotId.js index 311549c5..781b8191 100644 --- a/database/getNextLotId.js +++ b/database/getNextLotId.js @@ -1,8 +1,8 @@ -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; import { acquireConnection } from './pool.js'; export async function getNextLotId(lotId) { const database = await acquireConnection(); - database.function('userFn_lotNameSortName', configFunctions.getConfigProperty('settings.lot.lotNameSortNameFunction')); + database.function('userFn_lotNameSortName', getConfigProperty('settings.lot.lotNameSortNameFunction')); const result = database .prepare(`select lotId from Lots diff --git a/database/getNextLotId.ts b/database/getNextLotId.ts index c6266b46..e16cad64 100644 --- a/database/getNextLotId.ts +++ b/database/getNextLotId.ts @@ -1,4 +1,4 @@ -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import { acquireConnection } from './pool.js' @@ -9,7 +9,7 @@ export async function getNextLotId( database.function( 'userFn_lotNameSortName', - configFunctions.getConfigProperty('settings.lot.lotNameSortNameFunction') + getConfigProperty('settings.lot.lotNameSortNameFunction') ) const result = database diff --git a/database/getNextWorkOrderNumber.js b/database/getNextWorkOrderNumber.js index ec9f9980..01e0b66d 100644 --- a/database/getNextWorkOrderNumber.js +++ b/database/getNextWorkOrderNumber.js @@ -1,10 +1,10 @@ -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; import { acquireConnection } from './pool.js'; export async function getNextWorkOrderNumber(connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); - const paddingLength = configFunctions.getConfigProperty('settings.workOrders.workOrderNumberLength'); + const paddingLength = getConfigProperty('settings.workOrders.workOrderNumberLength'); const currentYearString = new Date().getFullYear().toString(); - const regex = new RegExp('^' + currentYearString + '-\\d+$'); + const regex = new RegExp(`^${currentYearString}-\\d+$`); database.function('userFn_matchesWorkOrderNumberSyntax', (workOrderNumber) => { return regex.test(workOrderNumber) ? 1 : 0; }); @@ -21,8 +21,6 @@ export async function getNextWorkOrderNumber(connectedDatabase) { workOrderNumberIndex = Number.parseInt(workOrderNumberRecord.workOrderNumber.split('-')[1], 10); } workOrderNumberIndex += 1; - return (currentYearString + - '-' + - workOrderNumberIndex.toString().padStart(paddingLength, '0')); + return `${currentYearString}-${workOrderNumberIndex.toString().padStart(paddingLength, '0')}`; } export default getNextWorkOrderNumber; diff --git a/database/getNextWorkOrderNumber.ts b/database/getNextWorkOrderNumber.ts index ee9889a9..3c0b2b6d 100644 --- a/database/getNextWorkOrderNumber.ts +++ b/database/getNextWorkOrderNumber.ts @@ -1,6 +1,6 @@ import type { PoolConnection } from 'better-sqlite-pool' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import { acquireConnection } from './pool.js' @@ -9,12 +9,12 @@ export async function getNextWorkOrderNumber( ): Promise { const database = connectedDatabase ?? (await acquireConnection()) - const paddingLength = configFunctions.getConfigProperty( + const paddingLength = getConfigProperty( 'settings.workOrders.workOrderNumberLength' ) const currentYearString = new Date().getFullYear().toString() - const regex = new RegExp('^' + currentYearString + '-\\d+$') + const regex = new RegExp(`^${currentYearString}-\\d+$`) database.function( 'userFn_matchesWorkOrderNumberSyntax', @@ -48,11 +48,7 @@ export async function getNextWorkOrderNumber( workOrderNumberIndex += 1 - return ( - currentYearString + - '-' + - workOrderNumberIndex.toString().padStart(paddingLength, '0') - ) + return `${currentYearString}-${workOrderNumberIndex.toString().padStart(paddingLength, '0')}` } export default getNextWorkOrderNumber diff --git a/database/getOccupancyTypePrints.js b/database/getOccupancyTypePrints.js index a309a189..053029dd 100644 --- a/database/getOccupancyTypePrints.js +++ b/database/getOccupancyTypePrints.js @@ -1,6 +1,6 @@ -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; import { acquireConnection } from './pool.js'; -const availablePrints = configFunctions.getConfigProperty('settings.lotOccupancy.prints'); +const availablePrints = getConfigProperty('settings.lotOccupancy.prints'); const userFunction_configContainsPrintEJS = (printEJS) => { if (printEJS === '*' || availablePrints.includes(printEJS)) { return 1; diff --git a/database/getOccupancyTypePrints.ts b/database/getOccupancyTypePrints.ts index 4cd81a9f..1f4908bb 100644 --- a/database/getOccupancyTypePrints.ts +++ b/database/getOccupancyTypePrints.ts @@ -1,12 +1,10 @@ import type { PoolConnection } from 'better-sqlite-pool' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import { acquireConnection } from './pool.js' -const availablePrints = configFunctions.getConfigProperty( - 'settings.lotOccupancy.prints' -) +const availablePrints = getConfigProperty('settings.lotOccupancy.prints') // eslint-disable-next-line @typescript-eslint/naming-convention const userFunction_configContainsPrintEJS = (printEJS: string): number => { diff --git a/database/getPreviousLotId.js b/database/getPreviousLotId.js index 2676d04d..05633b0e 100644 --- a/database/getPreviousLotId.js +++ b/database/getPreviousLotId.js @@ -1,8 +1,8 @@ -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; import { acquireConnection } from './pool.js'; export async function getPreviousLotId(lotId) { const database = await acquireConnection(); - database.function('userFn_lotNameSortName', configFunctions.getConfigProperty('settings.lot.lotNameSortNameFunction')); + database.function('userFn_lotNameSortName', getConfigProperty('settings.lot.lotNameSortNameFunction')); const result = database .prepare(`select lotId from Lots where recordDelete_timeMillis is null diff --git a/database/getPreviousLotId.ts b/database/getPreviousLotId.ts index 58b49877..38b94d81 100644 --- a/database/getPreviousLotId.ts +++ b/database/getPreviousLotId.ts @@ -1,4 +1,4 @@ -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import { acquireConnection } from './pool.js' @@ -9,7 +9,7 @@ export async function getPreviousLotId( database.function( 'userFn_lotNameSortName', - configFunctions.getConfigProperty('settings.lot.lotNameSortNameFunction') + getConfigProperty('settings.lot.lotNameSortNameFunction') ) const result = database diff --git a/database/getReportData.js b/database/getReportData.js index 314ee019..40f9f82a 100644 --- a/database/getReportData.js +++ b/database/getReportData.js @@ -1,8 +1,8 @@ import * as dateTimeFunctions from '@cityssm/utils-datetime'; import camelCase from 'camelcase'; -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; import { acquireConnection } from './pool.js'; -const mapCamelCase = camelCase(configFunctions.getConfigProperty('aliases.map')); +const mapCamelCase = camelCase(getConfigProperty('aliases.map')); const mapNameAlias = `${mapCamelCase}Name`; const mapDescriptionAlias = `${mapCamelCase}Description`; const mapAddress1Alias = `${mapCamelCase}Address1`; @@ -11,17 +11,17 @@ const mapCityAlias = `${mapCamelCase}City`; const mapProvinceAlias = `${mapCamelCase}Province`; const mapPostalCodeAlias = `${mapCamelCase}PostalCode`; const mapPhoneNumberAlias = `${mapCamelCase}PhoneNumber`; -const lotCamelCase = camelCase(configFunctions.getConfigProperty('aliases.lot')); +const lotCamelCase = camelCase(getConfigProperty('aliases.lot')); const lotIdAlias = `${lotCamelCase}Id`; const lotNameAlias = `${lotCamelCase}Name`; const lotTypeAlias = `${lotCamelCase}Type`; const lotStatusAlias = `${lotCamelCase}Status`; -const occupancyCamelCase = camelCase(configFunctions.getConfigProperty('aliases.occupancy')); +const occupancyCamelCase = camelCase(getConfigProperty('aliases.occupancy')); const lotOccupancyIdAlias = `${occupancyCamelCase}Id`; const occupancyTypeAlias = `${occupancyCamelCase}Type`; const occupancyStartDateAlias = `${occupancyCamelCase}StartDate`; const occupancyEndDateAlias = `${occupancyCamelCase}EndDate`; -const occupantCamelCase = camelCase(configFunctions.getConfigProperty('aliases.occupant')); +const occupantCamelCase = camelCase(getConfigProperty('aliases.occupant')); const lotOccupantIndexAlias = `${occupantCamelCase}Index`; const lotOccupantTypeAlias = `${occupantCamelCase}Type`; const occupantNameAlias = `${occupantCamelCase}Name`; diff --git a/database/getReportData.ts b/database/getReportData.ts index 8b3cb47e..0943db41 100644 --- a/database/getReportData.ts +++ b/database/getReportData.ts @@ -4,13 +4,13 @@ import * as dateTimeFunctions from '@cityssm/utils-datetime' import camelCase from 'camelcase' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' import { acquireConnection } from './pool.js' export type ReportParameters = Record -const mapCamelCase = camelCase(configFunctions.getConfigProperty('aliases.map')) +const mapCamelCase = camelCase(getConfigProperty('aliases.map')) const mapNameAlias = `${mapCamelCase}Name` const mapDescriptionAlias = `${mapCamelCase}Description` const mapAddress1Alias = `${mapCamelCase}Address1` @@ -20,23 +20,19 @@ const mapProvinceAlias = `${mapCamelCase}Province` const mapPostalCodeAlias = `${mapCamelCase}PostalCode` const mapPhoneNumberAlias = `${mapCamelCase}PhoneNumber` -const lotCamelCase = camelCase(configFunctions.getConfigProperty('aliases.lot')) +const lotCamelCase = camelCase(getConfigProperty('aliases.lot')) const lotIdAlias = `${lotCamelCase}Id` const lotNameAlias = `${lotCamelCase}Name` const lotTypeAlias = `${lotCamelCase}Type` const lotStatusAlias = `${lotCamelCase}Status` -const occupancyCamelCase = camelCase( - configFunctions.getConfigProperty('aliases.occupancy') -) +const occupancyCamelCase = camelCase(getConfigProperty('aliases.occupancy')) const lotOccupancyIdAlias = `${occupancyCamelCase}Id` const occupancyTypeAlias = `${occupancyCamelCase}Type` const occupancyStartDateAlias = `${occupancyCamelCase}StartDate` const occupancyEndDateAlias = `${occupancyCamelCase}EndDate` -const occupantCamelCase = camelCase( - configFunctions.getConfigProperty('aliases.occupant') -) +const occupantCamelCase = camelCase(getConfigProperty('aliases.occupant')) const lotOccupantIndexAlias = `${occupantCamelCase}Index` const lotOccupantTypeAlias = `${occupantCamelCase}Type` const occupantNameAlias = `${occupantCamelCase}Name` @@ -235,7 +231,7 @@ export async function getReportData( sqlParameters.push( dateTimeFunctions.dateStringToInteger( - reportParameters.transactionDateString as string + reportParameters.transactionDateString as dateTimeFunctions.DateString ) ) break diff --git a/handlers/admin-get/lotTypes.js b/handlers/admin-get/lotTypes.js index a4da711f..5fd2443d 100644 --- a/handlers/admin-get/lotTypes.js +++ b/handlers/admin-get/lotTypes.js @@ -1,9 +1,9 @@ import { getLotTypes } from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(_request, response) { const lotTypes = await getLotTypes(); response.render('admin-lotTypes', { - headTitle: `${configFunctions.getConfigProperty('aliases.lot')} Type Management`, + headTitle: `${getConfigProperty('aliases.lot')} Type Management`, lotTypes }); } diff --git a/handlers/admin-get/lotTypes.ts b/handlers/admin-get/lotTypes.ts index d7d53105..afd91b2f 100644 --- a/handlers/admin-get/lotTypes.ts +++ b/handlers/admin-get/lotTypes.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' import { getLotTypes } from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( _request: Request, @@ -10,7 +10,7 @@ export default async function handler( const lotTypes = await getLotTypes() response.render('admin-lotTypes', { - headTitle: `${configFunctions.getConfigProperty('aliases.lot')} Type Management`, + headTitle: `${getConfigProperty('aliases.lot')} Type Management`, lotTypes }) } diff --git a/handlers/admin-get/ntfyStartup.js b/handlers/admin-get/ntfyStartup.js index 2e6cb81e..4381f40f 100644 --- a/handlers/admin-get/ntfyStartup.js +++ b/handlers/admin-get/ntfyStartup.js @@ -1,8 +1,7 @@ -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default function handler(_request, response) { - if (configFunctions.getConfigProperty('application.ntfyStartup') === undefined) { - response.redirect(configFunctions.getConfigProperty('reverseProxy.urlPrefix') + - '/dashboard/?error=ntfyNotConfigured'); + if (getConfigProperty('application.ntfyStartup') === undefined) { + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=ntfyNotConfigured`); return; } response.render('admin-ntfyStartup', { diff --git a/handlers/admin-get/ntfyStartup.ts b/handlers/admin-get/ntfyStartup.ts index 58b86775..ced61ee8 100644 --- a/handlers/admin-get/ntfyStartup.ts +++ b/handlers/admin-get/ntfyStartup.ts @@ -1,14 +1,11 @@ import type { Request, Response } from 'express' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default function handler(_request: Request, response: Response): void { - if ( - configFunctions.getConfigProperty('application.ntfyStartup') === undefined - ) { + if (getConfigProperty('application.ntfyStartup') === undefined) { response.redirect( - configFunctions.getConfigProperty('reverseProxy.urlPrefix') + - '/dashboard/?error=ntfyNotConfigured' + `${getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=ntfyNotConfigured` ) return } diff --git a/handlers/admin-get/occupancyTypes.js b/handlers/admin-get/occupancyTypes.js index e5a4a501..e9fd082f 100644 --- a/handlers/admin-get/occupancyTypes.js +++ b/handlers/admin-get/occupancyTypes.js @@ -1,10 +1,10 @@ import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; import * as printFunctions from '../../helpers/functions.print.js'; export default async function handler(_request, response) { const occupancyTypes = await getOccupancyTypes(); const allOccupancyTypeFields = await getAllOccupancyTypeFields(); - const occupancyTypePrints = configFunctions.getConfigProperty('settings.lotOccupancy.prints'); + const occupancyTypePrints = getConfigProperty('settings.lotOccupancy.prints'); const occupancyTypePrintTitles = {}; for (const printEJS of occupancyTypePrints) { const printConfig = printFunctions.getPrintConfig(printEJS); @@ -13,7 +13,7 @@ export default async function handler(_request, response) { } } response.render('admin-occupancyTypes', { - headTitle: `${configFunctions.getConfigProperty('aliases.occupancy')} Type Management`, + headTitle: `${getConfigProperty('aliases.occupancy')} Type Management`, occupancyTypes, allOccupancyTypeFields, occupancyTypePrintTitles diff --git a/handlers/admin-get/occupancyTypes.ts b/handlers/admin-get/occupancyTypes.ts index 7072e1c8..0fafb22b 100644 --- a/handlers/admin-get/occupancyTypes.ts +++ b/handlers/admin-get/occupancyTypes.ts @@ -4,7 +4,7 @@ import { getAllOccupancyTypeFields, getOccupancyTypes } from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import * as printFunctions from '../../helpers/functions.print.js' export default async function handler( @@ -14,9 +14,7 @@ export default async function handler( const occupancyTypes = await getOccupancyTypes() const allOccupancyTypeFields = await getAllOccupancyTypeFields() - const occupancyTypePrints = configFunctions.getConfigProperty( - 'settings.lotOccupancy.prints' - ) + const occupancyTypePrints = getConfigProperty('settings.lotOccupancy.prints') const occupancyTypePrintTitles = {} @@ -29,7 +27,7 @@ export default async function handler( } response.render('admin-occupancyTypes', { - headTitle: `${configFunctions.getConfigProperty('aliases.occupancy')} Type Management`, + headTitle: `${getConfigProperty('aliases.occupancy')} Type Management`, occupancyTypes, allOccupancyTypeFields, occupancyTypePrintTitles diff --git a/handlers/api-get/milestoneICS.js b/handlers/api-get/milestoneICS.js index 66c27c17..0548b9b9 100644 --- a/handlers/api-get/milestoneICS.js +++ b/handlers/api-get/milestoneICS.js @@ -1,9 +1,9 @@ import ical, { ICalEventStatus } from 'ical-generator'; import { getWorkOrderMilestones } from '../../database/getWorkOrderMilestones.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; import { getPrintConfig } from '../../helpers/functions.print.js'; const calendarCompany = 'cityssm.github.io'; -const calendarProduct = configFunctions.getConfigProperty('application.applicationName'); +const calendarProduct = getConfigProperty('application.applicationName'); const timeStringSplitRegex = /[ :-]/; function escapeHTML(stringToEscape) { return stringToEscape.replaceAll(/[^\d a-z]/gi, (c) => `&#${c.codePointAt(0)};`); @@ -11,10 +11,10 @@ function escapeHTML(stringToEscape) { function getUrlRoot(request) { return ('http://' + request.hostname + - (configFunctions.getConfigProperty('application.httpPort') === 80 + (getConfigProperty('application.httpPort') === 80 ? '' - : `:${configFunctions.getConfigProperty('application.httpPort')}`) + - configFunctions.getConfigProperty('reverseProxy.urlPrefix')); + : `:${getConfigProperty('application.httpPort')}`) + + getConfigProperty('reverseProxy.urlPrefix')); } function getWorkOrderUrl(request, milestone) { return `${getUrlRoot(request)}/workOrders/${milestone.workOrderId}`; @@ -25,8 +25,8 @@ function buildEventSummary(milestone) { ? milestone.workOrderMilestoneDescription ?? '' : milestone.workOrderMilestoneType ?? '').trim(); let occupantCount = 0; - for (const lotOccupancy of milestone.workOrderLotOccupancies) { - for (const occupant of lotOccupancy.lotOccupancyOccupants) { + for (const lotOccupancy of milestone.workOrderLotOccupancies ?? []) { + for (const occupant of lotOccupancy.lotOccupancyOccupants ?? []) { occupantCount += 1; if (occupantCount === 1) { if (summary !== '') { @@ -49,22 +49,22 @@ function buildEventDescriptionHTML_occupancies(request, milestone) { if (milestone.workOrderLotOccupancies.length > 0) { const urlRoot = getUrlRoot(request); descriptionHTML = `

- Related ${escapeHTML(configFunctions.getConfigProperty('aliases.occupancies'))} + Related ${escapeHTML(getConfigProperty('aliases.occupancies'))}

- - + + - + `; - for (const occupancy of milestone.workOrderLotOccupancies) { + for (const occupancy of milestone.workOrderLotOccupancies ?? []) { descriptionHTML += `'; } @@ -93,22 +93,22 @@ function buildEventDescriptionHTML_lots(request, milestone) { if (milestone.workOrderLots.length > 0) { const urlRoot = getUrlRoot(request); descriptionHTML += `

- Related ${escapeHTML(configFunctions.getConfigProperty('aliases.lots'))} + Related ${escapeHTML(getConfigProperty('aliases.lots'))}

${escapeHTML(configFunctions.getConfigProperty('aliases.occupancy'))} Type${escapeHTML(configFunctions.getConfigProperty('aliases.lot'))}${escapeHTML(getConfigProperty('aliases.occupancy'))} Type${escapeHTML(getConfigProperty('aliases.lot'))} Start Date End Date${escapeHTML(configFunctions.getConfigProperty('aliases.occupants'))}${escapeHTML(getConfigProperty('aliases.occupants'))}
- ${escapeHTML(occupancy.occupancyType)} + ${escapeHTML(occupancy.occupancyType ?? '')} @@ -79,8 +79,8 @@ function buildEventDescriptionHTML_occupancies(request, milestone) { : '(No End Date)'} `; - for (const occupant of occupancy.lotOccupancyOccupants) { - descriptionHTML += `${escapeHTML(occupant.lotOccupantType)}: ${escapeHTML(occupant.occupantName)} ${escapeHTML(occupant.occupantFamilyName)}
`; + for (const occupant of occupancy.lotOccupancyOccupants ?? []) { + descriptionHTML += `${escapeHTML(occupant.lotOccupantType)}: ${escapeHTML(occupant.occupantName ?? '')} ${escapeHTML(occupant.occupantFamilyName ?? '')}
`; } descriptionHTML += '
`; - for (const lot of milestone.workOrderLots) { + for (const lot of milestone.workOrderLots ?? []) { descriptionHTML += `
- ${escapeHTML(configFunctions.getConfigProperty('aliases.lot'))} Type + ${escapeHTML(getConfigProperty('aliases.lot'))} Type - ${escapeHTML(configFunctions.getConfigProperty('aliases.map'))} + ${escapeHTML(getConfigProperty('aliases.map'))} - ${escapeHTML(configFunctions.getConfigProperty('aliases.lot'))} Type + ${escapeHTML(getConfigProperty('aliases.lot'))} Type Status
@@ -126,7 +126,7 @@ function buildEventDescriptionHTML_lots(request, milestone) { } function buildEventDescriptionHTML_prints(request, milestone) { let descriptionHTML = ''; - const prints = configFunctions.getConfigProperty('settings.workOrders.prints'); + const prints = getConfigProperty('settings.workOrders.prints'); if (prints.length > 0) { const urlRoot = getUrlRoot(request); descriptionHTML += '

Prints

'; @@ -167,7 +167,7 @@ function buildEventCategoryList(milestone) { function buildEventLocation(milestone) { const lotNames = []; if (milestone.workOrderLots.length > 0) { - for (const lot of milestone.workOrderLots) { + for (const lot of milestone.workOrderLots ?? []) { lotNames.push(`${lot.mapName ?? ''}: ${lot.lotName ?? ''}`); } } @@ -240,18 +240,18 @@ export default async function handler(request, response) { calendarEvent.location(location); if (milestone.workOrderLotOccupancies.length > 0) { let organizerSet = false; - for (const lotOccupancy of milestone.workOrderLotOccupancies) { - for (const occupant of lotOccupancy.lotOccupancyOccupants) { + for (const lotOccupancy of milestone.workOrderLotOccupancies ?? []) { + for (const occupant of lotOccupancy.lotOccupancyOccupants ?? []) { if (organizerSet) { calendarEvent.createAttendee({ name: `${occupant.occupantName ?? ''} ${occupant.occupantFamilyName ?? ''}`, - email: configFunctions.getConfigProperty('settings.workOrders.calendarEmailAddress') + email: getConfigProperty('settings.workOrders.calendarEmailAddress') }); } else { calendarEvent.organizer({ name: `${occupant.occupantName ?? ''} ${occupant.occupantFamilyName ?? ''}`, - email: configFunctions.getConfigProperty('settings.workOrders.calendarEmailAddress') + email: getConfigProperty('settings.workOrders.calendarEmailAddress') }); organizerSet = true; } @@ -261,7 +261,7 @@ export default async function handler(request, response) { else { calendarEvent.organizer({ name: milestone.recordCreate_userName, - email: configFunctions.getConfigProperty('settings.workOrders.calendarEmailAddress') + email: getConfigProperty('settings.workOrders.calendarEmailAddress') }); } } diff --git a/handlers/api-get/milestoneICS.ts b/handlers/api-get/milestoneICS.ts index a107fb44..baa957e8 100644 --- a/handlers/api-get/milestoneICS.ts +++ b/handlers/api-get/milestoneICS.ts @@ -7,21 +7,19 @@ import { type WorkOrderMilestoneFilters, getWorkOrderMilestones } from '../../database/getWorkOrderMilestones.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import { getPrintConfig } from '../../helpers/functions.print.js' import type { WorkOrderMilestone } from '../../types/recordTypes.js' const calendarCompany = 'cityssm.github.io' -const calendarProduct = configFunctions.getConfigProperty( - 'application.applicationName' -) +const calendarProduct = getConfigProperty('application.applicationName') const timeStringSplitRegex = /[ :-]/ function escapeHTML(stringToEscape: string): string { return stringToEscape.replaceAll( /[^\d a-z]/gi, - (c) => `&#${c.codePointAt(0)!};` + (c) => `&#${c.codePointAt(0)};` ) } @@ -29,10 +27,10 @@ function getUrlRoot(request: Request): string { return ( 'http://' + request.hostname + - (configFunctions.getConfigProperty('application.httpPort') === 80 + (getConfigProperty('application.httpPort') === 80 ? '' - : `:${configFunctions.getConfigProperty('application.httpPort')}`) + - configFunctions.getConfigProperty('reverseProxy.urlPrefix') + : `:${getConfigProperty('application.httpPort')}`) + + getConfigProperty('reverseProxy.urlPrefix') ) } @@ -40,7 +38,7 @@ function getWorkOrderUrl( request: Request, milestone: WorkOrderMilestone ): string { - return `${getUrlRoot(request)}/workOrders/${milestone.workOrderId!}` + return `${getUrlRoot(request)}/workOrders/${milestone.workOrderId}` } function buildEventSummary(milestone: WorkOrderMilestone): string { @@ -53,8 +51,8 @@ function buildEventSummary(milestone: WorkOrderMilestone): string { let occupantCount = 0 - for (const lotOccupancy of milestone.workOrderLotOccupancies!) { - for (const occupant of lotOccupancy.lotOccupancyOccupants!) { + for (const lotOccupancy of milestone.workOrderLotOccupancies ?? []) { + for (const occupant of lotOccupancy.lotOccupancyOccupants ?? []) { occupantCount += 1 if (occupantCount === 1) { @@ -88,47 +86,45 @@ function buildEventDescriptionHTML_occupancies( const urlRoot = getUrlRoot(request) descriptionHTML = `

- Related ${escapeHTML(configFunctions.getConfigProperty('aliases.occupancies'))} + Related ${escapeHTML(getConfigProperty('aliases.occupancies'))}

- - + + - + ` - for (const occupancy of milestone.workOrderLotOccupancies!) { + for (const occupancy of milestone.workOrderLotOccupancies ?? []) { descriptionHTML += `
${escapeHTML( - configFunctions.getConfigProperty('aliases.occupancy') - )} Type${escapeHTML(configFunctions.getConfigProperty('aliases.lot'))}${escapeHTML(getConfigProperty('aliases.occupancy'))} Type${escapeHTML(getConfigProperty('aliases.lot'))} Start Date End Date${escapeHTML(configFunctions.getConfigProperty('aliases.occupants'))}${escapeHTML(getConfigProperty('aliases.occupants'))}
- - ${escapeHTML(occupancy.occupancyType!)} + + ${escapeHTML(occupancy.occupancyType ?? '')} ${occupancy.lotName ? escapeHTML(occupancy.lotName) : '(Not Set)'} - ${occupancy.occupancyStartDateString!} + ${occupancy.occupancyStartDateString} ${ occupancy.occupancyEndDate - ? occupancy.occupancyEndDateString! + ? occupancy.occupancyEndDateString : '(No End Date)' } ` - for (const occupant of occupancy.lotOccupancyOccupants!) { + for (const occupant of occupancy.lotOccupancyOccupants ?? []) { descriptionHTML += `${escapeHTML( occupant.lotOccupantType! - )}: ${escapeHTML(occupant.occupantName!)} ${escapeHTML( - occupant.occupantFamilyName! + )}: ${escapeHTML(occupant.occupantName ?? '')} ${escapeHTML( + occupant.occupantFamilyName ?? '' )}
` } @@ -152,23 +148,23 @@ function buildEventDescriptionHTML_lots( const urlRoot = getUrlRoot(request) descriptionHTML += `

- Related ${escapeHTML(configFunctions.getConfigProperty('aliases.lots'))} + Related ${escapeHTML(getConfigProperty('aliases.lots'))}

` - for (const lot of milestone.workOrderLots!) { + for (const lot of milestone.workOrderLots ?? []) { descriptionHTML += `
- ${escapeHTML(configFunctions.getConfigProperty('aliases.lot'))} Type + ${escapeHTML(getConfigProperty('aliases.lot'))} Type - ${escapeHTML(configFunctions.getConfigProperty('aliases.map'))} + ${escapeHTML(getConfigProperty('aliases.map'))} - ${escapeHTML(configFunctions.getConfigProperty('aliases.lot'))} Type + ${escapeHTML(getConfigProperty('aliases.lot'))} Type Status
@@ -194,7 +190,7 @@ function buildEventDescriptionHTML_prints( ): string { let descriptionHTML = '' - const prints = configFunctions.getConfigProperty('settings.workOrders.prints') + const prints = getConfigProperty('settings.workOrders.prints') if (prints.length > 0) { const urlRoot = getUrlRoot(request) @@ -256,7 +252,7 @@ function buildEventLocation(milestone: WorkOrderMilestone): string { const lotNames: string[] = [] if (milestone.workOrderLots!.length > 0) { - for (const lot of milestone.workOrderLots!) { + for (const lot of milestone.workOrderLots ?? []) { lotNames.push(`${lot.mapName ?? ''}: ${lot.lotName ?? ''}`) } } @@ -388,14 +384,14 @@ export default async function handler( // Set organizer / attendees if (milestone.workOrderLotOccupancies!.length > 0) { let organizerSet = false - for (const lotOccupancy of milestone.workOrderLotOccupancies!) { - for (const occupant of lotOccupancy.lotOccupancyOccupants!) { + for (const lotOccupancy of milestone.workOrderLotOccupancies ?? []) { + for (const occupant of lotOccupancy.lotOccupancyOccupants ?? []) { if (organizerSet) { calendarEvent.createAttendee({ name: `${occupant.occupantName ?? ''} ${ occupant.occupantFamilyName ?? '' }`, - email: configFunctions.getConfigProperty( + email: getConfigProperty( 'settings.workOrders.calendarEmailAddress' ) }) @@ -404,7 +400,7 @@ export default async function handler( name: `${occupant.occupantName ?? ''} ${ occupant.occupantFamilyName ?? '' }`, - email: configFunctions.getConfigProperty( + email: getConfigProperty( 'settings.workOrders.calendarEmailAddress' ) }) @@ -415,13 +411,10 @@ export default async function handler( } else { calendarEvent.organizer({ name: milestone.recordCreate_userName!, - email: configFunctions.getConfigProperty( - 'settings.workOrders.calendarEmailAddress' - ) + email: getConfigProperty('settings.workOrders.calendarEmailAddress') }) } } calendar.serve(response) } - diff --git a/handlers/lotOccupancies-get/edit.js b/handlers/lotOccupancies-get/edit.js index 8f5876e2..f16183b9 100644 --- a/handlers/lotOccupancies-get/edit.js +++ b/handlers/lotOccupancies-get/edit.js @@ -1,11 +1,11 @@ import { getLotOccupancy } from '../../database/getLotOccupancy.js'; import { getMaps } from '../../database/getMaps.js'; import { getLotOccupantTypes, getLotStatuses, getLotTypes, getOccupancyTypePrintsById, getOccupancyTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId); if (lotOccupancy === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=lotOccupancyIdNotFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=lotOccupancyIdNotFound`); return; } const occupancyTypePrints = await getOccupancyTypePrintsById(lotOccupancy.occupancyTypeId); @@ -16,7 +16,7 @@ export default async function handler(request, response) { const maps = await getMaps(); const workOrderTypes = await getWorkOrderTypes(); response.render('lotOccupancy-edit', { - headTitle: `${configFunctions.getConfigProperty('aliases.occupancy')} Update`, + headTitle: `${getConfigProperty('aliases.occupancy')} Update`, lotOccupancy, occupancyTypePrints, occupancyTypes, diff --git a/handlers/lotOccupancies-get/edit.ts b/handlers/lotOccupancies-get/edit.ts index b29d8bd5..f3e1796f 100644 --- a/handlers/lotOccupancies-get/edit.ts +++ b/handlers/lotOccupancies-get/edit.ts @@ -10,14 +10,17 @@ import { getOccupancyTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' -export default async function handler(request: Request, response: Response): Promise { +export default async function handler( + request: Request, + response: Response +): Promise { const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId) if (lotOccupancy === undefined) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/lotOccupancies/?error=lotOccupancyIdNotFound` ) @@ -36,7 +39,7 @@ export default async function handler(request: Request, response: Response): Pro const workOrderTypes = await getWorkOrderTypes() response.render('lotOccupancy-edit', { - headTitle: `${configFunctions.getConfigProperty('aliases.occupancy')} Update`, + headTitle: `${getConfigProperty('aliases.occupancy')} Update`, lotOccupancy, occupancyTypePrints, @@ -50,4 +53,3 @@ export default async function handler(request: Request, response: Response): Pro isCreate: false }) } - diff --git a/handlers/lotOccupancies-get/new.js b/handlers/lotOccupancies-get/new.js index 925d5073..794e82c8 100644 --- a/handlers/lotOccupancies-get/new.js +++ b/handlers/lotOccupancies-get/new.js @@ -2,7 +2,7 @@ import { dateToInteger, dateToString } from '@cityssm/utils-datetime'; import { getLot } from '../../database/getLot.js'; import { getMaps } from '../../database/getMaps.js'; import { getLotOccupantTypes, getLotStatuses, getLotTypes, getOccupancyTypes } from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const startDate = new Date(); const lotOccupancy = { @@ -24,7 +24,7 @@ export default async function handler(request, response) { const lotStatuses = await getLotStatuses(); const maps = await getMaps(); response.render('lotOccupancy-edit', { - headTitle: `Create a New ${configFunctions.getConfigProperty('aliases.occupancy')} Record`, + headTitle: `Create a New ${getConfigProperty('aliases.occupancy')} Record`, lotOccupancy, occupancyTypes, lotOccupantTypes, diff --git a/handlers/lotOccupancies-get/new.ts b/handlers/lotOccupancies-get/new.ts index 4ce649a0..40aa7e6f 100644 --- a/handlers/lotOccupancies-get/new.ts +++ b/handlers/lotOccupancies-get/new.ts @@ -1,7 +1,4 @@ -import { - dateToInteger, - dateToString -} from '@cityssm/utils-datetime' +import { dateToInteger, dateToString } from '@cityssm/utils-datetime' import type { Request, Response } from 'express' import { getLot } from '../../database/getLot.js' @@ -12,7 +9,7 @@ import { getLotTypes, getOccupancyTypes } from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import type { LotOccupancy } from '../../types/recordTypes.js' export default async function handler( @@ -44,9 +41,7 @@ export default async function handler( const maps = await getMaps() response.render('lotOccupancy-edit', { - headTitle: `Create a New ${configFunctions.getConfigProperty( - 'aliases.occupancy' - )} Record`, + headTitle: `Create a New ${getConfigProperty('aliases.occupancy')} Record`, lotOccupancy, occupancyTypes, @@ -58,4 +53,3 @@ export default async function handler( isCreate: true }) } - diff --git a/handlers/lotOccupancies-get/search.js b/handlers/lotOccupancies-get/search.js index c05c6156..a453eb44 100644 --- a/handlers/lotOccupancies-get/search.js +++ b/handlers/lotOccupancies-get/search.js @@ -1,12 +1,12 @@ import { getMaps } from '../../database/getMaps.js'; import { getLotTypes, getOccupancyTypes } from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const maps = await getMaps(); const lotTypes = await getLotTypes(); const occupancyTypes = await getOccupancyTypes(); response.render('lotOccupancy-search', { - headTitle: `${configFunctions.getConfigProperty('aliases.occupancy')} Search`, + headTitle: `${getConfigProperty('aliases.occupancy')} Search`, maps, lotTypes, occupancyTypes, diff --git a/handlers/lotOccupancies-get/search.ts b/handlers/lotOccupancies-get/search.ts index 81987a28..f1b7615d 100644 --- a/handlers/lotOccupancies-get/search.ts +++ b/handlers/lotOccupancies-get/search.ts @@ -5,7 +5,7 @@ import { getLotTypes, getOccupancyTypes } from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( request: Request, @@ -16,11 +16,10 @@ export default async function handler( const occupancyTypes = await getOccupancyTypes() response.render('lotOccupancy-search', { - headTitle: `${configFunctions.getConfigProperty('aliases.occupancy')} Search`, + headTitle: `${getConfigProperty('aliases.occupancy')} Search`, maps, lotTypes, occupancyTypes, mapId: request.query.mapId }) } - diff --git a/handlers/lotOccupancies-get/view.js b/handlers/lotOccupancies-get/view.js index fc36b7ba..146c4369 100644 --- a/handlers/lotOccupancies-get/view.js +++ b/handlers/lotOccupancies-get/view.js @@ -1,15 +1,15 @@ import { getLotOccupancy } from '../../database/getLotOccupancy.js'; import { getOccupancyTypePrintsById } from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const lotOccupancy = await getLotOccupancy(request.params.lotOccupancyId); if (lotOccupancy === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=lotOccupancyIdNotFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lotOccupancies/?error=lotOccupancyIdNotFound`); return; } const occupancyTypePrints = await getOccupancyTypePrintsById(lotOccupancy.occupancyTypeId); response.render('lotOccupancy-view', { - headTitle: `${configFunctions.getConfigProperty('aliases.occupancy')} View`, + headTitle: `${getConfigProperty('aliases.occupancy')} View`, lotOccupancy, occupancyTypePrints }); diff --git a/handlers/lotOccupancies-get/view.ts b/handlers/lotOccupancies-get/view.ts index 37275127..45622ac9 100644 --- a/handlers/lotOccupancies-get/view.ts +++ b/handlers/lotOccupancies-get/view.ts @@ -2,7 +2,7 @@ import type { Request, Response } from 'express' import { getLotOccupancy } from '../../database/getLotOccupancy.js' import { getOccupancyTypePrintsById } from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( request: Request, @@ -12,7 +12,7 @@ export default async function handler( if (lotOccupancy === undefined) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/lotOccupancies/?error=lotOccupancyIdNotFound` ) @@ -24,9 +24,8 @@ export default async function handler( ) response.render('lotOccupancy-view', { - headTitle: `${configFunctions.getConfigProperty('aliases.occupancy')} View`, + headTitle: `${getConfigProperty('aliases.occupancy')} View`, lotOccupancy, occupancyTypePrints }) } - diff --git a/handlers/lots-get/edit.js b/handlers/lots-get/edit.js index 7a57621a..f10779b4 100644 --- a/handlers/lots-get/edit.js +++ b/handlers/lots-get/edit.js @@ -1,17 +1,16 @@ import { getLot } from '../../database/getLot.js'; import { getMaps } from '../../database/getMaps.js'; -import * as cacheFunctions from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const lot = await getLot(request.params.lotId); if (lot === undefined) { - response.redirect(configFunctions.getConfigProperty('reverseProxy.urlPrefix') + - '/lots/?error=lotIdNotFound'); + response.redirect(getConfigProperty('reverseProxy.urlPrefix') + '/lots/?error=lotIdNotFound'); return; } const maps = await getMaps(); - const lotTypes = await cacheFunctions.getLotTypes(); - const lotStatuses = await cacheFunctions.getLotStatuses(); + const lotTypes = await getLotTypes(); + const lotStatuses = await getLotStatuses(); response.render('lot-edit', { headTitle: lot.lotName, lot, diff --git a/handlers/lots-get/edit.ts b/handlers/lots-get/edit.ts index 20ce67cb..5c821595 100644 --- a/handlers/lots-get/edit.ts +++ b/handlers/lots-get/edit.ts @@ -2,8 +2,8 @@ import type { Request, Response } from 'express' import { getLot } from '../../database/getLot.js' import { getMaps } from '../../database/getMaps.js' -import * as cacheFunctions from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( request: Request, @@ -13,15 +13,14 @@ export default async function handler( if (lot === undefined) { response.redirect( - configFunctions.getConfigProperty('reverseProxy.urlPrefix') + - '/lots/?error=lotIdNotFound' + getConfigProperty('reverseProxy.urlPrefix') + '/lots/?error=lotIdNotFound' ) return } const maps = await getMaps() - const lotTypes = await cacheFunctions.getLotTypes() - const lotStatuses = await cacheFunctions.getLotStatuses() + const lotTypes = await getLotTypes() + const lotStatuses = await getLotStatuses() response.render('lot-edit', { headTitle: lot.lotName, @@ -32,4 +31,3 @@ export default async function handler( lotStatuses }) } - diff --git a/handlers/lots-get/new.js b/handlers/lots-get/new.js index c1a8d505..42a1bdb2 100644 --- a/handlers/lots-get/new.js +++ b/handlers/lots-get/new.js @@ -1,6 +1,6 @@ import { getMaps } from '../../database/getMaps.js'; -import * as cacheFunctions from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const lot = { lotId: -1, @@ -17,10 +17,10 @@ export default async function handler(request, response) { lot.mapName = map.mapName; } } - const lotTypes = await cacheFunctions.getLotTypes(); - const lotStatuses = await cacheFunctions.getLotStatuses(); + const lotTypes = await getLotTypes(); + const lotStatuses = await getLotStatuses(); response.render('lot-edit', { - headTitle: `Create a New ${configFunctions.getConfigProperty('aliases.lot')}`, + headTitle: `Create a New ${getConfigProperty('aliases.lot')}`, lot, isCreate: true, maps, diff --git a/handlers/lots-get/new.ts b/handlers/lots-get/new.ts index 3e84cfef..bfb7e2e1 100644 --- a/handlers/lots-get/new.ts +++ b/handlers/lots-get/new.ts @@ -1,8 +1,8 @@ import type { Request, Response } from 'express' import { getMaps } from '../../database/getMaps.js' -import * as cacheFunctions from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import type { Lot } from '../../types/recordTypes.js' export default async function handler( @@ -29,11 +29,11 @@ export default async function handler( } } - const lotTypes = await cacheFunctions.getLotTypes() - const lotStatuses = await cacheFunctions.getLotStatuses() + const lotTypes = await getLotTypes() + const lotStatuses = await getLotStatuses() response.render('lot-edit', { - headTitle: `Create a New ${configFunctions.getConfigProperty('aliases.lot')}`, + headTitle: `Create a New ${getConfigProperty('aliases.lot')}`, lot, isCreate: true, maps, @@ -41,4 +41,3 @@ export default async function handler( lotStatuses }) } - diff --git a/handlers/lots-get/next.js b/handlers/lots-get/next.js index 58123557..821aec81 100644 --- a/handlers/lots-get/next.js +++ b/handlers/lots-get/next.js @@ -1,11 +1,11 @@ -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; import { getNextLotId } from '../../helpers/functions.lots.js'; export default async function handler(request, response) { const lotId = Number.parseInt(request.params.lotId, 10); const nextLotId = await getNextLotId(lotId); if (nextLotId === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/lots/?error=noNextLotIdFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lots/?error=noNextLotIdFound`); return; } - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/lots/${nextLotId.toString()}`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lots/${nextLotId.toString()}`); } diff --git a/handlers/lots-get/next.ts b/handlers/lots-get/next.ts index ba8e4343..555c8f25 100644 --- a/handlers/lots-get/next.ts +++ b/handlers/lots-get/next.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import { getNextLotId } from '../../helpers/functions.lots.js' export default async function handler( @@ -13,7 +13,7 @@ export default async function handler( if (nextLotId === undefined) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/lots/?error=noNextLotIdFound` ) @@ -21,9 +21,8 @@ export default async function handler( } response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/lots/${nextLotId.toString()}` ) } - diff --git a/handlers/lots-get/previous.js b/handlers/lots-get/previous.js index 54dbcbfd..01b95241 100644 --- a/handlers/lots-get/previous.js +++ b/handlers/lots-get/previous.js @@ -1,11 +1,11 @@ -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; import { getPreviousLotId } from '../../helpers/functions.lots.js'; export default async function handler(request, response) { const lotId = Number.parseInt(request.params.lotId, 10); const previousLotId = await getPreviousLotId(lotId); if (previousLotId === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/lots/?error=noPreviousLotIdFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lots/?error=noPreviousLotIdFound`); return; } - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/lots/${previousLotId.toString()}`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lots/${previousLotId.toString()}`); } diff --git a/handlers/lots-get/previous.ts b/handlers/lots-get/previous.ts index 18432ade..79cd0f47 100644 --- a/handlers/lots-get/previous.ts +++ b/handlers/lots-get/previous.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import { getPreviousLotId } from '../../helpers/functions.lots.js' export default async function handler( @@ -13,7 +13,7 @@ export default async function handler( if (previousLotId === undefined) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/lots/?error=noPreviousLotIdFound` ) @@ -21,9 +21,8 @@ export default async function handler( } response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/lots/${previousLotId.toString()}` ) } - diff --git a/handlers/lots-get/search.js b/handlers/lots-get/search.js index e6fa985e..520be19e 100644 --- a/handlers/lots-get/search.js +++ b/handlers/lots-get/search.js @@ -1,12 +1,12 @@ import { getMaps } from '../../database/getMaps.js'; -import { getLotTypes, getLotStatuses } from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const maps = await getMaps(); const lotTypes = await getLotTypes(); const lotStatuses = await getLotStatuses(); response.render('lot-search', { - headTitle: `${configFunctions.getConfigProperty('aliases.lot')} Search`, + headTitle: `${getConfigProperty('aliases.lot')} Search`, maps, lotTypes, lotStatuses, diff --git a/handlers/lots-get/search.ts b/handlers/lots-get/search.ts index f75a8224..a5a76fb6 100644 --- a/handlers/lots-get/search.ts +++ b/handlers/lots-get/search.ts @@ -1,8 +1,8 @@ import type { Request, Response } from 'express' import { getMaps } from '../../database/getMaps.js' -import { getLotTypes, getLotStatuses } from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( request: Request, @@ -13,7 +13,7 @@ export default async function handler( const lotStatuses = await getLotStatuses() response.render('lot-search', { - headTitle: `${configFunctions.getConfigProperty('aliases.lot')} Search`, + headTitle: `${getConfigProperty('aliases.lot')} Search`, maps, lotTypes, lotStatuses, @@ -22,4 +22,3 @@ export default async function handler( lotStatusId: request.query.lotStatusId }) } - diff --git a/handlers/lots-get/view.js b/handlers/lots-get/view.js index c72b618a..f84a7e08 100644 --- a/handlers/lots-get/view.js +++ b/handlers/lots-get/view.js @@ -1,11 +1,10 @@ import { getLot } from '../../database/getLot.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; import { getNextLotId, getPreviousLotId } from '../../helpers/functions.lots.js'; export default async function handler(request, response) { const lot = await getLot(request.params.lotId); if (lot === undefined) { - response.redirect(configFunctions.getConfigProperty('reverseProxy.urlPrefix') + - '/lots/?error=lotIdNotFound'); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lots/?error=lotIdNotFound`); return; } response.render('lot-view', { diff --git a/handlers/lots-get/view.ts b/handlers/lots-get/view.ts index b983a46b..f50cdc1e 100644 --- a/handlers/lots-get/view.ts +++ b/handlers/lots-get/view.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' import { getLot } from '../../database/getLot.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import { getNextLotId, getPreviousLotId } from '../../helpers/functions.lots.js' export default async function handler( @@ -12,8 +12,7 @@ export default async function handler( if (lot === undefined) { response.redirect( - configFunctions.getConfigProperty('reverseProxy.urlPrefix') + - '/lots/?error=lotIdNotFound' + `${getConfigProperty('reverseProxy.urlPrefix')}/lots/?error=lotIdNotFound` ) return } @@ -28,4 +27,3 @@ export default async function handler( void getPreviousLotId(lot.lotId) }) } - diff --git a/handlers/maps-get/edit.js b/handlers/maps-get/edit.js index 002bd1b8..b79a8018 100644 --- a/handlers/maps-get/edit.js +++ b/handlers/maps-get/edit.js @@ -1,12 +1,12 @@ import { getLotStatusSummary } from '../../database/getLotStatusSummary.js'; import { getLotTypeSummary } from '../../database/getLotTypeSummary.js'; import { getMap } from '../../database/getMap.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; import { getMapSVGs } from '../../helpers/functions.map.js'; export default async function handler(request, response) { const map = await getMap(request.params.mapId); if (map === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound`); return; } const mapSVGs = await getMapSVGs(); diff --git a/handlers/maps-get/edit.ts b/handlers/maps-get/edit.ts index 2ef33cd2..6c03acab 100644 --- a/handlers/maps-get/edit.ts +++ b/handlers/maps-get/edit.ts @@ -3,7 +3,7 @@ import type { Request, Response } from 'express' import { getLotStatusSummary } from '../../database/getLotStatusSummary.js' import { getLotTypeSummary } from '../../database/getLotTypeSummary.js' import { getMap } from '../../database/getMap.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import { getMapSVGs } from '../../helpers/functions.map.js' export default async function handler( @@ -14,9 +14,7 @@ export default async function handler( if (map === undefined) { response.redirect( - `${configFunctions.getConfigProperty( - 'reverseProxy.urlPrefix' - )}/maps/?error=mapIdNotFound` + `${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound` ) return } @@ -40,4 +38,3 @@ export default async function handler( lotStatusSummary }) } - diff --git a/handlers/maps-get/new.js b/handlers/maps-get/new.js index 79376a23..eb3d7ea3 100644 --- a/handlers/maps-get/new.js +++ b/handlers/maps-get/new.js @@ -1,13 +1,13 @@ -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; import { getMapSVGs } from '../../helpers/functions.map.js'; export default async function handler(_request, response) { const map = { - mapCity: configFunctions.getConfigProperty('settings.map.mapCityDefault'), - mapProvince: configFunctions.getConfigProperty('settings.map.mapProvinceDefault') + mapCity: getConfigProperty('settings.map.mapCityDefault'), + mapProvince: getConfigProperty('settings.map.mapProvinceDefault') }; const mapSVGs = await getMapSVGs(); response.render('map-edit', { - headTitle: `${configFunctions.getConfigProperty('aliases.map')} Create`, + headTitle: `${getConfigProperty('aliases.map')} Create`, isCreate: true, map, mapSVGs diff --git a/handlers/maps-get/new.ts b/handlers/maps-get/new.ts index fc4f608a..691fa3a9 100644 --- a/handlers/maps-get/new.ts +++ b/handlers/maps-get/new.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import { getMapSVGs } from '../../helpers/functions.map.js' import type { MapRecord } from '../../types/recordTypes.js' @@ -9,17 +9,16 @@ export default async function handler( response: Response ): Promise { const map: MapRecord = { - mapCity: configFunctions.getConfigProperty('settings.map.mapCityDefault'), - mapProvince: configFunctions.getConfigProperty('settings.map.mapProvinceDefault') + mapCity: getConfigProperty('settings.map.mapCityDefault'), + mapProvince: getConfigProperty('settings.map.mapProvinceDefault') } const mapSVGs = await getMapSVGs() response.render('map-edit', { - headTitle: `${configFunctions.getConfigProperty('aliases.map')} Create`, + headTitle: `${getConfigProperty('aliases.map')} Create`, isCreate: true, map, mapSVGs }) } - diff --git a/handlers/maps-get/next.js b/handlers/maps-get/next.js index 5f82aedb..7484da0a 100644 --- a/handlers/maps-get/next.js +++ b/handlers/maps-get/next.js @@ -1,11 +1,11 @@ import { getNextMapId } from '../../database/getNextMapId.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const mapId = Number.parseInt(request.params.mapId, 10); const nextMapId = await getNextMapId(mapId); if (nextMapId === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=noNextMapIdFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=noNextMapIdFound`); return; } - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/maps/${nextMapId.toString()}`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/${nextMapId.toString()}`); } diff --git a/handlers/maps-get/next.ts b/handlers/maps-get/next.ts index 115b801b..062f9375 100644 --- a/handlers/maps-get/next.ts +++ b/handlers/maps-get/next.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' import { getNextMapId } from '../../database/getNextMapId.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( request: Request, @@ -13,7 +13,7 @@ export default async function handler( if (nextMapId === undefined) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/maps/?error=noNextMapIdFound` ) @@ -21,9 +21,8 @@ export default async function handler( } response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/maps/${nextMapId.toString()}` ) } - diff --git a/handlers/maps-get/previous.js b/handlers/maps-get/previous.js index b2b34287..5a3a3ac7 100644 --- a/handlers/maps-get/previous.js +++ b/handlers/maps-get/previous.js @@ -1,11 +1,11 @@ import { getPreviousMapId } from '../../database/getPreviousMapId.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const mapId = Number.parseInt(request.params.mapId, 10); const previousMapId = await getPreviousMapId(mapId); if (previousMapId === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=noPreviousMapIdFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=noPreviousMapIdFound`); return; } - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/maps/${previousMapId.toString()}`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/${previousMapId.toString()}`); } diff --git a/handlers/maps-get/previous.ts b/handlers/maps-get/previous.ts index 685536ee..3d4a559e 100644 --- a/handlers/maps-get/previous.ts +++ b/handlers/maps-get/previous.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' import { getPreviousMapId } from '../../database/getPreviousMapId.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( request: Request, @@ -13,7 +13,7 @@ export default async function handler( if (previousMapId === undefined) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/maps/?error=noPreviousMapIdFound` ) @@ -21,9 +21,8 @@ export default async function handler( } response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/maps/${previousMapId.toString()}` ) } - diff --git a/handlers/maps-get/search.js b/handlers/maps-get/search.js index d9988859..be4e3dfb 100644 --- a/handlers/maps-get/search.js +++ b/handlers/maps-get/search.js @@ -1,9 +1,9 @@ import { getMaps } from '../../database/getMaps.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(_request, response) { const maps = await getMaps(); response.render('map-search', { - headTitle: `${configFunctions.getConfigProperty('aliases.map')} Search`, + headTitle: `${getConfigProperty('aliases.map')} Search`, maps }); } diff --git a/handlers/maps-get/search.ts b/handlers/maps-get/search.ts index 4399dfb2..d35b2f22 100644 --- a/handlers/maps-get/search.ts +++ b/handlers/maps-get/search.ts @@ -1,14 +1,16 @@ import type { Request, Response } from 'express' import { getMaps } from '../../database/getMaps.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' -export default async function handler(_request: Request, response: Response): Promise { +export default async function handler( + _request: Request, + response: Response +): Promise { const maps = await getMaps() response.render('map-search', { - headTitle: `${configFunctions.getConfigProperty('aliases.map')} Search`, + headTitle: `${getConfigProperty('aliases.map')} Search`, maps }) } - diff --git a/handlers/maps-get/view.js b/handlers/maps-get/view.js index fc580fd3..4bb512dc 100644 --- a/handlers/maps-get/view.js +++ b/handlers/maps-get/view.js @@ -1,11 +1,11 @@ import { getLotStatusSummary } from '../../database/getLotStatusSummary.js'; import { getLotTypeSummary } from '../../database/getLotTypeSummary.js'; import { getMap } from '../../database/getMap.js'; -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const map = await getMap(request.params.mapId); if (map === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound`); return; } const lotTypeSummary = await getLotTypeSummary({ diff --git a/handlers/maps-get/view.ts b/handlers/maps-get/view.ts index 480ba53c..ded27b30 100644 --- a/handlers/maps-get/view.ts +++ b/handlers/maps-get/view.ts @@ -3,7 +3,7 @@ import type { Request, Response } from 'express' import { getLotStatusSummary } from '../../database/getLotStatusSummary.js' import { getLotTypeSummary } from '../../database/getLotTypeSummary.js' import { getMap } from '../../database/getMap.js' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( request: Request, @@ -13,7 +13,7 @@ export default async function handler( if (map === undefined) { response.redirect( - `${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound` + `${getConfigProperty('reverseProxy.urlPrefix')}/maps/?error=mapIdNotFound` ) return } @@ -33,4 +33,3 @@ export default async function handler( lotStatusSummary }) } - diff --git a/handlers/print-get/pdf.d.ts b/handlers/print-get/pdf.d.ts index beba9398..57b7a29b 100644 --- a/handlers/print-get/pdf.d.ts +++ b/handlers/print-get/pdf.d.ts @@ -1,3 +1,4 @@ /// import type { NextFunction, Request, Response } from 'express'; -export default function handler(request: Request, response: Response, next: NextFunction): Promise; +export declare function handler(request: Request, response: Response, next: NextFunction): Promise; +export default handler; diff --git a/handlers/print-get/pdf.js b/handlers/print-get/pdf.js index 3ed04500..c89f1e56 100644 --- a/handlers/print-get/pdf.js +++ b/handlers/print-get/pdf.js @@ -7,7 +7,7 @@ import * as configFunctions from '../../helpers/functions.config.js'; import * as lotOccupancyFunctions from '../../helpers/functions.lotOccupancy.js'; import { getPdfPrintConfig, getReportData } from '../../helpers/functions.print.js'; const attachmentOrInline = configFunctions.getConfigProperty('settings.printPdf.contentDisposition'); -export default async function handler(request, response, next) { +export async function handler(request, response, next) { const printName = request.params.printName; if (!configFunctions .getConfigProperty('settings.lotOccupancy.prints') @@ -48,3 +48,4 @@ export default async function handler(request, response, next) { reportData.lotOccupancyFunctions = lotOccupancyFunctions; await ejs.renderFile(reportPath, reportData, {}, ejsCallbackFunction); } +export default handler; diff --git a/handlers/print-get/pdf.ts b/handlers/print-get/pdf.ts index 8adb2541..92720f4a 100644 --- a/handlers/print-get/pdf.ts +++ b/handlers/print-get/pdf.ts @@ -17,7 +17,7 @@ const attachmentOrInline = configFunctions.getConfigProperty( 'settings.printPdf.contentDisposition' ) -export default async function handler( +export async function handler( request: Request, response: Response, next: NextFunction @@ -90,3 +90,4 @@ export default async function handler( await ejs.renderFile(reportPath, reportData, {}, ejsCallbackFunction) } +export default handler diff --git a/handlers/print-get/screen.js b/handlers/print-get/screen.js index 8cd00bf7..b22c592a 100644 --- a/handlers/print-get/screen.js +++ b/handlers/print-get/screen.js @@ -1,19 +1,15 @@ -import * as configFunctions from '../../helpers/functions.config.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; import { getReportData, getScreenPrintConfig } from '../../helpers/functions.print.js'; export default async function handler(request, response) { const printName = request.params.printName; - if (!configFunctions - .getConfigProperty('settings.lotOccupancy.prints') - .includes(`screen/${printName}`) && - !configFunctions - .getConfigProperty('settings.workOrders.prints') - .includes(`screen/${printName}`)) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotAllowed`); + if (!getConfigProperty('settings.lotOccupancy.prints').includes(`screen/${printName}`) && + !getConfigProperty('settings.workOrders.prints').includes(`screen/${printName}`)) { + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotAllowed`); return; } const printConfig = getScreenPrintConfig(printName); if (printConfig === undefined) { - response.redirect(configFunctions.getConfigProperty('reverseProxy.urlPrefix') + + response.redirect(getConfigProperty('reverseProxy.urlPrefix') + '/dashboard/?error=printConfigNotFound'); return; } diff --git a/handlers/print-get/screen.ts b/handlers/print-get/screen.ts index 77311dcb..482b8752 100644 --- a/handlers/print-get/screen.ts +++ b/handlers/print-get/screen.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express' -import * as configFunctions from '../../helpers/functions.config.js' +import { getConfigProperty } from '../../helpers/functions.config.js' import { getReportData, getScreenPrintConfig @@ -13,15 +13,15 @@ export default async function handler( const printName = request.params.printName if ( - !configFunctions - .getConfigProperty('settings.lotOccupancy.prints') - .includes(`screen/${printName}`) && - !configFunctions - .getConfigProperty('settings.workOrders.prints') - .includes(`screen/${printName}`) + !getConfigProperty('settings.lotOccupancy.prints').includes( + `screen/${printName}` + ) && + !getConfigProperty('settings.workOrders.prints').includes( + `screen/${printName}` + ) ) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/dashboard/?error=printConfigNotAllowed` ) @@ -32,7 +32,7 @@ export default async function handler( if (printConfig === undefined) { response.redirect( - configFunctions.getConfigProperty('reverseProxy.urlPrefix') + + getConfigProperty('reverseProxy.urlPrefix') + '/dashboard/?error=printConfigNotFound' ) return @@ -42,4 +42,3 @@ export default async function handler( response.render(`print/screen/${printName}`, reportData) } - diff --git a/handlers/workOrders-get/edit.js b/handlers/workOrders-get/edit.js index b14a87dc..4679b61b 100644 --- a/handlers/workOrders-get/edit.js +++ b/handlers/workOrders-get/edit.js @@ -1,6 +1,6 @@ -import { getLotStatuses, getWorkOrderMilestoneTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; -import * as configFunctions from '../../helpers/functions.config.js'; import { getWorkOrder } from '../../database/getWorkOrder.js'; +import { getLotStatuses, getWorkOrderMilestoneTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const workOrder = await getWorkOrder(request.params.workOrderId, { includeLotsAndLotOccupancies: true, @@ -8,11 +8,11 @@ export default async function handler(request, response) { includeMilestones: true }); if (workOrder === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/workOrders/?error=workOrderIdNotFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/workOrders/?error=workOrderIdNotFound`); return; } if (workOrder.workOrderCloseDate) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/workOrders/${workOrder.workOrderId.toString()}/?error=workOrderIsClosed`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/workOrders/${workOrder.workOrderId.toString()}/?error=workOrderIsClosed`); return; } const workOrderTypes = await getWorkOrderTypes(); diff --git a/handlers/workOrders-get/edit.ts b/handlers/workOrders-get/edit.ts index c1192da9..d11b5379 100644 --- a/handlers/workOrders-get/edit.ts +++ b/handlers/workOrders-get/edit.ts @@ -1,12 +1,12 @@ import type { Request, Response } from 'express' +import { getWorkOrder } from '../../database/getWorkOrder.js' import { getLotStatuses, getWorkOrderMilestoneTypes, getWorkOrderTypes } from '../../helpers/functions.cache.js' -import * as configFunctions from '../../helpers/functions.config.js' -import { getWorkOrder } from '../../database/getWorkOrder.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( request: Request, @@ -20,7 +20,7 @@ export default async function handler( if (workOrder === undefined) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/workOrders/?error=workOrderIdNotFound` ) @@ -29,9 +29,9 @@ export default async function handler( if (workOrder.workOrderCloseDate) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' - )}/workOrders/${workOrder.workOrderId!.toString()}/?error=workOrderIsClosed` + )}/workOrders/${workOrder.workOrderId.toString()}/?error=workOrderIsClosed` ) return } @@ -43,7 +43,7 @@ export default async function handler( const lotStatuses = await getLotStatuses() response.render('workOrder-edit', { - headTitle: `Work Order #${workOrder.workOrderNumber!}`, + headTitle: `Work Order #${workOrder.workOrderNumber}`, workOrder, isCreate: false, workOrderTypes, @@ -51,4 +51,3 @@ export default async function handler( lotStatuses }) } - diff --git a/handlers/workOrders-get/view.js b/handlers/workOrders-get/view.js index bb1ea9e4..aa6862f0 100644 --- a/handlers/workOrders-get/view.js +++ b/handlers/workOrders-get/view.js @@ -1,5 +1,5 @@ -import * as configFunctions from '../../helpers/functions.config.js'; import { getWorkOrder } from '../../database/getWorkOrder.js'; +import { getConfigProperty } from '../../helpers/functions.config.js'; export default async function handler(request, response) { const workOrder = await getWorkOrder(request.params.workOrderId, { includeLotsAndLotOccupancies: true, @@ -7,7 +7,7 @@ export default async function handler(request, response) { includeMilestones: true }); if (workOrder === undefined) { - response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/workOrders/?error=workOrderIdNotFound`); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/workOrders/?error=workOrderIdNotFound`); return; } response.render('workOrder-view', { diff --git a/handlers/workOrders-get/view.ts b/handlers/workOrders-get/view.ts index 083d860c..3c83dba6 100644 --- a/handlers/workOrders-get/view.ts +++ b/handlers/workOrders-get/view.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express' -import * as configFunctions from '../../helpers/functions.config.js' import { getWorkOrder } from '../../database/getWorkOrder.js' +import { getConfigProperty } from '../../helpers/functions.config.js' export default async function handler( request: Request, @@ -15,7 +15,7 @@ export default async function handler( if (workOrder === undefined) { response.redirect( - `${configFunctions.getConfigProperty( + `${getConfigProperty( 'reverseProxy.urlPrefix' )}/workOrders/?error=workOrderIdNotFound` ) @@ -23,8 +23,7 @@ export default async function handler( } response.render('workOrder-view', { - headTitle: `Work Order #${workOrder.workOrderNumber!}`, + headTitle: `Work Order #${workOrder.workOrderNumber}`, workOrder }) } - diff --git a/helpers/functions.authentication.js b/helpers/functions.authentication.js index 3a04f484..6efb2207 100644 --- a/helpers/functions.authentication.js +++ b/helpers/functions.authentication.js @@ -1,7 +1,7 @@ import ActiveDirectory from 'activedirectory2'; -import * as configFunctions from './functions.config.js'; -const userDomain = configFunctions.getConfigProperty('application.userDomain'); -const activeDirectoryConfig = configFunctions.getConfigProperty('activeDirectory'); +import { getConfigProperty } from './functions.config.js'; +const userDomain = getConfigProperty('application.userDomain'); +const activeDirectoryConfig = getConfigProperty('activeDirectory'); async function authenticateViaActiveDirectory(userName, password) { return await new Promise((resolve) => { try { @@ -46,7 +46,7 @@ const safeRedirects = new Set([ const recordUrl = /^\/(?:maps|lots|lotoccupancies|workorders)\/\d+(?:\/edit)?$/; const printUrl = /^\/print\/(?:pdf|screen)\/[\d/=?A-Za-z-]+$/; export function getSafeRedirectURL(possibleRedirectURL = '') { - const urlPrefix = configFunctions.getConfigProperty('reverseProxy.urlPrefix'); + const urlPrefix = getConfigProperty('reverseProxy.urlPrefix'); if (typeof possibleRedirectURL === 'string') { const urlToCheck = possibleRedirectURL.startsWith(urlPrefix) ? possibleRedirectURL.slice(urlPrefix.length) diff --git a/helpers/functions.authentication.ts b/helpers/functions.authentication.ts index 26d729a0..a389afc9 100644 --- a/helpers/functions.authentication.ts +++ b/helpers/functions.authentication.ts @@ -1,11 +1,10 @@ import ActiveDirectory from 'activedirectory2' -import * as configFunctions from './functions.config.js' +import { getConfigProperty } from './functions.config.js' -const userDomain = configFunctions.getConfigProperty('application.userDomain') +const userDomain = getConfigProperty('application.userDomain') -const activeDirectoryConfig = - configFunctions.getConfigProperty('activeDirectory') +const activeDirectoryConfig = getConfigProperty('activeDirectory') async function authenticateViaActiveDirectory( userName: string, @@ -65,7 +64,7 @@ const recordUrl = /^\/(?:maps|lots|lotoccupancies|workorders)\/\d+(?:\/edit)?$/ const printUrl = /^\/print\/(?:pdf|screen)\/[\d/=?A-Za-z-]+$/ export function getSafeRedirectURL(possibleRedirectURL = ''): string { - const urlPrefix = configFunctions.getConfigProperty('reverseProxy.urlPrefix') + const urlPrefix = getConfigProperty('reverseProxy.urlPrefix') if (typeof possibleRedirectURL === 'string') { const urlToCheck = possibleRedirectURL.startsWith(urlPrefix) diff --git a/helpers/functions.cache.js b/helpers/functions.cache.js index 8c0172df..7092a73d 100644 --- a/helpers/functions.cache.js +++ b/helpers/functions.cache.js @@ -7,7 +7,7 @@ import { getOccupancyTypeFields as getOccupancyTypeFieldsFromDatabase } from '.. import { getOccupancyTypes as getOccupancyTypesFromDatabase } from '../database/getOccupancyTypes.js'; import { getWorkOrderMilestoneTypes as getWorkOrderMilestoneTypesFromDatabase } from '../database/getWorkOrderMilestoneTypes.js'; import { getWorkOrderTypes as getWorkOrderTypesFromDatabase } from '../database/getWorkOrderTypes.js'; -import * as configFunctions from './functions.config.js'; +import { getConfigProperty } from './functions.config.js'; const debug = Debug(`lot-occupancy-system:functions.cache:${process.pid}`); let lotOccupantTypes; export async function getLotOccupantTypes() { @@ -114,7 +114,7 @@ export async function getOccupancyTypePrintsById(occupancyTypeId) { return []; } if (occupancyType.occupancyTypePrints.includes('*')) { - return configFunctions.getConfigProperty('settings.lotOccupancy.prints'); + return getConfigProperty('settings.lotOccupancy.prints'); } return occupancyType.occupancyTypePrints ?? []; } diff --git a/helpers/functions.cache.ts b/helpers/functions.cache.ts index 47b9d16b..4b5ec499 100644 --- a/helpers/functions.cache.ts +++ b/helpers/functions.cache.ts @@ -12,7 +12,7 @@ import { getWorkOrderTypes as getWorkOrderTypesFromDatabase } from '../database/ import type { ClearCacheWorkerMessage } from '../types/applicationTypes.js' import type * as recordTypes from '../types/recordTypes.js' -import * as configFunctions from './functions.config.js' +import { getConfigProperty } from './functions.config.js' const debug = Debug(`lot-occupancy-system:functions.cache:${process.pid}`) @@ -205,7 +205,7 @@ export async function getOccupancyTypePrintsById( } if (occupancyType.occupancyTypePrints.includes('*')) { - return configFunctions.getConfigProperty('settings.lotOccupancy.prints') + return getConfigProperty('settings.lotOccupancy.prints') } return occupancyType.occupancyTypePrints ?? [] diff --git a/helpers/functions.dynamicsGP.js b/helpers/functions.dynamicsGP.js index 5d7c7384..1b9fdebb 100644 --- a/helpers/functions.dynamicsGP.js +++ b/helpers/functions.dynamicsGP.js @@ -1,11 +1,11 @@ import { DynamicsGP } from '@cityssm/dynamics-gp'; -import * as configFunctions from './functions.config.js'; +import { getConfigProperty } from './functions.config.js'; let gp; -if (configFunctions.getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { - gp = new DynamicsGP(configFunctions.getConfigProperty('settings.dynamicsGP.mssqlConfig')); +if (getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { + gp = new DynamicsGP(getConfigProperty('settings.dynamicsGP.mssqlConfig')); } function filterCashReceipt(cashReceipt) { - const accountCodes = configFunctions.getConfigProperty('settings.dynamicsGP.accountCodes'); + const accountCodes = getConfigProperty('settings.dynamicsGP.accountCodes'); if (accountCodes.length > 0) { for (const detail of cashReceipt.details) { if (accountCodes.includes(detail.accountCode)) { @@ -22,7 +22,7 @@ function filterCashReceipt(cashReceipt) { return cashReceipt; } function filterInvoice(invoice) { - const itemNumbers = configFunctions.getConfigProperty('settings.dynamicsGP.itemNumbers'); + const itemNumbers = getConfigProperty('settings.dynamicsGP.itemNumbers'); for (const itemNumber of itemNumbers) { const found = invoice.lineItems.some((itemRecord) => { return itemRecord.itemNumber === itemNumber; @@ -37,7 +37,7 @@ function filterExtendedInvoice(invoice) { if (filterInvoice(invoice) === undefined) { return undefined; } - const trialBalanceCodes = configFunctions.getConfigProperty('settings.dynamicsGP.trialBalanceCodes'); + const trialBalanceCodes = getConfigProperty('settings.dynamicsGP.trialBalanceCodes'); if (trialBalanceCodes.length > 0 && trialBalanceCodes.includes(invoice.trialBalanceCode ?? '')) { return invoice; @@ -115,11 +115,11 @@ async function _getDynamicsGPDocument(documentNumber, lookupType) { return document; } export async function getDynamicsGPDocument(documentNumber) { - if (!configFunctions.getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { + if (!getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { return undefined; } let document; - for (const lookupType of configFunctions.getConfigProperty('settings.dynamicsGP.lookupOrder')) { + for (const lookupType of getConfigProperty('settings.dynamicsGP.lookupOrder')) { document = await _getDynamicsGPDocument(documentNumber, lookupType); if (document !== undefined) { break; diff --git a/helpers/functions.dynamicsGP.ts b/helpers/functions.dynamicsGP.ts index d652da2e..a7bfba44 100644 --- a/helpers/functions.dynamicsGP.ts +++ b/helpers/functions.dynamicsGP.ts @@ -10,22 +10,18 @@ import { import type { DynamicsGPLookup } from '../types/configTypes.js' import type { DynamicsGPDocument } from '../types/recordTypes.js' -import * as configFunctions from './functions.config.js' +import { getConfigProperty } from './functions.config.js' let gp: DynamicsGP -if (configFunctions.getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { - gp = new DynamicsGP( - configFunctions.getConfigProperty('settings.dynamicsGP.mssqlConfig') - ) +if (getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { + gp = new DynamicsGP(getConfigProperty('settings.dynamicsGP.mssqlConfig')) } function filterCashReceipt( cashReceipt: DiamondCashReceipt ): DiamondCashReceipt | undefined { - const accountCodes = configFunctions.getConfigProperty( - 'settings.dynamicsGP.accountCodes' - ) + const accountCodes = getConfigProperty('settings.dynamicsGP.accountCodes') if (accountCodes.length > 0) { for (const detail of cashReceipt.details) { @@ -47,9 +43,7 @@ function filterCashReceipt( } function filterInvoice(invoice: GPInvoice): GPInvoice | undefined { - const itemNumbers = configFunctions.getConfigProperty( - 'settings.dynamicsGP.itemNumbers' - ) + const itemNumbers = getConfigProperty('settings.dynamicsGP.itemNumbers') for (const itemNumber of itemNumbers) { const found = invoice.lineItems.some((itemRecord) => { @@ -71,7 +65,7 @@ function filterExtendedInvoice( return undefined } - const trialBalanceCodes = configFunctions.getConfigProperty( + const trialBalanceCodes = getConfigProperty( 'settings.dynamicsGP.trialBalanceCodes' ) @@ -143,9 +137,8 @@ async function _getDynamicsGPDocument( break } case 'diamond/extendedInvoice': { - let invoice = await gp.getDiamondExtendedInvoiceByInvoiceNumber( - documentNumber - ) + let invoice = + await gp.getDiamondExtendedInvoiceByInvoiceNumber(documentNumber) if (invoice !== undefined) { invoice = filterExtendedInvoice(invoice) @@ -176,15 +169,13 @@ async function _getDynamicsGPDocument( export async function getDynamicsGPDocument( documentNumber: string ): Promise { - if ( - !configFunctions.getConfigProperty('settings.dynamicsGP.integrationIsEnabled') - ) { + if (!getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { return undefined } let document: DynamicsGPDocument | undefined - for (const lookupType of configFunctions.getConfigProperty( + for (const lookupType of getConfigProperty( 'settings.dynamicsGP.lookupOrder' )) { document = await _getDynamicsGPDocument(documentNumber, lookupType) diff --git a/routes/login.js b/routes/login.js index 29512464..7be26171 100644 --- a/routes/login.js +++ b/routes/login.js @@ -3,11 +3,11 @@ import { Router } from 'express'; import { useTestDatabases } from '../data/databasePaths.js'; import { getApiKey } from '../helpers/functions.api.js'; import * as authenticationFunctions from '../helpers/functions.authentication.js'; -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; const debug = Debug('lot-occupancy-system:login'); export const router = Router(); function getHandler(request, response) { - const sessionCookieName = configFunctions.getConfigProperty('session.cookieName'); + const sessionCookieName = getConfigProperty('session.cookieName'); if (request.session.user !== undefined && request.cookies[sessionCookieName] !== undefined) { const redirectURL = authenticationFunctions.getSafeRedirectURL((request.query.redirect ?? '')); @@ -30,9 +30,7 @@ async function postHandler(request, response) { let isAuthenticated = false; if (userName.startsWith('*')) { if (useTestDatabases && userName === passwordPlain) { - isAuthenticated = configFunctions - .getConfigProperty('users.testing') - .includes(userName); + isAuthenticated = getConfigProperty('users.testing').includes(userName); if (isAuthenticated) { debug('Authenticated testing user: ' + userName); } @@ -44,20 +42,14 @@ async function postHandler(request, response) { let userObject; if (isAuthenticated) { const userNameLowerCase = userName.toLowerCase(); - const canLogin = configFunctions - .getConfigProperty('users.canLogin') - .some((currentUserName) => { + const canLogin = getConfigProperty('users.canLogin').some((currentUserName) => { return userNameLowerCase === currentUserName.toLowerCase(); }); if (canLogin) { - const canUpdate = configFunctions - .getConfigProperty('users.canUpdate') - .some((currentUserName) => { + const canUpdate = getConfigProperty('users.canUpdate').some((currentUserName) => { return userNameLowerCase === currentUserName.toLowerCase(); }); - const isAdmin = configFunctions - .getConfigProperty('users.isAdmin') - .some((currentUserName) => { + const isAdmin = getConfigProperty('users.isAdmin').some((currentUserName) => { return userNameLowerCase === currentUserName.toLowerCase(); }); const apiKey = await getApiKey(userNameLowerCase); diff --git a/routes/login.ts b/routes/login.ts index 12dcf8b5..0380a259 100644 --- a/routes/login.ts +++ b/routes/login.ts @@ -1,22 +1,22 @@ import Debug from 'debug' import { - Router, - type RequestHandler, type Request, - type Response + type RequestHandler, + type Response, + Router } from 'express' import { useTestDatabases } from '../data/databasePaths.js' import { getApiKey } from '../helpers/functions.api.js' import * as authenticationFunctions from '../helpers/functions.authentication.js' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' const debug = Debug('lot-occupancy-system:login') export const router = Router() function getHandler(request: Request, response: Response): void { - const sessionCookieName = configFunctions.getConfigProperty('session.cookieName') + const sessionCookieName = getConfigProperty('session.cookieName') if ( request.session.user !== undefined && @@ -59,9 +59,7 @@ async function postHandler( if (userName.startsWith('*')) { if (useTestDatabases && userName === passwordPlain) { - isAuthenticated = configFunctions - .getConfigProperty('users.testing') - .includes(userName) + isAuthenticated = getConfigProperty('users.testing').includes(userName) if (isAuthenticated) { debug('Authenticated testing user: ' + userName) @@ -79,24 +77,24 @@ async function postHandler( if (isAuthenticated) { const userNameLowerCase = userName.toLowerCase() - const canLogin = configFunctions - .getConfigProperty('users.canLogin') - .some((currentUserName) => { + const canLogin = getConfigProperty('users.canLogin').some( + (currentUserName) => { return userNameLowerCase === currentUserName.toLowerCase() - }) + } + ) if (canLogin) { - const canUpdate = configFunctions - .getConfigProperty('users.canUpdate') - .some((currentUserName) => { + const canUpdate = getConfigProperty('users.canUpdate').some( + (currentUserName) => { return userNameLowerCase === currentUserName.toLowerCase() - }) + } + ) - const isAdmin = configFunctions - .getConfigProperty('users.isAdmin') - .some((currentUserName) => { + const isAdmin = getConfigProperty('users.isAdmin').some( + (currentUserName) => { return userNameLowerCase === currentUserName.toLowerCase() - }) + } + ) const apiKey = await getApiKey(userNameLowerCase) diff --git a/routes/lotOccupancies.js b/routes/lotOccupancies.js index 822cb1f3..9e8cfeca 100644 --- a/routes/lotOccupancies.js +++ b/routes/lotOccupancies.js @@ -25,7 +25,7 @@ import handler_doUpdateLotOccupancyFeeQuantity from '../handlers/lotOccupancies- import handler_doUpdateLotOccupancyOccupant from '../handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.js'; import handler_doUpdateLotOccupancyTransaction from '../handlers/lotOccupancies-post/doUpdateLotOccupancyTransaction.js'; import * as permissionHandlers from '../handlers/permissions.js'; -import * as configFunctions from '../helpers/functions.config.js'; +import { getConfigProperty } from '../helpers/functions.config.js'; export const router = Router(); router.get('/', handler_search); router.post('/doSearchLotOccupancies', handler_doSearchLotOccupancies); @@ -48,7 +48,7 @@ router.post('/doGetFees', permissionHandlers.updatePostHandler, handler_doGetFee router.post('/doAddLotOccupancyFee', permissionHandlers.updatePostHandler, handler_doAddLotOccupancyFee); router.post('/doUpdateLotOccupancyFeeQuantity', permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancyFeeQuantity); router.post('/doDeleteLotOccupancyFee', permissionHandlers.updatePostHandler, handler_doDeleteLotOccupancyFee); -if (configFunctions.getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { +if (getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { router.post('/doGetDynamicsGPDocument', permissionHandlers.updatePostHandler, handler_doGetDynamicsGPDocument); } router.post('/doAddLotOccupancyTransaction', permissionHandlers.updatePostHandler, handler_doAddLotOccupancyTransaction); diff --git a/routes/lotOccupancies.ts b/routes/lotOccupancies.ts index 3220e99b..471eb4f6 100644 --- a/routes/lotOccupancies.ts +++ b/routes/lotOccupancies.ts @@ -26,7 +26,7 @@ import handler_doUpdateLotOccupancyFeeQuantity from '../handlers/lotOccupancies- import handler_doUpdateLotOccupancyOccupant from '../handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.js' import handler_doUpdateLotOccupancyTransaction from '../handlers/lotOccupancies-post/doUpdateLotOccupancyTransaction.js' import * as permissionHandlers from '../handlers/permissions.js' -import * as configFunctions from '../helpers/functions.config.js' +import { getConfigProperty } from '../helpers/functions.config.js' export const router = Router() @@ -163,7 +163,7 @@ router.post( // Transactions -if (configFunctions.getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { +if (getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { router.post( '/doGetDynamicsGPDocument', permissionHandlers.updatePostHandler,