code cleanup, updated prettier rules
parent
ae58b8d922
commit
c7f60fad91
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { RequestHandler } from "express";
|
||||
|
||||
export const handler: RequestHandler = (_request, response) => {
|
||||
|
||||
response.render("admin-cleanup", {
|
||||
headTitle: "Database Cleanup"
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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) ||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue