From 77db067a5e55918f19ca4475865b34117c4564c1 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Fri, 2 Sep 2022 16:13:32 -0400 Subject: [PATCH] reformatting with prettier --- .eslintrc.json | 112 ++- .ncurc.json | 4 +- bin/www.ts | 85 +-- cypress/e2e/xx-other/loginPage.cy.ts | 10 +- handlers/dashboard-get/dashboard.ts | 9 +- handlers/lotOccupancies-get/edit.js | 8 +- handlers/lotOccupancies-get/edit.ts | 24 +- handlers/lotOccupancies-get/new.js | 6 +- handlers/lotOccupancies-get/new.ts | 25 +- handlers/lotOccupancies-get/print.js | 8 +- handlers/lotOccupancies-get/print.ts | 24 +- handlers/lotOccupancies-get/search.ts | 23 +- handlers/lotOccupancies-get/view.js | 8 +- handlers/lotOccupancies-get/view.ts | 24 +- .../doAddLotOccupancyComment.ts | 21 +- .../doAddLotOccupancyFee.ts | 17 +- .../doAddLotOccupancyOccupant.ts | 21 +- .../doAddLotOccupancyTransaction.ts | 21 +- .../doCreateLotOccupancy.ts | 13 +- .../doDeleteLotOccupancy.ts | 18 +- .../doDeleteLotOccupancyComment.ts | 24 +- .../doDeleteLotOccupancyFee.ts | 23 +- .../doDeleteLotOccupancyOccupant.ts | 27 +- .../doDeleteLotOccupancyTransaction.ts | 27 +- handlers/lotOccupancies-post/doGetFees.js | 2 +- handlers/lotOccupancies-post/doGetFees.ts | 34 +- .../doGetOccupancyTypeFields.ts | 13 +- .../doSearchLotOccupancies.ts | 13 +- .../doUpdateLotOccupancy.ts | 13 +- .../doUpdateLotOccupancyComment.ts | 19 +- .../doUpdateLotOccupancyOccupant.ts | 21 +- handlers/lots-get/edit.js | 3 +- handlers/lots-get/edit.ts | 35 +- handlers/lots-get/new.ts | 31 +- handlers/lots-get/next.js | 7 +- handlers/lots-get/next.ts | 24 +- handlers/lots-get/previous.js | 7 +- handlers/lots-get/previous.ts | 24 +- handlers/lots-get/search.ts | 15 +- handlers/lots-get/view.js | 3 +- handlers/lots-get/view.ts | 22 +- handlers/lots-post/doAddLotComment.ts | 17 +- handlers/lots-post/doCreateLot.ts | 13 +- handlers/lots-post/doDeleteLotComment.ts | 22 +- handlers/lots-post/doSearchLots.ts | 13 +- handlers/lots-post/doUpdateLot.ts | 13 +- handlers/lots-post/doUpdateLotComment.ts | 17 +- handlers/maps-get/edit.js | 3 +- handlers/maps-get/edit.ts | 30 +- handlers/maps-get/new.ts | 17 +- handlers/maps-get/search.ts | 13 +- handlers/maps-get/view.js | 3 +- handlers/maps-get/view.ts | 18 +- handlers/maps-post/doCreateMap.ts | 13 +- handlers/maps-post/doDeleteMap.ts | 13 +- handlers/maps-post/doUpdateMap.ts | 13 +- handlers/permissions.js | 4 +- handlers/permissions.ts | 51 +- handlers/reports-get/reportName.js | 10 +- handlers/reports-get/reportName.ts | 30 +- handlers/workOrders-get/search.ts | 9 +- handlers/workOrders-get/view.js | 3 +- handlers/workOrders-get/view.ts | 18 +- .../workOrders-post/doSearchWorkOrders.ts | 13 +- helpers/functions.authentication.ts | 57 +- helpers/functions.cache.js | 24 +- helpers/functions.cache.ts | 72 +- helpers/functions.config.js | 6 +- helpers/functions.config.ts | 110 ++- helpers/functions.fee.js | 10 +- helpers/functions.fee.ts | 21 +- helpers/functions.map.ts | 8 +- helpers/functions.user.ts | 24 +- helpers/initializer.database.cemetery.ts | 429 ++++++----- helpers/initializer.database.js | 258 ++++--- helpers/initializer.database.ts | 690 +++++++++++------- helpers/lotOccupancyDB/addFee.js | 2 +- helpers/lotOccupancyDB/addFee.ts | 66 +- helpers/lotOccupancyDB/addFeeCategory.js | 2 +- helpers/lotOccupancyDB/addFeeCategory.ts | 44 +- helpers/lotOccupancyDB/addLot.js | 2 +- helpers/lotOccupancyDB/addLot.ts | 58 +- helpers/lotOccupancyDB/addLotComment.ts | 52 +- helpers/lotOccupancyDB/addLotOccupancy.js | 8 +- helpers/lotOccupancyDB/addLotOccupancy.ts | 100 +-- .../lotOccupancyDB/addLotOccupancyComment.ts | 78 +- helpers/lotOccupancyDB/addLotOccupancyFee.js | 33 +- helpers/lotOccupancyDB/addLotOccupancyFee.ts | 213 +++--- .../lotOccupancyDB/addLotOccupancyOccupant.js | 3 +- .../lotOccupancyDB/addLotOccupancyOccupant.ts | 81 +- .../addLotOccupancyTransaction.js | 15 +- .../addLotOccupancyTransaction.ts | 91 +-- helpers/lotOccupancyDB/addLotOccupantType.js | 2 +- helpers/lotOccupancyDB/addLotOccupantType.ts | 50 +- helpers/lotOccupancyDB/addLotStatus.js | 2 +- helpers/lotOccupancyDB/addLotStatus.ts | 50 +- helpers/lotOccupancyDB/addLotType.js | 2 +- helpers/lotOccupancyDB/addLotType.ts | 56 +- helpers/lotOccupancyDB/addMap.js | 2 +- helpers/lotOccupancyDB/addMap.ts | 66 +- helpers/lotOccupancyDB/addOccupancyType.js | 2 +- helpers/lotOccupancyDB/addOccupancyType.ts | 56 +- .../lotOccupancyDB/addOccupancyTypeField.js | 2 +- .../lotOccupancyDB/addOccupancyTypeField.ts | 60 +- .../addOrUpdateLotOccupancyField.js | 2 +- .../addOrUpdateLotOccupancyField.ts | 82 ++- helpers/lotOccupancyDB/addWorkOrder.js | 6 +- helpers/lotOccupancyDB/addWorkOrder.ts | 62 +- helpers/lotOccupancyDB/addWorkOrderLot.ts | 48 +- .../addWorkOrderLotOccupancy.ts | 48 +- helpers/lotOccupancyDB/addWorkOrderType.js | 2 +- helpers/lotOccupancyDB/addWorkOrderType.ts | 56 +- helpers/lotOccupancyDB/deleteFee.js | 2 +- helpers/lotOccupancyDB/deleteFee.ts | 38 +- helpers/lotOccupancyDB/deleteFeeCategory.js | 2 +- helpers/lotOccupancyDB/deleteFeeCategory.ts | 38 +- helpers/lotOccupancyDB/deleteLotComment.js | 2 +- helpers/lotOccupancyDB/deleteLotComment.ts | 38 +- helpers/lotOccupancyDB/deleteLotOccupancy.js | 2 +- helpers/lotOccupancyDB/deleteLotOccupancy.ts | 38 +- .../deleteLotOccupancyComment.js | 2 +- .../deleteLotOccupancyComment.ts | 42 +- .../lotOccupancyDB/deleteLotOccupancyFee.js | 2 +- .../lotOccupancyDB/deleteLotOccupancyFee.ts | 46 +- .../lotOccupancyDB/deleteLotOccupancyField.js | 2 +- .../lotOccupancyDB/deleteLotOccupancyField.ts | 52 +- .../deleteLotOccupancyOccupant.js | 2 +- .../deleteLotOccupancyOccupant.ts | 46 +- .../deleteLotOccupancyTransaction.js | 2 +- .../deleteLotOccupancyTransaction.ts | 46 +- .../lotOccupancyDB/deleteLotOccupantType.js | 2 +- .../lotOccupancyDB/deleteLotOccupantType.ts | 44 +- helpers/lotOccupancyDB/deleteLotStatus.js | 2 +- helpers/lotOccupancyDB/deleteLotStatus.ts | 44 +- helpers/lotOccupancyDB/deleteMap.js | 2 +- helpers/lotOccupancyDB/deleteMap.ts | 38 +- helpers/lotOccupancyDB/deleteWorkOrderType.js | 2 +- helpers/lotOccupancyDB/deleteWorkOrderType.ts | 44 +- helpers/lotOccupancyDB/getFee.js | 3 +- helpers/lotOccupancyDB/getFee.ts | 42 +- helpers/lotOccupancyDB/getFeeCategories.js | 60 +- helpers/lotOccupancyDB/getFeeCategories.ts | 75 +- helpers/lotOccupancyDB/getLot.ts | 61 +- helpers/lotOccupancyDB/getLotComments.js | 7 +- helpers/lotOccupancyDB/getLotComments.ts | 42 +- helpers/lotOccupancyDB/getLotOccupancies.js | 35 +- helpers/lotOccupancyDB/getLotOccupancies.ts | 118 +-- helpers/lotOccupancyDB/getLotOccupancy.ts | 88 +-- .../lotOccupancyDB/getLotOccupancyComments.js | 7 +- .../lotOccupancyDB/getLotOccupancyComments.ts | 42 +- helpers/lotOccupancyDB/getLotOccupancyFees.js | 7 +- helpers/lotOccupancyDB/getLotOccupancyFees.ts | 45 +- .../lotOccupancyDB/getLotOccupancyFields.js | 7 +- .../lotOccupancyDB/getLotOccupancyFields.ts | 67 +- .../getLotOccupancyOccupants.js | 7 +- .../getLotOccupancyOccupants.ts | 31 +- .../getLotOccupancyTransactions.js | 7 +- .../getLotOccupancyTransactions.ts | 46 +- helpers/lotOccupancyDB/getLotOccupantTypes.js | 3 +- helpers/lotOccupancyDB/getLotOccupantTypes.ts | 33 +- helpers/lotOccupancyDB/getLotStatuses.js | 3 +- helpers/lotOccupancyDB/getLotStatuses.ts | 33 +- helpers/lotOccupancyDB/getLotTypes.ts | 19 +- helpers/lotOccupancyDB/getLots.js | 42 +- helpers/lotOccupancyDB/getLots.ts | 133 ++-- helpers/lotOccupancyDB/getMap.ts | 57 +- helpers/lotOccupancyDB/getMaps.ts | 42 +- helpers/lotOccupancyDB/getNextLotId.ts | 30 +- helpers/lotOccupancyDB/getOccupancyType.d.ts | 3 - helpers/lotOccupancyDB/getOccupancyType.js | 22 - helpers/lotOccupancyDB/getOccupancyType.ts | 37 - helpers/lotOccupancyDB/getOccupancyTypes.js | 40 +- helpers/lotOccupancyDB/getOccupancyTypes.ts | 75 +- helpers/lotOccupancyDB/getPreviousLotId.ts | 30 +- helpers/lotOccupancyDB/getReportData.js | 41 +- helpers/lotOccupancyDB/getReportData.ts | 89 ++- helpers/lotOccupancyDB/getWorkOrder.ts | 81 +- helpers/lotOccupancyDB/getWorkOrderTypes.js | 3 +- helpers/lotOccupancyDB/getWorkOrderTypes.ts | 33 +- helpers/lotOccupancyDB/getWorkOrders.js | 15 +- helpers/lotOccupancyDB/getWorkOrders.ts | 63 +- helpers/lotOccupancyDB/moveFeeCategoryDown.js | 6 +- helpers/lotOccupancyDB/moveFeeCategoryDown.ts | 52 +- helpers/lotOccupancyDB/moveFeeCategoryUp.js | 6 +- helpers/lotOccupancyDB/moveFeeCategoryUp.ts | 58 +- helpers/lotOccupancyDB/moveFeeDown.js | 12 +- helpers/lotOccupancyDB/moveFeeDown.ts | 48 +- helpers/lotOccupancyDB/moveFeeUp.js | 12 +- helpers/lotOccupancyDB/moveFeeUp.ts | 56 +- .../lotOccupancyDB/moveLotOccupantTypeDown.js | 6 +- .../lotOccupancyDB/moveLotOccupantTypeDown.ts | 58 +- .../lotOccupancyDB/moveLotOccupantTypeUp.js | 6 +- .../lotOccupancyDB/moveLotOccupantTypeUp.ts | 66 +- helpers/lotOccupancyDB/moveLotStatusDown.js | 6 +- helpers/lotOccupancyDB/moveLotStatusDown.ts | 56 +- helpers/lotOccupancyDB/moveLotStatusUp.js | 6 +- helpers/lotOccupancyDB/moveLotStatusUp.ts | 64 +- .../lotOccupancyDB/moveOccupancyTypeDown.d.ts | 2 + .../lotOccupancyDB/moveOccupancyTypeDown.js | 26 + .../lotOccupancyDB/moveOccupancyTypeDown.ts | 44 ++ .../lotOccupancyDB/moveOccupancyTypeUp.d.ts | 2 + helpers/lotOccupancyDB/moveOccupancyTypeUp.js | 30 + helpers/lotOccupancyDB/moveOccupancyTypeUp.ts | 49 ++ .../lotOccupancyDB/moveWorkOrderTypeDown.js | 6 +- .../lotOccupancyDB/moveWorkOrderTypeDown.ts | 58 +- helpers/lotOccupancyDB/moveWorkOrderTypeUp.js | 6 +- helpers/lotOccupancyDB/moveWorkOrderTypeUp.ts | 66 +- helpers/lotOccupancyDB/updateFee.js | 2 +- helpers/lotOccupancyDB/updateFee.ts | 80 +- helpers/lotOccupancyDB/updateFeeCategory.ts | 44 +- helpers/lotOccupancyDB/updateLot.js | 4 +- helpers/lotOccupancyDB/updateLot.ts | 82 ++- helpers/lotOccupancyDB/updateLotComment.ts | 52 +- helpers/lotOccupancyDB/updateLotOccupancy.js | 4 +- helpers/lotOccupancyDB/updateLotOccupancy.ts | 89 +-- .../updateLotOccupancyComment.ts | 52 +- .../updateLotOccupancyOccupant.ts | 84 +-- .../lotOccupancyDB/updateLotOccupantType.ts | 50 +- helpers/lotOccupancyDB/updateLotStatus.ts | 50 +- helpers/lotOccupancyDB/updateMap.js | 2 +- helpers/lotOccupancyDB/updateMap.ts | 64 +- helpers/lotOccupancyDB/updateWorkOrderType.ts | 50 +- package.json | 192 ++--- public-typescript/adminFees.js | 100 +-- public-typescript/adminFees.ts | 105 ++- public-typescript/adminOccupancyTypes.d.ts | 1 + public-typescript/adminOccupancyTypes.js | 147 ++++ public-typescript/adminOccupancyTypes.ts | 205 +++++- public/javascripts/adminFees.min.js | 2 +- public/javascripts/adminOccupancyTypes.min.js | 1 + routes/login.js | 2 + routes/login.ts | 2 + temp/so.exportMaps.js | 9 +- temp/so.exportMaps.ts | 26 +- windowsService-install.ts | 2 +- windowsService-uninstall.ts | 6 +- windowsService.ts | 8 +- 237 files changed, 4866 insertions(+), 4199 deletions(-) delete mode 100644 helpers/lotOccupancyDB/getOccupancyType.d.ts delete mode 100644 helpers/lotOccupancyDB/getOccupancyType.js delete mode 100644 helpers/lotOccupancyDB/getOccupancyType.ts create mode 100644 helpers/lotOccupancyDB/moveOccupancyTypeDown.d.ts create mode 100644 helpers/lotOccupancyDB/moveOccupancyTypeDown.js create mode 100644 helpers/lotOccupancyDB/moveOccupancyTypeDown.ts create mode 100644 helpers/lotOccupancyDB/moveOccupancyTypeUp.d.ts create mode 100644 helpers/lotOccupancyDB/moveOccupancyTypeUp.js create mode 100644 helpers/lotOccupancyDB/moveOccupancyTypeUp.ts diff --git a/.eslintrc.json b/.eslintrc.json index bbf2855d..dafb0707 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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 + } + } + } + ] + } } diff --git a/.ncurc.json b/.ncurc.json index e87c23e8..ddac39cd 100644 --- a/.ncurc.json +++ b/.ncurc.json @@ -1,5 +1,3 @@ { - "reject": [ - "@fortawesome/fontawesome-free" - ] + "reject": ["@fortawesome/fontawesome-free"] } diff --git a/bin/www.ts b/bin/www.ts index d0e5ee79..d88b96dd 100644 --- a/bin/www.ts +++ b/bin/www.ts @@ -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; + } }); diff --git a/cypress/e2e/xx-other/loginPage.cy.ts b/cypress/e2e/xx-other/loginPage.cy.ts index 97d6b05a..f6318a0e 100644 --- a/cypress/e2e/xx-other/loginPage.cy.ts +++ b/cypress/e2e/xx-other/loginPage.cy.ts @@ -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 }); }); -}); \ No newline at end of file +}); diff --git a/handlers/dashboard-get/dashboard.ts b/handlers/dashboard-get/dashboard.ts index f334eeba..3ef67bf2 100644 --- a/handlers/dashboard-get/dashboard.ts +++ b/handlers/dashboard-get/dashboard.ts @@ -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; diff --git a/handlers/lotOccupancies-get/edit.js b/handlers/lotOccupancies-get/edit.js index 0cb86296..f9cf3391 100644 --- a/handlers/lotOccupancies-get/edit.js +++ b/handlers/lotOccupancies-get/edit.js @@ -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, diff --git a/handlers/lotOccupancies-get/edit.ts b/handlers/lotOccupancies-get/edit.ts index 0d650de4..9e47d7d1 100644 --- a/handlers/lotOccupancies-get/edit.ts +++ b/handlers/lotOccupancies-get/edit.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-get/new.js b/handlers/lotOccupancies-get/new.js index 21abfb0b..541fcb63 100644 --- a/handlers/lotOccupancies-get/new.js +++ b/handlers/lotOccupancies-get/new.js @@ -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 diff --git a/handlers/lotOccupancies-get/new.ts b/handlers/lotOccupancies-get/new.ts index 01f39790..2f423aa0 100644 --- a/handlers/lotOccupancies-get/new.ts +++ b/handlers/lotOccupancies-get/new.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-get/print.js b/handlers/lotOccupancies-get/print.js index 71d22633..c84d9a5f 100644 --- a/handlers/lotOccupancies-get/print.js +++ b/handlers/lotOccupancies-get/print.js @@ -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 }); }; diff --git a/handlers/lotOccupancies-get/print.ts b/handlers/lotOccupancies-get/print.ts index f5067354..311a7a19 100644 --- a/handlers/lotOccupancies-get/print.ts +++ b/handlers/lotOccupancies-get/print.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-get/search.ts b/handlers/lotOccupancies-get/search.ts index ac169dd2..cf2e205b 100644 --- a/handlers/lotOccupancies-get/search.ts +++ b/handlers/lotOccupancies-get/search.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-get/view.js b/handlers/lotOccupancies-get/view.js index 9198eba1..11d01b25 100644 --- a/handlers/lotOccupancies-get/view.js +++ b/handlers/lotOccupancies-get/view.js @@ -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 }); }; diff --git a/handlers/lotOccupancies-get/view.ts b/handlers/lotOccupancies-get/view.ts index cc241949..ae12e322 100644 --- a/handlers/lotOccupancies-get/view.ts +++ b/handlers/lotOccupancies-get/view.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doAddLotOccupancyComment.ts b/handlers/lotOccupancies-post/doAddLotOccupancyComment.ts index 20f1d669..51a5063b 100644 --- a/handlers/lotOccupancies-post/doAddLotOccupancyComment.ts +++ b/handlers/lotOccupancies-post/doAddLotOccupancyComment.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doAddLotOccupancyFee.ts b/handlers/lotOccupancies-post/doAddLotOccupancyFee.ts index 7b742771..de0d152b 100644 --- a/handlers/lotOccupancies-post/doAddLotOccupancyFee.ts +++ b/handlers/lotOccupancies-post/doAddLotOccupancyFee.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.ts b/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.ts index 94a0d1aa..de98ddd8 100644 --- a/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.ts +++ b/handlers/lotOccupancies-post/doAddLotOccupancyOccupant.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doAddLotOccupancyTransaction.ts b/handlers/lotOccupancies-post/doAddLotOccupancyTransaction.ts index 759cceab..d8e009c1 100644 --- a/handlers/lotOccupancies-post/doAddLotOccupancyTransaction.ts +++ b/handlers/lotOccupancies-post/doAddLotOccupancyTransaction.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doCreateLotOccupancy.ts b/handlers/lotOccupancies-post/doCreateLotOccupancy.ts index 33ec0ac3..c3cdeb6b 100644 --- a/handlers/lotOccupancies-post/doCreateLotOccupancy.ts +++ b/handlers/lotOccupancies-post/doCreateLotOccupancy.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doDeleteLotOccupancy.ts b/handlers/lotOccupancies-post/doDeleteLotOccupancy.ts index ff578ae9..4af8bb80 100644 --- a/handlers/lotOccupancies-post/doDeleteLotOccupancy.ts +++ b/handlers/lotOccupancies-post/doDeleteLotOccupancy.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doDeleteLotOccupancyComment.ts b/handlers/lotOccupancies-post/doDeleteLotOccupancyComment.ts index ed4e1c69..621b4d9f 100644 --- a/handlers/lotOccupancies-post/doDeleteLotOccupancyComment.ts +++ b/handlers/lotOccupancies-post/doDeleteLotOccupancyComment.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doDeleteLotOccupancyFee.ts b/handlers/lotOccupancies-post/doDeleteLotOccupancyFee.ts index 7cdbe5a6..26e36106 100644 --- a/handlers/lotOccupancies-post/doDeleteLotOccupancyFee.ts +++ b/handlers/lotOccupancies-post/doDeleteLotOccupancyFee.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.ts b/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.ts index 19d8c535..0c6bbeb4 100644 --- a/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.ts +++ b/handlers/lotOccupancies-post/doDeleteLotOccupancyOccupant.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doDeleteLotOccupancyTransaction.ts b/handlers/lotOccupancies-post/doDeleteLotOccupancyTransaction.ts index e9a738b5..2175d096 100644 --- a/handlers/lotOccupancies-post/doDeleteLotOccupancyTransaction.ts +++ b/handlers/lotOccupancies-post/doDeleteLotOccupancyTransaction.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doGetFees.js b/handlers/lotOccupancies-post/doGetFees.js index a71f5b90..7bd98e2a 100644 --- a/handlers/lotOccupancies-post/doGetFees.js +++ b/handlers/lotOccupancies-post/doGetFees.js @@ -10,7 +10,7 @@ export const handler = (request, response) => { includeFees: true }); response.json({ - feeCategories, + feeCategories }); }; export default handler; diff --git a/handlers/lotOccupancies-post/doGetFees.ts b/handlers/lotOccupancies-post/doGetFees.ts index 1d5d866a..5549907f 100644 --- a/handlers/lotOccupancies-post/doGetFees.ts +++ b/handlers/lotOccupancies-post/doGetFees.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doGetOccupancyTypeFields.ts b/handlers/lotOccupancies-post/doGetOccupancyTypeFields.ts index fc20dc12..bef08adc 100644 --- a/handlers/lotOccupancies-post/doGetOccupancyTypeFields.ts +++ b/handlers/lotOccupancies-post/doGetOccupancyTypeFields.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doSearchLotOccupancies.ts b/handlers/lotOccupancies-post/doSearchLotOccupancies.ts index 7870fe89..eb21bc88 100644 --- a/handlers/lotOccupancies-post/doSearchLotOccupancies.ts +++ b/handlers/lotOccupancies-post/doSearchLotOccupancies.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doUpdateLotOccupancy.ts b/handlers/lotOccupancies-post/doUpdateLotOccupancy.ts index 719ff058..5cffc759 100644 --- a/handlers/lotOccupancies-post/doUpdateLotOccupancy.ts +++ b/handlers/lotOccupancies-post/doUpdateLotOccupancy.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doUpdateLotOccupancyComment.ts b/handlers/lotOccupancies-post/doUpdateLotOccupancyComment.ts index 0efd81c0..04d6713f 100644 --- a/handlers/lotOccupancies-post/doUpdateLotOccupancyComment.ts +++ b/handlers/lotOccupancies-post/doUpdateLotOccupancyComment.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.ts b/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.ts index 73437ba8..69455117 100644 --- a/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.ts +++ b/handlers/lotOccupancies-post/doUpdateLotOccupancyOccupant.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lots-get/edit.js b/handlers/lots-get/edit.js index 3e783da0..b1abc8b2 100644 --- a/handlers/lots-get/edit.js +++ b/handlers/lots-get/edit.js @@ -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(); diff --git a/handlers/lots-get/edit.ts b/handlers/lots-get/edit.ts index bd9d82dc..0882b05a 100644 --- a/handlers/lots-get/edit.ts +++ b/handlers/lots-get/edit.ts @@ -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; diff --git a/handlers/lots-get/new.ts b/handlers/lots-get/new.ts index 95fe59f9..e149851d 100644 --- a/handlers/lots-get/new.ts +++ b/handlers/lots-get/new.ts @@ -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; diff --git a/handlers/lots-get/next.js b/handlers/lots-get/next.js index a90e2d1e..52750f53 100644 --- a/handlers/lots-get/next.js +++ b/handlers/lots-get/next.js @@ -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; diff --git a/handlers/lots-get/next.ts b/handlers/lots-get/next.ts index 68d54e83..a9b82b16 100644 --- a/handlers/lots-get/next.ts +++ b/handlers/lots-get/next.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lots-get/previous.js b/handlers/lots-get/previous.js index 8559eb18..2e7edc6f 100644 --- a/handlers/lots-get/previous.js +++ b/handlers/lots-get/previous.js @@ -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; diff --git a/handlers/lots-get/previous.ts b/handlers/lots-get/previous.ts index a3ed9f36..bc1faeb7 100644 --- a/handlers/lots-get/previous.ts +++ b/handlers/lots-get/previous.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lots-get/search.ts b/handlers/lots-get/search.ts index 963f4bf3..1f543d4b 100644 --- a/handlers/lots-get/search.ts +++ b/handlers/lots-get/search.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lots-get/view.js b/handlers/lots-get/view.js index e83384e8..898990e4 100644 --- a/handlers/lots-get/view.js +++ b/handlers/lots-get/view.js @@ -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, diff --git a/handlers/lots-get/view.ts b/handlers/lots-get/view.ts index 918907d9..5cae6c5c 100644 --- a/handlers/lots-get/view.ts +++ b/handlers/lots-get/view.ts @@ -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; diff --git a/handlers/lots-post/doAddLotComment.ts b/handlers/lots-post/doAddLotComment.ts index 9f817b9f..1359af1f 100644 --- a/handlers/lots-post/doAddLotComment.ts +++ b/handlers/lots-post/doAddLotComment.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lots-post/doCreateLot.ts b/handlers/lots-post/doCreateLot.ts index 21a7b324..85c41bed 100644 --- a/handlers/lots-post/doCreateLot.ts +++ b/handlers/lots-post/doCreateLot.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lots-post/doDeleteLotComment.ts b/handlers/lots-post/doDeleteLotComment.ts index 1e9aab56..aaf431e0 100644 --- a/handlers/lots-post/doDeleteLotComment.ts +++ b/handlers/lots-post/doDeleteLotComment.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lots-post/doSearchLots.ts b/handlers/lots-post/doSearchLots.ts index 0ad31a09..60ac7c70 100644 --- a/handlers/lots-post/doSearchLots.ts +++ b/handlers/lots-post/doSearchLots.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lots-post/doUpdateLot.ts b/handlers/lots-post/doUpdateLot.ts index 081527e2..74a55a03 100644 --- a/handlers/lots-post/doUpdateLot.ts +++ b/handlers/lots-post/doUpdateLot.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/lots-post/doUpdateLotComment.ts b/handlers/lots-post/doUpdateLotComment.ts index 4535e53b..995ad9a0 100644 --- a/handlers/lots-post/doUpdateLotComment.ts +++ b/handlers/lots-post/doUpdateLotComment.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/maps-get/edit.js b/handlers/maps-get/edit.js index 68cc97dd..9dedc347 100644 --- a/handlers/maps-get/edit.js +++ b/handlers/maps-get/edit.js @@ -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", { diff --git a/handlers/maps-get/edit.ts b/handlers/maps-get/edit.ts index f3650e1b..f991016e 100644 --- a/handlers/maps-get/edit.ts +++ b/handlers/maps-get/edit.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/maps-get/new.ts b/handlers/maps-get/new.ts index c5de00bc..a33797ac 100644 --- a/handlers/maps-get/new.ts +++ b/handlers/maps-get/new.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/maps-get/search.ts b/handlers/maps-get/search.ts index d15163f1..a6e8275e 100644 --- a/handlers/maps-get/search.ts +++ b/handlers/maps-get/search.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/maps-get/view.js b/handlers/maps-get/view.js index 931c4d18..c81ae464 100644 --- a/handlers/maps-get/view.js +++ b/handlers/maps-get/view.js @@ -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, diff --git a/handlers/maps-get/view.ts b/handlers/maps-get/view.ts index 74588de9..4b119937 100644 --- a/handlers/maps-get/view.ts +++ b/handlers/maps-get/view.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/maps-post/doCreateMap.ts b/handlers/maps-post/doCreateMap.ts index 538f6031..90616616 100644 --- a/handlers/maps-post/doCreateMap.ts +++ b/handlers/maps-post/doCreateMap.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/maps-post/doDeleteMap.ts b/handlers/maps-post/doDeleteMap.ts index ca413eac..b1103bae 100644 --- a/handlers/maps-post/doDeleteMap.ts +++ b/handlers/maps-post/doDeleteMap.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/maps-post/doUpdateMap.ts b/handlers/maps-post/doUpdateMap.ts index 9108961d..b40b95d1 100644 --- a/handlers/maps-post/doUpdateMap.ts +++ b/handlers/maps-post/doUpdateMap.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/permissions.js b/handlers/permissions.js index e523cc49..988c47b4 100644 --- a/handlers/permissions.js +++ b/handlers/permissions.js @@ -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" }); diff --git a/handlers/permissions.ts b/handlers/permissions.ts index 7cb40d89..5cfb05d4 100644 --- a/handlers/permissions.ts +++ b/handlers/permissions.ts @@ -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); }; diff --git a/handlers/reports-get/reportName.js b/handlers/reports-get/reportName.js index 26026229..49ebd7fb 100644 --- a/handlers/reports-get/reportName.js +++ b/handlers/reports-get/reportName.js @@ -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); }; diff --git a/handlers/reports-get/reportName.ts b/handlers/reports-get/reportName.ts index 4f3cf09d..42083d0e 100644 --- a/handlers/reports-get/reportName.ts +++ b/handlers/reports-get/reportName.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/workOrders-get/search.ts b/handlers/workOrders-get/search.ts index 0d2cc2ef..30f620d7 100644 --- a/handlers/workOrders-get/search.ts +++ b/handlers/workOrders-get/search.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/workOrders-get/view.js b/handlers/workOrders-get/view.js index 1c0fec2f..8c16271e 100644 --- a/handlers/workOrders-get/view.js +++ b/handlers/workOrders-get/view.js @@ -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, diff --git a/handlers/workOrders-get/view.ts b/handlers/workOrders-get/view.ts index 4ab10129..35812786 100644 --- a/handlers/workOrders-get/view.ts +++ b/handlers/workOrders-get/view.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/handlers/workOrders-post/doSearchWorkOrders.ts b/handlers/workOrders-post/doSearchWorkOrders.ts index e09abf86..3cc96cc0 100644 --- a/handlers/workOrders-post/doSearchWorkOrders.ts +++ b/handlers/workOrders-post/doSearchWorkOrders.ts @@ -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; \ No newline at end of file +export default handler; diff --git a/helpers/functions.authentication.ts b/helpers/functions.authentication.ts index 5ef89382..199c00a7 100644 --- a/helpers/functions.authentication.ts +++ b/helpers/functions.authentication.ts @@ -6,37 +6,38 @@ const userDomain = configFunctions.getProperty("application.userDomain"); const activeDirectoryConfig = configFunctions.getProperty("activeDirectory"); +const authenticateViaActiveDirectory = async ( + userName: string, + password: string +): Promise => { + 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 => { - - 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 => { + if (!userName || userName === "" || !password || password === "") { + return false; } - }); -}; - - - -export const authenticate = async (userName: string, password: string): Promise => { - - if (!userName || userName === "" || !password || password === "") { - return false; - } - - return await authenticateViaActiveDirectory(userName, password); + + return await authenticateViaActiveDirectory(userName, password); }; diff --git a/helpers/functions.cache.js b/helpers/functions.cache.js index 8431185b..65e59950 100644 --- a/helpers/functions.cache.js +++ b/helpers/functions.cache.js @@ -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() { diff --git a/helpers/functions.cache.ts b/helpers/functions.cache.ts index d41ef5a7..dab10ed2 100644 --- a/helpers/functions.cache.ts +++ b/helpers/functions.cache.ts @@ -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; -} \ No newline at end of file +} diff --git a/helpers/functions.config.js b/helpers/functions.config.js index 768adfab..353493b0 100644 --- a/helpers/functions.config.js +++ b/helpers/functions.config.js @@ -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; diff --git a/helpers/functions.config.ts b/helpers/functions.config.ts index 03edd896..70de2832 100644 --- a/helpers/functions.config.ts +++ b/helpers/functions.config.ts @@ -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(); 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; \ No newline at end of file +export const keepAliveMillis = getProperty("session.doKeepAlive") + ? Math.max( + getProperty("session.maxAgeMillis") / 2, + getProperty("session.maxAgeMillis") - 10 * 60 * 1000 + ) + : 0; diff --git a/helpers/functions.fee.js b/helpers/functions.fee.js index e523838d..d7b31ac8 100644 --- a/helpers/functions.fee.js +++ b/helpers/functions.fee.js @@ -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; }; diff --git a/helpers/functions.fee.ts b/helpers/functions.fee.ts index 374ab884..140ddfed 100644 --- a/helpers/functions.fee.ts +++ b/helpers/functions.fee.ts @@ -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); -}; \ No newline at end of file + return fee.taxPercentage + ? feeAmount * (fee.taxPercentage / 100) + : fee.taxAmount || 0; +}; diff --git a/helpers/functions.map.ts b/helpers/functions.map.ts index 1a9a8a5c..2b10d021 100644 --- a/helpers/functions.map.ts +++ b/helpers/functions.map.ts @@ -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; -} \ No newline at end of file +} diff --git a/helpers/functions.user.ts b/helpers/functions.user.ts index 420c5560..27a812e4 100644 --- a/helpers/functions.user.ts +++ b/helpers/functions.user.ts @@ -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; }; diff --git a/helpers/initializer.database.cemetery.ts b/helpers/initializer.database.cemetery.ts index 02dbe37a..26325edd 100644 --- a/helpers/initializer.database.cemetery.ts +++ b/helpers/initializer.database.cemetery.ts @@ -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(); \ No newline at end of file +initializeCemeteryDatabase(); diff --git a/helpers/initializer.database.js b/helpers/initializer.database.js index 24ea030e..c7d24bd7 100644 --- a/helpers/initializer.database.js +++ b/helpers/initializer.database.js @@ -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; } diff --git a/helpers/initializer.database.ts b/helpers/initializer.database.ts index c3ef3c57..9337b57a 100644 --- a/helpers/initializer.database.ts +++ b/helpers/initializer.database.ts @@ -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; -}; \ No newline at end of file +}; diff --git a/helpers/lotOccupancyDB/addFee.js b/helpers/lotOccupancyDB/addFee.js index f0d96923..687dd3eb 100644 --- a/helpers/lotOccupancyDB/addFee.js +++ b/helpers/lotOccupancyDB/addFee.js @@ -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; }; diff --git a/helpers/lotOccupancyDB/addFee.ts b/helpers/lotOccupancyDB/addFee.ts index 4d8d7454..5f3d91a2 100644 --- a/helpers/lotOccupancyDB/addFee.ts +++ b/helpers/lotOccupancyDB/addFee.ts @@ -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; \ No newline at end of file +export default addFee; diff --git a/helpers/lotOccupancyDB/addFeeCategory.js b/helpers/lotOccupancyDB/addFeeCategory.js index 574d38cf..829ef786 100644 --- a/helpers/lotOccupancyDB/addFeeCategory.js +++ b/helpers/lotOccupancyDB/addFeeCategory.js @@ -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; }; diff --git a/helpers/lotOccupancyDB/addFeeCategory.ts b/helpers/lotOccupancyDB/addFeeCategory.ts index 13e28699..c19a9f17 100644 --- a/helpers/lotOccupancyDB/addFeeCategory.ts +++ b/helpers/lotOccupancyDB/addFeeCategory.ts @@ -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; \ No newline at end of file +export default addFeeCategory; diff --git a/helpers/lotOccupancyDB/addLot.js b/helpers/lotOccupancyDB/addLot.js index 608452c1..730205bb 100644 --- a/helpers/lotOccupancyDB/addLot.js +++ b/helpers/lotOccupancyDB/addLot.js @@ -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; }; diff --git a/helpers/lotOccupancyDB/addLot.ts b/helpers/lotOccupancyDB/addLot.ts index f3bec367..5049bc79 100644 --- a/helpers/lotOccupancyDB/addLot.ts +++ b/helpers/lotOccupancyDB/addLot.ts @@ -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; \ No newline at end of file +export default addLot; diff --git a/helpers/lotOccupancyDB/addLotComment.ts b/helpers/lotOccupancyDB/addLotComment.ts index da6a137a..3bd34e67 100644 --- a/helpers/lotOccupancyDB/addLotComment.ts +++ b/helpers/lotOccupancyDB/addLotComment.ts @@ -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; \ No newline at end of file +export default addLotComment; diff --git a/helpers/lotOccupancyDB/addLotOccupancy.js b/helpers/lotOccupancyDB/addLotOccupancy.js index 67b75273..af4c2f07 100644 --- a/helpers/lotOccupancyDB/addLotOccupancy.js +++ b/helpers/lotOccupancyDB/addLotOccupancy.js @@ -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) { diff --git a/helpers/lotOccupancyDB/addLotOccupancy.ts b/helpers/lotOccupancyDB/addLotOccupancy.ts index 1bb2b75a..5cc7604b 100644 --- a/helpers/lotOccupancyDB/addLotOccupancy.ts +++ b/helpers/lotOccupancyDB/addLotOccupancy.ts @@ -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; \ No newline at end of file +export default addLotOccupancy; diff --git a/helpers/lotOccupancyDB/addLotOccupancyComment.ts b/helpers/lotOccupancyDB/addLotOccupancyComment.ts index 2b6cee5f..ff61c7e5 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyComment.ts +++ b/helpers/lotOccupancyDB/addLotOccupancyComment.ts @@ -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; \ No newline at end of file +export default addLotOccupancyComment; diff --git a/helpers/lotOccupancyDB/addLotOccupancyFee.js b/helpers/lotOccupancyDB/addLotOccupancyFee.js index 86de6f80..24651684 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyFee.js +++ b/helpers/lotOccupancyDB/addLotOccupancyFee.js @@ -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; } diff --git a/helpers/lotOccupancyDB/addLotOccupancyFee.ts b/helpers/lotOccupancyDB/addLotOccupancyFee.ts index 15324653..916f66c6 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyFee.ts +++ b/helpers/lotOccupancyDB/addLotOccupancyFee.ts @@ -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; \ No newline at end of file +export default addLotOccupancyFee; diff --git a/helpers/lotOccupancyDB/addLotOccupancyOccupant.js b/helpers/lotOccupancyDB/addLotOccupancyOccupant.js index 0a5a4358..1cdb21e9 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyOccupant.js +++ b/helpers/lotOccupancyDB/addLotOccupancyOccupant.js @@ -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" + diff --git a/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts b/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts index 878c8140..d101c224 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts +++ b/helpers/lotOccupancyDB/addLotOccupancyOccupant.ts @@ -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; \ No newline at end of file +export default addLotOccupancyOccupant; diff --git a/helpers/lotOccupancyDB/addLotOccupancyTransaction.js b/helpers/lotOccupancyDB/addLotOccupancyTransaction.js index 64563824..d21e3461 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyTransaction.js +++ b/helpers/lotOccupancyDB/addLotOccupancyTransaction.js @@ -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," + diff --git a/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts b/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts index c2072814..d393b3db 100644 --- a/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts +++ b/helpers/lotOccupancyDB/addLotOccupancyTransaction.ts @@ -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; \ No newline at end of file +export default addLotOccupancyTransaction; diff --git a/helpers/lotOccupancyDB/addLotOccupantType.js b/helpers/lotOccupancyDB/addLotOccupantType.js index 10663923..b1c21dfd 100644 --- a/helpers/lotOccupancyDB/addLotOccupantType.js +++ b/helpers/lotOccupancyDB/addLotOccupantType.js @@ -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; diff --git a/helpers/lotOccupancyDB/addLotOccupantType.ts b/helpers/lotOccupancyDB/addLotOccupantType.ts index 24aae01d..e231ac2b 100644 --- a/helpers/lotOccupancyDB/addLotOccupantType.ts +++ b/helpers/lotOccupancyDB/addLotOccupantType.ts @@ -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; \ No newline at end of file +export default addLotOccupantType; diff --git a/helpers/lotOccupancyDB/addLotStatus.js b/helpers/lotOccupancyDB/addLotStatus.js index e99f15c9..304559ad 100644 --- a/helpers/lotOccupancyDB/addLotStatus.js +++ b/helpers/lotOccupancyDB/addLotStatus.js @@ -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; diff --git a/helpers/lotOccupancyDB/addLotStatus.ts b/helpers/lotOccupancyDB/addLotStatus.ts index 33b5d2f4..5441bedb 100644 --- a/helpers/lotOccupancyDB/addLotStatus.ts +++ b/helpers/lotOccupancyDB/addLotStatus.ts @@ -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; \ No newline at end of file +export default addLotStatus; diff --git a/helpers/lotOccupancyDB/addLotType.js b/helpers/lotOccupancyDB/addLotType.js index 128a32ac..78ed9194 100644 --- a/helpers/lotOccupancyDB/addLotType.js +++ b/helpers/lotOccupancyDB/addLotType.js @@ -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; diff --git a/helpers/lotOccupancyDB/addLotType.ts b/helpers/lotOccupancyDB/addLotType.ts index 32ac543e..27358c32 100644 --- a/helpers/lotOccupancyDB/addLotType.ts +++ b/helpers/lotOccupancyDB/addLotType.ts @@ -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; \ No newline at end of file +export default addLotType; diff --git a/helpers/lotOccupancyDB/addMap.js b/helpers/lotOccupancyDB/addMap.js index bff4bf07..0f14b7be 100644 --- a/helpers/lotOccupancyDB/addMap.js +++ b/helpers/lotOccupancyDB/addMap.js @@ -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; }; diff --git a/helpers/lotOccupancyDB/addMap.ts b/helpers/lotOccupancyDB/addMap.ts index 092ecc6d..0aedc70f 100644 --- a/helpers/lotOccupancyDB/addMap.ts +++ b/helpers/lotOccupancyDB/addMap.ts @@ -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; \ No newline at end of file +export default addMap; diff --git a/helpers/lotOccupancyDB/addOccupancyType.js b/helpers/lotOccupancyDB/addOccupancyType.js index a1b7b576..682cba5a 100644 --- a/helpers/lotOccupancyDB/addOccupancyType.js +++ b/helpers/lotOccupancyDB/addOccupancyType.js @@ -10,7 +10,7 @@ export const addOccupancyType = (occupancyTypeForm, requestSession) => { " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + " values (?, ?, ?, ?, ?, ?)") - .run(occupancyTypeForm.occupancyType, (occupancyTypeForm.orderNumber || 0), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); + .run(occupancyTypeForm.occupancyType, occupancyTypeForm.orderNumber || 0, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); database.close(); clearOccupancyTypesCache(); return result.lastInsertRowid; diff --git a/helpers/lotOccupancyDB/addOccupancyType.ts b/helpers/lotOccupancyDB/addOccupancyType.ts index 21895deb..af31416f 100644 --- a/helpers/lotOccupancyDB/addOccupancyType.ts +++ b/helpers/lotOccupancyDB/addOccupancyType.ts @@ -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 { - clearOccupancyTypesCache -} from "../functions.cache.js"; +import { clearOccupancyTypesCache } from "../functions.cache.js"; import type * as recordTypes from "../../types/recordTypes"; - interface AddOccupancyTypeForm { occupancyType: string; - orderNumber ? : number; + orderNumber?: number; } +export const addOccupancyType = ( + occupancyTypeForm: AddOccupancyTypeForm, + requestSession: recordTypes.PartialSession +): number => { + const database = sqlite(databasePath); -export const addOccupancyType = - (occupancyTypeForm: AddOccupancyTypeForm, requestSession: recordTypes.PartialSession): number => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("insert into OccupancyTypes (" + + const result = database + .prepare( + "insert into OccupancyTypes (" + "occupancyType, orderNumber," + " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + - " values (?, ?, ?, ?, ?, ?)") - .run(occupancyTypeForm.occupancyType, - (occupancyTypeForm.orderNumber || 0), - requestSession.user.userName, - rightNowMillis, - requestSession.user.userName, - rightNowMillis); + " values (?, ?, ?, ?, ?, ?)" + ) + .run( + occupancyTypeForm.occupancyType, + occupancyTypeForm.orderNumber || 0, + requestSession.user.userName, + rightNowMillis, + requestSession.user.userName, + rightNowMillis + ); - database.close(); + database.close(); - clearOccupancyTypesCache(); + clearOccupancyTypesCache(); - return result.lastInsertRowid as number; - }; + return result.lastInsertRowid as number; +}; - -export default addOccupancyType; \ No newline at end of file +export default addOccupancyType; diff --git a/helpers/lotOccupancyDB/addOccupancyTypeField.js b/helpers/lotOccupancyDB/addOccupancyTypeField.js index 3bfa49f1..d10d2d3c 100644 --- a/helpers/lotOccupancyDB/addOccupancyTypeField.js +++ b/helpers/lotOccupancyDB/addOccupancyTypeField.js @@ -12,7 +12,7 @@ export const addOccupancyTypeField = (occupancyTypeFieldForm, requestSession) => " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") - .run(occupancyTypeFieldForm.occupancyTypeId, occupancyTypeFieldForm.occupancyTypeField, occupancyTypeFieldForm.occupancyTypeFieldValues, (occupancyTypeFieldForm.isRequired ? 1 : 0), occupancyTypeFieldForm.pattern, (occupancyTypeFieldForm.minimumLength || 0), (occupancyTypeFieldForm.maximumLength || 100), (occupancyTypeFieldForm.orderNumber || 0), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); + .run(occupancyTypeFieldForm.occupancyTypeId, occupancyTypeFieldForm.occupancyTypeField, occupancyTypeFieldForm.occupancyTypeFieldValues, occupancyTypeFieldForm.isRequired ? 1 : 0, occupancyTypeFieldForm.pattern, occupancyTypeFieldForm.minimumLength || 0, occupancyTypeFieldForm.maximumLength || 100, occupancyTypeFieldForm.orderNumber || 0, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); database.close(); return result.lastInsertRowid; }; diff --git a/helpers/lotOccupancyDB/addOccupancyTypeField.ts b/helpers/lotOccupancyDB/addOccupancyTypeField.ts index 1fe582e4..767e3f98 100644 --- a/helpers/lotOccupancyDB/addOccupancyTypeField.ts +++ b/helpers/lotOccupancyDB/addOccupancyTypeField.ts @@ -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 AddOccupancyTypeFieldForm { occupancyTypeId: string | number; occupancyTypeField: string; @@ -18,40 +15,43 @@ interface AddOccupancyTypeFieldForm { orderNumber?: number; } +export const addOccupancyTypeField = ( + occupancyTypeFieldForm: AddOccupancyTypeFieldForm, + requestSession: recordTypes.PartialSession +): number => { + const database = sqlite(databasePath); -export const addOccupancyTypeField = - (occupancyTypeFieldForm: AddOccupancyTypeFieldForm, requestSession: recordTypes.PartialSession): number => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("insert into OccupancyTypeFields (" + + const result = database + .prepare( + "insert into OccupancyTypeFields (" + "occupancyTypeId, occupancyTypeField," + " occupancyTypeFieldValues, isRequired, pattern," + " minimumLength, maximumLength," + " orderNumber," + " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + - " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") - .run(occupancyTypeFieldForm.occupancyTypeId, - occupancyTypeFieldForm.occupancyTypeField, - occupancyTypeFieldForm.occupancyTypeFieldValues, - (occupancyTypeFieldForm.isRequired ? 1 : 0), - occupancyTypeFieldForm.pattern, - (occupancyTypeFieldForm.minimumLength || 0), - (occupancyTypeFieldForm.maximumLength || 100), - (occupancyTypeFieldForm.orderNumber || 0), - requestSession.user.userName, - rightNowMillis, - requestSession.user.userName, - rightNowMillis); + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + ) + .run( + occupancyTypeFieldForm.occupancyTypeId, + occupancyTypeFieldForm.occupancyTypeField, + occupancyTypeFieldForm.occupancyTypeFieldValues, + occupancyTypeFieldForm.isRequired ? 1 : 0, + occupancyTypeFieldForm.pattern, + occupancyTypeFieldForm.minimumLength || 0, + occupancyTypeFieldForm.maximumLength || 100, + occupancyTypeFieldForm.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 addOccupancyTypeField; \ No newline at end of file +export default addOccupancyTypeField; diff --git a/helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js b/helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js index 9bb5184b..56e286df 100644 --- a/helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js +++ b/helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.js @@ -26,6 +26,6 @@ export const addOrUpdateLotOccupancyField = (lotOccupancyFieldForm, requestSessi if (!connectedDatabase) { database.close(); } - return (result.changes > 0); + return result.changes > 0; }; export default addOrUpdateLotOccupancyField; diff --git a/helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.ts b/helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.ts index 4bed2a65..df236b83 100644 --- a/helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.ts +++ b/helpers/lotOccupancyDB/addOrUpdateLotOccupancyField.ts @@ -1,67 +1,69 @@ 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 LotOccupancyFieldForm { lotOccupancyId: string | number; occupancyTypeFieldId: string | number; lotOccupancyFieldValue: string; } +export const addOrUpdateLotOccupancyField = ( + lotOccupancyFieldForm: LotOccupancyFieldForm, + requestSession: recordTypes.PartialSession, + connectedDatabase?: sqlite.Database +): boolean => { + const database = connectedDatabase || sqlite(databasePath); -export const addOrUpdateLotOccupancyField = - (lotOccupancyFieldForm: LotOccupancyFieldForm, - requestSession: recordTypes.PartialSession, - connectedDatabase?: sqlite.Database): boolean => { + const rightNowMillis = Date.now(); - const database = connectedDatabase || sqlite(databasePath); - - const rightNowMillis = Date.now(); - - let result = database - .prepare("update LotOccupancyFields" + + let result = database + .prepare( + "update LotOccupancyFields" + " set lotOccupancyFieldValue = ?," + " recordUpdate_userName = ?," + " recordUpdate_timeMillis = ?," + " recordDelete_userName = null," + " recordDelete_timeMillis = null" + " where lotOccupancyId = ?" + - " and occupancyTypeFieldId = ?") - .run(lotOccupancyFieldForm.lotOccupancyFieldValue, - requestSession.user.userName, - rightNowMillis, - lotOccupancyFieldForm.lotOccupancyId, - lotOccupancyFieldForm.occupancyTypeFieldId); + " and occupancyTypeFieldId = ?" + ) + .run( + lotOccupancyFieldForm.lotOccupancyFieldValue, + requestSession.user.userName, + rightNowMillis, + lotOccupancyFieldForm.lotOccupancyId, + lotOccupancyFieldForm.occupancyTypeFieldId + ); - if (result.changes === 0) { - - result = database - .prepare("insert into LotOccupancyFields (" + + if (result.changes === 0) { + result = database + .prepare( + "insert into LotOccupancyFields (" + "lotOccupancyId, occupancyTypeFieldId," + " lotOccupancyFieldValue," + " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + - " values (?, ?, ?, ?, ?, ?, ?)") - .run(lotOccupancyFieldForm.lotOccupancyId, - lotOccupancyFieldForm.occupancyTypeFieldId, - lotOccupancyFieldForm.lotOccupancyFieldValue, - requestSession.user.userName, - rightNowMillis, - requestSession.user.userName, - rightNowMillis); - } + " values (?, ?, ?, ?, ?, ?, ?)" + ) + .run( + lotOccupancyFieldForm.lotOccupancyId, + lotOccupancyFieldForm.occupancyTypeFieldId, + lotOccupancyFieldForm.lotOccupancyFieldValue, + requestSession.user.userName, + rightNowMillis, + requestSession.user.userName, + rightNowMillis + ); + } - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close(); + } - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default addOrUpdateLotOccupancyField; \ No newline at end of file +export default addOrUpdateLotOccupancyField; diff --git a/helpers/lotOccupancyDB/addWorkOrder.js b/helpers/lotOccupancyDB/addWorkOrder.js index 18cfbfc7..3f0bcc3a 100644 --- a/helpers/lotOccupancyDB/addWorkOrder.js +++ b/helpers/lotOccupancyDB/addWorkOrder.js @@ -11,7 +11,11 @@ export const addWorkOrder = (workOrderForm, requestSession) => { " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + " values (?, ?, ?, ?, ?, ?, ?, ?, ?)") - .run(workOrderForm.workOrderTypeId, workOrderForm.workOrderNumber, workOrderForm.workOrderDescription, (workOrderForm.workOrderOpenDateString ? dateStringToInteger(workOrderForm.workOrderOpenDateString) : dateToInteger(rightNow)), (workOrderForm.workOrderCloseDateString ? dateStringToInteger(workOrderForm.workOrderCloseDateString) : undefined), requestSession.user.userName, rightNow.getTime(), requestSession.user.userName, rightNow.getTime()); + .run(workOrderForm.workOrderTypeId, workOrderForm.workOrderNumber, workOrderForm.workOrderDescription, workOrderForm.workOrderOpenDateString + ? dateStringToInteger(workOrderForm.workOrderOpenDateString) + : dateToInteger(rightNow), workOrderForm.workOrderCloseDateString + ? dateStringToInteger(workOrderForm.workOrderCloseDateString) + : undefined, requestSession.user.userName, rightNow.getTime(), requestSession.user.userName, rightNow.getTime()); database.close(); return result.lastInsertRowid; }; diff --git a/helpers/lotOccupancyDB/addWorkOrder.ts b/helpers/lotOccupancyDB/addWorkOrder.ts index af628244..0365f335 100644 --- a/helpers/lotOccupancyDB/addWorkOrder.ts +++ b/helpers/lotOccupancyDB/addWorkOrder.ts @@ -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, @@ -11,44 +9,50 @@ import { import type * as recordTypes from "../../types/recordTypes"; - interface AddWorkOrderForm { workOrderTypeId: number | string; workOrderNumber: string; workOrderDescription: string; - workOrderOpenDateString ? : string; - workOrderCloseDateString ? : string; + workOrderOpenDateString?: string; + workOrderCloseDateString?: string; } +export const addWorkOrder = ( + workOrderForm: AddWorkOrderForm, + requestSession: recordTypes.PartialSession +): number => { + const database = sqlite(databasePath); -export const addWorkOrder = - (workOrderForm: AddWorkOrderForm, requestSession: recordTypes.PartialSession): number => { + const rightNow = new Date(); - const database = sqlite(databasePath); - - const rightNow = new Date(); - - const result = database - .prepare("insert into WorkOrders (" + + const result = database + .prepare( + "insert into WorkOrders (" + "workOrderTypeId, workOrderNumber, workOrderDescription," + " workOrderOpenDate, workOrderCloseDate," + " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + - " values (?, ?, ?, ?, ?, ?, ?, ?, ?)") - .run(workOrderForm.workOrderTypeId, - workOrderForm.workOrderNumber, - workOrderForm.workOrderDescription, - (workOrderForm.workOrderOpenDateString ? dateStringToInteger(workOrderForm.workOrderOpenDateString) : dateToInteger(rightNow)), - (workOrderForm.workOrderCloseDateString ? dateStringToInteger(workOrderForm.workOrderCloseDateString) : undefined), - requestSession.user.userName, - rightNow.getTime(), - requestSession.user.userName, - rightNow.getTime()); + " values (?, ?, ?, ?, ?, ?, ?, ?, ?)" + ) + .run( + workOrderForm.workOrderTypeId, + workOrderForm.workOrderNumber, + workOrderForm.workOrderDescription, + workOrderForm.workOrderOpenDateString + ? dateStringToInteger(workOrderForm.workOrderOpenDateString) + : dateToInteger(rightNow), + workOrderForm.workOrderCloseDateString + ? dateStringToInteger(workOrderForm.workOrderCloseDateString) + : undefined, + 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 addWorkOrder; \ No newline at end of file +export default addWorkOrder; diff --git a/helpers/lotOccupancyDB/addWorkOrderLot.ts b/helpers/lotOccupancyDB/addWorkOrderLot.ts index b1c0695a..d6aef4de 100644 --- a/helpers/lotOccupancyDB/addWorkOrderLot.ts +++ b/helpers/lotOccupancyDB/addWorkOrderLot.ts @@ -1,42 +1,42 @@ 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 AddWorkOrderLotForm { workOrderId: number | string; lotId: number | string; } +export const addWorkOrderLot = ( + workOrderLotForm: AddWorkOrderLotForm, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const addWorkOrderLot = - (workOrderLotForm: AddWorkOrderLotForm, requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("insert into WorkOrderLots (" + + const result = database + .prepare( + "insert into WorkOrderLots (" + "workOrderId, lotId," + " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + - " values (?, ?, ?, ?, ?, ?)") - .run(workOrderLotForm.workOrderId, - workOrderLotForm.lotId, - requestSession.user.userName, - rightNowMillis, - requestSession.user.userName, - rightNowMillis); + " values (?, ?, ?, ?, ?, ?)" + ) + .run( + workOrderLotForm.workOrderId, + workOrderLotForm.lotId, + requestSession.user.userName, + rightNowMillis, + requestSession.user.userName, + rightNowMillis + ); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default addWorkOrderLot; \ No newline at end of file +export default addWorkOrderLot; diff --git a/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.ts b/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.ts index 98bfc709..01652e39 100644 --- a/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.ts +++ b/helpers/lotOccupancyDB/addWorkOrderLotOccupancy.ts @@ -1,42 +1,42 @@ 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 AddWorkOrderLotOccupancyForm { workOrderId: number | string; lotOccupancyId: number | string; } +export const addWorkOrderLotOccupancy = ( + workOrderLotOccupancyForm: AddWorkOrderLotOccupancyForm, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const addWorkOrderLotOccupancy = - (workOrderLotOccupancyForm: AddWorkOrderLotOccupancyForm, requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("insert into WorkOrderLotOccupancies (" + + const result = database + .prepare( + "insert into WorkOrderLotOccupancies (" + "workOrderId, lotOccupancyId," + " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + - " values (?, ?, ?, ?, ?, ?)") - .run(workOrderLotOccupancyForm.workOrderId, - workOrderLotOccupancyForm.lotOccupancyId, - requestSession.user.userName, - rightNowMillis, - requestSession.user.userName, - rightNowMillis); + " values (?, ?, ?, ?, ?, ?)" + ) + .run( + workOrderLotOccupancyForm.workOrderId, + workOrderLotOccupancyForm.lotOccupancyId, + requestSession.user.userName, + rightNowMillis, + requestSession.user.userName, + rightNowMillis + ); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default addWorkOrderLotOccupancy; \ No newline at end of file +export default addWorkOrderLotOccupancy; diff --git a/helpers/lotOccupancyDB/addWorkOrderType.js b/helpers/lotOccupancyDB/addWorkOrderType.js index 95559beb..411c1cb6 100644 --- a/helpers/lotOccupancyDB/addWorkOrderType.js +++ b/helpers/lotOccupancyDB/addWorkOrderType.js @@ -10,7 +10,7 @@ export const addWorkOrderType = (workOrderTypeForm, requestSession) => { " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + " values (?, ?, ?, ?, ?, ?)") - .run(workOrderTypeForm.workOrderType, (workOrderTypeForm.orderNumber || -1), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); + .run(workOrderTypeForm.workOrderType, workOrderTypeForm.orderNumber || -1, requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis); database.close(); clearWorkOrderTypesCache(); return result.lastInsertRowid; diff --git a/helpers/lotOccupancyDB/addWorkOrderType.ts b/helpers/lotOccupancyDB/addWorkOrderType.ts index f65dbcb0..7eeadff5 100644 --- a/helpers/lotOccupancyDB/addWorkOrderType.ts +++ b/helpers/lotOccupancyDB/addWorkOrderType.ts @@ -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 { - clearWorkOrderTypesCache -} from "../functions.cache.js"; +import { clearWorkOrderTypesCache } from "../functions.cache.js"; import type * as recordTypes from "../../types/recordTypes"; - interface AddWorkOrderTypeForm { workOrderType: string; - orderNumber ? : number; + orderNumber?: number; } +export const addWorkOrderType = ( + workOrderTypeForm: AddWorkOrderTypeForm, + requestSession: recordTypes.PartialSession +): number => { + const database = sqlite(databasePath); -export const addWorkOrderType = - (workOrderTypeForm: AddWorkOrderTypeForm, requestSession: recordTypes.PartialSession): number => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("insert into WorkOrderTypes (" + + const result = database + .prepare( + "insert into WorkOrderTypes (" + "workOrderType, orderNumber," + " recordCreate_userName, recordCreate_timeMillis," + " recordUpdate_userName, recordUpdate_timeMillis)" + - " values (?, ?, ?, ?, ?, ?)") - .run(workOrderTypeForm.workOrderType, - (workOrderTypeForm.orderNumber || -1), - requestSession.user.userName, - rightNowMillis, - requestSession.user.userName, - rightNowMillis); + " values (?, ?, ?, ?, ?, ?)" + ) + .run( + workOrderTypeForm.workOrderType, + workOrderTypeForm.orderNumber || -1, + requestSession.user.userName, + rightNowMillis, + requestSession.user.userName, + rightNowMillis + ); - database.close(); + database.close(); - clearWorkOrderTypesCache(); + clearWorkOrderTypesCache(); - return result.lastInsertRowid as number; - }; + return result.lastInsertRowid as number; +}; - -export default addWorkOrderType; \ No newline at end of file +export default addWorkOrderType; diff --git a/helpers/lotOccupancyDB/deleteFee.js b/helpers/lotOccupancyDB/deleteFee.js index 763e0591..0828772b 100644 --- a/helpers/lotOccupancyDB/deleteFee.js +++ b/helpers/lotOccupancyDB/deleteFee.js @@ -10,6 +10,6 @@ export const deleteFee = (feeId, requestSession) => { " where feeId = ?") .run(requestSession.user.userName, rightNowMillis, feeId); database.close(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteFee; diff --git a/helpers/lotOccupancyDB/deleteFee.ts b/helpers/lotOccupancyDB/deleteFee.ts index ee7a9cc5..e41d7b69 100644 --- a/helpers/lotOccupancyDB/deleteFee.ts +++ b/helpers/lotOccupancyDB/deleteFee.ts @@ -1,33 +1,29 @@ 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"; +export const deleteFee = ( + feeId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteFee = - (feeId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update Fees" + + const result = database + .prepare( + "update Fees" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + - " where feeId = ?") - .run(requestSession.user.userName, - rightNowMillis, - feeId); + " where feeId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, feeId); - database.close(); + database.close(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteFee; \ No newline at end of file +export default deleteFee; diff --git a/helpers/lotOccupancyDB/deleteFeeCategory.js b/helpers/lotOccupancyDB/deleteFeeCategory.js index 93cae785..478ff8bd 100644 --- a/helpers/lotOccupancyDB/deleteFeeCategory.js +++ b/helpers/lotOccupancyDB/deleteFeeCategory.js @@ -10,6 +10,6 @@ export const deleteFeeCategory = (feeCategoryId, requestSession) => { " where feeCategoryId = ?") .run(requestSession.user.userName, rightNowMillis, feeCategoryId); database.close(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteFeeCategory; diff --git a/helpers/lotOccupancyDB/deleteFeeCategory.ts b/helpers/lotOccupancyDB/deleteFeeCategory.ts index 19820265..25f60447 100644 --- a/helpers/lotOccupancyDB/deleteFeeCategory.ts +++ b/helpers/lotOccupancyDB/deleteFeeCategory.ts @@ -1,33 +1,29 @@ 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"; +export const deleteFeeCategory = ( + feeCategoryId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteFeeCategory = - (feeCategoryId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update FeeCategories" + + const result = database + .prepare( + "update FeeCategories" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + - " where feeCategoryId = ?") - .run(requestSession.user.userName, - rightNowMillis, - feeCategoryId); + " where feeCategoryId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, feeCategoryId); - database.close(); + database.close(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteFeeCategory; \ No newline at end of file +export default deleteFeeCategory; diff --git a/helpers/lotOccupancyDB/deleteLotComment.js b/helpers/lotOccupancyDB/deleteLotComment.js index 2fbda89f..806a5021 100644 --- a/helpers/lotOccupancyDB/deleteLotComment.js +++ b/helpers/lotOccupancyDB/deleteLotComment.js @@ -10,6 +10,6 @@ export const deleteLotComment = (lotCommentId, requestSession) => { " where lotCommentId = ?") .run(requestSession.user.userName, rightNowMillis, lotCommentId); database.close(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteLotComment; diff --git a/helpers/lotOccupancyDB/deleteLotComment.ts b/helpers/lotOccupancyDB/deleteLotComment.ts index 46439e3e..2d225236 100644 --- a/helpers/lotOccupancyDB/deleteLotComment.ts +++ b/helpers/lotOccupancyDB/deleteLotComment.ts @@ -1,33 +1,29 @@ 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"; +export const deleteLotComment = ( + lotCommentId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteLotComment = - (lotCommentId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotComments" + + const result = database + .prepare( + "update LotComments" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + - " where lotCommentId = ?") - .run(requestSession.user.userName, - rightNowMillis, - lotCommentId); + " where lotCommentId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, lotCommentId); - database.close(); + database.close(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteLotComment; \ No newline at end of file +export default deleteLotComment; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancy.js b/helpers/lotOccupancyDB/deleteLotOccupancy.js index 4d3bb2f4..564854aa 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancy.js +++ b/helpers/lotOccupancyDB/deleteLotOccupancy.js @@ -10,6 +10,6 @@ export const deleteLotOccupancy = (lotOccupancyId, requestSession) => { " where lotOccupancyId = ?") .run(requestSession.user.userName, rightNowMillis, lotOccupancyId); database.close(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteLotOccupancy; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancy.ts b/helpers/lotOccupancyDB/deleteLotOccupancy.ts index 9747e134..a862b6ab 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancy.ts +++ b/helpers/lotOccupancyDB/deleteLotOccupancy.ts @@ -1,33 +1,29 @@ 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"; +export const deleteLotOccupancy = ( + lotOccupancyId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteLotOccupancy = - (lotOccupancyId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotOccupancies" + + const result = database + .prepare( + "update LotOccupancies" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + - " where lotOccupancyId = ?") - .run(requestSession.user.userName, - rightNowMillis, - lotOccupancyId); + " where lotOccupancyId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, lotOccupancyId); - database.close(); + database.close(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteLotOccupancy; \ No newline at end of file +export default deleteLotOccupancy; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyComment.js b/helpers/lotOccupancyDB/deleteLotOccupancyComment.js index b9e70c74..8e90173c 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyComment.js +++ b/helpers/lotOccupancyDB/deleteLotOccupancyComment.js @@ -10,6 +10,6 @@ export const deleteLotOccupancyComment = (lotOccupancyCommentId, requestSession) " where lotOccupancyCommentId = ?") .run(requestSession.user.userName, rightNowMillis, lotOccupancyCommentId); database.close(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteLotOccupancyComment; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyComment.ts b/helpers/lotOccupancyDB/deleteLotOccupancyComment.ts index f6f6dfec..0c5a7516 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyComment.ts +++ b/helpers/lotOccupancyDB/deleteLotOccupancyComment.ts @@ -1,33 +1,33 @@ 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"; +export const deleteLotOccupancyComment = ( + lotOccupancyCommentId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteLotOccupancyComment = - (lotOccupancyCommentId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotOccupancyComments" + + const result = database + .prepare( + "update LotOccupancyComments" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + - " where lotOccupancyCommentId = ?") - .run(requestSession.user.userName, - rightNowMillis, - lotOccupancyCommentId); + " where lotOccupancyCommentId = ?" + ) + .run( + requestSession.user.userName, + rightNowMillis, + lotOccupancyCommentId + ); - database.close(); + database.close(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteLotOccupancyComment; \ No newline at end of file +export default deleteLotOccupancyComment; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyFee.js b/helpers/lotOccupancyDB/deleteLotOccupancyFee.js index 234ce486..dbed9b9f 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyFee.js +++ b/helpers/lotOccupancyDB/deleteLotOccupancyFee.js @@ -11,6 +11,6 @@ export const deleteLotOccupancyFee = (lotOccupancyId, feeId, requestSession) => " and feeId = ?") .run(requestSession.user.userName, rightNowMillis, lotOccupancyId, feeId); database.close(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteLotOccupancyFee; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyFee.ts b/helpers/lotOccupancyDB/deleteLotOccupancyFee.ts index 37ca8260..6d649801 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyFee.ts +++ b/helpers/lotOccupancyDB/deleteLotOccupancyFee.ts @@ -1,36 +1,36 @@ 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"; +export const deleteLotOccupancyFee = ( + lotOccupancyId: number | string, + feeId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteLotOccupancyFee = - (lotOccupancyId: number | string, - feeId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotOccupancyFees" + + const result = database + .prepare( + "update LotOccupancyFees" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + " where lotOccupancyId = ?" + - " and feeId = ?") - .run(requestSession.user.userName, - rightNowMillis, - lotOccupancyId, - feeId); + " and feeId = ?" + ) + .run( + requestSession.user.userName, + rightNowMillis, + lotOccupancyId, + feeId + ); - database.close(); + database.close(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteLotOccupancyFee; \ No newline at end of file +export default deleteLotOccupancyFee; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyField.js b/helpers/lotOccupancyDB/deleteLotOccupancyField.js index c5425dd6..2619252e 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyField.js +++ b/helpers/lotOccupancyDB/deleteLotOccupancyField.js @@ -13,6 +13,6 @@ export const deleteLotOccupancyField = (lotOccupancyId, occupancyTypeFieldId, re if (!connectedDatabase) { database.close(); } - return (result.changes > 0); + return result.changes > 0; }; export default deleteLotOccupancyField; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyField.ts b/helpers/lotOccupancyDB/deleteLotOccupancyField.ts index 5cfcb714..ee068459 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyField.ts +++ b/helpers/lotOccupancyDB/deleteLotOccupancyField.ts @@ -1,39 +1,39 @@ 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"; +export const deleteLotOccupancyField = ( + lotOccupancyId: number | string, + occupancyTypeFieldId: number | string, + requestSession: recordTypes.PartialSession, + connectedDatabase?: sqlite.Database +): boolean => { + const database = connectedDatabase || sqlite(databasePath); -export const deleteLotOccupancyField = - (lotOccupancyId: number | string, - occupancyTypeFieldId: number | string, - requestSession: recordTypes.PartialSession, - connectedDatabase ? : sqlite.Database): boolean => { + const rightNowMillis = Date.now(); - const database = connectedDatabase || sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotOccupancyFields" + + const result = database + .prepare( + "update LotOccupancyFields" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + " where lotOccupancyId = ?" + - " and occupancyTypeFieldId = ?") - .run(requestSession.user.userName, - rightNowMillis, - lotOccupancyId, - occupancyTypeFieldId); + " and occupancyTypeFieldId = ?" + ) + .run( + requestSession.user.userName, + rightNowMillis, + lotOccupancyId, + occupancyTypeFieldId + ); - if (!connectedDatabase) { - database.close(); - } + if (!connectedDatabase) { + database.close(); + } - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteLotOccupancyField; \ No newline at end of file +export default deleteLotOccupancyField; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js index cb00dbfa..c4fc6c09 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js +++ b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.js @@ -11,6 +11,6 @@ export const deleteLotOccupancyOccupant = (lotOccupancyId, lotOccupantIndex, req " and lotOccupantIndex = ?") .run(requestSession.user.userName, rightNowMillis, lotOccupancyId, lotOccupantIndex); database.close(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteLotOccupancyOccupant; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.ts b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.ts index de217a3e..1589c4eb 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.ts +++ b/helpers/lotOccupancyDB/deleteLotOccupancyOccupant.ts @@ -1,36 +1,36 @@ 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"; +export const deleteLotOccupancyOccupant = ( + lotOccupancyId: number | string, + lotOccupantIndex: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteLotOccupancyOccupant = - (lotOccupancyId: number | string, - lotOccupantIndex: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotOccupancyOccupants" + + const result = database + .prepare( + "update LotOccupancyOccupants" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + " where lotOccupancyId = ?" + - " and lotOccupantIndex = ?") - .run(requestSession.user.userName, - rightNowMillis, - lotOccupancyId, - lotOccupantIndex); + " and lotOccupantIndex = ?" + ) + .run( + requestSession.user.userName, + rightNowMillis, + lotOccupancyId, + lotOccupantIndex + ); - database.close(); + database.close(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteLotOccupancyOccupant; \ No newline at end of file +export default deleteLotOccupancyOccupant; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyTransaction.js b/helpers/lotOccupancyDB/deleteLotOccupancyTransaction.js index 85d6f863..762bb9ba 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyTransaction.js +++ b/helpers/lotOccupancyDB/deleteLotOccupancyTransaction.js @@ -11,6 +11,6 @@ export const deleteLotOccupancyTransaction = (lotOccupancyId, transactionIndex, " and transactionIndex = ?") .run(requestSession.user.userName, rightNowMillis, lotOccupancyId, transactionIndex); database.close(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteLotOccupancyTransaction; diff --git a/helpers/lotOccupancyDB/deleteLotOccupancyTransaction.ts b/helpers/lotOccupancyDB/deleteLotOccupancyTransaction.ts index 863d7638..c586b8f7 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupancyTransaction.ts +++ b/helpers/lotOccupancyDB/deleteLotOccupancyTransaction.ts @@ -1,36 +1,36 @@ 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"; +export const deleteLotOccupancyTransaction = ( + lotOccupancyId: number | string, + transactionIndex: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteLotOccupancyTransaction = - (lotOccupancyId: number | string, - transactionIndex: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotOccupancyTransactions" + + const result = database + .prepare( + "update LotOccupancyTransactions" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + " where lotOccupancyId = ?" + - " and transactionIndex = ?") - .run(requestSession.user.userName, - rightNowMillis, - lotOccupancyId, - transactionIndex); + " and transactionIndex = ?" + ) + .run( + requestSession.user.userName, + rightNowMillis, + lotOccupancyId, + transactionIndex + ); - database.close(); + database.close(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteLotOccupancyTransaction; \ No newline at end of file +export default deleteLotOccupancyTransaction; diff --git a/helpers/lotOccupancyDB/deleteLotOccupantType.js b/helpers/lotOccupancyDB/deleteLotOccupantType.js index 0384e7bb..fc7647eb 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupantType.js +++ b/helpers/lotOccupancyDB/deleteLotOccupantType.js @@ -12,6 +12,6 @@ export const deleteLotOccupantType = (lotOccupantTypeId, requestSession) => { .run(requestSession.user.userName, rightNowMillis, lotOccupantTypeId); database.close(); clearLotOccupantTypesCache(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteLotOccupantType; diff --git a/helpers/lotOccupancyDB/deleteLotOccupantType.ts b/helpers/lotOccupancyDB/deleteLotOccupantType.ts index 22edad65..b5ef752c 100644 --- a/helpers/lotOccupancyDB/deleteLotOccupantType.ts +++ b/helpers/lotOccupancyDB/deleteLotOccupantType.ts @@ -1,39 +1,33 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearLotOccupantTypesCache -} from "../functions.cache.js"; +import { clearLotOccupantTypesCache } from "../functions.cache.js"; import type * as recordTypes from "../../types/recordTypes"; +export const deleteLotOccupantType = ( + lotOccupantTypeId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteLotOccupantType = - (lotOccupantTypeId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotOccupantTypes" + + const result = database + .prepare( + "update LotOccupantTypes" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + - " where lotOccupantTypeId = ?") - .run(requestSession.user.userName, - rightNowMillis, - lotOccupantTypeId); + " where lotOccupantTypeId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, lotOccupantTypeId); - database.close(); + database.close(); - clearLotOccupantTypesCache(); + clearLotOccupantTypesCache(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteLotOccupantType; \ No newline at end of file +export default deleteLotOccupantType; diff --git a/helpers/lotOccupancyDB/deleteLotStatus.js b/helpers/lotOccupancyDB/deleteLotStatus.js index b9bf874f..53a75359 100644 --- a/helpers/lotOccupancyDB/deleteLotStatus.js +++ b/helpers/lotOccupancyDB/deleteLotStatus.js @@ -12,6 +12,6 @@ export const deleteLotStatus = (lotStatusId, requestSession) => { .run(requestSession.user.userName, rightNowMillis, lotStatusId); database.close(); clearLotStatusesCache(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteLotStatus; diff --git a/helpers/lotOccupancyDB/deleteLotStatus.ts b/helpers/lotOccupancyDB/deleteLotStatus.ts index 88b958cc..259a92e0 100644 --- a/helpers/lotOccupancyDB/deleteLotStatus.ts +++ b/helpers/lotOccupancyDB/deleteLotStatus.ts @@ -1,39 +1,33 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearLotStatusesCache -} from "../functions.cache.js"; +import { clearLotStatusesCache } from "../functions.cache.js"; import type * as recordTypes from "../../types/recordTypes"; +export const deleteLotStatus = ( + lotStatusId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteLotStatus = - (lotStatusId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotStatuses" + + const result = database + .prepare( + "update LotStatuses" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + - " where lotStatusId = ?") - .run(requestSession.user.userName, - rightNowMillis, - lotStatusId); + " where lotStatusId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, lotStatusId); - database.close(); + database.close(); - clearLotStatusesCache(); + clearLotStatusesCache(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteLotStatus; \ No newline at end of file +export default deleteLotStatus; diff --git a/helpers/lotOccupancyDB/deleteMap.js b/helpers/lotOccupancyDB/deleteMap.js index b81fcaf0..ea0aa39f 100644 --- a/helpers/lotOccupancyDB/deleteMap.js +++ b/helpers/lotOccupancyDB/deleteMap.js @@ -10,6 +10,6 @@ export const deleteMap = (mapId, requestSession) => { " where mapId = ?") .run(requestSession.user.userName, rightNowMillis, mapId); database.close(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteMap; diff --git a/helpers/lotOccupancyDB/deleteMap.ts b/helpers/lotOccupancyDB/deleteMap.ts index 177894e4..4e4bc8fa 100644 --- a/helpers/lotOccupancyDB/deleteMap.ts +++ b/helpers/lotOccupancyDB/deleteMap.ts @@ -1,33 +1,29 @@ 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"; +export const deleteMap = ( + mapId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteMap = - (mapId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update Maps" + + const result = database + .prepare( + "update Maps" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + - " where mapId = ?") - .run(requestSession.user.userName, - rightNowMillis, - mapId); + " where mapId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, mapId); - database.close(); + database.close(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteMap; \ No newline at end of file +export default deleteMap; diff --git a/helpers/lotOccupancyDB/deleteWorkOrderType.js b/helpers/lotOccupancyDB/deleteWorkOrderType.js index a4fda52c..eaeaa807 100644 --- a/helpers/lotOccupancyDB/deleteWorkOrderType.js +++ b/helpers/lotOccupancyDB/deleteWorkOrderType.js @@ -12,6 +12,6 @@ export const deleteWorkOrderType = (workOrderTypeId, requestSession) => { .run(requestSession.user.userName, rightNowMillis, workOrderTypeId); database.close(); clearWorkOrderTypesCache(); - return (result.changes > 0); + return result.changes > 0; }; export default deleteWorkOrderType; diff --git a/helpers/lotOccupancyDB/deleteWorkOrderType.ts b/helpers/lotOccupancyDB/deleteWorkOrderType.ts index 110867c1..62f50182 100644 --- a/helpers/lotOccupancyDB/deleteWorkOrderType.ts +++ b/helpers/lotOccupancyDB/deleteWorkOrderType.ts @@ -1,39 +1,33 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearWorkOrderTypesCache -} from "../functions.cache.js"; +import { clearWorkOrderTypesCache } from "../functions.cache.js"; import type * as recordTypes from "../../types/recordTypes"; +export const deleteWorkOrderType = ( + workOrderTypeId: number | string, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const deleteWorkOrderType = - (workOrderTypeId: number | string, - requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update WorkOrderTypes" + + const result = database + .prepare( + "update WorkOrderTypes" + " set recordDelete_userName = ?," + " recordDelete_timeMillis = ?" + - " where workOrderTypeId = ?") - .run(requestSession.user.userName, - rightNowMillis, - workOrderTypeId); + " where workOrderTypeId = ?" + ) + .run(requestSession.user.userName, rightNowMillis, workOrderTypeId); - database.close(); + database.close(); - clearWorkOrderTypesCache(); + clearWorkOrderTypesCache(); - return (result.changes > 0); - }; + return result.changes > 0; +}; - -export default deleteWorkOrderType; \ No newline at end of file +export default deleteWorkOrderType; diff --git a/helpers/lotOccupancyDB/getFee.js b/helpers/lotOccupancyDB/getFee.js index 9fa8aefc..d9e50047 100644 --- a/helpers/lotOccupancyDB/getFee.js +++ b/helpers/lotOccupancyDB/getFee.js @@ -4,7 +4,8 @@ export const getFee = (feeId) => { const database = sqlite(databasePath, { readonly: true }); - const fee = database.prepare("select f.feeId," + + const fee = database + .prepare("select f.feeId," + " f.feeCategoryId, c.feeCategory," + " f.feeName, f.feeDescription," + " f.occupancyTypeId, o.occupancyType," + diff --git a/helpers/lotOccupancyDB/getFee.ts b/helpers/lotOccupancyDB/getFee.ts index 1bd8d965..2de99911 100644 --- a/helpers/lotOccupancyDB/getFee.ts +++ b/helpers/lotOccupancyDB/getFee.ts @@ -1,33 +1,32 @@ 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"; - export const getFee = (feeId: number | string): recordTypes.Fee => { - const database = sqlite(databasePath, { readonly: true }); - const fee = database.prepare("select f.feeId," + - " f.feeCategoryId, c.feeCategory," + - " f.feeName, f.feeDescription," + - " f.occupancyTypeId, o.occupancyType," + - " f.lotTypeId, l.lotType," + - " ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," + - " f.taxAmount, f.taxPercentage," + - " f.includeQuantity, f.quantityUnit," + - " f.isRequired" + - " from Fees f" + - " left join FeeCategories c on f.feeCategoryId = c.feeCategoryId" + - " left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId" + - " left join LotTypes l on f.lotTypeId = l.lotTypeId" + - " where f.recordDelete_timeMillis is null" + - " and f.feeId = ?") + const fee = database + .prepare( + "select f.feeId," + + " f.feeCategoryId, c.feeCategory," + + " f.feeName, f.feeDescription," + + " f.occupancyTypeId, o.occupancyType," + + " f.lotTypeId, l.lotType," + + " ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," + + " f.taxAmount, f.taxPercentage," + + " f.includeQuantity, f.quantityUnit," + + " f.isRequired" + + " from Fees f" + + " left join FeeCategories c on f.feeCategoryId = c.feeCategoryId" + + " left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId" + + " left join LotTypes l on f.lotTypeId = l.lotTypeId" + + " where f.recordDelete_timeMillis is null" + + " and f.feeId = ?" + ) .get(feeId); database.close(); @@ -35,5 +34,4 @@ export const getFee = (feeId: number | string): recordTypes.Fee => { return fee; }; - -export default getFee; \ No newline at end of file +export default getFee; diff --git a/helpers/lotOccupancyDB/getFeeCategories.js b/helpers/lotOccupancyDB/getFeeCategories.js index 212115f0..20baa740 100644 --- a/helpers/lotOccupancyDB/getFeeCategories.js +++ b/helpers/lotOccupancyDB/getFeeCategories.js @@ -10,64 +10,70 @@ export const getFeeCategories = (filters, options) => { " where recordDelete_timeMillis is null"; let sqlParameters = []; if (filters.occupancyTypeId) { - sql += " and feeCategoryId in (" + - "select feeCategoryId from Fees" + - " where recordDelete_timeMillis is null" + - " and (occupancyTypeId is null or occupancyTypeId = ?))"; + sql += + " and feeCategoryId in (" + + "select feeCategoryId from Fees" + + " where recordDelete_timeMillis is null" + + " and (occupancyTypeId is null or occupancyTypeId = ?))"; sqlParameters.push(filters.occupancyTypeId); } if (filters.lotTypeId) { - sql += " and feeCategoryId in (" + - "select feeCategoryId from Fees" + - " where recordDelete_timeMillis is null" + - " and (lotTypeId is null or lotTypeId = ?))"; + sql += + " and feeCategoryId in (" + + "select feeCategoryId from Fees" + + " where recordDelete_timeMillis is null" + + " and (lotTypeId is null or lotTypeId = ?))"; sqlParameters.push(filters.lotTypeId); } - const feeCategories = database.prepare(sql + - " order by orderNumber, feeCategory") + const feeCategories = database + .prepare(sql + " order by orderNumber, feeCategory") .all(sqlParameters); if (options.includeFees) { let expectedFeeCategoryOrderNumber = -1; for (const feeCategory of feeCategories) { expectedFeeCategoryOrderNumber += 1; if (feeCategory.orderNumber !== expectedFeeCategoryOrderNumber) { - database.prepare("update FeeCategories" + + database + .prepare("update FeeCategories" + " set orderNumber = ?" + " where feeCategoryId = ?") .run(expectedFeeCategoryOrderNumber, feeCategory.feeCategoryId); feeCategory.orderNumber = expectedFeeCategoryOrderNumber; } - sql = "select f.feeId, f.feeName, f.feeDescription," + - " f.occupancyTypeId, o.occupancyType," + - " f.lotTypeId, l.lotType," + - " ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," + - " f.taxAmount, f.taxPercentage," + - " f.includeQuantity, f.quantityUnit," + - " f.isRequired, f.orderNumber" + - " from Fees f" + - " left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId" + - " left join LotTypes l on f.lotTypeId = l.lotTypeId" + - " where f.recordDelete_timeMillis is null" + - " and f.feeCategoryId = ?"; + sql = + "select f.feeId, f.feeName, f.feeDescription," + + " f.occupancyTypeId, o.occupancyType," + + " f.lotTypeId, l.lotType," + + " ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," + + " f.taxAmount, f.taxPercentage," + + " f.includeQuantity, f.quantityUnit," + + " f.isRequired, f.orderNumber" + + " from Fees f" + + " left join OccupancyTypes o on f.occupancyTypeId = o.occupancyTypeId" + + " left join LotTypes l on f.lotTypeId = l.lotTypeId" + + " where f.recordDelete_timeMillis is null" + + " and f.feeCategoryId = ?"; sqlParameters = []; sqlParameters.push(feeCategory.feeCategoryId); if (filters.occupancyTypeId) { - sql += " and (f.occupancyTypeId is null or f.occupancyTypeId = ?)"; + sql += + " and (f.occupancyTypeId is null or f.occupancyTypeId = ?)"; sqlParameters.push(filters.occupancyTypeId); } if (filters.lotTypeId) { sql += " and (f.lotTypeId is null or f.lotTypeId = ?)"; sqlParameters.push(filters.lotTypeId); } - feeCategory.fees = database.prepare(sql + - " order by f.orderNumber, f.feeName") + feeCategory.fees = database + .prepare(sql + " order by f.orderNumber, f.feeName") .all(sqlParameters); if (updateOrderNumbers) { let expectedFeeOrderNumber = -1; for (const fee of feeCategory.fees) { expectedFeeOrderNumber += 1; if (fee.orderNumber !== expectedFeeOrderNumber) { - database.prepare("update Fees" + + database + .prepare("update Fees" + " set orderNumber = ?" + " where feeId = ?") .run(expectedFeeOrderNumber, fee.feeId); diff --git a/helpers/lotOccupancyDB/getFeeCategories.ts b/helpers/lotOccupancyDB/getFeeCategories.ts index 8a218e4e..e9c834d2 100644 --- a/helpers/lotOccupancyDB/getFeeCategories.ts +++ b/helpers/lotOccupancyDB/getFeeCategories.ts @@ -1,38 +1,39 @@ 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 GetFeeCategoriesFilters { - occupancyTypeId ? : number | string; - lotTypeId ? : number | string; + occupancyTypeId?: number | string; + lotTypeId?: number | string; } interface GetFeeCategoriesOptions { - includeFees ? : boolean; + includeFees?: boolean; } - -export const getFeeCategories = (filters: GetFeeCategoriesFilters, options: GetFeeCategoriesOptions): recordTypes.FeeCategory[] => { - - const updateOrderNumbers = !(filters.lotTypeId || filters.occupancyTypeId) && options.includeFees; +export const getFeeCategories = ( + filters: GetFeeCategoriesFilters, + options: GetFeeCategoriesOptions +): recordTypes.FeeCategory[] => { + const updateOrderNumbers = + !(filters.lotTypeId || filters.occupancyTypeId) && options.includeFees; const database = sqlite(databasePath, { readonly: !updateOrderNumbers }); - let sql = "select feeCategoryId, feeCategory, orderNumber" + + let sql = + "select feeCategoryId, feeCategory, orderNumber" + " from FeeCategories" + " where recordDelete_timeMillis is null"; let sqlParameters = []; if (filters.occupancyTypeId) { - sql += " and feeCategoryId in (" + + sql += + " and feeCategoryId in (" + "select feeCategoryId from Fees" + " where recordDelete_timeMillis is null" + " and (occupancyTypeId is null or occupancyTypeId = ?))"; @@ -41,7 +42,8 @@ export const getFeeCategories = (filters: GetFeeCategoriesFilters, options: GetF } if (filters.lotTypeId) { - sql += " and feeCategoryId in (" + + sql += + " and feeCategoryId in (" + "select feeCategoryId from Fees" + " where recordDelete_timeMillis is null" + " and (lotTypeId is null or lotTypeId = ?))"; @@ -49,28 +51,33 @@ export const getFeeCategories = (filters: GetFeeCategoriesFilters, options: GetF sqlParameters.push(filters.lotTypeId); } - const feeCategories: recordTypes.FeeCategory[] = database.prepare(sql + - " order by orderNumber, feeCategory") + const feeCategories: recordTypes.FeeCategory[] = database + .prepare(sql + " order by orderNumber, feeCategory") .all(sqlParameters); if (options.includeFees) { - let expectedFeeCategoryOrderNumber = -1; for (const feeCategory of feeCategories) { - expectedFeeCategoryOrderNumber += 1; if (feeCategory.orderNumber !== expectedFeeCategoryOrderNumber) { - database.prepare("update FeeCategories" + - " set orderNumber = ?" + - " where feeCategoryId = ?") - .run(expectedFeeCategoryOrderNumber, feeCategory.feeCategoryId); + database + .prepare( + "update FeeCategories" + + " set orderNumber = ?" + + " where feeCategoryId = ?" + ) + .run( + expectedFeeCategoryOrderNumber, + feeCategory.feeCategoryId + ); feeCategory.orderNumber = expectedFeeCategoryOrderNumber; } - sql = "select f.feeId, f.feeName, f.feeDescription," + + sql = + "select f.feeId, f.feeName, f.feeDescription," + " f.occupancyTypeId, o.occupancyType," + " f.lotTypeId, l.lotType," + " ifnull(f.feeAmount, 0) as feeAmount, f.feeFunction," + @@ -88,7 +95,8 @@ export const getFeeCategories = (filters: GetFeeCategoriesFilters, options: GetF sqlParameters.push(feeCategory.feeCategoryId); if (filters.occupancyTypeId) { - sql += " and (f.occupancyTypeId is null or f.occupancyTypeId = ?)"; + sql += + " and (f.occupancyTypeId is null or f.occupancyTypeId = ?)"; sqlParameters.push(filters.occupancyTypeId); } @@ -99,23 +107,23 @@ export const getFeeCategories = (filters: GetFeeCategoriesFilters, options: GetF sqlParameters.push(filters.lotTypeId); } - feeCategory.fees = database.prepare(sql + - " order by f.orderNumber, f.feeName") + feeCategory.fees = database + .prepare(sql + " order by f.orderNumber, f.feeName") .all(sqlParameters); if (updateOrderNumbers) { - let expectedFeeOrderNumber = -1; for (const fee of feeCategory.fees) { - expectedFeeOrderNumber += 1; if (fee.orderNumber !== expectedFeeOrderNumber) { - - database.prepare("update Fees" + - " set orderNumber = ?" + - " where feeId = ?") + database + .prepare( + "update Fees" + + " set orderNumber = ?" + + " where feeId = ?" + ) .run(expectedFeeOrderNumber, fee.feeId); fee.orderNumber = expectedFeeOrderNumber; @@ -130,5 +138,4 @@ export const getFeeCategories = (filters: GetFeeCategoriesFilters, options: GetF return feeCategories; }; - -export default getFeeCategories; \ No newline at end of file +export default getFeeCategories; diff --git a/helpers/lotOccupancyDB/getLot.ts b/helpers/lotOccupancyDB/getLot.ts index d4f71919..2535a671 100644 --- a/helpers/lotOccupancyDB/getLot.ts +++ b/helpers/lotOccupancyDB/getLot.ts @@ -1,49 +1,47 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - getLotComments -} from "./getLotComments.js"; +import { getLotComments } from "./getLotComments.js"; -import { - getLotOccupancies -} from "./getLotOccupancies.js"; +import { getLotOccupancies } from "./getLotOccupancies.js"; import type * as recordTypes from "../../types/recordTypes"; - export const getLot = (lotId: number | string): recordTypes.Lot => { - const database = sqlite(databasePath, { readonly: true }); const lot: recordTypes.Lot = database - .prepare("select l.lotId," + - " l.lotTypeId, t.lotType," + - " l.lotName," + - " l.lotStatusId, s.lotStatus," + - " l.mapId, m.mapName, m.mapSVG, l.mapKey," + - " l.lotLatitude, l.lotLongitude" + - " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + - " left join Maps m on l.mapId = m.mapId" + - " where l.recordDelete_timeMillis is null" + - " and l.lotId = ?") + .prepare( + "select l.lotId," + + " l.lotTypeId, t.lotType," + + " l.lotName," + + " l.lotStatusId, s.lotStatus," + + " l.mapId, m.mapName, m.mapSVG, l.mapKey," + + " l.lotLatitude, l.lotLongitude" + + " from Lots l" + + " left join LotTypes t on l.lotTypeId = t.lotTypeId" + + " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + + " left join Maps m on l.mapId = m.mapId" + + " where l.recordDelete_timeMillis is null" + + " and l.lotId = ?" + ) .get(lotId); if (lot) { - lot.lotOccupancies = getLotOccupancies({ - lotId - }, { - includeOccupants: true, - limit: -1, - offset: 0 - }, database).lotOccupancies; + lot.lotOccupancies = getLotOccupancies( + { + lotId + }, + { + includeOccupants: true, + limit: -1, + offset: 0 + }, + database + ).lotOccupancies; lot.lotComments = getLotComments(lotId); } @@ -53,5 +51,4 @@ export const getLot = (lotId: number | string): recordTypes.Lot => { return lot; }; - -export default getLot; \ No newline at end of file +export default getLot; diff --git a/helpers/lotOccupancyDB/getLotComments.js b/helpers/lotOccupancyDB/getLotComments.js index 7ab3cf3e..04d6450f 100644 --- a/helpers/lotOccupancyDB/getLotComments.js +++ b/helpers/lotOccupancyDB/getLotComments.js @@ -2,9 +2,10 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { dateIntegerToString, timeIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; export const getLotComments = (lotId, connectedDatabase) => { - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = connectedDatabase || + sqlite(databasePath, { + readonly: true + }); database.function("userFn_dateIntegerToString", dateIntegerToString); database.function("userFn_timeIntegerToString", timeIntegerToString); const lotComments = database diff --git a/helpers/lotOccupancyDB/getLotComments.ts b/helpers/lotOccupancyDB/getLotComments.ts index 29e82aa6..e885cc90 100644 --- a/helpers/lotOccupancyDB/getLotComments.ts +++ b/helpers/lotOccupancyDB/getLotComments.ts @@ -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 { dateIntegerToString, @@ -11,26 +9,31 @@ import { import type * as recordTypes from "../../types/recordTypes"; - -export const getLotComments = (lotId: number | string, connectedDatabase ? : sqlite.Database): recordTypes.LotComment[] => { - - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); +export const getLotComments = ( + lotId: number | string, + connectedDatabase?: sqlite.Database +): recordTypes.LotComment[] => { + const database = + connectedDatabase || + sqlite(databasePath, { + readonly: true + }); database.function("userFn_dateIntegerToString", dateIntegerToString); database.function("userFn_timeIntegerToString", timeIntegerToString); const lotComments = database - .prepare("select lotCommentId," + - " lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString," + - " lotCommentTime, userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString," + - " lotComment," + - " recordCreate_userName, recordUpdate_userName" + - " from LotComments" + - " where recordDelete_timeMillis is null" + - " and lotId = ?" + - " order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc") + .prepare( + "select lotCommentId," + + " lotCommentDate, userFn_dateIntegerToString(lotCommentDate) as lotCommentDateString," + + " lotCommentTime, userFn_timeIntegerToString(lotCommentTime) as lotCommentTimeString," + + " lotComment," + + " recordCreate_userName, recordUpdate_userName" + + " from LotComments" + + " where recordDelete_timeMillis is null" + + " and lotId = ?" + + " order by lotCommentDate desc, lotCommentTime desc, lotCommentId desc" + ) .all(lotId); if (!connectedDatabase) { @@ -40,5 +43,4 @@ export const getLotComments = (lotId: number | string, connectedDatabase ? : sql return lotComments; }; - -export default getLotComments; \ No newline at end of file +export default getLotComments; diff --git a/helpers/lotOccupancyDB/getLotOccupancies.js b/helpers/lotOccupancyDB/getLotOccupancies.js index 55c4aebd..9fe2de3b 100644 --- a/helpers/lotOccupancyDB/getLotOccupancies.js +++ b/helpers/lotOccupancyDB/getLotOccupancies.js @@ -3,9 +3,10 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { dateIntegerToString, dateStringToInteger, dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js"; import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js"; export const getLotOccupancies = (filters, options, connectedDatabase) => { - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = connectedDatabase || + sqlite(databasePath, { + readonly: true + }); database.function("userFn_dateIntegerToString", dateIntegerToString); let sqlWhereClause = " where o.recordDelete_timeMillis is null"; const sqlParameters = []; @@ -21,9 +22,12 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => { } } if (filters.occupantName) { - const occupantNamePieces = filters.occupantName.toLowerCase().split(" "); + const occupantNamePieces = filters.occupantName + .toLowerCase() + .split(" "); for (const occupantNamePiece of occupantNamePieces) { - sqlWhereClause += " and o.lotOccupancyId in (select oo.lotOccupancyId from LotOccupancyOccupants oo where oo.recordDelete_timeMillis is null and instr(lower(oo.occupantName), ?))"; + sqlWhereClause += + " and o.lotOccupancyId in (select oo.lotOccupancyId from LotOccupancyOccupants oo where oo.recordDelete_timeMillis is null and instr(lower(oo.occupantName), ?))"; sqlParameters.push(occupantNamePiece); } } @@ -35,7 +39,8 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => { const currentDateString = dateToInteger(new Date()); switch (filters.occupancyTime) { case "current": - sqlWhereClause += " and o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)"; + sqlWhereClause += + " and o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)"; sqlParameters.push(currentDateString, currentDateString); break; case "past": @@ -61,15 +66,16 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => { sqlParameters.push(filters.lotTypeId); } if (filters.workOrderId) { - sqlWhereClause += " and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)"; + sqlWhereClause += + " and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)"; sqlParameters.push(filters.workOrderId); } - const count = database.prepare("select count(*) as recordCount" + + const count = database + .prepare("select count(*) as recordCount" + " from LotOccupancies o" + " left join Lots l on o.lotId = l.lotId" + sqlWhereClause) - .get(sqlParameters) - .recordCount; + .get(sqlParameters).recordCount; let lotOccupancies = []; if (count > 0) { lotOccupancies = database @@ -85,9 +91,12 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => { " left join Maps m on l.mapId = m.mapId" + sqlWhereClause + " order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId" + - (options.limit !== -1 ? - " limit " + options.limit + " offset " + options.offset : - "")) + (options.limit !== -1 + ? " limit " + + options.limit + + " offset " + + options.offset + : "")) .all(sqlParameters); if (options.includeOccupants) { for (const lotOccupancy of lotOccupancies) { diff --git a/helpers/lotOccupancyDB/getLotOccupancies.ts b/helpers/lotOccupancyDB/getLotOccupancies.ts index c5b3a6f8..381564f0 100644 --- a/helpers/lotOccupancyDB/getLotOccupancies.ts +++ b/helpers/lotOccupancyDB/getLotOccupancies.ts @@ -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 { dateIntegerToString, @@ -10,43 +8,41 @@ import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js"; -import { - getLotOccupancyOccupants -} from "./getLotOccupancyOccupants.js"; +import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js"; import type * as recordTypes from "../../types/recordTypes"; - interface GetLotOccupanciesFilters { - lotId ? : number | string; - occupancyTime ? : "" | "past" | "current" | "future"; + lotId?: number | string; + occupancyTime?: "" | "past" | "current" | "future"; occupancyStartDateString?: string; - occupantName ? : string; - occupancyTypeId ? : number | string; - mapId ? : number | string; - lotName ? : string; - lotTypeId ? : number | string; + occupantName?: string; + occupancyTypeId?: number | string; + mapId?: number | string; + lotName?: string; + lotTypeId?: number | string; workOrderId?: number | string; } - interface GetLotOccupanciesOptions { limit: -1 | number; offset: number; includeOccupants: boolean; } - -export const getLotOccupancies = (filters: GetLotOccupanciesFilters, +export const getLotOccupancies = ( + filters: GetLotOccupanciesFilters, options: GetLotOccupanciesOptions, - connectedDatabase ? : sqlite.Database): { + connectedDatabase?: sqlite.Database +): { count: number; lotOccupancies: recordTypes.LotOccupancy[]; } => { - - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = + connectedDatabase || + sqlite(databasePath, { + readonly: true + }); database.function("userFn_dateIntegerToString", dateIntegerToString); @@ -67,9 +63,12 @@ export const getLotOccupancies = (filters: GetLotOccupanciesFilters, } if (filters.occupantName) { - const occupantNamePieces = filters.occupantName.toLowerCase().split(" "); + const occupantNamePieces = filters.occupantName + .toLowerCase() + .split(" "); for (const occupantNamePiece of occupantNamePieces) { - sqlWhereClause += " and o.lotOccupancyId in (select oo.lotOccupancyId from LotOccupancyOccupants oo where oo.recordDelete_timeMillis is null and instr(lower(oo.occupantName), ?))"; + sqlWhereClause += + " and o.lotOccupancyId in (select oo.lotOccupancyId from LotOccupancyOccupants oo where oo.recordDelete_timeMillis is null and instr(lower(oo.occupantName), ?))"; sqlParameters.push(occupantNamePiece); } } @@ -80,13 +79,12 @@ export const getLotOccupancies = (filters: GetLotOccupanciesFilters, } if (filters.occupancyTime) { - const currentDateString = dateToInteger(new Date()); switch (filters.occupancyTime) { - case "current": - sqlWhereClause += " and o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)"; + sqlWhereClause += + " and o.occupancyStartDate <= ? and (o.occupancyEndDate is null or o.occupancyEndDate >= ?)"; sqlParameters.push(currentDateString, currentDateString); break; @@ -99,13 +97,14 @@ export const getLotOccupancies = (filters: GetLotOccupanciesFilters, sqlWhereClause += " and o.occupancyStartDate > ?"; sqlParameters.push(currentDateString); break; - } } if (filters.occupancyStartDateString) { sqlWhereClause += " and o.occupancyStartDate = ?"; - sqlParameters.push(dateStringToInteger(filters.occupancyStartDateString)); + sqlParameters.push( + dateStringToInteger(filters.occupancyStartDateString) + ); } if (filters.mapId) { @@ -119,42 +118,52 @@ export const getLotOccupancies = (filters: GetLotOccupanciesFilters, } if (filters.workOrderId) { - sqlWhereClause += " and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)"; + sqlWhereClause += + " and o.lotOccupancyId in (select lotOccupancyId from WorkOrderLotOccupancies where recordDelete_timeMillis is null and workOrderId = ?)"; sqlParameters.push(filters.workOrderId); } - const count: number = database.prepare("select count(*) as recordCount" + - " from LotOccupancies o" + - " left join Lots l on o.lotId = l.lotId" + - sqlWhereClause) - .get(sqlParameters) - .recordCount; + const count: number = database + .prepare( + "select count(*) as recordCount" + + " from LotOccupancies o" + + " left join Lots l on o.lotId = l.lotId" + + sqlWhereClause + ) + .get(sqlParameters).recordCount; let lotOccupancies: recordTypes.LotOccupancy[] = []; if (count > 0) { - lotOccupancies = database - .prepare("select o.lotOccupancyId," + - " o.occupancyTypeId, t.occupancyType," + - " o.lotId, l.lotName," + - " l.mapId, m.mapName," + - " o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString," + - " o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString" + - " from LotOccupancies o" + - " left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId" + - " left join Lots l on o.lotId = l.lotId" + - " left join Maps m on l.mapId = m.mapId" + - sqlWhereClause + - " order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId" + - (options.limit !== -1 ? - " limit " + options.limit + " offset " + options.offset : - "")) + .prepare( + "select o.lotOccupancyId," + + " o.occupancyTypeId, t.occupancyType," + + " o.lotId, l.lotName," + + " l.mapId, m.mapName," + + " o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString," + + " o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString" + + " from LotOccupancies o" + + " left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId" + + " left join Lots l on o.lotId = l.lotId" + + " left join Maps m on l.mapId = m.mapId" + + sqlWhereClause + + " order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId" + + (options.limit !== -1 + ? " limit " + + options.limit + + " offset " + + options.offset + : "") + ) .all(sqlParameters); if (options.includeOccupants) { for (const lotOccupancy of lotOccupancies) { - lotOccupancy.lotOccupancyOccupants = getLotOccupancyOccupants(lotOccupancy.lotOccupancyId, database); + lotOccupancy.lotOccupancyOccupants = getLotOccupancyOccupants( + lotOccupancy.lotOccupancyId, + database + ); } } } @@ -169,5 +178,4 @@ export const getLotOccupancies = (filters: GetLotOccupanciesFilters, }; }; - -export default getLotOccupancies; \ No newline at end of file +export default getLotOccupancies; diff --git a/helpers/lotOccupancyDB/getLotOccupancy.ts b/helpers/lotOccupancyDB/getLotOccupancy.ts index b70649b0..c1ca4feb 100644 --- a/helpers/lotOccupancyDB/getLotOccupancy.ts +++ b/helpers/lotOccupancyDB/getLotOccupancy.ts @@ -1,38 +1,24 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - dateIntegerToString -} from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import { dateIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; -import { - getLotOccupancyOccupants -} from "./getLotOccupancyOccupants.js"; +import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js"; -import { - getLotOccupancyComments -} from "./getLotOccupancyComments.js"; +import { getLotOccupancyComments } from "./getLotOccupancyComments.js"; -import { - getLotOccupancyFields -} from "./getLotOccupancyFields.js"; +import { getLotOccupancyFields } from "./getLotOccupancyFields.js"; -import { - getLotOccupancyFees -} from "./getLotOccupancyFees.js"; +import { getLotOccupancyFees } from "./getLotOccupancyFees.js"; -import { - getLotOccupancyTransactions -} from "./getLotOccupancyTransactions.js"; +import { getLotOccupancyTransactions } from "./getLotOccupancyTransactions.js"; import type * as recordTypes from "../../types/recordTypes"; - -export const getLotOccupancy = (lotOccupancyId: number | string): recordTypes.LotOccupancy => { - +export const getLotOccupancy = ( + lotOccupancyId: number | string +): recordTypes.LotOccupancy => { const database = sqlite(databasePath, { readonly: true }); @@ -40,34 +26,48 @@ export const getLotOccupancy = (lotOccupancyId: number | string): recordTypes.Lo database.function("userFn_dateIntegerToString", dateIntegerToString); const lotOccupancy: recordTypes.LotOccupancy = database - .prepare("select o.lotOccupancyId," + - " o.occupancyTypeId, t.occupancyType," + - " o.lotId, l.lotName, l.lotTypeId," + - " l.mapId, m.mapName," + - " o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString," + - " o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString" + - " from LotOccupancies o" + - " left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId" + - " left join Lots l on o.lotId = l.lotId" + - " left join Maps m on l.mapId = m.mapId" + - " where o.recordDelete_timeMillis is null" + - " and o.lotOccupancyId = ?" + .prepare( + "select o.lotOccupancyId," + + " o.occupancyTypeId, t.occupancyType," + + " o.lotId, l.lotName, l.lotTypeId," + + " l.mapId, m.mapName," + + " o.occupancyStartDate, userFn_dateIntegerToString(o.occupancyStartDate) as occupancyStartDateString," + + " o.occupancyEndDate, userFn_dateIntegerToString(o.occupancyEndDate) as occupancyEndDateString" + + " from LotOccupancies o" + + " left join OccupancyTypes t on o.occupancyTypeId = t.occupancyTypeId" + + " left join Lots l on o.lotId = l.lotId" + + " left join Maps m on l.mapId = m.mapId" + + " where o.recordDelete_timeMillis is null" + + " and o.lotOccupancyId = ?" ) .get(lotOccupancyId); if (lotOccupancy) { - lotOccupancy.lotOccupancyFields = getLotOccupancyFields(lotOccupancyId, database); - lotOccupancy.lotOccupancyOccupants = getLotOccupancyOccupants(lotOccupancyId, database); - lotOccupancy.lotOccupancyComments = getLotOccupancyComments(lotOccupancyId, database); - lotOccupancy.lotOccupancyFees = getLotOccupancyFees(lotOccupancyId, database); - lotOccupancy.lotOccupancyTransactions = getLotOccupancyTransactions(lotOccupancyId, database); + lotOccupancy.lotOccupancyFields = getLotOccupancyFields( + lotOccupancyId, + database + ); + lotOccupancy.lotOccupancyOccupants = getLotOccupancyOccupants( + lotOccupancyId, + database + ); + lotOccupancy.lotOccupancyComments = getLotOccupancyComments( + lotOccupancyId, + database + ); + lotOccupancy.lotOccupancyFees = getLotOccupancyFees( + lotOccupancyId, + database + ); + lotOccupancy.lotOccupancyTransactions = getLotOccupancyTransactions( + lotOccupancyId, + database + ); } database.close(); - return lotOccupancy; }; - -export default getLotOccupancy; \ No newline at end of file +export default getLotOccupancy; diff --git a/helpers/lotOccupancyDB/getLotOccupancyComments.js b/helpers/lotOccupancyDB/getLotOccupancyComments.js index ae729f89..9033b5b6 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyComments.js +++ b/helpers/lotOccupancyDB/getLotOccupancyComments.js @@ -2,9 +2,10 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { dateIntegerToString, timeIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; export const getLotOccupancyComments = (lotOccupancyId, connectedDatabase) => { - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = connectedDatabase || + sqlite(databasePath, { + readonly: true + }); database.function("userFn_dateIntegerToString", dateIntegerToString); database.function("userFn_timeIntegerToString", timeIntegerToString); const lotComments = database diff --git a/helpers/lotOccupancyDB/getLotOccupancyComments.ts b/helpers/lotOccupancyDB/getLotOccupancyComments.ts index 5c723091..be4a3984 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyComments.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyComments.ts @@ -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 { dateIntegerToString, @@ -11,26 +9,31 @@ import { import type * as recordTypes from "../../types/recordTypes"; - -export const getLotOccupancyComments = (lotOccupancyId: number | string, connectedDatabase ? : sqlite.Database): recordTypes.LotOccupancyComment[] => { - - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); +export const getLotOccupancyComments = ( + lotOccupancyId: number | string, + connectedDatabase?: sqlite.Database +): recordTypes.LotOccupancyComment[] => { + const database = + connectedDatabase || + sqlite(databasePath, { + readonly: true + }); database.function("userFn_dateIntegerToString", dateIntegerToString); database.function("userFn_timeIntegerToString", timeIntegerToString); const lotComments = database - .prepare("select lotOccupancyCommentId," + - " lotOccupancyCommentDate, userFn_dateIntegerToString(lotOccupancyCommentDate) as lotOccupancyCommentDateString," + - " lotOccupancyCommentTime, userFn_timeIntegerToString(lotOccupancyCommentTime) as lotOccupancyCommentTimeString," + - " lotOccupancyComment," + - " recordCreate_userName, recordUpdate_userName" + - " from LotOccupancyComments" + - " where recordDelete_timeMillis is null" + - " and lotOccupancyId = ?" + - " order by lotOccupancyCommentDate desc, lotOccupancyCommentTime desc, lotOccupancyCommentId desc") + .prepare( + "select lotOccupancyCommentId," + + " lotOccupancyCommentDate, userFn_dateIntegerToString(lotOccupancyCommentDate) as lotOccupancyCommentDateString," + + " lotOccupancyCommentTime, userFn_timeIntegerToString(lotOccupancyCommentTime) as lotOccupancyCommentTimeString," + + " lotOccupancyComment," + + " recordCreate_userName, recordUpdate_userName" + + " from LotOccupancyComments" + + " where recordDelete_timeMillis is null" + + " and lotOccupancyId = ?" + + " order by lotOccupancyCommentDate desc, lotOccupancyCommentTime desc, lotOccupancyCommentId desc" + ) .all(lotOccupancyId); if (!connectedDatabase) { @@ -40,5 +43,4 @@ export const getLotOccupancyComments = (lotOccupancyId: number | string, connect return lotComments; }; - -export default getLotOccupancyComments; \ No newline at end of file +export default getLotOccupancyComments; diff --git a/helpers/lotOccupancyDB/getLotOccupancyFees.js b/helpers/lotOccupancyDB/getLotOccupancyFees.js index 4fd75597..edbb388c 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFees.js +++ b/helpers/lotOccupancyDB/getLotOccupancyFees.js @@ -1,9 +1,10 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; export const getLotOccupancyFees = (lotOccupancyId, connectedDatabase) => { - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = connectedDatabase || + sqlite(databasePath, { + readonly: true + }); const lotOccupancyFees = database .prepare("select o.lotOccupancyId," + " o.feeId, c.feeCategory, f.feeName, f.includeQuantity," + diff --git a/helpers/lotOccupancyDB/getLotOccupancyFees.ts b/helpers/lotOccupancyDB/getLotOccupancyFees.ts index 697de005..ad13945c 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFees.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyFees.ts @@ -1,30 +1,32 @@ 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"; - -export const getLotOccupancyFees = (lotOccupancyId: number | string, - connectedDatabase ? : sqlite.Database): recordTypes.LotOccupancyFee[] => { - - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); +export const getLotOccupancyFees = ( + lotOccupancyId: number | string, + connectedDatabase?: sqlite.Database +): recordTypes.LotOccupancyFee[] => { + const database = + connectedDatabase || + sqlite(databasePath, { + readonly: true + }); const lotOccupancyFees: recordTypes.LotOccupancyFee[] = database - .prepare("select o.lotOccupancyId," + - " o.feeId, c.feeCategory, f.feeName, f.includeQuantity," + - " o.feeAmount, o.taxAmount, o.quantity" + - " from LotOccupancyFees o" + - " left join Fees f on o.feeId = f.feeId" + - " left join FeeCategories c on f.feeCategoryId = c.feeCategoryId" + - " where o.recordDelete_timeMillis is null" + - " and o.lotOccupancyId = ?" + - " order by o.recordCreate_timeMillis") - .all(lotOccupancyId); + .prepare( + "select o.lotOccupancyId," + + " o.feeId, c.feeCategory, f.feeName, f.includeQuantity," + + " o.feeAmount, o.taxAmount, o.quantity" + + " from LotOccupancyFees o" + + " left join Fees f on o.feeId = f.feeId" + + " left join FeeCategories c on f.feeCategoryId = c.feeCategoryId" + + " where o.recordDelete_timeMillis is null" + + " and o.lotOccupancyId = ?" + + " order by o.recordCreate_timeMillis" + ) + .all(lotOccupancyId); if (!connectedDatabase) { database.close(); @@ -33,5 +35,4 @@ export const getLotOccupancyFees = (lotOccupancyId: number | string, return lotOccupancyFees; }; - -export default getLotOccupancyFees; \ No newline at end of file +export default getLotOccupancyFees; diff --git a/helpers/lotOccupancyDB/getLotOccupancyFields.js b/helpers/lotOccupancyDB/getLotOccupancyFields.js index 835d0dbe..30c635f7 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFields.js +++ b/helpers/lotOccupancyDB/getLotOccupancyFields.js @@ -1,9 +1,10 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; export const getLotOccupancyFields = (lotOccupancyId, connectedDatabase) => { - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = connectedDatabase || + sqlite(databasePath, { + readonly: true + }); const lotOccupancyFields = database .prepare("select o.lotOccupancyId," + " o.occupancyTypeFieldId, o.lotOccupancyFieldValue," + diff --git a/helpers/lotOccupancyDB/getLotOccupancyFields.ts b/helpers/lotOccupancyDB/getLotOccupancyFields.ts index 7c470fab..92785166 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyFields.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyFields.ts @@ -1,41 +1,43 @@ 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"; - -export const getLotOccupancyFields = (lotOccupancyId: number | string, - connectedDatabase ? : sqlite.Database): recordTypes.LotOccupancyField[] => { - - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); +export const getLotOccupancyFields = ( + lotOccupancyId: number | string, + connectedDatabase?: sqlite.Database +): recordTypes.LotOccupancyField[] => { + const database = + connectedDatabase || + sqlite(databasePath, { + readonly: true + }); const lotOccupancyFields: recordTypes.LotOccupancyField[] = database - .prepare("select o.lotOccupancyId," + - " o.occupancyTypeFieldId, o.lotOccupancyFieldValue," + - " f.occupancyTypeField," + - " f.occupancyTypeFieldValues, f.isRequired, f.pattern, f.minimumLength, f.maximumLength," + - " f.orderNumber" + - " from LotOccupancyFields o" + - " left join OccupancyTypeFields f on o.occupancyTypeFieldId = f.occupancyTypeFieldId" + - " where o.recordDelete_timeMillis is null" + - " and o.lotOccupancyId = ?" + - " union" + - " select ? as lotOccupancyId," + - " f.occupancyTypeFieldId, '' as lotOccupancyFieldValue," + - " f.occupancyTypeField," + - " f.occupancyTypeFieldValues, f.isRequired, f.pattern, f.minimumLength, f.maximumLength," + - " f.orderNumber" + - " from OccupancyTypeFields f" + - " where f.recordDelete_timeMillis is null" + - " and f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)" + - " and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null)" + - " order by orderNumber, occupancyTypeField") - .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId); + .prepare( + "select o.lotOccupancyId," + + " o.occupancyTypeFieldId, o.lotOccupancyFieldValue," + + " f.occupancyTypeField," + + " f.occupancyTypeFieldValues, f.isRequired, f.pattern, f.minimumLength, f.maximumLength," + + " f.orderNumber" + + " from LotOccupancyFields o" + + " left join OccupancyTypeFields f on o.occupancyTypeFieldId = f.occupancyTypeFieldId" + + " where o.recordDelete_timeMillis is null" + + " and o.lotOccupancyId = ?" + + " union" + + " select ? as lotOccupancyId," + + " f.occupancyTypeFieldId, '' as lotOccupancyFieldValue," + + " f.occupancyTypeField," + + " f.occupancyTypeFieldValues, f.isRequired, f.pattern, f.minimumLength, f.maximumLength," + + " f.orderNumber" + + " from OccupancyTypeFields f" + + " where f.recordDelete_timeMillis is null" + + " and f.occupancyTypeId in (select occupancyTypeId from LotOccupancies where lotOccupancyId = ?)" + + " and f.occupancyTypeFieldId not in (select occupancyTypeFieldId from LotOccupancyFields where lotOccupancyId = ? and recordDelete_timeMillis is null)" + + " order by orderNumber, occupancyTypeField" + ) + .all(lotOccupancyId, lotOccupancyId, lotOccupancyId, lotOccupancyId); if (!connectedDatabase) { database.close(); @@ -44,5 +46,4 @@ export const getLotOccupancyFields = (lotOccupancyId: number | string, return lotOccupancyFields; }; - -export default getLotOccupancyFields; \ No newline at end of file +export default getLotOccupancyFields; diff --git a/helpers/lotOccupancyDB/getLotOccupancyOccupants.js b/helpers/lotOccupancyDB/getLotOccupancyOccupants.js index 173b956b..015900c5 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyOccupants.js +++ b/helpers/lotOccupancyDB/getLotOccupancyOccupants.js @@ -1,9 +1,10 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; export const getLotOccupancyOccupants = (lotOccupancyId, connectedDatabase) => { - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = connectedDatabase || + sqlite(databasePath, { + readonly: true + }); const lotOccupancyOccupants = database .prepare("select o.lotOccupancyId, o.lotOccupantIndex," + " o.occupantName, o.occupantAddress1, o.occupantAddress2," + diff --git a/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts b/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts index 1b7bce69..1b440a98 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyOccupants.ts @@ -1,21 +1,22 @@ 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"; - -export const getLotOccupancyOccupants = (lotOccupancyId: number | string, - connectedDatabase ? : sqlite.Database): recordTypes.LotOccupancyOccupant[] => { - - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); +export const getLotOccupancyOccupants = ( + lotOccupancyId: number | string, + connectedDatabase?: sqlite.Database +): recordTypes.LotOccupancyOccupant[] => { + const database = + connectedDatabase || + sqlite(databasePath, { + readonly: true + }); const lotOccupancyOccupants: recordTypes.LotOccupancyOccupant[] = database - .prepare("select o.lotOccupancyId, o.lotOccupantIndex," + + .prepare( + "select o.lotOccupancyId, o.lotOccupantIndex," + " o.occupantName, o.occupantAddress1, o.occupantAddress2," + " o.occupantCity, o.occupantProvince, o.occupantPostalCode, o.occupantPhoneNumber," + " o.lotOccupantTypeId, t.lotOccupantType" + @@ -23,8 +24,9 @@ export const getLotOccupancyOccupants = (lotOccupancyId: number | string, " left join LotOccupantTypes t on o.lotOccupantTypeId = t.lotOccupantTypeId" + " where o.recordDelete_timeMillis is null" + " and o.lotOccupancyId = ?" + - " order by t.orderNumber, t.lotOccupantType, o.occupantName, o.lotOccupantIndex") - .all(lotOccupancyId); + " order by t.orderNumber, t.lotOccupantType, o.occupantName, o.lotOccupantIndex" + ) + .all(lotOccupancyId); if (!connectedDatabase) { database.close(); @@ -33,5 +35,4 @@ export const getLotOccupancyOccupants = (lotOccupancyId: number | string, return lotOccupancyOccupants; }; - -export default getLotOccupancyOccupants; \ No newline at end of file +export default getLotOccupancyOccupants; diff --git a/helpers/lotOccupancyDB/getLotOccupancyTransactions.js b/helpers/lotOccupancyDB/getLotOccupancyTransactions.js index f238d326..56452161 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyTransactions.js +++ b/helpers/lotOccupancyDB/getLotOccupancyTransactions.js @@ -2,9 +2,10 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { dateIntegerToString, timeIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; export const getLotOccupancyTransactions = (lotOccupancyId, connectedDatabase) => { - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = connectedDatabase || + sqlite(databasePath, { + readonly: true + }); database.function("userFn_dateIntegerToString", dateIntegerToString); database.function("userFn_timeIntegerToString", timeIntegerToString); const lotOccupancyTransactions = database diff --git a/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts b/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts index aa9d5202..b33f0d3e 100644 --- a/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts +++ b/helpers/lotOccupancyDB/getLotOccupancyTransactions.ts @@ -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 { dateIntegerToString, @@ -11,27 +9,32 @@ import { import type * as recordTypes from "../../types/recordTypes"; - -export const getLotOccupancyTransactions = (lotOccupancyId: number | string, - connectedDatabase ? : sqlite.Database): recordTypes.LotOccupancyTransaction[] => { - - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); +export const getLotOccupancyTransactions = ( + lotOccupancyId: number | string, + connectedDatabase?: sqlite.Database +): recordTypes.LotOccupancyTransaction[] => { + const database = + connectedDatabase || + sqlite(databasePath, { + readonly: true + }); database.function("userFn_dateIntegerToString", dateIntegerToString); database.function("userFn_timeIntegerToString", timeIntegerToString); - const lotOccupancyTransactions: recordTypes.LotOccupancyTransaction[] = database - .prepare("select lotOccupancyId, transactionIndex," + - " transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString," + - " transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString," + - " transactionAmount, externalReceiptNumber, transactionNote" + - " from LotOccupancyTransactions" + - " where recordDelete_timeMillis is null" + - " and lotOccupancyId = ?" + - " order by transactionDate, transactionTime, transactionIndex") - .all(lotOccupancyId); + const lotOccupancyTransactions: recordTypes.LotOccupancyTransaction[] = + database + .prepare( + "select lotOccupancyId, transactionIndex," + + " transactionDate, userFn_dateIntegerToString(transactionDate) as transactionDateString," + + " transactionTime, userFn_timeIntegerToString(transactionTime) as transactionTimeString," + + " transactionAmount, externalReceiptNumber, transactionNote" + + " from LotOccupancyTransactions" + + " where recordDelete_timeMillis is null" + + " and lotOccupancyId = ?" + + " order by transactionDate, transactionTime, transactionIndex" + ) + .all(lotOccupancyId); if (!connectedDatabase) { database.close(); @@ -40,5 +43,4 @@ export const getLotOccupancyTransactions = (lotOccupancyId: number | string, return lotOccupancyTransactions; }; - -export default getLotOccupancyTransactions; \ No newline at end of file +export default getLotOccupancyTransactions; diff --git a/helpers/lotOccupancyDB/getLotOccupantTypes.js b/helpers/lotOccupancyDB/getLotOccupantTypes.js index 0989e69d..47e9ee7a 100644 --- a/helpers/lotOccupancyDB/getLotOccupantTypes.js +++ b/helpers/lotOccupancyDB/getLotOccupantTypes.js @@ -11,7 +11,8 @@ export const getLotOccupantTypes = () => { let expectedOrderNumber = 0; for (const lotOccupantType of lotOccupantTypes) { if (lotOccupantType.orderNumber !== expectedOrderNumber) { - database.prepare("update LotOccupantTypes" + + database + .prepare("update LotOccupantTypes" + " set orderNumber = ?" + " where lotOccupantTypeId = ?") .run(expectedOrderNumber, lotOccupantType.lotOccupantTypeId); diff --git a/helpers/lotOccupancyDB/getLotOccupantTypes.ts b/helpers/lotOccupancyDB/getLotOccupantTypes.ts index 2dd45341..9c506c1d 100644 --- a/helpers/lotOccupancyDB/getLotOccupantTypes.ts +++ b/helpers/lotOccupancyDB/getLotOccupantTypes.ts @@ -1,34 +1,32 @@ 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"; - export const getLotOccupantTypes = (): recordTypes.LotOccupantType[] => { - const database = sqlite(databasePath); const lotOccupantTypes: recordTypes.LotOccupantType[] = database - .prepare("select lotOccupantTypeId, lotOccupantType" + - " from LotOccupantTypes" + - " where recordDelete_timeMillis is null" + - " order by orderNumber, lotOccupantType") + .prepare( + "select lotOccupantTypeId, lotOccupantType" + + " from LotOccupantTypes" + + " where recordDelete_timeMillis is null" + + " order by orderNumber, lotOccupantType" + ) .all(); let expectedOrderNumber = 0; for (const lotOccupantType of lotOccupantTypes) { - if (lotOccupantType.orderNumber !== expectedOrderNumber) { - - database.prepare("update LotOccupantTypes" + - " set orderNumber = ?" + - " where lotOccupantTypeId = ?") - .run(expectedOrderNumber, - lotOccupantType.lotOccupantTypeId); + database + .prepare( + "update LotOccupantTypes" + + " set orderNumber = ?" + + " where lotOccupantTypeId = ?" + ) + .run(expectedOrderNumber, lotOccupantType.lotOccupantTypeId); lotOccupantType.orderNumber = expectedOrderNumber; } @@ -41,5 +39,4 @@ export const getLotOccupantTypes = (): recordTypes.LotOccupantType[] => { return lotOccupantTypes; }; - -export default getLotOccupantTypes; \ No newline at end of file +export default getLotOccupantTypes; diff --git a/helpers/lotOccupancyDB/getLotStatuses.js b/helpers/lotOccupancyDB/getLotStatuses.js index 116ec381..0a754c9b 100644 --- a/helpers/lotOccupancyDB/getLotStatuses.js +++ b/helpers/lotOccupancyDB/getLotStatuses.js @@ -11,7 +11,8 @@ export const getLotStatuses = () => { let expectedOrderNumber = 0; for (const lotStatus of lotStatuses) { if (lotStatus.orderNumber !== expectedOrderNumber) { - database.prepare("update LotStatuses" + + database + .prepare("update LotStatuses" + " set orderNumber = ?" + " where lotStatusId = ?") .run(expectedOrderNumber, lotStatus.lotStatusId); diff --git a/helpers/lotOccupancyDB/getLotStatuses.ts b/helpers/lotOccupancyDB/getLotStatuses.ts index 46b7ca80..391a41e6 100644 --- a/helpers/lotOccupancyDB/getLotStatuses.ts +++ b/helpers/lotOccupancyDB/getLotStatuses.ts @@ -1,34 +1,32 @@ 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"; - export const getLotStatuses = (): recordTypes.LotStatus[] => { - const database = sqlite(databasePath); const lotStatuses: recordTypes.LotStatus[] = database - .prepare("select lotStatusId, lotStatus" + - " from LotStatuses" + - " where recordDelete_timeMillis is null" + - " order by orderNumber, lotStatus") + .prepare( + "select lotStatusId, lotStatus" + + " from LotStatuses" + + " where recordDelete_timeMillis is null" + + " order by orderNumber, lotStatus" + ) .all(); let expectedOrderNumber = 0; for (const lotStatus of lotStatuses) { - if (lotStatus.orderNumber !== expectedOrderNumber) { - - database.prepare("update LotStatuses" + - " set orderNumber = ?" + - " where lotStatusId = ?") - .run(expectedOrderNumber, - lotStatus.lotStatusId); + database + .prepare( + "update LotStatuses" + + " set orderNumber = ?" + + " where lotStatusId = ?" + ) + .run(expectedOrderNumber, lotStatus.lotStatusId); lotStatus.orderNumber = expectedOrderNumber; } @@ -41,5 +39,4 @@ export const getLotStatuses = (): recordTypes.LotStatus[] => { return lotStatuses; }; - -export default getLotStatuses; \ No newline at end of file +export default getLotStatuses; diff --git a/helpers/lotOccupancyDB/getLotTypes.ts b/helpers/lotOccupancyDB/getLotTypes.ts index 6a95e426..50a809a8 100644 --- a/helpers/lotOccupancyDB/getLotTypes.ts +++ b/helpers/lotOccupancyDB/getLotTypes.ts @@ -1,23 +1,21 @@ 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"; - export const getLotTypes = (): recordTypes.LotType[] => { - const database = sqlite(databasePath, { readonly: true }); const lotTypes: recordTypes.LotType[] = database - .prepare("select lotTypeId, lotType" + - " from LotTypes" + - " where recordDelete_timeMillis is null" + - " order by orderNumber, lotType") + .prepare( + "select lotTypeId, lotType" + + " from LotTypes" + + " where recordDelete_timeMillis is null" + + " order by orderNumber, lotType" + ) .all(); database.close(); @@ -25,5 +23,4 @@ export const getLotTypes = (): recordTypes.LotType[] => { return lotTypes; }; - -export default getLotTypes; \ No newline at end of file +export default getLotTypes; diff --git a/helpers/lotOccupancyDB/getLots.js b/helpers/lotOccupancyDB/getLots.js index 1ea88ae2..cab95d50 100644 --- a/helpers/lotOccupancyDB/getLots.js +++ b/helpers/lotOccupancyDB/getLots.js @@ -3,9 +3,10 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js"; import * as configFunctions from "../functions.config.js"; export const getLots = (filters, options, connectedDatabase) => { - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = connectedDatabase || + sqlite(databasePath, { + readonly: true + }); let sqlWhereClause = " where l.recordDelete_timeMillis is null"; const sqlParameters = []; if (filters.lotName) { @@ -32,27 +33,32 @@ export const getLots = (filters, options, connectedDatabase) => { sqlWhereClause += " and lotOccupancyCount > 0"; } else if (filters.occupancyStatus === "unoccupied") { - sqlWhereClause += " and (lotOccupancyCount is null or lotOccupancyCount = 0)"; + sqlWhereClause += + " and (lotOccupancyCount is null or lotOccupancyCount = 0)"; } } if (filters.workOrderId) { - sqlWhereClause += " and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)"; + sqlWhereClause += + " and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)"; sqlParameters.push(filters.workOrderId); } const currentDate = dateToInteger(new Date()); - const count = database.prepare("select count(*) as recordCount" + + const count = database + .prepare("select count(*) as recordCount" + " from Lots l" + (" left join (" + "select lotId, count(lotOccupancyId) as lotOccupancyCount" + " from LotOccupancies" + " where recordDelete_timeMillis is null" + - " and occupancyStartDate <= " + currentDate + - " and (occupancyEndDate is null or occupancyEndDate >= " + currentDate + ")" + + " and occupancyStartDate <= " + + currentDate + + " and (occupancyEndDate is null or occupancyEndDate >= " + + currentDate + + ")" + " group by lotId" + ") o on l.lotId = o.lotId") + sqlWhereClause) - .get(sqlParameters) - .recordCount; + .get(sqlParameters).recordCount; let lots = []; if (count > 0) { database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction")); @@ -70,15 +76,21 @@ export const getLots = (filters, options, connectedDatabase) => { "select lotId, count(lotOccupancyId) as lotOccupancyCount" + " from LotOccupancies" + " where recordDelete_timeMillis is null" + - " and occupancyStartDate <= " + currentDate + - " and (occupancyEndDate is null or occupancyEndDate >= " + currentDate + ")" + + " and occupancyStartDate <= " + + currentDate + + " and (occupancyEndDate is null or occupancyEndDate >= " + + currentDate + + ")" + " group by lotId" + ") o on l.lotId = o.lotId") + sqlWhereClause + " order by userFn_lotNameSortName(l.lotName), l.lotId" + - (options ? - " limit " + options.limit + " offset " + options.offset : - "")) + (options + ? " limit " + + options.limit + + " offset " + + options.offset + : "")) .all(sqlParameters); } if (!connectedDatabase) { diff --git a/helpers/lotOccupancyDB/getLots.ts b/helpers/lotOccupancyDB/getLots.ts index 736f6b08..ffa54d33 100644 --- a/helpers/lotOccupancyDB/getLots.ts +++ b/helpers/lotOccupancyDB/getLots.ts @@ -1,25 +1,20 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - dateToInteger -} from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js"; import * as configFunctions from "../functions.config.js"; import type * as recordTypes from "../../types/recordTypes"; - interface GetLotsFilters { - lotName ? : string; - mapId ? : number | string; - lotTypeId ? : number | string; - lotStatusId ? : number | string; - occupancyStatus ? : "" | "occupied" | "unoccupied"; - workOrderId ? : number | string; + lotName?: string; + mapId?: number | string; + lotTypeId?: number | string; + lotStatusId?: number | string; + occupancyStatus?: "" | "occupied" | "unoccupied"; + workOrderId?: number | string; } interface GetLotsOptions { @@ -27,17 +22,19 @@ interface GetLotsOptions { offset: number; } - -export const getLots = (filters: GetLotsFilters, +export const getLots = ( + filters: GetLotsFilters, options: GetLotsOptions, - connectedDatabase ? : sqlite.Database): { + connectedDatabase?: sqlite.Database +): { count: number; lots: recordTypes.Lot[]; } => { - - const database = connectedDatabase || sqlite(databasePath, { - readonly: true - }); + const database = + connectedDatabase || + sqlite(databasePath, { + readonly: true + }); let sqlWhereClause = " where l.recordDelete_timeMillis is null"; const sqlParameters = []; @@ -69,60 +66,77 @@ export const getLots = (filters: GetLotsFilters, if (filters.occupancyStatus === "occupied") { sqlWhereClause += " and lotOccupancyCount > 0"; } else if (filters.occupancyStatus === "unoccupied") { - sqlWhereClause += " and (lotOccupancyCount is null or lotOccupancyCount = 0)"; + sqlWhereClause += + " and (lotOccupancyCount is null or lotOccupancyCount = 0)"; } } if (filters.workOrderId) { - sqlWhereClause += " and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)"; + sqlWhereClause += + " and l.lotId in (select lotId from WorkOrderLots where recordDelete_timeMillis is null and workOrderId = ?)"; sqlParameters.push(filters.workOrderId); } const currentDate = dateToInteger(new Date()); - const count: number = database.prepare("select count(*) as recordCount" + - " from Lots l" + - (" left join (" + - "select lotId, count(lotOccupancyId) as lotOccupancyCount" + - " from LotOccupancies" + - " where recordDelete_timeMillis is null" + - " and occupancyStartDate <= " + currentDate + - " and (occupancyEndDate is null or occupancyEndDate >= " + currentDate + ")" + - " group by lotId" + - ") o on l.lotId = o.lotId") + - sqlWhereClause) - .get(sqlParameters) - .recordCount; - - let lots: recordTypes.Lot[] = []; - - if (count > 0) { - - database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction")); - - lots = database - .prepare("select l.lotId, l.lotName," + - " t.lotType," + - " l.mapId, m.mapName, l.mapKey," + - " s.lotStatus," + - " ifnull(o.lotOccupancyCount, 0) as lotOccupancyCount" + + const count: number = database + .prepare( + "select count(*) as recordCount" + " from Lots l" + - " left join LotTypes t on l.lotTypeId = t.lotTypeId" + - " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + - " left join Maps m on l.mapId = m.mapId" + (" left join (" + "select lotId, count(lotOccupancyId) as lotOccupancyCount" + " from LotOccupancies" + " where recordDelete_timeMillis is null" + - " and occupancyStartDate <= " + currentDate + - " and (occupancyEndDate is null or occupancyEndDate >= " + currentDate + ")" + + " and occupancyStartDate <= " + + currentDate + + " and (occupancyEndDate is null or occupancyEndDate >= " + + currentDate + + ")" + " group by lotId" + ") o on l.lotId = o.lotId") + - sqlWhereClause + - " order by userFn_lotNameSortName(l.lotName), l.lotId" + - (options ? - " limit " + options.limit + " offset " + options.offset : - "")) + sqlWhereClause + ) + .get(sqlParameters).recordCount; + + let lots: recordTypes.Lot[] = []; + + if (count > 0) { + database.function( + "userFn_lotNameSortName", + configFunctions.getProperty("settings.lot.lotNameSortNameFunction") + ); + + lots = database + .prepare( + "select l.lotId, l.lotName," + + " t.lotType," + + " l.mapId, m.mapName, l.mapKey," + + " s.lotStatus," + + " ifnull(o.lotOccupancyCount, 0) as lotOccupancyCount" + + " from Lots l" + + " left join LotTypes t on l.lotTypeId = t.lotTypeId" + + " left join LotStatuses s on l.lotStatusId = s.lotStatusId" + + " left join Maps m on l.mapId = m.mapId" + + (" left join (" + + "select lotId, count(lotOccupancyId) as lotOccupancyCount" + + " from LotOccupancies" + + " where recordDelete_timeMillis is null" + + " and occupancyStartDate <= " + + currentDate + + " and (occupancyEndDate is null or occupancyEndDate >= " + + currentDate + + ")" + + " group by lotId" + + ") o on l.lotId = o.lotId") + + sqlWhereClause + + " order by userFn_lotNameSortName(l.lotName), l.lotId" + + (options + ? " limit " + + options.limit + + " offset " + + options.offset + : "") + ) .all(sqlParameters); } @@ -136,5 +150,4 @@ export const getLots = (filters: GetLotsFilters, }; }; - -export default getLots; \ No newline at end of file +export default getLots; diff --git a/helpers/lotOccupancyDB/getMap.ts b/helpers/lotOccupancyDB/getMap.ts index fdf35fdd..0c6408e9 100644 --- a/helpers/lotOccupancyDB/getMap.ts +++ b/helpers/lotOccupancyDB/getMap.ts @@ -1,41 +1,38 @@ 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"; - export const getMap = (mapId: number | string): recordTypes.Map => { + const database = sqlite(databasePath, { + readonly: true + }); - const database = sqlite(databasePath, { - readonly: true - }); + const map: recordTypes.Map = database + .prepare( + "select m.mapId, m.mapName, m.mapDescription," + + " m.mapLatitude, m.mapLongitude, m.mapSVG," + + " m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, m.mapPhoneNumber," + + " m.recordCreate_userName, m.recordCreate_timeMillis," + + " m.recordUpdate_userName, m.recordUpdate_timeMillis," + + " m.recordDelete_userName, m.recordDelete_timeMillis," + + " count(l.lotId) as lotCount" + + " from Maps m" + + " left join Lots l on m.mapId = l.mapId and l.recordDelete_timeMillis is null" + + " where m.mapId = ?" + + " group by m.mapId, m.mapName, m.mapDescription," + + " m.mapLatitude, m.mapLongitude, m.mapSVG," + + " m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, m.mapPhoneNumber," + + " m.recordCreate_userName, m.recordCreate_timeMillis," + + " m.recordUpdate_userName, m.recordUpdate_timeMillis," + + " m.recordDelete_userName, m.recordDelete_timeMillis" + ) + .get(mapId); - const map: recordTypes.Map = database - .prepare("select m.mapId, m.mapName, m.mapDescription," + - " m.mapLatitude, m.mapLongitude, m.mapSVG," + - " m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, m.mapPhoneNumber," + - " m.recordCreate_userName, m.recordCreate_timeMillis," + - " m.recordUpdate_userName, m.recordUpdate_timeMillis," + - " m.recordDelete_userName, m.recordDelete_timeMillis," + - " count(l.lotId) as lotCount" + - " from Maps m" + - " left join Lots l on m.mapId = l.mapId and l.recordDelete_timeMillis is null" + - " where m.mapId = ?" + - " group by m.mapId, m.mapName, m.mapDescription," + - " m.mapLatitude, m.mapLongitude, m.mapSVG," + - " m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, m.mapPhoneNumber," + - " m.recordCreate_userName, m.recordCreate_timeMillis," + - " m.recordUpdate_userName, m.recordUpdate_timeMillis," + - " m.recordDelete_userName, m.recordDelete_timeMillis") - .get(mapId); + database.close(); - database.close(); - - return map; + return map; }; - -export default getMap; \ No newline at end of file +export default getMap; diff --git a/helpers/lotOccupancyDB/getMaps.ts b/helpers/lotOccupancyDB/getMaps.ts index 8382ede5..0d511bdc 100644 --- a/helpers/lotOccupancyDB/getMaps.ts +++ b/helpers/lotOccupancyDB/getMaps.ts @@ -1,36 +1,31 @@ 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 GetMapsFilters {} -interface GetMapsFilters { - -} - - -export const getMaps = (filters ? : GetMapsFilters): recordTypes.Map[] => { - +export const getMaps = (filters?: GetMapsFilters): recordTypes.Map[] => { const database = sqlite(databasePath, { readonly: true }); const maps: recordTypes.Map[] = database - .prepare("select m.mapId, m.mapName, m.mapDescription," + - " m.mapLatitude, m.mapLongitude, m.mapSVG," + - " m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, m.mapPhoneNumber," + - " ifnull(l.lotCount,0) as lotCount" + - " from Maps m" + - (" left join (" + - "select mapId, count(lotId) as lotCount" + - " from Lots" + - " where recordDelete_timeMillis is null" + - " group by mapId) l on m.mapId = l.mapId") + - " where m.recordDelete_timeMillis is null" + - " order by m.mapName, m.mapId") + .prepare( + "select m.mapId, m.mapName, m.mapDescription," + + " m.mapLatitude, m.mapLongitude, m.mapSVG," + + " m.mapAddress1, m.mapAddress2, m.mapCity, m.mapProvince, m.mapPostalCode, m.mapPhoneNumber," + + " ifnull(l.lotCount,0) as lotCount" + + " from Maps m" + + (" left join (" + + "select mapId, count(lotId) as lotCount" + + " from Lots" + + " where recordDelete_timeMillis is null" + + " group by mapId) l on m.mapId = l.mapId") + + " where m.recordDelete_timeMillis is null" + + " order by m.mapName, m.mapId" + ) .all(); database.close(); @@ -38,5 +33,4 @@ export const getMaps = (filters ? : GetMapsFilters): recordTypes.Map[] => { return maps; }; - -export default getMaps; \ No newline at end of file +export default getMaps; diff --git a/helpers/lotOccupancyDB/getNextLotId.ts b/helpers/lotOccupancyDB/getNextLotId.ts index 3f886ffb..0372070c 100644 --- a/helpers/lotOccupancyDB/getNextLotId.ts +++ b/helpers/lotOccupancyDB/getNextLotId.ts @@ -1,28 +1,29 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import * as configFunctions from "../functions.config.js"; - export const getNextLotId = (lotId: number | string): number => { - const database = sqlite(databasePath, { readonly: true }); - database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction")); + database.function( + "userFn_lotNameSortName", + configFunctions.getProperty("settings.lot.lotNameSortNameFunction") + ); const result: { - lotId: number - } = database - .prepare("select lotId from Lots" + - " where recordDelete_timeMillis is null" + - " and userFn_lotNameSortName(lotName) > (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" + - " order by userFn_lotNameSortName(lotName)" + - " limit 1") + lotId: number; + } = database + .prepare( + "select lotId from Lots" + + " where recordDelete_timeMillis is null" + + " and userFn_lotNameSortName(lotName) > (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" + + " order by userFn_lotNameSortName(lotName)" + + " limit 1" + ) .get(lotId); database.close(); @@ -34,5 +35,4 @@ export const getNextLotId = (lotId: number | string): number => { return undefined; }; - -export default getNextLotId; \ No newline at end of file +export default getNextLotId; diff --git a/helpers/lotOccupancyDB/getOccupancyType.d.ts b/helpers/lotOccupancyDB/getOccupancyType.d.ts deleted file mode 100644 index 3fc62095..00000000 --- a/helpers/lotOccupancyDB/getOccupancyType.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type * as recordTypes from "../../types/recordTypes"; -export declare const getOccupancyType: (occupancyTypeId: number | string) => recordTypes.OccupancyType; -export default getOccupancyType; diff --git a/helpers/lotOccupancyDB/getOccupancyType.js b/helpers/lotOccupancyDB/getOccupancyType.js deleted file mode 100644 index 74ed0ece..00000000 --- a/helpers/lotOccupancyDB/getOccupancyType.js +++ /dev/null @@ -1,22 +0,0 @@ -import sqlite from "better-sqlite3"; -import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -export const getOccupancyType = (occupancyTypeId) => { - const database = sqlite(databasePath, { - readonly: true - }); - const occupancyType = database - .prepare("select occupancyTypeId, occupancyType" + - " from OccupancyTypes" + - " where occupancyTypeId = ?") - .get(occupancyTypeId); - if (occupancyType) { - occupancyType.occupancyTypeFields = database.prepare("select * from OccupancyTypeFields" + - " where recordDelete_timeMillis is null" + - " and occupancyTypeId = ?" + - " order by orderNumber, occupancyTypeField") - .all(occupancyTypeId); - } - database.close(); - return occupancyType; -}; -export default getOccupancyType; diff --git a/helpers/lotOccupancyDB/getOccupancyType.ts b/helpers/lotOccupancyDB/getOccupancyType.ts deleted file mode 100644 index 494b4f03..00000000 --- a/helpers/lotOccupancyDB/getOccupancyType.ts +++ /dev/null @@ -1,37 +0,0 @@ -import sqlite from "better-sqlite3"; - -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; - -import type * as recordTypes from "../../types/recordTypes"; - - -export const getOccupancyType = (occupancyTypeId: number | string): recordTypes.OccupancyType => { - - const database = sqlite(databasePath, { - readonly: true - }); - - const occupancyType: recordTypes.OccupancyType = database - .prepare("select occupancyTypeId, occupancyType" + - " from OccupancyTypes" + - " where occupancyTypeId = ?") - .get(occupancyTypeId); - - if (occupancyType) { - - occupancyType.occupancyTypeFields = database.prepare("select * from OccupancyTypeFields" + - " where recordDelete_timeMillis is null" + - " and occupancyTypeId = ?" + - " order by orderNumber, occupancyTypeField") - .all(occupancyTypeId); - } - - database.close(); - - return occupancyType; -}; - - -export default getOccupancyType; \ No newline at end of file diff --git a/helpers/lotOccupancyDB/getOccupancyTypes.js b/helpers/lotOccupancyDB/getOccupancyTypes.js index 6579f780..7fd001ea 100644 --- a/helpers/lotOccupancyDB/getOccupancyTypes.js +++ b/helpers/lotOccupancyDB/getOccupancyTypes.js @@ -1,15 +1,47 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; export const getOccupancyTypes = () => { - const database = sqlite(databasePath, { - readonly: true - }); + const database = sqlite(databasePath); const occupancyTypes = database - .prepare("select occupancyTypeId, occupancyType" + + .prepare("select occupancyTypeId, occupancyType, orderNumber" + " from OccupancyTypes" + " where recordDelete_timeMillis is null" + " order by orderNumber, occupancyType") .all(); + let expectedTypeOrderNumber = -1; + for (const occupancyType of occupancyTypes) { + expectedTypeOrderNumber += 1; + if (occupancyType.orderNumber !== expectedTypeOrderNumber) { + database + .prepare("update OccupancyTypes" + + " set orderNumber = ?" + + " where occupancyTypeId = ?") + .run(expectedTypeOrderNumber, occupancyType.occupancyTypeId); + occupancyType.orderNumber = expectedTypeOrderNumber; + } + occupancyType.occupancyTypeFields = database + .prepare("select occupancyTypeFieldId," + + " occupancyTypeField, occupancyTypeFieldValues, isRequired, pattern," + + " minimumLength, maximumLength," + + " orderNumber" + + " from OccupancyTypeFields" + + " where recordDelete_timeMillis is null" + + " and occupancyTypeId = ?" + + " order by orderNumber, occupancyTypeField") + .all(occupancyType.occupancyTypeId); + let expectedFieldOrderNumber = -1; + for (const occupancyTypeField of occupancyType.occupancyTypeFields) { + expectedFieldOrderNumber += 1; + if (occupancyTypeField.orderNumber !== expectedFieldOrderNumber) { + database + .prepare("update OccupancyTypeFields" + + " set orderNumber = ?" + + " where occupancyTypeFieldId = ?") + .run(expectedFieldOrderNumber, occupancyTypeField.occupancyTypeFieldId); + occupancyTypeField.orderNumber = expectedFieldOrderNumber; + } + } + } database.close(); return occupancyTypes; }; diff --git a/helpers/lotOccupancyDB/getOccupancyTypes.ts b/helpers/lotOccupancyDB/getOccupancyTypes.ts index b1e88137..24df53c5 100644 --- a/helpers/lotOccupancyDB/getOccupancyTypes.ts +++ b/helpers/lotOccupancyDB/getOccupancyTypes.ts @@ -1,29 +1,76 @@ 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"; - export const getOccupancyTypes = (): recordTypes.OccupancyType[] => { - - const database = sqlite(databasePath, { - readonly: true - }); + const database = sqlite(databasePath); const occupancyTypes: recordTypes.OccupancyType[] = database - .prepare("select occupancyTypeId, occupancyType" + - " from OccupancyTypes" + - " where recordDelete_timeMillis is null" + - " order by orderNumber, occupancyType") + .prepare( + "select occupancyTypeId, occupancyType, orderNumber" + + " from OccupancyTypes" + + " where recordDelete_timeMillis is null" + + " order by orderNumber, occupancyType" + ) .all(); + let expectedTypeOrderNumber = -1; + + for (const occupancyType of occupancyTypes) { + expectedTypeOrderNumber += 1; + + if (occupancyType.orderNumber !== expectedTypeOrderNumber) { + database + .prepare( + "update OccupancyTypes" + + " set orderNumber = ?" + + " where occupancyTypeId = ?" + ) + .run(expectedTypeOrderNumber, occupancyType.occupancyTypeId); + + occupancyType.orderNumber = expectedTypeOrderNumber; + } + + occupancyType.occupancyTypeFields = database + .prepare( + "select occupancyTypeFieldId," + + " occupancyTypeField, occupancyTypeFieldValues, isRequired, pattern," + + " minimumLength, maximumLength," + + " orderNumber" + + " from OccupancyTypeFields" + + " where recordDelete_timeMillis is null" + + " and occupancyTypeId = ?" + + " order by orderNumber, occupancyTypeField" + ) + .all(occupancyType.occupancyTypeId); + + let expectedFieldOrderNumber = -1; + + for (const occupancyTypeField of occupancyType.occupancyTypeFields) { + expectedFieldOrderNumber += 1; + + if (occupancyTypeField.orderNumber !== expectedFieldOrderNumber) { + database + .prepare( + "update OccupancyTypeFields" + + " set orderNumber = ?" + + " where occupancyTypeFieldId = ?" + ) + .run( + expectedFieldOrderNumber, + occupancyTypeField.occupancyTypeFieldId + ); + + occupancyTypeField.orderNumber = expectedFieldOrderNumber; + } + } + } + database.close(); return occupancyTypes; }; - -export default getOccupancyTypes; \ No newline at end of file +export default getOccupancyTypes; diff --git a/helpers/lotOccupancyDB/getPreviousLotId.ts b/helpers/lotOccupancyDB/getPreviousLotId.ts index e869ae54..1e2e44ee 100644 --- a/helpers/lotOccupancyDB/getPreviousLotId.ts +++ b/helpers/lotOccupancyDB/getPreviousLotId.ts @@ -1,28 +1,29 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import * as configFunctions from "../functions.config.js"; - export const getPreviousLotId = (lotId: number | string): number => { - const database = sqlite(databasePath, { readonly: true }); - database.function("userFn_lotNameSortName", configFunctions.getProperty("settings.lot.lotNameSortNameFunction")); + database.function( + "userFn_lotNameSortName", + configFunctions.getProperty("settings.lot.lotNameSortNameFunction") + ); const result: { - lotId: number - } = database - .prepare("select lotId from Lots" + - " where recordDelete_timeMillis is null" + - " and userFn_lotNameSortName(lotName) < (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" + - " order by userFn_lotNameSortName(lotName) desc" + - " limit 1") + lotId: number; + } = database + .prepare( + "select lotId from Lots" + + " where recordDelete_timeMillis is null" + + " and userFn_lotNameSortName(lotName) < (select userFn_lotNameSortName(lotName) from Lots where lotId = ?)" + + " order by userFn_lotNameSortName(lotName) desc" + + " limit 1" + ) .get(lotId); database.close(); @@ -34,5 +35,4 @@ export const getPreviousLotId = (lotId: number | string): number => { return undefined; }; - -export default getPreviousLotId; \ No newline at end of file +export default getPreviousLotId; diff --git a/helpers/lotOccupancyDB/getReportData.js b/helpers/lotOccupancyDB/getReportData.js index c87beacb..d84a1f89 100644 --- a/helpers/lotOccupancyDB/getReportData.js +++ b/helpers/lotOccupancyDB/getReportData.js @@ -20,17 +20,33 @@ export const getReportData = (reportName, reportParameters) => { sql = "select * from Maps"; break; case "maps-formatted": - sql = "select mapName as " + mapNameAlias + "," + - " mapDescription as " + mapDescriptionAlias + "," + - " mapAddress1 as " + mapAddress1Alias + "," + - " mapAddress2 as " + mapAddress2Alias + "," + - " mapCity as " + mapCityAlias + "," + - " mapProvince as " + mapProvinceAlias + "," + - " mapPostalCode as " + mapPostalCodeAlias + "," + - " mapPhoneNumber as " + mapPhoneNumberAlias + - " from Maps" + - " where recordDelete_timeMillis is null" + - " order by mapName"; + sql = + "select mapName as " + + mapNameAlias + + "," + + " mapDescription as " + + mapDescriptionAlias + + "," + + " mapAddress1 as " + + mapAddress1Alias + + "," + + " mapAddress2 as " + + mapAddress2Alias + + "," + + " mapCity as " + + mapCityAlias + + "," + + " mapProvince as " + + mapProvinceAlias + + "," + + " mapPostalCode as " + + mapPostalCodeAlias + + "," + + " mapPhoneNumber as " + + mapPhoneNumberAlias + + " from Maps" + + " where recordDelete_timeMillis is null" + + " order by mapName"; break; case "lots-all": sql = "select * from Lots"; @@ -103,8 +119,7 @@ export const getReportData = (reportName, reportParameters) => { }); database.function("userFn_dateIntegerToString", dateTimeFunctions.dateIntegerToString); database.function("userFn_timeIntegerToString", dateTimeFunctions.timeIntegerToString); - const rows = database.prepare(sql) - .all(sqlParameters); + const rows = database.prepare(sql).all(sqlParameters); database.close(); return rows; }; diff --git a/helpers/lotOccupancyDB/getReportData.ts b/helpers/lotOccupancyDB/getReportData.ts index ae5695df..7a9cce8c 100644 --- a/helpers/lotOccupancyDB/getReportData.ts +++ b/helpers/lotOccupancyDB/getReportData.ts @@ -2,9 +2,7 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import * as configFunctions from "../functions.config.js"; import * as dateTimeFunctions from "@cityssm/expressjs-server-js/dateTimeFns.js"; @@ -15,7 +13,6 @@ export interface ReportParameters { [parameterName: string]: string | number; } - const mapCamelCase = camelCase(configFunctions.getProperty("aliases.map")); const mapNameAlias = mapCamelCase + "Name"; const mapDescriptionAlias = mapCamelCase + "Description"; @@ -26,29 +23,43 @@ const mapProvinceAlias = mapCamelCase + "Province"; const mapPostalCodeAlias = mapCamelCase + "PostalCode"; const mapPhoneNumberAlias = mapCamelCase + "PhoneNumber"; - -export const getReportData = (reportName: string, reportParameters ? : ReportParameters): unknown[] => { - +export const getReportData = ( + reportName: string, + reportParameters?: ReportParameters +): unknown[] => { let sql: string; const sqlParameters = []; switch (reportName) { - case "maps-all": - sql = "select * from Maps"; break; case "maps-formatted": - - sql = "select mapName as " + mapNameAlias + "," + - " mapDescription as " + mapDescriptionAlias + "," + - " mapAddress1 as " + mapAddress1Alias + "," + - " mapAddress2 as " + mapAddress2Alias + "," + - " mapCity as " + mapCityAlias + "," + - " mapProvince as " + mapProvinceAlias + "," + - " mapPostalCode as " + mapPostalCodeAlias + "," + - " mapPhoneNumber as " + mapPhoneNumberAlias + + sql = + "select mapName as " + + mapNameAlias + + "," + + " mapDescription as " + + mapDescriptionAlias + + "," + + " mapAddress1 as " + + mapAddress1Alias + + "," + + " mapAddress2 as " + + mapAddress2Alias + + "," + + " mapCity as " + + mapCityAlias + + "," + + " mapProvince as " + + mapProvinceAlias + + "," + + " mapPostalCode as " + + mapPostalCodeAlias + + "," + + " mapPhoneNumber as " + + mapPhoneNumberAlias + " from Maps" + " where recordDelete_timeMillis is null" + " order by mapName"; @@ -56,107 +67,86 @@ export const getReportData = (reportName: string, reportParameters ? : ReportPar break; case "lots-all": - sql = "select * from Lots"; break; case "lotComments-all": - sql = "select * from LotComments"; break; - - case "lotFields-all": + case "lotFields-all": sql = "select * from LotFields"; break; - - case "lotOccupancies-all": + case "lotOccupancies-all": sql = "select * from LotOccupancies"; break; case "lotOccupancyComments-all": - sql = "select * from LotOccupancyComments"; break; case "lotOccupancyFees-all": - sql = "select * from LotOccupancyFees"; break; case "lotOccupancyFields-all": - sql = "select * from LotOccupancyFields"; break; case "lotOccupancyOccupants-all": - sql = "select * from LotOccupancyOccupants"; break; case "lotOccupancyTransactions-all": - sql = "select * from LotOccupancyTransactions"; break; case "workOrders-all": - sql = "select * from WorkOrders"; break; case "workOrderComments-all": - sql = "select * from WorkOrderComments"; break; case "workOrderLots-all": - sql = "select * from WorkOrderLots"; break; case "fees-all": - sql = "select * from Fees"; break; case "feeCategories-all": - sql = "select * from FeeCategories"; break; case "lotTypes-all": - sql = "select * from LotTypes"; break; case "lotTypeFields-all": - sql = "select * from LotTypeFields"; break; case "lotStatuses-all": - sql = "select * from LotStatuses"; break; case "occupancyTypes-all": - sql = "select * from OccupancyTypes"; break; case "occupancyTypeFields-all": - sql = "select * from OccupancyTypeFields"; break; case "lotOccupantTypes-all": - sql = "select * from LotOccupantTypes"; break; case "workOrderTypes-all": - sql = "select * from WorkOrderTypes"; break; @@ -168,17 +158,20 @@ export const getReportData = (reportName: string, reportParameters ? : ReportPar readonly: true }); - database.function("userFn_dateIntegerToString", dateTimeFunctions.dateIntegerToString); - database.function("userFn_timeIntegerToString", dateTimeFunctions.timeIntegerToString); + database.function( + "userFn_dateIntegerToString", + dateTimeFunctions.dateIntegerToString + ); + database.function( + "userFn_timeIntegerToString", + dateTimeFunctions.timeIntegerToString + ); - const rows = - database.prepare(sql) - .all(sqlParameters); + const rows = database.prepare(sql).all(sqlParameters); database.close(); return rows; }; - -export default getReportData; \ No newline at end of file +export default getReportData; diff --git a/helpers/lotOccupancyDB/getWorkOrder.ts b/helpers/lotOccupancyDB/getWorkOrder.ts index 04e42256..6e9e1cf4 100644 --- a/helpers/lotOccupancyDB/getWorkOrder.ts +++ b/helpers/lotOccupancyDB/getWorkOrder.ts @@ -1,27 +1,18 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - dateIntegerToString -} from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import { dateIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; -import { - getLots -} from "./getLots.js"; +import { getLots } from "./getLots.js"; -import { - getLotOccupancies -} from "./getLotOccupancies.js"; +import { getLotOccupancies } from "./getLotOccupancies.js"; import type * as recordTypes from "../../types/recordTypes"; - - -export const getWorkOrder = (workOrderId: number | string): recordTypes.WorkOrder => { - +export const getWorkOrder = ( + workOrderId: number | string +): recordTypes.WorkOrder => { const database = sqlite(databasePath, { readonly: true }); @@ -29,33 +20,42 @@ export const getWorkOrder = (workOrderId: number | string): recordTypes.WorkOrde database.function("userFn_dateIntegerToString", dateIntegerToString); const workOrder: recordTypes.WorkOrder = database - .prepare("select w.workOrderId," + - " w.workOrderTypeId, t.workOrderType," + - " w.workOrderNumber, w.workOrderDescription," + - " w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString," + - " w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString" + - " from WorkOrders w" + - " left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" + - " where w.recordDelete_timeMillis is null" + - " and w.workOrderId = ?") + .prepare( + "select w.workOrderId," + + " w.workOrderTypeId, t.workOrderType," + + " w.workOrderNumber, w.workOrderDescription," + + " w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString," + + " w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString" + + " from WorkOrders w" + + " left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" + + " where w.recordDelete_timeMillis is null" + + " and w.workOrderId = ?" + ) .get(workOrderId); - if (workOrder) { - workOrder.workOrderLots = getLots({ - workOrderId: workOrder.workOrderId - }, { - limit: -1, - offset: 0 - }, database).lots; + workOrder.workOrderLots = getLots( + { + workOrderId: workOrder.workOrderId + }, + { + limit: -1, + offset: 0 + }, + database + ).lots; - workOrder.workOrderLotOccupancies = getLotOccupancies({ - workOrderId: workOrder.workOrderId - }, { - limit: -1, - offset: 0, - includeOccupants: true - }, database).lotOccupancies; + workOrder.workOrderLotOccupancies = getLotOccupancies( + { + workOrderId: workOrder.workOrderId + }, + { + limit: -1, + offset: 0, + includeOccupants: true + }, + database + ).lotOccupancies; } database.close(); @@ -63,5 +63,4 @@ export const getWorkOrder = (workOrderId: number | string): recordTypes.WorkOrde return workOrder; }; - -export default getWorkOrder; \ No newline at end of file +export default getWorkOrder; diff --git a/helpers/lotOccupancyDB/getWorkOrderTypes.js b/helpers/lotOccupancyDB/getWorkOrderTypes.js index 1841ce6c..fda6b98f 100644 --- a/helpers/lotOccupancyDB/getWorkOrderTypes.js +++ b/helpers/lotOccupancyDB/getWorkOrderTypes.js @@ -11,7 +11,8 @@ export const getWorkOrderTypes = () => { let expectedOrderNumber = 0; for (const workOrderType of workOrderTypes) { if (workOrderType.orderNumber !== expectedOrderNumber) { - database.prepare("update WorkOrderTypes" + + database + .prepare("update WorkOrderTypes" + " set orderNumber = ?" + " where workOrderTypeId = ?") .run(expectedOrderNumber, workOrderType.workOrderTypeId); diff --git a/helpers/lotOccupancyDB/getWorkOrderTypes.ts b/helpers/lotOccupancyDB/getWorkOrderTypes.ts index 78e21be4..e28bdfee 100644 --- a/helpers/lotOccupancyDB/getWorkOrderTypes.ts +++ b/helpers/lotOccupancyDB/getWorkOrderTypes.ts @@ -1,34 +1,32 @@ 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"; - export const getWorkOrderTypes = (): recordTypes.WorkOrderType[] => { - const database = sqlite(databasePath); const workOrderTypes: recordTypes.WorkOrderType[] = database - .prepare("select workOrderTypeId, workOrderType, orderNumber" + - " from WorkOrderTypes" + - " where recordDelete_timeMillis is null" + - " order by orderNumber, workOrderType") + .prepare( + "select workOrderTypeId, workOrderType, orderNumber" + + " from WorkOrderTypes" + + " where recordDelete_timeMillis is null" + + " order by orderNumber, workOrderType" + ) .all(); let expectedOrderNumber = 0; for (const workOrderType of workOrderTypes) { - if (workOrderType.orderNumber !== expectedOrderNumber) { - - database.prepare("update WorkOrderTypes" + - " set orderNumber = ?" + - " where workOrderTypeId = ?") - .run(expectedOrderNumber, - workOrderType.workOrderTypeId); + database + .prepare( + "update WorkOrderTypes" + + " set orderNumber = ?" + + " where workOrderTypeId = ?" + ) + .run(expectedOrderNumber, workOrderType.workOrderTypeId); workOrderType.orderNumber = expectedOrderNumber; } @@ -41,5 +39,4 @@ export const getWorkOrderTypes = (): recordTypes.WorkOrderType[] => { return workOrderTypes; }; - -export default getWorkOrderTypes; \ No newline at end of file +export default getWorkOrderTypes; diff --git a/helpers/lotOccupancyDB/getWorkOrders.js b/helpers/lotOccupancyDB/getWorkOrders.js index 84bbef82..42adc53c 100644 --- a/helpers/lotOccupancyDB/getWorkOrders.js +++ b/helpers/lotOccupancyDB/getWorkOrders.js @@ -12,11 +12,11 @@ export const getWorkOrders = (filters, options) => { sqlWhereClause += " and w.workOrderTypeId = ?"; sqlParameters.push(filters.workOrderTypeId); } - const count = database.prepare("select count(*) as recordCount" + + const count = database + .prepare("select count(*) as recordCount" + " from WorkOrders w" + sqlWhereClause) - .get(sqlParameters) - .recordCount; + .get(sqlParameters).recordCount; let workOrders = []; if (count > 0) { workOrders = database @@ -29,9 +29,12 @@ export const getWorkOrders = (filters, options) => { " left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" + sqlWhereClause + " order by w.workOrderOpenDate desc, w.workOrderNumber" + - (options ? - " limit " + options.limit + " offset " + options.offset : - "")) + (options + ? " limit " + + options.limit + + " offset " + + options.offset + : "")) .all(sqlParameters); } database.close(); diff --git a/helpers/lotOccupancyDB/getWorkOrders.ts b/helpers/lotOccupancyDB/getWorkOrders.ts index 9821ccf0..af51d4f1 100644 --- a/helpers/lotOccupancyDB/getWorkOrders.ts +++ b/helpers/lotOccupancyDB/getWorkOrders.ts @@ -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 { - dateIntegerToString -} from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import { dateIntegerToString } from "@cityssm/expressjs-server-js/dateTimeFns.js"; import type * as recordTypes from "../../types/recordTypes"; - interface GetWorkOrdersFilters { - workOrderTypeId ? : number | string; + workOrderTypeId?: number | string; } interface GetWorkOrdersOptions { @@ -20,12 +15,13 @@ interface GetWorkOrdersOptions { offset: number; } - -export const getWorkOrders = (filters ? : GetWorkOrdersFilters, options ? : GetWorkOrdersOptions): { +export const getWorkOrders = ( + filters?: GetWorkOrdersFilters, + options?: GetWorkOrdersOptions +): { count: number; workOrders: recordTypes.WorkOrder[]; } => { - const database = sqlite(databasePath, { readonly: true }); @@ -40,29 +36,35 @@ export const getWorkOrders = (filters ? : GetWorkOrdersFilters, options ? : GetW sqlParameters.push(filters.workOrderTypeId); } - const count: number = database.prepare("select count(*) as recordCount" + - " from WorkOrders w" + - sqlWhereClause) - .get(sqlParameters) - .recordCount; + const count: number = database + .prepare( + "select count(*) as recordCount" + + " from WorkOrders w" + + sqlWhereClause + ) + .get(sqlParameters).recordCount; let workOrders: recordTypes.WorkOrder[] = []; if (count > 0) { - workOrders = database - .prepare("select w.workOrderId," + - " w.workOrderTypeId, t.workOrderType," + - " w.workOrderNumber, w.workOrderDescription," + - " w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString," + - " w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString" + - " from WorkOrders w" + - " left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" + - sqlWhereClause + - " order by w.workOrderOpenDate desc, w.workOrderNumber" + - (options ? - " limit " + options.limit + " offset " + options.offset : - "")) + .prepare( + "select w.workOrderId," + + " w.workOrderTypeId, t.workOrderType," + + " w.workOrderNumber, w.workOrderDescription," + + " w.workOrderOpenDate, userFn_dateIntegerToString(w.workOrderOpenDate) as workOrderOpenDateString," + + " w.workOrderCloseDate, userFn_dateIntegerToString(w.workOrderCloseDate) as workOrderCloseDateString" + + " from WorkOrders w" + + " left join WorkOrderTypes t on w.workOrderTypeId = t.workOrderTypeId" + + sqlWhereClause + + " order by w.workOrderOpenDate desc, w.workOrderNumber" + + (options + ? " limit " + + options.limit + + " offset " + + options.offset + : "") + ) .all(sqlParameters); } @@ -74,5 +76,4 @@ export const getWorkOrders = (filters ? : GetWorkOrdersFilters, options ? : GetW }; }; - -export default getWorkOrders; \ No newline at end of file +export default getWorkOrders; diff --git a/helpers/lotOccupancyDB/moveFeeCategoryDown.js b/helpers/lotOccupancyDB/moveFeeCategoryDown.js index 3f682d31..86d24b51 100644 --- a/helpers/lotOccupancyDB/moveFeeCategoryDown.js +++ b/helpers/lotOccupancyDB/moveFeeCategoryDown.js @@ -2,11 +2,11 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; export const moveFeeCategoryDown = (feeCategoryId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + + const currentOrderNumber = database + .prepare("select orderNumber" + " from FeeCategories" + " where feeCategoryId = ?") - .get(feeCategoryId) - .orderNumber; + .get(feeCategoryId).orderNumber; database .prepare("update FeeCategories" + " set orderNumber = orderNumber - 1" + diff --git a/helpers/lotOccupancyDB/moveFeeCategoryDown.ts b/helpers/lotOccupancyDB/moveFeeCategoryDown.ts index e72037b1..6c83b998 100644 --- a/helpers/lotOccupancyDB/moveFeeCategoryDown.ts +++ b/helpers/lotOccupancyDB/moveFeeCategoryDown.ts @@ -1,38 +1,40 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +export const moveFeeCategoryDown = ( + feeCategoryId: number | string +): boolean => { + const database = sqlite(databasePath); -export const moveFeeCategoryDown = - (feeCategoryId: number | string): boolean => { - - const database = sqlite(databasePath); - - const currentOrderNumber: number = database.prepare("select orderNumber" + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + " from FeeCategories" + - " where feeCategoryId = ?") - .get(feeCategoryId) - .orderNumber; + " where feeCategoryId = ?" + ) + .get(feeCategoryId).orderNumber; - database - .prepare("update FeeCategories" + + database + .prepare( + "update FeeCategories" + " set orderNumber = orderNumber - 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? + 1") - .run(currentOrderNumber); + " and orderNumber = ? + 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update FeeCategories" + + const result = database + .prepare( + "update FeeCategories" + " set orderNumber = ? + 1" + - " where feeCategoryId = ?") - .run(currentOrderNumber, feeCategoryId); + " where feeCategoryId = ?" + ) + .run(currentOrderNumber, feeCategoryId); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveFeeCategoryDown; \ No newline at end of file +export default moveFeeCategoryDown; diff --git a/helpers/lotOccupancyDB/moveFeeCategoryUp.js b/helpers/lotOccupancyDB/moveFeeCategoryUp.js index dd5f3d00..a3fb7bc1 100644 --- a/helpers/lotOccupancyDB/moveFeeCategoryUp.js +++ b/helpers/lotOccupancyDB/moveFeeCategoryUp.js @@ -2,11 +2,11 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; export const moveFeeCategoryUp = (feeCategoryId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + + const currentOrderNumber = database + .prepare("select orderNumber" + " from FeeCategories" + " where feeCategoryId = ?") - .get(feeCategoryId) - .orderNumber; + .get(feeCategoryId).orderNumber; if (currentOrderNumber <= 0) { database.close(); return true; diff --git a/helpers/lotOccupancyDB/moveFeeCategoryUp.ts b/helpers/lotOccupancyDB/moveFeeCategoryUp.ts index 68836001..fbdfff6f 100644 --- a/helpers/lotOccupancyDB/moveFeeCategoryUp.ts +++ b/helpers/lotOccupancyDB/moveFeeCategoryUp.ts @@ -1,43 +1,43 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +export const moveFeeCategoryUp = (feeCategoryId: number | string): boolean => { + const database = sqlite(databasePath); -export const moveFeeCategoryUp = - (feeCategoryId: number | string): boolean => { - - const database = sqlite(databasePath); - - const currentOrderNumber: number = database.prepare("select orderNumber" + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + " from FeeCategories" + - " where feeCategoryId = ?") - .get(feeCategoryId) - .orderNumber; + " where feeCategoryId = ?" + ) + .get(feeCategoryId).orderNumber; - if (currentOrderNumber <= 0) { - database.close(); - return true; - } + if (currentOrderNumber <= 0) { + database.close(); + return true; + } - database - .prepare("update FeeCategories" + + database + .prepare( + "update FeeCategories" + " set orderNumber = orderNumber + 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? - 1") - .run(currentOrderNumber); + " and orderNumber = ? - 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update FeeCategories" + + const result = database + .prepare( + "update FeeCategories" + " set orderNumber = ? - 1" + - " where feeCategoryId = ?") - .run(currentOrderNumber, feeCategoryId); + " where feeCategoryId = ?" + ) + .run(currentOrderNumber, feeCategoryId); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveFeeCategoryUp; \ No newline at end of file +export default moveFeeCategoryUp; diff --git a/helpers/lotOccupancyDB/moveFeeDown.js b/helpers/lotOccupancyDB/moveFeeDown.js index 6056be12..38b3769d 100644 --- a/helpers/lotOccupancyDB/moveFeeDown.js +++ b/helpers/lotOccupancyDB/moveFeeDown.js @@ -2,11 +2,9 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; export const moveFeeDown = (feeId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + - " from Fees" + - " where feeId = ?") - .get(feeId) - .orderNumber; + const currentOrderNumber = database + .prepare("select orderNumber" + " from Fees" + " where feeId = ?") + .get(feeId).orderNumber; database .prepare("update Fees" + " set orderNumber = orderNumber - 1" + @@ -14,9 +12,7 @@ export const moveFeeDown = (feeId) => { " and orderNumber = ? + 1") .run(currentOrderNumber); const result = database - .prepare("update Fees" + - " set orderNumber = ? + 1" + - " where feeId = ?") + .prepare("update Fees" + " set orderNumber = ? + 1" + " where feeId = ?") .run(currentOrderNumber, feeId); database.close(); return result.changes > 0; diff --git a/helpers/lotOccupancyDB/moveFeeDown.ts b/helpers/lotOccupancyDB/moveFeeDown.ts index 97a099d9..3ddbd53b 100644 --- a/helpers/lotOccupancyDB/moveFeeDown.ts +++ b/helpers/lotOccupancyDB/moveFeeDown.ts @@ -1,38 +1,32 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +export const moveFeeDown = (feeId: number | string): boolean => { + const database = sqlite(databasePath); -export const moveFeeDown = - (feeId: number | string): boolean => { + const currentOrderNumber: number = database + .prepare("select orderNumber" + " from Fees" + " where feeId = ?") + .get(feeId).orderNumber; - const database = sqlite(databasePath); - - const currentOrderNumber: number = database.prepare("select orderNumber" + - " from Fees" + - " where feeId = ?") - .get(feeId) - .orderNumber; - - database - .prepare("update Fees" + + database + .prepare( + "update Fees" + " set orderNumber = orderNumber - 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? + 1") - .run(currentOrderNumber); + " and orderNumber = ? + 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update Fees" + - " set orderNumber = ? + 1" + - " where feeId = ?") - .run(currentOrderNumber, feeId); + const result = database + .prepare( + "update Fees" + " set orderNumber = ? + 1" + " where feeId = ?" + ) + .run(currentOrderNumber, feeId); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveFeeDown; \ No newline at end of file +export default moveFeeDown; diff --git a/helpers/lotOccupancyDB/moveFeeUp.js b/helpers/lotOccupancyDB/moveFeeUp.js index 7965c710..47ead832 100644 --- a/helpers/lotOccupancyDB/moveFeeUp.js +++ b/helpers/lotOccupancyDB/moveFeeUp.js @@ -2,11 +2,9 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; export const moveFeeUp = (feeId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + - " from Fees" + - " where feeId = ?") - .get(feeId) - .orderNumber; + const currentOrderNumber = database + .prepare("select orderNumber" + " from Fees" + " where feeId = ?") + .get(feeId).orderNumber; if (currentOrderNumber <= 0) { database.close(); return true; @@ -18,9 +16,7 @@ export const moveFeeUp = (feeId) => { " and orderNumber = ? - 1") .run(currentOrderNumber); const result = database - .prepare("update Fees" + - " set orderNumber = ? - 1" + - " where feeId = ?") + .prepare("update Fees" + " set orderNumber = ? - 1" + " where feeId = ?") .run(currentOrderNumber, feeId); database.close(); return result.changes > 0; diff --git a/helpers/lotOccupancyDB/moveFeeUp.ts b/helpers/lotOccupancyDB/moveFeeUp.ts index b51eeec1..02849bba 100644 --- a/helpers/lotOccupancyDB/moveFeeUp.ts +++ b/helpers/lotOccupancyDB/moveFeeUp.ts @@ -1,43 +1,37 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +export const moveFeeUp = (feeId: number | string): boolean => { + const database = sqlite(databasePath); -export const moveFeeUp = - (feeId: number | string): boolean => { + const currentOrderNumber: number = database + .prepare("select orderNumber" + " from Fees" + " where feeId = ?") + .get(feeId).orderNumber; - const database = sqlite(databasePath); + if (currentOrderNumber <= 0) { + database.close(); + return true; + } - const currentOrderNumber: number = database.prepare("select orderNumber" + - " from Fees" + - " where feeId = ?") - .get(feeId) - .orderNumber; - - if (currentOrderNumber <= 0) { - database.close(); - return true; - } - - database - .prepare("update Fees" + + database + .prepare( + "update Fees" + " set orderNumber = orderNumber + 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? - 1") - .run(currentOrderNumber); + " and orderNumber = ? - 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update Fees" + - " set orderNumber = ? - 1" + - " where feeId = ?") - .run(currentOrderNumber, feeId); + const result = database + .prepare( + "update Fees" + " set orderNumber = ? - 1" + " where feeId = ?" + ) + .run(currentOrderNumber, feeId); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveFeeUp; \ No newline at end of file +export default moveFeeUp; diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeDown.js b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.js index b95083c2..6333e839 100644 --- a/helpers/lotOccupancyDB/moveLotOccupantTypeDown.js +++ b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.js @@ -3,11 +3,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { clearLotOccupantTypesCache } from "../functions.cache.js"; export const moveLotOccupantTypeDown = (lotOccupantTypeId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + + const currentOrderNumber = database + .prepare("select orderNumber" + " from LotOccupantTypes" + " where lotOccupantTypeId = ?") - .get(lotOccupantTypeId) - .orderNumber; + .get(lotOccupantTypeId).orderNumber; database .prepare("update LotOccupantTypes" + " set orderNumber = orderNumber - 1" + diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeDown.ts b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.ts index e2683c18..279b49cd 100644 --- a/helpers/lotOccupancyDB/moveLotOccupantTypeDown.ts +++ b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.ts @@ -1,44 +1,44 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearLotOccupantTypesCache -} from "../functions.cache.js"; +import { clearLotOccupantTypesCache } from "../functions.cache.js"; +export const moveLotOccupantTypeDown = ( + lotOccupantTypeId: number | string +): boolean => { + const database = sqlite(databasePath); -export const moveLotOccupantTypeDown = - (lotOccupantTypeId: number | string): boolean => { - - const database = sqlite(databasePath); - - const currentOrderNumber: number = database.prepare("select orderNumber" + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + " from LotOccupantTypes" + - " where lotOccupantTypeId = ?") - .get(lotOccupantTypeId) - .orderNumber; + " where lotOccupantTypeId = ?" + ) + .get(lotOccupantTypeId).orderNumber; - database - .prepare("update LotOccupantTypes" + + database + .prepare( + "update LotOccupantTypes" + " set orderNumber = orderNumber - 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? + 1") - .run(currentOrderNumber); + " and orderNumber = ? + 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update LotOccupantTypes" + + const result = database + .prepare( + "update LotOccupantTypes" + " set orderNumber = ? + 1" + - " where lotOccupantTypeId = ?") - .run(currentOrderNumber, lotOccupantTypeId); + " where lotOccupantTypeId = ?" + ) + .run(currentOrderNumber, lotOccupantTypeId); - database.close(); + database.close(); - clearLotOccupantTypesCache(); + clearLotOccupantTypesCache(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveLotOccupantTypeDown; \ No newline at end of file +export default moveLotOccupantTypeDown; diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeUp.js b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.js index c8cebf7b..d65a90f9 100644 --- a/helpers/lotOccupancyDB/moveLotOccupantTypeUp.js +++ b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.js @@ -3,11 +3,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { clearLotOccupantTypesCache } from "../functions.cache.js"; export const moveLotOccupantTypeUp = (lotOccupantTypeId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + + const currentOrderNumber = database + .prepare("select orderNumber" + " from LotOccupantTypes" + " where lotOccupantTypeId = ?") - .get(lotOccupantTypeId) - .orderNumber; + .get(lotOccupantTypeId).orderNumber; if (currentOrderNumber <= 0) { database.close(); return true; diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeUp.ts b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.ts index 0996b964..bd6b4a2a 100644 --- a/helpers/lotOccupancyDB/moveLotOccupantTypeUp.ts +++ b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.ts @@ -1,49 +1,49 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearLotOccupantTypesCache -} from "../functions.cache.js"; +import { clearLotOccupantTypesCache } from "../functions.cache.js"; +export const moveLotOccupantTypeUp = ( + lotOccupantTypeId: number | string +): boolean => { + const database = sqlite(databasePath); -export const moveLotOccupantTypeUp = - (lotOccupantTypeId: number | string): boolean => { - - const database = sqlite(databasePath); - - const currentOrderNumber: number = database.prepare("select orderNumber" + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + " from LotOccupantTypes" + - " where lotOccupantTypeId = ?") - .get(lotOccupantTypeId) - .orderNumber; + " where lotOccupantTypeId = ?" + ) + .get(lotOccupantTypeId).orderNumber; - if (currentOrderNumber <= 0) { - database.close(); - return true; - } + if (currentOrderNumber <= 0) { + database.close(); + return true; + } - database - .prepare("update LotOccupantTypes" + + database + .prepare( + "update LotOccupantTypes" + " set orderNumber = orderNumber + 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? - 1") - .run(currentOrderNumber); + " and orderNumber = ? - 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update LotOccupantTypes" + + const result = database + .prepare( + "update LotOccupantTypes" + " set orderNumber = ? - 1" + - " where lotOccupantTypeId = ?") - .run(currentOrderNumber, lotOccupantTypeId); + " where lotOccupantTypeId = ?" + ) + .run(currentOrderNumber, lotOccupantTypeId); - database.close(); + database.close(); - clearLotOccupantTypesCache(); + clearLotOccupantTypesCache(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveLotOccupantTypeUp; \ No newline at end of file +export default moveLotOccupantTypeUp; diff --git a/helpers/lotOccupancyDB/moveLotStatusDown.js b/helpers/lotOccupancyDB/moveLotStatusDown.js index 4f14baa6..adad5f1d 100644 --- a/helpers/lotOccupancyDB/moveLotStatusDown.js +++ b/helpers/lotOccupancyDB/moveLotStatusDown.js @@ -3,11 +3,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { clearLotStatusesCache } from "../functions.cache.js"; export const moveLotStatusDown = (lotStatusId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + + const currentOrderNumber = database + .prepare("select orderNumber" + " from LotStatuses" + " where lotStatusId = ?") - .get(lotStatusId) - .orderNumber; + .get(lotStatusId).orderNumber; database .prepare("update LotStatuses" + " set orderNumber = orderNumber - 1" + diff --git a/helpers/lotOccupancyDB/moveLotStatusDown.ts b/helpers/lotOccupancyDB/moveLotStatusDown.ts index 730108e0..e7b32e02 100644 --- a/helpers/lotOccupancyDB/moveLotStatusDown.ts +++ b/helpers/lotOccupancyDB/moveLotStatusDown.ts @@ -1,44 +1,42 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearLotStatusesCache -} from "../functions.cache.js"; +import { clearLotStatusesCache } from "../functions.cache.js"; +export const moveLotStatusDown = (lotStatusId: number | string): boolean => { + const database = sqlite(databasePath); -export const moveLotStatusDown = - (lotStatusId: number | string): boolean => { - - const database = sqlite(databasePath); - - const currentOrderNumber: number = database.prepare("select orderNumber" + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + " from LotStatuses" + - " where lotStatusId = ?") - .get(lotStatusId) - .orderNumber; + " where lotStatusId = ?" + ) + .get(lotStatusId).orderNumber; - database - .prepare("update LotStatuses" + + database + .prepare( + "update LotStatuses" + " set orderNumber = orderNumber - 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? + 1") - .run(currentOrderNumber); + " and orderNumber = ? + 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update LotStatuses" + + const result = database + .prepare( + "update LotStatuses" + " set orderNumber = ? + 1" + - " where lotStatusId = ?") - .run(currentOrderNumber, lotStatusId); + " where lotStatusId = ?" + ) + .run(currentOrderNumber, lotStatusId); - database.close(); + database.close(); - clearLotStatusesCache(); + clearLotStatusesCache(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveLotStatusDown; \ No newline at end of file +export default moveLotStatusDown; diff --git a/helpers/lotOccupancyDB/moveLotStatusUp.js b/helpers/lotOccupancyDB/moveLotStatusUp.js index ab83bca0..6b80c97e 100644 --- a/helpers/lotOccupancyDB/moveLotStatusUp.js +++ b/helpers/lotOccupancyDB/moveLotStatusUp.js @@ -3,11 +3,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { clearLotStatusesCache } from "../functions.cache.js"; export const moveLotStatusUp = (lotStatusId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + + const currentOrderNumber = database + .prepare("select orderNumber" + " from LotStatuses" + " where lotStatusId = ?") - .get(lotStatusId) - .orderNumber; + .get(lotStatusId).orderNumber; if (currentOrderNumber <= 0) { database.close(); return true; diff --git a/helpers/lotOccupancyDB/moveLotStatusUp.ts b/helpers/lotOccupancyDB/moveLotStatusUp.ts index 988ca9f6..9e201ace 100644 --- a/helpers/lotOccupancyDB/moveLotStatusUp.ts +++ b/helpers/lotOccupancyDB/moveLotStatusUp.ts @@ -1,49 +1,47 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearLotStatusesCache -} from "../functions.cache.js"; +import { clearLotStatusesCache } from "../functions.cache.js"; +export const moveLotStatusUp = (lotStatusId: number | string): boolean => { + const database = sqlite(databasePath); -export const moveLotStatusUp = - (lotStatusId: number | string): boolean => { - - const database = sqlite(databasePath); - - const currentOrderNumber: number = database.prepare("select orderNumber" + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + " from LotStatuses" + - " where lotStatusId = ?") - .get(lotStatusId) - .orderNumber; + " where lotStatusId = ?" + ) + .get(lotStatusId).orderNumber; - if (currentOrderNumber <= 0) { - database.close(); - return true; - } + if (currentOrderNumber <= 0) { + database.close(); + return true; + } - database - .prepare("update LotStatuses" + + database + .prepare( + "update LotStatuses" + " set orderNumber = orderNumber + 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? - 1") - .run(currentOrderNumber); + " and orderNumber = ? - 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update LotStatuses" + + const result = database + .prepare( + "update LotStatuses" + " set orderNumber = ? - 1" + - " where lotStatusId = ?") - .run(currentOrderNumber, lotStatusId); + " where lotStatusId = ?" + ) + .run(currentOrderNumber, lotStatusId); - database.close(); + database.close(); - clearLotStatusesCache(); + clearLotStatusesCache(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveLotStatusUp; \ No newline at end of file +export default moveLotStatusUp; diff --git a/helpers/lotOccupancyDB/moveOccupancyTypeDown.d.ts b/helpers/lotOccupancyDB/moveOccupancyTypeDown.d.ts new file mode 100644 index 00000000..0a25bf2e --- /dev/null +++ b/helpers/lotOccupancyDB/moveOccupancyTypeDown.d.ts @@ -0,0 +1,2 @@ +export declare const moveOccupancyTypeDown: (occupancyTypeId: number | string) => boolean; +export default moveOccupancyTypeDown; diff --git a/helpers/lotOccupancyDB/moveOccupancyTypeDown.js b/helpers/lotOccupancyDB/moveOccupancyTypeDown.js new file mode 100644 index 00000000..2938eba5 --- /dev/null +++ b/helpers/lotOccupancyDB/moveOccupancyTypeDown.js @@ -0,0 +1,26 @@ +import sqlite from "better-sqlite3"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { clearOccupancyTypesCache } from "../functions.cache.js"; +export const moveOccupancyTypeDown = (occupancyTypeId) => { + const database = sqlite(databasePath); + const currentOrderNumber = database + .prepare("select orderNumber" + + " from OccupancyTypes" + + " where occupancyTypeId = ?") + .get(occupancyTypeId).orderNumber; + database + .prepare("update OccupancyTypes" + + " set orderNumber = orderNumber - 1" + + " where recordDelete_timeMillis is null" + + " and orderNumber = ? + 1") + .run(currentOrderNumber); + const result = database + .prepare("update OccupancyTypes" + + " set orderNumber = ? + 1" + + " where occupancyTypeId = ?") + .run(currentOrderNumber, occupancyTypeId); + database.close(); + clearOccupancyTypesCache(); + return result.changes > 0; +}; +export default moveOccupancyTypeDown; diff --git a/helpers/lotOccupancyDB/moveOccupancyTypeDown.ts b/helpers/lotOccupancyDB/moveOccupancyTypeDown.ts new file mode 100644 index 00000000..c8643a96 --- /dev/null +++ b/helpers/lotOccupancyDB/moveOccupancyTypeDown.ts @@ -0,0 +1,44 @@ +import sqlite from "better-sqlite3"; + +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; + +import { clearOccupancyTypesCache } from "../functions.cache.js"; + +export const moveOccupancyTypeDown = ( + occupancyTypeId: number | string +): boolean => { + const database = sqlite(databasePath); + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + + " from OccupancyTypes" + + " where occupancyTypeId = ?" + ) + .get(occupancyTypeId).orderNumber; + + database + .prepare( + "update OccupancyTypes" + + " set orderNumber = orderNumber - 1" + + " where recordDelete_timeMillis is null" + + " and orderNumber = ? + 1" + ) + .run(currentOrderNumber); + + const result = database + .prepare( + "update OccupancyTypes" + + " set orderNumber = ? + 1" + + " where occupancyTypeId = ?" + ) + .run(currentOrderNumber, occupancyTypeId); + + database.close(); + + clearOccupancyTypesCache(); + + return result.changes > 0; +}; + +export default moveOccupancyTypeDown; diff --git a/helpers/lotOccupancyDB/moveOccupancyTypeUp.d.ts b/helpers/lotOccupancyDB/moveOccupancyTypeUp.d.ts new file mode 100644 index 00000000..5b9be02c --- /dev/null +++ b/helpers/lotOccupancyDB/moveOccupancyTypeUp.d.ts @@ -0,0 +1,2 @@ +export declare const moveOccupancyTypeUp: (occupancyTypeId: number | string) => boolean; +export default moveOccupancyTypeUp; diff --git a/helpers/lotOccupancyDB/moveOccupancyTypeUp.js b/helpers/lotOccupancyDB/moveOccupancyTypeUp.js new file mode 100644 index 00000000..4b5ace9b --- /dev/null +++ b/helpers/lotOccupancyDB/moveOccupancyTypeUp.js @@ -0,0 +1,30 @@ +import sqlite from "better-sqlite3"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +import { clearOccupancyTypesCache } from "../functions.cache.js"; +export const moveOccupancyTypeUp = (occupancyTypeId) => { + const database = sqlite(databasePath); + const currentOrderNumber = database + .prepare("select orderNumber" + + " from OccupancyTypes" + + " where occupancyTypeId = ?") + .get(occupancyTypeId).orderNumber; + if (currentOrderNumber <= 0) { + database.close(); + return true; + } + database + .prepare("update OccupancyTypes" + + " set orderNumber = orderNumber + 1" + + " where recordDelete_timeMillis is null" + + " and orderNumber = ? - 1") + .run(currentOrderNumber); + const result = database + .prepare("update OccupancyTypes" + + " set orderNumber = ? - 1" + + " where occupancyTypeId = ?") + .run(currentOrderNumber, occupancyTypeId); + database.close(); + clearOccupancyTypesCache(); + return result.changes > 0; +}; +export default moveOccupancyTypeUp; diff --git a/helpers/lotOccupancyDB/moveOccupancyTypeUp.ts b/helpers/lotOccupancyDB/moveOccupancyTypeUp.ts new file mode 100644 index 00000000..e07d06db --- /dev/null +++ b/helpers/lotOccupancyDB/moveOccupancyTypeUp.ts @@ -0,0 +1,49 @@ +import sqlite from "better-sqlite3"; + +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; + +import { clearOccupancyTypesCache } from "../functions.cache.js"; + +export const moveOccupancyTypeUp = ( + occupancyTypeId: number | string +): boolean => { + const database = sqlite(databasePath); + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + + " from OccupancyTypes" + + " where occupancyTypeId = ?" + ) + .get(occupancyTypeId).orderNumber; + + if (currentOrderNumber <= 0) { + database.close(); + return true; + } + + database + .prepare( + "update OccupancyTypes" + + " set orderNumber = orderNumber + 1" + + " where recordDelete_timeMillis is null" + + " and orderNumber = ? - 1" + ) + .run(currentOrderNumber); + + const result = database + .prepare( + "update OccupancyTypes" + + " set orderNumber = ? - 1" + + " where occupancyTypeId = ?" + ) + .run(currentOrderNumber, occupancyTypeId); + + database.close(); + + clearOccupancyTypesCache(); + + return result.changes > 0; +}; + +export default moveOccupancyTypeUp; diff --git a/helpers/lotOccupancyDB/moveWorkOrderTypeDown.js b/helpers/lotOccupancyDB/moveWorkOrderTypeDown.js index ded00dca..e42ab03a 100644 --- a/helpers/lotOccupancyDB/moveWorkOrderTypeDown.js +++ b/helpers/lotOccupancyDB/moveWorkOrderTypeDown.js @@ -3,11 +3,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { clearWorkOrderTypesCache } from "../functions.cache.js"; export const moveWorkOrderTypeDown = (workOrderTypeId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + + const currentOrderNumber = database + .prepare("select orderNumber" + " from WorkOrderTypes" + " where workOrderTypeId = ?") - .get(workOrderTypeId) - .orderNumber; + .get(workOrderTypeId).orderNumber; database .prepare("update WorkOrderTypes" + " set orderNumber = orderNumber - 1" + diff --git a/helpers/lotOccupancyDB/moveWorkOrderTypeDown.ts b/helpers/lotOccupancyDB/moveWorkOrderTypeDown.ts index 52d561e7..32e66e78 100644 --- a/helpers/lotOccupancyDB/moveWorkOrderTypeDown.ts +++ b/helpers/lotOccupancyDB/moveWorkOrderTypeDown.ts @@ -1,44 +1,44 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearWorkOrderTypesCache -} from "../functions.cache.js"; +import { clearWorkOrderTypesCache } from "../functions.cache.js"; +export const moveWorkOrderTypeDown = ( + workOrderTypeId: number | string +): boolean => { + const database = sqlite(databasePath); -export const moveWorkOrderTypeDown = - (workOrderTypeId: number | string): boolean => { - - const database = sqlite(databasePath); - - const currentOrderNumber: number = database.prepare("select orderNumber" + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + " from WorkOrderTypes" + - " where workOrderTypeId = ?") - .get(workOrderTypeId) - .orderNumber; + " where workOrderTypeId = ?" + ) + .get(workOrderTypeId).orderNumber; - database - .prepare("update WorkOrderTypes" + + database + .prepare( + "update WorkOrderTypes" + " set orderNumber = orderNumber - 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? + 1") - .run(currentOrderNumber); + " and orderNumber = ? + 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update WorkOrderTypes" + + const result = database + .prepare( + "update WorkOrderTypes" + " set orderNumber = ? + 1" + - " where workOrderTypeId = ?") - .run(currentOrderNumber, workOrderTypeId); + " where workOrderTypeId = ?" + ) + .run(currentOrderNumber, workOrderTypeId); - database.close(); + database.close(); - clearWorkOrderTypesCache(); + clearWorkOrderTypesCache(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveWorkOrderTypeDown; \ No newline at end of file +export default moveWorkOrderTypeDown; diff --git a/helpers/lotOccupancyDB/moveWorkOrderTypeUp.js b/helpers/lotOccupancyDB/moveWorkOrderTypeUp.js index 8936db77..aad1a9f0 100644 --- a/helpers/lotOccupancyDB/moveWorkOrderTypeUp.js +++ b/helpers/lotOccupancyDB/moveWorkOrderTypeUp.js @@ -3,11 +3,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { clearWorkOrderTypesCache } from "../functions.cache.js"; export const moveWorkOrderTypeUp = (workOrderTypeId) => { const database = sqlite(databasePath); - const currentOrderNumber = database.prepare("select orderNumber" + + const currentOrderNumber = database + .prepare("select orderNumber" + " from WorkOrderTypes" + " where workOrderTypeId = ?") - .get(workOrderTypeId) - .orderNumber; + .get(workOrderTypeId).orderNumber; if (currentOrderNumber <= 0) { database.close(); return true; diff --git a/helpers/lotOccupancyDB/moveWorkOrderTypeUp.ts b/helpers/lotOccupancyDB/moveWorkOrderTypeUp.ts index 0d6ac758..19537570 100644 --- a/helpers/lotOccupancyDB/moveWorkOrderTypeUp.ts +++ b/helpers/lotOccupancyDB/moveWorkOrderTypeUp.ts @@ -1,49 +1,49 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearWorkOrderTypesCache -} from "../functions.cache.js"; +import { clearWorkOrderTypesCache } from "../functions.cache.js"; +export const moveWorkOrderTypeUp = ( + workOrderTypeId: number | string +): boolean => { + const database = sqlite(databasePath); -export const moveWorkOrderTypeUp = - (workOrderTypeId: number | string): boolean => { - - const database = sqlite(databasePath); - - const currentOrderNumber: number = database.prepare("select orderNumber" + + const currentOrderNumber: number = database + .prepare( + "select orderNumber" + " from WorkOrderTypes" + - " where workOrderTypeId = ?") - .get(workOrderTypeId) - .orderNumber; + " where workOrderTypeId = ?" + ) + .get(workOrderTypeId).orderNumber; - if (currentOrderNumber <= 0) { - database.close(); - return true; - } + if (currentOrderNumber <= 0) { + database.close(); + return true; + } - database - .prepare("update WorkOrderTypes" + + database + .prepare( + "update WorkOrderTypes" + " set orderNumber = orderNumber + 1" + " where recordDelete_timeMillis is null" + - " and orderNumber = ? - 1") - .run(currentOrderNumber); + " and orderNumber = ? - 1" + ) + .run(currentOrderNumber); - const result = database - .prepare("update WorkOrderTypes" + + const result = database + .prepare( + "update WorkOrderTypes" + " set orderNumber = ? - 1" + - " where workOrderTypeId = ?") - .run(currentOrderNumber, workOrderTypeId); + " where workOrderTypeId = ?" + ) + .run(currentOrderNumber, workOrderTypeId); - database.close(); + database.close(); - clearWorkOrderTypesCache(); + clearWorkOrderTypesCache(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default moveWorkOrderTypeUp; \ No newline at end of file +export default moveWorkOrderTypeUp; diff --git a/helpers/lotOccupancyDB/updateFee.js b/helpers/lotOccupancyDB/updateFee.js index b9ada7cb..27a5157b 100644 --- a/helpers/lotOccupancyDB/updateFee.js +++ b/helpers/lotOccupancyDB/updateFee.js @@ -21,7 +21,7 @@ export const updateFee = (feeForm, requestSession) => { " recordUpdate_timeMillis = ?" + " where recordDelete_timeMillis is null" + " and feeId = ?") - .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), requestSession.user.userName, rightNowMillis, feeForm.feeId); + .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, requestSession.user.userName, rightNowMillis, feeForm.feeId); database.close(); return result.changes > 0; }; diff --git a/helpers/lotOccupancyDB/updateFee.ts b/helpers/lotOccupancyDB/updateFee.ts index aed68ab7..96c4800f 100644 --- a/helpers/lotOccupancyDB/updateFee.ts +++ b/helpers/lotOccupancyDB/updateFee.ts @@ -1,38 +1,36 @@ 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 UpdateFeeForm { feeId: string; feeCategoryId: string; feeName: string; feeDescription: string; - occupancyTypeId ? : string; - lotTypeId ? : string; - feeAmount ? : string; - feeFunction ? : string; - taxAmount ? : string; - taxPercentage ? : string; + occupancyTypeId?: string; + lotTypeId?: string; + feeAmount?: string; + feeFunction?: string; + taxAmount?: string; + taxPercentage?: string; includeQuantity: "" | "1"; - quantityUnit ? : string; + quantityUnit?: string; isRequired: "" | "1"; } +export const updateFee = ( + feeForm: UpdateFeeForm, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const updateFee = - (feeForm: UpdateFeeForm, requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update Fees" + + const result = database + .prepare( + "update Fees" + " set feeCategoryId = ?," + " feeName = ?," + " feeDescription = ?," + @@ -48,27 +46,29 @@ export const updateFee = " recordUpdate_userName = ?," + " recordUpdate_timeMillis = ?" + " where recordDelete_timeMillis is null" + - " and feeId = ?") - .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), - requestSession.user.userName, - rightNowMillis, - feeForm.feeId); + " and feeId = ?" + ) + .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, + requestSession.user.userName, + rightNowMillis, + feeForm.feeId + ); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default updateFee; \ No newline at end of file +export default updateFee; diff --git a/helpers/lotOccupancyDB/updateFeeCategory.ts b/helpers/lotOccupancyDB/updateFeeCategory.ts index 4fd611f3..725d47b2 100644 --- a/helpers/lotOccupancyDB/updateFeeCategory.ts +++ b/helpers/lotOccupancyDB/updateFeeCategory.ts @@ -1,41 +1,41 @@ 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 UpdateFeeCategoryForm { feeCategoryId: number | string; feeCategory: string; } +export const updateFeeCategory = ( + feeCategoryForm: UpdateFeeCategoryForm, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const updateFeeCategory = - (feeCategoryForm: UpdateFeeCategoryForm, requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update FeeCategories" + + const result = database + .prepare( + "update FeeCategories" + " set feeCategory = ?," + " recordUpdate_userName = ?," + " recordUpdate_timeMillis = ?" + " where recordDelete_timeMillis is null" + - " and feeCategoryId = ?") - .run(feeCategoryForm.feeCategory, - requestSession.user.userName, - rightNowMillis, - feeCategoryForm.feeCategoryId); + " and feeCategoryId = ?" + ) + .run( + feeCategoryForm.feeCategory, + requestSession.user.userName, + rightNowMillis, + feeCategoryForm.feeCategoryId + ); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default updateFeeCategory; \ No newline at end of file +export default updateFeeCategory; diff --git a/helpers/lotOccupancyDB/updateLot.js b/helpers/lotOccupancyDB/updateLot.js index b03d970a..2cf65a28 100644 --- a/helpers/lotOccupancyDB/updateLot.js +++ b/helpers/lotOccupancyDB/updateLot.js @@ -16,7 +16,7 @@ export function updateLot(lotForm, requestSession) { " recordUpdate_timeMillis = ?" + " where lotId = ?" + " and recordDelete_timeMillis is null") - .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, lotForm.lotId); + .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, lotForm.lotId); database.close(); return result.changes > 0; } @@ -30,7 +30,7 @@ export function updateLotStatus(lotId, lotStatusId, requestSession) { " recordUpdate_timeMillis = ?" + " where lotId = ?" + " and recordDelete_timeMillis is null") - .run((lotStatusId === "" ? undefined : lotStatusId), requestSession.user.userName, rightNowMillis, lotId); + .run(lotStatusId === "" ? undefined : lotStatusId, requestSession.user.userName, rightNowMillis, lotId); database.close(); return result.changes > 0; } diff --git a/helpers/lotOccupancyDB/updateLot.ts b/helpers/lotOccupancyDB/updateLot.ts index ff7b5e33..ed298b0b 100644 --- a/helpers/lotOccupancyDB/updateLot.ts +++ b/helpers/lotOccupancyDB/updateLot.ts @@ -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 UpdateLotForm { lotId: string | number; lotName: string; @@ -20,64 +17,75 @@ interface UpdateLotForm { lotLongitude: string; } - -export function updateLot(lotForm: UpdateLotForm, requestSession: recordTypes.PartialSession): boolean { - +export function updateLot( + lotForm: UpdateLotForm, + requestSession: recordTypes.PartialSession +): boolean { const database = sqlite(databasePath); const rightNowMillis = Date.now(); const result = database - .prepare("update Lots" + - " set lotName = ?," + - " lotTypeId = ?," + - " lotStatusId = ?," + - " mapId = ?," + - " mapKey = ?," + - " lotLatitude = ?," + - " lotLongitude = ?," + - " recordUpdate_userName = ?," + - " recordUpdate_timeMillis = ?" + - " where lotId = ?" + - " and recordDelete_timeMillis is null") - .run(lotForm.lotName, + .prepare( + "update Lots" + + " set lotName = ?," + + " lotTypeId = ?," + + " lotStatusId = ?," + + " mapId = ?," + + " mapKey = ?," + + " lotLatitude = ?," + + " lotLongitude = ?," + + " recordUpdate_userName = ?," + + " recordUpdate_timeMillis = ?" + + " where lotId = ?" + + " and recordDelete_timeMillis is null" + ) + .run( + lotForm.lotName, lotForm.lotTypeId, - (lotForm.lotStatusId === "" ? undefined : lotForm.lotStatusId), - (lotForm.mapId === "" ? undefined : lotForm.mapId), + lotForm.lotStatusId === "" ? undefined : lotForm.lotStatusId, + lotForm.mapId === "" ? undefined : lotForm.mapId, lotForm.mapKey, - (lotForm.lotLatitude === "" ? undefined : lotForm.lotLatitude), - (lotForm.lotLongitude === "" ? undefined : lotForm.lotLongitude), + lotForm.lotLatitude === "" ? undefined : lotForm.lotLatitude, + lotForm.lotLongitude === "" ? undefined : lotForm.lotLongitude, requestSession.user.userName, rightNowMillis, - lotForm.lotId); + lotForm.lotId + ); database.close(); return result.changes > 0; } -export function updateLotStatus(lotId: number | string, lotStatusId: number | string, requestSession: recordTypes.PartialSession): boolean { - +export function updateLotStatus( + lotId: number | string, + lotStatusId: number | string, + requestSession: recordTypes.PartialSession +): boolean { const database = sqlite(databasePath); const rightNowMillis = Date.now(); const result = database - .prepare("update Lots" + - " set lotStatusId = ?," + - " recordUpdate_userName = ?," + - " recordUpdate_timeMillis = ?" + - " where lotId = ?" + - " and recordDelete_timeMillis is null") - .run((lotStatusId === "" ? undefined : lotStatusId), + .prepare( + "update Lots" + + " set lotStatusId = ?," + + " recordUpdate_userName = ?," + + " recordUpdate_timeMillis = ?" + + " where lotId = ?" + + " and recordDelete_timeMillis is null" + ) + .run( + lotStatusId === "" ? undefined : lotStatusId, requestSession.user.userName, rightNowMillis, - lotId); + lotId + ); database.close(); return result.changes > 0; } - -export default updateLot; \ No newline at end of file +export default updateLot; diff --git a/helpers/lotOccupancyDB/updateLotComment.ts b/helpers/lotOccupancyDB/updateLotComment.ts index 7a4cd6d9..a4c355cf 100644 --- a/helpers/lotOccupancyDB/updateLotComment.ts +++ b/helpers/lotOccupancyDB/updateLotComment.ts @@ -1,16 +1,11 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - dateStringToInteger -} from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import { dateStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js"; import type * as recordTypes from "../../types/recordTypes"; - interface UpdateLotCommentForm { lotCommentId: string | number; lotCommentDateString: string; @@ -18,34 +13,37 @@ interface UpdateLotCommentForm { lotComment: string; } +export const updateLotComment = ( + commentForm: UpdateLotCommentForm, + requestSession: recordTypes.PartialSession +): boolean => { + const rightNowMillis = Date.now(); -export const updateLotComment = - (commentForm: UpdateLotCommentForm, requestSession: recordTypes.PartialSession): boolean => { + const database = sqlite(databasePath); - const rightNowMillis = Date.now(); - - const database = sqlite(databasePath); - - const result = database - .prepare("update LotComments" + + const result = database + .prepare( + "update LotComments" + " set lotCommentDate = ?," + " lotCommentTime = ?," + " lotComment = ?," + " recordUpdate_userName = ?," + " recordUpdate_timeMillis = ?" + " where recordDelete_timeMillis is null" + - " and lotCommentId = ?") - .run(dateStringToInteger(commentForm.lotCommentDateString), - dateStringToInteger(commentForm.lotCommentTimeString), - commentForm.lotComment, - requestSession.user.userName, - rightNowMillis, - commentForm.lotCommentId); + " and lotCommentId = ?" + ) + .run( + dateStringToInteger(commentForm.lotCommentDateString), + dateStringToInteger(commentForm.lotCommentTimeString), + commentForm.lotComment, + requestSession.user.userName, + rightNowMillis, + commentForm.lotCommentId + ); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default updateLotComment; \ No newline at end of file +export default updateLotComment; diff --git a/helpers/lotOccupancyDB/updateLotOccupancy.js b/helpers/lotOccupancyDB/updateLotOccupancy.js index 2539d46b..cd35452b 100644 --- a/helpers/lotOccupancyDB/updateLotOccupancy.js +++ b/helpers/lotOccupancyDB/updateLotOccupancy.js @@ -16,7 +16,9 @@ export function updateLotOccupancy(lotOccupancyForm, requestSession) { " recordUpdate_timeMillis = ?" + " where lotOccupancyId = ?" + " and recordDelete_timeMillis is null") - .run(lotOccupancyForm.occupancyTypeId, (lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId), dateStringToInteger(lotOccupancyForm.occupancyStartDateString), (lotOccupancyForm.occupancyEndDateString === "" ? undefined : dateStringToInteger(lotOccupancyForm.occupancyEndDateString)), requestSession.user.userName, rightNowMillis, lotOccupancyForm.lotOccupancyId); + .run(lotOccupancyForm.occupancyTypeId, lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId, dateStringToInteger(lotOccupancyForm.occupancyStartDateString), lotOccupancyForm.occupancyEndDateString === "" + ? undefined + : dateStringToInteger(lotOccupancyForm.occupancyEndDateString), requestSession.user.userName, rightNowMillis, lotOccupancyForm.lotOccupancyId); if (result.changes > 0) { const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds || "").split(","); for (const occupancyTypeFieldId of occupancyTypeFieldIds) { diff --git a/helpers/lotOccupancyDB/updateLotOccupancy.ts b/helpers/lotOccupancyDB/updateLotOccupancy.ts index 65b68503..637f2e30 100644 --- a/helpers/lotOccupancyDB/updateLotOccupancy.ts +++ b/helpers/lotOccupancyDB/updateLotOccupancy.ts @@ -1,24 +1,15 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - dateStringToInteger -} from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import { dateStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js"; -import { - addOrUpdateLotOccupancyField -} from "./addOrUpdateLotOccupancyField.js"; +import { addOrUpdateLotOccupancyField } from "./addOrUpdateLotOccupancyField.js"; -import { - deleteLotOccupancyField -} from "./deleteLotOccupancyField.js"; +import { deleteLotOccupancyField } from "./deleteLotOccupancyField.js"; import type * as recordTypes from "../../types/recordTypes"; - interface UpdateLotOccupancyForm { lotOccupancyId: string | number; occupancyTypeId: string | number; @@ -31,50 +22,65 @@ interface UpdateLotOccupancyForm { [lotOccupancyFieldValue_occupancyTypeFieldId: string]: unknown; } - -export function updateLotOccupancy(lotOccupancyForm: UpdateLotOccupancyForm, requestSession: recordTypes.PartialSession): boolean { - +export function updateLotOccupancy( + lotOccupancyForm: UpdateLotOccupancyForm, + requestSession: recordTypes.PartialSession +): boolean { const database = sqlite(databasePath); const rightNowMillis = Date.now(); const result = database - .prepare("update LotOccupancies" + - " set occupancyTypeId = ?," + - " lotId = ?," + - " occupancyStartDate = ?," + - " occupancyEndDate = ?," + - " recordUpdate_userName = ?," + - " recordUpdate_timeMillis = ?" + - " where lotOccupancyId = ?" + - " and recordDelete_timeMillis is null") - .run(lotOccupancyForm.occupancyTypeId, - (lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId), + .prepare( + "update LotOccupancies" + + " set occupancyTypeId = ?," + + " lotId = ?," + + " occupancyStartDate = ?," + + " occupancyEndDate = ?," + + " recordUpdate_userName = ?," + + " recordUpdate_timeMillis = ?" + + " where lotOccupancyId = ?" + + " and recordDelete_timeMillis is null" + ) + .run( + lotOccupancyForm.occupancyTypeId, + lotOccupancyForm.lotId === "" ? undefined : lotOccupancyForm.lotId, dateStringToInteger(lotOccupancyForm.occupancyStartDateString), - (lotOccupancyForm.occupancyEndDateString === "" ? undefined : dateStringToInteger(lotOccupancyForm.occupancyEndDateString)), + lotOccupancyForm.occupancyEndDateString === "" + ? undefined + : dateStringToInteger(lotOccupancyForm.occupancyEndDateString), requestSession.user.userName, rightNowMillis, - lotOccupancyForm.lotOccupancyId); + lotOccupancyForm.lotOccupancyId + ); if (result.changes > 0) { - - const occupancyTypeFieldIds = (lotOccupancyForm.occupancyTypeFieldIds || "").split(","); + const occupancyTypeFieldIds = ( + lotOccupancyForm.occupancyTypeFieldIds || "" + ).split(","); for (const occupancyTypeFieldId of occupancyTypeFieldIds) { - - const lotOccupancyFieldValue = lotOccupancyForm["lotOccupancyFieldValue_" + occupancyTypeFieldId] as string; + const lotOccupancyFieldValue = lotOccupancyForm[ + "lotOccupancyFieldValue_" + occupancyTypeFieldId + ] as string; if (lotOccupancyFieldValue && lotOccupancyFieldValue !== "") { - addOrUpdateLotOccupancyField({ - lotOccupancyId: lotOccupancyForm.lotOccupancyId, - occupancyTypeFieldId, - lotOccupancyFieldValue - }, requestSession, database); + addOrUpdateLotOccupancyField( + { + lotOccupancyId: lotOccupancyForm.lotOccupancyId, + occupancyTypeFieldId, + lotOccupancyFieldValue + }, + requestSession, + database + ); } else { - deleteLotOccupancyField(lotOccupancyForm.lotOccupancyId, + deleteLotOccupancyField( + lotOccupancyForm.lotOccupancyId, occupancyTypeFieldId, requestSession, - database); + database + ); } } } @@ -84,5 +90,4 @@ export function updateLotOccupancy(lotOccupancyForm: UpdateLotOccupancyForm, req return result.changes > 0; } - -export default updateLotOccupancy; \ No newline at end of file +export default updateLotOccupancy; diff --git a/helpers/lotOccupancyDB/updateLotOccupancyComment.ts b/helpers/lotOccupancyDB/updateLotOccupancyComment.ts index a7f11e3a..2cf570f1 100644 --- a/helpers/lotOccupancyDB/updateLotOccupancyComment.ts +++ b/helpers/lotOccupancyDB/updateLotOccupancyComment.ts @@ -1,16 +1,11 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - dateStringToInteger -} from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import { dateStringToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js"; import type * as recordTypes from "../../types/recordTypes"; - interface UpdateLotOccupancyCommentForm { lotOccupancyCommentId: string | number; lotOccupancyCommentDateString: string; @@ -18,34 +13,37 @@ interface UpdateLotOccupancyCommentForm { lotOccupancyComment: string; } +export const updateLotOccupancyComment = ( + commentForm: UpdateLotOccupancyCommentForm, + requestSession: recordTypes.PartialSession +): boolean => { + const rightNowMillis = Date.now(); -export const updateLotOccupancyComment = - (commentForm: UpdateLotOccupancyCommentForm, requestSession: recordTypes.PartialSession): boolean => { + const database = sqlite(databasePath); - const rightNowMillis = Date.now(); - - const database = sqlite(databasePath); - - const result = database - .prepare("update LotOccupancyComments" + + const result = database + .prepare( + "update LotOccupancyComments" + " set lotOccupancyCommentDate = ?," + " lotOccupancyCommentTime = ?," + " lotOccupancyComment = ?," + " recordUpdate_userName = ?," + " recordUpdate_timeMillis = ?" + " where recordDelete_timeMillis is null" + - " and lotOccupancyCommentId = ?") - .run(dateStringToInteger(commentForm.lotOccupancyCommentDateString), - dateStringToInteger(commentForm.lotOccupancyCommentTimeString), - commentForm.lotOccupancyComment, - requestSession.user.userName, - rightNowMillis, - commentForm.lotOccupancyCommentId); + " and lotOccupancyCommentId = ?" + ) + .run( + dateStringToInteger(commentForm.lotOccupancyCommentDateString), + dateStringToInteger(commentForm.lotOccupancyCommentTimeString), + commentForm.lotOccupancyComment, + requestSession.user.userName, + rightNowMillis, + commentForm.lotOccupancyCommentId + ); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default updateLotOccupancyComment; \ No newline at end of file +export default updateLotOccupancyComment; diff --git a/helpers/lotOccupancyDB/updateLotOccupancyOccupant.ts b/helpers/lotOccupancyDB/updateLotOccupancyOccupant.ts index 669dbde6..5d7aa0cb 100644 --- a/helpers/lotOccupancyDB/updateLotOccupancyOccupant.ts +++ b/helpers/lotOccupancyDB/updateLotOccupancyOccupant.ts @@ -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 UpdateLotOccupancyOccupantForm { lotOccupancyId: string | number; lotOccupantIndex: string | number; @@ -20,46 +17,49 @@ interface UpdateLotOccupancyOccupantForm { occupantPhoneNumber: string; } +export const updateLotOccupancyOccupant = ( + lotOccupancyOccupantForm: UpdateLotOccupancyOccupantForm, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const updateLotOccupancyOccupant = - (lotOccupancyOccupantForm: UpdateLotOccupancyOccupantForm, requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); + const results = database + .prepare( + "update LotOccupancyOccupants" + + " set occupantName = ?," + + " occupantAddress1 = ?," + + " occupantAddress2 = ?," + + " occupantCity = ?," + + " occupantProvince = ?," + + " occupantPostalCode = ?," + + " occupantPhoneNumber = ?," + + " lotOccupantTypeId = ?," + + " recordUpdate_userName = ?," + + " recordUpdate_timeMillis = ?" + + " where recordDelete_timeMillis is null" + + " and lotOccupancyId = ?" + + " and lotOccupantIndex = ?" + ) + .run( + lotOccupancyOccupantForm.occupantName, + lotOccupancyOccupantForm.occupantAddress1, + lotOccupancyOccupantForm.occupantAddress2, + lotOccupancyOccupantForm.occupantCity, + lotOccupancyOccupantForm.occupantProvince, + lotOccupancyOccupantForm.occupantPostalCode, + lotOccupancyOccupantForm.occupantPhoneNumber, + lotOccupancyOccupantForm.lotOccupantTypeId, + requestSession.user.userName, + rightNowMillis, + lotOccupancyOccupantForm.lotOccupancyId, + lotOccupancyOccupantForm.lotOccupantIndex + ); - const rightNowMillis = Date.now(); + database.close(); - const results = database - .prepare("update LotOccupancyOccupants" + - " set occupantName = ?," + - " occupantAddress1 = ?," + - " occupantAddress2 = ?," + - " occupantCity = ?," + - " occupantProvince = ?," + - " occupantPostalCode = ?," + - " occupantPhoneNumber = ?," + - " lotOccupantTypeId = ?," + - " recordUpdate_userName = ?," + - " recordUpdate_timeMillis = ?" + - " where recordDelete_timeMillis is null" + - " and lotOccupancyId = ?" + - " and lotOccupantIndex = ?") - .run(lotOccupancyOccupantForm.occupantName, - lotOccupancyOccupantForm.occupantAddress1, - lotOccupancyOccupantForm.occupantAddress2, - lotOccupancyOccupantForm.occupantCity, - lotOccupancyOccupantForm.occupantProvince, - lotOccupancyOccupantForm.occupantPostalCode, - lotOccupancyOccupantForm.occupantPhoneNumber, - lotOccupancyOccupantForm.lotOccupantTypeId, - requestSession.user.userName, - rightNowMillis, - lotOccupancyOccupantForm.lotOccupancyId, - lotOccupancyOccupantForm.lotOccupantIndex); + return results.changes > 0; +}; - database.close(); - - return results.changes > 0; - }; - - -export default updateLotOccupancyOccupant; \ No newline at end of file +export default updateLotOccupancyOccupant; diff --git a/helpers/lotOccupancyDB/updateLotOccupantType.ts b/helpers/lotOccupancyDB/updateLotOccupantType.ts index 4de68af7..2b61850e 100644 --- a/helpers/lotOccupancyDB/updateLotOccupantType.ts +++ b/helpers/lotOccupancyDB/updateLotOccupantType.ts @@ -1,47 +1,45 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearLotOccupantTypesCache -} from "../functions.cache.js"; +import { clearLotOccupantTypesCache } from "../functions.cache.js"; import type * as recordTypes from "../../types/recordTypes"; - interface UpdateLotOccupantTypeForm { lotOccupantTypeId: number | string; lotOccupantType: string; } +export const updateLotOccupantType = ( + lotOccupantTypeForm: UpdateLotOccupantTypeForm, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const updateLotOccupantType = - (lotOccupantTypeForm: UpdateLotOccupantTypeForm, requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotOccupantTypes" + + const result = database + .prepare( + "update LotOccupantTypes" + " set lotOccupantType = ?," + " recordUpdate_userName = ?," + " recordUpdate_timeMillis = ?" + " where lotOccupantTypeId = ?" + - " and recordDelete_timeMillis is null") - .run(lotOccupantTypeForm.lotOccupantType, - requestSession.user.userName, - rightNowMillis, - lotOccupantTypeForm.lotOccupantTypeId); + " and recordDelete_timeMillis is null" + ) + .run( + lotOccupantTypeForm.lotOccupantType, + requestSession.user.userName, + rightNowMillis, + lotOccupantTypeForm.lotOccupantTypeId + ); - database.close(); + database.close(); - clearLotOccupantTypesCache(); + clearLotOccupantTypesCache(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default updateLotOccupantType; \ No newline at end of file +export default updateLotOccupantType; diff --git a/helpers/lotOccupancyDB/updateLotStatus.ts b/helpers/lotOccupancyDB/updateLotStatus.ts index 8e5d3ac8..95226c78 100644 --- a/helpers/lotOccupancyDB/updateLotStatus.ts +++ b/helpers/lotOccupancyDB/updateLotStatus.ts @@ -1,47 +1,45 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearLotStatusesCache -} from "../functions.cache.js"; +import { clearLotStatusesCache } from "../functions.cache.js"; import type * as recordTypes from "../../types/recordTypes"; - interface UpdateLotStatusForm { lotStatusId: number | string; lotStatus: string; } +export const updateLotStatus = ( + lotStatusForm: UpdateLotStatusForm, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const updateLotStatus = - (lotStatusForm: UpdateLotStatusForm, requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update LotStatuses" + + const result = database + .prepare( + "update LotStatuses" + " set lotStatus = ?," + " recordUpdate_userName = ?," + " recordUpdate_timeMillis = ?" + " where lotStatusId = ?" + - " and recordDelete_timeMillis is null") - .run(lotStatusForm.lotStatus, - requestSession.user.userName, - rightNowMillis, - lotStatusForm.lotStatusId); + " and recordDelete_timeMillis is null" + ) + .run( + lotStatusForm.lotStatus, + requestSession.user.userName, + rightNowMillis, + lotStatusForm.lotStatusId + ); - database.close(); + database.close(); - clearLotStatusesCache(); + clearLotStatusesCache(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default updateLotStatus; \ No newline at end of file +export default updateLotStatus; diff --git a/helpers/lotOccupancyDB/updateMap.js b/helpers/lotOccupancyDB/updateMap.js index aea642bb..1a42f272 100644 --- a/helpers/lotOccupancyDB/updateMap.js +++ b/helpers/lotOccupancyDB/updateMap.js @@ -20,7 +20,7 @@ export const updateMap = (mapForm, requestSession) => { " recordUpdate_timeMillis = ?" + " where mapId = ?" + " and recordDelete_timeMillis is null") - .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, mapForm.mapId); + .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, mapForm.mapId); database.close(); return result.changes > 0; }; diff --git a/helpers/lotOccupancyDB/updateMap.ts b/helpers/lotOccupancyDB/updateMap.ts index 286fc8de..6a825e64 100644 --- a/helpers/lotOccupancyDB/updateMap.ts +++ b/helpers/lotOccupancyDB/updateMap.ts @@ -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 UpdateMapForm { mapId: string; mapName: string; @@ -22,16 +19,17 @@ interface UpdateMapForm { mapPhoneNumber: string; } +export const updateMap = ( + mapForm: UpdateMapForm, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const updateMap = - (mapForm: UpdateMapForm, requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update Maps" + + const result = database + .prepare( + "update Maps" + " set mapName = ?," + " mapDescription = ?," + " mapSVG = ?," + @@ -46,26 +44,28 @@ export const updateMap = " recordUpdate_userName = ?," + " recordUpdate_timeMillis = ?" + " where mapId = ?" + - " and recordDelete_timeMillis is null") - .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, - mapForm.mapId); + " and recordDelete_timeMillis is null" + ) + .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, + mapForm.mapId + ); - database.close(); + database.close(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default updateMap; \ No newline at end of file +export default updateMap; diff --git a/helpers/lotOccupancyDB/updateWorkOrderType.ts b/helpers/lotOccupancyDB/updateWorkOrderType.ts index 40902e26..7f7cc6a0 100644 --- a/helpers/lotOccupancyDB/updateWorkOrderType.ts +++ b/helpers/lotOccupancyDB/updateWorkOrderType.ts @@ -1,47 +1,45 @@ import sqlite from "better-sqlite3"; -import { - lotOccupancyDB as databasePath -} from "../../data/databasePaths.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; -import { - clearWorkOrderTypesCache -} from "../functions.cache.js"; +import { clearWorkOrderTypesCache } from "../functions.cache.js"; import type * as recordTypes from "../../types/recordTypes"; - interface UpdateWorkOrderTypeForm { workOrderTypeId: number | string; workOrderType: string; } +export const updateWorkOrderType = ( + workOrderTypeForm: UpdateWorkOrderTypeForm, + requestSession: recordTypes.PartialSession +): boolean => { + const database = sqlite(databasePath); -export const updateWorkOrderType = - (workOrderTypeForm: UpdateWorkOrderTypeForm, requestSession: recordTypes.PartialSession): boolean => { + const rightNowMillis = Date.now(); - const database = sqlite(databasePath); - - const rightNowMillis = Date.now(); - - const result = database - .prepare("update WorkOrderTypes" + + const result = database + .prepare( + "update WorkOrderTypes" + " set workOrderType = ?," + " recordUpdate_userName = ?," + " recordUpdate_timeMillis = ?" + " where workOrderTypeId = ?" + - " and recordDelete_timeMillis is null") - .run(workOrderTypeForm.workOrderType, - requestSession.user.userName, - rightNowMillis, - workOrderTypeForm.workOrderTypeId); + " and recordDelete_timeMillis is null" + ) + .run( + workOrderTypeForm.workOrderType, + requestSession.user.userName, + rightNowMillis, + workOrderTypeForm.workOrderTypeId + ); - database.close(); + database.close(); - clearWorkOrderTypesCache(); + clearWorkOrderTypesCache(); - return result.changes > 0; - }; + return result.changes > 0; +}; - -export default updateWorkOrderType; \ No newline at end of file +export default updateWorkOrderType; diff --git a/package.json b/package.json index 7989dd6d..5b80713e 100644 --- a/package.json +++ b/package.json @@ -1,98 +1,98 @@ { - "name": "lot-occupancy-system", - "version": "1.0.0-dev", - "type": "module", - "description": "A system for managing the occupancy of lots. (i.e. Cemetery management)", - "exports": "./app.js", - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "scripts": { - "build:version": "npx genversion --es6 --semi version.js", - "init:cemetery": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* node ./helpers/initializer.database.cemetery.js", - "init:cemetery:test": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true node ./helpers/initializer.database.cemetery.js", - "start": "cross-env NODE_ENV=production node ./bin/www", - "dev:test": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true nodemon ./bin/www.js", - "dev:live": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* nodemon ./bin/www.js", - "cy:open": "cypress open --config-file cypress.config.ts", - "cy:run": "cypress run --config-file cypress.config.ts", - "test": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true mocha --timeout 30000 --exit", - "coverage": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true c8 --reporter=lcov --reporter=text --reporter=text-summary mocha --timeout 30000 --exit", - "temp:legacy:importFromCsv": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true node ./temp/legacy.importFromCsv.js", - "temp:so:exportMaps": "node ./temp/so.exportMaps.js" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/cityssm/lot-occupancy-manager.git" - }, - "author": "The Corporation of the City of Sault Ste. Marie", - "license": "MIT", - "bugs": { - "url": "https://github.com/cityssm/lot-occupancy-manager/issues" - }, - "homepage": "https://github.com/cityssm/lot-occupancy-manager#readme", - "private": true, - "dependencies": { - "@cityssm/bulma-js": "^0.3.3", - "@cityssm/bulma-webapp-js": "^1.5.0", - "@cityssm/date-diff": "^2.2.3", - "@cityssm/expressjs-server-js": "^2.3.2", - "@fortawesome/fontawesome-free": "^5.15.4", - "activedirectory2": "^2.1.0", - "better-sqlite3": "^7.6.2", - "camelcase": "^7.0.0", - "compression": "^1.7.4", - "cookie-parser": "^1.4.6", - "cross-env": "^7.0.3", - "csurf": "^1.11.0", - "debug": "^4.3.4", - "ejs": "^3.1.8", - "exit-hook": "^3.1.0", - "express": "^4.18.1", - "express-rate-limit": "^6.5.2", - "express-session": "^1.17.3", - "http-errors": "^2.0.0", - "leaflet": "^1.8.0", - "papaparse": "^5.3.2", - "session-file-store": "^1.5.0" - }, - "devDependencies": { - "@cityssm/bulma-webapp-css": "^0.11.0", - "@cityssm/mssql-multi-pool": "^2.1.6", - "@types/activedirectory2": "^1.2.3", - "@types/better-sqlite3": "^7.6.0", - "@types/compression": "^1.7.2", - "@types/cookie-parser": "^1.4.3", - "@types/csurf": "^1.11.2", - "@types/debug": "^4.1.7", - "@types/ejs": "^3.1.1", - "@types/express": "^4.17.13", - "@types/express-session": "^1.17.5", - "@types/gulp": "^4.0.9", - "@types/gulp-changed": "^0.0.35", - "@types/gulp-minify": "^3.1.1", - "@types/gulp-sass": "^5.0.0", - "@types/http-errors": "^1.8.2", - "@types/leaflet": "^1.7.11", - "@types/mocha": "^9.1.1", - "@types/node-windows": "^0.1.2", - "@types/papaparse": "^5.3.5", - "@types/session-file-store": "^1.2.2", - "@typescript-eslint/eslint-plugin": "^5.36.1", - "@typescript-eslint/parser": "^5.36.1", - "bulma": "^0.9.4", - "cypress": "^10.7.0", - "cypress-axe": "^1.0.0", - "eslint": "^8.23.0", - "eslint-plugin-import": "^2.26.0", - "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^6.0.1", - "eslint-plugin-unicorn": "^43.0.2", - "gulp": "^4.0.2", - "gulp-changed": "^4.0.3", - "gulp-minify": "^3.1.0", - "gulp-sass": "^5.1.0", - "nodemon": "^2.0.19", - "sass": "^1.54.8" - } + "name": "lot-occupancy-system", + "version": "1.0.0-dev", + "type": "module", + "description": "A system for managing the occupancy of lots. (i.e. Cemetery management)", + "exports": "./app.js", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "scripts": { + "build:version": "npx genversion --es6 --semi version.js", + "init:cemetery": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* node ./helpers/initializer.database.cemetery.js", + "init:cemetery:test": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true node ./helpers/initializer.database.cemetery.js", + "start": "cross-env NODE_ENV=production node ./bin/www", + "dev:test": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true nodemon ./bin/www.js", + "dev:live": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* nodemon ./bin/www.js", + "cy:open": "cypress open --config-file cypress.config.ts", + "cy:run": "cypress run --config-file cypress.config.ts", + "test": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true mocha --timeout 30000 --exit", + "coverage": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true c8 --reporter=lcov --reporter=text --reporter=text-summary mocha --timeout 30000 --exit", + "temp:legacy:importFromCsv": "cross-env NODE_ENV=dev DEBUG=lot-occupancy-system:* TEST_DATABASES=true node ./temp/legacy.importFromCsv.js", + "temp:so:exportMaps": "node ./temp/so.exportMaps.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/cityssm/lot-occupancy-manager.git" + }, + "author": "The Corporation of the City of Sault Ste. Marie", + "license": "MIT", + "bugs": { + "url": "https://github.com/cityssm/lot-occupancy-manager/issues" + }, + "homepage": "https://github.com/cityssm/lot-occupancy-manager#readme", + "private": true, + "dependencies": { + "@cityssm/bulma-js": "^0.3.3", + "@cityssm/bulma-webapp-js": "^1.5.0", + "@cityssm/date-diff": "^2.2.3", + "@cityssm/expressjs-server-js": "^2.3.2", + "@fortawesome/fontawesome-free": "^5.15.4", + "activedirectory2": "^2.1.0", + "better-sqlite3": "^7.6.2", + "camelcase": "^7.0.0", + "compression": "^1.7.4", + "cookie-parser": "^1.4.6", + "cross-env": "^7.0.3", + "csurf": "^1.11.0", + "debug": "^4.3.4", + "ejs": "^3.1.8", + "exit-hook": "^3.1.0", + "express": "^4.18.1", + "express-rate-limit": "^6.5.2", + "express-session": "^1.17.3", + "http-errors": "^2.0.0", + "leaflet": "^1.8.0", + "papaparse": "^5.3.2", + "session-file-store": "^1.5.0" + }, + "devDependencies": { + "@cityssm/bulma-webapp-css": "^0.11.0", + "@cityssm/mssql-multi-pool": "^2.1.6", + "@types/activedirectory2": "^1.2.3", + "@types/better-sqlite3": "^7.6.0", + "@types/compression": "^1.7.2", + "@types/cookie-parser": "^1.4.3", + "@types/csurf": "^1.11.2", + "@types/debug": "^4.1.7", + "@types/ejs": "^3.1.1", + "@types/express": "^4.17.13", + "@types/express-session": "^1.17.5", + "@types/gulp": "^4.0.9", + "@types/gulp-changed": "^0.0.35", + "@types/gulp-minify": "^3.1.1", + "@types/gulp-sass": "^5.0.0", + "@types/http-errors": "^1.8.2", + "@types/leaflet": "^1.7.11", + "@types/mocha": "^9.1.1", + "@types/node-windows": "^0.1.2", + "@types/papaparse": "^5.3.5", + "@types/session-file-store": "^1.2.2", + "@typescript-eslint/eslint-plugin": "^5.36.1", + "@typescript-eslint/parser": "^5.36.1", + "bulma": "^0.9.4", + "cypress": "^10.7.0", + "cypress-axe": "^1.0.0", + "eslint": "^8.23.0", + "eslint-plugin-import": "^2.26.0", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-promise": "^6.0.1", + "eslint-plugin-unicorn": "^43.0.2", + "gulp": "^4.0.2", + "gulp-changed": "^4.0.3", + "gulp-minify": "^3.1.0", + "gulp-sass": "^5.1.0", + "nodemon": "^2.0.19", + "sass": "^1.54.8" + } } diff --git a/public-typescript/adminFees.js b/public-typescript/adminFees.js index 97bbc899..34f1aba7 100644 --- a/public-typescript/adminFees.js +++ b/public-typescript/adminFees.js @@ -18,64 +18,67 @@ Object.defineProperty(exports, "__esModule", { value: true }); for (const feeCategory of feeCategories) { const feeCategoryContainerElement = document.createElement("section"); feeCategoryContainerElement.className = - "container--feeCategory mb-5"; + "panel container--feeCategory"; feeCategoryContainerElement.dataset.feeCategoryId = feeCategory.feeCategoryId.toString(); - feeCategoryContainerElement.insertAdjacentHTML("beforeend", '
' + - ('
' + - '
' + - '

' + - cityssm.escapeHTML(feeCategory.feeCategory) + - "

" + - "
" + - "
") + - ('
' + - (feeCategory.fees.length === 0 - ? '
' + - '" + + "
" + : "") + + ('
' + + '" + - "
" - : "") + - ('
' + - '" + + "
") + + ('
' + + '" + + "
") + + ('
' + + '
' + + '
' + + '" + + "
" + + '
' + + '" + + "
" + + "
" + + "
") + "
") + - ('
' + - '" + - "
") + - ('
' + - '
' + - '
' + - '" + - "
" + - '
' + - '" + - "
" + - "
" + - "
") + - "
") + - ""); + "" + + ""; if (feeCategory.fees.length === 0) { - feeCategoryContainerElement.insertAdjacentHTML("beforeend", '
' + + feeCategoryContainerElement.insertAdjacentHTML("beforeend", '
' + + '
' + '

There are no fees in the "' + cityssm.escapeHTML(feeCategory.feeCategory) + '" category.

' + + "
" + "
"); } else { - const panelElement = document.createElement("div"); - panelElement.className = "panel"; for (const fee of feeCategory.fees) { const panelBlockElement = document.createElement("div"); panelBlockElement.className = @@ -161,9 +164,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); panelBlockElement .querySelector(".button--moveFeeDown") .addEventListener("click", moveFeeDown); - panelElement.append(panelBlockElement); + feeCategoryContainerElement.append(panelBlockElement); } - feeCategoryContainerElement.append(panelElement); } if (feeCategory.fees.length === 0) { feeCategoryContainerElement diff --git a/public-typescript/adminFees.ts b/public-typescript/adminFees.ts index 3823ed8c..1ead6696 100644 --- a/public-typescript/adminFees.ts +++ b/public-typescript/adminFees.ts @@ -37,73 +37,74 @@ declare const bulmaJS: BulmaJS; for (const feeCategory of feeCategories) { const feeCategoryContainerElement = document.createElement("section"); + feeCategoryContainerElement.className = - "container--feeCategory mb-5"; + "panel container--feeCategory"; + feeCategoryContainerElement.dataset.feeCategoryId = feeCategory.feeCategoryId.toString(); - feeCategoryContainerElement.insertAdjacentHTML( - "beforeend", + feeCategoryContainerElement.innerHTML = + '
' + '
' + - ('
' + - '
' + - '

' + - cityssm.escapeHTML(feeCategory.feeCategory) + - "

" + + ('
' + + '
' + + '

' + + cityssm.escapeHTML(feeCategory.feeCategory) + + "

" + + "
" + + "
") + + ('
' + + (feeCategory.fees.length === 0 + ? '
' + + '" + + "
" + : "") + + ('
' + + '" + + "
") + + ('
' + + '" + + "
") + + ('
' + + '
' + + '
' + + '" + + "
" + + '
' + + '" + + "
" + "
" + "
") + - ('
' + - (feeCategory.fees.length === 0 - ? '
' + - '" + - "
" - : "") + - ('
' + - '" + - "
") + - ('
' + - '" + - "
") + - ('
' + - '
' + - '
' + - '" + - "
" + - '
' + - '" + - "
" + - "
" + - "
") + - "
") + - "
" - ); + "
") + + "
" + + "
"; if (feeCategory.fees.length === 0) { feeCategoryContainerElement.insertAdjacentHTML( "beforeend", - '
' + + '
' + + '
' + '

There are no fees in the "' + cityssm.escapeHTML(feeCategory.feeCategory) + '" category.

' + + "
" + "
" ); } else { - const panelElement = document.createElement("div"); - panelElement.className = "panel"; - for (const fee of feeCategory.fees) { const panelBlockElement = document.createElement("div"); panelBlockElement.className = @@ -195,10 +196,8 @@ declare const bulmaJS: BulmaJS; .querySelector(".button--moveFeeDown") .addEventListener("click", moveFeeDown); - panelElement.append(panelBlockElement); + feeCategoryContainerElement.append(panelBlockElement); } - - feeCategoryContainerElement.append(panelElement); } if (feeCategory.fees.length === 0) { diff --git a/public-typescript/adminOccupancyTypes.d.ts b/public-typescript/adminOccupancyTypes.d.ts index e69de29b..cb0ff5c3 100644 --- a/public-typescript/adminOccupancyTypes.d.ts +++ b/public-typescript/adminOccupancyTypes.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/public-typescript/adminOccupancyTypes.js b/public-typescript/adminOccupancyTypes.js index 8afef300..e9f7c071 100644 --- a/public-typescript/adminOccupancyTypes.js +++ b/public-typescript/adminOccupancyTypes.js @@ -1,2 +1,149 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); (() => { + const urlPrefix = document.querySelector("main").dataset.urlPrefix; + const containerElement = document.querySelector("#container--occupancyTypes"); + const occupancyTypes = exports.occupancyTypes; + delete exports.occupancyTypes; + const expandedOccupancyTypes = new Set(); + const toggleOccupancyTypeFields = (clickEvent) => { + const toggleButtonElement = clickEvent.currentTarget; + const occupancyTypeElement = toggleButtonElement.closest(".container--occupancyType"); + const occupancyTypeId = Number.parseInt(occupancyTypeElement.dataset.occupancyTypeId, 10); + if (expandedOccupancyTypes.has(occupancyTypeId)) { + expandedOccupancyTypes.delete(occupancyTypeId); + } + else { + expandedOccupancyTypes.add(occupancyTypeId); + } + toggleButtonElement.innerHTML = expandedOccupancyTypes.has(occupancyTypeId) + ? '' + : ''; + const panelBlockElements = occupancyTypeElement.querySelectorAll(".panel-block"); + for (const panelBlockElement of panelBlockElements) { + panelBlockElement.classList.toggle("is-hidden"); + } + }; + const renderOccupancyTypes = () => { + if (occupancyTypes.length === 0) { + containerElement.innerHTML = + '
There are no active ' + + exports.aliases.occupancy.toLowerCase() + + " types.

" + + "
"; + return; + } + containerElement.innerHTML = ""; + for (const occupancyType of occupancyTypes) { + const occupancyTypeContainer = document.createElement("div"); + occupancyTypeContainer.className = "panel container--occupancyType"; + occupancyTypeContainer.dataset.occupancyTypeId = + occupancyType.occupancyTypeId.toString(); + occupancyTypeContainer.innerHTML = + '
' + + '
' + + ('
' + + '
' + + '" + + "
" + + '
' + + '

' + + cityssm.escapeHTML(occupancyType.occupancyType) + + "

" + + "
" + + "
") + + ('
' + + '
' + + '" + + "
" + + '
' + + '" + + "
" + + ('
' + + '
' + + '
' + + '" + + "
" + + '
' + + '" + + "
" + + "
" + + "
") + + "
") + + "
" + + "
"; + if (occupancyType.occupancyTypeFields.length === 0) { + occupancyTypeContainer.insertAdjacentHTML("beforeend", '
' + + '
' + + '

There are no additional fields.

' + + "
" + + "
"); + } + else { + for (const occupancyTypeField of occupancyType.occupancyTypeFields) { + const panelBlockElement = document.createElement("div"); + panelBlockElement.className = + "panel-block is-block container--occupancyTypeField"; + if (!expandedOccupancyTypes.has(occupancyType.occupancyTypeId)) { + panelBlockElement.classList.add("is-hidden"); + } + panelBlockElement.dataset.occupancyTypeFieldId = + occupancyTypeField.occupancyTypeFieldId.toString(); + panelBlockElement.innerHTML = + '
' + + '" + + '
' + + ('
' + + '
' + + '
' + + '" + + "
" + + '
' + + '" + + "
" + + "
" + + "
") + + "
" + + "
"; + occupancyTypeContainer.append(panelBlockElement); + } + } + occupancyTypeContainer + .querySelector(".button--toggleOccupancyTypeFields") + .addEventListener("click", toggleOccupancyTypeFields); + containerElement.append(occupancyTypeContainer); + } + }; + renderOccupancyTypes(); })(); diff --git a/public-typescript/adminOccupancyTypes.ts b/public-typescript/adminOccupancyTypes.ts index 9afd6e69..76b15ec2 100644 --- a/public-typescript/adminOccupancyTypes.ts +++ b/public-typescript/adminOccupancyTypes.ts @@ -1,3 +1,204 @@ -(() => { +/* eslint-disable unicorn/prefer-module */ -})(); \ No newline at end of file +import type * as globalTypes from "../types/globalTypes"; +import type * as recordTypes from "../types/recordTypes"; + +import type { cityssmGlobal } from "@cityssm/bulma-webapp-js/src/types"; + +import type { BulmaJS } from "@cityssm/bulma-js/types"; + +declare const cityssm: cityssmGlobal; +declare const bulmaJS: BulmaJS; + +(() => { + const urlPrefix = document.querySelector("main").dataset.urlPrefix; + + const containerElement = document.querySelector( + "#container--occupancyTypes" + ) as HTMLElement; + + const occupancyTypes: recordTypes.OccupancyType[] = exports.occupancyTypes; + delete exports.occupancyTypes; + + const expandedOccupancyTypes = new Set(); + + const toggleOccupancyTypeFields = (clickEvent: Event) => { + const toggleButtonElement = + clickEvent.currentTarget as HTMLButtonElement; + + const occupancyTypeElement = toggleButtonElement.closest( + ".container--occupancyType" + ) as HTMLElement; + + const occupancyTypeId = Number.parseInt( + occupancyTypeElement.dataset.occupancyTypeId, + 10 + ); + + if (expandedOccupancyTypes.has(occupancyTypeId)) { + expandedOccupancyTypes.delete(occupancyTypeId); + } else { + expandedOccupancyTypes.add(occupancyTypeId); + } + + toggleButtonElement.innerHTML = expandedOccupancyTypes.has( + occupancyTypeId + ) + ? '' + : ''; + + const panelBlockElements = + occupancyTypeElement.querySelectorAll(".panel-block"); + + for (const panelBlockElement of panelBlockElements) { + panelBlockElement.classList.toggle("is-hidden"); + } + }; + + const renderOccupancyTypes = () => { + if (occupancyTypes.length === 0) { + containerElement.innerHTML = + '
There are no active ' + + exports.aliases.occupancy.toLowerCase() + + " types.

" + + "
"; + + return; + } + + containerElement.innerHTML = ""; + + for (const occupancyType of occupancyTypes) { + const occupancyTypeContainer = document.createElement("div"); + + occupancyTypeContainer.className = "panel container--occupancyType"; + + occupancyTypeContainer.dataset.occupancyTypeId = + occupancyType.occupancyTypeId.toString(); + + occupancyTypeContainer.innerHTML = + '
' + + '
' + + ('
' + + '
' + + '" + + "
" + + '
' + + '

' + + cityssm.escapeHTML(occupancyType.occupancyType) + + "

" + + "
" + + "
") + + ('
' + + '
' + + '" + + "
" + + '
' + + '" + + "
" + + ('
' + + '
' + + '
' + + '" + + "
" + + '
' + + '" + + "
" + + "
" + + "
") + + "
") + + "
" + + "
"; + + if (occupancyType.occupancyTypeFields.length === 0) { + occupancyTypeContainer.insertAdjacentHTML( + "beforeend", + '
' + + '
' + + '

There are no additional fields.

' + + "
" + + "
" + ); + } else { + for (const occupancyTypeField of occupancyType.occupancyTypeFields) { + const panelBlockElement = document.createElement("div"); + panelBlockElement.className = + "panel-block is-block container--occupancyTypeField"; + + if ( + !expandedOccupancyTypes.has( + occupancyType.occupancyTypeId + ) + ) { + panelBlockElement.classList.add("is-hidden"); + } + + panelBlockElement.dataset.occupancyTypeFieldId = + occupancyTypeField.occupancyTypeFieldId.toString(); + + panelBlockElement.innerHTML = + '
' + + '" + + '
' + + ('
' + + '
' + + '
' + + '" + + "
" + + '
' + + '" + + "
" + + "
" + + "
") + + "
" + + "
"; + + occupancyTypeContainer.append(panelBlockElement); + } + } + + occupancyTypeContainer + .querySelector(".button--toggleOccupancyTypeFields") + .addEventListener("click", toggleOccupancyTypeFields); + + containerElement.append(occupancyTypeContainer); + } + }; + + renderOccupancyTypes(); +})(); diff --git a/public/javascripts/adminFees.min.js b/public/javascripts/adminFees.min.js index cbb91b55..cd090e7d 100644 --- a/public/javascripts/adminFees.min.js +++ b/public/javascripts/adminFees.min.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const e=exports.los,t=document.querySelector("main").dataset.urlPrefix,s=document.querySelector("#container--feeCategories");let a=exports.feeCategories;delete exports.feeCategories;const o=()=>{if(0!==a.length){s.innerHTML="";for(const e of a){const t=document.createElement("section");if(t.className="container--feeCategory mb-5",t.dataset.feeCategoryId=e.feeCategoryId.toString(),t.insertAdjacentHTML("beforeend",'

'+cityssm.escapeHTML(e.feeCategory)+'

'+(0===e.fees.length?'
':"")+'
'),0===e.fees.length)t.insertAdjacentHTML("beforeend",'

There are no fees in the "'+cityssm.escapeHTML(e.feeCategory)+'" category.

');else{const s=document.createElement("div");s.className="panel";for(const t of e.fees){const e=document.createElement("div");e.className="panel-block is-block container--fee",e.dataset.feeId=t.feeId.toString(),e.innerHTML='

'+cityssm.escapeHTML(t.feeName)+"
"+cityssm.escapeHTML(t.feeDescription).replace(/\n/g,"
")+'

'+(t.isRequired?'Required':"")+(t.occupancyTypeId?' '+cityssm.escapeHTML(t.occupancyType)+"":"")+(t.lotTypeId?' '+cityssm.escapeHTML(t.lotType)+"":"")+'

'+(t.feeFunction?cityssm.escapeHTML(t.feeFunction)+"
Fee Function":"$"+t.feeAmount.toFixed(2)+"
Fee")+'
'+(t.taxPercentage?t.taxPercentage+"%":"$"+t.taxAmount.toFixed(2))+'
Tax
'+(t.includeQuantity?cityssm.escapeHTML(t.quantityUnit)+"
Quantity":"")+'
',e.querySelector("a").addEventListener("click",d),e.querySelector(".button--moveFeeUp").addEventListener("click",u),e.querySelector(".button--moveFeeDown").addEventListener("click",m),s.append(e)}t.append(s)}0===e.fees.length&&t.querySelector(".button--deleteFeeCategory").addEventListener("click",n),t.querySelector(".button--editFeeCategory").addEventListener("click",r),t.querySelector(".button--addFee").addEventListener("click",i),t.querySelector(".button--moveFeeCategoryUp").addEventListener("click",l),t.querySelector(".button--moveFeeCategoryDown").addEventListener("click",c),s.append(t)}}else s.innerHTML='

There are no available fees.

'};document.querySelector("#button--addFeeCategory").addEventListener("click",()=>{let e;const s=s=>{s.preventDefault(),cityssm.postJSON(t+"/admin/doAddFeeCategory",s.currentTarget,t=>{t.success?(a=t.feeCategories,e(),o()):bulmaJS.alert({title:"Error Creating Fee Category",message:t.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("adminFees-addFeeCategory",{onshown:(t,a)=>{bulmaJS.toggleHtmlClipped(),t.querySelector("#feeCategoryAdd--feeCategory").focus(),e=a,t.querySelector("form").addEventListener("submit",s)},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})});const r=e=>{const s=Number.parseInt(e.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10),r=a.find(e=>e.feeCategoryId===s);let n;const l=e=>{e.preventDefault(),cityssm.postJSON(t+"/admin/doUpdateFeeCategory",e.currentTarget,e=>{e.success?(a=e.feeCategories,n(),o()):bulmaJS.alert({title:"Error Updating Fee Category",message:e.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("adminFees-editFeeCategory",{onshow:e=>{e.querySelector("#feeCategoryEdit--feeCategoryId").value=r.feeCategoryId.toString(),e.querySelector("#feeCategoryEdit--feeCategory").value=r.feeCategory},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),n=t,e.querySelector("form").addEventListener("submit",l),e.querySelector("#feeCategoryEdit--feeCategory").focus()},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},n=e=>{const s=Number.parseInt(e.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10);bulmaJS.confirm({title:"Delete Fee Category?",message:"Are you sure you want to delete this fee category?",contextualColorName:"warning",okButton:{text:"Yes, Delete the Fee Category",callbackFunction:()=>{cityssm.postJSON(t+"/admin/doDeleteFeeCategory",{feeCategoryId:s},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Updating Fee Category",message:e.errorMessage,contextualColorName:"danger"})})}}})},l=e=>{const s=Number.parseInt(e.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10);cityssm.postJSON(t+"/admin/doMoveFeeCategoryUp",{feeCategoryId:s},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Moving Fee Category",message:e.errorMessage,contextualColorName:"danger"})})},c=e=>{const s=Number.parseInt(e.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10);cityssm.postJSON(t+"/admin/doMoveFeeCategoryDown",{feeCategoryId:s},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Moving Fee Category",message:e.errorMessage,contextualColorName:"danger"})})},i=s=>{const r=Number.parseInt(s.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10);let n;const l=e=>{e.preventDefault(),cityssm.postJSON(t+"/admin/doAddFee",e.currentTarget,e=>{e.success?(a=e.feeCategories,n(),o()):bulmaJS.alert({title:"Error Adding Fee",message:e.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("adminFees-addFee",{onshow:t=>{const s=t.querySelector("#feeAdd--feeCategoryId");for(const e of a){const t=document.createElement("option");t.value=e.feeCategoryId.toString(),t.textContent=e.feeCategory,e.feeCategoryId===r&&(t.selected=!0),s.append(t)}const o=t.querySelector("#feeAdd--occupancyTypeId");for(const e of exports.occupancyTypes){const t=document.createElement("option");t.value=e.occupancyTypeId.toString(),t.textContent=e.occupancyType,o.append(t)}const n=t.querySelector("#feeAdd--lotTypeId");for(const e of exports.lotTypes){const t=document.createElement("option");t.value=e.lotTypeId.toString(),t.textContent=e.lotType,n.append(t)}t.querySelector("#feeAdd--taxPercentage").value=exports.taxPercentageDefault.toString(),e.populateAliases(t)},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),n=t,e.querySelector("form").addEventListener("submit",l),e.querySelector("#feeAdd--feeName").focus(),e.querySelector("#feeAdd--feeFunction").addEventListener("change",()=>{const t=e.querySelector("#feeAdd--feeAmount"),s=e.querySelector("#feeAdd--feeFunction");""===s.value?(s.closest(".select").classList.remove("is-success"),t.classList.add("is-success"),t.disabled=!1):(s.closest(".select").classList.add("is-success"),t.classList.remove("is-success"),t.disabled=!0)}),e.querySelector("#feeAdd--taxPercentage").addEventListener("keyup",()=>{const t=e.querySelector("#feeAdd--taxAmount"),s=e.querySelector("#feeAdd--taxPercentage");""===s.value?(s.classList.remove("is-success"),t.classList.add("is-success"),t.disabled=!1):(s.classList.add("is-success"),t.classList.remove("is-success"),t.disabled=!0)}),e.querySelector("#feeAdd--includeQuantity").addEventListener("change",()=>{e.querySelector("#feeAdd--quantityUnit").disabled=""===e.querySelector("#feeAdd--includeQuantity").value})},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},d=s=>{s.preventDefault();const r=s.currentTarget.closest(".container--fee"),n=Number.parseInt(r.dataset.feeId,10),l=Number.parseInt(r.closest(".container--feeCategory").dataset.feeCategoryId),c=a.find(e=>e.feeCategoryId===l).fees.find(e=>e.feeId===n);let i,d;const u=e=>{e.preventDefault(),cityssm.postJSON(t+"/admin/doUpdateFee",e.currentTarget,e=>{e.success?(a=e.feeCategories,i(),o()):bulmaJS.alert({title:"Error Updating Fee",message:e.errorMessage,contextualColorName:"danger"})})},m=e=>{e.preventDefault();bulmaJS.confirm({title:"Delete Fee?",message:"Are you sure you want to delete this fee?",contextualColorName:"warning",okButton:{text:"Yes, Delete the Fee",callbackFunction:()=>{cityssm.postJSON(t+"/admin/doDeleteFee",{feeId:n},e=>{e.success?(a=e.feeCategories,i(),o()):bulmaJS.alert({title:"Error Deleting Fee",message:e.errorMessage,contextualColorName:"danger"})})}}})},y=()=>{const e=d.querySelector("#feeEdit--feeAmount"),t=d.querySelector("#feeEdit--feeFunction");""===t.value?(t.closest(".select").classList.remove("is-success"),e.classList.add("is-success"),e.disabled=!1):(t.closest(".select").classList.add("is-success"),e.classList.remove("is-success"),e.disabled=!0)},p=()=>{const e=d.querySelector("#feeEdit--taxAmount"),t=d.querySelector("#feeEdit--taxPercentage");""===t.value?(t.classList.remove("is-success"),e.classList.add("is-success"),e.disabled=!1):(t.classList.add("is-success"),e.classList.remove("is-success"),e.disabled=!0)},g=()=>{d.querySelector("#feeEdit--quantityUnit").disabled=""===d.querySelector("#feeEdit--includeQuantity").value};cityssm.openHtmlModal("adminFees-editFee",{onshow:t=>{d=t,t.querySelector("#feeEdit--feeId").value=c.feeId.toString();const s=t.querySelector("#feeEdit--feeCategoryId");for(const e of a){const t=document.createElement("option");t.value=e.feeCategoryId.toString(),t.textContent=e.feeCategory,e.feeCategoryId===l&&(t.selected=!0),s.append(t)}t.querySelector("#feeEdit--feeName").value=c.feeName,t.querySelector("#feeEdit--feeDescription").value=c.feeDescription;const o=t.querySelector("#feeEdit--occupancyTypeId");for(const e of exports.occupancyTypes){const t=document.createElement("option");t.value=e.occupancyTypeId.toString(),t.textContent=e.occupancyType,e.occupancyTypeId===c.occupancyTypeId&&(t.selected=!0),o.append(t)}const r=t.querySelector("#feeEdit--lotTypeId");for(const e of exports.lotTypes){const t=document.createElement("option");t.value=e.lotTypeId.toString(),t.textContent=e.lotType,e.lotTypeId===c.lotTypeId&&(t.selected=!0),r.append(t)}t.querySelector("#feeEdit--feeAmount").value=c.feeAmount?c.feeAmount.toFixed(2):"",t.querySelector("#feeEdit--feeFunction").addEventListener("change",y),y(),t.querySelector("#feeEdit--taxAmount").value=c.taxAmount?c.taxAmount.toFixed(2):"";const n=t.querySelector("#feeEdit--taxPercentage");n.value=c.taxPercentage?c.taxPercentage.toString():"",n.addEventListener("keyup",p),p();const i=t.querySelector("#feeEdit--includeQuantity");c.includeQuantity&&(i.value="1"),i.addEventListener("change",g),t.querySelector("#feeEdit--quantityUnit").value=c.quantityUnit||"",g(),c.isRequired&&(t.querySelector("#feeEdit--isRequired").value="1"),e.populateAliases(t)},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),i=t,e.querySelector("form").addEventListener("submit",u),bulmaJS.init(e),e.querySelector(".button--deleteFee").addEventListener("click",m)},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},u=e=>{const s=e.currentTarget.closest(".container--fee"),r=Number.parseInt(s.dataset.feeId,10);cityssm.postJSON(t+"/admin/doMoveFeeUp",{feeId:r},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Moving Fee",message:e.errorMessage,contextualColorName:"danger"})})},m=e=>{const s=e.currentTarget.closest(".container--fee"),r=Number.parseInt(s.dataset.feeId,10);cityssm.postJSON(t+"/admin/doMoveFeeDown",{feeId:r},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Moving Fee",message:e.errorMessage,contextualColorName:"danger"})})};o()})(); \ No newline at end of file +"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const e=exports.los,t=document.querySelector("main").dataset.urlPrefix,s=document.querySelector("#container--feeCategories");let a=exports.feeCategories;delete exports.feeCategories;const o=()=>{if(0!==a.length){s.innerHTML="";for(const e of a){const t=document.createElement("section");if(t.className="panel container--feeCategory",t.dataset.feeCategoryId=e.feeCategoryId.toString(),t.innerHTML='

'+cityssm.escapeHTML(e.feeCategory)+'

'+(0===e.fees.length?'
':"")+'
',0===e.fees.length)t.insertAdjacentHTML("beforeend",'

There are no fees in the "'+cityssm.escapeHTML(e.feeCategory)+'" category.

');else for(const s of e.fees){const e=document.createElement("div");e.className="panel-block is-block container--fee",e.dataset.feeId=s.feeId.toString(),e.innerHTML='

'+cityssm.escapeHTML(s.feeName)+"
"+cityssm.escapeHTML(s.feeDescription).replace(/\n/g,"
")+'

'+(s.isRequired?'Required':"")+(s.occupancyTypeId?' '+cityssm.escapeHTML(s.occupancyType)+"":"")+(s.lotTypeId?' '+cityssm.escapeHTML(s.lotType)+"":"")+'

'+(s.feeFunction?cityssm.escapeHTML(s.feeFunction)+"
Fee Function":"$"+s.feeAmount.toFixed(2)+"
Fee")+'
'+(s.taxPercentage?s.taxPercentage+"%":"$"+s.taxAmount.toFixed(2))+'
Tax
'+(s.includeQuantity?cityssm.escapeHTML(s.quantityUnit)+"
Quantity":"")+'
',e.querySelector("a").addEventListener("click",d),e.querySelector(".button--moveFeeUp").addEventListener("click",u),e.querySelector(".button--moveFeeDown").addEventListener("click",y),t.append(e)}0===e.fees.length&&t.querySelector(".button--deleteFeeCategory").addEventListener("click",n),t.querySelector(".button--editFeeCategory").addEventListener("click",r),t.querySelector(".button--addFee").addEventListener("click",i),t.querySelector(".button--moveFeeCategoryUp").addEventListener("click",l),t.querySelector(".button--moveFeeCategoryDown").addEventListener("click",c),s.append(t)}}else s.innerHTML='

There are no available fees.

'};document.querySelector("#button--addFeeCategory").addEventListener("click",()=>{let e;const s=s=>{s.preventDefault(),cityssm.postJSON(t+"/admin/doAddFeeCategory",s.currentTarget,t=>{t.success?(a=t.feeCategories,e(),o()):bulmaJS.alert({title:"Error Creating Fee Category",message:t.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("adminFees-addFeeCategory",{onshown:(t,a)=>{bulmaJS.toggleHtmlClipped(),t.querySelector("#feeCategoryAdd--feeCategory").focus(),e=a,t.querySelector("form").addEventListener("submit",s)},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})});const r=e=>{const s=Number.parseInt(e.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10),r=a.find(e=>e.feeCategoryId===s);let n;const l=e=>{e.preventDefault(),cityssm.postJSON(t+"/admin/doUpdateFeeCategory",e.currentTarget,e=>{e.success?(a=e.feeCategories,n(),o()):bulmaJS.alert({title:"Error Updating Fee Category",message:e.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("adminFees-editFeeCategory",{onshow:e=>{e.querySelector("#feeCategoryEdit--feeCategoryId").value=r.feeCategoryId.toString(),e.querySelector("#feeCategoryEdit--feeCategory").value=r.feeCategory},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),n=t,e.querySelector("form").addEventListener("submit",l),e.querySelector("#feeCategoryEdit--feeCategory").focus()},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},n=e=>{const s=Number.parseInt(e.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10);bulmaJS.confirm({title:"Delete Fee Category?",message:"Are you sure you want to delete this fee category?",contextualColorName:"warning",okButton:{text:"Yes, Delete the Fee Category",callbackFunction:()=>{cityssm.postJSON(t+"/admin/doDeleteFeeCategory",{feeCategoryId:s},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Updating Fee Category",message:e.errorMessage,contextualColorName:"danger"})})}}})},l=e=>{const s=Number.parseInt(e.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10);cityssm.postJSON(t+"/admin/doMoveFeeCategoryUp",{feeCategoryId:s},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Moving Fee Category",message:e.errorMessage,contextualColorName:"danger"})})},c=e=>{const s=Number.parseInt(e.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10);cityssm.postJSON(t+"/admin/doMoveFeeCategoryDown",{feeCategoryId:s},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Moving Fee Category",message:e.errorMessage,contextualColorName:"danger"})})},i=s=>{const r=Number.parseInt(s.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId,10);let n;const l=e=>{e.preventDefault(),cityssm.postJSON(t+"/admin/doAddFee",e.currentTarget,e=>{e.success?(a=e.feeCategories,n(),o()):bulmaJS.alert({title:"Error Adding Fee",message:e.errorMessage,contextualColorName:"danger"})})};cityssm.openHtmlModal("adminFees-addFee",{onshow:t=>{const s=t.querySelector("#feeAdd--feeCategoryId");for(const e of a){const t=document.createElement("option");t.value=e.feeCategoryId.toString(),t.textContent=e.feeCategory,e.feeCategoryId===r&&(t.selected=!0),s.append(t)}const o=t.querySelector("#feeAdd--occupancyTypeId");for(const e of exports.occupancyTypes){const t=document.createElement("option");t.value=e.occupancyTypeId.toString(),t.textContent=e.occupancyType,o.append(t)}const n=t.querySelector("#feeAdd--lotTypeId");for(const e of exports.lotTypes){const t=document.createElement("option");t.value=e.lotTypeId.toString(),t.textContent=e.lotType,n.append(t)}t.querySelector("#feeAdd--taxPercentage").value=exports.taxPercentageDefault.toString(),e.populateAliases(t)},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),n=t,e.querySelector("form").addEventListener("submit",l),e.querySelector("#feeAdd--feeName").focus(),e.querySelector("#feeAdd--feeFunction").addEventListener("change",()=>{const t=e.querySelector("#feeAdd--feeAmount"),s=e.querySelector("#feeAdd--feeFunction");""===s.value?(s.closest(".select").classList.remove("is-success"),t.classList.add("is-success"),t.disabled=!1):(s.closest(".select").classList.add("is-success"),t.classList.remove("is-success"),t.disabled=!0)}),e.querySelector("#feeAdd--taxPercentage").addEventListener("keyup",()=>{const t=e.querySelector("#feeAdd--taxAmount"),s=e.querySelector("#feeAdd--taxPercentage");""===s.value?(s.classList.remove("is-success"),t.classList.add("is-success"),t.disabled=!1):(s.classList.add("is-success"),t.classList.remove("is-success"),t.disabled=!0)}),e.querySelector("#feeAdd--includeQuantity").addEventListener("change",()=>{e.querySelector("#feeAdd--quantityUnit").disabled=""===e.querySelector("#feeAdd--includeQuantity").value})},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},d=s=>{s.preventDefault();const r=s.currentTarget.closest(".container--fee"),n=Number.parseInt(r.dataset.feeId,10),l=Number.parseInt(r.closest(".container--feeCategory").dataset.feeCategoryId),c=a.find(e=>e.feeCategoryId===l).fees.find(e=>e.feeId===n);let i,d;const u=e=>{e.preventDefault(),cityssm.postJSON(t+"/admin/doUpdateFee",e.currentTarget,e=>{e.success?(a=e.feeCategories,i(),o()):bulmaJS.alert({title:"Error Updating Fee",message:e.errorMessage,contextualColorName:"danger"})})},y=e=>{e.preventDefault();bulmaJS.confirm({title:"Delete Fee?",message:"Are you sure you want to delete this fee?",contextualColorName:"warning",okButton:{text:"Yes, Delete the Fee",callbackFunction:()=>{cityssm.postJSON(t+"/admin/doDeleteFee",{feeId:n},e=>{e.success?(a=e.feeCategories,i(),o()):bulmaJS.alert({title:"Error Deleting Fee",message:e.errorMessage,contextualColorName:"danger"})})}}})},m=()=>{const e=d.querySelector("#feeEdit--feeAmount"),t=d.querySelector("#feeEdit--feeFunction");""===t.value?(t.closest(".select").classList.remove("is-success"),e.classList.add("is-success"),e.disabled=!1):(t.closest(".select").classList.add("is-success"),e.classList.remove("is-success"),e.disabled=!0)},p=()=>{const e=d.querySelector("#feeEdit--taxAmount"),t=d.querySelector("#feeEdit--taxPercentage");""===t.value?(t.classList.remove("is-success"),e.classList.add("is-success"),e.disabled=!1):(t.classList.add("is-success"),e.classList.remove("is-success"),e.disabled=!0)},g=()=>{d.querySelector("#feeEdit--quantityUnit").disabled=""===d.querySelector("#feeEdit--includeQuantity").value};cityssm.openHtmlModal("adminFees-editFee",{onshow:t=>{d=t,t.querySelector("#feeEdit--feeId").value=c.feeId.toString();const s=t.querySelector("#feeEdit--feeCategoryId");for(const e of a){const t=document.createElement("option");t.value=e.feeCategoryId.toString(),t.textContent=e.feeCategory,e.feeCategoryId===l&&(t.selected=!0),s.append(t)}t.querySelector("#feeEdit--feeName").value=c.feeName,t.querySelector("#feeEdit--feeDescription").value=c.feeDescription;const o=t.querySelector("#feeEdit--occupancyTypeId");for(const e of exports.occupancyTypes){const t=document.createElement("option");t.value=e.occupancyTypeId.toString(),t.textContent=e.occupancyType,e.occupancyTypeId===c.occupancyTypeId&&(t.selected=!0),o.append(t)}const r=t.querySelector("#feeEdit--lotTypeId");for(const e of exports.lotTypes){const t=document.createElement("option");t.value=e.lotTypeId.toString(),t.textContent=e.lotType,e.lotTypeId===c.lotTypeId&&(t.selected=!0),r.append(t)}t.querySelector("#feeEdit--feeAmount").value=c.feeAmount?c.feeAmount.toFixed(2):"",t.querySelector("#feeEdit--feeFunction").addEventListener("change",m),m(),t.querySelector("#feeEdit--taxAmount").value=c.taxAmount?c.taxAmount.toFixed(2):"";const n=t.querySelector("#feeEdit--taxPercentage");n.value=c.taxPercentage?c.taxPercentage.toString():"",n.addEventListener("keyup",p),p();const i=t.querySelector("#feeEdit--includeQuantity");c.includeQuantity&&(i.value="1"),i.addEventListener("change",g),t.querySelector("#feeEdit--quantityUnit").value=c.quantityUnit||"",g(),c.isRequired&&(t.querySelector("#feeEdit--isRequired").value="1"),e.populateAliases(t)},onshown:(e,t)=>{bulmaJS.toggleHtmlClipped(),i=t,e.querySelector("form").addEventListener("submit",u),bulmaJS.init(e),e.querySelector(".button--deleteFee").addEventListener("click",y)},onremoved:()=>{bulmaJS.toggleHtmlClipped()}})},u=e=>{const s=e.currentTarget.closest(".container--fee"),r=Number.parseInt(s.dataset.feeId,10);cityssm.postJSON(t+"/admin/doMoveFeeUp",{feeId:r},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Moving Fee",message:e.errorMessage,contextualColorName:"danger"})})},y=e=>{const s=e.currentTarget.closest(".container--fee"),r=Number.parseInt(s.dataset.feeId,10);cityssm.postJSON(t+"/admin/doMoveFeeDown",{feeId:r},e=>{e.success?(a=e.feeCategories,o()):bulmaJS.alert({title:"Error Moving Fee",message:e.errorMessage,contextualColorName:"danger"})})};o()})(); \ No newline at end of file diff --git a/public/javascripts/adminOccupancyTypes.min.js b/public/javascripts/adminOccupancyTypes.min.js index e69de29b..e7f1ce65 100644 --- a/public/javascripts/adminOccupancyTypes.min.js +++ b/public/javascripts/adminOccupancyTypes.min.js @@ -0,0 +1 @@ +"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{document.querySelector("main").dataset.urlPrefix;const e=document.querySelector("#container--occupancyTypes"),a=exports.occupancyTypes;delete exports.occupancyTypes;const s=new Set,t=e=>{const a=e.currentTarget,t=a.closest(".container--occupancyType"),i=Number.parseInt(t.dataset.occupancyTypeId,10);s.has(i)?s.delete(i):s.add(i),a.innerHTML=s.has(i)?'':'';const c=t.querySelectorAll(".panel-block");for(const e of c)e.classList.toggle("is-hidden")};(()=>{if(0!==a.length){e.innerHTML="";for(const i of a){const a=document.createElement("div");if(a.className="panel container--occupancyType",a.dataset.occupancyTypeId=i.occupancyTypeId.toString(),a.innerHTML='

'+cityssm.escapeHTML(i.occupancyType)+'

',0===i.occupancyTypeFields.length)a.insertAdjacentHTML("beforeend",'

There are no additional fields.

');else for(const e of i.occupancyTypeFields){const t=document.createElement("div");t.className="panel-block is-block container--occupancyTypeField",s.has(i.occupancyTypeId)||t.classList.add("is-hidden"),t.dataset.occupancyTypeFieldId=e.occupancyTypeFieldId.toString(),t.innerHTML='',a.append(t)}a.querySelector(".button--toggleOccupancyTypeFields").addEventListener("click",t),e.append(a)}}else e.innerHTML='
There are no active '+exports.aliases.occupancy.toLowerCase()+" types.

"})()})(); \ No newline at end of file diff --git a/routes/login.js b/routes/login.js index 8bb1abda..a1d93551 100644 --- a/routes/login.js +++ b/routes/login.js @@ -11,6 +11,8 @@ const getSafeRedirectURL = (possibleRedirectURL = "") => { : possibleRedirectURL).toLowerCase(); switch (urlToCheck) { case "/admin/fees": + case "/admin/occupancyTypes": + case "/admin/tables": case "/lotOccupancies": case "/lots": case "/maps": diff --git a/routes/login.ts b/routes/login.ts index 10e72ee6..0a8d9e7c 100644 --- a/routes/login.ts +++ b/routes/login.ts @@ -22,6 +22,8 @@ const getSafeRedirectURL = (possibleRedirectURL = "") => { switch (urlToCheck) { case "/admin/fees": + case "/admin/occupancyTypes": + case "/admin/tables": case "/lotOccupancies": case "/lots": case "/maps": diff --git a/temp/so.exportMaps.js b/temp/so.exportMaps.js index 6367a925..af5bfc66 100644 --- a/temp/so.exportMaps.js +++ b/temp/so.exportMaps.js @@ -11,7 +11,14 @@ async function importMaps() { " left join Legacy_Layers l on m.ID = l.Map_ID"); for (const layer of result.recordset) { const imageBuffer = layer.layerImage; - const fileName = layer.mapName + " - " + layer.layerName + " (" + layer.mapId + ", " + layer.layerId + ").wmf"; + const fileName = layer.mapName + + " - " + + layer.layerName + + " (" + + layer.mapId + + ", " + + layer.layerId + + ").wmf"; fs.writeFile("./temp/wmf/" + fileName, imageBuffer, (error) => { if (error) { console.log(error); diff --git a/temp/so.exportMaps.ts b/temp/so.exportMaps.ts index 140f4648..f20539f3 100644 --- a/temp/so.exportMaps.ts +++ b/temp/so.exportMaps.ts @@ -6,22 +6,30 @@ import { soMSSQL } from "./config.js"; import type * as sqlTypes from "mssql"; async function importMaps() { - let pool: sqlTypes.ConnectionPool; try { pool = await sql.connect(soMSSQL); - const result = await pool.query("select m.ID as mapId, m.Name as mapName," + - " l.ID as layerId, l.Name as layerName, l.Image as layerImage" + - " from Legacy_Maps m" + - " left join Legacy_Layers l on m.ID = l.Map_ID"); + const result = await pool.query( + "select m.ID as mapId, m.Name as mapName," + + " l.ID as layerId, l.Name as layerName, l.Image as layerImage" + + " from Legacy_Maps m" + + " left join Legacy_Layers l on m.ID = l.Map_ID" + ); for (const layer of result.recordset) { - const imageBuffer: Buffer = layer.layerImage; - const fileName = layer.mapName + " - " + layer.layerName + " (" + layer.mapId + ", " + layer.layerId + ").wmf"; + const fileName = + layer.mapName + + " - " + + layer.layerName + + " (" + + layer.mapId + + ", " + + layer.layerId + + ").wmf"; fs.writeFile("./temp/wmf/" + fileName, imageBuffer, (error) => { if (error) { @@ -29,7 +37,6 @@ async function importMaps() { } }); } - } catch { // ignore } finally { @@ -41,5 +48,4 @@ async function importMaps() { } } - -await importMaps(); \ No newline at end of file +await importMaps(); diff --git a/windowsService-install.ts b/windowsService-install.ts index 75354bad..e756f52f 100644 --- a/windowsService-install.ts +++ b/windowsService-install.ts @@ -7,7 +7,7 @@ const svc = new Service(serviceConfig); // Listen for the "install" event, which indicates the // process is available as a service. svc.on("install", () => { - svc.start(); + svc.start(); }); svc.install(); diff --git a/windowsService-uninstall.ts b/windowsService-uninstall.ts index d2f0d0d9..cf2b6a00 100644 --- a/windowsService-uninstall.ts +++ b/windowsService-uninstall.ts @@ -5,9 +5,9 @@ import { serviceConfig } from "./windowsService.js"; const svc = new Service(serviceConfig); // Listen for the "uninstall" event so we know when it's done. -svc.on("uninstall", function() { - console.log("Uninstall complete."); - console.log("The service exists:", svc.exists); +svc.on("uninstall", function () { + console.log("Uninstall complete."); + console.log("The service exists:", svc.exists); }); // Uninstall the service. diff --git a/windowsService.ts b/windowsService.ts index 197480c5..dbc95880 100644 --- a/windowsService.ts +++ b/windowsService.ts @@ -1,11 +1,11 @@ import path from "path"; import type { ServiceConfig } from "node-windows"; - const __dirname = "."; export const serviceConfig: ServiceConfig = { - name: "Lot Occupancy Manager", - description: "A system for managing the occupancy of lots. (i.e. Cemetery management)", - script: path.join(__dirname, "bin", "www.js") + name: "Lot Occupancy Manager", + description: + "A system for managing the occupancy of lots. (i.e. Cemetery management)", + script: path.join(__dirname, "bin", "www.js") };