From b10fbde5305a5644b3e5316c95fe313e3aacb3ed Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Mon, 24 Jun 2024 15:36:51 -0400 Subject: [PATCH] linting --- app.js | 4 +- app.ts | 4 +- database/addLotComment.js | 4 +- database/addLotComment.ts | 6 +-- database/addLotOccupancy.js | 6 +-- database/addLotOccupancy.ts | 10 ++--- database/addWorkOrderComment.js | 4 +- database/addWorkOrderComment.ts | 6 +-- database/getReportData.js | 10 ++--- database/getReportData.ts | 27 ++++++------- gulpfile.ts | 3 +- handlers/permissions.js | 12 +++--- handlers/permissions.ts | 16 +++++--- handlers/reports-get/search.js | 4 +- handlers/reports-get/search.ts | 4 +- helpers/functions.lotOccupancy.d.ts | 10 ++--- helpers/functions.lotOccupancy.ts | 14 +++---- helpers/functions.user.js | 6 +-- helpers/functions.user.ts | 10 ++--- helpers/initializer.database.cemetery.js | 2 +- helpers/initializer.database.cemetery.ts | 2 +- routes/login.js | 8 ++-- routes/login.ts | 14 +++---- routes/lotOccupancies.js | 46 +++++++++++----------- routes/lotOccupancies.ts | 50 +++++++++++------------- 25 files changed, 138 insertions(+), 144 deletions(-) diff --git a/app.js b/app.js index 36766d38..a4184174 100644 --- a/app.js +++ b/app.js @@ -14,7 +14,7 @@ import * as permissionHandlers from './handlers/permissions.js'; import { getSafeRedirectURL } from './helpers/functions.authentication.js'; import * as configFunctions from './helpers/functions.config.js'; import * as printFunctions from './helpers/functions.print.js'; -import * as databaseInitializer from './helpers/initializer.database.js'; +import { initializeDatabase } from './helpers/initializer.database.js'; import routerAdmin from './routes/admin.js'; import routerApi from './routes/api.js'; import routerDashboard from './routes/dashboard.js'; @@ -27,7 +27,7 @@ import routerReports from './routes/reports.js'; import routerWorkOrders from './routes/workOrders.js'; import { version } from './version.js'; const debug = Debug(`lot-occupancy-system:app:${process.pid}`); -databaseInitializer.initializeDatabase(); +initializeDatabase(); const _dirname = '.'; export const app = express(); app.disable('X-Powered-By'); diff --git a/app.ts b/app.ts index d0ae282b..41c4f136 100644 --- a/app.ts +++ b/app.ts @@ -16,7 +16,7 @@ import * as permissionHandlers from './handlers/permissions.js' import { getSafeRedirectURL } from './helpers/functions.authentication.js' import * as configFunctions from './helpers/functions.config.js' import * as printFunctions from './helpers/functions.print.js' -import * as databaseInitializer from './helpers/initializer.database.js' +import { initializeDatabase } from './helpers/initializer.database.js' import routerAdmin from './routes/admin.js' import routerApi from './routes/api.js' import routerDashboard from './routes/dashboard.js' @@ -35,7 +35,7 @@ const debug = Debug(`lot-occupancy-system:app:${process.pid}`) * INITIALIZE THE DATABASE */ -databaseInitializer.initializeDatabase() +initializeDatabase() /* * INITIALIZE APP diff --git a/database/addLotComment.js b/database/addLotComment.js index be6f086a..078d8849 100644 --- a/database/addLotComment.js +++ b/database/addLotComment.js @@ -1,4 +1,4 @@ -import * as dateTimeFunctions from '@cityssm/utils-datetime'; +import { dateToInteger, dateToTimeInteger } from '@cityssm/utils-datetime'; import { acquireConnection } from './pool.js'; export default async function addLotComment(lotCommentForm, user) { const database = await acquireConnection(); @@ -10,7 +10,7 @@ export default async function addLotComment(lotCommentForm, user) { recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) values (?, ?, ?, ?, ?, ?, ?, ?)`) - .run(lotCommentForm.lotId, dateTimeFunctions.dateToInteger(rightNow), dateTimeFunctions.dateToTimeInteger(rightNow), lotCommentForm.lotComment, user.userName, rightNow.getTime(), user.userName, rightNow.getTime()); + .run(lotCommentForm.lotId, dateToInteger(rightNow), dateToTimeInteger(rightNow), lotCommentForm.lotComment, user.userName, rightNow.getTime(), user.userName, rightNow.getTime()); database.release(); return result.lastInsertRowid; } diff --git a/database/addLotComment.ts b/database/addLotComment.ts index d6f74e5f..b55ceb11 100644 --- a/database/addLotComment.ts +++ b/database/addLotComment.ts @@ -1,4 +1,4 @@ -import * as dateTimeFunctions from '@cityssm/utils-datetime' +import { dateToInteger, dateToTimeInteger } from '@cityssm/utils-datetime' import { acquireConnection } from './pool.js' @@ -26,8 +26,8 @@ export default async function addLotComment( ) .run( lotCommentForm.lotId, - dateTimeFunctions.dateToInteger(rightNow), - dateTimeFunctions.dateToTimeInteger(rightNow), + dateToInteger(rightNow), + dateToTimeInteger(rightNow), lotCommentForm.lotComment, user.userName, rightNow.getTime(), diff --git a/database/addLotOccupancy.js b/database/addLotOccupancy.js index e496f152..53eb071f 100644 --- a/database/addLotOccupancy.js +++ b/database/addLotOccupancy.js @@ -1,11 +1,11 @@ -import * as dateTimeFunctions from '@cityssm/utils-datetime'; +import { dateStringToInteger } from '@cityssm/utils-datetime'; import addLotOccupancyOccupant from './addLotOccupancyOccupant.js'; import addOrUpdateLotOccupancyField from './addOrUpdateLotOccupancyField.js'; import { acquireConnection } from './pool.js'; export default async function addLotOccupancy(lotOccupancyForm, user, connectedDatabase) { const database = connectedDatabase ?? (await acquireConnection()); const rightNowMillis = Date.now(); - const occupancyStartDate = dateTimeFunctions.dateStringToInteger(lotOccupancyForm.occupancyStartDateString); + const occupancyStartDate = dateStringToInteger(lotOccupancyForm.occupancyStartDateString); if (occupancyStartDate <= 0) { console.error(lotOccupancyForm); } @@ -18,7 +18,7 @@ export default async function addLotOccupancy(lotOccupancyForm, user, connectedD values (?, ?, ?, ?, ?, ?, ?, ?)`) .run(lotOccupancyForm.occupancyTypeId, lotOccupancyForm.lotId === '' ? undefined : lotOccupancyForm.lotId, occupancyStartDate, lotOccupancyForm.occupancyEndDateString === '' ? undefined - : dateTimeFunctions.dateStringToInteger(lotOccupancyForm.occupancyEndDateString), user.userName, rightNowMillis, user.userName, rightNowMillis); + : dateStringToInteger(lotOccupancyForm.occupancyEndDateString), user.userName, rightNowMillis, user.userName, rightNowMillis); const lotOccupancyId = result.lastInsertRowid; const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds ?? '').split(','); for (const occupancyTypeFieldId of occupancyTypeFieldIds) { diff --git a/database/addLotOccupancy.ts b/database/addLotOccupancy.ts index dfb7e054..21330d16 100644 --- a/database/addLotOccupancy.ts +++ b/database/addLotOccupancy.ts @@ -1,4 +1,4 @@ -import * as dateTimeFunctions from '@cityssm/utils-datetime' +import { type DateString, dateStringToInteger } from '@cityssm/utils-datetime' import type { PoolConnection } from 'better-sqlite-pool' import addLotOccupancyOccupant from './addLotOccupancyOccupant.js' @@ -37,8 +37,8 @@ export default async function addLotOccupancy( const rightNowMillis = Date.now() - const occupancyStartDate = dateTimeFunctions.dateStringToInteger( - lotOccupancyForm.occupancyStartDateString as dateTimeFunctions.DateString + const occupancyStartDate = dateStringToInteger( + lotOccupancyForm.occupancyStartDateString as DateString ) if (occupancyStartDate <= 0) { @@ -60,8 +60,8 @@ export default async function addLotOccupancy( occupancyStartDate, lotOccupancyForm.occupancyEndDateString === '' ? undefined - : dateTimeFunctions.dateStringToInteger( - lotOccupancyForm.occupancyEndDateString as dateTimeFunctions.DateString + : dateStringToInteger( + lotOccupancyForm.occupancyEndDateString as DateString ), user.userName, rightNowMillis, diff --git a/database/addWorkOrderComment.js b/database/addWorkOrderComment.js index d980a008..cf90b964 100644 --- a/database/addWorkOrderComment.js +++ b/database/addWorkOrderComment.js @@ -1,4 +1,4 @@ -import * as dateTimeFunctions from '@cityssm/utils-datetime'; +import { dateToInteger, dateToTimeInteger } from '@cityssm/utils-datetime'; import { acquireConnection } from './pool.js'; export default async function addWorkOrderComment(workOrderCommentForm, user) { const database = await acquireConnection(); @@ -11,7 +11,7 @@ export default async function addWorkOrderComment(workOrderCommentForm, user) { recordCreate_userName, recordCreate_timeMillis, recordUpdate_userName, recordUpdate_timeMillis) values (?, ?, ?, ?, ?, ?, ?, ?)`) - .run(workOrderCommentForm.workOrderId, dateTimeFunctions.dateToInteger(rightNow), dateTimeFunctions.dateToTimeInteger(rightNow), workOrderCommentForm.workOrderComment, user.userName, rightNow.getTime(), user.userName, rightNow.getTime()); + .run(workOrderCommentForm.workOrderId, dateToInteger(rightNow), dateToTimeInteger(rightNow), workOrderCommentForm.workOrderComment, user.userName, rightNow.getTime(), user.userName, rightNow.getTime()); database.release(); return result.lastInsertRowid; } diff --git a/database/addWorkOrderComment.ts b/database/addWorkOrderComment.ts index 923e009a..1d5ca2c5 100644 --- a/database/addWorkOrderComment.ts +++ b/database/addWorkOrderComment.ts @@ -1,4 +1,4 @@ -import * as dateTimeFunctions from '@cityssm/utils-datetime' +import { dateToInteger, dateToTimeInteger } from '@cityssm/utils-datetime' import { acquireConnection } from './pool.js' @@ -27,8 +27,8 @@ export default async function addWorkOrderComment( ) .run( workOrderCommentForm.workOrderId, - dateTimeFunctions.dateToInteger(rightNow), - dateTimeFunctions.dateToTimeInteger(rightNow), + dateToInteger(rightNow), + dateToTimeInteger(rightNow), workOrderCommentForm.workOrderComment, user.userName, rightNow.getTime(), diff --git a/database/getReportData.js b/database/getReportData.js index a6d44401..0e1d71bd 100644 --- a/database/getReportData.js +++ b/database/getReportData.js @@ -1,4 +1,4 @@ -import * as dateTimeFunctions from '@cityssm/utils-datetime'; +import { dateIntegerToString, dateStringToInteger, dateToInteger, timeIntegerToString } from '@cityssm/utils-datetime'; import camelCase from 'camelcase'; import { getConfigProperty } from '../helpers/functions.config.js'; import { acquireConnection } from './pool.js'; @@ -132,7 +132,7 @@ export default async function getReportData(reportName, reportParameters = {}) { where o.recordDelete_timeMillis is null and (o.occupancyEndDate is null or o.occupancyEndDate >= ?) and l.mapId = ?`; - sqlParameters.push(dateTimeFunctions.dateToInteger(new Date()), reportParameters.mapId); + sqlParameters.push(dateToInteger(new Date()), reportParameters.mapId); break; } case 'lotOccupancyComments-all': { @@ -184,7 +184,7 @@ export default async function getReportData(reportName, reportParameters = {}) { from LotOccupancyTransactions t where t.recordDelete_timeMillis is null and t.transactionDate = ?`; - sqlParameters.push(dateTimeFunctions.dateStringToInteger(reportParameters.transactionDateString)); + sqlParameters.push(dateStringToInteger(reportParameters.transactionDateString)); break; } case 'workOrders-all': { @@ -281,8 +281,8 @@ export default async function getReportData(reportName, reportParameters = {}) { } } const database = await acquireConnection(); - database.function('userFn_dateIntegerToString', dateTimeFunctions.dateIntegerToString); - database.function('userFn_timeIntegerToString', dateTimeFunctions.timeIntegerToString); + database.function('userFn_dateIntegerToString', dateIntegerToString); + database.function('userFn_timeIntegerToString', timeIntegerToString); const rows = database.prepare(sql).all(sqlParameters); database.release(); return rows; diff --git a/database/getReportData.ts b/database/getReportData.ts index a7175136..87b5850a 100644 --- a/database/getReportData.ts +++ b/database/getReportData.ts @@ -1,7 +1,13 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair /* eslint-disable no-case-declarations */ -import * as dateTimeFunctions from '@cityssm/utils-datetime' +import { + type DateString, + dateIntegerToString, + dateStringToInteger, + dateToInteger, + timeIntegerToString +} from '@cityssm/utils-datetime' import camelCase from 'camelcase' import { getConfigProperty } from '../helpers/functions.config.js' @@ -166,10 +172,7 @@ export default async function getReportData( and (o.occupancyEndDate is null or o.occupancyEndDate >= ?) and l.mapId = ?` - sqlParameters.push( - dateTimeFunctions.dateToInteger(new Date()), - reportParameters.mapId - ) + sqlParameters.push(dateToInteger(new Date()), reportParameters.mapId) break } @@ -231,8 +234,8 @@ export default async function getReportData( and t.transactionDate = ?` sqlParameters.push( - dateTimeFunctions.dateStringToInteger( - reportParameters.transactionDateString as dateTimeFunctions.DateString + dateStringToInteger( + reportParameters.transactionDateString as DateString ) ) break @@ -350,14 +353,8 @@ export default async function getReportData( const database = await acquireConnection() - database.function( - 'userFn_dateIntegerToString', - dateTimeFunctions.dateIntegerToString - ) - database.function( - 'userFn_timeIntegerToString', - dateTimeFunctions.timeIntegerToString - ) + database.function('userFn_dateIntegerToString', dateIntegerToString) + database.function('userFn_timeIntegerToString', timeIntegerToString) const rows = database.prepare(sql).all(sqlParameters) diff --git a/gulpfile.ts b/gulpfile.ts index 2f758b03..5eaa6d68 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair -/* eslint-disable n/no-unpublished-import */ +/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, n/no-unpublished-import */ import gulp from 'gulp' import changed from 'gulp-changed' @@ -22,6 +22,7 @@ function publicSCSSFunction(): NodeJS.ReadWriteStream { .pipe( sass({ outputStyle: 'compressed', includePaths: ['node_modules'] }).on( 'error', + // eslint-disable-next-line @typescript-eslint/unbound-method sass.logError ) ) diff --git a/handlers/permissions.js b/handlers/permissions.js index 8964cfd0..f2d6adfa 100644 --- a/handlers/permissions.js +++ b/handlers/permissions.js @@ -1,5 +1,5 @@ import { getConfigProperty } from '../helpers/functions.config.js'; -import * as userFunctions from '../helpers/functions.user.js'; +import { apiKeyIsValid, userCanUpdate, userIsAdmin } from '../helpers/functions.user.js'; const urlPrefix = getConfigProperty('reverseProxy.urlPrefix'); const forbiddenStatus = 403; const forbiddenJSON = { @@ -8,35 +8,35 @@ const forbiddenJSON = { }; const forbiddenRedirectURL = `${urlPrefix}/dashboard/?error=accessDenied`; export function adminGetHandler(request, response, next) { - if (userFunctions.userIsAdmin(request)) { + if (userIsAdmin(request)) { next(); return; } response.redirect(forbiddenRedirectURL); } export function adminPostHandler(request, response, next) { - if (userFunctions.userIsAdmin(request)) { + if (userIsAdmin(request)) { next(); return; } response.status(forbiddenStatus).json(forbiddenJSON); } export function updateGetHandler(request, response, next) { - if (userFunctions.userCanUpdate(request)) { + if (userCanUpdate(request)) { next(); return; } response.redirect(forbiddenRedirectURL); } export function updatePostHandler(request, response, next) { - if (userFunctions.userCanUpdate(request)) { + if (userCanUpdate(request)) { next(); return; } response.status(forbiddenStatus).json(forbiddenJSON); } export async function apiGetHandler(request, response, next) { - if (await userFunctions.apiKeyIsValid(request)) { + if (await apiKeyIsValid(request)) { next(); } else { diff --git a/handlers/permissions.ts b/handlers/permissions.ts index 033c23cc..fd7985d8 100644 --- a/handlers/permissions.ts +++ b/handlers/permissions.ts @@ -1,7 +1,11 @@ import type { NextFunction, Request, Response } from 'express' import { getConfigProperty } from '../helpers/functions.config.js' -import * as userFunctions from '../helpers/functions.user.js' +import { + apiKeyIsValid, + userCanUpdate, + userIsAdmin +} from '../helpers/functions.user.js' const urlPrefix = getConfigProperty('reverseProxy.urlPrefix') @@ -19,7 +23,7 @@ export function adminGetHandler( response: Response, next: NextFunction ): void { - if (userFunctions.userIsAdmin(request)) { + if (userIsAdmin(request)) { next() return } @@ -32,7 +36,7 @@ export function adminPostHandler( response: Response, next: NextFunction ): void { - if (userFunctions.userIsAdmin(request)) { + if (userIsAdmin(request)) { next() return } @@ -45,7 +49,7 @@ export function updateGetHandler( response: Response, next: NextFunction ): void { - if (userFunctions.userCanUpdate(request)) { + if (userCanUpdate(request)) { next() return } @@ -58,7 +62,7 @@ export function updatePostHandler( response: Response, next: NextFunction ): void { - if (userFunctions.userCanUpdate(request)) { + if (userCanUpdate(request)) { next() return } @@ -71,7 +75,7 @@ export async function apiGetHandler( response: Response, next: NextFunction ): Promise { - if (await userFunctions.apiKeyIsValid(request)) { + if (await apiKeyIsValid(request)) { next() } else { response.redirect(`${urlPrefix}/login`) diff --git a/handlers/reports-get/search.js b/handlers/reports-get/search.js index 5cdd2429..09526ea5 100644 --- a/handlers/reports-get/search.js +++ b/handlers/reports-get/search.js @@ -1,4 +1,4 @@ -import * as dateTimeFunctions from '@cityssm/utils-datetime'; +import { dateToString } from '@cityssm/utils-datetime'; import getMaps from '../../database/getMaps.js'; import { getLotStatuses, getLotTypes } from '../../helpers/functions.cache.js'; export default async function handler(_request, response) { @@ -8,7 +8,7 @@ export default async function handler(_request, response) { const lotStatuses = await getLotStatuses(); response.render('report-search', { headTitle: 'Reports', - todayDateString: dateTimeFunctions.dateToString(rightNow), + todayDateString: dateToString(rightNow), maps, lotTypes, lotStatuses diff --git a/handlers/reports-get/search.ts b/handlers/reports-get/search.ts index be806186..e22e3547 100644 --- a/handlers/reports-get/search.ts +++ b/handlers/reports-get/search.ts @@ -1,4 +1,4 @@ -import * as dateTimeFunctions from '@cityssm/utils-datetime' +import { dateToString } from '@cityssm/utils-datetime' import type { Request, Response } from 'express' import getMaps from '../../database/getMaps.js' @@ -16,7 +16,7 @@ export default async function handler( response.render('report-search', { headTitle: 'Reports', - todayDateString: dateTimeFunctions.dateToString(rightNow), + todayDateString: dateToString(rightNow), maps, lotTypes, lotStatuses diff --git a/helpers/functions.lotOccupancy.d.ts b/helpers/functions.lotOccupancy.d.ts index e1eb4b03..d147f9b6 100644 --- a/helpers/functions.lotOccupancy.d.ts +++ b/helpers/functions.lotOccupancy.d.ts @@ -1,5 +1,5 @@ -import type * as recordTypes from '../types/recordTypes'; -export declare function filterOccupantsByLotOccupantType(lotOccupancy: recordTypes.LotOccupancy, lotOccupantType: string): recordTypes.LotOccupancyOccupant[]; -export declare function getFieldValueByOccupancyTypeField(lotOccupancy: recordTypes.LotOccupancy, occupancyTypeField: string): string | undefined; -export declare function getFeesByFeeCategory(lotOccupancy: recordTypes.LotOccupancy, feeCategory: string, feeCategoryContains?: boolean): recordTypes.LotOccupancyFee[]; -export declare function getTransactionTotal(lotOccupancy: recordTypes.LotOccupancy): number; +import type { LotOccupancy, LotOccupancyFee, LotOccupancyOccupant } from '../types/recordTypes'; +export declare function filterOccupantsByLotOccupantType(lotOccupancy: LotOccupancy, lotOccupantType: string): LotOccupancyOccupant[]; +export declare function getFieldValueByOccupancyTypeField(lotOccupancy: LotOccupancy, occupancyTypeField: string): string | undefined; +export declare function getFeesByFeeCategory(lotOccupancy: LotOccupancy, feeCategory: string, feeCategoryContains?: boolean): LotOccupancyFee[]; +export declare function getTransactionTotal(lotOccupancy: LotOccupancy): number; diff --git a/helpers/functions.lotOccupancy.ts b/helpers/functions.lotOccupancy.ts index d616d5bc..279cbe35 100644 --- a/helpers/functions.lotOccupancy.ts +++ b/helpers/functions.lotOccupancy.ts @@ -1,9 +1,9 @@ -import type * as recordTypes from '../types/recordTypes' +import type { LotOccupancy, LotOccupancyFee, LotOccupancyOccupant } from '../types/recordTypes' export function filterOccupantsByLotOccupantType( - lotOccupancy: recordTypes.LotOccupancy, + lotOccupancy: LotOccupancy, lotOccupantType: string -): recordTypes.LotOccupancyOccupant[] { +): LotOccupancyOccupant[] { const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase() return (lotOccupancy.lotOccupancyOccupants ?? []).filter( @@ -17,7 +17,7 @@ export function filterOccupantsByLotOccupantType( } export function getFieldValueByOccupancyTypeField( - lotOccupancy: recordTypes.LotOccupancy, + lotOccupancy: LotOccupancy, occupancyTypeField: string ): string | undefined { const occupancyTypeFieldLowerCase = occupancyTypeField.toLowerCase() @@ -39,10 +39,10 @@ export function getFieldValueByOccupancyTypeField( } export function getFeesByFeeCategory( - lotOccupancy: recordTypes.LotOccupancy, + lotOccupancy: LotOccupancy, feeCategory: string, feeCategoryContains = false -): recordTypes.LotOccupancyFee[] { +): LotOccupancyFee[] { const feeCategoryLowerCase = feeCategory.toLowerCase() return (lotOccupancy.lotOccupancyFees ?? []).filter((possibleFee) => { @@ -56,7 +56,7 @@ export function getFeesByFeeCategory( } export function getTransactionTotal( - lotOccupancy: recordTypes.LotOccupancy + lotOccupancy: LotOccupancy ): number { let transactionTotal = 0 diff --git a/helpers/functions.user.js b/helpers/functions.user.js index 5059dfa0..c89e097f 100644 --- a/helpers/functions.user.js +++ b/helpers/functions.user.js @@ -1,5 +1,5 @@ import { getUserNameFromApiKey } from './functions.api.js'; -import * as configFunctions from './functions.config.js'; +import { getConfigProperty } from './functions.config.js'; export function userIsAdmin(request) { return request.session?.user?.userProperties?.isAdmin ?? false; } @@ -15,9 +15,7 @@ export async function apiKeyIsValid(request) { if (userName === undefined) { return false; } - return configFunctions - .getConfigProperty('users.canLogin') - .some((currentUserName) => { + return getConfigProperty('users.canLogin').some((currentUserName) => { return userName === currentUserName.toLowerCase(); }); } diff --git a/helpers/functions.user.ts b/helpers/functions.user.ts index 4ff56907..715cacdc 100644 --- a/helpers/functions.user.ts +++ b/helpers/functions.user.ts @@ -1,5 +1,5 @@ import { getUserNameFromApiKey } from './functions.api.js' -import * as configFunctions from './functions.config.js' +import { getConfigProperty } from './functions.config.js' export interface UserRequest { session?: { @@ -34,9 +34,7 @@ export async function apiKeyIsValid(request: APIRequest): Promise { return false } - return configFunctions - .getConfigProperty('users.canLogin') - .some((currentUserName) => { - return userName === currentUserName.toLowerCase() - }) + return getConfigProperty('users.canLogin').some((currentUserName) => { + return userName === currentUserName.toLowerCase() + }) } diff --git a/helpers/initializer.database.cemetery.js b/helpers/initializer.database.cemetery.js index 476330cc..52df6796 100644 --- a/helpers/initializer.database.cemetery.js +++ b/helpers/initializer.database.cemetery.js @@ -14,7 +14,7 @@ const user = { } }; export async function initializeCemeteryDatabase() { - debug('Checking for ' + databasePath + '...'); + debug(`Checking for ${databasePath}...`); const databaseInitialized = initializeDatabase(); if (!databaseInitialized) { debug('Database already created.\n' + diff --git a/helpers/initializer.database.cemetery.ts b/helpers/initializer.database.cemetery.ts index d19f69af..85c21949 100644 --- a/helpers/initializer.database.cemetery.ts +++ b/helpers/initializer.database.cemetery.ts @@ -22,7 +22,7 @@ export async function initializeCemeteryDatabase(): Promise { /* * Ensure database does not already exist */ - debug('Checking for ' + databasePath + '...') + debug(`Checking for ${databasePath}...`) const databaseInitialized = initializeDatabase() diff --git a/routes/login.js b/routes/login.js index 491e0519..195c1902 100644 --- a/routes/login.js +++ b/routes/login.js @@ -2,7 +2,7 @@ import Debug from 'debug'; 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 { authenticate, getSafeRedirectURL } from '../helpers/functions.authentication.js'; import { getConfigProperty } from '../helpers/functions.config.js'; const debug = Debug('lot-occupancy-system:login'); export const router = Router(); @@ -10,7 +10,7 @@ function getHandler(request, response) { const sessionCookieName = getConfigProperty('session.cookieName'); if (request.session.user !== undefined && request.cookies[sessionCookieName] !== undefined) { - const redirectURL = authenticationFunctions.getSafeRedirectURL((request.query.redirect ?? '')); + const redirectURL = getSafeRedirectURL((request.query.redirect ?? '')); response.redirect(redirectURL); } else { @@ -26,7 +26,7 @@ async function postHandler(request, response) { const userName = (typeof request.body.userName === 'string' ? request.body.userName : ''); const passwordPlain = (typeof request.body.password === 'string' ? request.body.password : ''); const unsafeRedirectURL = request.body.redirect; - const redirectURL = authenticationFunctions.getSafeRedirectURL(typeof unsafeRedirectURL === 'string' ? unsafeRedirectURL : ''); + const redirectURL = getSafeRedirectURL(typeof unsafeRedirectURL === 'string' ? unsafeRedirectURL : ''); let isAuthenticated = false; if (userName.startsWith('*')) { if (useTestDatabases && userName === passwordPlain) { @@ -37,7 +37,7 @@ async function postHandler(request, response) { } } else if (userName !== '' && passwordPlain !== '') { - isAuthenticated = await authenticationFunctions.authenticate(userName, passwordPlain); + isAuthenticated = await authenticate(userName, passwordPlain); } let userObject; if (isAuthenticated) { diff --git a/routes/login.ts b/routes/login.ts index 661593c0..1572d0f0 100644 --- a/routes/login.ts +++ b/routes/login.ts @@ -8,7 +8,10 @@ import { import { useTestDatabases } from '../data/databasePaths.js' import { getApiKey } from '../helpers/functions.api.js' -import * as authenticationFunctions from '../helpers/functions.authentication.js' +import { + authenticate, + getSafeRedirectURL +} from '../helpers/functions.authentication.js' import { getConfigProperty } from '../helpers/functions.config.js' const debug = Debug('lot-occupancy-system:login') @@ -22,7 +25,7 @@ function getHandler(request: Request, response: Response): void { request.session.user !== undefined && request.cookies[sessionCookieName] !== undefined ) { - const redirectURL = authenticationFunctions.getSafeRedirectURL( + const redirectURL = getSafeRedirectURL( (request.query.redirect ?? '') as string ) @@ -51,7 +54,7 @@ async function postHandler( const unsafeRedirectURL = request.body.redirect - const redirectURL = authenticationFunctions.getSafeRedirectURL( + const redirectURL = getSafeRedirectURL( typeof unsafeRedirectURL === 'string' ? unsafeRedirectURL : '' ) @@ -66,10 +69,7 @@ async function postHandler( } } } else if (userName !== '' && passwordPlain !== '') { - isAuthenticated = await authenticationFunctions.authenticate( - userName, - passwordPlain - ) + isAuthenticated = await authenticate(userName, passwordPlain) } let userObject: User | undefined diff --git a/routes/lotOccupancies.js b/routes/lotOccupancies.js index 9e8cfeca..908d7d71 100644 --- a/routes/lotOccupancies.js +++ b/routes/lotOccupancies.js @@ -24,34 +24,34 @@ import handler_doUpdateLotOccupancyComment from '../handlers/lotOccupancies-post import handler_doUpdateLotOccupancyFeeQuantity from '../handlers/lotOccupancies-post/doUpdateLotOccupancyFeeQuantity.js'; 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 { updateGetHandler, updatePostHandler } from '../handlers/permissions.js'; import { getConfigProperty } from '../helpers/functions.config.js'; export const router = Router(); router.get('/', handler_search); router.post('/doSearchLotOccupancies', handler_doSearchLotOccupancies); -router.get('/new', permissionHandlers.updateGetHandler, handler_new); -router.post('/doGetOccupancyTypeFields', permissionHandlers.updatePostHandler, handler_doGetOccupancyTypeFields); -router.post('/doCreateLotOccupancy', permissionHandlers.updatePostHandler, handler_doCreateLotOccupancy); +router.get('/new', updateGetHandler, handler_new); +router.post('/doGetOccupancyTypeFields', updatePostHandler, handler_doGetOccupancyTypeFields); +router.post('/doCreateLotOccupancy', updatePostHandler, handler_doCreateLotOccupancy); router.get('/:lotOccupancyId', handler_view); -router.get('/:lotOccupancyId/edit', permissionHandlers.updateGetHandler, handler_edit); -router.post('/doUpdateLotOccupancy', permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancy); -router.post('/doCopyLotOccupancy', permissionHandlers.updatePostHandler, handler_doCopyLotOccupancy); -router.post('/doDeleteLotOccupancy', permissionHandlers.updatePostHandler, handler_doDeleteLotOccupancy); -router.post('/doSearchPastOccupants', permissionHandlers.updatePostHandler, handler_doSearchPastOccupants); -router.post('/doAddLotOccupancyOccupant', permissionHandlers.updatePostHandler, handler_doAddLotOccupancyOccupant); -router.post('/doUpdateLotOccupancyOccupant', permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancyOccupant); -router.post('/doDeleteLotOccupancyOccupant', permissionHandlers.updatePostHandler, handler_doDeleteLotOccupancyOccupant); -router.post('/doAddLotOccupancyComment', permissionHandlers.updatePostHandler, handler_doAddLotOccupancyComment); -router.post('/doUpdateLotOccupancyComment', permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancyComment); -router.post('/doDeleteLotOccupancyComment', permissionHandlers.updatePostHandler, handler_doDeleteLotOccupancyComment); -router.post('/doGetFees', permissionHandlers.updatePostHandler, handler_doGetFees); -router.post('/doAddLotOccupancyFee', permissionHandlers.updatePostHandler, handler_doAddLotOccupancyFee); -router.post('/doUpdateLotOccupancyFeeQuantity', permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancyFeeQuantity); -router.post('/doDeleteLotOccupancyFee', permissionHandlers.updatePostHandler, handler_doDeleteLotOccupancyFee); +router.get('/:lotOccupancyId/edit', updateGetHandler, handler_edit); +router.post('/doUpdateLotOccupancy', updatePostHandler, handler_doUpdateLotOccupancy); +router.post('/doCopyLotOccupancy', updatePostHandler, handler_doCopyLotOccupancy); +router.post('/doDeleteLotOccupancy', updatePostHandler, handler_doDeleteLotOccupancy); +router.post('/doSearchPastOccupants', updatePostHandler, handler_doSearchPastOccupants); +router.post('/doAddLotOccupancyOccupant', updatePostHandler, handler_doAddLotOccupancyOccupant); +router.post('/doUpdateLotOccupancyOccupant', updatePostHandler, handler_doUpdateLotOccupancyOccupant); +router.post('/doDeleteLotOccupancyOccupant', updatePostHandler, handler_doDeleteLotOccupancyOccupant); +router.post('/doAddLotOccupancyComment', updatePostHandler, handler_doAddLotOccupancyComment); +router.post('/doUpdateLotOccupancyComment', updatePostHandler, handler_doUpdateLotOccupancyComment); +router.post('/doDeleteLotOccupancyComment', updatePostHandler, handler_doDeleteLotOccupancyComment); +router.post('/doGetFees', updatePostHandler, handler_doGetFees); +router.post('/doAddLotOccupancyFee', updatePostHandler, handler_doAddLotOccupancyFee); +router.post('/doUpdateLotOccupancyFeeQuantity', updatePostHandler, handler_doUpdateLotOccupancyFeeQuantity); +router.post('/doDeleteLotOccupancyFee', updatePostHandler, handler_doDeleteLotOccupancyFee); if (getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { - router.post('/doGetDynamicsGPDocument', permissionHandlers.updatePostHandler, handler_doGetDynamicsGPDocument); + router.post('/doGetDynamicsGPDocument', updatePostHandler, handler_doGetDynamicsGPDocument); } -router.post('/doAddLotOccupancyTransaction', permissionHandlers.updatePostHandler, handler_doAddLotOccupancyTransaction); -router.post('/doUpdateLotOccupancyTransaction', permissionHandlers.updatePostHandler, handler_doUpdateLotOccupancyTransaction); -router.post('/doDeleteLotOccupancyTransaction', permissionHandlers.updatePostHandler, handler_doDeleteLotOccupancyTransaction); +router.post('/doAddLotOccupancyTransaction', updatePostHandler, handler_doAddLotOccupancyTransaction); +router.post('/doUpdateLotOccupancyTransaction', updatePostHandler, handler_doUpdateLotOccupancyTransaction); +router.post('/doDeleteLotOccupancyTransaction', updatePostHandler, handler_doDeleteLotOccupancyTransaction); export default router; diff --git a/routes/lotOccupancies.ts b/routes/lotOccupancies.ts index 471eb4f6..58d12681 100644 --- a/routes/lotOccupancies.ts +++ b/routes/lotOccupancies.ts @@ -25,7 +25,7 @@ import handler_doUpdateLotOccupancyComment from '../handlers/lotOccupancies-post import handler_doUpdateLotOccupancyFeeQuantity from '../handlers/lotOccupancies-post/doUpdateLotOccupancyFeeQuantity.js' 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 { updateGetHandler, updatePostHandler } from '../handlers/permissions.js' import { getConfigProperty } from '../helpers/functions.config.js' export const router = Router() @@ -41,21 +41,17 @@ router.post( // Create -router.get( - '/new', - permissionHandlers.updateGetHandler, - handler_new as RequestHandler -) +router.get('/new', updateGetHandler, handler_new as RequestHandler) router.post( '/doGetOccupancyTypeFields', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doGetOccupancyTypeFields as RequestHandler ) router.post( '/doCreateLotOccupancy', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doCreateLotOccupancy as RequestHandler ) @@ -67,25 +63,25 @@ router.get('/:lotOccupancyId', handler_view as RequestHandler) router.get( '/:lotOccupancyId/edit', - permissionHandlers.updateGetHandler, + updateGetHandler, handler_edit as RequestHandler ) router.post( '/doUpdateLotOccupancy', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doUpdateLotOccupancy as RequestHandler ) router.post( '/doCopyLotOccupancy', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doCopyLotOccupancy as RequestHandler ) router.post( '/doDeleteLotOccupancy', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doDeleteLotOccupancy as RequestHandler ) @@ -93,25 +89,25 @@ router.post( router.post( '/doSearchPastOccupants', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doSearchPastOccupants as RequestHandler ) router.post( '/doAddLotOccupancyOccupant', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doAddLotOccupancyOccupant as RequestHandler ) router.post( '/doUpdateLotOccupancyOccupant', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doUpdateLotOccupancyOccupant as RequestHandler ) router.post( '/doDeleteLotOccupancyOccupant', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doDeleteLotOccupancyOccupant as RequestHandler ) @@ -119,19 +115,19 @@ router.post( router.post( '/doAddLotOccupancyComment', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doAddLotOccupancyComment as RequestHandler ) router.post( '/doUpdateLotOccupancyComment', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doUpdateLotOccupancyComment as RequestHandler ) router.post( '/doDeleteLotOccupancyComment', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doDeleteLotOccupancyComment as RequestHandler ) @@ -139,25 +135,25 @@ router.post( router.post( '/doGetFees', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doGetFees as RequestHandler ) router.post( '/doAddLotOccupancyFee', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doAddLotOccupancyFee as RequestHandler ) router.post( '/doUpdateLotOccupancyFeeQuantity', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doUpdateLotOccupancyFeeQuantity as RequestHandler ) router.post( '/doDeleteLotOccupancyFee', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doDeleteLotOccupancyFee as RequestHandler ) @@ -166,26 +162,26 @@ router.post( if (getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { router.post( '/doGetDynamicsGPDocument', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doGetDynamicsGPDocument as RequestHandler ) } router.post( '/doAddLotOccupancyTransaction', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doAddLotOccupancyTransaction as RequestHandler ) router.post( '/doUpdateLotOccupancyTransaction', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doUpdateLotOccupancyTransaction as RequestHandler ) router.post( '/doDeleteLotOccupancyTransaction', - permissionHandlers.updatePostHandler, + updatePostHandler, handler_doDeleteLotOccupancyTransaction as RequestHandler )