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,
"env": {
"es6": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json", "./public-typescript/tsconfig.json"],
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"unicorn"
],
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:node/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"
]
}
"root": true,
"env": {
"es6": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json", "./public-typescript/tsconfig.json"],
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "unicorn"],
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:node/recommended",
"plugin:promise/recommended",
"plugin:unicorn/recommended",
"plugin:@typescript-eslint/recommended"
],
"unicorn/prefer-node-protocol": "off",
"unicorn/prevent-abbreviations": [
"error", {
"replacements": {
"def": {
"definition": true
},
"ele": {
"element": true
},
"eles": {
"elements": true
},
"fns": {
"functions": true
},
"res": {
"result": false
}
}
}
]
}
"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",
"unicorn/prevent-abbreviations": [
"error",
{
"replacements": {
"def": {
"definition": true
},
"ele": {
"element": true
},
"eles": {
"elements": true
},
"fns": {
"functions": true
},
"res": {
"result": false
}
}
}
]
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -4,12 +4,16 @@ import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js
export const handler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
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 lotOccupantTypes = getLotOccupantTypes();
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,
occupancyTypes,
lotOccupantTypes,

View File

@ -1,6 +1,4 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
getLotOccupantTypes,
@ -9,24 +7,27 @@ import {
import * as configFunctions from "../../helpers/functions.config.js";
import {
getLotOccupancy
} from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
export const handler: RequestHandler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
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 lotOccupantTypes = getLotOccupantTypes();
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,
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();
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,
occupancyTypes,
isCreate: true

View File

@ -1,26 +1,19 @@
import type { RequestHandler } from "express";
import {
dateToInteger,
dateToString
} from "@cityssm/expressjs-server-js/dateTimeFns.js";
import type {
RequestHandler
} from "express";
import {
getOccupancyTypes
} from "../../helpers/functions.cache.js";
import { getOccupancyTypes } from "../../helpers/functions.cache.js";
import {
getLot
} from "../../helpers/lotOccupancyDB/getLot.js";
import { getLot } from "../../helpers/lotOccupancyDB/getLot.js";
import * as configFunctions from "../../helpers/functions.config.js";
import type * as recordTypes from "../../types/recordTypes";
export const handler: RequestHandler = (request, response) => {
const startDate = new Date();
const lotOccupancy: recordTypes.LotOccupancy = {
@ -39,7 +32,12 @@ export const handler: RequestHandler = (request, response) => {
const occupancyTypes = getOccupancyTypes();
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,
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) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
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", {
headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Print",
headTitle: configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" Print",
lotOccupancy
});
};

View File

@ -1,27 +1,27 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import * as configFunctions from "../../helpers/functions.config.js";
import {
getLotOccupancy
} from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
export const handler: RequestHandler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
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", {
headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " Print",
headTitle:
configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" Print",
lotOccupancy
});
};
export default handler;
export default handler;

View File

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

View File

@ -1,27 +1,27 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import * as configFunctions from "../../helpers/functions.config.js";
import {
getLotOccupancy
} from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js";
export const handler: RequestHandler = (request, response) => {
const lotOccupancy = getLotOccupancy(request.params.lotOccupancyId);
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", {
headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " View",
headTitle:
configFunctions.getProperty("aliases.lot") +
" " +
configFunctions.getProperty("aliases.occupancy") +
" View",
lotOccupancy
});
};
export default handler;
export default handler;

View File

