reformatting with prettier

deepsource-autofix-76c6eb20
Dan Gowans 2022-09-02 16:13:32 -04:00
parent 765bb5220b
commit 77db067a5e
237 changed files with 4866 additions and 4199 deletions

View File

@ -1,61 +1,57 @@
{ {
"root": true, "root": true,
"env": { "env": {
"es6": true "es6": true
}, },
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"project": ["./tsconfig.json", "./public-typescript/tsconfig.json"], "project": ["./tsconfig.json", "./public-typescript/tsconfig.json"],
"ecmaVersion": 2020, "ecmaVersion": 2020,
"sourceType": "module" "sourceType": "module"
}, },
"plugins": [ "plugins": ["@typescript-eslint", "unicorn"],
"@typescript-eslint", "extends": [
"unicorn" "eslint:recommended",
], "plugin:import/recommended",
"extends": [ "plugin:import/typescript",
"eslint:recommended", "plugin:node/recommended",
"plugin:import/recommended", "plugin:promise/recommended",
"plugin:import/typescript", "plugin:unicorn/recommended",
"plugin:node/recommended", "plugin:@typescript-eslint/recommended"
"plugin:promise/recommended",
"plugin:unicorn/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"node/no-missing-import": "off",
"unicorn/consistent-function-scoping": "warn",
"unicorn/empty-brace-spaces": "off",
"unicorn/filename-case": [
"error", {
"case": "camelCase",
"ignore": [
"DB",
"URL"
]
}
], ],
"unicorn/prefer-node-protocol": "off", "rules": {
"unicorn/prevent-abbreviations": [ "node/no-missing-import": "off",
"error", { "unicorn/consistent-function-scoping": "warn",
"replacements": { "unicorn/empty-brace-spaces": "off",
"def": { "unicorn/filename-case": [
"definition": true "error",
}, {
"ele": { "case": "camelCase",
"element": true "ignore": ["DB", "URL"]
}, }
"eles": { ],
"elements": true "unicorn/prefer-node-protocol": "off",
}, "unicorn/prevent-abbreviations": [
"fns": { "error",
"functions": true {
}, "replacements": {
"res": { "def": {
"result": false "definition": true
} },
} "ele": {
} "element": true
] },
} "eles": {
"elements": true
},
"fns": {
"functions": true
},
"res": {
"result": false
}
}
}
]
}
} }

View File

@ -1,5 +1,3 @@
{ {
"reject": [ "reject": ["@fortawesome/fontawesome-free"]
"@fortawesome/fontawesome-free"
]
} }

View File

