From f98179b433848edc33994b9a97f72536521b19c6 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Mon, 24 Jun 2024 15:02:41 -0400 Subject: [PATCH] linting --- database/getLotOccupancies.js | 11 ++++++----- database/getLotOccupancies.ts | 13 ++++++++----- database/getWorkOrder.js | 4 ++-- database/getWorkOrder.ts | 4 ++-- database/getWorkOrders.js | 26 +++++++++++++++----------- database/getWorkOrders.ts | 26 +++++++++++++++----------- handlers/api-get/milestoneICS.js | 14 ++++---------- handlers/api-get/milestoneICS.ts | 16 +++++----------- handlers/lots-get/edit.js | 2 +- handlers/lots-get/edit.ts | 2 +- handlers/print-get/pdf.js | 3 +-- handlers/print-get/pdf.ts | 5 ++--- handlers/print-get/screen.js | 3 +-- handlers/print-get/screen.ts | 3 +-- helpers/initializer.database.js | 2 +- helpers/initializer.database.ts | 2 +- 16 files changed, 66 insertions(+), 70 deletions(-) diff --git a/database/getLotOccupancies.js b/database/getLotOccupancies.js index bf2541ca..8ac3257e 100644 --- a/database/getLotOccupancies.js +++ b/database/getLotOccupancies.js @@ -19,9 +19,10 @@ function buildWhereClause(filters) { const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, 'o'); if (occupantNameFilters.sqlParameters.length > 0) { sqlWhereClause += - ' and o.lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null' + - occupantNameFilters.sqlWhereClause + - ')'; + ` and o.lotOccupancyId in ( + select lotOccupancyId from LotOccupancyOccupants o + where recordDelete_timeMillis is null + ${occupantNameFilters.sqlWhereClause})`; sqlParameters.push(...occupantNameFilters.sqlParameters); } if ((filters.occupancyTypeId ?? '') !== '') { @@ -106,8 +107,8 @@ export default async function getLotOccupancies(filters, options, connectedDatab left join LotTypes lt on l.lotTypeId = lt.lotTypeId left join Maps m on l.mapId = m.mapId ${sqlWhereClause} - order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc` + - (isLimited ? ` limit ${options.limit} offset ${options.offset}` : '')) + order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc + ${isLimited ? ` limit ${options.limit} offset ${options.offset}` : ''}`) .all(sqlParameters); if (!isLimited) { count = lotOccupancies.length; diff --git a/database/getLotOccupancies.ts b/database/getLotOccupancies.ts index 604dc7b8..18f769a0 100644 --- a/database/getLotOccupancies.ts +++ b/database/getLotOccupancies.ts @@ -68,9 +68,10 @@ function buildWhereClause(filters: GetLotOccupanciesFilters): { ) if (occupantNameFilters.sqlParameters.length > 0) { sqlWhereClause += - ' and o.lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null' + - occupantNameFilters.sqlWhereClause + - ')' + ` and o.lotOccupancyId in ( + select lotOccupancyId from LotOccupancyOccupants o + where recordDelete_timeMillis is null + ${occupantNameFilters.sqlWhereClause})` sqlParameters.push(...occupantNameFilters.sqlParameters) } @@ -207,8 +208,10 @@ export default async function getLotOccupancies( left join LotTypes lt on l.lotTypeId = lt.lotTypeId left join Maps m on l.mapId = m.mapId ${sqlWhereClause} - order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc` + - (isLimited ? ` limit ${options.limit} offset ${options.offset}` : '') + order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId, o.lotOccupancyId desc + ${ + isLimited ? ` limit ${options.limit} offset ${options.offset}` : '' + }` ) .all(sqlParameters) as LotOccupancy[] diff --git a/database/getWorkOrder.js b/database/getWorkOrder.js index 87da8d38..12d45022 100644 --- a/database/getWorkOrder.js +++ b/database/getWorkOrder.js @@ -57,12 +57,12 @@ async function _getWorkOrder(sql, workOrderIdOrWorkOrderNumber, options, connect return workOrder; } export async function getWorkOrderByWorkOrderNumber(workOrderNumber) { - return await _getWorkOrder(baseSQL + ' and w.workOrderNumber = ?', workOrderNumber, { + return await _getWorkOrder(`${baseSQL} and w.workOrderNumber = ?`, workOrderNumber, { includeLotsAndLotOccupancies: true, includeComments: true, includeMilestones: true }); } export default async function getWorkOrder(workOrderId, options, connectedDatabase) { - return await _getWorkOrder(baseSQL + ' and w.workOrderId = ?', workOrderId, options, connectedDatabase); + return await _getWorkOrder(`${baseSQL} and w.workOrderId = ?`, workOrderId, options, connectedDatabase); } diff --git a/database/getWorkOrder.ts b/database/getWorkOrder.ts index 377430f1..75f948a0 100644 --- a/database/getWorkOrder.ts +++ b/database/getWorkOrder.ts @@ -105,7 +105,7 @@ export async function getWorkOrderByWorkOrderNumber( workOrderNumber: string ): Promise { return await _getWorkOrder( - baseSQL + ' and w.workOrderNumber = ?', + `${baseSQL} and w.workOrderNumber = ?`, workOrderNumber, { includeLotsAndLotOccupancies: true, @@ -121,7 +121,7 @@ export default async function getWorkOrder( connectedDatabase?: PoolConnection ): Promise { return await _getWorkOrder( - baseSQL + ' and w.workOrderId = ?', + `${baseSQL} and w.workOrderId = ?`, workOrderId, options, connectedDatabase diff --git a/database/getWorkOrders.js b/database/getWorkOrders.js index 01babf20..3b2bfeb1 100644 --- a/database/getWorkOrders.js +++ b/database/getWorkOrders.js @@ -27,22 +27,26 @@ function buildWhereClause(filters) { const occupantNameFilters = getOccupantNameWhereClause(filters.occupantName, 'o'); if (occupantNameFilters.sqlParameters.length > 0) { sqlWhereClause += - ' and w.workOrderId in (' + - 'select workOrderId from WorkOrderLotOccupancies o' + - ' where recordDelete_timeMillis is null' + - ' and o.lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null' + - occupantNameFilters.sqlWhereClause + - ')' + - ')'; + ` and w.workOrderId in ( + select workOrderId from WorkOrderLotOccupancies o + where recordDelete_timeMillis is null + and o.lotOccupancyId in ( + select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null + ${occupantNameFilters.sqlWhereClause} + ))`; sqlParameters.push(...occupantNameFilters.sqlParameters); } const lotNameFilters = getLotNameWhereClause(filters.lotName, '', 'l'); if (lotNameFilters.sqlParameters.length > 0) { sqlWhereClause += - ' and w.workOrderId in (' + - 'select workOrderId from WorkOrderLots where recordDelete_timeMillis is null and lotId in (select lotId from Lots l where recordDelete_timeMillis is null' + - lotNameFilters.sqlWhereClause + - '))'; + ` and w.workOrderId in ( + select workOrderId from WorkOrderLots + where recordDelete_timeMillis is null + and lotId in ( + select lotId from Lots l + where recordDelete_timeMillis is null + ${lotNameFilters.sqlWhereClause} + ))`; sqlParameters.push(...lotNameFilters.sqlParameters); } if ((filters.lotOccupancyId ?? '') !== '') { diff --git a/database/getWorkOrders.ts b/database/getWorkOrders.ts index b6f159d9..9f9a1420 100644 --- a/database/getWorkOrders.ts +++ b/database/getWorkOrders.ts @@ -67,23 +67,27 @@ function buildWhereClause(filters: GetWorkOrdersFilters): { ) if (occupantNameFilters.sqlParameters.length > 0) { sqlWhereClause += - ' and w.workOrderId in (' + - 'select workOrderId from WorkOrderLotOccupancies o' + - ' where recordDelete_timeMillis is null' + - ' and o.lotOccupancyId in (select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null' + - occupantNameFilters.sqlWhereClause + - ')' + - ')' + ` and w.workOrderId in ( + select workOrderId from WorkOrderLotOccupancies o + where recordDelete_timeMillis is null + and o.lotOccupancyId in ( + select lotOccupancyId from LotOccupancyOccupants o where recordDelete_timeMillis is null + ${occupantNameFilters.sqlWhereClause} + ))` sqlParameters.push(...occupantNameFilters.sqlParameters) } const lotNameFilters = getLotNameWhereClause(filters.lotName, '', 'l') if (lotNameFilters.sqlParameters.length > 0) { sqlWhereClause += - ' and w.workOrderId in (' + - 'select workOrderId from WorkOrderLots where recordDelete_timeMillis is null and lotId in (select lotId from Lots l where recordDelete_timeMillis is null' + - lotNameFilters.sqlWhereClause + - '))' + ` and w.workOrderId in ( + select workOrderId from WorkOrderLots + where recordDelete_timeMillis is null + and lotId in ( + select lotId from Lots l + where recordDelete_timeMillis is null + ${lotNameFilters.sqlWhereClause} + ))` sqlParameters.push(...lotNameFilters.sqlParameters) } diff --git a/handlers/api-get/milestoneICS.js b/handlers/api-get/milestoneICS.js index d42fb881..6126ec30 100644 --- a/handlers/api-get/milestoneICS.js +++ b/handlers/api-get/milestoneICS.js @@ -9,12 +9,9 @@ function escapeHTML(stringToEscape) { return stringToEscape.replaceAll(/[^\d a-z]/gi, (c) => `&#${c.codePointAt(0)};`); } function getUrlRoot(request) { - return ('http://' + - request.hostname + - (getConfigProperty('application.httpPort') === 80 - ? '' - : `:${getConfigProperty('application.httpPort')}`) + - getConfigProperty('reverseProxy.urlPrefix')); + return `http://${request.hostname}${getConfigProperty('application.httpPort') === 80 + ? '' + : `:${getConfigProperty('application.httpPort')}`}${getConfigProperty('reverseProxy.urlPrefix')}`; } function getWorkOrderUrl(request, milestone) { return `${getUrlRoot(request)}/workOrders/${milestone.workOrderId}`; @@ -32,10 +29,7 @@ function buildEventSummary(milestone) { if (summary !== '') { summary += ': '; } - summary += - (occupant.occupantName ?? '') + - ' ' + - (occupant.occupantFamilyName ?? ''); + summary += `${occupant.occupantName ?? ''} ${occupant.occupantFamilyName ?? ''}`; } } } diff --git a/handlers/api-get/milestoneICS.ts b/handlers/api-get/milestoneICS.ts index 475c054b..69e72162 100644 --- a/handlers/api-get/milestoneICS.ts +++ b/handlers/api-get/milestoneICS.ts @@ -23,14 +23,11 @@ function escapeHTML(stringToEscape: string): string { } function getUrlRoot(request: Request): string { - return ( - 'http://' + - request.hostname + - (getConfigProperty('application.httpPort') === 80 + return `http://${request.hostname}${ + getConfigProperty('application.httpPort') === 80 ? '' - : `:${getConfigProperty('application.httpPort')}`) + - getConfigProperty('reverseProxy.urlPrefix') - ) + : `:${getConfigProperty('application.httpPort')}` + }${getConfigProperty('reverseProxy.urlPrefix')}` } function getWorkOrderUrl( @@ -59,10 +56,7 @@ function buildEventSummary(milestone: WorkOrderMilestone): string { summary += ': ' } - summary += - (occupant.occupantName ?? '') + - ' ' + - (occupant.occupantFamilyName ?? '') + summary += `${occupant.occupantName ?? ''} ${occupant.occupantFamilyName ?? ''}` } } } diff --git a/handlers/lots-get/edit.js b/handlers/lots-get/edit.js index 0bf5e957..4238823f 100644 --- a/handlers/lots-get/edit.js +++ b/handlers/lots-get/edit.js @@ -5,7 +5,7 @@ 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(getConfigProperty('reverseProxy.urlPrefix') + '/lots/?error=lotIdNotFound'); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/lots/?error=lotIdNotFound`); return; } const maps = await getMaps(); diff --git a/handlers/lots-get/edit.ts b/handlers/lots-get/edit.ts index 5dae7389..18ef8d5a 100644 --- a/handlers/lots-get/edit.ts +++ b/handlers/lots-get/edit.ts @@ -13,7 +13,7 @@ export default async function handler( if (lot === undefined) { response.redirect( - getConfigProperty('reverseProxy.urlPrefix') + '/lots/?error=lotIdNotFound' + `${getConfigProperty('reverseProxy.urlPrefix')}/lots/?error=lotIdNotFound` ) return } diff --git a/handlers/print-get/pdf.js b/handlers/print-get/pdf.js index a6716070..8db2b32f 100644 --- a/handlers/print-get/pdf.js +++ b/handlers/print-get/pdf.js @@ -20,8 +20,7 @@ export async function handler(request, response, next) { } const printConfig = getPdfPrintConfig(printName); if (printConfig === undefined) { - response.redirect(configFunctions.getConfigProperty('reverseProxy.urlPrefix') + - '/dashboard/?error=printConfigNotFound'); + response.redirect(`${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotFound`); return; } const reportData = await getReportData(printConfig, request.query); diff --git a/handlers/print-get/pdf.ts b/handlers/print-get/pdf.ts index 3bb82594..46b8828a 100644 --- a/handlers/print-get/pdf.ts +++ b/handlers/print-get/pdf.ts @@ -3,7 +3,7 @@ import path from 'node:path' import { convertHTMLToPDF } from '@cityssm/pdf-puppeteer' import * as dateTimeFunctions from '@cityssm/utils-datetime' import camelcase from 'camelcase' -import {renderFile as renderEjsFile } from 'ejs' +import { renderFile as renderEjsFile } from 'ejs' import type { NextFunction, Request, Response } from 'express' import * as configFunctions from '../../helpers/functions.config.js' @@ -44,8 +44,7 @@ export async function handler( if (printConfig === undefined) { response.redirect( - configFunctions.getConfigProperty('reverseProxy.urlPrefix') + - '/dashboard/?error=printConfigNotFound' + `${configFunctions.getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotFound` ) return } diff --git a/handlers/print-get/screen.js b/handlers/print-get/screen.js index b22c592a..c550d358 100644 --- a/handlers/print-get/screen.js +++ b/handlers/print-get/screen.js @@ -9,8 +9,7 @@ export default async function handler(request, response) { } const printConfig = getScreenPrintConfig(printName); if (printConfig === undefined) { - response.redirect(getConfigProperty('reverseProxy.urlPrefix') + - '/dashboard/?error=printConfigNotFound'); + response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotFound`); return; } const reportData = await getReportData(printConfig, request.query); diff --git a/handlers/print-get/screen.ts b/handlers/print-get/screen.ts index 482b8752..0b980489 100644 --- a/handlers/print-get/screen.ts +++ b/handlers/print-get/screen.ts @@ -32,8 +32,7 @@ export default async function handler( if (printConfig === undefined) { response.redirect( - getConfigProperty('reverseProxy.urlPrefix') + - '/dashboard/?error=printConfigNotFound' + `${getConfigProperty('reverseProxy.urlPrefix')}/dashboard/?error=printConfigNotFound` ) return } diff --git a/helpers/initializer.database.js b/helpers/initializer.database.js index 98028edd..760548ae 100644 --- a/helpers/initializer.database.js +++ b/helpers/initializer.database.js @@ -80,7 +80,7 @@ export function initializeDatabase() { .prepare("select name from sqlite_master where type = 'table' and name = 'WorkOrderMilestones'") .get(); if (row === undefined) { - debugSQL('Creating ' + databasePath); + debugSQL(`Creating ${databasePath}`); for (const sql of createStatements) { lotOccupancyDB.prepare(sql).run(); } diff --git a/helpers/initializer.database.ts b/helpers/initializer.database.ts index 33a7cebe..71863dec 100644 --- a/helpers/initializer.database.ts +++ b/helpers/initializer.database.ts @@ -120,7 +120,7 @@ export function initializeDatabase(): boolean { .get() if (row === undefined) { - debugSQL('Creating ' + databasePath) + debugSQL(`Creating ${databasePath}`) for (const sql of createStatements) { lotOccupancyDB.prepare(sql).run()