@ -1,21 +1,15 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
addLotOccupancyComment
} from "../../helpers/lotOccupancyDB/addLotOccupancyComment.js";
import {
getLotOccupancyComments
} from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
import { addLotOccupancyComment } from "../../helpers/lotOccupancyDB/addLotOccupancyComment.js";
import { getLotOccupancyComments } from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
export const handler: RequestHandler = async (request, response) => {
addLotOccupancyComment(request.body, request.session);
const lotOccupancyComments = getLotOccupancyComments(request.body.lotOccupancyId);
const lotOccupancyComments = getLotOccupancyComments(
request.body.lotOccupancyId
);
response.json({
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
addLotOccupancyFee
} from "../../helpers/lotOccupancyDB/addLotOccupancyFee.js";
import {
getLotOccupancyFees
} from "../../helpers/lotOccupancyDB/getLotOccupancyFees.js";
import { addLotOccupancyFee } from "../../helpers/lotOccupancyDB/addLotOccupancyFee.js";
import { getLotOccupancyFees } from "../../helpers/lotOccupancyDB/getLotOccupancyFees.js";
export const handler: RequestHandler = async (request, response) => {
addLotOccupancyFee(request.body, request.session);
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
addLotOccupancyOccupant
} from "../../helpers/lotOccupancyDB/addLotOccupancyOccupant.js";
import {
getLotOccupancyOccupants
} from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
import { addLotOccupancyOccupant } from "../../helpers/lotOccupancyDB/addLotOccupancyOccupant.js";
import { getLotOccupancyOccupants } from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
export const handler: RequestHandler = async (request, response) => {
addLotOccupancyOccupant(request.body, request.session);
const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId);
const lotOccupancyOccupants = getLotOccupancyOccupants(
request.body.lotOccupancyId
);
response.json({
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
addLotOccupancyTransaction
} from "../../helpers/lotOccupancyDB/addLotOccupancyTransaction.js";
import {
getLotOccupancyTransactions
} from "../../helpers/lotOccupancyDB/getLotOccupancyTransactions.js";
import { addLotOccupancyTransaction } from "../../helpers/lotOccupancyDB/addLotOccupancyTransaction.js";
import { getLotOccupancyTransactions } from "../../helpers/lotOccupancyDB/getLotOccupancyTransactions.js";
export const handler: RequestHandler = async (request, response) => {
addLotOccupancyTransaction(request.body, request.session);
const lotOccupancyTransactions = getLotOccupancyTransactions(request.body.lotOccupancyId);
const lotOccupancyTransactions = getLotOccupancyTransactions(
request.body.lotOccupancyId
);
response.json({
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 {
RequestHandler
} from "express";
import {
addLotOccupancy
} from "../../helpers/lotOccupancyDB/addLotOccupancy.js";
import type { RequestHandler } from "express";
import { addLotOccupancy } from "../../helpers/lotOccupancyDB/addLotOccupancy.js";
export const handler: RequestHandler = async (request, response) => {
const lotOccupancyId = addLotOccupancy(request.body, request.session);
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 {
RequestHandler
} from "express";
import {
deleteLotOccupancy
} from "../../helpers/lotOccupancyDB/deleteLotOccupancy.js";
import type { RequestHandler } from "express";
import { deleteLotOccupancy } from "../../helpers/lotOccupancyDB/deleteLotOccupancy.js";
export const handler: RequestHandler = async (request, response) => {
const success = deleteLotOccupancy(request.body.lotOccupancyId, request.session);
const success = deleteLotOccupancy(
request.body.lotOccupancyId,
request.session
);
response.json({
success
});
};
export default handler;
export default handler;

View File

@ -1,19 +1,18 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
deleteLotOccupancyComment
} from "../../helpers/lotOccupancyDB/deleteLotOccupancyComment.js";
import {getLotOccupancyComments} from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
import { deleteLotOccupancyComment } from "../../helpers/lotOccupancyDB/deleteLotOccupancyComment.js";
import { getLotOccupancyComments } from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
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({
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
deleteLotOccupancyFee
} from "../../helpers/lotOccupancyDB/deleteLotOccupancyFee.js";
import {
getLotOccupancyFees
} from "../../helpers/lotOccupancyDB/getLotOccupancyFees.js";
import { deleteLotOccupancyFee } from "../../helpers/lotOccupancyDB/deleteLotOccupancyFee.js";
import { getLotOccupancyFees } from "../../helpers/lotOccupancyDB/getLotOccupancyFees.js";
export const handler: RequestHandler = async (request, response) => {
const success = deleteLotOccupancyFee(request.body.lotOccupancyId, request.body.feeId, request.session);
const success = deleteLotOccupancyFee(
request.body.lotOccupancyId,
request.body.feeId,
request.session
);
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
deleteLotOccupancyOccupant
} from "../../helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js";
import {
getLotOccupancyOccupants
} from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
import { deleteLotOccupancyOccupant } from "../../helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js";
import { getLotOccupancyOccupants } from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
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({
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
deleteLotOccupancyTransaction
} from "../../helpers/lotOccupancyDB/deleteLotOccupancyTransaction.js";
import {
getLotOccupancyTransactions
} from "../../helpers/lotOccupancyDB/getLotOccupancyTransactions.js";
import { deleteLotOccupancyTransaction } from "../../helpers/lotOccupancyDB/deleteLotOccupancyTransaction.js";
import { getLotOccupancyTransactions } from "../../helpers/lotOccupancyDB/getLotOccupancyTransactions.js";
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({
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
});
response.json({
feeCategories,
feeCategories
});
};
export default handler;

View File

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

View File

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

View File

@ -1,14 +1,8 @@
import type {
RequestHandler
} from "express";
import {
getLotOccupancies
} from "../../helpers/lotOccupancyDB/getLotOccupancies.js";
import type { RequestHandler } from "express";
import { getLotOccupancies } from "../../helpers/lotOccupancyDB/getLotOccupancies.js";
export const handler: RequestHandler = async (request, response) => {
const result = getLotOccupancies(request.body, {
limit: request.body.limit,
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 {
RequestHandler
} from "express";
import {
updateLotOccupancy
} from "../../helpers/lotOccupancyDB/updateLotOccupancy.js";
import type { RequestHandler } from "express";
import { updateLotOccupancy } from "../../helpers/lotOccupancyDB/updateLotOccupancy.js";
export const handler: RequestHandler = async (request, response) => {
const success = updateLotOccupancy(request.body, request.session);
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
updateLotOccupancyComment
} from "../../helpers/lotOccupancyDB/updateLotOccupancyComment.js";
import {getLotOccupancyComments} from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
import { updateLotOccupancyComment } from "../../helpers/lotOccupancyDB/updateLotOccupancyComment.js";
import { getLotOccupancyComments } from "../../helpers/lotOccupancyDB/getLotOccupancyComments.js";
export const handler: RequestHandler = async (request, response) => {
const success = updateLotOccupancyComment(request.body, request.session);
const lotOccupancyComments = getLotOccupancyComments(request.body.lotOccupancyId);
const lotOccupancyComments = getLotOccupancyComments(
request.body.lotOccupancyId
);
response.json({
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
updateLotOccupancyOccupant
} from "../../helpers/lotOccupancyDB/updateLotOccupancyOccupant.js";
import {
getLotOccupancyOccupants
} from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
import { updateLotOccupancyOccupant } from "../../helpers/lotOccupancyDB/updateLotOccupancyOccupant.js";
import { getLotOccupancyOccupants } from "../../helpers/lotOccupancyDB/getLotOccupancyOccupants.js";
export const handler: RequestHandler = async (request, response) => {
const success = updateLotOccupancyOccupant(request.body, request.session);
const lotOccupancyOccupants = getLotOccupancyOccupants(request.body.lotOccupancyId);
const lotOccupancyOccupants = getLotOccupancyOccupants(
request.body.lotOccupancyId
);
response.json({
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) => {
const lot = getLot(request.params.lotId);
if (!lot) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=lotIdNotFound");
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lots/?error=lotIdNotFound");
}
const maps = getMaps();
const lotTypes = cacheFunctions.getLotTypes();

View File

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

View File

@ -7,26 +7,23 @@ import * as cacheFunctions from "../../helpers/functions.cache.js";
import * as recordTypes from "../../types/recordTypes";
export const handler: RequestHandler = (_request, response) => {
const lot: recordTypes.Lot = {
lotOccupancies: []
};
const lot: recordTypes.Lot = {
lotOccupancies: []
};
const maps = getMaps();
const lotTypes = cacheFunctions.getLotTypes();
const lotStatuses = cacheFunctions.getLotStatuses();
const maps = getMaps();
const lotTypes = cacheFunctions.getLotTypes();
const lotStatuses = cacheFunctions.getLotStatuses();
response.render("lot-edit", {
headTitle: "Create a New " + configFunctions.getProperty("aliases.lot"),
lot,
isCreate: true,
maps,
lotTypes,
lotStatuses
});
response.render("lot-edit", {
headTitle: "Create a New " + configFunctions.getProperty("aliases.lot"),
lot,
isCreate: true,
maps,
lotTypes,
lotStatuses
});
};
export default handler;

View File

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

View File

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

View File

@ -4,8 +4,11 @@ export const handler = (request, response) => {
const lotId = request.params.lotId;
const previousLotId = getPreviousLotId(lotId);
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;

View File

@ -1,26 +1,26 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import * as configFunctions from "../../helpers/functions.config.js";
import {
getPreviousLotId
} from "../../helpers/lotOccupancyDB/getPreviousLotId.js";
import { getPreviousLotId } from "../../helpers/lotOccupancyDB/getPreviousLotId.js";
export const handler: RequestHandler = (request, response) => {
const lotId = request.params.lotId;
const previousLotId = getPreviousLotId(lotId);
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import * as configFunctions from "../../helpers/functions.config.js";
import {
getMaps
} from "../../helpers/lotOccupancyDB/getMaps.js";
import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js";
import { getLotTypes, getLotStatuses } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = (request, response) => {
const maps = getMaps();
const lotTypes = getLotTypes();
const lotStatuses = getLotStatuses();
response.render("lot-search", {
headTitle: configFunctions.getProperty("aliases.lot") + " Search",
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) => {
const lot = getLot(request.params.lotId);
if (!lot) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=lotIdNotFound");
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") +
"/lots/?error=lotIdNotFound");
}
return response.render("lot-view", {
headTitle: lot.lotName,

View File

@ -4,20 +4,20 @@ import * as configFunctions from "../../helpers/functions.config.js";
import { getLot } from "../../helpers/lotOccupancyDB/getLot.js";
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.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=lotIdNotFound");
}
return response.render("lot-view", {
headTitle: lot.lotName,
lot
});
return response.render("lot-view", {
headTitle: lot.lotName,
lot
});
};
export default handler;

View File

@ -1,18 +1,10 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
addLotComment
} from "../../helpers/lotOccupancyDB/addLotComment.js";
import {
getLotComments
} from "../../helpers/lotOccupancyDB/getLotComments.js";
import { addLotComment } from "../../helpers/lotOccupancyDB/addLotComment.js";
import { getLotComments } from "../../helpers/lotOccupancyDB/getLotComments.js";
export const handler: RequestHandler = async (request, response) => {
addLotComment(request.body, request.session);
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 {
RequestHandler
} from "express";
import {
addLot
} from "../../helpers/lotOccupancyDB/addLot.js";
import type { RequestHandler } from "express";
import { addLot } from "../../helpers/lotOccupancyDB/addLot.js";
export const handler: RequestHandler = async (request, response) => {
const lotId = addLot(request.body, request.session);
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
deleteLotComment
} from "../../helpers/lotOccupancyDB/deleteLotComment.js";
import {
getLotComments
} from "../../helpers/lotOccupancyDB/getLotComments.js";
import { deleteLotComment } from "../../helpers/lotOccupancyDB/deleteLotComment.js";
import { getLotComments } from "../../helpers/lotOccupancyDB/getLotComments.js";
export const handler: RequestHandler = async (request, response) => {
const success = deleteLotComment(request.body.lotCommentId, request.session);
const success = deleteLotComment(
request.body.lotCommentId,
request.session
);
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 {
RequestHandler
} from "express";
import {
getLots
} from "../../helpers/lotOccupancyDB/getLots.js";
import type { RequestHandler } from "express";
import { getLots } from "../../helpers/lotOccupancyDB/getLots.js";
export const handler: RequestHandler = async (request, response) => {
const result = getLots(request.body, {
limit: request.body.limit,
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 {
RequestHandler
} from "express";
import {
updateLot
} from "../../helpers/lotOccupancyDB/updateLot.js";
import type { RequestHandler } from "express";
import { updateLot } from "../../helpers/lotOccupancyDB/updateLot.js";
export const handler: RequestHandler = async (request, response) => {
const success = updateLot(request.body, request.session);
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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
updateLotComment
} from "../../helpers/lotOccupancyDB/updateLotComment.js";
import {
getLotComments
} from "../../helpers/lotOccupancyDB/getLotComments.js";
import { updateLotComment } from "../../helpers/lotOccupancyDB/updateLotComment.js";
import { getLotComments } from "../../helpers/lotOccupancyDB/getLotComments.js";
export const handler: RequestHandler = async (request, response) => {
const success = updateLotComment(request.body, request.session);
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) => {
const map = getMap(request.params.mapId);
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();
response.render("map-edit", {

View File

@ -6,24 +6,24 @@ import { getMap } from "../../helpers/lotOccupancyDB/getMap.js";
import { getMapSVGs } from "../../helpers/functions.map.js";
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) {
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/maps/?error=mapIdNotFound");
}
const mapSVGs = await getMapSVGs();
const mapSVGs = await getMapSVGs();
response.render("map-edit", {
headTitle: map.mapName,
isCreate: false,
map,
mapSVGs
});
response.render("map-edit", {
headTitle: map.mapName,
isCreate: false,
map,
mapSVGs
});
};
export default handler;
export default handler;

View File

@ -1,21 +1,17 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import * as configFunctions from "../../helpers/functions.config.js";
import {
getMapSVGs
} from "../../helpers/functions.map.js";
import { getMapSVGs } from "../../helpers/functions.map.js";
import * as recordTypes from "../../types/recordTypes";
export const handler: RequestHandler = async (_request, response) => {
const map: recordTypes.Map = {
mapCity: configFunctions.getProperty("settings.map.mapCityDefault"),
mapProvince: configFunctions.getProperty("settings.map.mapProvinceDefault")
mapProvince: configFunctions.getProperty(
"settings.map.mapProvinceDefault"
)
};
const mapSVGs = await getMapSVGs();
@ -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 {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import * as configFunctions from "../../helpers/functions.config.js";
import {
getMaps
} from "../../helpers/lotOccupancyDB/getMaps.js";
import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js";
export const handler: RequestHandler = (_request, response) => {
const maps = getMaps();
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) => {
const map = getMap(request.params.mapId);
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", {
headTitle: map.mapName,

View File

@ -1,20 +1,17 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import * as configFunctions from "../../helpers/functions.config.js";
import {
getMap
} from "../../helpers/lotOccupancyDB/getMap.js";
import { getMap } from "../../helpers/lotOccupancyDB/getMap.js";
export const handler: RequestHandler = (request, response) => {
const map = getMap(request.params.mapId);
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", {
@ -23,5 +20,4 @@ export const handler: RequestHandler = (request, response) => {
});
};
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type {
RequestHandler
} from "express";
import {
addMap
} from "../../helpers/lotOccupancyDB/addMap.js";
import type { RequestHandler } from "express";
import { addMap } from "../../helpers/lotOccupancyDB/addMap.js";
export const handler: RequestHandler = async (request, response) => {
const mapId = addMap(request.body, request.session);
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 {
RequestHandler
} from "express";
import {
deleteMap
} from "../../helpers/lotOccupancyDB/deleteMap.js";
import type { RequestHandler } from "express";
import { deleteMap } from "../../helpers/lotOccupancyDB/deleteMap.js";
export const handler: RequestHandler = async (request, response) => {
const success = deleteMap(request.body.mapId, request.session);
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 {
RequestHandler
} from "express";
import {
updateMap
} from "../../helpers/lotOccupancyDB/updateMap.js";
import type { RequestHandler } from "express";
import { updateMap } from "../../helpers/lotOccupancyDB/updateMap.js";
export const handler: RequestHandler = async (request, response) => {
const success = updateMap(request.body, request.session);
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";
const urlPrefix = configFunctions.getProperty("reverseProxy.urlPrefix");
export const forbiddenJSON = (response) => {
return response
.status(403)
.json({
return response.status(403).json({
success: false,
message: "Forbidden"
});

View File

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

View File

@ -9,15 +9,17 @@ export const handler = (request, response) => {
break;
}
if (!rows) {
return response
.status(404)
.json({
return response.status(404).json({
success: false,
message: "Report Not Found"
});
}
const csv = papaparse.unparse(rows);
response.setHeader("Content-Disposition", "attachment; filename=" + reportName + "-" + Date.now().toString() + ".csv");
response.setHeader("Content-Disposition", "attachment; filename=" +
reportName +
"-" +
Date.now().toString() +
".csv");
response.setHeader("Content-Type", "text/csv");
response.send(csv);
};

View File

@ -1,6 +1,4 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import {
getReportData,
@ -9,38 +7,38 @@ import {
import papaparse from "papaparse";
export const handler: RequestHandler = (request, response) => {
const reportName = request.params.reportName;
let rows: unknown[];
switch (reportName) {
default:
rows = getReportData(reportName, request.query as ReportParameters);
break;
}
if (!rows) {
return response
.status(404)
.json({
success: false,
message: "Report Not Found"
});
return response.status(404).json({
success: false,
message: "Report Not Found"
});
}
const csv = papaparse.unparse(rows);
response.setHeader("Content-Disposition",
"attachment; filename=" + reportName + "-" + Date.now().toString() + ".csv");
response.setHeader(
"Content-Disposition",
"attachment; filename=" +
reportName +
"-" +
Date.now().toString() +
".csv"
);
response.setHeader("Content-Type", "text/csv");
response.send(csv);
};
export default handler;
export default handler;

View File

@ -1,12 +1,8 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import { getWorkOrderTypes } from "../../helpers/functions.cache.js";
export const handler: RequestHandler = (request, response) => {
const workOrderTypes = getWorkOrderTypes();
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) => {
const workOrder = getWorkOrder(request.params.workOrderId);
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", {
headTitle: "Work Order #" + workOrder.workOrderNumber,

View File

@ -1,20 +1,17 @@
import type {
RequestHandler
} from "express";
import type { RequestHandler } from "express";
import * as configFunctions from "../../helpers/functions.config.js";
import {
getWorkOrder
} from "../../helpers/lotOccupancyDB/getWorkOrder.js";
import { getWorkOrder } from "../../helpers/lotOccupancyDB/getWorkOrder.js";
export const handler: RequestHandler = (request, response) => {
const workOrder = getWorkOrder(request.params.workOrderId);
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", {
@ -23,5 +20,4 @@ export const handler: RequestHandler = (request, response) => {
});
};
export default handler;
export default handler;

View File

@ -1,14 +1,8 @@
import type {
RequestHandler
} from "express";
import {
getWorkOrders
} from "../../helpers/lotOccupancyDB/getWorkOrders.js";
import type { RequestHandler } from "express";
import { getWorkOrders } from "../../helpers/lotOccupancyDB/getWorkOrders.js";
export const handler: RequestHandler = async (request, response) => {
const result = getWorkOrders(request.body, {
limit: request.body.limit,
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 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> => {
return new Promise((resolve) => {
try {
const ad = new ActiveDirectory(activeDirectoryConfig);
ad.authenticate(userDomain + "\\" + userName, password, async (error, auth) => {
if (error) {
resolve(false);
resolve(auth);
}
);
} catch {
resolve(false);
}
});
};
resolve(auth);
});
} catch {
resolve(false);
export const authenticate = async (
userName: string,
password: string
): Promise<boolean> => {
if (!userName || userName === "" || !password || password === "") {
return false;
}
});
};
export const authenticate = async (userName: string, password: string): Promise<boolean> => {
if (!userName || userName === "" || !password || password === "") {
return false;
}
return await authenticateViaActiveDirectory(userName, password);
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 { getOccupancyTypes as getOccupancyTypesFromDatabase } from "./lotOccupancyDB/getOccupancyTypes.js";
import { getWorkOrderTypes as getWorkOrderTypesFromDatabase } from "./lotOccupancyDB/getWorkOrderTypes.js";
import { getOccupancyType } from "./lotOccupancyDB/getOccupancyType.js";
let lotOccupantTypes;
export function getLotOccupantTypes() {
if (!lotOccupantTypes) {
@ -21,7 +20,8 @@ export function getLotOccupantTypesByLotOccupantType(lotOccupantType) {
const cachedLotOccupantTypes = getLotOccupantTypes();
const lotOccupantTypeLowerCase = lotOccupantType.toLowerCase();
return cachedLotOccupantTypes.find((currentLotOccupantType) => {
return currentLotOccupantType.lotOccupantType.toLowerCase() === lotOccupantTypeLowerCase;
return (currentLotOccupantType.lotOccupantType.toLowerCase() ===
lotOccupantTypeLowerCase);
});
}
export function clearLotOccupantTypesCache() {
@ -74,7 +74,6 @@ export function clearLotTypesCache() {
lotTypes = undefined;
}
let occupancyTypes;
const occupancyTypeMap = new Map();
export function getOccupancyTypes() {
if (!occupancyTypes) {
occupancyTypes = getOccupancyTypesFromDatabase();
@ -82,26 +81,21 @@ export function getOccupancyTypes() {
return occupancyTypes;
}
export function getOccupancyTypeById(occupancyTypeId) {
if (!occupancyTypeMap.has(occupancyTypeId)) {
const occupancyType = getOccupancyType(occupancyTypeId);
occupancyTypeMap.set(occupancyTypeId, occupancyType);
}
return occupancyTypeMap.get(occupancyTypeId);
const cachedOccupancyTypes = getOccupancyTypes();
return cachedOccupancyTypes.find((currentOccupancyType) => {
return currentOccupancyType.occupancyTypeId === occupancyTypeId;
});
}
export function getOccupancyTypeByOccupancyType(occupancyTypeString) {
const cachedOccupancyTypes = getOccupancyTypes();
const occupancyTypeLowerCase = occupancyTypeString.toLowerCase();
let occupancyType = cachedOccupancyTypes.find((currentOccupancyType) => {
return currentOccupancyType.occupancyType.toLowerCase() === occupancyTypeLowerCase;
return cachedOccupancyTypes.find((currentOccupancyType) => {
return (currentOccupancyType.occupancyType.toLowerCase() ===
occupancyTypeLowerCase);
});
if (occupancyType) {
occupancyType = getOccupancyTypeById(occupancyType.occupancyTypeId);
}
return occupancyType;
}
export function clearOccupancyTypesCache() {
occupancyTypes = undefined;
occupancyTypeMap.clear();
}
let workOrderTypes;
export function getWorkOrderTypes() {

View File

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

View File

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

View File

@ -1,21 +1,20 @@
/* eslint-disable node/no-unpublished-import */
import {
config
} from "../data/config.js";
import { config } from "../data/config.js";
import type * as configTypes from "../types/configTypes";
/*
* SET UP FALLBACK VALUES
*/
const configFallbackValues = new Map < string,
unknown > ();
const configFallbackValues = new Map<string, unknown>();
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.httpPort", 7000);
configFallbackValues.set("application.useTestDatabases", false);
@ -41,37 +40,55 @@ configFallbackValues.set("aliases.occupancy", "Occupancy");
configFallbackValues.set("aliases.occupancies", "Occupancies");
configFallbackValues.set("aliases.occupant", "Occupant");
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.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.occupantProvinceDefault", "");
configFallbackValues.set("settings.fees.taxPercentageDefault", 0);
/*
* 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.httpPort"): number;
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.canUpdate"): 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.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.occupant"): 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(propertyName: "settings.map.mapProvinceDefault"): string;
export function getProperty(
propertyName: "aliases.externalReceiptNumber"
): string;
export function getProperty(propertyName: "settings.lot.lotNamePattern"): RegExp;
export function getProperty(propertyName: "settings.lot.lotNameSortNameFunction"): (lotName: string) => string;
export function getProperty(
propertyName: "settings.map.mapCityDefault"
): 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.map.mapProvinceDefault"
): 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 {
const propertyNameSplit = propertyName.split(".");
let currentObject = config;
for (const propertyNamePiece of propertyNameSplit) {
if (Object.prototype.hasOwnProperty.call(currentObject, propertyNamePiece)) {
if (
Object.prototype.hasOwnProperty.call(
currentObject,
propertyNamePiece
)
) {
currentObject = currentObject[propertyNamePiece];
continue;
}
@ -121,10 +164,9 @@ export function getProperty(propertyName: string): unknown {
return currentObject;
}
export const keepAliveMillis =
getProperty("session.doKeepAlive") ?
Math.max(
getProperty("session.maxAgeMillis") / 2,
getProperty("session.maxAgeMillis") - (10 * 60 * 1000)
) :
0;
export const keepAliveMillis = getProperty("session.doKeepAlive")
? Math.max(
getProperty("session.maxAgeMillis") / 2,
getProperty("session.maxAgeMillis") - 10 * 60 * 1000
)
: 0;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ export const addFee = (feeForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" 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();
return result.lastInsertRowid;
};

View File

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

View File

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

View File

@ -1,12 +1,9 @@
import sqlite from "better-sqlite3";
import {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import type * as recordTypes from "../../types/recordTypes";
interface AddLotForm {
lotName: string;
lotTypeId: string | number;
@ -19,38 +16,41 @@ interface AddLotForm {
lotLongitude: string;
}
export const addLot = (
lotForm: AddLotForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLot =
(lotForm: AddLotForm, requestSession: recordTypes.PartialSession): number => {
const rightNowMillis = Date.now();
const database = sqlite(databasePath);
const rightNowMillis = Date.now();
const result = database
.prepare("insert into Lots (" +
const result = database
.prepare(
"insert into Lots (" +
"lotName, lotTypeId, lotStatusId," +
" mapId, mapKey," +
" lotLatitude, lotLongitude," +
" recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" 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);
" 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
);
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 {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js";
import type * as recordTypes from "../../types/recordTypes";
interface AddLotCommentForm {
lotId: string;
lotComment: string;
}
export const addLotComment = (
lotCommentForm: AddLotCommentForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotComment =
(lotCommentForm: AddLotCommentForm, requestSession: recordTypes.PartialSession): number => {
const rightNow = new Date();
const database = sqlite(databasePath);
const rightNow = new Date();
const result = database
.prepare("insert into LotComments (" +
const result = database
.prepare(
"insert into LotComments (" +
"lotId, lotCommentDate, lotCommentTime, lotComment," +
" recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?)")
.run(lotCommentForm.lotId,
dateTimeFunctions.dateToInteger(rightNow),
dateTimeFunctions.dateToTimeInteger(rightNow),
lotCommentForm.lotComment,
requestSession.user.userName,
rightNow.getTime(),
requestSession.user.userName,
rightNow.getTime());
" values (?, ?, ?, ?, ?, ?, ?, ?)"
)
.run(
lotCommentForm.lotId,
dateTimeFunctions.dateToInteger(rightNow),
dateTimeFunctions.dateToTimeInteger(rightNow),
lotCommentForm.lotComment,
requestSession.user.userName,
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," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?)")
.run(lotOccupancyForm.occupancyTypeId, (lotOccupancyForm.lotId === "" ?
undefined :
lotOccupancyForm.lotId), occupancyStartDate, (lotOccupancyForm.occupancyEndDateString === "" ?
undefined :
dateTimeFunctions.dateStringToInteger(lotOccupancyForm.occupancyEndDateString)), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
.run(lotOccupancyForm.occupancyTypeId, lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId, occupancyStartDate, lotOccupancyForm.occupancyEndDateString === ""
? undefined
: dateTimeFunctions.dateStringToInteger(lotOccupancyForm.occupancyEndDateString), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
const lotOccupancyId = result.lastInsertRowid;
const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds || "").split(",");
for (const occupancyTypeFieldId of occupancyTypeFieldIds) {

View File

@ -1,18 +1,13 @@
import sqlite from "better-sqlite3";
import {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js";
import {
addOrUpdateLotOccupancyField
} from "./addOrUpdateLotOccupancyField.js";
import { addOrUpdateLotOccupancyField } from "./addOrUpdateLotOccupancyField.js";
import type * as recordTypes from "../../types/recordTypes";
interface AddLotOccupancyForm {
occupancyTypeId: string | number;
lotId: string | number;
@ -24,62 +19,73 @@ interface AddLotOccupancyForm {
[lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown;
}
export const addLotOccupancy = (
lotOccupancyForm: AddLotOccupancyForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotOccupancy =
(lotOccupancyForm: AddLotOccupancyForm, requestSession: recordTypes.PartialSession): number => {
const rightNowMillis = Date.now();
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);
if (occupancyStartDate <= 0) {
console.error(lotOccupancyForm);
}
const result = database
.prepare("insert into LotOccupancies (" +
const result = database
.prepare(
"insert into LotOccupancies (" +
"occupancyTypeId, lotId," +
" occupancyStartDate, occupancyEndDate," +
" recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?)")
.run(lotOccupancyForm.occupancyTypeId,
(lotOccupancyForm.lotId === "" ?
undefined :
lotOccupancyForm.lotId),
occupancyStartDate,
(lotOccupancyForm.occupancyEndDateString === "" ?
undefined :
dateTimeFunctions.dateStringToInteger(lotOccupancyForm.occupancyEndDateString)),
requestSession.user.userName,
rightNowMillis,
requestSession.user.userName,
rightNowMillis);
" values (?, ?, ?, ?, ?, ?, ?, ?)"
)
.run(
lotOccupancyForm.occupancyTypeId,
lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId,
occupancyStartDate,
lotOccupancyForm.occupancyEndDateString === ""
? undefined
: dateTimeFunctions.dateStringToInteger(
lotOccupancyForm.occupancyEndDateString
),
requestSession.user.userName,
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,
occupancyTypeFieldId,
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 {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import {
dateStringToInteger,
@ -13,52 +11,58 @@ import {
import type * as recordTypes from "../../types/recordTypes";
interface AddLotOccupancyCommentForm {
lotOccupancyId: string | number;
lotOccupancyCommentDateString ? : string;
lotOccupancyCommentTimeString ? : string;
lotOccupancyCommentDateString?: string;
lotOccupancyCommentTimeString?: string;
lotOccupancyComment: string;
}
export const addLotOccupancyComment = (
commentForm: AddLotOccupancyCommentForm,
requestSession: recordTypes.PartialSession
): number => {
const rightNow = new Date();
export const addLotOccupancyComment =
(commentForm: AddLotOccupancyCommentForm, requestSession: recordTypes.PartialSession): number => {
let lotOccupancyCommentDate: 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;
let lotOccupancyCommentTime: number;
const database = sqlite(databasePath);
if (commentForm.lotOccupancyCommentDateString) {
lotOccupancyCommentDate = dateStringToInteger(commentForm.lotOccupancyCommentDateString);
lotOccupancyCommentTime = timeStringToInteger(commentForm.lotOccupancyCommentTimeString);
} else {
lotOccupancyCommentDate = dateToInteger(rightNow);
lotOccupancyCommentTime = dateToTimeInteger(rightNow);
}
const database = sqlite(databasePath);
const result = database
.prepare("insert into LotOccupancyComments (" +
const result = database
.prepare(
"insert into LotOccupancyComments (" +
"lotOccupancyId, lotOccupancyCommentDate, lotOccupancyCommentTime, lotOccupancyComment," +
" recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?)")
.run(commentForm.lotOccupancyId,
lotOccupancyCommentDate,
lotOccupancyCommentTime,
commentForm.lotOccupancyComment,
requestSession.user.userName,
rightNow.getTime(),
requestSession.user.userName,
rightNow.getTime());
" values (?, ?, ?, ?, ?, ?, ?, ?)"
)
.run(
commentForm.lotOccupancyId,
lotOccupancyCommentDate,
lotOccupancyCommentTime,
commentForm.lotOccupancyComment,
requestSession.user.userName,
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 taxAmount;
if (lotOccupancyFeeForm.feeAmount) {
feeAmount = typeof (lotOccupancyFeeForm.feeAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.feeAmount) : feeAmount;
taxAmount = typeof (lotOccupancyFeeForm.taxAmount) === "string" ? Number.parseFloat(lotOccupancyFeeForm.taxAmount) : taxAmount;
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);
@ -18,21 +24,25 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
feeAmount = calculateFeeAmount(fee, lotOccupancy);
taxAmount = calculateTaxAmount(fee, feeAmount);
}
const record = database.prepare("select feeAmount, taxAmount, recordDelete_timeMillis" +
const record = database
.prepare("select feeAmount, taxAmount, recordDelete_timeMillis" +
" from LotOccupancyFees" +
" where lotOccupancyId = ?" +
" and feeId = ?")
.get(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
if (record) {
if (record.recordDelete_timeMillis) {
database.prepare("delete from LotOccupancyFees" +
database
.prepare("delete from LotOccupancyFees" +
" where recordDelete_timeMillis is not null" +
" and lotOccupancyId = ?" +
" and feeId = ?")
.run(lotOccupancyFeeForm.lotOccupancyId, lotOccupancyFeeForm.feeId);
}
else if (record.feeAmount === feeAmount && record.taxAmount === taxAmount) {
database.prepare("update LotOccupancyFees" +
else if (record.feeAmount === feeAmount &&
record.taxAmount === taxAmount) {
database
.prepare("update LotOccupancyFees" +
" set quantity = quantity + ?," +
" recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?" +
@ -43,10 +53,11 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
return true;
}
else {
const quantity = typeof (lotOccupancyFeeForm.quantity) === "string" ?
Number.parseFloat(lotOccupancyFeeForm.quantity) :
lotOccupancyFeeForm.quantity;
database.prepare("update LotOccupancyFees" +
const quantity = typeof lotOccupancyFeeForm.quantity === "string"
? Number.parseFloat(lotOccupancyFeeForm.quantity)
: lotOccupancyFeeForm.quantity;
database
.prepare("update LotOccupancyFees" +
" set feeAmount = (feeAmount * quantity) + ?," +
" taxAmount = (taxAmount * quantity) + ?," +
" quantity = 1," +
@ -54,7 +65,7 @@ export const addLotOccupancyFee = (lotOccupancyFeeForm, requestSession) => {
" recordUpdate_timeMillis = ?" +
" where lotOccupancyId = ?" +
" 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();
return true;
}

View File

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

View File

@ -1,12 +1,9 @@
import sqlite from "better-sqlite3";
import {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import type * as recordTypes from "../../types/recordTypes";
interface AddLotOccupancyOccupantForm {
lotOccupancyId: string | number;
lotOccupantTypeId: string | number;
@ -19,29 +16,33 @@ interface AddLotOccupancyOccupantForm {
occupantPhoneNumber: string;
}
export const addLotOccupancyOccupant = (
lotOccupancyOccupantForm: AddLotOccupancyOccupantForm,
requestSession: recordTypes.PartialSession
): number => {
const database = sqlite(databasePath);
export const addLotOccupancyOccupant =
(lotOccupancyOccupantForm: AddLotOccupancyOccupantForm, requestSession: recordTypes.PartialSession): number => {
let lotOccupantIndex = 0;
const database = sqlite(databasePath);
let lotOccupantIndex = 0;
const maxIndexResult = database.prepare("select lotOccupantIndex" +
const maxIndexResult = database
.prepare(
"select lotOccupantIndex" +
" from LotOccupancyOccupants" +
" where lotOccupancyId = ?" +
" order by lotOccupantIndex desc" +
" limit 1")
.get(lotOccupancyOccupantForm.lotOccupancyId);
" limit 1"
)
.get(lotOccupancyOccupantForm.lotOccupancyId);
if (maxIndexResult) {
lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1;
}
if (maxIndexResult) {
lotOccupantIndex = maxIndexResult.lotOccupantIndex + 1;
}
const rightNowMillis = Date.now();
const rightNowMillis = Date.now();
database
.prepare("insert into LotOccupancyOccupants (" +
database
.prepare(
"insert into LotOccupancyOccupants (" +
"lotOccupancyId, lotOccupantIndex," +
" occupantName," +
" occupantAddress1, occupantAddress2," +
@ -50,26 +51,28 @@ export const addLotOccupancyOccupant =
" lotOccupantTypeId," +
" recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
.run(lotOccupancyOccupantForm.lotOccupancyId,
lotOccupantIndex,
lotOccupancyOccupantForm.occupantName,
lotOccupancyOccupantForm.occupantAddress1,
lotOccupancyOccupantForm.occupantAddress2,
lotOccupancyOccupantForm.occupantCity,
lotOccupancyOccupantForm.occupantProvince,
lotOccupancyOccupantForm.occupantPostalCode,
lotOccupancyOccupantForm.occupantPhoneNumber,
lotOccupancyOccupantForm.lotOccupantTypeId,
requestSession.user.userName,
rightNowMillis,
requestSession.user.userName,
rightNowMillis);
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
)
.run(
lotOccupancyOccupantForm.lotOccupancyId,
lotOccupantIndex,
lotOccupancyOccupantForm.occupantName,
lotOccupancyOccupantForm.occupantAddress1,
lotOccupancyOccupantForm.occupantAddress2,
lotOccupancyOccupantForm.occupantCity,
lotOccupancyOccupantForm.occupantProvince,
lotOccupancyOccupantForm.occupantPostalCode,
lotOccupancyOccupantForm.occupantPhoneNumber,
lotOccupancyOccupantForm.lotOccupantTypeId,
requestSession.user.userName,
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) => {
const database = sqlite(databasePath);
let transactionIndex = 0;
const maxIndexResult = database.prepare("select transactionIndex" +
const maxIndexResult = database
.prepare("select transactionIndex" +
" from LotOccupancyTransactions" +
" where lotOccupancyId = ?" +
" order by transactionIndex desc" +
@ -14,12 +15,12 @@ export const addLotOccupancyTransaction = (lotOccupancyTransactionForm, requestS
transactionIndex = maxIndexResult.transactionIndex + 1;
}
const rightNow = new Date();
const transactionDate = lotOccupancyTransactionForm.transactionDateString ?
dateStringToInteger(lotOccupancyTransactionForm.transactionDateString) :
dateToInteger(rightNow);
const transactionTime = lotOccupancyTransactionForm.transactionTimeString ?
timeStringToInteger(lotOccupancyTransactionForm.transactionTimeString) :
dateToTimeInteger(rightNow);
const transactionDate = lotOccupancyTransactionForm.transactionDateString
? dateStringToInteger(lotOccupancyTransactionForm.transactionDateString)
: dateToInteger(rightNow);
const transactionTime = lotOccupancyTransactionForm.transactionTimeString
? timeStringToInteger(lotOccupancyTransactionForm.transactionTimeString)
: dateToTimeInteger(rightNow);
database
.prepare("insert into LotOccupancyTransactions (" +
"lotOccupancyId, transactionIndex," +

View File

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

View File

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

View File

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

View File

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

View File

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