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

View File

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

View File

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

View File

@ -1,9 +1,6 @@
import type { RequestHandler } from "express";
import {
getLotTypes,
getOccupancyTypes
} from "../../helpers/functions.cache.js";
import { getLotTypes, getOccupancyTypes } from "../../helpers/functions.cache.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 { 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) => {
const currentDateString = dateToString(new Date());
const workOrderMilestones = getWorkOrderMilestones(
@ -20,12 +19,15 @@ export const handler: RequestHandler = (_request, response) => {
}
);
const workOrderCount = getWorkOrders({
workOrderOpenDateString: currentDateString
}, {
limit: 1,
offset: 0
}).count;
const workOrderCount = getWorkOrders(
{
workOrderOpenDateString: currentDateString
},
{
limit: 1,
offset: 0
}
).count;
response.render("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 {
getLotTypes,
getOccupancyTypes
} from "../../helpers/functions.cache.js";
import { getLotTypes, getOccupancyTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = (request, response) => {
const maps = getMaps();
@ -15,8 +12,7 @@ export const handler: RequestHandler = (request, response) => {
const occupancyTypes = getOccupancyTypes();
response.render("lotOccupancy-search", {
headTitle:
configFunctions.getProperty("aliases.lot") + " Occupancy Search",
headTitle: configFunctions.getProperty("aliases.lot") + " Occupancy Search",
maps,
lotTypes,
occupancyTypes,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -48,10 +48,10 @@ export const getFeesByFeeCategory = (
export const getTransactionTotal = (lotOccupancy: recordTypes.LotOccupancy) => {
let transactionTotal = 0;
for (const transaction of lotOccupancy.lotOccupancyTransactions) {
transactionTotal += transaction.transactionAmount;
}
return transactionTotal;
};
};