code cleanup, updated prettier rules

deepsource-autofix-76c6eb20
Dan Gowans 2022-10-20 13:40:43 -04:00
parent ae58b8d922
commit c7f60fad91
22 changed files with 52 additions and 100 deletions

View File

@ -1,5 +1,5 @@
import { app } from "../app.js"; import { app } from "../app.js";
import http from "http"; import http from "node:http";
import * as configFunctions from "../helpers/functions.config.js"; import * as configFunctions from "../helpers/functions.config.js";
import exitHook from "exit-hook"; import exitHook from "exit-hook";
import debug from "debug"; import debug from "debug";
@ -22,9 +22,7 @@ const onError = (error) => {
}; };
const onListening = (server) => { const onListening = (server) => {
const addr = server.address(); const addr = server.address();
const bind = typeof addr === "string" const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port.toString();
? "pipe " + addr
: "port " + addr.port.toString();
debugWWW("Listening on " + bind); debugWWW("Listening on " + bind);
}; };
const httpPort = configFunctions.getProperty("application.httpPort"); const httpPort = configFunctions.getProperty("application.httpPort");

View File

@ -2,7 +2,7 @@
import { app } from "../app.js"; import { app } from "../app.js";
import http from "http"; import http from "node:http";
import * as configFunctions from "../helpers/functions.config.js"; import * as configFunctions from "../helpers/functions.config.js";
@ -46,10 +46,7 @@ const onError = (error: ServerError) => {
const onListening = (server: http.Server) => { const onListening = (server: http.Server) => {
const addr = server.address(); const addr = server.address();
const bind = const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port.toString();
typeof addr === "string"
? "pipe " + addr
: "port " + addr.port.toString();
debugWWW("Listening on " + bind); debugWWW("Listening on " + bind);
}; };

View File

@ -1,7 +1,6 @@
import type { RequestHandler } from "express"; import type { RequestHandler } from "express";
export const handler: RequestHandler = (_request, response) => { export const handler: RequestHandler = (_request, response) => {
response.render("admin-cleanup", { response.render("admin-cleanup", {
headTitle: "Database Cleanup" headTitle: "Database Cleanup"
}); });

View File

@ -1,9 +1,6 @@
import type { RequestHandler } from "express"; import type { RequestHandler } from "express";
import { import { getLotTypes, getOccupancyTypes } from "../../helpers/functions.cache.js";
getLotTypes,
getOccupancyTypes
} from "../../helpers/functions.cache.js";
import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js"; import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js";

View File

@ -3,10 +3,9 @@ import type { RequestHandler } from "express";
import { dateToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; import { dateToString } from "@cityssm/expressjs-server-js/dateTimeFns.js";
import { getWorkOrderMilestones } from "../../helpers/lotOccupancyDB/getWorkOrderMilestones.js"; import { getWorkOrderMilestones } from "../../helpers/lotOccupancyDB/getWorkOrderMilestones.js";
import {getWorkOrders} from "../../helpers/lotOccupancyDB/getWorkOrders.js"; import { getWorkOrders } from "../../helpers/lotOccupancyDB/getWorkOrders.js";
export const handler: RequestHandler = (_request, response) => { export const handler: RequestHandler = (_request, response) => {
const currentDateString = dateToString(new Date()); const currentDateString = dateToString(new Date());
const workOrderMilestones = getWorkOrderMilestones( const workOrderMilestones = getWorkOrderMilestones(
@ -20,12 +19,15 @@ export const handler: RequestHandler = (_request, response) => {
} }
); );
const workOrderCount = getWorkOrders({ const workOrderCount = getWorkOrders(
workOrderOpenDateString: currentDateString {
}, { workOrderOpenDateString: currentDateString
limit: 1, },
offset: 0 {
}).count; limit: 1,
offset: 0
}
).count;
response.render("dashboard", { response.render("dashboard", {
headTitle: "Dashboard", headTitle: "Dashboard",

View File

@ -4,10 +4,7 @@ import * as configFunctions from "../../helpers/functions.config.js";
import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js"; import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js";
import { import { getLotTypes, getOccupancyTypes } from "../../helpers/functions.cache.js";
getLotTypes,
getOccupancyTypes
} from "../../helpers/functions.cache.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const maps = getMaps(); const maps = getMaps();
@ -15,8 +12,7 @@ export const handler: RequestHandler = (request, response) => {
const occupancyTypes = getOccupancyTypes(); const occupancyTypes = getOccupancyTypes();
response.render("lotOccupancy-search", { response.render("lotOccupancy-search", {
headTitle: headTitle: configFunctions.getProperty("aliases.lot") + " Occupancy Search",
configFunctions.getProperty("aliases.lot") + " Occupancy Search",
maps, maps,
lotTypes, lotTypes,
occupancyTypes, occupancyTypes,

View File

@ -5,8 +5,7 @@ import * as cacheFunctions from "../../helpers/functions.cache.js";
export const handler = (request, response) => { export const handler = (request, response) => {
const lot = getLot(request.params.lotId); const lot = getLot(request.params.lotId);
if (!lot) { if (!lot) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=lotIdNotFound");
"/lots/?error=lotIdNotFound");
} }
const maps = getMaps(); const maps = getMaps();
const lotTypes = cacheFunctions.getLotTypes(); const lotTypes = cacheFunctions.getLotTypes();

View File

@ -11,8 +11,7 @@ export const handler: RequestHandler = (request, response) => {
if (!lot) { if (!lot) {
return response.redirect( return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") + configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=lotIdNotFound"
"/lots/?error=lotIdNotFound"
); );
} }

View File

@ -4,11 +4,8 @@ export const handler = (request, response) => {
const lotId = request.params.lotId; const lotId = request.params.lotId;
const nextLotId = getNextLotId(lotId); const nextLotId = getNextLotId(lotId);
if (!nextLotId) { if (!nextLotId) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=noNextLotIdFound");
"/lots/?error=noNextLotIdFound");
} }
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/" + nextLotId);
"/lots/" +
nextLotId);
}; };
export default handler; export default handler;

View File

@ -11,15 +11,12 @@ export const handler: RequestHandler = (request, response) => {
if (!nextLotId) { if (!nextLotId) {
return response.redirect( return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") + configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=noNextLotIdFound"
"/lots/?error=noNextLotIdFound"
); );
} }
return response.redirect( return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") + configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/" + nextLotId
"/lots/" +
nextLotId
); );
}; };

View File

@ -7,8 +7,6 @@ export const handler = (request, response) => {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lots/?error=noPreviousLotIdFound"); "/lots/?error=noPreviousLotIdFound");
} }
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/" + previousLotId);
"/lots/" +
previousLotId);
}; };
export default handler; export default handler;

View File

@ -17,9 +17,7 @@ export const handler: RequestHandler = (request, response) => {
} }
return response.redirect( return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") + configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/" + previousLotId
"/lots/" +
previousLotId
); );
}; };