@ -11,51 +11,47 @@ import exitHook from "exit-hook";
import debug from "debug"; import debug from "debug";
const debugWWW = debug("lot-occupancy-system:www"); const debugWWW = debug("lot-occupancy-system:www");
let httpServer: http.Server; let httpServer: http.Server;
interface ServerError extends Error { interface ServerError extends Error {
syscall: string; syscall: string;
code: string; code: string;
} }
const onError = (error: ServerError) => { const onError = (error: ServerError) => {
if (error.syscall !== "listen") {
throw error;
}
if (error.syscall !== "listen") { // handle specific listen errors with friendly messages
throw error; switch (error.code) {
} // eslint-disable-next-line no-fallthrough
case "EACCES":
debugWWW("Requires elevated privileges");
process.exit(1);
// break;
// handle specific listen errors with friendly messages // eslint-disable-next-line no-fallthrough
switch (error.code) { case "EADDRINUSE":
debugWWW("Port is already in use.");
process.exit(1);
// break;
// eslint-disable-next-line no-fallthrough // eslint-disable-next-line no-fallthrough
case "EACCES": default:
debugWWW("Requires elevated privileges"); throw error;
process.exit(1); }
// break;
// eslint-disable-next-line no-fallthrough
case "EADDRINUSE":
debugWWW("Port is already in use.");
process.exit(1);
// break;
// eslint-disable-next-line no-fallthrough
default:
throw error;
}
}; };
const onListening = (server: http.Server) => { const onListening = (server: http.Server) => {
const addr = server.address();
const addr = server.address(); const bind =
typeof addr === "string"
? "pipe " + addr
: "port " + addr.port.toString();
const bind = typeof addr === "string" debugWWW("Listening on " + bind);
? "pipe " + addr
: "port " + addr.port.toString();
debugWWW("Listening on " + bind);
}; };
/** /**
@ -65,25 +61,22 @@ const onListening = (server: http.Server) => {
const httpPort = configFunctions.getProperty("application.httpPort"); const httpPort = configFunctions.getProperty("application.httpPort");
if (httpPort) { if (httpPort) {
httpServer = http.createServer(app);
httpServer = http.createServer(app); httpServer.listen(httpPort);
httpServer.listen(httpPort); httpServer.on("error", onError);
httpServer.on("listening", () => {
onListening(httpServer);
});
httpServer.on("error", onError); debugWWW("HTTP listening on " + httpPort.toString());
httpServer.on("listening", () => {
onListening(httpServer);
});
debugWWW("HTTP listening on " + httpPort.toString());
} }
exitHook(() => { exitHook(() => {
if (httpServer) {
if (httpServer) { debugWWW("Closing HTTP");
debugWWW("Closing HTTP"); httpServer.close();
httpServer.close(); httpServer = undefined;
httpServer = undefined; }
}
}); });

View File

@ -1,10 +1,6 @@
import { import { logout } from "../../support/index.js";
logout
} from "../../support/index.js";
describe("Login Page", () => { describe("Login Page", () => {
before(logout); before(logout);
it("Has no detectable accessibility issues", () => { it("Has no detectable accessibility issues", () => {
@ -29,11 +25,11 @@ describe("Login Page", () => {
.should("have.length", 1) .should("have.length", 1)
.invoke("attr", "type") .invoke("attr", "type")
.should("equal", "password"); .should("equal", "password");
}) });
it("Contains a help link", () => { it("Contains a help link", () => {
cy.get("a").contains("help", { cy.get("a").contains("help", {
matchCase: false matchCase: false
}); });
}); });
}); });

View File

@ -1,12 +1,9 @@
import type { RequestHandler } from "express"; import type { RequestHandler } from "express";
export const handler: RequestHandler = (_request, response) => { export const handler: RequestHandler = (_request, response) => {
response.render("dashboard", {
response.render("dashboard", { headTitle: "Dashboard"
headTitle: "Dashboard" });
});
}; };
export default handler; export default handler;

View File

@ -4,12 +4,16 @@ import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js
export const handler = (request, response) => { export const handler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId); const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
if (!lotOccupancy) { if (!lotOccupancy) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lotOccupancies/?error=lotOccupancyIdNotFound");
} }
const occupancyTypes = getOccupancyTypes(); const occupancyTypes = getOccupancyTypes();
const lotOccupantTypes = getLotOccupantTypes(); const lotOccupantTypes = getLotOccupantTypes();
return response.render("lotOccupancy-edit", { return response.render("lotOccupancy-edit", {
headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Update", headTitle: configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" Update",
lotOccupancy, lotOccupancy,
occupancyTypes, occupancyTypes,
lotOccupantTypes, lotOccupantTypes,

View File

@ -1,6 +1,4 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import {
getLotOccupantTypes, getLotOccupantTypes,
@ -9,24 +7,27 @@ import {
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
getLotOccupancy
} from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId); const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
if (!lotOccupancy) { if (!lotOccupancy) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lotOccupancies/?error=lotOccupancyIdNotFound"
);
} }
const occupancyTypes = getOccupancyTypes(); const occupancyTypes = getOccupancyTypes();
const lotOccupantTypes = getLotOccupantTypes(); const lotOccupantTypes = getLotOccupantTypes();
return response.render("lotOccupancy-edit", { return response.render("lotOccupancy-edit", {
headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Update", headTitle:
configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" Update",
lotOccupancy, lotOccupancy,
occupancyTypes, occupancyTypes,
@ -35,5 +36,4 @@ export const handler: RequestHandler = (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -17,7 +17,11 @@ export const handler = (request, response) => {
} }
const occupancyTypes = getOccupancyTypes(); const occupancyTypes = getOccupancyTypes();
return response.render("lotOccupancy-edit", { return response.render("lotOccupancy-edit", {
headTitle: "Create a New " + configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Record", headTitle: "Create a New " +
configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" Record",
lotOccupancy, lotOccupancy,
occupancyTypes, occupancyTypes,
isCreate: true isCreate: true

View File

@ -1,26 +1,19 @@
import type { RequestHandler } from "express";
import { import {
dateToInteger, dateToInteger,
dateToString dateToString
} from "@cityssm/expressjs-server-js/dateTimeFns.js"; } from "@cityssm/expressjs-server-js/dateTimeFns.js";
import type {
RequestHandler
} from "express";
import { import { getOccupancyTypes } from "../../helpers/functions.cache.js";
getOccupancyTypes
} from "../../helpers/functions.cache.js";
import { import { getLot } from "../../helpers/lotOccupancyDB/getLot.js";
getLot
} from "../../helpers/lotOccupancyDB/getLot.js";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const startDate = new Date(); const startDate = new Date();
const lotOccupancy: recordTypes.LotOccupancy = { const lotOccupancy: recordTypes.LotOccupancy = {
@ -39,7 +32,12 @@ export const handler: RequestHandler = (request, response) => {
const occupancyTypes = getOccupancyTypes(); const occupancyTypes = getOccupancyTypes();
return response.render("lotOccupancy-edit", { return response.render("lotOccupancy-edit", {
headTitle: "Create a New " + configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Record", headTitle:
"Create a New " +
configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" Record",
lotOccupancy, lotOccupancy,
occupancyTypes, occupancyTypes,
@ -47,5 +45,4 @@ export const handler: RequestHandler = (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -3,10 +3,14 @@ import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js
export const handler = (request, response) => { export const handler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId); const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
if (!lotOccupancy) { if (!lotOccupancy) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lotOccupancies/?error=lotOccupancyIdNotFound");
} }
return response.render("lotOccupancy-print", { return response.render("lotOccupancy-print", {
headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Print", headTitle: configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" Print",
lotOccupancy lotOccupancy
}); });
}; };

View File

@ -1,27 +1,27 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
getLotOccupancy
} from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId); const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
if (!lotOccupancy) { if (!lotOccupancy) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lotOccupancies/?error=lotOccupancyIdNotFound"
);
} }
return response.render("lotOccupancy-print", { return response.render("lotOccupancy-print", {
headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Print", headTitle:
configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" Print",
lotOccupancy lotOccupancy
}); });
}; };
export default handler;
export default handler;

View File

@ -1,24 +1,22 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js";
import { import {
getMaps getLotTypes,
} from "../../helpers/lotOccupancyDB/getMaps.js"; getOccupancyTypes
} from "../../helpers/functions.cache.js";
import { 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();
const lotTypes = getLotTypes(); const lotTypes = getLotTypes();
const occupancyTypes = getOccupancyTypes(); const occupancyTypes = getOccupancyTypes();
response.render("lotOccupancy-search", { response.render("lotOccupancy-search", {
headTitle: configFunctions.getProperty("aliases.lot") + " Occupancy Search", headTitle:
configFunctions.getProperty("aliases.lot") + " Occupancy Search",
maps, maps,
lotTypes, lotTypes,
occupancyTypes, occupancyTypes,
@ -26,5 +24,4 @@ export const handler: RequestHandler = (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -3,10 +3,14 @@ import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js
export const handler = (request, response) => { export const handler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId); const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
if (!lotOccupancy) { if (!lotOccupancy) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lotOccupancies/?error=lotOccupancyIdNotFound");
} }
return response.render("lotOccupancy-view", { return response.render("lotOccupancy-view", {
headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " View", headTitle: configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" View",
lotOccupancy lotOccupancy
}); });
}; };

View File

@ -1,27 +1,27 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
getLotOccupancy
} from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId); const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
if (!lotOccupancy) { if (!lotOccupancy) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lotOccupancies/?error=lotOccupancyIdNotFound"
);
} }
return response.render("lotOccupancy-view", { return response.render("lotOccupancy-view", {
headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " View", headTitle:
configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" View",
lotOccupancy lotOccupancy
}); });
}; };
export default handler;
export default handler;

View File

@ -1,21 +1,15 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { addLotOccupancyComment } from "../../helpers/lotOccupancyDB/addLotOccupancyComment.js";
addLotOccupancyComment
} from "../../helpers/lotOccupancyDB/addLotOccupancyComment.js";
import {
getLotOccupancyComments
} from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
import { getLotOccupancyComments } from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
addLotOccupancyComment(request.body, request.session); addLotOccupancyComment(request.body, request.session);
const lotOccupancyComments = getLotOccupancyComments(request.body.lotOccupancyId); const lotOccupancyComments = getLotOccupancyComments(
request.body.lotOccupancyId
);
response.json({ response.json({
success: true, success: true,
@ -23,5 +17,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,18 +1,10 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { addLotOccupancyFee } from "../../helpers/lotOccupancyDB/addLotOccupancyFee.js";
addLotOccupancyFee
} from "../../helpers/lotOccupancyDB/addLotOccupancyFee.js";
import {
getLotOccupancyFees
} from "../../helpers/lotOccupancyDB/getLotOccupancyFees.js";
import { getLotOccupancyFees } from "../../helpers/lotOccupancyDB/getLotOccupancyFees.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
addLotOccupancyFee(request.body, request.session); addLotOccupancyFee(request.body, request.session);
const lotOccupancyFees = getLotOccupancyFees(request.body.lotOccupancyId); const lotOccupancyFees = getLotOccupancyFees(request.body.lotOccupancyId);
@ -23,5 +15,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,21 +1,15 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { addLotOccupancyOccupant } from "../../helpers/lotOccupancyDB/addLotOccupancyOccupant.js";
addLotOccupancyOccupant
} from "../../helpers/lotOccupancyDB/addLotOccupancyOccupant.js";
import {
getLotOccupancyOccupants
} from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
import { getLotOccupancyOccupants } from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
addLotOccupancyOccupant(request.body, request.session); addLotOccupancyOccupant(request.body, request.session);
const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId); const lotOccupancyOccupants = getLotOccupancyOccupants(
request.body.lotOccupancyId
);
response.json({ response.json({
success: true, success: true,
@ -23,5 +17,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,21 +1,15 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { addLotOccupancyTransaction } from "../../helpers/lotOccupancyDB/addLotOccupancyTransaction.js";
addLotOccupancyTransaction
} from "../../helpers/lotOccupancyDB/addLotOccupancyTransaction.js";
import {
getLotOccupancyTransactions
} from "../../helpers/lotOccupancyDB/getLotOccupancyTransactions.js";
import { getLotOccupancyTransactions } from "../../helpers/lotOccupancyDB/getLotOccupancyTransactions.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
addLotOccupancyTransaction(request.body, request.session); addLotOccupancyTransaction(request.body, request.session);
const lotOccupancyTransactions = getLotOccupancyTransactions(request.body.lotOccupancyId); const lotOccupancyTransactions = getLotOccupancyTransactions(
request.body.lotOccupancyId
);
response.json({ response.json({
success: true, success: true,
@ -23,5 +17,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
addLotOccupancy
} from "../../helpers/lotOccupancyDB/addLotOccupancy.js";
import { addLotOccupancy } from "../../helpers/lotOccupancyDB/addLotOccupancy.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const lotOccupancyId = addLotOccupancy(request.body, request.session); const lotOccupancyId = addLotOccupancy(request.body, request.session);
response.json({ response.json({
@ -17,5 +11,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,20 +1,16 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
deleteLotOccupancy
} from "../../helpers/lotOccupancyDB/deleteLotOccupancy.js";
import { deleteLotOccupancy } from "../../helpers/lotOccupancyDB/deleteLotOccupancy.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = deleteLotOccupancy(
const success = deleteLotOccupancy(request.body.lotOccupancyId, request.session); request.body.lotOccupancyId,
request.session
);
response.json({ response.json({
success success
}); });
}; };
export default handler;
export default handler;

View File

@ -1,19 +1,18 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { deleteLotOccupancyComment } from "../../helpers/lotOccupancyDB/deleteLotOccupancyComment.js";
deleteLotOccupancyComment
} from "../../helpers/lotOccupancyDB/deleteLotOccupancyComment.js";
import {getLotOccupancyComments} from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
import { getLotOccupancyComments } from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = deleteLotOccupancyComment(
request.body.lotOccupancyCommentId,
request.session
);
const success = deleteLotOccupancyComment(request.body.lotOccupancyCommentId, request.session); const lotOccupancyComments = getLotOccupancyComments(
request.body.lotOccupancyId
const lotOccupancyComments = getLotOccupancyComments(request.body.lotOccupancyId); );
response.json({ response.json({
success, success,
@ -21,5 +20,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,19 +1,15 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { deleteLotOccupancyFee } from "../../helpers/lotOccupancyDB/deleteLotOccupancyFee.js";
deleteLotOccupancyFee
} from "../../helpers/lotOccupancyDB/deleteLotOccupancyFee.js";
import {
getLotOccupancyFees
} from "../../helpers/lotOccupancyDB/getLotOccupancyFees.js";
import { getLotOccupancyFees } from "../../helpers/lotOccupancyDB/getLotOccupancyFees.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = deleteLotOccupancyFee(
const success = deleteLotOccupancyFee(request.body.lotOccupancyId, request.body.feeId, request.session); request.body.lotOccupancyId,
request.body.feeId,
request.session
);
const lotOccupancyFees = getLotOccupancyFees(request.body.lotOccupancyId); const lotOccupancyFees = getLotOccupancyFees(request.body.lotOccupancyId);
@ -23,5 +19,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,21 +1,19 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { deleteLotOccupancyOccupant } from "../../helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js";
deleteLotOccupancyOccupant
} from "../../helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js";
import {
getLotOccupancyOccupants
} from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
import { getLotOccupancyOccupants } from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = deleteLotOccupancyOccupant(
request.body.lotOccupancyId,
request.body.lotOccupantIndex,
request.session
);
const success = deleteLotOccupancyOccupant(request.body.lotOccupancyId, request.body.lotOccupantIndex, request.session); const lotOccupancyOccupants = getLotOccupancyOccupants(
request.body.lotOccupancyId
const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId); );
response.json({ response.json({
success, success,
@ -23,5 +21,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,21 +1,19 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { deleteLotOccupancyTransaction } from "../../helpers/lotOccupancyDB/deleteLotOccupancyTransaction.js";
deleteLotOccupancyTransaction
} from "../../helpers/lotOccupancyDB/deleteLotOccupancyTransaction.js";
import {
getLotOccupancyTransactions
} from "../../helpers/lotOccupancyDB/getLotOccupancyTransactions.js";
import { getLotOccupancyTransactions } from "../../helpers/lotOccupancyDB/getLotOccupancyTransactions.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = deleteLotOccupancyTransaction(
request.body.lotOccupancyId,
request.body.transactionIndex,
request.session
);
const success = deleteLotOccupancyTransaction(request.body.lotOccupancyId, request.body.transactionIndex, request.session); const lotOccupancyTransactions = getLotOccupancyTransactions(
request.body.lotOccupancyId
const lotOccupancyTransactions = getLotOccupancyTransactions(request.body.lotOccupancyId); );
response.json({ response.json({
success, success,
@ -23,5 +21,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -10,7 +10,7 @@ export const handler = (request, response) => {
includeFees: true includeFees: true
}); });
response.json({ response.json({
feeCategories, feeCategories
}); });
}; };
export default handler; export default handler;

View File

@ -1,33 +1,27 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
getLotOccupancy
} from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
import {
getFeeCategories
} from "../../helpers/lotOccupancyDB/getFeeCategories.js";
import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const lotOccupancyId = request.body.lotOccupancyId; const lotOccupancyId = request.body.lotOccupancyId;
const lotOccupancy = getLotOccupancy(lotOccupancyId); const lotOccupancy = getLotOccupancy(lotOccupancyId);
const feeCategories = getFeeCategories({ const feeCategories = getFeeCategories(
occupancyTypeId: lotOccupancy.occupancyTypeId, {
lotTypeId: lotOccupancy.lotTypeId occupancyTypeId: lotOccupancy.occupancyTypeId,
}, { lotTypeId: lotOccupancy.lotTypeId
includeFees: true },
}); {
includeFees: true
}
);
response.json({ response.json({
feeCategories, feeCategories
}); });
}; };
export default handler;
export default handler;

View File

@ -1,18 +1,15 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { getOccupancyTypeById } from "../../helpers/functions.cache.js"; import { getOccupancyTypeById } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const result = getOccupancyTypeById(
const result = getOccupancyTypeById(Number.parseInt(request.body.occupancyTypeId, 10)); Number.parseInt(request.body.occupancyTypeId, 10)
);
response.json({ response.json({
occupancyTypeFields: result.occupancyTypeFields occupancyTypeFields: result.occupancyTypeFields
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
getLotOccupancies
} from "../../helpers/lotOccupancyDB/getLotOccupancies.js";
import { getLotOccupancies } from "../../helpers/lotOccupancyDB/getLotOccupancies.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const result = getLotOccupancies(request.body, { const result = getLotOccupancies(request.body, {
limit: request.body.limit, limit: request.body.limit,
offset: request.body.offset, offset: request.body.offset,
@ -21,5 +15,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
updateLotOccupancy
} from "../../helpers/lotOccupancyDB/updateLotOccupancy.js";
import { updateLotOccupancy } from "../../helpers/lotOccupancyDB/updateLotOccupancy.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = updateLotOccupancy(request.body, request.session); const success = updateLotOccupancy(request.body, request.session);
response.json({ response.json({
@ -17,5 +11,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,19 +1,15 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { updateLotOccupancyComment } from "../../helpers/lotOccupancyDB/updateLotOccupancyComment.js";
updateLotOccupancyComment
} from "../../helpers/lotOccupancyDB/updateLotOccupancyComment.js";
import {getLotOccupancyComments} from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
import { getLotOccupancyComments } from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = updateLotOccupancyComment(request.body, request.session); const success = updateLotOccupancyComment(request.body, request.session);
const lotOccupancyComments = getLotOccupancyComments(request.body.lotOccupancyId); const lotOccupancyComments = getLotOccupancyComments(
request.body.lotOccupancyId
);
response.json({ response.json({
success, success,
@ -21,5 +17,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,21 +1,15 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { updateLotOccupancyOccupant } from "../../helpers/lotOccupancyDB/updateLotOccupancyOccupant.js";
updateLotOccupancyOccupant
} from "../../helpers/lotOccupancyDB/updateLotOccupancyOccupant.js";
import {
getLotOccupancyOccupants
} from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
import { getLotOccupancyOccupants } from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = updateLotOccupancyOccupant(request.body, request.session); const success = updateLotOccupancyOccupant(request.body, request.session);
const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId); const lotOccupancyOccupants = getLotOccupancyOccupants(
request.body.lotOccupancyId
);
response.json({ response.json({
success, success,
@ -23,5 +17,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -5,7 +5,8 @@ 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") + "/lots/?error=lotIdNotFound"); return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lots/?error=lotIdNotFound");
} }
const maps = getMaps(); const maps = getMaps();
const lotTypes = cacheFunctions.getLotTypes(); const lotTypes = cacheFunctions.getLotTypes();

View File

@ -7,26 +7,27 @@ import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js";
import * as cacheFunctions from "../../helpers/functions.cache.js"; import * as cacheFunctions from "../../helpers/functions.cache.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const lot = getLot(request.params.lotId);
const lot = getLot(request.params.lotId); if (!lot) {
return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lots/?error=lotIdNotFound"
);
}
if (!lot) { const maps = getMaps();
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=lotIdNotFound"); const lotTypes = cacheFunctions.getLotTypes();
} const lotStatuses = cacheFunctions.getLotStatuses();
const maps = getMaps(); return response.render("lot-edit", {
const lotTypes = cacheFunctions.getLotTypes(); headTitle: lot.lotName,
const lotStatuses = cacheFunctions.getLotStatuses(); lot,
isCreate: false,
return response.render("lot-edit", { maps,
headTitle: lot.lotName, lotTypes,
lot, lotStatuses
isCreate: false, });
maps,
lotTypes,
lotStatuses
});
}; };
export default handler; export default handler;

View File

@ -7,26 +7,23 @@ import * as cacheFunctions 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 lot: recordTypes.Lot = {
lotOccupancies: []
};
const lot: recordTypes.Lot = { const maps = getMaps();
lotOccupancies: [] const lotTypes = cacheFunctions.getLotTypes();
}; const lotStatuses = cacheFunctions.getLotStatuses();
const maps = getMaps(); response.render("lot-edit", {
const lotTypes = cacheFunctions.getLotTypes(); headTitle: "Create a New " + configFunctions.getProperty("aliases.lot"),
const lotStatuses = cacheFunctions.getLotStatuses(); lot,
isCreate: true,
response.render("lot-edit", { maps,
headTitle: "Create a New " + configFunctions.getProperty("aliases.lot"), lotTypes,
lot, lotStatuses
isCreate: true, });
maps,
lotTypes,
lotStatuses
});
}; };
export default handler; export default handler;

View File

@ -4,8 +4,11 @@ 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") + "/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; export default handler;

View File

@ -1,26 +1,26 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getNextLotId } from "../../helpers/lotOccupancyDB/getNextLotId.js";
getNextLotId
} from "../../helpers/lotOccupancyDB/getNextLotId.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (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") + "/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;
export default handler;

View File

@ -4,8 +4,11 @@ export const handler = (request, response) => {
const lotId = request.params.lotId; const lotId = request.params.lotId;
const previousLotId = getPreviousLotId(lotId); const previousLotId = getPreviousLotId(lotId);
if (!previousLotId) { if (!previousLotId) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=noPreviousLotIdFound"); 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; export default handler;

View File

@ -1,26 +1,26 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getPreviousLotId } from "../../helpers/lotOccupancyDB/getPreviousLotId.js";
getPreviousLotId
} from "../../helpers/lotOccupancyDB/getPreviousLotId.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const lotId = request.params.lotId; const lotId = request.params.lotId;
const previousLotId = getPreviousLotId(lotId); const previousLotId = getPreviousLotId(lotId);
if (!previousLotId) { if (!previousLotId) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=noPreviousLotIdFound"); 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;
export default handler;

View File

@ -1,22 +1,16 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js";
getMaps
} from "../../helpers/lotOccupancyDB/getMaps.js";
import { getLotTypes, getLotStatuses } from "../../helpers/functions.cache.js"; import { getLotTypes, getLotStatuses } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const maps = getMaps(); const maps = getMaps();
const lotTypes = getLotTypes(); const lotTypes = getLotTypes();
const lotStatuses = getLotStatuses(); const lotStatuses = getLotStatuses();
response.render("lot-search", { response.render("lot-search", {
headTitle: configFunctions.getProperty("aliases.lot") + " Search", headTitle: configFunctions.getProperty("aliases.lot") + " Search",
maps, maps,
@ -26,5 +20,4 @@ export const handler: RequestHandler = (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -3,7 +3,8 @@ 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") + "/lots/?error=lotIdNotFound"); return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lots/?error=lotIdNotFound");
} }
return response.render("lot-view", { return response.render("lot-view", {
headTitle: lot.lotName, headTitle: lot.lotName,

View File

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

View File

@ -1,18 +1,10 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { addLotComment } from "../../helpers/lotOccupancyDB/addLotComment.js";
addLotComment
} from "../../helpers/lotOccupancyDB/addLotComment.js";
import {
getLotComments
} from "../../helpers/lotOccupancyDB/getLotComments.js";
import { getLotComments } from "../../helpers/lotOccupancyDB/getLotComments.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
addLotComment(request.body, request.session); addLotComment(request.body, request.session);
const lotComments = getLotComments(request.body.lotId); const lotComments = getLotComments(request.body.lotId);
@ -23,5 +15,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
addLot
} from "../../helpers/lotOccupancyDB/addLot.js";
import { addLot } from "../../helpers/lotOccupancyDB/addLot.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const lotId = addLot(request.body, request.session); const lotId = addLot(request.body, request.session);
response.json({ response.json({
@ -17,5 +11,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,19 +1,14 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { deleteLotComment } from "../../helpers/lotOccupancyDB/deleteLotComment.js";
deleteLotComment
} from "../../helpers/lotOccupancyDB/deleteLotComment.js";
import {
getLotComments
} from "../../helpers/lotOccupancyDB/getLotComments.js";
import { getLotComments } from "../../helpers/lotOccupancyDB/getLotComments.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = deleteLotComment(
const success = deleteLotComment(request.body.lotCommentId, request.session); request.body.lotCommentId,
request.session
);
const lotComments = getLotComments(request.body.lotId); const lotComments = getLotComments(request.body.lotId);
@ -23,5 +18,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
getLots
} from "../../helpers/lotOccupancyDB/getLots.js";
import { getLots } from "../../helpers/lotOccupancyDB/getLots.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const result = getLots(request.body, { const result = getLots(request.body, {
limit: request.body.limit, limit: request.body.limit,
offset: request.body.offset offset: request.body.offset
@ -20,5 +14,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
updateLot
} from "../../helpers/lotOccupancyDB/updateLot.js";
import { updateLot } from "../../helpers/lotOccupancyDB/updateLot.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = updateLot(request.body, request.session); const success = updateLot(request.body, request.session);
response.json({ response.json({
@ -17,5 +11,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,18 +1,10 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import { updateLotComment } from "../../helpers/lotOccupancyDB/updateLotComment.js";
updateLotComment
} from "../../helpers/lotOccupancyDB/updateLotComment.js";
import {
getLotComments
} from "../../helpers/lotOccupancyDB/getLotComments.js";
import { getLotComments } from "../../helpers/lotOccupancyDB/getLotComments.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = updateLotComment(request.body, request.session); const success = updateLotComment(request.body, request.session);
const lotComments = getLotComments(request.body.lotId); const lotComments = getLotComments(request.body.lotId);
@ -23,5 +15,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -4,7 +4,8 @@ import { getMapSVGs } from "../../helpers/functions.map.js";
export const handler = async (request, response) => { export const handler = async (request, response) => {
const map = getMap(request.params.mapId); const map = getMap(request.params.mapId);
if (!map) { if (!map) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/maps/?error=mapIdNotFound"); return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/maps/?error=mapIdNotFound");
} }
const mapSVGs = await getMapSVGs(); const mapSVGs = await getMapSVGs();
response.render("map-edit", { response.render("map-edit", {

View File

@ -6,24 +6,24 @@ import { getMap } from "../../helpers/lotOccupancyDB/getMap.js";
import { getMapSVGs } from "../../helpers/functions.map.js"; import { getMapSVGs } from "../../helpers/functions.map.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const map = getMap(request.params.mapId);
const map = getMap(request.params.mapId); if (!map) {
return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") +
"/maps/?error=mapIdNotFound"
);
}
if (!map) { const mapSVGs = await getMapSVGs();
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/maps/?error=mapIdNotFound");
}
const mapSVGs = await getMapSVGs(); response.render("map-edit", {
headTitle: map.mapName,
response.render("map-edit", { isCreate: false,
headTitle: map.mapName, map,
isCreate: false, mapSVGs
map, });
mapSVGs
});
}; };
export default handler;
export default handler;

View File

@ -1,21 +1,17 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getMapSVGs } from "../../helpers/functions.map.js";
getMapSVGs
} from "../../helpers/functions.map.js";
import * as recordTypes from "../../types/recordTypes"; 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("settings.map.mapProvinceDefault") mapProvince: configFunctions.getProperty(
"settings.map.mapProvinceDefault"
)
}; };
const mapSVGs = await getMapSVGs(); const mapSVGs = await getMapSVGs();
@ -28,5 +24,4 @@ export const handler: RequestHandler = async (_request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,16 +1,10 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js";
getMaps
} from "../../helpers/lotOccupancyDB/getMaps.js";
export const handler: RequestHandler = (_request, response) => { export const handler: RequestHandler = (_request, response) => {
const maps = getMaps(); const maps = getMaps();
response.render("map-search", { response.render("map-search", {
@ -19,5 +13,4 @@ export const handler: RequestHandler = (_request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -3,7 +3,8 @@ import { getMap } from "../../helpers/lotOccupancyDB/getMap.js";
export const handler = (request, response) => { export const handler = (request, response) => {
const map = getMap(request.params.mapId); const map = getMap(request.params.mapId);
if (!map) { if (!map) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/maps/?error=mapIdNotFound"); return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/maps/?error=mapIdNotFound");
} }
response.render("map-view", { response.render("map-view", {
headTitle: map.mapName, headTitle: map.mapName,

View File

@ -1,20 +1,17 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getMap } from "../../helpers/lotOccupancyDB/getMap.js";
getMap
} from "../../helpers/lotOccupancyDB/getMap.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const map = getMap(request.params.mapId); const map = getMap(request.params.mapId);
if (!map) { if (!map) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/maps/?error=mapIdNotFound"); return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") +
"/maps/?error=mapIdNotFound"
);
} }
response.render("map-view", { response.render("map-view", {
@ -23,5 +20,4 @@ export const handler: RequestHandler = (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
addMap
} from "../../helpers/lotOccupancyDB/addMap.js";
import { addMap } from "../../helpers/lotOccupancyDB/addMap.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const mapId = addMap(request.body, request.session); const mapId = addMap(request.body, request.session);
response.json({ response.json({
@ -17,5 +11,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
deleteMap
} from "../../helpers/lotOccupancyDB/deleteMap.js";
import { deleteMap } from "../../helpers/lotOccupancyDB/deleteMap.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = deleteMap(request.body.mapId, request.session); const success = deleteMap(request.body.mapId, request.session);
response.json({ response.json({
@ -16,5 +10,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
updateMap
} from "../../helpers/lotOccupancyDB/updateMap.js";
import { updateMap } from "../../helpers/lotOccupancyDB/updateMap.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = updateMap(request.body, request.session); const success = updateMap(request.body, request.session);
response.json({ response.json({
@ -17,5 +11,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -2,9 +2,7 @@ import * as configFunctions from "../helpers/functions.config.js";
import * as userFunctions from "../helpers/functions.user.js"; import * as userFunctions from "../helpers/functions.user.js";
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix"); const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
export const forbiddenJSON = (response) => { export const forbiddenJSON = (response) => {
return response return response.status(403).json({
.status(403)
.json({
success: false, success: false,
message: "Forbidden" message: "Forbidden"
}); });

View File

@ -4,56 +4,43 @@ import * as configFunctions from "../helpers/functions.config.js";
import * as userFunctions from "../helpers/functions.user.js"; import * as userFunctions from "../helpers/functions.user.js";
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix"); const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
export const forbiddenJSON = (response: Response): Response => { export const forbiddenJSON = (response: Response): Response => {
return response.status(403).json({
return response success: false,
.status(403) message: "Forbidden"
.json({
success: false,
message: "Forbidden"
}); });
}; };
export const adminGetHandler: RequestHandler = (request, response, next) => { export const adminGetHandler: RequestHandler = (request, response, next) => {
if (userFunctions.userIsAdmin(request)) {
return next();
}
if (userFunctions.userIsAdmin(request)) { return response.redirect(urlPrefix + "/dashboard");
return next();
}
return response.redirect(urlPrefix + "/dashboard");
}; };
export const adminPostHandler: RequestHandler = (request, response, next) => { export const adminPostHandler: RequestHandler = (request, response, next) => {
if (userFunctions.userIsAdmin(request)) {
return next();
}
if (userFunctions.userIsAdmin(request)) { return response.json(forbiddenJSON);
return next();
}
return response.json(forbiddenJSON);
}; };
export const updateGetHandler: RequestHandler = (request, response, next) => { export const updateGetHandler: RequestHandler = (request, response, next) => {
if (userFunctions.userCanUpdate(request)) {
return next();
}
if (userFunctions.userCanUpdate(request)) { return response.redirect(urlPrefix + "/dashboard");
return next();
}
return response.redirect(urlPrefix + "/dashboard");
}; };
export const updatePostHandler: RequestHandler = (request, response, next) => { export const updatePostHandler: RequestHandler = (request, response, next) => {
if (userFunctions.userCanUpdate(request)) {
return next();
}
if (userFunctions.userCanUpdate(request)) { return response.json(forbiddenJSON);
return next();
}
return response.json(forbiddenJSON);
}; };

View File

@ -9,15 +9,17 @@ export const handler = (request, response) => {
break; break;
} }
if (!rows) { if (!rows) {
return response return response.status(404).json({
.status(404)
.json({
success: false, success: false,
message: "Report Not Found" message: "Report Not Found"
}); });
} }
const csv = papaparse.unparse(rows); 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.setHeader("Content-Type", "text/csv");
response.send(csv); response.send(csv);
}; };

View File

@ -1,6 +1,4 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import { import {
getReportData, getReportData,
@ -9,38 +7,38 @@ import {
import papaparse from "papaparse"; import papaparse from "papaparse";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const reportName = request.params.reportName; const reportName = request.params.reportName;
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) {
return response return response.status(404).json({
.status(404) success: false,
.json({ message: "Report Not Found"
success: false, });
message: "Report Not Found"
});
} }
const csv = papaparse.unparse(rows); const csv = papaparse.unparse(rows);
response.setHeader("Content-Disposition", response.setHeader(
"attachment; filename=" + reportName + "-" + Date.now().toString() + ".csv"); "Content-Disposition",
"attachment; filename=" +
reportName +
"-" +
Date.now().toString() +
".csv"
);
response.setHeader("Content-Type", "text/csv"); response.setHeader("Content-Type", "text/csv");
response.send(csv); response.send(csv);
}; };
export default handler;
export default handler;

View File

@ -1,12 +1,8 @@
import type { import type { RequestHandler } from "express";
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 workOrderTypes = getWorkOrderTypes(); const workOrderTypes = getWorkOrderTypes();
response.render("workOrder-search", { response.render("workOrder-search", {
@ -15,5 +11,4 @@ export const handler: RequestHandler = (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -3,7 +3,8 @@ import { getWorkOrder } from "../../helpers/lotOccupancyDB/getWorkOrder.js";
export const handler = (request, response) => { export const handler = (request, response) => {
const workOrder = getWorkOrder(request.params.workOrderId); const workOrder = getWorkOrder(request.params.workOrderId);
if (!workOrder) { if (!workOrder) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/workOrders/?error=workOrderIdNotFound"); return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/workOrders/?error=workOrderIdNotFound");
} }
response.render("workOrder-view", { response.render("workOrder-view", {
headTitle: "Work Order #" + workOrder.workOrderNumber, headTitle: "Work Order #" + workOrder.workOrderNumber,

View File

@ -1,20 +1,17 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import * as configFunctions from "../../helpers/functions.config.js"; import * as configFunctions from "../../helpers/functions.config.js";
import { import { getWorkOrder } from "../../helpers/lotOccupancyDB/getWorkOrder.js";
getWorkOrder
} from "../../helpers/lotOccupancyDB/getWorkOrder.js";
export const handler: RequestHandler = (request, response) => { export const handler: RequestHandler = (request, response) => {
const workOrder = getWorkOrder(request.params.workOrderId); const workOrder = getWorkOrder(request.params.workOrderId);
if (!workOrder) { if (!workOrder) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/workOrders/?error=workOrderIdNotFound"); return response.redirect(
configFunctions.getProperty("reverseProxy.urlPrefix") +
"/workOrders/?error=workOrderIdNotFound"
);
} }
response.render("workOrder-view", { response.render("workOrder-view", {
@ -23,5 +20,4 @@ export const handler: RequestHandler = (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type { import type { RequestHandler } from "express";
RequestHandler
} from "express";
import {
getWorkOrders
} from "../../helpers/lotOccupancyDB/getWorkOrders.js";
import { getWorkOrders } from "../../helpers/lotOccupancyDB/getWorkOrders.js";
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const result = getWorkOrders(request.body, { const result = getWorkOrders(request.body, {
limit: request.body.limit, limit: request.body.limit,
offset: request.body.offset offset: request.body.offset
@ -20,5 +14,4 @@ export const handler: RequestHandler = async (request, response) => {
}); });
}; };
export default handler;
export default handler;

View File

@ -6,37 +6,38 @@ const userDomain = configFunctions.getProperty("application.userDomain");
const activeDirectoryConfig = configFunctions.getProperty("activeDirectory"); const activeDirectoryConfig = configFunctions.getProperty("activeDirectory");
const authenticateViaActiveDirectory = async (
userName: string,
password: string
): Promise<boolean> => {
return new Promise((resolve) => {
try {
const ad = new ActiveDirectory(activeDirectoryConfig);
ad.authenticate(
userDomain + "\\" + userName,
password,
async (error, auth) => {
if (error) {
resolve(false);
}
const authenticateViaActiveDirectory = async (userName: string, password: string): Promise<boolean> => { resolve(auth);
}
return new Promise((resolve) => { );
} catch {
try { resolve(false);
const ad = new ActiveDirectory(activeDirectoryConfig);
ad.authenticate(userDomain + "\\" + userName, password, async (error, auth) => {
if (error) {
resolve(false);
} }
});
};
resolve(auth); export const authenticate = async (
}); userName: string,
password: string
} catch { ): Promise<boolean> => {
resolve(false); if (!userName || userName === "" || !password || password === "") {
return false;
} }
});
}; return await authenticateViaActiveDirectory(userName, password);
export const authenticate = async (userName: string, password: string): Promise<boolean> => {
if (!userName || userName === "" || !password || password === "") {
return false;
}
return await authenticateViaActiveDirectory(userName, password);
}; };

View File

@ -3,7 +3,6 @@ import { getLotStatuses as getLotStatusesFromDatabase } from "./lotOccupancyDB/g
import { getLotTypes as getLotTypesFromDatabase } from "./lotOccupancyDB/getLotTypes.js"; import { getLotTypes as getLotTypesFromDatabase } from "./lotOccupancyDB/getLotTypes.js";
import { getOccupancyTypes as getOccupancyTypesFromDatabase } from "./lotOccupancyDB/getOccupancyTypes.js"; import { getOccupancyTypes as getOccupancyTypesFromDatabase } from "./lotOccupancyDB/getOccupancyTypes.js";
import { getWorkOrderTypes as getWorkOrderTypesFromDatabase } from "./lotOccupancyDB/getWorkOrderTypes.js"; import { getWorkOrderTypes as getWorkOrderTypesFromDatabase } from "./lotOccupancyDB/getWorkOrderTypes.js";
import { getOccupancyType } from "./lotOccupancyDB/getOccupancyType.js";
let lotOccupantTypes; let lotOccupantTypes;
export function getLotOccupantTypes() { export function getLotOccupantTypes() {
if (!lotOccupantTypes) { if (!lotOccupantTypes) {
@ -21,7 +20,8 @@ export function getLotOccupantTypesByLotOccupantType(lotOccupantType) {
const cachedLotOccupantTypes = getLotOccupantTypes(); const cachedLotOccupantTypes = getLotOccupantTypes();
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase(); const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
return cachedLotOccupantTypes.find((currentLotOccupantType) => { return cachedLotOccupantTypes.find((currentLotOccupantType) => {
return currentLotOccupantType.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase; return (currentLotOccupantType.lotOccupantType.toLowerCase() ===
lotOccupantTypeLowerCase);
}); });
} }
export function clearLotOccupantTypesCache() { export function clearLotOccupantTypesCache() {
@ -74,7 +74,6 @@ export function clearLotTypesCache() {
lotTypes = undefined; lotTypes = undefined;
} }
let occupancyTypes; let occupancyTypes;
const occupancyTypeMap = new Map();
export function getOccupancyTypes() { export function getOccupancyTypes() {
if (!occupancyTypes) { if (!occupancyTypes) {
occupancyTypes = getOccupancyTypesFromDatabase(); occupancyTypes = getOccupancyTypesFromDatabase();
@ -82,26 +81,21 @@ export function getOccupancyTypes() {
return occupancyTypes; return occupancyTypes;
} }
export function getOccupancyTypeById(occupancyTypeId) { export function getOccupancyTypeById(occupancyTypeId) {
if (!occupancyTypeMap.has(occupancyTypeId)) { const cachedOccupancyTypes = getOccupancyTypes();
const occupancyType = getOccupancyType(occupancyTypeId); return cachedOccupancyTypes.find((currentOccupancyType) => {
occupancyTypeMap.set(occupancyTypeId, occupancyType); return currentOccupancyType.occupancyTypeId === occupancyTypeId;
} });
return occupancyTypeMap.get(occupancyTypeId);
} }
export function getOccupancyTypeByOccupancyType(occupancyTypeString) { export function getOccupancyTypeByOccupancyType(occupancyTypeString) {
const cachedOccupancyTypes = getOccupancyTypes(); const cachedOccupancyTypes = getOccupancyTypes();
const occupancyTypeLowerCase = occupancyTypeString.toLowerCase(); const occupancyTypeLowerCase = occupancyTypeString.toLowerCase();
let occupancyType = cachedOccupancyTypes.find((currentOccupancyType) => { return cachedOccupancyTypes.find((currentOccupancyType) => {
return currentOccupancyType.occupancyType.toLowerCase() === occupancyTypeLowerCase; return (currentOccupancyType.occupancyType.toLowerCase() ===
occupancyTypeLowerCase);
}); });
if (occupancyType) {
occupancyType = getOccupancyTypeById(occupancyType.occupancyTypeId);
}
return occupancyType;
} }
export function clearOccupancyTypesCache() { export function clearOccupancyTypesCache() {
occupancyTypes = undefined; occupancyTypes = undefined;
occupancyTypeMap.clear();
} }
let workOrderTypes; let workOrderTypes;
export function getWorkOrderTypes() { export function getWorkOrderTypes() {

View File

@ -1,26 +1,12 @@
import { import { getLotOccupantTypes as getLotOccupantTypesFromDatabase } from "./lotOccupancyDB/getLotOccupantTypes.js";
getLotOccupantTypes as getLotOccupantTypesFromDatabase
} from "./lotOccupancyDB/getLotOccupantTypes.js";
import { import { getLotStatuses as getLotStatusesFromDatabase } from "./lotOccupancyDB/getLotStatuses.js";
getLotStatuses as getLotStatusesFromDatabase
} from "./lotOccupancyDB/getLotStatuses.js";
import { import { getLotTypes as getLotTypesFromDatabase } from "./lotOccupancyDB/getLotTypes.js";
getLotTypes as getLotTypesFromDatabase
} from "./lotOccupancyDB/getLotTypes.js";
import { import { getOccupancyTypes as getOccupancyTypesFromDatabase } from "./lotOccupancyDB/getOccupancyTypes.js";
getOccupancyTypes as getOccupancyTypesFromDatabase
} from "./lotOccupancyDB/getOccupancyTypes.js";
import { import { getWorkOrderTypes as getWorkOrderTypesFromDatabase } from "./lotOccupancyDB/getWorkOrderTypes.js";
getWorkOrderTypes as getWorkOrderTypesFromDatabase
} from "./lotOccupancyDB/getWorkOrderTypes.js";
import {
getOccupancyType
} from "./lotOccupancyDB/getOccupancyType.js";
import type * as recordTypes from "../types/recordTypes"; import type * as recordTypes from "../types/recordTypes";
@ -31,7 +17,6 @@ import type * as recordTypes from "../types/recordTypes";
let lotOccupantTypes: recordTypes.LotOccupantType[]; let lotOccupantTypes: recordTypes.LotOccupantType[];
export function getLotOccupantTypes() { export function getLotOccupantTypes() {
if (!lotOccupantTypes) { if (!lotOccupantTypes) {
lotOccupantTypes = getLotOccupantTypesFromDatabase(); lotOccupantTypes = getLotOccupantTypesFromDatabase();
} }
@ -40,7 +25,6 @@ export function getLotOccupantTypes() {
} }
export function getLotOccupantTypeById(lotOccupantTypeId: number) { export function getLotOccupantTypeById(lotOccupantTypeId: number) {
const cachedLotOccupantTypes = getLotOccupantTypes(); const cachedLotOccupantTypes = getLotOccupantTypes();
return cachedLotOccupantTypes.find((currentLotOccupantType) => { return cachedLotOccupantTypes.find((currentLotOccupantType) => {
@ -49,13 +33,15 @@ export function getLotOccupantTypeById(lotOccupantTypeId: number) {
} }
export function getLotOccupantTypesByLotOccupantType(lotOccupantType: string) { export function getLotOccupantTypesByLotOccupantType(lotOccupantType: string) {
const cachedLotOccupantTypes = getLotOccupantTypes(); const cachedLotOccupantTypes = getLotOccupantTypes();
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase(); const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
return cachedLotOccupantTypes.find((currentLotOccupantType) => { return cachedLotOccupantTypes.find((currentLotOccupantType) => {
return currentLotOccupantType.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase; return (
currentLotOccupantType.lotOccupantType.toLowerCase() ===
lotOccupantTypeLowerCase
);
}); });
} }
@ -63,7 +49,6 @@ export function clearLotOccupantTypesCache() {
lotOccupantTypes = undefined; lotOccupantTypes = undefined;
} }
/* /*
* Lot Statuses * Lot Statuses
*/ */
@ -71,7 +56,6 @@ export function clearLotOccupantTypesCache() {
let lotStatuses: recordTypes.LotStatus[]; let lotStatuses: recordTypes.LotStatus[];
export function getLotStatuses() { export function getLotStatuses() {
if (!lotStatuses) { if (!lotStatuses) {
lotStatuses = getLotStatusesFromDatabase(); lotStatuses = getLotStatusesFromDatabase();
} }
@ -80,7 +64,6 @@ export function getLotStatuses() {
} }
export function getLotStatusById(lotStatusId: number) { export function getLotStatusById(lotStatusId: number) {
const cachedLotStatuses = getLotStatuses(); const cachedLotStatuses = getLotStatuses();
return cachedLotStatuses.find((currentLotStatus) => { return cachedLotStatuses.find((currentLotStatus) => {
@ -89,7 +72,6 @@ export function getLotStatusById(lotStatusId: number) {
} }
export function getLotStatusByLotStatus(lotStatus: string) { export function getLotStatusByLotStatus(lotStatus: string) {
const cachedLotStatuses = getLotStatuses(); const cachedLotStatuses = getLotStatuses();
const lotStatusLowerCase = lotStatus.toLowerCase(); const lotStatusLowerCase = lotStatus.toLowerCase();
@ -110,7 +92,6 @@ export function clearLotStatusesCache() {
let lotTypes: recordTypes.LotType[]; let lotTypes: recordTypes.LotType[];
export function getLotTypes() { export function getLotTypes() {
if (!lotTypes) { if (!lotTypes) {
lotTypes = getLotTypesFromDatabase(); lotTypes = getLotTypesFromDatabase();
} }
@ -119,7 +100,6 @@ export function getLotTypes() {
} }
export function getLotTypeById(lotTypeId: number) { export function getLotTypeById(lotTypeId: number) {
const cachedLotTypes = getLotTypes(); const cachedLotTypes = getLotTypes();
return cachedLotTypes.find((currentLotType) => { return cachedLotTypes.find((currentLotType) => {
@ -128,7 +108,6 @@ export function getLotTypeById(lotTypeId: number) {
} }
export function getLotTypesByLotType(lotType: string) { export function getLotTypesByLotType(lotType: string) {
const cachedLotTypes = getLotTypes(); const cachedLotTypes = getLotTypes();
const lotTypeLowerCase = lotType.toLowerCase(); const lotTypeLowerCase = lotType.toLowerCase();
@ -147,11 +126,8 @@ export function clearLotTypesCache() {
*/ */
let occupancyTypes: recordTypes.OccupancyType[]; let occupancyTypes: recordTypes.OccupancyType[];
const occupancyTypeMap = new Map < number,
recordTypes.OccupancyType > ();
export function getOccupancyTypes() { export function getOccupancyTypes() {
if (!occupancyTypes) { if (!occupancyTypes) {
occupancyTypes = getOccupancyTypesFromDatabase(); occupancyTypes = getOccupancyTypesFromDatabase();
} }
@ -160,37 +136,28 @@ export function getOccupancyTypes() {
} }
export function getOccupancyTypeById(occupancyTypeId: number) { export function getOccupancyTypeById(occupancyTypeId: number) {
const cachedOccupancyTypes = getOccupancyTypes();
if (!occupancyTypeMap.has(occupancyTypeId)) { return cachedOccupancyTypes.find((currentOccupancyType) => {
return currentOccupancyType.occupancyTypeId === occupancyTypeId;
const occupancyType = getOccupancyType(occupancyTypeId); });
occupancyTypeMap.set(occupancyTypeId, occupancyType);
}
return occupancyTypeMap.get(occupancyTypeId);
} }
export function getOccupancyTypeByOccupancyType(occupancyTypeString: string) { export function getOccupancyTypeByOccupancyType(occupancyTypeString: string) {
const cachedOccupancyTypes = getOccupancyTypes(); const cachedOccupancyTypes = getOccupancyTypes();
const occupancyTypeLowerCase = occupancyTypeString.toLowerCase(); const occupancyTypeLowerCase = occupancyTypeString.toLowerCase();
let occupancyType = cachedOccupancyTypes.find((currentOccupancyType) => { return cachedOccupancyTypes.find((currentOccupancyType) => {
return currentOccupancyType.occupancyType.toLowerCase() === occupancyTypeLowerCase; return (
currentOccupancyType.occupancyType.toLowerCase() ===
occupancyTypeLowerCase
);
}); });
// get object with related fields
if (occupancyType) {
occupancyType = getOccupancyTypeById(occupancyType.occupancyTypeId);
}
return occupancyType;
} }
export function clearOccupancyTypesCache() { export function clearOccupancyTypesCache() {
occupancyTypes = undefined; occupancyTypes = undefined;
occupancyTypeMap.clear();
} }
/* /*
@ -200,7 +167,6 @@ export function clearOccupancyTypesCache() {
let workOrderTypes: recordTypes.WorkOrderType[]; let workOrderTypes: recordTypes.WorkOrderType[];
export function getWorkOrderTypes() { export function getWorkOrderTypes() {
if (!workOrderTypes) { if (!workOrderTypes) {
workOrderTypes = getWorkOrderTypesFromDatabase(); workOrderTypes = getWorkOrderTypesFromDatabase();
} }
@ -210,4 +176,4 @@ export function getWorkOrderTypes() {
export function clearWorkOrderTypesCache() { export function clearWorkOrderTypesCache() {
workOrderTypes = undefined; workOrderTypes = undefined;
} }

View File

@ -43,6 +43,6 @@ export function getProperty(propertyName) {
} }
return currentObject; return currentObject;
} }
export const keepAliveMillis = getProperty("session.doKeepAlive") ? export const keepAliveMillis = getProperty("session.doKeepAlive")
Math.max(getProperty("session.maxAgeMillis") / 2, getProperty("session.maxAgeMillis") - (10 * 60 * 1000)) : ? Math.max(getProperty("session.maxAgeMillis") / 2, getProperty("session.maxAgeMillis") - 10 * 60 * 1000)
0; : 0;

View File

@ -1,21 +1,20 @@
/* eslint-disable node/no-unpublished-import */ /* eslint-disable node/no-unpublished-import */
import { import { config } from "../data/config.js";
config
} from "../data/config.js";
import type * as configTypes from "../types/configTypes"; import type * as configTypes from "../types/configTypes";
/* /*
* SET UP FALLBACK VALUES * SET UP FALLBACK VALUES
*/ */
const configFallbackValues = new Map < string, const configFallbackValues = new Map<string, unknown>();
unknown > ();
configFallbackValues.set("application.applicationName", "Lot Occupancy System"); configFallbackValues.set("application.applicationName", "Lot Occupancy System");
configFallbackValues.set("application.backgroundURL", "/images/cemetery-background.jpg"); configFallbackValues.set(
"application.backgroundURL",
"/images/cemetery-background.jpg"
);
configFallbackValues.set("application.logoURL", "/images/cemetery-logo.png"); configFallbackValues.set("application.logoURL", "/images/cemetery-logo.png");
configFallbackValues.set("application.httpPort", 7000); configFallbackValues.set("application.httpPort", 7000);
configFallbackValues.set("application.useTestDatabases", false); configFallbackValues.set("application.useTestDatabases", false);
@ -41,37 +40,55 @@ configFallbackValues.set("aliases.occupancy", "Occupancy");
configFallbackValues.set("aliases.occupancies", "Occupancies"); configFallbackValues.set("aliases.occupancies", "Occupancies");
configFallbackValues.set("aliases.occupant", "Occupant"); configFallbackValues.set("aliases.occupant", "Occupant");
configFallbackValues.set("aliases.occupants", "Occupants"); configFallbackValues.set("aliases.occupants", "Occupants");
configFallbackValues.set("aliases.externalReceiptNumber", "External Receipt Number"); configFallbackValues.set(
"aliases.externalReceiptNumber",
"External Receipt Number"
);
configFallbackValues.set("settings.map.mapCityDefault", ""); configFallbackValues.set("settings.map.mapCityDefault", "");
configFallbackValues.set("settings.map.mapProvinceDefault", ""); configFallbackValues.set("settings.map.mapProvinceDefault", "");
configFallbackValues.set("settings.lot.lotNameSortNameFunction", (lotName: string) => lotName); configFallbackValues.set(
"settings.lot.lotNameSortNameFunction",
(lotName: string) => lotName
);
configFallbackValues.set("settings.lotOccupancy.occupancyEndDateIsRequired", true); configFallbackValues.set(
"settings.lotOccupancy.occupancyEndDateIsRequired",
true
);
configFallbackValues.set("settings.lotOccupancy.occupantCityDefault", ""); configFallbackValues.set("settings.lotOccupancy.occupantCityDefault", "");
configFallbackValues.set("settings.lotOccupancy.occupantProvinceDefault", ""); configFallbackValues.set("settings.lotOccupancy.occupantProvinceDefault", "");
configFallbackValues.set("settings.fees.taxPercentageDefault", 0); configFallbackValues.set("settings.fees.taxPercentageDefault", 0);
/* /*
* Set up function overloads * Set up function overloads
*/ */
export function getProperty(propertyName: "application.applicationName"): string; export function getProperty(
propertyName: "application.applicationName"
): string;
export function getProperty(propertyName: "application.logoURL"): string; export function getProperty(propertyName: "application.logoURL"): string;
export function getProperty(propertyName: "application.httpPort"): number; export function getProperty(propertyName: "application.httpPort"): number;
export function getProperty(propertyName: "application.userDomain"): string; export function getProperty(propertyName: "application.userDomain"): string;
export function getProperty(propertyName: "application.useTestDatabases"): boolean; export function getProperty(
propertyName: "application.useTestDatabases"
): boolean;
export function getProperty(propertyName: "activeDirectory"): configTypes.ConfigActiveDirectory; export function getProperty(
propertyName: "activeDirectory"
): configTypes.ConfigActiveDirectory;
export function getProperty(propertyName: "users.canLogin"): string[]; export function getProperty(propertyName: "users.canLogin"): string[];
export function getProperty(propertyName: "users.canUpdate"): string[]; export function getProperty(propertyName: "users.canUpdate"): string[];
export function getProperty(propertyName: "users.isAdmin"): string[]; export function getProperty(propertyName: "users.isAdmin"): string[];
export function getProperty(propertyName: "reverseProxy.disableCompression"): boolean; export function getProperty(
propertyName: "reverseProxy.disableCompression"
): boolean;
export function getProperty(propertyName: "reverseProxy.disableEtag"): boolean; export function getProperty(propertyName: "reverseProxy.disableEtag"): boolean;
export function getProperty(propertyName: "reverseProxy.urlPrefix"): string; export function getProperty(propertyName: "reverseProxy.urlPrefix"): string;
@ -88,29 +105,55 @@ export function getProperty(propertyName: "aliases.occupancy"): string;
export function getProperty(propertyName: "aliases.occupancies"): string; export function getProperty(propertyName: "aliases.occupancies"): string;
export function getProperty(propertyName: "aliases.occupant"): string; export function getProperty(propertyName: "aliases.occupant"): string;
export function getProperty(propertyName: "aliases.occupants"): string; export function getProperty(propertyName: "aliases.occupants"): string;
export function getProperty(propertyName: "aliases.externalReceiptNumber"): string;
export function getProperty(propertyName: "settings.map.mapCityDefault"): string; export function getProperty(
export function getProperty(propertyName: "settings.map.mapProvinceDefault"): string; propertyName: "aliases.externalReceiptNumber"
): string;
export function getProperty(propertyName: "settings.lot.lotNamePattern"): RegExp; export function getProperty(
export function getProperty(propertyName: "settings.lot.lotNameSortNameFunction"): (lotName: string) => string; propertyName: "settings.map.mapCityDefault"
): string;
export function getProperty(propertyName: "settings.lotOccupancy.occupancyEndDateIsRequired"): boolean; export function getProperty(
export function getProperty(propertyName: "settings.lotOccupancy.occupantCityDefault"): string; propertyName: "settings.map.mapProvinceDefault"
export function getProperty(propertyName: "settings.lotOccupancy.occupantProvinceDefault"): string; ): string;
export function getProperty(propertyName: "settings.fees.taxPercentageDefault"): number; export function getProperty(
propertyName: "settings.lot.lotNamePattern"
): RegExp;
export function getProperty(
propertyName: "settings.lot.lotNameSortNameFunction"
): (lotName: string) => string;
export function getProperty(
propertyName: "settings.lotOccupancy.occupancyEndDateIsRequired"
): boolean;
export function getProperty(
propertyName: "settings.lotOccupancy.occupantCityDefault"
): string;
export function getProperty(
propertyName: "settings.lotOccupancy.occupantProvinceDefault"
): string;
export function getProperty(
propertyName: "settings.fees.taxPercentageDefault"
): number;
export function getProperty(propertyName: string): unknown { export function getProperty(propertyName: string): unknown {
const propertyNameSplit = propertyName.split("."); const propertyNameSplit = propertyName.split(".");
let currentObject = config; let currentObject = config;
for (const propertyNamePiece of propertyNameSplit) { for (const propertyNamePiece of propertyNameSplit) {
if (
if (Object.prototype.hasOwnProperty.call(currentObject, propertyNamePiece)) { Object.prototype.hasOwnProperty.call(
currentObject,
propertyNamePiece
)
) {
currentObject = currentObject[propertyNamePiece]; currentObject = currentObject[propertyNamePiece];
continue; continue;
} }
@ -121,10 +164,9 @@ export function getProperty(propertyName: string): unknown {
return currentObject; return currentObject;
} }
export const keepAliveMillis = export const keepAliveMillis = getProperty("session.doKeepAlive")
getProperty("session.doKeepAlive") ? ? Math.max(
Math.max( getProperty("session.maxAgeMillis") / 2,
getProperty("session.maxAgeMillis") / 2, getProperty("session.maxAgeMillis") - 10 * 60 * 1000
getProperty("session.maxAgeMillis") - (10 * 60 * 1000) )
) : : 0;
0;

View File

@ -1,10 +1,8 @@
export const calculateFeeAmount = (fee, lotOccupancy) => { export const calculateFeeAmount = (fee, lotOccupancy) => {
return fee.feeFunction ? return fee.feeFunction ? 0 : fee.feeAmount || 0;
0 :
(fee.feeAmount || 0);
}; };
export const calculateTaxAmount = (fee, feeAmount) => { export const calculateTaxAmount = (fee, feeAmount) => {
return fee.taxPercentage ? return fee.taxPercentage
feeAmount * (fee.taxPercentage / 100) : ? feeAmount * (fee.taxPercentage / 100)
(fee.taxAmount || 0); : fee.taxAmount || 0;
}; };

View File

@ -1,17 +1,14 @@
import * as recordTypes from "../types/recordTypes"; import * as recordTypes from "../types/recordTypes";
export const calculateFeeAmount = (
export const calculateFeeAmount = (fee: recordTypes.Fee, lotOccupancy: recordTypes.LotOccupancy): number => { fee: recordTypes.Fee,
lotOccupancy: recordTypes.LotOccupancy
return fee.feeFunction ? ): number => {
0 : return fee.feeFunction ? 0 : fee.feeAmount || 0;
(fee.feeAmount || 0);
}; };
export const calculateTaxAmount = (fee: recordTypes.Fee, feeAmount: number) => { export const calculateTaxAmount = (fee: recordTypes.Fee, feeAmount: number) => {
return fee.taxPercentage
return fee.taxPercentage ? ? feeAmount * (fee.taxPercentage / 100)
feeAmount * (fee.taxPercentage / 100) : : fee.taxAmount || 0;
(fee.taxAmount || 0); };
};

View File

@ -2,15 +2,13 @@ import fs from "node:fs/promises";
let mapSVGs: string[]; let mapSVGs: string[];
export async function getMapSVGs () { export async function getMapSVGs() {
if (!mapSVGs) {
if (!mapSVGs) {
const files = await fs.readdir("./public/images/maps/"); const files = await fs.readdir("./public/images/maps/");
const SVGs: string[] = []; const SVGs: string[] = [];
for (const file of files) { for (const file of files) {
if (file.toLowerCase().endsWith(".svg")) { if (file.toLowerCase().endsWith(".svg")) {
SVGs.push(file); SVGs.push(file);
} }
@ -20,4 +18,4 @@ export async function getMapSVGs () {
} }
return mapSVGs; return mapSVGs;
} }

View File

@ -1,25 +1,21 @@
import type { Request } from "express"; import type { Request } from "express";
export const userIsAdmin = (request: Request): boolean => { export const userIsAdmin = (request: Request): boolean => {
const user = request.session?.user;
const user = request.session?.user; if (!user) {
return false;
}
if (!user) { return user.userProperties.isAdmin;
return false;
}
return user.userProperties.isAdmin;
}; };
export const userCanUpdate = (request: Request): boolean => { export const userCanUpdate = (request: Request): boolean => {
const user = request.session?.user;
const user = request.session?.user; if (!user) {
return false;
}
if (!user) { return user.userProperties.canUpdate;
return false;
}
return user.userProperties.canUpdate;
}; };

View File

@ -1,43 +1,24 @@
import { import { lotOccupancyDB as databasePath } from "../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../data/databasePaths.js";
import { import { initializeDatabase } from "./initializer.database.js";
initializeDatabase
} from "./initializer.database.js";
import { import { addLotType } from "./lotOccupancyDB/addLotType.js";
addLotType
} from "./lotOccupancyDB/addLotType.js";
import { import { addOccupancyType } from "./lotOccupancyDB/addOccupancyType.js";
addOccupancyType
} from "./lotOccupancyDB/addOccupancyType.js";
import { import { addOccupancyTypeField } from "./lotOccupancyDB/addOccupancyTypeField.js";
addOccupancyTypeField
} from "./lotOccupancyDB/addOccupancyTypeField.js";
import { import { addLotStatus } from "./lotOccupancyDB/addLotStatus.js";
addLotStatus
} from "./lotOccupancyDB/addLotStatus.js";
import { import { addLotOccupantType } from "./lotOccupancyDB/addLotOccupantType.js";
addLotOccupantType
} from "./lotOccupancyDB/addLotOccupantType.js";
import { import { addFeeCategory } from "./lotOccupancyDB/addFeeCategory.js";
addFeeCategory
} from "./lotOccupancyDB/addFeeCategory.js";
import type { import type { PartialSession } from "../types/recordTypes.js";
PartialSession
} from "../types/recordTypes.js";
import Debug from "debug"; import Debug from "debug";
const debug = Debug("lot-occupancy-system:initialize"); const debug = Debug("lot-occupancy-system:initialize");
const session: PartialSession = { const session: PartialSession = {
user: { user: {
userName: "init.cemetery", userName: "init.cemetery",
@ -48,9 +29,7 @@ const session: PartialSession = {
} }
}; };
const initializeCemeteryDatabase = () => { const initializeCemeteryDatabase = () => {
/* /*
* Ensure database does not already exist * Ensure database does not already exist
*/ */
@ -60,8 +39,10 @@ const initializeCemeteryDatabase = () => {
const databaseInitialized = initializeDatabase(); const databaseInitialized = initializeDatabase();
if (!databaseInitialized) { if (!databaseInitialized) {
debug("Database already created.\n" + debug(
"To initialize this database with cemetery types, delete the database file first, then rerun this script."); "Database already created.\n" +
"To initialize this database with cemetery types, delete the database file first, then rerun this script."
);
return; return;
} }
@ -71,199 +52,279 @@ const initializeCemeteryDatabase = () => {
* Lot Types * Lot Types
*/ */
addLotType({ addLotType(
lotType: "Casket Grave", {
orderNumber: 1 lotType: "Casket Grave",
}, session); orderNumber: 1
},
session
);
addLotType({ addLotType(
lotType: "Columbarium", {
orderNumber: 2 lotType: "Columbarium",
}, session); orderNumber: 2
},
session
);
addLotType({ addLotType(
lotType: "Mausoleum", {
orderNumber: 2 lotType: "Mausoleum",
}, session); orderNumber: 2
},
session
);
addLotType({ addLotType(
lotType: "Niche Wall", {
orderNumber: 2 lotType: "Niche Wall",
}, session); orderNumber: 2
},
session
);
addLotType({ addLotType(
lotType: "Urn Garden", {
orderNumber: 2 lotType: "Urn Garden",
}, session); orderNumber: 2
},
session
);
addLotType({ addLotType(
lotType: "Crematorium", {
orderNumber: 3 lotType: "Crematorium",
}, session); orderNumber: 3
},
session
);
/* /*
* Lot Statuses * Lot Statuses
*/ */
addLotStatus({ addLotStatus(
lotStatus: "Available", {
orderNumber: 1 lotStatus: "Available",
}, session); orderNumber: 1
},
session
);
addLotStatus({ addLotStatus(
lotStatus: "Reserved", {
orderNumber: 2 lotStatus: "Reserved",
}, session); orderNumber: 2
},
session
);
addLotStatus({ addLotStatus(
lotStatus: "Taken", {
orderNumber: 3 lotStatus: "Taken",
}, session); orderNumber: 3
},
session
);
/* /*
* Lot Occupant Types * Lot Occupant Types
*/ */
addLotOccupantType({ addLotOccupantType(
lotOccupantType: "Deceased", {
orderNumber: 1 lotOccupantType: "Deceased",
}, session); orderNumber: 1
},
session
);
addLotOccupantType({ addLotOccupantType(
lotOccupantType: "Preneed Owner", {
orderNumber: 2 lotOccupantType: "Preneed Owner",
}, session); orderNumber: 2
},
session
);
addLotOccupantType({ addLotOccupantType(
lotOccupantType: "Arranger", {
orderNumber: 3 lotOccupantType: "Arranger",
}, session); orderNumber: 3
},
session
);
/* /*
* Occupancy Types * Occupancy Types
*/ */
addOccupancyType({ addOccupancyType(
occupancyType: "Preneed", {
orderNumber: 1 occupancyType: "Preneed",
}, session); orderNumber: 1
},
session
);
const intermentOccupancyTypeId = addOccupancyType({ const intermentOccupancyTypeId = addOccupancyType(
occupancyType: "Interment", {
orderNumber: 2 occupancyType: "Interment",
}, session); orderNumber: 2
},
session
);
addOccupancyType({ addOccupancyType(
occupancyType: "Cremation", {
orderNumber: 3 occupancyType: "Cremation",
}, session); orderNumber: 3
},
session
);
addOccupancyTypeField({ addOccupancyTypeField(
occupancyTypeId: intermentOccupancyTypeId, {
occupancyTypeField: "Death Date", occupancyTypeId: intermentOccupancyTypeId,
occupancyTypeFieldValues: "", occupancyTypeField: "Death Date",
pattern: "\\d{4}([\\/-]\\d{2}){2}", occupancyTypeFieldValues: "",
isRequired: "", pattern: "\\d{4}([\\/-]\\d{2}){2}",
minimumLength: 10, isRequired: "",
maximumLength: 10, minimumLength: 10,
orderNumber: 1 maximumLength: 10,
}, session); orderNumber: 1
},
session
);
addOccupancyTypeField({ addOccupancyTypeField(
occupancyTypeId: intermentOccupancyTypeId, {
occupancyTypeField: "Death Age", occupancyTypeId: intermentOccupancyTypeId,
occupancyTypeFieldValues: "", occupancyTypeField: "Death Age",
pattern: "\\d+", occupancyTypeFieldValues: "",
isRequired: "", pattern: "\\d+",
minimumLength: 1, isRequired: "",
maximumLength: 3, minimumLength: 1,
orderNumber: 2 maximumLength: 3,
}, session); orderNumber: 2
},
session
);
addOccupancyTypeField({ addOccupancyTypeField(
occupancyTypeId: intermentOccupancyTypeId, {
occupancyTypeField: "Death Age Period", occupancyTypeId: intermentOccupancyTypeId,
occupancyTypeFieldValues: "Years,Months,Days,Stillborn", occupancyTypeField: "Death Age Period",
pattern: "", occupancyTypeFieldValues: "Years,Months,Days,Stillborn",
isRequired: "", pattern: "",
minimumLength: 1, isRequired: "",
maximumLength: 10, minimumLength: 1,
orderNumber: 3 maximumLength: 10,
}, session); orderNumber: 3
},
session
);
addOccupancyTypeField({ addOccupancyTypeField(
occupancyTypeId: intermentOccupancyTypeId, {
occupancyTypeField: "Funeral Home", occupancyTypeId: intermentOccupancyTypeId,
occupancyTypeFieldValues: "", occupancyTypeField: "Funeral Home",
pattern: "", occupancyTypeFieldValues: "",
isRequired: "", pattern: "",
minimumLength: 1, isRequired: "",
maximumLength: 100, minimumLength: 1,
orderNumber: 10 maximumLength: 100,
}, session); orderNumber: 10
},
session
);
addOccupancyTypeField({ addOccupancyTypeField(
occupancyTypeId: intermentOccupancyTypeId, {
occupancyTypeField: "Funeral Date", occupancyTypeId: intermentOccupancyTypeId,
occupancyTypeFieldValues: "", occupancyTypeField: "Funeral Date",
pattern: "\\d{4}([\\/-]\\d{2}){2}", occupancyTypeFieldValues: "",
isRequired: "", pattern: "\\d{4}([\\/-]\\d{2}){2}",
minimumLength: 10, isRequired: "",
maximumLength: 10, minimumLength: 10,
orderNumber: 11 maximumLength: 10,
}, session); orderNumber: 11
},
session
);
addOccupancyTypeField({ addOccupancyTypeField(
occupancyTypeId: intermentOccupancyTypeId, {
occupancyTypeField: "Container Type", occupancyTypeId: intermentOccupancyTypeId,
occupancyTypeFieldValues: "", occupancyTypeField: "Container Type",
pattern: "", occupancyTypeFieldValues: "",
isRequired: "", pattern: "",
minimumLength: 1, isRequired: "",
maximumLength: 100, minimumLength: 1,
orderNumber: 20 maximumLength: 100,
}, session); orderNumber: 20
},
session
);
addOccupancyTypeField({ addOccupancyTypeField(
occupancyTypeId: intermentOccupancyTypeId, {
occupancyTypeField: "Committal Type", occupancyTypeId: intermentOccupancyTypeId,
occupancyTypeFieldValues: "", occupancyTypeField: "Committal Type",
pattern: "", occupancyTypeFieldValues: "",
isRequired: "", pattern: "",
minimumLength: 1, isRequired: "",
maximumLength: 100, minimumLength: 1,
orderNumber: 21 maximumLength: 100,
}, session); orderNumber: 21
},
session
);
/* /*
* Fee Categories * Fee Categories
*/ */
addFeeCategory({ addFeeCategory(
feeCategory: "Interment Rights", {
orderNumber: 1 feeCategory: "Interment Rights",
}, session); orderNumber: 1
},
session
);
addFeeCategory({ addFeeCategory(
feeCategory: "Cremation Services", {
orderNumber: 2 feeCategory: "Cremation Services",
}, session); orderNumber: 2
},
session
);
addFeeCategory({ addFeeCategory(
feeCategory: "Burial Charges", {
orderNumber: 3 feeCategory: "Burial Charges",
}, session); orderNumber: 3
},
session
);
addFeeCategory({ addFeeCategory(
feeCategory: "Disinterment of Human Remains", {
orderNumber: 4 feeCategory: "Disinterment of Human Remains",
}, session); orderNumber: 4
},
session
);
addFeeCategory({ addFeeCategory(
feeCategory: "Additional Services", {
orderNumber: 5 feeCategory: "Additional Services",
}, session); orderNumber: 5
},
session
);
}; };
initializeCemeteryDatabase();
initializeCemeteryDatabase();

View File

@ -15,15 +15,20 @@ export const initializeDatabase = () => {
.get(); .get();
if (!row) { if (!row) {
debugSQL("Creating " + databasePath); debugSQL("Creating " + databasePath);
lotOccupancyDB.prepare("create table if not exists LotTypes (" + lotOccupancyDB
.prepare("create table if not exists LotTypes (" +
"lotTypeId integer not null primary key autoincrement," + "lotTypeId integer not null primary key autoincrement," +
" lotType varchar(100) not null," + " lotType varchar(100) not null," +
" orderNumber smallint not null default 0," + " orderNumber smallint not null default 0," +
recordColumns + recordColumns +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_lottypes_ordernumber" + .run();
" on LotTypes (orderNumber, lotType)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists LotTypeFields (" + .prepare("create index if not exists idx_lottypes_ordernumber" +
" on LotTypes (orderNumber, lotType)")
.run();
lotOccupancyDB
.prepare("create table if not exists LotTypeFields (" +
"lotTypeFieldId integer not null primary key autoincrement," + "lotTypeFieldId integer not null primary key autoincrement," +
" lotTypeId integer not null," + " lotTypeId integer not null," +
" lotTypeField varchar(100) not null," + " lotTypeField varchar(100) not null," +
@ -33,20 +38,29 @@ export const initializeDatabase = () => {
" minimumLength smallint not null default 1 check (minimumLength >= 0)," + " minimumLength smallint not null default 1 check (minimumLength >= 0)," +
" maximumLength smallint not null default 100 check (maximumLength >= 0)," + " maximumLength smallint not null default 100 check (maximumLength >= 0)," +
" orderNumber smallint not null default 0," + " orderNumber smallint not null default 0," +
recordColumns + "," + recordColumns +
"," +
" foreign key (lotTypeId) references LotTypes (lotTypeId)" + " foreign key (lotTypeId) references LotTypes (lotTypeId)" +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_lottypefields_ordernumber" + .run();
" on LotTypeFields (lotTypeId, orderNumber, lotTypeField)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists LotStatuses (" + .prepare("create index if not exists idx_lottypefields_ordernumber" +
" on LotTypeFields (lotTypeId, orderNumber, lotTypeField)")
.run();
lotOccupancyDB
.prepare("create table if not exists LotStatuses (" +
"lotStatusId integer not null primary key autoincrement," + "lotStatusId integer not null primary key autoincrement," +
" lotStatus varchar(100) not null," + " lotStatus varchar(100) not null," +
" orderNumber smallint not null default 0," + " orderNumber smallint not null default 0," +
recordColumns + recordColumns +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_lotstatuses_ordernumber" + .run();
" on LotStatuses (orderNumber, lotStatus)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists Maps (" + .prepare("create index if not exists idx_lotstatuses_ordernumber" +
" on LotStatuses (orderNumber, lotStatus)")
.run();
lotOccupancyDB
.prepare("create table if not exists Maps (" +
"mapId integer not null primary key autoincrement," + "mapId integer not null primary key autoincrement," +
" mapName varchar(200) not null," + " mapName varchar(200) not null," +
" mapDescription text," + " mapDescription text," +
@ -60,8 +74,10 @@ export const initializeDatabase = () => {
" mapPostalCode varchar(7)," + " mapPostalCode varchar(7)," +
" mapPhoneNumber varchar(30)," + " mapPhoneNumber varchar(30)," +
recordColumns + recordColumns +
")").run(); ")")
lotOccupancyDB.prepare("create table if not exists Lots (" + .run();
lotOccupancyDB
.prepare("create table if not exists Lots (" +
"lotId integer not null primary key autoincrement," + "lotId integer not null primary key autoincrement," +
" lotTypeId integer not null," + " lotTypeId integer not null," +
" lotName varchar(100)," + " lotName varchar(100)," +
@ -70,40 +86,55 @@ export const initializeDatabase = () => {
" lotLatitude decimal(10, 8) check (lotLatitude between -90 and 90)," + " lotLatitude decimal(10, 8) check (lotLatitude between -90 and 90)," +
" lotLongitude decimal(11, 8) check (lotLongitude between -180 and 180)," + " lotLongitude decimal(11, 8) check (lotLongitude between -180 and 180)," +
" lotStatusId integer," + " lotStatusId integer," +
recordColumns + "," + recordColumns +
"," +
" foreign key (lotTypeId) references LotTypes (lotTypeId)," + " foreign key (lotTypeId) references LotTypes (lotTypeId)," +
" foreign key (mapId) references Maps (mapId)," + " foreign key (mapId) references Maps (mapId)," +
" foreign key (lotStatusId) references LotStatuses (lotStatusId)" + " foreign key (lotStatusId) references LotStatuses (lotStatusId)" +
")").run(); ")")
lotOccupancyDB.prepare("create table if not exists LotFields (" + .run();
lotOccupancyDB
.prepare("create table if not exists LotFields (" +
"lotId integer not null," + "lotId integer not null," +
" lotTypeFieldId integer not null," + " lotTypeFieldId integer not null," +
" lotFieldValue text not null," + " lotFieldValue text not null," +
recordColumns + "," + recordColumns +
"," +
" primary key (lotId, lotTypeFieldId)," + " primary key (lotId, lotTypeFieldId)," +
" foreign key (lotId) references Lots (lotId)," + " foreign key (lotId) references Lots (lotId)," +
" foreign key (lotTypeFieldId) references LotTypeFields (lotTypeFieldId)" + " foreign key (lotTypeFieldId) references LotTypeFields (lotTypeFieldId)" +
") without rowid").run(); ") without rowid")
lotOccupancyDB.prepare("create table if not exists LotComments (" + .run();
lotOccupancyDB
.prepare("create table if not exists LotComments (" +
"lotCommentId integer not null primary key autoincrement," + "lotCommentId integer not null primary key autoincrement," +
" lotId integer not null," + " lotId integer not null," +
" lotCommentDate integer not null check (lotCommentDate > 0)," + " lotCommentDate integer not null check (lotCommentDate > 0)," +
" lotCommentTime integer not null check (lotCommentTime >= 0)," + " lotCommentTime integer not null check (lotCommentTime >= 0)," +
" lotComment text not null," + " lotComment text not null," +
recordColumns + "," + recordColumns +
"," +
" foreign key (lotId) references Lots (lotId)" + " foreign key (lotId) references Lots (lotId)" +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_lotcomments_datetime" + .run();
" on LotComments (lotId, lotCommentDate, lotCommentTime)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists OccupancyTypes (" + .prepare("create index if not exists idx_lotcomments_datetime" +
" on LotComments (lotId, lotCommentDate, lotCommentTime)")
.run();
lotOccupancyDB
.prepare("create table if not exists OccupancyTypes (" +
"occupancyTypeId integer not null primary key autoincrement," + "occupancyTypeId integer not null primary key autoincrement," +
" occupancyType varchar(100) not null," + " occupancyType varchar(100) not null," +
" orderNumber smallint not null default 0," + " orderNumber smallint not null default 0," +
recordColumns + recordColumns +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_occupancytypes_ordernumber" + .run();
" on OccupancyTypes (orderNumber, occupancyType)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists OccupancyTypeFields (" + .prepare("create index if not exists idx_occupancytypes_ordernumber" +
" on OccupancyTypes (orderNumber, occupancyType)")
.run();
lotOccupancyDB
.prepare("create table if not exists OccupancyTypeFields (" +
"occupancyTypeFieldId integer not null primary key autoincrement," + "occupancyTypeFieldId integer not null primary key autoincrement," +
" occupancyTypeId integer not null," + " occupancyTypeId integer not null," +
" occupancyTypeField varchar(100) not null," + " occupancyTypeField varchar(100) not null," +
@ -113,30 +144,42 @@ export const initializeDatabase = () => {
" minimumLength smallint not null default 1 check (minimumLength >= 0)," + " minimumLength smallint not null default 1 check (minimumLength >= 0)," +
" maximumLength smallint not null default 100 check (maximumLength >= 0)," + " maximumLength smallint not null default 100 check (maximumLength >= 0)," +
" orderNumber smallint not null default 0," + " orderNumber smallint not null default 0," +
recordColumns + "," + recordColumns +
"," +
" foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" + " foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_occupancytypefields_ordernumber" + .run();
" on OccupancyTypeFields (occupancyTypeId, orderNumber, occupancyTypeField)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists LotOccupantTypes (" + .prepare("create index if not exists idx_occupancytypefields_ordernumber" +
" on OccupancyTypeFields (occupancyTypeId, orderNumber, occupancyTypeField)")
.run();
lotOccupancyDB
.prepare("create table if not exists LotOccupantTypes (" +
"lotOccupantTypeId integer not null primary key autoincrement," + "lotOccupantTypeId integer not null primary key autoincrement," +
" lotOccupantType varchar(100) not null," + " lotOccupantType varchar(100) not null," +
" orderNumber smallint not null default 0," + " orderNumber smallint not null default 0," +
recordColumns + recordColumns +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_lotoccupanttypes_ordernumber" + .run();
" on LotOccupantTypes (orderNumber, lotOccupantType)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists LotOccupancies (" + .prepare("create index if not exists idx_lotoccupanttypes_ordernumber" +
" on LotOccupantTypes (orderNumber, lotOccupantType)")
.run();
lotOccupancyDB
.prepare("create table if not exists LotOccupancies (" +
"lotOccupancyId integer not null primary key autoincrement," + "lotOccupancyId integer not null primary key autoincrement," +
" occupancyTypeId integer not null," + " occupancyTypeId integer not null," +
" lotId integer," + " lotId integer," +
" occupancyStartDate integer not null check (occupancyStartDate > 0)," + " occupancyStartDate integer not null check (occupancyStartDate > 0)," +
" occupancyEndDate integer check (occupancyEndDate > 0)," + " occupancyEndDate integer check (occupancyEndDate > 0)," +
recordColumns + "," + recordColumns +
"," +
" foreign key (lotId) references Lots (lotId)," + " foreign key (lotId) references Lots (lotId)," +
" foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" + " foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" +
")").run(); ")")
lotOccupancyDB.prepare("create table if not exists LotOccupancyOccupants (" + .run();
lotOccupancyDB
.prepare("create table if not exists LotOccupancyOccupants (" +
"lotOccupancyId integer not null," + "lotOccupancyId integer not null," +
" lotOccupantIndex integer not null," + " lotOccupantIndex integer not null," +
" occupantName varchar(200) not null," + " occupantName varchar(200) not null," +
@ -147,38 +190,51 @@ export const initializeDatabase = () => {
" occupantPostalCode varchar(7)," + " occupantPostalCode varchar(7)," +
" occupantPhoneNumber varchar(30)," + " occupantPhoneNumber varchar(30)," +
" lotOccupantTypeId integer not null," + " lotOccupantTypeId integer not null," +
recordColumns + "," + recordColumns +
"," +
" primary key (lotOccupancyId, lotOccupantIndex)," + " primary key (lotOccupancyId, lotOccupantIndex)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," + " foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," +
" foreign key (lotOccupantTypeId) references LotOccupantTypes (lotOccupantTypeId)" + " foreign key (lotOccupantTypeId) references LotOccupantTypes (lotOccupantTypeId)" +
") without rowid").run(); ") without rowid")
lotOccupancyDB.prepare("create table if not exists LotOccupancyFields (" + .run();
lotOccupancyDB
.prepare("create table if not exists LotOccupancyFields (" +
"lotOccupancyId integer not null," + "lotOccupancyId integer not null," +
" occupancyTypeFieldId integer not null," + " occupancyTypeFieldId integer not null," +
" lotOccupancyFieldValue text not null," + " lotOccupancyFieldValue text not null," +
recordColumns + "," + recordColumns +
"," +
" primary key (lotOccupancyId, occupancyTypeFieldId)," + " primary key (lotOccupancyId, occupancyTypeFieldId)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," + " foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," +
" foreign key (occupancyTypeFieldId) references OccupancyTypeFields (occupancyTypeFieldId)" + " foreign key (occupancyTypeFieldId) references OccupancyTypeFields (occupancyTypeFieldId)" +
") without rowid").run(); ") without rowid")
lotOccupancyDB.prepare("create table if not exists LotOccupancyComments (" + .run();
lotOccupancyDB
.prepare("create table if not exists LotOccupancyComments (" +
"lotOccupancyCommentId integer not null primary key autoincrement," + "lotOccupancyCommentId integer not null primary key autoincrement," +
" lotOccupancyId integer not null," + " lotOccupancyId integer not null," +
" lotOccupancyCommentDate integer not null check (lotOccupancyCommentDate > 0)," + " lotOccupancyCommentDate integer not null check (lotOccupancyCommentDate > 0)," +
" lotOccupancyCommentTime integer not null check (lotOccupancyCommentTime >= 0)," + " lotOccupancyCommentTime integer not null check (lotOccupancyCommentTime >= 0)," +
" lotOccupancyComment text not null," + " lotOccupancyComment text not null," +
recordColumns + "," + recordColumns +
"," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" + " foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_lotoccupancycomments_datetime" + .run();
" on LotOccupancyComments (lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists FeeCategories (" + .prepare("create index if not exists idx_lotoccupancycomments_datetime" +
" on LotOccupancyComments (lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime)")
.run();
lotOccupancyDB
.prepare("create table if not exists FeeCategories (" +
"feeCategoryId integer not null primary key autoincrement," + "feeCategoryId integer not null primary key autoincrement," +
" feeCategory varchar(100) not null," + " feeCategory varchar(100) not null," +
" orderNumber smallint not null default 0," + " orderNumber smallint not null default 0," +
recordColumns + recordColumns +
")").run(); ")")
lotOccupancyDB.prepare("create table if not exists Fees (" + .run();
lotOccupancyDB
.prepare("create table if not exists Fees (" +
"feeId integer not null primary key autoincrement," + "feeId integer not null primary key autoincrement," +
" feeCategoryId integer not null," + " feeCategoryId integer not null," +
" feeName varchar(100) not null," + " feeName varchar(100) not null," +
@ -193,25 +249,33 @@ export const initializeDatabase = () => {
" taxPercentage decimal(5, 2)," + " taxPercentage decimal(5, 2)," +
" isRequired bit not null default 0," + " isRequired bit not null default 0," +
" orderNumber smallint not null default 0," + " orderNumber smallint not null default 0," +
recordColumns + "," + recordColumns +
"," +
" foreign key (feeCategoryId) references FeeCategories (feeCategoryId)," + " foreign key (feeCategoryId) references FeeCategories (feeCategoryId)," +
" foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)," + " foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)," +
" foreign key (lotTypeId) references LotTypes (lotTypeId)" + " foreign key (lotTypeId) references LotTypes (lotTypeId)" +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_fees_ordernumber" + .run();
" on Fees (orderNumber, feeName)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists LotOccupancyFees (" + .prepare("create index if not exists idx_fees_ordernumber" +
" on Fees (orderNumber, feeName)")
.run();
lotOccupancyDB
.prepare("create table if not exists LotOccupancyFees (" +
"lotOccupancyId integer not null," + "lotOccupancyId integer not null," +
" feeId integer not null," + " feeId integer not null," +
" quantity decimal(4, 1) not null default 1," + " quantity decimal(4, 1) not null default 1," +
" feeAmount decimal(6, 2) not null," + " feeAmount decimal(6, 2) not null," +
" taxAmount decmial(6, 2) not null," + " taxAmount decmial(6, 2) not null," +
recordColumns + "," + recordColumns +
"," +
" primary key (lotOccupancyId, feeId)," + " primary key (lotOccupancyId, feeId)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," + " foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," +
" foreign key (feeId) references Fees (feeId)" + " foreign key (feeId) references Fees (feeId)" +
") without rowid").run(); ") without rowid")
lotOccupancyDB.prepare("create table if not exists LotOccupancyTransactions (" + .run();
lotOccupancyDB
.prepare("create table if not exists LotOccupancyTransactions (" +
"lotOccupancyId integer not null," + "lotOccupancyId integer not null," +
" transactionIndex integer not null," + " transactionIndex integer not null," +
" transactionDate integer not null check (transactionDate > 0)," + " transactionDate integer not null check (transactionDate > 0)," +
@ -219,57 +283,79 @@ export const initializeDatabase = () => {
" transactionAmount decimal(6, 2) not null," + " transactionAmount decimal(6, 2) not null," +
" externalReceiptNumber varchar(100)," + " externalReceiptNumber varchar(100)," +
" transactionNote text," + " transactionNote text," +
recordColumns + "," + recordColumns +
"," +
" primary key (lotOccupancyId, transactionIndex)," + " primary key (lotOccupancyId, transactionIndex)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" + " foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" +
") without rowid").run(); ") without rowid")
lotOccupancyDB.prepare("create index if not exists idx_lotoccupancytransactions_ordernumber" + .run();
" on LotOccupancyTransactions (lotOccupancyId, transactionDate, transactionTime)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists WorkOrderTypes (" + .prepare("create index if not exists idx_lotoccupancytransactions_ordernumber" +
" on LotOccupancyTransactions (lotOccupancyId, transactionDate, transactionTime)")
.run();
lotOccupancyDB
.prepare("create table if not exists WorkOrderTypes (" +
"workOrderTypeId integer not null primary key autoincrement," + "workOrderTypeId integer not null primary key autoincrement," +
" workOrderType varchar(100) not null," + " workOrderType varchar(100) not null," +
" orderNumber smallint not null default 0," + " orderNumber smallint not null default 0," +
recordColumns + recordColumns +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_workordertypes_ordernumber" + .run();
" on WorkOrderTypes (orderNumber, workOrderType)").run(); lotOccupancyDB
lotOccupancyDB.prepare("create table if not exists WorkOrders (" + .prepare("create index if not exists idx_workordertypes_ordernumber" +
" on WorkOrderTypes (orderNumber, workOrderType)")
.run();
lotOccupancyDB
.prepare("create table if not exists WorkOrders (" +
"workOrderId integer not null primary key autoincrement," + "workOrderId integer not null primary key autoincrement," +
" workOrderTypeId integer not null," + " workOrderTypeId integer not null," +
" workOrderNumber varchar(50) not null," + " workOrderNumber varchar(50) not null," +
" workOrderDescription text," + " workOrderDescription text," +
" workOrderOpenDate integer check (workOrderOpenDate > 0)," + " workOrderOpenDate integer check (workOrderOpenDate > 0)," +
" workOrderCloseDate integer check (workOrderCloseDate > 0)," + " workOrderCloseDate integer check (workOrderCloseDate > 0)," +
recordColumns + "," + recordColumns +
"," +
" foreign key (workOrderTypeId) references WorkOrderTypes (workOrderTypeId)" + " foreign key (workOrderTypeId) references WorkOrderTypes (workOrderTypeId)" +
")").run(); ")")
lotOccupancyDB.prepare("create table if not exists WorkOrderLots (" + .run();
lotOccupancyDB
.prepare("create table if not exists WorkOrderLots (" +
"workOrderId integer not null," + "workOrderId integer not null," +
" lotId integer not null," + " lotId integer not null," +
recordColumns + "," + recordColumns +
"," +
" primary key (workOrderId, lotId)," + " primary key (workOrderId, lotId)," +
" foreign key (workOrderId) references WorkOrders (workOrderId)," + " foreign key (workOrderId) references WorkOrders (workOrderId)," +
" foreign key (lotId) references Lots (lotId)" + " foreign key (lotId) references Lots (lotId)" +
") without rowid").run(); ") without rowid")
lotOccupancyDB.prepare("create table if not exists WorkOrderLotOccupancies (" + .run();
lotOccupancyDB
.prepare("create table if not exists WorkOrderLotOccupancies (" +
"workOrderId integer not null," + "workOrderId integer not null," +
" lotOccupancyId integer not null," + " lotOccupancyId integer not null," +
recordColumns + "," + recordColumns +
"," +
" primary key (workOrderId, lotOccupancyId)," + " primary key (workOrderId, lotOccupancyId)," +
" foreign key (workOrderId) references WorkOrders (workOrderId)," + " foreign key (workOrderId) references WorkOrders (workOrderId)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" + " foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" +
") without rowid").run(); ") without rowid")
lotOccupancyDB.prepare("create table if not exists WorkOrderComments (" + .run();
lotOccupancyDB
.prepare("create table if not exists WorkOrderComments (" +
"workOrderCommentId integer not null primary key autoincrement," + "workOrderCommentId integer not null primary key autoincrement," +
" workOrderId integer not null," + " workOrderId integer not null," +
" workOrderCommentDate integer not null check (workOrderCommentDate > 0)," + " workOrderCommentDate integer not null check (workOrderCommentDate > 0)," +
" workOrderCommentTime integer not null check (workOrderCommentTime >= 0)," + " workOrderCommentTime integer not null check (workOrderCommentTime >= 0)," +
" workOrderComment text not null," + " workOrderComment text not null," +
recordColumns + "," + recordColumns +
"," +
" foreign key (workOrderId) references WorkOrders (workOrderId)" + " foreign key (workOrderId) references WorkOrders (workOrderId)" +
")").run(); ")")
lotOccupancyDB.prepare("create index if not exists idx_workordercomments_datetime" + .run();
" on WorkOrderComments (workOrderId, workOrderCommentDate, workOrderCommentTime)").run(); lotOccupancyDB
.prepare("create index if not exists idx_workordercomments_datetime" +
" on WorkOrderComments (workOrderId, workOrderCommentDate, workOrderCommentTime)")
.run();
lotOccupancyDB.close(); lotOccupancyDB.close();
return true; return true;
} }

View File

@ -1,339 +1,485 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../data/databasePaths.js";
import debug from "debug"; import debug from "debug";
const debugSQL = debug("lot-occupancy-system:databaseInitializer"); const debugSQL = debug("lot-occupancy-system:databaseInitializer");
const recordColumns =
const recordColumns = " recordCreate_userName varchar(30) not null," + " recordCreate_userName varchar(30) not null," +
" recordCreate_timeMillis integer not null," + " recordCreate_timeMillis integer not null," +
" recordUpdate_userName varchar(30) not null," + " recordUpdate_userName varchar(30) not null," +
" recordUpdate_timeMillis integer not null," + " recordUpdate_timeMillis integer not null," +
" recordDelete_userName varchar(30)," + " recordDelete_userName varchar(30)," +
" recordDelete_timeMillis integer"; " recordDelete_timeMillis integer";
export const initializeDatabase = (): boolean => { export const initializeDatabase = (): boolean => {
const lotOccupancyDB = sqlite(databasePath); const lotOccupancyDB = sqlite(databasePath);
const row = lotOccupancyDB const row = lotOccupancyDB
.prepare("select name from sqlite_master where type = 'table' and name = 'WorkOrderComments'") .prepare(
"select name from sqlite_master where type = 'table' and name = 'WorkOrderComments'"
)
.get(); .get();
if (!row) { if (!row) {
debugSQL("Creating " + databasePath); debugSQL("Creating " + databasePath);
// Lot Types // Lot Types
lotOccupancyDB.prepare("create table if not exists LotTypes (" + lotOccupancyDB
"lotTypeId integer not null primary key autoincrement," + .prepare(
" lotType varchar(100) not null," + "create table if not exists LotTypes (" +
" orderNumber smallint not null default 0," + "lotTypeId integer not null primary key autoincrement," +
recordColumns + " lotType varchar(100) not null," +
")").run(); " orderNumber smallint not null default 0," +
recordColumns +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_lottypes_ordernumber" + lotOccupancyDB
" on LotTypes (orderNumber, lotType)").run(); .prepare(
"create index if not exists idx_lottypes_ordernumber" +
" on LotTypes (orderNumber, lotType)"
)
.run();
lotOccupancyDB.prepare("create table if not exists LotTypeFields (" + lotOccupancyDB
"lotTypeFieldId integer not null primary key autoincrement," + .prepare(
" lotTypeId integer not null," + "create table if not exists LotTypeFields (" +
" lotTypeField varchar(100) not null," + "lotTypeFieldId integer not null primary key autoincrement," +
" lotTypeFieldValues text," + " lotTypeId integer not null," +
" isRequired bit not null default 0," + " lotTypeField varchar(100) not null," +
" pattern varchar(100)," + " lotTypeFieldValues text," +
" minimumLength smallint not null default 1 check (minimumLength >= 0)," + " isRequired bit not null default 0," +
" maximumLength smallint not null default 100 check (maximumLength >= 0)," + " pattern varchar(100)," +
" orderNumber smallint not null default 0," + " minimumLength smallint not null default 1 check (minimumLength >= 0)," +
recordColumns + "," + " maximumLength smallint not null default 100 check (maximumLength >= 0)," +
" foreign key (lotTypeId) references LotTypes (lotTypeId)" + " orderNumber smallint not null default 0," +
")").run(); recordColumns +
"," +
" foreign key (lotTypeId) references LotTypes (lotTypeId)" +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_lottypefields_ordernumber" + lotOccupancyDB
" on LotTypeFields (lotTypeId, orderNumber, lotTypeField)").run(); .prepare(
"create index if not exists idx_lottypefields_ordernumber" +
" on LotTypeFields (lotTypeId, orderNumber, lotTypeField)"
)
.run();
lotOccupancyDB.prepare("create table if not exists LotStatuses (" + lotOccupancyDB
"lotStatusId integer not null primary key autoincrement," + .prepare(
" lotStatus varchar(100) not null," + "create table if not exists LotStatuses (" +
" orderNumber smallint not null default 0," + "lotStatusId integer not null primary key autoincrement," +
recordColumns + " lotStatus varchar(100) not null," +
")").run(); " orderNumber smallint not null default 0," +
recordColumns +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_lotstatuses_ordernumber" + lotOccupancyDB
" on LotStatuses (orderNumber, lotStatus)").run(); .prepare(
"create index if not exists idx_lotstatuses_ordernumber" +
" on LotStatuses (orderNumber, lotStatus)"
)
.run();
// Maps and Lots // Maps and Lots
lotOccupancyDB.prepare("create table if not exists Maps (" + lotOccupancyDB
"mapId integer not null primary key autoincrement," + .prepare(
" mapName varchar(200) not null," + "create table if not exists Maps (" +
" mapDescription text," + "mapId integer not null primary key autoincrement," +
" mapName varchar(200) not null," +
" mapDescription text," +
" mapLatitude decimal(10, 8) check (mapLatitude between -90 and 90)," +
" mapLongitude decimal(11, 8) check (mapLongitude between -180 and 180)," +
" mapSVG varchar(50)," +
" mapAddress1 varchar(50)," +
" mapAddress2 varchar(50)," +
" mapCity varchar(20)," +
" mapProvince varchar(2)," +
" mapPostalCode varchar(7)," +
" mapPhoneNumber varchar(30)," +
recordColumns +
")"
)
.run();
" mapLatitude decimal(10, 8) check (mapLatitude between -90 and 90)," + lotOccupancyDB
" mapLongitude decimal(11, 8) check (mapLongitude between -180 and 180)," + .prepare(
"create table if not exists Lots (" +
"lotId integer not null primary key autoincrement," +
" lotTypeId integer not null," +
" lotName varchar(100)," +
" mapId integer," +
" mapKey varchar(100)," +
" lotLatitude decimal(10, 8) check (lotLatitude between -90 and 90)," +
" lotLongitude decimal(11, 8) check (lotLongitude between -180 and 180)," +
" lotStatusId integer," +
recordColumns +
"," +
" foreign key (lotTypeId) references LotTypes (lotTypeId)," +
" foreign key (mapId) references Maps (mapId)," +
" foreign key (lotStatusId) references LotStatuses (lotStatusId)" +
")"
)
.run();
" mapSVG varchar(50)," + lotOccupancyDB
.prepare(
"create table if not exists LotFields (" +
"lotId integer not null," +
" lotTypeFieldId integer not null," +
" lotFieldValue text not null," +
recordColumns +
"," +
" primary key (lotId, lotTypeFieldId)," +
" foreign key (lotId) references Lots (lotId)," +
" foreign key (lotTypeFieldId) references LotTypeFields (lotTypeFieldId)" +
") without rowid"
)
.run();
" mapAddress1 varchar(50)," + lotOccupancyDB
" mapAddress2 varchar(50)," + .prepare(
" mapCity varchar(20)," + "create table if not exists LotComments (" +
" mapProvince varchar(2)," + "lotCommentId integer not null primary key autoincrement," +
" mapPostalCode varchar(7)," + " lotId integer not null," +
" mapPhoneNumber varchar(30)," + " lotCommentDate integer not null check (lotCommentDate > 0)," +
" lotCommentTime integer not null check (lotCommentTime >= 0)," +
" lotComment text not null," +
recordColumns +
"," +
" foreign key (lotId) references Lots (lotId)" +
")"
)
.run();
recordColumns + lotOccupancyDB
")").run(); .prepare(
"create index if not exists idx_lotcomments_datetime" +
lotOccupancyDB.prepare("create table if not exists Lots (" + " on LotComments (lotId, lotCommentDate, lotCommentTime)"
"lotId integer not null primary key autoincrement," + )
" lotTypeId integer not null," + .run();
" lotName varchar(100)," +
" mapId integer," +
" mapKey varchar(100)," +
" lotLatitude decimal(10, 8) check (lotLatitude between -90 and 90)," +
" lotLongitude decimal(11, 8) check (lotLongitude between -180 and 180)," +
" lotStatusId integer," +
recordColumns + "," +
" foreign key (lotTypeId) references LotTypes (lotTypeId)," +
" foreign key (mapId) references Maps (mapId)," +
" foreign key (lotStatusId) references LotStatuses (lotStatusId)" +
")").run();
lotOccupancyDB.prepare("create table if not exists LotFields (" +
"lotId integer not null," +
" lotTypeFieldId integer not null," +
" lotFieldValue text not null," +
recordColumns + "," +
" primary key (lotId, lotTypeFieldId)," +
" foreign key (lotId) references Lots (lotId)," +
" foreign key (lotTypeFieldId) references LotTypeFields (lotTypeFieldId)" +
") without rowid").run();
lotOccupancyDB.prepare("create table if not exists LotComments (" +
"lotCommentId integer not null primary key autoincrement," +
" lotId integer not null," +
" lotCommentDate integer not null check (lotCommentDate > 0)," +
" lotCommentTime integer not null check (lotCommentTime >= 0)," +
" lotComment text not null," +
recordColumns + "," +
" foreign key (lotId) references Lots (lotId)" +
")").run();
lotOccupancyDB.prepare("create index if not exists idx_lotcomments_datetime" +
" on LotComments (lotId, lotCommentDate, lotCommentTime)").run();
// Occupancies // Occupancies
lotOccupancyDB.prepare("create table if not exists OccupancyTypes (" + lotOccupancyDB
"occupancyTypeId integer not null primary key autoincrement," + .prepare(
" occupancyType varchar(100) not null," + "create table if not exists OccupancyTypes (" +
" orderNumber smallint not null default 0," + "occupancyTypeId integer not null primary key autoincrement," +
recordColumns + " occupancyType varchar(100) not null," +
")").run(); " orderNumber smallint not null default 0," +
recordColumns +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_occupancytypes_ordernumber" + lotOccupancyDB
" on OccupancyTypes (orderNumber, occupancyType)").run(); .prepare(
"create index if not exists idx_occupancytypes_ordernumber" +
" on OccupancyTypes (orderNumber, occupancyType)"
)
.run();
lotOccupancyDB.prepare("create table if not exists OccupancyTypeFields (" + lotOccupancyDB
"occupancyTypeFieldId integer not null primary key autoincrement," + .prepare(
" occupancyTypeId integer not null," + "create table if not exists OccupancyTypeFields (" +
" occupancyTypeField varchar(100) not null," + "occupancyTypeFieldId integer not null primary key autoincrement," +
" occupancyTypeFieldValues text," + " occupancyTypeId integer not null," +
" isRequired bit not null default 0," + " occupancyTypeField varchar(100) not null," +
" pattern varchar(100)," + " occupancyTypeFieldValues text," +
" minimumLength smallint not null default 1 check (minimumLength >= 0)," + " isRequired bit not null default 0," +
" maximumLength smallint not null default 100 check (maximumLength >= 0)," + " pattern varchar(100)," +
" orderNumber smallint not null default 0," + " minimumLength smallint not null default 1 check (minimumLength >= 0)," +
recordColumns + "," + " maximumLength smallint not null default 100 check (maximumLength >= 0)," +
" foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" + " orderNumber smallint not null default 0," +
")").run(); recordColumns +
"," +
" foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_occupancytypefields_ordernumber" + lotOccupancyDB
" on OccupancyTypeFields (occupancyTypeId, orderNumber, occupancyTypeField)").run(); .prepare(
"create index if not exists idx_occupancytypefields_ordernumber" +
" on OccupancyTypeFields (occupancyTypeId, orderNumber, occupancyTypeField)"
)
.run();
lotOccupancyDB.prepare("create table if not exists LotOccupantTypes (" + lotOccupancyDB
"lotOccupantTypeId integer not null primary key autoincrement," + .prepare(
" lotOccupantType varchar(100) not null," + "create table if not exists LotOccupantTypes (" +
" orderNumber smallint not null default 0," + "lotOccupantTypeId integer not null primary key autoincrement," +
recordColumns + " lotOccupantType varchar(100) not null," +
")").run(); " orderNumber smallint not null default 0," +
recordColumns +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_lotoccupanttypes_ordernumber" + lotOccupancyDB
" on LotOccupantTypes (orderNumber, lotOccupantType)").run(); .prepare(
"create index if not exists idx_lotoccupanttypes_ordernumber" +
" on LotOccupantTypes (orderNumber, lotOccupantType)"
)
.run();
lotOccupancyDB.prepare("create table if not exists LotOccupancies (" + lotOccupancyDB
"lotOccupancyId integer not null primary key autoincrement," + .prepare(
" occupancyTypeId integer not null," + "create table if not exists LotOccupancies (" +
" lotId integer," + "lotOccupancyId integer not null primary key autoincrement," +
" occupancyStartDate integer not null check (occupancyStartDate > 0)," + " occupancyTypeId integer not null," +
" occupancyEndDate integer check (occupancyEndDate > 0)," + " lotId integer," +
recordColumns + "," + " occupancyStartDate integer not null check (occupancyStartDate > 0)," +
" foreign key (lotId) references Lots (lotId)," + " occupancyEndDate integer check (occupancyEndDate > 0)," +
" foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" + recordColumns +
")").run(); "," +
" foreign key (lotId) references Lots (lotId)," +
" foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" +
")"
)
.run();
lotOccupancyDB.prepare("create table if not exists LotOccupancyOccupants (" + lotOccupancyDB
"lotOccupancyId integer not null," + .prepare(
" lotOccupantIndex integer not null," + "create table if not exists LotOccupancyOccupants (" +
" occupantName varchar(200) not null," + "lotOccupancyId integer not null," +
" occupantAddress1 varchar(50)," + " lotOccupantIndex integer not null," +
" occupantAddress2 varchar(50)," + " occupantName varchar(200) not null," +
" occupantCity varchar(20)," + " occupantAddress1 varchar(50)," +
" occupantProvince varchar(2)," + " occupantAddress2 varchar(50)," +
" occupantPostalCode varchar(7)," + " occupantCity varchar(20)," +
" occupantPhoneNumber varchar(30)," + " occupantProvince varchar(2)," +
" lotOccupantTypeId integer not null," + " occupantPostalCode varchar(7)," +
recordColumns + "," + " occupantPhoneNumber varchar(30)," +
" primary key (lotOccupancyId, lotOccupantIndex)," + " lotOccupantTypeId integer not null," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," + recordColumns +
" foreign key (lotOccupantTypeId) references LotOccupantTypes (lotOccupantTypeId)" + "," +
") without rowid").run(); " primary key (lotOccupancyId, lotOccupantIndex)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," +
" foreign key (lotOccupantTypeId) references LotOccupantTypes (lotOccupantTypeId)" +
") without rowid"
)
.run();
lotOccupancyDB.prepare("create table if not exists LotOccupancyFields (" + lotOccupancyDB
"lotOccupancyId integer not null," + .prepare(
" occupancyTypeFieldId integer not null," + "create table if not exists LotOccupancyFields (" +
" lotOccupancyFieldValue text not null," + "lotOccupancyId integer not null," +
recordColumns + "," + " occupancyTypeFieldId integer not null," +
" primary key (lotOccupancyId, occupancyTypeFieldId)," + " lotOccupancyFieldValue text not null," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," + recordColumns +
" foreign key (occupancyTypeFieldId) references OccupancyTypeFields (occupancyTypeFieldId)" + "," +
") without rowid").run(); " primary key (lotOccupancyId, occupancyTypeFieldId)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," +
" foreign key (occupancyTypeFieldId) references OccupancyTypeFields (occupancyTypeFieldId)" +
") without rowid"
)
.run();
lotOccupancyDB.prepare("create table if not exists LotOccupancyComments (" + lotOccupancyDB
"lotOccupancyCommentId integer not null primary key autoincrement," + .prepare(
" lotOccupancyId integer not null," + "create table if not exists LotOccupancyComments (" +
" lotOccupancyCommentDate integer not null check (lotOccupancyCommentDate > 0)," + "lotOccupancyCommentId integer not null primary key autoincrement," +
" lotOccupancyCommentTime integer not null check (lotOccupancyCommentTime >= 0)," + " lotOccupancyId integer not null," +
" lotOccupancyComment text not null," + " lotOccupancyCommentDate integer not null check (lotOccupancyCommentDate > 0)," +
recordColumns + "," + " lotOccupancyCommentTime integer not null check (lotOccupancyCommentTime >= 0)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" + " lotOccupancyComment text not null," +
")").run(); recordColumns +
"," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_lotoccupancycomments_datetime" + lotOccupancyDB
" on LotOccupancyComments (lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime)").run(); .prepare(
"create index if not exists idx_lotoccupancycomments_datetime" +
" on LotOccupancyComments (lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime)"
)
.run();
// Occupancy Fees and Transactions // Occupancy Fees and Transactions
lotOccupancyDB.prepare("create table if not exists FeeCategories (" + lotOccupancyDB
"feeCategoryId integer not null primary key autoincrement," + .prepare(
" feeCategory varchar(100) not null," + "create table if not exists FeeCategories (" +
" orderNumber smallint not null default 0," + "feeCategoryId integer not null primary key autoincrement," +
recordColumns + " feeCategory varchar(100) not null," +
")").run(); " orderNumber smallint not null default 0," +
recordColumns +
")"
)
.run();
lotOccupancyDB.prepare("create table if not exists Fees (" + lotOccupancyDB
"feeId integer not null primary key autoincrement," + .prepare(
" feeCategoryId integer not null," + "create table if not exists Fees (" +
" feeName varchar(100) not null," + "feeId integer not null primary key autoincrement," +
" feeDescription text," + " feeCategoryId integer not null," +
" occupancyTypeId integer," + " feeName varchar(100) not null," +
" lotTypeId integer," + " feeDescription text," +
" includeQuantity boolean not null default 0," + " occupancyTypeId integer," +
" quantityUnit varchar(30)," + " lotTypeId integer," +
" feeAmount decimal(6, 2)," + " includeQuantity boolean not null default 0," +
" feeFunction varchar(100)," + " quantityUnit varchar(30)," +
" taxAmount decimal(6, 2)," + " feeAmount decimal(6, 2)," +
" taxPercentage decimal(5, 2)," + " feeFunction varchar(100)," +
" isRequired bit not null default 0," + " taxAmount decimal(6, 2)," +
" orderNumber smallint not null default 0," + " taxPercentage decimal(5, 2)," +
recordColumns + "," + " isRequired bit not null default 0," +
" foreign key (feeCategoryId) references FeeCategories (feeCategoryId)," + " orderNumber smallint not null default 0," +
" foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)," + recordColumns +
" foreign key (lotTypeId) references LotTypes (lotTypeId)" + "," +
")").run(); " foreign key (feeCategoryId) references FeeCategories (feeCategoryId)," +
" foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)," +
" foreign key (lotTypeId) references LotTypes (lotTypeId)" +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_fees_ordernumber" + lotOccupancyDB
" on Fees (orderNumber, feeName)").run(); .prepare(
"create index if not exists idx_fees_ordernumber" +
" on Fees (orderNumber, feeName)"
)
.run();
lotOccupancyDB.prepare("create table if not exists LotOccupancyFees (" + lotOccupancyDB
"lotOccupancyId integer not null," + .prepare(
" feeId integer not null," + "create table if not exists LotOccupancyFees (" +
" quantity decimal(4, 1) not null default 1," + "lotOccupancyId integer not null," +
" feeAmount decimal(6, 2) not null," + " feeId integer not null," +
" taxAmount decmial(6, 2) not null," + " quantity decimal(4, 1) not null default 1," +
recordColumns + "," + " feeAmount decimal(6, 2) not null," +
" primary key (lotOccupancyId, feeId)," + " taxAmount decmial(6, 2) not null," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," + recordColumns +
" foreign key (feeId) references Fees (feeId)" + "," +
") without rowid").run(); " primary key (lotOccupancyId, feeId)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)," +
" foreign key (feeId) references Fees (feeId)" +
") without rowid"
)
.run();
lotOccupancyDB.prepare("create table if not exists LotOccupancyTransactions (" + lotOccupancyDB
"lotOccupancyId integer not null," + .prepare(
" transactionIndex integer not null," + "create table if not exists LotOccupancyTransactions (" +
" transactionDate integer not null check (transactionDate > 0)," + "lotOccupancyId integer not null," +
" transactionTime integer not null check (transactionTime >= 0)," + " transactionIndex integer not null," +
" transactionAmount decimal(6, 2) not null," + " transactionDate integer not null check (transactionDate > 0)," +
" externalReceiptNumber varchar(100)," + " transactionTime integer not null check (transactionTime >= 0)," +
" transactionNote text," + " transactionAmount decimal(6, 2) not null," +
recordColumns + "," + " externalReceiptNumber varchar(100)," +
" primary key (lotOccupancyId, transactionIndex)," + " transactionNote text," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" + recordColumns +
") without rowid").run(); "," +
" primary key (lotOccupancyId, transactionIndex)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" +
") without rowid"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_lotoccupancytransactions_ordernumber" + lotOccupancyDB
" on LotOccupancyTransactions (lotOccupancyId, transactionDate, transactionTime)").run(); .prepare(
"create index if not exists idx_lotoccupancytransactions_ordernumber" +
" on LotOccupancyTransactions (lotOccupancyId, transactionDate, transactionTime)"
)
.run();
// Work Orders // Work Orders
lotOccupancyDB.prepare("create table if not exists WorkOrderTypes (" + lotOccupancyDB
"workOrderTypeId integer not null primary key autoincrement," + .prepare(
" workOrderType varchar(100) not null," + "create table if not exists WorkOrderTypes (" +
" orderNumber smallint not null default 0," + "workOrderTypeId integer not null primary key autoincrement," +
recordColumns + " workOrderType varchar(100) not null," +
")").run(); " orderNumber smallint not null default 0," +
recordColumns +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_workordertypes_ordernumber" + lotOccupancyDB
" on WorkOrderTypes (orderNumber, workOrderType)").run(); .prepare(
"create index if not exists idx_workordertypes_ordernumber" +
" on WorkOrderTypes (orderNumber, workOrderType)"
)
.run();
lotOccupancyDB.prepare("create table if not exists WorkOrders (" + lotOccupancyDB
"workOrderId integer not null primary key autoincrement," + .prepare(
" workOrderTypeId integer not null," + "create table if not exists WorkOrders (" +
" workOrderNumber varchar(50) not null," + "workOrderId integer not null primary key autoincrement," +
" workOrderDescription text," + " workOrderTypeId integer not null," +
" workOrderOpenDate integer check (workOrderOpenDate > 0)," + " workOrderNumber varchar(50) not null," +
" workOrderCloseDate integer check (workOrderCloseDate > 0)," + " workOrderDescription text," +
recordColumns + "," + " workOrderOpenDate integer check (workOrderOpenDate > 0)," +
" foreign key (workOrderTypeId) references WorkOrderTypes (workOrderTypeId)" + " workOrderCloseDate integer check (workOrderCloseDate > 0)," +
")").run(); recordColumns +
"," +
" foreign key (workOrderTypeId) references WorkOrderTypes (workOrderTypeId)" +
")"
)
.run();
lotOccupancyDB.prepare("create table if not exists WorkOrderLots (" + lotOccupancyDB
"workOrderId integer not null," + .prepare(
" lotId integer not null," + "create table if not exists WorkOrderLots (" +
recordColumns + "," + "workOrderId integer not null," +
" primary key (workOrderId, lotId)," + " lotId integer not null," +
" foreign key (workOrderId) references WorkOrders (workOrderId)," + recordColumns +
" foreign key (lotId) references Lots (lotId)" + "," +
") without rowid").run(); " primary key (workOrderId, lotId)," +
" foreign key (workOrderId) references WorkOrders (workOrderId)," +
" foreign key (lotId) references Lots (lotId)" +
") without rowid"
)
.run();
lotOccupancyDB.prepare("create table if not exists WorkOrderLotOccupancies (" + lotOccupancyDB
"workOrderId integer not null," + .prepare(
" lotOccupancyId integer not null," + "create table if not exists WorkOrderLotOccupancies (" +
recordColumns + "," + "workOrderId integer not null," +
" primary key (workOrderId, lotOccupancyId)," + " lotOccupancyId integer not null," +
" foreign key (workOrderId) references WorkOrders (workOrderId)," + recordColumns +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" + "," +
") without rowid").run(); " primary key (workOrderId, lotOccupancyId)," +
" foreign key (workOrderId) references WorkOrders (workOrderId)," +
" foreign key (lotOccupancyId) references LotOccupancies (lotOccupancyId)" +
") without rowid"
)
.run();
lotOccupancyDB.prepare("create table if not exists WorkOrderComments (" + lotOccupancyDB
"workOrderCommentId integer not null primary key autoincrement," + .prepare(
" workOrderId integer not null," + "create table if not exists WorkOrderComments (" +
" workOrderCommentDate integer not null check (workOrderCommentDate > 0)," + "workOrderCommentId integer not null primary key autoincrement," +
" workOrderCommentTime integer not null check (workOrderCommentTime >= 0)," + " workOrderId integer not null," +
" workOrderComment text not null," + " workOrderCommentDate integer not null check (workOrderCommentDate > 0)," +
recordColumns + "," + " workOrderCommentTime integer not null check (workOrderCommentTime >= 0)," +
" foreign key (workOrderId) references WorkOrders (workOrderId)" + " workOrderComment text not null," +
")").run(); recordColumns +
"," +
" foreign key (workOrderId) references WorkOrders (workOrderId)" +
")"
)
.run();
lotOccupancyDB.prepare("create index if not exists idx_workordercomments_datetime" + lotOccupancyDB
" on WorkOrderComments (workOrderId, workOrderCommentDate, workOrderCommentTime)").run(); .prepare(
"create index if not exists idx_workordercomments_datetime" +
" on WorkOrderComments (workOrderId, workOrderCommentDate, workOrderCommentTime)"
)
.run();
lotOccupancyDB.close(); lotOccupancyDB.close();
@ -341,4 +487,4 @@ export const initializeDatabase = (): boolean => {
} }
return false; return false;
}; };

View File

@ -14,7 +14,7 @@ export const addFee = (feeForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
.run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, (feeForm.occupancyTypeId || undefined), (feeForm.lotTypeId || undefined), (feeForm.feeAmount || undefined), (feeForm.feeFunction || undefined), (feeForm.taxAmount || undefined), (feeForm.taxPercentage || undefined), (feeForm.includeQuantity ? 1 : 0), feeForm.quantityUnit, (feeForm.isRequired ? 1 : 0), (feeForm.orderNumber || 0), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); .run(feeForm.feeCategoryId, feeForm.feeName, feeForm.feeDescription, feeForm.occupancyTypeId || undefined, feeForm.lotTypeId || undefined, feeForm.feeAmount || undefined, feeForm.feeFunction || undefined, feeForm.taxAmount || undefined, feeForm.taxPercentage || undefined, feeForm.includeQuantity ? 1 : 0, feeForm.quantityUnit, feeForm.isRequired ? 1 : 0, feeForm.orderNumber || 0, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
database.close(); database.close();
return result.lastInsertRowid; return result.lastInsertRowid;
}; };

View File

@ -3,7 +3,6 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddFeeForm { interface AddFeeForm {
feeCategoryId: string; feeCategoryId: string;
feeName: string; feeName: string;
@ -20,16 +19,17 @@ interface AddFeeForm {
orderNumber?: number; orderNumber?: number;
} }
export const addFee = (
feeForm: AddFeeForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addFee = const rightNowMillis = Date.now();
(feeForm: AddFeeForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const result = database
.prepare(
const rightNowMillis = Date.now(); "insert into Fees (" +
const result = database
.prepare("insert into Fees (" +
"feeCategoryId, feeName, feeDescription," + "feeCategoryId, feeName, feeDescription," +
" occupancyTypeId, lotTypeId," + " occupancyTypeId, lotTypeId," +
" feeAmount, feeFunction," + " feeAmount, feeFunction," +
@ -38,29 +38,31 @@ export const addFee =
" isRequired, orderNumber," + " isRequired, orderNumber," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
.run(feeForm.feeCategoryId, )
feeForm.feeName, .run(
feeForm.feeDescription, feeForm.feeCategoryId,
(feeForm.occupancyTypeId || undefined), feeForm.feeName,
(feeForm.lotTypeId || undefined), feeForm.feeDescription,
(feeForm.feeAmount || undefined), feeForm.occupancyTypeId || undefined,
(feeForm.feeFunction || undefined), feeForm.lotTypeId || undefined,
(feeForm.taxAmount || undefined), feeForm.feeAmount || undefined,
(feeForm.taxPercentage || undefined), feeForm.feeFunction || undefined,
(feeForm.includeQuantity ? 1 : 0), feeForm.taxAmount || undefined,
feeForm.quantityUnit, feeForm.taxPercentage || undefined,
(feeForm.isRequired ? 1 : 0), feeForm.includeQuantity ? 1 : 0,
(feeForm.orderNumber || 0), feeForm.quantityUnit,
requestSession.user.userName, feeForm.isRequired ? 1 : 0,
rightNowMillis, feeForm.orderNumber || 0,
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
database.close(); database.close();
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
}; };
export default addFee;
export default addFee;

View File

@ -9,7 +9,7 @@ export const addFeeCategory = (feeCategoryForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?)")
.run(feeCategoryForm.feeCategory, (feeCategoryForm.orderNumber || 0), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); .run(feeCategoryForm.feeCategory, feeCategoryForm.orderNumber || 0, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
database.close(); database.close();
return result.lastInsertRowid; return result.lastInsertRowid;
}; };

View File

@ -3,37 +3,39 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddFeeCategoryForm { interface AddFeeCategoryForm {
feeCategory: string; feeCategory: string;
orderNumber?: number; orderNumber?: number;
} }
export const addFeeCategory = (
feeCategoryForm: AddFeeCategoryForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addFeeCategory = const rightNowMillis = Date.now();
(feeCategoryForm: AddFeeCategoryForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const result = database
.prepare(
const rightNowMillis = Date.now(); "insert into FeeCategories (" +
const result = database
.prepare("insert into FeeCategories (" +
"feeCategory, orderNumber," + "feeCategory, orderNumber," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?)"
.run(feeCategoryForm.feeCategory, )
(feeCategoryForm.orderNumber || 0), .run(
requestSession.user.userName, feeCategoryForm.feeCategory,
rightNowMillis, feeCategoryForm.orderNumber || 0,
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
database.close(); database.close();
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
}; };
export default addFeeCategory;
export default addFeeCategory;

View File

@ -11,7 +11,7 @@ export const addLot = (lotForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
.run(lotForm.lotName, lotForm.lotTypeId, (lotForm.lotStatusId === "" ? undefined : lotForm.lotStatusId), (lotForm.mapId === "" ? undefined : lotForm.mapId), lotForm.mapKey, (lotForm.lotLatitude === "" ? undefined : lotForm.lotLatitude), (lotForm.lotLongitude === "" ? undefined : lotForm.lotLongitude), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); .run(lotForm.lotName, lotForm.lotTypeId, lotForm.lotStatusId === "" ? undefined : lotForm.lotStatusId, lotForm.mapId === "" ? undefined : lotForm.mapId, lotForm.mapKey, lotForm.lotLatitude === "" ? undefined : lotForm.lotLatitude, lotForm.lotLongitude === "" ? undefined : lotForm.lotLongitude, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
database.close(); database.close();
return result.lastInsertRowid; return result.lastInsertRowid;
}; };

View File

@ -1,12 +1,9 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddLotForm { interface AddLotForm {
lotName: string; lotName: string;
lotTypeId: string | number; lotTypeId: string | number;
@ -19,38 +16,41 @@ interface AddLotForm {
lotLongitude: string; lotLongitude: string;
} }
export const addLot = (
lotForm: AddLotForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLot = const rightNowMillis = Date.now();
(lotForm: AddLotForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const result = database
.prepare(
const rightNowMillis = Date.now(); "insert into Lots (" +
const result = database
.prepare("insert into Lots (" +
"lotName, lotTypeId, lotStatusId," + "lotName, lotTypeId, lotStatusId," +
" mapId, mapKey," + " mapId, mapKey," +
" lotLatitude, lotLongitude," + " lotLatitude, lotLongitude," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
.run(lotForm.lotName, )
lotForm.lotTypeId, .run(
(lotForm.lotStatusId === "" ? undefined : lotForm.lotStatusId), lotForm.lotName,
(lotForm.mapId === "" ? undefined : lotForm.mapId), lotForm.lotTypeId,
lotForm.mapKey, lotForm.lotStatusId === "" ? undefined : lotForm.lotStatusId,
(lotForm.lotLatitude === "" ? undefined : lotForm.lotLatitude), lotForm.mapId === "" ? undefined : lotForm.mapId,
(lotForm.lotLongitude === "" ? undefined : lotForm.lotLongitude), lotForm.mapKey,
requestSession.user.userName, lotForm.lotLatitude === "" ? undefined : lotForm.lotLatitude,
rightNowMillis, lotForm.lotLongitude === "" ? undefined : lotForm.lotLongitude,
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
database.close(); database.close();
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
}; };
export default addLot;
export default addLot;

View File

@ -1,46 +1,46 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js"; import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddLotCommentForm { interface AddLotCommentForm {
lotId: string; lotId: string;
lotComment: string; lotComment: string;
} }
export const addLotComment = (
lotCommentForm: AddLotCommentForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotComment = const rightNow = new Date();
(lotCommentForm: AddLotCommentForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const result = database
.prepare(
const rightNow = new Date(); "insert into LotComments (" +
const result = database
.prepare("insert into LotComments (" +
"lotId, lotCommentDate, lotCommentTime, lotComment," + "lotId, lotCommentDate, lotCommentTime, lotComment," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?)"
.run(lotCommentForm.lotId, )
dateTimeFunctions.dateToInteger(rightNow), .run(
dateTimeFunctions.dateToTimeInteger(rightNow), lotCommentForm.lotId,
lotCommentForm.lotComment, dateTimeFunctions.dateToInteger(rightNow),
requestSession.user.userName, dateTimeFunctions.dateToTimeInteger(rightNow),
rightNow.getTime(), lotCommentForm.lotComment,
requestSession.user.userName, requestSession.user.userName,
rightNow.getTime()); rightNow.getTime(),
requestSession.user.userName,
rightNow.getTime()
);
database.close(); database.close();
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
}; };
export default addLotComment;
export default addLotComment;

View File

@ -16,11 +16,9 @@ export const addLotOccupancy = (lotOccupancyForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?)")
.run(lotOccupancyForm.occupancyTypeId, (lotOccupancyForm.lotId === "" ? .run(lotOccupancyForm.occupancyTypeId, lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId, occupancyStartDate, lotOccupancyForm.occupancyEndDateString === ""
undefined : ? undefined
lotOccupancyForm.lotId), occupancyStartDate, (lotOccupancyForm.occupancyEndDateString === "" ? : dateTimeFunctions.dateStringToInteger(lotOccupancyForm.occupancyEndDateString), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
undefined :
dateTimeFunctions.dateStringToInteger(lotOccupancyForm.occupancyEndDateString)), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
const lotOccupancyId = result.lastInsertRowid; const lotOccupancyId = result.lastInsertRowid;
const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds || "").split(","); const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds || "").split(",");
for (const occupancyTypeFieldId of occupancyTypeFieldIds) { for (const occupancyTypeFieldId of occupancyTypeFieldIds) {

View File

@ -1,18 +1,13 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js"; import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js";
import { import { addOrUpdateLotOccupancyField } from "./addOrUpdateLotOccupancyField.js";
addOrUpdateLotOccupancyField
} from "./addOrUpdateLotOccupancyField.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddLotOccupancyForm { interface AddLotOccupancyForm {
occupancyTypeId: string | number; occupancyTypeId: string | number;
lotId: string | number; lotId: string | number;
@ -24,62 +19,73 @@ interface AddLotOccupancyForm {
[lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown; [lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown;
} }
export const addLotOccupancy = (
lotOccupancyForm: AddLotOccupancyForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotOccupancy = const rightNowMillis = Date.now();
(lotOccupancyForm: AddLotOccupancyForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const occupancyStartDate = dateTimeFunctions.dateStringToInteger(
lotOccupancyForm.occupancyStartDateString
);
const rightNowMillis = Date.now(); if (occupancyStartDate <= 0) {
console.error(lotOccupancyForm);
}
const occupancyStartDate = dateTimeFunctions.dateStringToInteger(lotOccupancyForm.occupancyStartDateString); const result = database
.prepare(
if (occupancyStartDate <= 0) { "insert into LotOccupancies (" +
console.error(lotOccupancyForm);
}
const result = database
.prepare("insert into LotOccupancies (" +
"occupancyTypeId, lotId," + "occupancyTypeId, lotId," +
" occupancyStartDate, occupancyEndDate," + " occupancyStartDate, occupancyEndDate," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?)"
.run(lotOccupancyForm.occupancyTypeId, )
(lotOccupancyForm.lotId === "" ? .run(
undefined : lotOccupancyForm.occupancyTypeId,
lotOccupancyForm.lotId), lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId,
occupancyStartDate, occupancyStartDate,
(lotOccupancyForm.occupancyEndDateString === "" ? lotOccupancyForm.occupancyEndDateString === ""
undefined : ? undefined
dateTimeFunctions.dateStringToInteger(lotOccupancyForm.occupancyEndDateString)), : dateTimeFunctions.dateStringToInteger(
requestSession.user.userName, lotOccupancyForm.occupancyEndDateString
rightNowMillis, ),
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
const lotOccupancyId = result.lastInsertRowid as number; const lotOccupancyId = result.lastInsertRowid as number;
const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds || "").split(","); const occupancyTypeFieldIds = (
lotOccupancyForm.occupancyTypeFieldIds || ""
).split(",");
for (const occupancyTypeFieldId of occupancyTypeFieldIds) { for (const occupancyTypeFieldId of occupancyTypeFieldIds) {
const lotOccupancyFieldValue = lotOccupancyForm[
"lotOccupancyFieldValue_" + occupancyTypeFieldId
] as string;
const lotOccupancyFieldValue = lotOccupancyForm["lotOccupancyFieldValue_" + occupancyTypeFieldId] as string; if (lotOccupancyFieldValue && lotOccupancyFieldValue !== "") {
addOrUpdateLotOccupancyField(
if (lotOccupancyFieldValue && lotOccupancyFieldValue !== "") { {
addOrUpdateLotOccupancyField({
lotOccupancyId, lotOccupancyId,
occupancyTypeFieldId, occupancyTypeFieldId,
lotOccupancyFieldValue lotOccupancyFieldValue
}, requestSession, database); },
} requestSession,
database
);
} }
}
database.close();
database.close(); return lotOccupancyId;
};
return lotOccupancyId; export default addLotOccupancy;
};
export default addLotOccupancy;

View File

@ -1,8 +1,6 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import { import {
dateStringToInteger, dateStringToInteger,
@ -13,52 +11,58 @@ import {
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddLotOccupancyCommentForm { interface AddLotOccupancyCommentForm {
lotOccupancyId: string | number; lotOccupancyId: string | number;
lotOccupancyCommentDateString ? : string; lotOccupancyCommentDateString?: string;
lotOccupancyCommentTimeString ? : string; lotOccupancyCommentTimeString?: string;
lotOccupancyComment: string; lotOccupancyComment: string;
} }
export const addLotOccupancyComment = (
commentForm: AddLotOccupancyCommentForm,
requestSession: recordTypes.PartialSession
): number => {
const rightNow = new Date();
export const addLotOccupancyComment = let lotOccupancyCommentDate: number;
(commentForm: AddLotOccupancyCommentForm, requestSession: recordTypes.PartialSession): number => { let lotOccupancyCommentTime: number;
const rightNow = new Date(); if (commentForm.lotOccupancyCommentDateString) {
lotOccupancyCommentDate = dateStringToInteger(
commentForm.lotOccupancyCommentDateString
);
lotOccupancyCommentTime = timeStringToInteger(
commentForm.lotOccupancyCommentTimeString
);
} else {
lotOccupancyCommentDate = dateToInteger(rightNow);
lotOccupancyCommentTime = dateToTimeInteger(rightNow);
}
let lotOccupancyCommentDate: number; const database = sqlite(databasePath);
let lotOccupancyCommentTime: number;
if (commentForm.lotOccupancyCommentDateString) { const result = database
lotOccupancyCommentDate = dateStringToInteger(commentForm.lotOccupancyCommentDateString); .prepare(
lotOccupancyCommentTime = timeStringToInteger(commentForm.lotOccupancyCommentTimeString); "insert into LotOccupancyComments (" +
} else {
lotOccupancyCommentDate = dateToInteger(rightNow);
lotOccupancyCommentTime = dateToTimeInteger(rightNow);
}
const database = sqlite(databasePath);
const result = database
.prepare("insert into LotOccupancyComments (" +
"lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime, lotOccupancyComment," + "lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime, lotOccupancyComment," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?)"
.run(commentForm.lotOccupancyId, )
lotOccupancyCommentDate, .run(
lotOccupancyCommentTime, commentForm.lotOccupancyId,
commentForm.lotOccupancyComment, lotOccupancyCommentDate,
requestSession.user.userName, lotOccupancyCommentTime,
rightNow.getTime(), commentForm.lotOccupancyComment,
requestSession.user.userName, requestSession.user.userName,
rightNow.getTime()); rightNow.getTime(),
requestSession.user.userName,
rightNow.getTime()
);
database.close(); database.close();
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
}; };
export default addLotOccupancyComment;
export default addLotOccupancyComment;

View File

@ -9,8 +9,14 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
let feeAmount; let feeAmount;
let taxAmount; let taxAmount;
if (lotOccupancyFeeForm.feeAmount) { if (lotOccupancyFeeForm.feeAmount) {
feeAmount = typeof (lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount; feeAmount =
taxAmount = typeof (lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount; typeof lotOccupancyFeeForm.feeAmount === "string"
? Number.parseFloat(lotOccupancyFeeForm.feeAmount)
: feeAmount;
taxAmount =
typeof lotOccupancyFeeForm.taxAmount === "string"
? Number.parseFloat(lotOccupancyFeeForm.taxAmount)
: taxAmount;
} }
else { else {
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId); const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId);
@ -18,21 +24,25 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
feeAmount = calculateFeeAmount(fee, lotOccupancy); feeAmount = calculateFeeAmount(fee, lotOccupancy);
taxAmount = calculateTaxAmount(fee, feeAmount); taxAmount = calculateTaxAmount(fee, feeAmount);
} }
const record = database.prepare("select feeAmount, taxAmount, recordDelete_timeMillis" + const record = database
.prepare("select feeAmount, taxAmount, recordDelete_timeMillis" +
" from LotOccupancyFees" + " from LotOccupancyFees" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
" and feeId = ?") " and feeId = ?")
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); .get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
if (record) { if (record) {
if (record.recordDelete_timeMillis) { if (record.recordDelete_timeMillis) {
database.prepare("delete from LotOccupancyFees" + database
.prepare("delete from LotOccupancyFees" +
" where recordDelete_timeMillis is not null" + " where recordDelete_timeMillis is not null" +
" and lotOccupancyId = ?" + " and lotOccupancyId = ?" +
" and feeId = ?") " and feeId = ?")
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); .run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
} }
else if (record.feeAmount === feeAmount && record.taxAmount === taxAmount) { else if (record.feeAmount === feeAmount &&
database.prepare("update LotOccupancyFees" + record.taxAmount === taxAmount) {
database
.prepare("update LotOccupancyFees" +
" set quantity = quantity + ?," + " set quantity = quantity + ?," +
" recordUpdate_userName = ?," + " recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?" + " recordUpdate_timeMillis = ?" +
@ -43,10 +53,11 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
return true; return true;
} }
else { else {
const quantity = typeof (lotOccupancyFeeForm.quantity) === "string" ? const quantity = typeof lotOccupancyFeeForm.quantity === "string"
Number.parseFloat(lotOccupancyFeeForm.quantity) : ? Number.parseFloat(lotOccupancyFeeForm.quantity)
lotOccupancyFeeForm.quantity; : lotOccupancyFeeForm.quantity;
database.prepare("update LotOccupancyFees" + database
.prepare("update LotOccupancyFees" +
" set feeAmount = (feeAmount * quantity) + ?," + " set feeAmount = (feeAmount * quantity) + ?," +
" taxAmount = (taxAmount * quantity) + ?," + " taxAmount = (taxAmount * quantity) + ?," +
" quantity = 1," + " quantity = 1," +
@ -54,7 +65,7 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
" recordUpdate_timeMillis = ?" + " recordUpdate_timeMillis = ?" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
" and feeId = ?") " and feeId = ?")
.run((feeAmount * quantity), (taxAmount * quantity), requestSession.user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); .run(feeAmount * quantity, taxAmount * quantity, requestSession.user.userName, rightNowMillis, lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
database.close(); database.close();
return true; return true;
} }

View File

@ -1,150 +1,165 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import { import { calculateFeeAmount, calculateTaxAmount } from "../functions.fee.js";
calculateFeeAmount,
calculateTaxAmount
} from "../functions.fee.js";
import { import { getFee } from "./getFee.js";
getFee
} from "./getFee.js";
import { import { getLotOccupancy } from "./getLotOccupancy.js";
getLotOccupancy
} from "./getLotOccupancy.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddLotOccupancyFeeForm { interface AddLotOccupancyFeeForm {
lotOccupancyId: number | string; lotOccupancyId: number | string;
feeId: number | string; feeId: number | string;
quantity: number | string; quantity: number | string;
feeAmount ? : number | string; feeAmount?: number | string;
taxAmount ? : number | string; taxAmount?: number | string;
} }
export const addLotOccupancyFee = (
lotOccupancyFeeForm: AddLotOccupancyFeeForm,
requestSession: recordTypes.PartialSession
): boolean => {
const database = sqlite(databasePath);
export const addLotOccupancyFee = const rightNowMillis = Date.now();
(lotOccupancyFeeForm: AddLotOccupancyFeeForm, requestSession: recordTypes.PartialSession): boolean => {
const database = sqlite(databasePath); // Calculate fee and tax (if not set)
const rightNowMillis = Date.now(); let feeAmount: number;
let taxAmount: number;
// Calculate fee and tax (if not set) if (lotOccupancyFeeForm.feeAmount) {
feeAmount =
typeof lotOccupancyFeeForm.feeAmount === "string"
? Number.parseFloat(lotOccupancyFeeForm.feeAmount)
: feeAmount;
taxAmount =
typeof lotOccupancyFeeForm.taxAmount === "string"
? Number.parseFloat(lotOccupancyFeeForm.taxAmount)
: taxAmount;
} else {
const lotOccupancy = getLotOccupancy(
lotOccupancyFeeForm.lotOccupancyId
);
const fee = getFee(lotOccupancyFeeForm.feeId);
let feeAmount: number; feeAmount = calculateFeeAmount(fee, lotOccupancy);
let taxAmount: number; taxAmount = calculateTaxAmount(fee, feeAmount);
}
if (lotOccupancyFeeForm.feeAmount) { // Check if record already exists
feeAmount = typeof (lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
taxAmount = typeof (lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
} else {
const lotOccupancy = getLotOccupancy(lotOccupancyFeeForm.lotOccupancyId); const record: {
const fee = getFee(lotOccupancyFeeForm.feeId); feeAmount?: number;
taxAmount?: number;
feeAmount = calculateFeeAmount(fee, lotOccupancy); recordDelete_timeMillis?: number;
taxAmount = calculateTaxAmount(fee, feeAmount); } = database
} .prepare(
"select feeAmount, taxAmount, recordDelete_timeMillis" +
// Check if record already exists
const record: {
feeAmount ? : number;
taxAmount ? : number;
recordDelete_timeMillis ? : number
} = database.prepare("select feeAmount, taxAmount, recordDelete_timeMillis" +
" from LotOccupancyFees" + " from LotOccupancyFees" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
" and feeId = ?") " and feeId = ?"
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); )
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
if (record) { if (record) {
if (record.recordDelete_timeMillis) { if (record.recordDelete_timeMillis) {
database
database.prepare("delete from LotOccupancyFees" + .prepare(
"delete from LotOccupancyFees" +
" where recordDelete_timeMillis is not null" + " where recordDelete_timeMillis is not null" +
" and lotOccupancyId = ?" + " and lotOccupancyId = ?" +
" and feeId = ?") " and feeId = ?"
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId); )
.run(
} else if (record.feeAmount === feeAmount && record.taxAmount === taxAmount) { lotOccupancyFeeForm.lotOccupancyId,
lotOccupancyFeeForm.feeId
database.prepare("update LotOccupancyFees" + );
} else if (
record.feeAmount === feeAmount &&
record.taxAmount === taxAmount
) {
database
.prepare(
"update LotOccupancyFees" +
" set quantity = quantity + ?," + " set quantity = quantity + ?," +
" recordUpdate_userName = ?," + " recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?" + " recordUpdate_timeMillis = ?" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
" and feeId = ?") " and feeId = ?"
.run( )
lotOccupancyFeeForm.quantity, .run(
requestSession.user.userName, lotOccupancyFeeForm.quantity,
rightNowMillis, requestSession.user.userName,
lotOccupancyFeeForm.lotOccupancyId, rightNowMillis,
lotOccupancyFeeForm.feeId); lotOccupancyFeeForm.lotOccupancyId,
lotOccupancyFeeForm.feeId
);
database.close(); database.close();
return true; return true;
} else {
const quantity =
typeof lotOccupancyFeeForm.quantity === "string"
? Number.parseFloat(lotOccupancyFeeForm.quantity)
: lotOccupancyFeeForm.quantity;
} else { database
.prepare(
const quantity = typeof (lotOccupancyFeeForm.quantity) === "string" ? "update LotOccupancyFees" +
Number.parseFloat(lotOccupancyFeeForm.quantity) :
lotOccupancyFeeForm.quantity;
database.prepare("update LotOccupancyFees" +
" set feeAmount = (feeAmount * quantity) + ?," + " set feeAmount = (feeAmount * quantity) + ?," +
" taxAmount = (taxAmount * quantity) + ?," + " taxAmount = (taxAmount * quantity) + ?," +
" quantity = 1," + " quantity = 1," +
" recordUpdate_userName = ?," + " recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?" + " recordUpdate_timeMillis = ?" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
" and feeId = ?") " and feeId = ?"
.run( )
(feeAmount * quantity), .run(
(taxAmount * quantity), feeAmount * quantity,
requestSession.user.userName, taxAmount * quantity,
rightNowMillis, requestSession.user.userName,
lotOccupancyFeeForm.lotOccupancyId, rightNowMillis,
lotOccupancyFeeForm.feeId); lotOccupancyFeeForm.lotOccupancyId,
lotOccupancyFeeForm.feeId
);
database.close(); database.close();
return true;
}
return true;
} }
}
// Create new record // Create new record
const result = database const result = database
.prepare("insert into LotOccupancyFees (" + .prepare(
"insert into LotOccupancyFees (" +
"lotOccupancyId, feeId," + "lotOccupancyId, feeId," +
" quantity, feeAmount, taxAmount," + " quantity, feeAmount, taxAmount," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?, ?)"
.run(lotOccupancyFeeForm.lotOccupancyId, )
lotOccupancyFeeForm.feeId, .run(
lotOccupancyFeeForm.quantity, lotOccupancyFeeForm.lotOccupancyId,
feeAmount, lotOccupancyFeeForm.feeId,
taxAmount, lotOccupancyFeeForm.quantity,
requestSession.user.userName, feeAmount,
rightNowMillis, taxAmount,
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
database.close(); database.close();
return result.changes > 0 return result.changes > 0;
}; };
export default addLotOccupancyFee;
export default addLotOccupancyFee;

View File

@ -3,7 +3,8 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
export const addLotOccupancyOccupant = (lotOccupancyOccupantForm, requestSession) => { export const addLotOccupancyOccupant = (lotOccupancyOccupantForm, requestSession) => {
const database = sqlite(databasePath); const database = sqlite(databasePath);
let lotOccupantIndex = 0; let lotOccupantIndex = 0;
const maxIndexResult = database.prepare("select lotOccupantIndex" + const maxIndexResult = database
.prepare("select lotOccupantIndex" +
" from LotOccupancyOccupants" + " from LotOccupancyOccupants" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
" order by lotOccupantIndex desc" + " order by lotOccupantIndex desc" +

View File

@ -1,12 +1,9 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddLotOccupancyOccupantForm { interface AddLotOccupancyOccupantForm {
lotOccupancyId: string | number; lotOccupancyId: string | number;
lotOccupantTypeId: string | number; lotOccupantTypeId: string | number;
@ -19,29 +16,33 @@ interface AddLotOccupancyOccupantForm {
occupantPhoneNumber: string; occupantPhoneNumber: string;
} }
export const addLotOccupancyOccupant = (
lotOccupancyOccupantForm: AddLotOccupancyOccupantForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotOccupancyOccupant = let lotOccupantIndex = 0;
(lotOccupancyOccupantForm: AddLotOccupancyOccupantForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const maxIndexResult = database
.prepare(
let lotOccupantIndex = 0; "select lotOccupantIndex" +
const maxIndexResult = database.prepare("select lotOccupantIndex" +
" from LotOccupancyOccupants" + " from LotOccupancyOccupants" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
" order by lotOccupantIndex desc" + " order by lotOccupantIndex desc" +
" limit 1") " limit 1"
.get(lotOccupancyOccupantForm.lotOccupancyId); )
.get(lotOccupancyOccupantForm.lotOccupancyId);
if (maxIndexResult) { if (maxIndexResult) {
lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1; lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1;
} }
const rightNowMillis = Date.now(); const rightNowMillis = Date.now();
database database
.prepare("insert into LotOccupancyOccupants (" + .prepare(
"insert into LotOccupancyOccupants (" +
"lotOccupancyId, lotOccupantIndex," + "lotOccupancyId, lotOccupantIndex," +
" occupantName," + " occupantName," +
" occupantAddress1, occupantAddress2," + " occupantAddress1, occupantAddress2," +
@ -50,26 +51,28 @@ export const addLotOccupancyOccupant =
" lotOccupantTypeId," + " lotOccupantTypeId," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
.run(lotOccupancyOccupantForm.lotOccupancyId, )
lotOccupantIndex, .run(
lotOccupancyOccupantForm.occupantName, lotOccupancyOccupantForm.lotOccupancyId,
lotOccupancyOccupantForm.occupantAddress1, lotOccupantIndex,
lotOccupancyOccupantForm.occupantAddress2, lotOccupancyOccupantForm.occupantName,
lotOccupancyOccupantForm.occupantCity, lotOccupancyOccupantForm.occupantAddress1,
lotOccupancyOccupantForm.occupantProvince, lotOccupancyOccupantForm.occupantAddress2,
lotOccupancyOccupantForm.occupantPostalCode, lotOccupancyOccupantForm.occupantCity,
lotOccupancyOccupantForm.occupantPhoneNumber, lotOccupancyOccupantForm.occupantProvince,
lotOccupancyOccupantForm.lotOccupantTypeId, lotOccupancyOccupantForm.occupantPostalCode,
requestSession.user.userName, lotOccupancyOccupantForm.occupantPhoneNumber,
rightNowMillis, lotOccupancyOccupantForm.lotOccupantTypeId,
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
database.close(); database.close();
return lotOccupantIndex; return lotOccupantIndex;
}; };
export default addLotOccupancyOccupant;
export default addLotOccupancyOccupant;

View File

@ -4,7 +4,8 @@ import { dateStringToInteger, dateToInteger, dateToTimeInteger, timeStringToInte
export const addLotOccupancyTransaction = (lotOccupancyTransactionForm, requestSession) => { export const addLotOccupancyTransaction = (lotOccupancyTransactionForm, requestSession) => {
const database = sqlite(databasePath); const database = sqlite(databasePath);
let transactionIndex = 0; let transactionIndex = 0;
const maxIndexResult = database.prepare("select transactionIndex" + const maxIndexResult = database
.prepare("select transactionIndex" +
" from LotOccupancyTransactions" + " from LotOccupancyTransactions" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
" order by transactionIndex desc" + " order by transactionIndex desc" +
@ -14,12 +15,12 @@ export const addLotOccupancyTransaction = (lotOccupancyTransactionForm, requestS
transactionIndex = maxIndexResult.transactionIndex + 1; transactionIndex = maxIndexResult.transactionIndex + 1;
} }
const rightNow = new Date(); const rightNow = new Date();
const transactionDate = lotOccupancyTransactionForm.transactionDateString ? const transactionDate = lotOccupancyTransactionForm.transactionDateString
dateStringToInteger(lotOccupancyTransactionForm.transactionDateString) : ? dateStringToInteger(lotOccupancyTransactionForm.transactionDateString)
dateToInteger(rightNow); : dateToInteger(rightNow);
const transactionTime = lotOccupancyTransactionForm.transactionTimeString ? const transactionTime = lotOccupancyTransactionForm.transactionTimeString
timeStringToInteger(lotOccupancyTransactionForm.transactionTimeString) : ? timeStringToInteger(lotOccupancyTransactionForm.transactionTimeString)
dateToTimeInteger(rightNow); : dateToTimeInteger(rightNow);
database database
.prepare("insert into LotOccupancyTransactions (" + .prepare("insert into LotOccupancyTransactions (" +
"lotOccupancyId, transactionIndex," + "lotOccupancyId, transactionIndex," +

View File

@ -1,8 +1,6 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import { import {
dateStringToInteger, dateStringToInteger,
@ -13,70 +11,75 @@ import {
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddLotOccupancyTransactionForm { interface AddLotOccupancyTransactionForm {
lotOccupancyId: string | number; lotOccupancyId: string | number;
transactionDateString ? : string; transactionDateString?: string;
transactionTimeString ? : string; transactionTimeString?: string;
transactionAmount: string | number; transactionAmount: string | number;
externalReceiptNumber: string; externalReceiptNumber: string;
transactionNote: string; transactionNote: string;
} }
export const addLotOccupancyTransaction = (
lotOccupancyTransactionForm: AddLotOccupancyTransactionForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotOccupancyTransaction = let transactionIndex = 0;
(lotOccupancyTransactionForm: AddLotOccupancyTransactionForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const maxIndexResult = database
.prepare(
let transactionIndex = 0; "select transactionIndex" +
const maxIndexResult = database.prepare("select transactionIndex" +
" from LotOccupancyTransactions" + " from LotOccupancyTransactions" +
" where lotOccupancyId = ?" + " where lotOccupancyId = ?" +
" order by transactionIndex desc" + " order by transactionIndex desc" +
" limit 1") " limit 1"
.get(lotOccupancyTransactionForm.lotOccupancyId); )
.get(lotOccupancyTransactionForm.lotOccupancyId);
if (maxIndexResult) { if (maxIndexResult) {
transactionIndex = maxIndexResult.transactionIndex + 1; transactionIndex = maxIndexResult.transactionIndex + 1;
} }
const rightNow = new Date(); const rightNow = new Date();
const transactionDate = lotOccupancyTransactionForm.transactionDateString ? const transactionDate = lotOccupancyTransactionForm.transactionDateString
dateStringToInteger(lotOccupancyTransactionForm.transactionDateString) : ? dateStringToInteger(lotOccupancyTransactionForm.transactionDateString)
dateToInteger(rightNow); : dateToInteger(rightNow);
const transactionTime = lotOccupancyTransactionForm.transactionTimeString ? const transactionTime = lotOccupancyTransactionForm.transactionTimeString
timeStringToInteger(lotOccupancyTransactionForm.transactionTimeString) : ? timeStringToInteger(lotOccupancyTransactionForm.transactionTimeString)
dateToTimeInteger(rightNow); : dateToTimeInteger(rightNow);
database database
.prepare("insert into LotOccupancyTransactions (" + .prepare(
"insert into LotOccupancyTransactions (" +
"lotOccupancyId, transactionIndex," + "lotOccupancyId, transactionIndex," +
" transactionDate, transactionTime," + " transactionDate, transactionTime," +
" transactionAmount, externalReceiptNumber," + " transactionAmount, externalReceiptNumber," +
" transactionNote," + " transactionNote," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
.run(lotOccupancyTransactionForm.lotOccupancyId, )
transactionIndex, .run(
transactionDate, lotOccupancyTransactionForm.lotOccupancyId,
transactionTime, transactionIndex,
lotOccupancyTransactionForm.transactionAmount, transactionDate,
lotOccupancyTransactionForm.externalReceiptNumber, transactionTime,
lotOccupancyTransactionForm.transactionNote, lotOccupancyTransactionForm.transactionAmount,
requestSession.user.userName, lotOccupancyTransactionForm.externalReceiptNumber,
rightNow.getTime(), lotOccupancyTransactionForm.transactionNote,
requestSession.user.userName, requestSession.user.userName,
rightNow.getTime()); rightNow.getTime(),
requestSession.user.userName,
rightNow.getTime()
);
database.close(); database.close();
return transactionIndex; return transactionIndex;
}; };
export default addLotOccupancyTransaction;
export default addLotOccupancyTransaction;

View File

@ -10,7 +10,7 @@ export const addLotOccupantType = (lotOccupantTypeForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?)")
.run(lotOccupantTypeForm.lotOccupantType, (lotOccupantTypeForm.orderNumber || -1), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); .run(lotOccupantTypeForm.lotOccupantType, lotOccupantTypeForm.orderNumber || -1, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
database.close(); database.close();
clearLotOccupantTypesCache(); clearLotOccupantTypesCache();
return result.lastInsertRowid; return result.lastInsertRowid;

View File

@ -1,45 +1,45 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
import { clearLotOccupantTypesCache } from "../functions.cache.js"; import { clearLotOccupantTypesCache } from "../functions.cache.js";
interface AddLotOccupantTypeForm { interface AddLotOccupantTypeForm {
lotOccupantType: string; lotOccupantType: string;
orderNumber?: number; orderNumber?: number;
} }
export const addLotOccupantType = (
lotOccupantTypeForm: AddLotOccupantTypeForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotOccupantType = const rightNowMillis = Date.now();
(lotOccupantTypeForm: AddLotOccupantTypeForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const result = database
.prepare(
const rightNowMillis = Date.now(); "insert into LotOccupantTypes (" +
const result = database
.prepare("insert into LotOccupantTypes (" +
"lotOccupantType, orderNumber," + "lotOccupantType, orderNumber," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?)"
.run(lotOccupantTypeForm.lotOccupantType, )
(lotOccupantTypeForm.orderNumber || -1), .run(
requestSession.user.userName, lotOccupantTypeForm.lotOccupantType,
rightNowMillis, lotOccupantTypeForm.orderNumber || -1,
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
database.close(); database.close();
clearLotOccupantTypesCache(); clearLotOccupantTypesCache();
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
}; };
export default addLotOccupantType;
export default addLotOccupantType;

View File

@ -10,7 +10,7 @@ export const addLotStatus = (lotStatusForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?)")
.run(lotStatusForm.lotStatus, (lotStatusForm.orderNumber || -1), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); .run(lotStatusForm.lotStatus, lotStatusForm.orderNumber || -1, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
database.close(); database.close();
clearLotStatusesCache(); clearLotStatusesCache();
return result.lastInsertRowid; return result.lastInsertRowid;

View File

@ -1,45 +1,45 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
import { clearLotStatusesCache } from "../functions.cache.js"; import { clearLotStatusesCache } from "../functions.cache.js";
interface AddLotStatusForm { interface AddLotStatusForm {
lotStatus: string; lotStatus: string;
orderNumber?: number; orderNumber?: number;
} }
export const addLotStatus = (
lotStatusForm: AddLotStatusForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotStatus = const rightNowMillis = Date.now();
(lotStatusForm: AddLotStatusForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const result = database
.prepare(
const rightNowMillis = Date.now(); "insert into LotStatuses (" +
const result = database
.prepare("insert into LotStatuses (" +
"lotStatus, orderNumber," + "lotStatus, orderNumber," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?)"
.run(lotStatusForm.lotStatus, )
(lotStatusForm.orderNumber || -1), .run(
requestSession.user.userName, lotStatusForm.lotStatus,
rightNowMillis, lotStatusForm.orderNumber || -1,
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
database.close(); database.close();
clearLotStatusesCache(); clearLotStatusesCache();
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
}; };
export default addLotStatus;
export default addLotStatus;

View File

@ -10,7 +10,7 @@ export const addLotType = (lotTypeForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?)")
.run(lotTypeForm.lotType, (lotTypeForm.orderNumber || 0), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); .run(lotTypeForm.lotType, lotTypeForm.orderNumber || 0, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
database.close(); database.close();
clearLotTypesCache(); clearLotTypesCache();
return result.lastInsertRowid; return result.lastInsertRowid;

View File

@ -1,48 +1,46 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import { import { clearLotTypesCache } from "../functions.cache.js";
clearLotTypesCache
} from "../functions.cache.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddLotTypeForm { interface AddLotTypeForm {
lotType: string; lotType: string;
orderNumber ? : number; orderNumber?: number;
} }
export const addLotType = (
lotTypeForm: AddLotTypeForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotType = const rightNowMillis = Date.now();
(lotTypeForm: AddLotTypeForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const result = database
.prepare(
const rightNowMillis = Date.now(); "insert into LotTypes (" +
const result = database
.prepare("insert into LotTypes (" +
"lotType, orderNumber," + "lotType, orderNumber," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?)"
.run(lotTypeForm.lotType, )
(lotTypeForm.orderNumber || 0), .run(
requestSession.user.userName, lotTypeForm.lotType,
rightNowMillis, lotTypeForm.orderNumber || 0,
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
database.close(); database.close();
clearLotTypesCache(); clearLotTypesCache();
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
}; };
export default addLotType;
export default addLotType;

View File

@ -11,7 +11,7 @@ export const addMap = (mapForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
.run(mapForm.mapName, mapForm.mapDescription, mapForm.mapSVG, (mapForm.mapLatitude === "" ? undefined : mapForm.mapLatitude), (mapForm.mapLongitude === "" ? undefined : mapForm.mapLongitude), mapForm.mapAddress1, mapForm.mapAddress2, mapForm.mapCity, mapForm.mapProvince, mapForm.mapPostalCode, mapForm.mapPhoneNumber, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); .run(mapForm.mapName, mapForm.mapDescription, mapForm.mapSVG, mapForm.mapLatitude === "" ? undefined : mapForm.mapLatitude, mapForm.mapLongitude === "" ? undefined : mapForm.mapLongitude, mapForm.mapAddress1, mapForm.mapAddress2, mapForm.mapCity, mapForm.mapProvince, mapForm.mapPostalCode, mapForm.mapPhoneNumber, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
database.close(); database.close();
return result.lastInsertRowid; return result.lastInsertRowid;
}; };

View File

@ -1,12 +1,9 @@
import sqlite from "better-sqlite3"; import sqlite from "better-sqlite3";
import { import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import type * as recordTypes from "../../types/recordTypes"; import type * as recordTypes from "../../types/recordTypes";
interface AddMapForm { interface AddMapForm {
mapName: string; mapName: string;
mapDescription: string; mapDescription: string;
@ -21,42 +18,45 @@ interface AddMapForm {
mapPhoneNumber: string; mapPhoneNumber: string;
} }
export const addMap = (
mapForm: AddMapForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addMap = const rightNowMillis = Date.now();
(mapForm: AddMapForm, requestSession: recordTypes.PartialSession): number => {
const database = sqlite(databasePath); const result = database
.prepare(
const rightNowMillis = Date.now(); "insert into Maps (" +
const result = database
.prepare("insert into Maps (" +
"mapName, mapDescription," + "mapName, mapDescription," +
" mapSVG, mapLatitude, mapLongitude," + " mapSVG, mapLatitude, mapLongitude," +
" mapAddress1, mapAddress2, mapCity, mapProvince, mapPostalCode, mapPhoneNumber," + " mapAddress1, mapAddress2, mapCity, mapProvince, mapPostalCode, mapPhoneNumber," +
" recordCreate_userName, recordCreate_timeMillis," + " recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" + " recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
.run(mapForm.mapName, )
mapForm.mapDescription, .run(
mapForm.mapSVG, mapForm.mapName,
(mapForm.mapLatitude === "" ? undefined : mapForm.mapLatitude), mapForm.mapDescription,
(mapForm.mapLongitude === "" ? undefined : mapForm.mapLongitude), mapForm.mapSVG,
mapForm.mapAddress1, mapForm.mapLatitude === "" ? undefined : mapForm.mapLatitude,
mapForm.mapAddress2, mapForm.mapLongitude === "" ? undefined : mapForm.mapLongitude,
mapForm.mapCity, mapForm.mapAddress1,
mapForm.mapProvince, mapForm.mapAddress2,
mapForm.mapPostalCode, mapForm.mapCity,
mapForm.mapPhoneNumber, mapForm.mapProvince,
requestSession.user.userName, mapForm.mapPostalCode,
rightNowMillis, mapForm.mapPhoneNumber,
requestSession.user.userName, requestSession.user.userName,
rightNowMillis); rightNowMillis,
requestSession.user.userName,
rightNowMillis
);
database.close(); database.close();
return result.lastInsertRowid as number; return result.lastInsertRowid as number;
}; };
export default addMap;
export default addMap;

Some files were not shown because too many files have changed in this diff Show More