From 4dca27d34bbd3a9a73921cf966af5526ce3d5d58 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Wed, 29 Nov 2023 14:42:33 -0500 Subject: [PATCH] code cleanup --- app.js | 6 +++--- app.ts | 6 +++--- bin/www.js | 5 ++--- bin/www.ts | 7 ++++--- bin/wwwProcess.js | 7 +++---- bin/wwwProcess.ts | 9 ++++---- handlers/permissions.js | 4 ++-- handlers/permissions.ts | 4 ++-- temp/legacy.importFromCSV.js | 13 ++++++------ temp/legacy.importFromCSV.ts | 17 ++++++++------- temp/legacy.importFromCsv.data.js | 24 ++++++++++----------- temp/legacy.importFromCsv.data.ts | 35 +++++++++++++++++-------------- 12 files changed, 71 insertions(+), 66 deletions(-) diff --git a/app.js b/app.js index b73c0ac4..4243b7b3 100644 --- a/app.js +++ b/app.js @@ -114,7 +114,7 @@ app.use((request, response, next) => { response.locals.urlPrefix = configFunctions.getProperty('reverseProxy.urlPrefix'); next(); }); -app.get(urlPrefix + '/', sessionChecker, (_request, response) => { +app.get(`${urlPrefix}/`, sessionChecker, (_request, response) => { response.redirect(`${urlPrefix}/dashboard`); }); app.use(`${urlPrefix}/dashboard`, sessionChecker, routerDashboard); @@ -137,11 +137,11 @@ app.get(`${urlPrefix}/logout`, (request, response) => { Object.hasOwn(request.cookies, sessionCookieName)) { request.session.destroy(() => { response.clearCookie(sessionCookieName); - response.redirect(urlPrefix + '/'); + response.redirect(`${urlPrefix}/`); }); } else { - response.redirect(urlPrefix + '/login'); + response.redirect(`${urlPrefix}/login`); } }); app.use((request, _response, next) => { diff --git a/app.ts b/app.ts index e7becdbc..5ecfc818 100644 --- a/app.ts +++ b/app.ts @@ -225,7 +225,7 @@ app.use((request, response, next) => { next() }) -app.get(urlPrefix + '/', sessionChecker, (_request, response) => { +app.get(`${urlPrefix}/`, sessionChecker, (_request, response) => { response.redirect(`${urlPrefix}/dashboard`) }) @@ -266,10 +266,10 @@ app.get(`${urlPrefix}/logout`, (request, response) => { ) { request.session.destroy(() => { response.clearCookie(sessionCookieName) - response.redirect(urlPrefix + '/') + response.redirect(`${urlPrefix}/`) }) } else { - response.redirect(urlPrefix + '/login') + response.redirect(`${urlPrefix}/login`) } }) diff --git a/bin/www.js b/bin/www.js index 31ce8e79..90162a28 100644 --- a/bin/www.js +++ b/bin/www.js @@ -9,13 +9,12 @@ import * as configFunctions 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.getProperty('application.maximumProcesses'), os.cpus().length); -process.title = - configFunctions.getProperty('application.applicationName') + ' (Primary)'; +process.title = `${configFunctions.getProperty('application.applicationName')} (Primary)`; debug(`Primary pid: ${process.pid}`); debug(`Primary title: ${process.title}`); debug(`Launching ${processCount} processes`); const clusterSettings = { - exec: directoryName + '/wwwProcess.js' + exec: `${directoryName}/wwwProcess.js` }; cluster.setupPrimary(clusterSettings); const activeWorkers = new Map(); diff --git a/bin/www.ts b/bin/www.ts index ae015d82..5d293c0b 100644 --- a/bin/www.ts +++ b/bin/www.ts @@ -19,15 +19,16 @@ const processCount = Math.min( os.cpus().length ) -process.title = - configFunctions.getProperty('application.applicationName') + ' (Primary)' +process.title = `${configFunctions.getProperty( + 'application.applicationName' +)} (Primary)` debug(`Primary pid: ${process.pid}`) debug(`Primary title: ${process.title}`) debug(`Launching ${processCount} processes`) const clusterSettings = { - exec: directoryName + '/wwwProcess.js' + exec: `${directoryName}/wwwProcess.js` } cluster.setupPrimary(clusterSettings) diff --git a/bin/wwwProcess.js b/bin/wwwProcess.js index 60c74e8c..9c5a34df 100644 --- a/bin/wwwProcess.js +++ b/bin/wwwProcess.js @@ -25,12 +25,11 @@ function onError(error) { function onListening(server) { const addr = server.address(); if (addr !== null) { - const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port.toString(); - debug('HTTP Listening on ' + bind); + const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port.toString()}`; + debug(`HTTP Listening on ${bind}`); } } -process.title = - configFunctions.getProperty('application.applicationName') + ' (Worker)'; +process.title = `${configFunctions.getProperty('application.applicationName')} (Worker)`; const httpPort = configFunctions.getProperty('application.httpPort'); const httpServer = http.createServer(app); httpServer.listen(httpPort); diff --git a/bin/wwwProcess.ts b/bin/wwwProcess.ts index 2d1ce473..1df72ba7 100644 --- a/bin/wwwProcess.ts +++ b/bin/wwwProcess.ts @@ -49,8 +49,8 @@ function onListening(server: http.Server): void { if (addr !== null) { const bind = - typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port.toString() - debug('HTTP Listening on ' + bind) + typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port.toString()}` + debug(`HTTP Listening on ${bind}`) } } @@ -58,8 +58,9 @@ function onListening(server: http.Server): void { * Initialize HTTP */ -process.title = - configFunctions.getProperty('application.applicationName') + ' (Worker)' +process.title = `${configFunctions.getProperty( + 'application.applicationName' +)} (Worker)` const httpPort = configFunctions.getProperty('application.httpPort') diff --git a/handlers/permissions.js b/handlers/permissions.js index 1ed966e0..09fba670 100644 --- a/handlers/permissions.js +++ b/handlers/permissions.js @@ -6,7 +6,7 @@ const forbiddenJSON = { success: false, message: 'Forbidden' }; -const forbiddenRedirectURL = urlPrefix + '/dashboard/?error=accessDenied'; +const forbiddenRedirectURL = `${urlPrefix}/dashboard/?error=accessDenied`; export function adminGetHandler(request, response, next) { if (userFunctions.userIsAdmin(request)) { next(); @@ -40,6 +40,6 @@ export async function apiGetHandler(request, response, next) { next(); } else { - response.redirect(urlPrefix + '/login'); + response.redirect(`${urlPrefix}/login`); } } diff --git a/handlers/permissions.ts b/handlers/permissions.ts index d1fdbe3b..0f45f78e 100644 --- a/handlers/permissions.ts +++ b/handlers/permissions.ts @@ -12,7 +12,7 @@ const forbiddenJSON = { message: 'Forbidden' } -const forbiddenRedirectURL = urlPrefix + '/dashboard/?error=accessDenied' +const forbiddenRedirectURL = `${urlPrefix}/dashboard/?error=accessDenied` export function adminGetHandler( request: Request, @@ -74,6 +74,6 @@ export async function apiGetHandler( if (await userFunctions.apiKeyIsValid(request)) { next() } else { - response.redirect(urlPrefix + '/login') + response.redirect(`${urlPrefix}/login`) } } diff --git a/temp/legacy.importFromCSV.js b/temp/legacy.importFromCSV.js index 1bae9607..388d9bf3 100644 --- a/temp/legacy.importFromCSV.js +++ b/temp/legacy.importFromCSV.js @@ -79,14 +79,15 @@ function getMapByMapDescription(mapDescription) { return map; } function formatDateString(year, month, day) { - return (`0000${year}`.slice(-4) + - '-' + - `00${month}`.slice(-2) + - '-' + - `00${day}`.slice(-2)); + const formattedYear = `0000${year}`.slice(-4); + const formattedMonth = `00${month}`.slice(-2); + const formattedDay = `00${day}`.slice(-2); + return `${formattedYear}-${formattedMonth}-${formattedDay}`; } function formatTimeString(hour, minute) { - return `00${hour}`.slice(-2) + ':' + `00${minute}`.slice(-2); + const formattedHour = `00${hour}`.slice(-2); + const formattedMinute = `00${minute}`.slice(-2); + return `${formattedHour}:${formattedMinute}`; } const cemeteryToMapName = { '00': 'Crematorium', diff --git a/temp/legacy.importFromCSV.ts b/temp/legacy.importFromCSV.ts index fccb5a94..826fd8d9 100644 --- a/temp/legacy.importFromCSV.ts +++ b/temp/legacy.importFromCSV.ts @@ -245,17 +245,18 @@ function getMapByMapDescription(mapDescription: string): recordTypes.MapRecord { } function formatDateString(year: string, month: string, day: string): string { - return ( - `0000${year}`.slice(-4) + - '-' + - `00${month}`.slice(-2) + - '-' + - `00${day}`.slice(-2) - ) + const formattedYear = `0000${year}`.slice(-4) + const formattedMonth = `00${month}`.slice(-2) + const formattedDay = `00${day}`.slice(-2) + + return `${formattedYear}-${formattedMonth}-${formattedDay}` } function formatTimeString(hour: string, minute: string): string { - return `00${hour}`.slice(-2) + ':' + `00${minute}`.slice(-2) + const formattedHour = `00${hour}`.slice(-2) + const formattedMinute = `00${minute}`.slice(-2) + + return `${formattedHour}:${formattedMinute}` } const cemeteryToMapName = { diff --git a/temp/legacy.importFromCsv.data.js b/temp/legacy.importFromCsv.data.js index 34fb9858..aa5370b3 100644 --- a/temp/legacy.importFromCsv.data.js +++ b/temp/legacy.importFromCsv.data.js @@ -1,17 +1,17 @@ import * as importIds from './legacy.importFromCsv.ids.js'; export function buildLotName(lotNamePieces) { - return (lotNamePieces.cemetery + - '-' + - (lotNamePieces.block === '' ? '' : `B${lotNamePieces.block}-`) + - (lotNamePieces.range1 === '0' && lotNamePieces.range2 === '' - ? '' - : `R${lotNamePieces.range1 === '0' ? '' : lotNamePieces.range1}${lotNamePieces.range2}-`) + - (lotNamePieces.lot1 === '0' && lotNamePieces.lot2 === '' - ? '' - : `L${lotNamePieces.lot1}${lotNamePieces.lot2}-`) + - `G${lotNamePieces.grave1}${lotNamePieces.grave2}` + - ', ' + - `Interment ${lotNamePieces.interment}`); + let lotName = `${lotNamePieces.cemetery}-`; + if (lotNamePieces.block !== '') { + lotName += `B${lotNamePieces.block}-`; + } + if (lotNamePieces.range1 !== '0' || lotNamePieces.range2 !== '') { + lotName += `R${lotNamePieces.range1 === '0' ? '' : lotNamePieces.range1}${lotNamePieces.range2}-`; + } + if (lotNamePieces.lot1 !== '0' || lotNamePieces.lot2 === '') { + lotName += `L${lotNamePieces.lot1}${lotNamePieces.lot2}-`; + } + lotName += `G${lotNamePieces.grave1}${lotNamePieces.grave2}, Interment ${lotNamePieces.interment}`; + return lotName; } export function getFuneralHomeLotOccupancyOccupantData(funeralHomeKey) { switch (funeralHomeKey) { diff --git a/temp/legacy.importFromCsv.data.ts b/temp/legacy.importFromCsv.data.ts index 6ecefeee..63354951 100644 --- a/temp/legacy.importFromCsv.data.ts +++ b/temp/legacy.importFromCsv.data.ts @@ -13,22 +13,25 @@ export function buildLotName(lotNamePieces: { grave2: string interment: string }): string { - return ( - lotNamePieces.cemetery + - '-' + - (lotNamePieces.block === '' ? '' : `B${lotNamePieces.block}-`) + - (lotNamePieces.range1 === '0' && lotNamePieces.range2 === '' - ? '' - : `R${lotNamePieces.range1 === '0' ? '' : lotNamePieces.range1}${ - lotNamePieces.range2 - }-`) + - (lotNamePieces.lot1 === '0' && lotNamePieces.lot2 === '' - ? '' - : `L${lotNamePieces.lot1}${lotNamePieces.lot2}-`) + - `G${lotNamePieces.grave1}${lotNamePieces.grave2}` + - ', ' + - `Interment ${lotNamePieces.interment}` - ) + let lotName = `${lotNamePieces.cemetery}-` + + if (lotNamePieces.block !== '') { + lotName += `B${lotNamePieces.block}-` + } + + if (lotNamePieces.range1 !== '0' || lotNamePieces.range2 !== '') { + lotName += `R${lotNamePieces.range1 === '0' ? '' : lotNamePieces.range1}${ + lotNamePieces.range2 + }-` + } + + if (lotNamePieces.lot1 !== '0' || lotNamePieces.lot2 === '') { + lotName += `L${lotNamePieces.lot1}${lotNamePieces.lot2}-` + } + + lotName += `G${lotNamePieces.grave1}${lotNamePieces.grave2}, Interment ${lotNamePieces.interment}` + + return lotName } export function getFuneralHomeLotOccupancyOccupantData(