View File

@ -3,8 +3,7 @@ import { getLot } from "../../helpers/lotOccupancyDB/getLot.js";
export const handler = (request, response) => { export const handler = (request, response) => {
const lot = getLot(request.params.lotId); const lot = getLot(request.params.lotId);
if (!lot) { if (!lot) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=lotIdNotFound");
"/lots/?error=lotIdNotFound");
} }
return response.render("lot-view", { return response.render("lot-view", {
headTitle: lot.lotName, headTitle: lot.lotName,

View File

@ -9,8 +9,7 @@ export const handler: RequestHandler = (request, response) => {
if (!lot) { if (!lot) {
return response.redirect( return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") + configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=lotIdNotFound"
"/lots/?error=lotIdNotFound"
); );
} }

View File

@ -9,9 +9,7 @@ import * as recordTypes from "../../types/recordTypes";
export const handler: RequestHandler = async (_request, response) => { export const handler: RequestHandler = async (_request, response) => {
const map: recordTypes.Map = { const map: recordTypes.Map = {
mapCity: configFunctions.getProperty("settings.map.mapCityDefault"), mapCity: configFunctions.getProperty("settings.map.mapCityDefault"),
mapProvince: configFunctions.getProperty( mapProvince: configFunctions.getProperty("settings.map.mapProvinceDefault")
"settings.map.mapProvinceDefault"
)
}; };
const mapSVGs = await getMapSVGs(); const mapSVGs = await getMapSVGs();

View File

@ -4,9 +4,10 @@ export const handler = (request, response) => {
const reportName = request.params.reportName; const reportName = request.params.reportName;
let rows; let rows;
switch (reportName) { switch (reportName) {
default: default: {
rows = getReportData(reportName, request.query); rows = getReportData(reportName, request.query);
break; break;
}
} }
if (!rows) { if (!rows) {
return response.status(404).json({ return response.status(404).json({
@ -15,11 +16,7 @@ export const handler = (request, response) => {
}); });
} }
const csv = papaparse.unparse(rows); const csv = papaparse.unparse(rows);
response.setHeader("Content-Disposition", "attachment; filename=" + response.setHeader("Content-Disposition", "attachment; filename=" + reportName + "-" + Date.now().toString() + ".csv");
reportName +
"-" +
Date.now().toString() +
".csv");
response.setHeader("Content-Type", "text/csv"); response.setHeader("Content-Type", "text/csv");
response.send(csv); response.send(csv);
}; };

View File

@ -1,9 +1,6 @@
import type { RequestHandler } from "express"; import type { RequestHandler } from "express";
import { import { getReportData, ReportParameters } from "../../helpers/lotOccupancyDB/getReportData.js";
getReportData,
ReportParameters
} from "../../helpers/lotOccupancyDB/getReportData.js";
import papaparse from "papaparse"; import papaparse from "papaparse";
@ -13,9 +10,10 @@ export const handler: RequestHandler = (request, response) => {
let rows: unknown[]; let rows: unknown[];
switch (reportName) { switch (reportName) {
default: default: {
rows = getReportData(reportName, request.query as ReportParameters); rows = getReportData(reportName, request.query as ReportParameters);
break; break;
}
} }
if (!rows) { if (!rows) {
@ -29,11 +27,7 @@ export const handler: RequestHandler = (request, response) => {
response.setHeader( response.setHeader(
"Content-Disposition", "Content-Disposition",
"attachment; filename=" + "attachment; filename=" + reportName + "-" + Date.now().toString() + ".csv"
reportName +
"-" +
Date.now().toString() +
".csv"
); );
response.setHeader("Content-Type", "text/csv"); response.setHeader("Content-Type", "text/csv");

View File

@ -1,14 +1,11 @@
import { dateToInteger, dateToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; import { dateToInteger, dateToString } from "@cityssm/expressjs-server-js/dateTimeFns.js";
import type { RequestHandler } from "express"; import type { RequestHandler } from "express";
import { import { getWorkOrderTypes } from "../../helpers/functions.cache.js";
getWorkOrderTypes
} from "../../helpers/functions.cache.js";
import * as recordTypes from "../../types/recordTypes"; import * as recordTypes from "../../types/recordTypes";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const currentDate = new Date(); const currentDate = new Date();
const workOrder: recordTypes.WorkOrder = { const workOrder: recordTypes.WorkOrder = {

View File

@ -3,7 +3,6 @@ import type { RequestHandler } from "express";
import { getWorkOrderTypes } from "../../helpers/functions.cache.js"; import { getWorkOrderTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const workOrderOpenDateString = request.query.workOrderOpenDateString; const workOrderOpenDateString = request.query.workOrderOpenDateString;
const workOrderTypes = getWorkOrderTypes(); const workOrderTypes = getWorkOrderTypes();

View File

@ -27,6 +27,7 @@ export const authenticate = async (userName, password) => {
const safeRedirects = new Set([ const safeRedirects = new Set([
"/admin/cleanup", "/admin/cleanup",
"/admin/fees", "/admin/fees",
"/admin/lottypes",
"/admin/occupancytypes", "/admin/occupancytypes",
"/admin/tables", "/admin/tables",
"/lotoccupancies", "/lotoccupancies",
@ -44,9 +45,9 @@ const safeRedirects = new Set([
export const getSafeRedirectURL = (possibleRedirectURL = "") => { export const getSafeRedirectURL = (possibleRedirectURL = "") => {
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix"); const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
if (typeof possibleRedirectURL === "string") { if (typeof possibleRedirectURL === "string") {
const urlToCheck = (possibleRedirectURL.startsWith(urlPrefix) const urlToCheck = possibleRedirectURL.startsWith(urlPrefix)
? possibleRedirectURL.slice(urlPrefix.length) ? possibleRedirectURL.slice(urlPrefix.length)
: possibleRedirectURL); : possibleRedirectURL;
const urlToCheckLowerCase = urlToCheck.toLowerCase(); const urlToCheckLowerCase = urlToCheck.toLowerCase();
if (safeRedirects.has(urlToCheckLowerCase) || if (safeRedirects.has(urlToCheckLowerCase) ||
/^(\/maps\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) || /^(\/maps\/)\d+(\/edit)?$/.test(urlToCheckLowerCase) ||

View File

@ -14,27 +14,20 @@ const authenticateViaActiveDirectory = async (
try { try {
const ad = new ActiveDirectory(activeDirectoryConfig); const ad = new ActiveDirectory(activeDirectoryConfig);
ad.authenticate( ad.authenticate(userDomain + "\\" + userName, password, async (error, auth) => {
userDomain + "\\" + userName, if (error) {
password, resolve(false);
async (error, auth) => {
if (error) {
resolve(false);
}
resolve(auth);
} }
);
resolve(auth);
});
} catch { } catch {
resolve(false); resolve(false);
} }
}); });
}; };
export const authenticate = async ( export const authenticate = async (userName: string, password: string): Promise<boolean> => {
userName: string,
password: string
): Promise<boolean> => {
if (!userName || userName === "" || !password || password === "") { if (!userName || userName === "" || !password || password === "") {
return false; return false;
} }
@ -42,10 +35,10 @@ export const authenticate = async (
return await authenticateViaActiveDirectory(userName, password); return await authenticateViaActiveDirectory(userName, password);
}; };
const safeRedirects = new Set([ const safeRedirects = new Set([
"/admin/cleanup", "/admin/cleanup",
"/admin/fees", "/admin/fees",
"/admin/lottypes",
"/admin/occupancytypes", "/admin/occupancytypes",
"/admin/tables", "/admin/tables",
"/lotoccupancies", "/lotoccupancies",
@ -65,11 +58,9 @@ export const getSafeRedirectURL = (possibleRedirectURL = "") => {
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix"); const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
if (typeof possibleRedirectURL === "string") { if (typeof possibleRedirectURL === "string") {
const urlToCheck = ( const urlToCheck = possibleRedirectURL.startsWith(urlPrefix)
possibleRedirectURL.startsWith(urlPrefix) ? possibleRedirectURL.slice(urlPrefix.length)
? possibleRedirectURL.slice(urlPrefix.length) : possibleRedirectURL;
: possibleRedirectURL
);
const urlToCheckLowerCase = urlToCheck.toLowerCase(); const urlToCheckLowerCase = urlToCheck.toLowerCase();