diff --git a/handlers/admin-post/doAddLotOccupantType.d.ts b/handlers/admin-post/doAddLotOccupantType.d.ts
new file mode 100644
index 00000000..9621c611
--- /dev/null
+++ b/handlers/admin-post/doAddLotOccupantType.d.ts
@@ -0,0 +1,3 @@
+import type { RequestHandler } from "express";
+export declare const handler: RequestHandler;
+export default handler;
diff --git a/handlers/admin-post/doAddLotOccupantType.js b/handlers/admin-post/doAddLotOccupantType.js
new file mode 100644
index 00000000..b1513222
--- /dev/null
+++ b/handlers/admin-post/doAddLotOccupantType.js
@@ -0,0 +1,12 @@
+import { addLotOccupantType } from "../../helpers/lotOccupancyDB/addLotOccupantType.js";
+import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
+export const handler = async (request, response) => {
+ const lotOccupantTypeId = addLotOccupantType(request.body, request.session);
+ const lotOccupantTypes = getLotOccupantTypes();
+ response.json({
+ success: true,
+ lotOccupantTypeId,
+ lotOccupantTypes
+ });
+};
+export default handler;
diff --git a/handlers/admin-post/doAddLotOccupantType.ts b/handlers/admin-post/doAddLotOccupantType.ts
new file mode 100644
index 00000000..b13b68f7
--- /dev/null
+++ b/handlers/admin-post/doAddLotOccupantType.ts
@@ -0,0 +1,28 @@
+import type {
+ RequestHandler
+} from "express";
+
+import {
+ addLotOccupantType
+} from "../../helpers/lotOccupancyDB/addLotOccupantType.js";
+
+import {
+ getLotOccupantTypes
+} from "../../helpers/functions.cache.js";
+
+
+export const handler: RequestHandler = async (request, response) => {
+
+ const lotOccupantTypeId = addLotOccupantType(request.body, request.session);
+
+ const lotOccupantTypes = getLotOccupantTypes();
+
+ response.json({
+ success: true,
+ lotOccupantTypeId,
+ lotOccupantTypes
+ });
+};
+
+
+export default handler;
\ No newline at end of file
diff --git a/handlers/admin-post/doDeleteLotOccupantType.d.ts b/handlers/admin-post/doDeleteLotOccupantType.d.ts
new file mode 100644
index 00000000..9621c611
--- /dev/null
+++ b/handlers/admin-post/doDeleteLotOccupantType.d.ts
@@ -0,0 +1,3 @@
+import type { RequestHandler } from "express";
+export declare const handler: RequestHandler;
+export default handler;
diff --git a/handlers/admin-post/doDeleteLotOccupantType.js b/handlers/admin-post/doDeleteLotOccupantType.js
new file mode 100644
index 00000000..49d92746
--- /dev/null
+++ b/handlers/admin-post/doDeleteLotOccupantType.js
@@ -0,0 +1,11 @@
+import { deleteLotOccupantType } from "../../helpers/lotOccupancyDB/deleteLotOccupantType.js";
+import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
+export const handler = async (request, response) => {
+ const success = deleteLotOccupantType(request.body.lotOccupantTypeId, request.session);
+ const lotOccupantTypes = getLotOccupantTypes();
+ response.json({
+ success,
+ lotOccupantTypes
+ });
+};
+export default handler;
diff --git a/handlers/admin-post/doDeleteLotOccupantType.ts b/handlers/admin-post/doDeleteLotOccupantType.ts
new file mode 100644
index 00000000..7df6b0ad
--- /dev/null
+++ b/handlers/admin-post/doDeleteLotOccupantType.ts
@@ -0,0 +1,27 @@
+import type {
+ RequestHandler
+} from "express";
+
+import {
+ deleteLotOccupantType
+} from "../../helpers/lotOccupancyDB/deleteLotOccupantType.js";
+
+import {
+ getLotOccupantTypes
+} from "../../helpers/functions.cache.js";
+
+
+export const handler: RequestHandler = async (request, response) => {
+
+ const success = deleteLotOccupantType(request.body.lotOccupantTypeId, request.session);
+
+ const lotOccupantTypes = getLotOccupantTypes();
+
+ response.json({
+ success,
+ lotOccupantTypes
+ });
+};
+
+
+export default handler;
\ No newline at end of file
diff --git a/handlers/admin-post/doMoveLotOccupantTypeDown.d.ts b/handlers/admin-post/doMoveLotOccupantTypeDown.d.ts
new file mode 100644
index 00000000..9621c611
--- /dev/null
+++ b/handlers/admin-post/doMoveLotOccupantTypeDown.d.ts
@@ -0,0 +1,3 @@
+import type { RequestHandler } from "express";
+export declare const handler: RequestHandler;
+export default handler;
diff --git a/handlers/admin-post/doMoveLotOccupantTypeDown.js b/handlers/admin-post/doMoveLotOccupantTypeDown.js
new file mode 100644
index 00000000..57f0b58c
--- /dev/null
+++ b/handlers/admin-post/doMoveLotOccupantTypeDown.js
@@ -0,0 +1,11 @@
+import { moveLotOccupantTypeDown } from "../../helpers/lotOccupancyDB/moveLotOccupantTypeDown.js";
+import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
+export const handler = async (request, response) => {
+ const success = moveLotOccupantTypeDown(request.body.lotOccupantTypeId);
+ const lotOccupantTypes = getLotOccupantTypes();
+ response.json({
+ success,
+ lotOccupantTypes
+ });
+};
+export default handler;
diff --git a/handlers/admin-post/doMoveLotOccupantTypeDown.ts b/handlers/admin-post/doMoveLotOccupantTypeDown.ts
new file mode 100644
index 00000000..a2709d40
--- /dev/null
+++ b/handlers/admin-post/doMoveLotOccupantTypeDown.ts
@@ -0,0 +1,27 @@
+import type {
+ RequestHandler
+} from "express";
+
+import {
+ moveLotOccupantTypeDown
+} from "../../helpers/lotOccupancyDB/moveLotOccupantTypeDown.js";
+
+import {
+ getLotOccupantTypes
+} from "../../helpers/functions.cache.js";
+
+
+export const handler: RequestHandler = async (request, response) => {
+
+ const success = moveLotOccupantTypeDown(request.body.lotOccupantTypeId);
+
+ const lotOccupantTypes = getLotOccupantTypes();
+
+ response.json({
+ success,
+ lotOccupantTypes
+ });
+};
+
+
+export default handler;
\ No newline at end of file
diff --git a/handlers/admin-post/doMoveLotOccupantTypeUp.d.ts b/handlers/admin-post/doMoveLotOccupantTypeUp.d.ts
new file mode 100644
index 00000000..9621c611
--- /dev/null
+++ b/handlers/admin-post/doMoveLotOccupantTypeUp.d.ts
@@ -0,0 +1,3 @@
+import type { RequestHandler } from "express";
+export declare const handler: RequestHandler;
+export default handler;
diff --git a/handlers/admin-post/doMoveLotOccupantTypeUp.js b/handlers/admin-post/doMoveLotOccupantTypeUp.js
new file mode 100644
index 00000000..5e2e0d51
--- /dev/null
+++ b/handlers/admin-post/doMoveLotOccupantTypeUp.js
@@ -0,0 +1,11 @@
+import { moveLotOccupantTypeUp } from "../../helpers/lotOccupancyDB/moveLotOccupantTypeUp.js";
+import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
+export const handler = async (request, response) => {
+ const success = moveLotOccupantTypeUp(request.body.lotOccupantTypeId);
+ const lotOccupantTypes = getLotOccupantTypes();
+ response.json({
+ success,
+ lotOccupantTypes
+ });
+};
+export default handler;
diff --git a/handlers/admin-post/doMoveLotOccupantTypeUp.ts b/handlers/admin-post/doMoveLotOccupantTypeUp.ts
new file mode 100644
index 00000000..63cc2a6e
--- /dev/null
+++ b/handlers/admin-post/doMoveLotOccupantTypeUp.ts
@@ -0,0 +1,27 @@
+import type {
+ RequestHandler
+} from "express";
+
+import {
+ moveLotOccupantTypeUp
+} from "../../helpers/lotOccupancyDB/moveLotOccupantTypeUp.js";
+
+import {
+ getLotOccupantTypes
+} from "../../helpers/functions.cache.js";
+
+
+export const handler: RequestHandler = async (request, response) => {
+
+ const success = moveLotOccupantTypeUp(request.body.lotOccupantTypeId);
+
+ const lotOccupantTypes = getLotOccupantTypes();
+
+ response.json({
+ success,
+ lotOccupantTypes
+ });
+};
+
+
+export default handler;
\ No newline at end of file
diff --git a/handlers/admin-post/doUpdateLotOccupantType.d.ts b/handlers/admin-post/doUpdateLotOccupantType.d.ts
new file mode 100644
index 00000000..9621c611
--- /dev/null
+++ b/handlers/admin-post/doUpdateLotOccupantType.d.ts
@@ -0,0 +1,3 @@
+import type { RequestHandler } from "express";
+export declare const handler: RequestHandler;
+export default handler;
diff --git a/handlers/admin-post/doUpdateLotOccupantType.js b/handlers/admin-post/doUpdateLotOccupantType.js
new file mode 100644
index 00000000..82d3d080
--- /dev/null
+++ b/handlers/admin-post/doUpdateLotOccupantType.js
@@ -0,0 +1,11 @@
+import { updateLotOccupantType } from "../../helpers/lotOccupancyDB/updateLotOccupantType.js";
+import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
+export const handler = async (request, response) => {
+ const success = updateLotOccupantType(request.body, request.session);
+ const lotOccupantTypes = getLotOccupantTypes();
+ response.json({
+ success,
+ lotOccupantTypes
+ });
+};
+export default handler;
diff --git a/handlers/admin-post/doUpdateLotOccupantType.ts b/handlers/admin-post/doUpdateLotOccupantType.ts
new file mode 100644
index 00000000..b103cc20
--- /dev/null
+++ b/handlers/admin-post/doUpdateLotOccupantType.ts
@@ -0,0 +1,27 @@
+import type {
+ RequestHandler
+} from "express";
+
+import {
+ updateLotOccupantType
+} from "../../helpers/lotOccupancyDB/updateLotOccupantType.js";
+
+import {
+ getLotOccupantTypes
+} from "../../helpers/functions.cache.js";
+
+
+export const handler: RequestHandler = async (request, response) => {
+
+ const success = updateLotOccupantType(request.body, request.session);
+
+ const lotOccupantTypes = getLotOccupantTypes();
+
+ response.json({
+ success,
+ lotOccupantTypes
+ });
+};
+
+
+export default handler;
\ No newline at end of file
diff --git a/helpers/lotOccupancyDB/addLotOccupantType.js b/helpers/lotOccupancyDB/addLotOccupantType.js
index 20340200..10663923 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 || 0), 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 28d04c27..24aae01d 100644
--- a/helpers/lotOccupancyDB/addLotOccupantType.ts
+++ b/helpers/lotOccupancyDB/addLotOccupantType.ts
@@ -28,7 +28,7 @@ export const addLotOccupantType =
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)")
.run(lotOccupantTypeForm.lotOccupantType,
- (lotOccupantTypeForm.orderNumber || 0),
+ (lotOccupantTypeForm.orderNumber || -1),
requestSession.user.userName,
rightNowMillis,
requestSession.user.userName,
diff --git a/helpers/lotOccupancyDB/deleteLotOccupantType.d.ts b/helpers/lotOccupancyDB/deleteLotOccupantType.d.ts
new file mode 100644
index 00000000..4e095f08
--- /dev/null
+++ b/helpers/lotOccupancyDB/deleteLotOccupantType.d.ts
@@ -0,0 +1,3 @@
+import type * as recordTypes from "../../types/recordTypes";
+export declare const deleteLotOccupantType: (lotOccupantTypeId: number | string, requestSession: recordTypes.PartialSession) => boolean;
+export default deleteLotOccupantType;
diff --git a/helpers/lotOccupancyDB/deleteLotOccupantType.js b/helpers/lotOccupancyDB/deleteLotOccupantType.js
new file mode 100644
index 00000000..0384e7bb
--- /dev/null
+++ b/helpers/lotOccupancyDB/deleteLotOccupantType.js
@@ -0,0 +1,17 @@
+import sqlite from "better-sqlite3";
+import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
+import { clearLotOccupantTypesCache } from "../functions.cache.js";
+export const deleteLotOccupantType = (lotOccupantTypeId, requestSession) => {
+ const database = sqlite(databasePath);
+ const rightNowMillis = Date.now();
+ const result = database
+ .prepare("update LotOccupantTypes" +
+ " set recordDelete_userName = ?," +
+ " recordDelete_timeMillis = ?" +
+ " where lotOccupantTypeId = ?")
+ .run(requestSession.user.userName, rightNowMillis, lotOccupantTypeId);
+ database.close();
+ clearLotOccupantTypesCache();
+ return (result.changes > 0);
+};
+export default deleteLotOccupantType;
diff --git a/helpers/lotOccupancyDB/deleteLotOccupantType.ts b/helpers/lotOccupancyDB/deleteLotOccupantType.ts
new file mode 100644
index 00000000..22edad65
--- /dev/null
+++ b/helpers/lotOccupancyDB/deleteLotOccupantType.ts
@@ -0,0 +1,39 @@
+import sqlite from "better-sqlite3";
+
+import {
+ lotOccupancyDB as databasePath
+} from "../../data/databasePaths.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);
+
+ const rightNowMillis = Date.now();
+
+ const result = database
+ .prepare("update LotOccupantTypes" +
+ " set recordDelete_userName = ?," +
+ " recordDelete_timeMillis = ?" +
+ " where lotOccupantTypeId = ?")
+ .run(requestSession.user.userName,
+ rightNowMillis,
+ lotOccupantTypeId);
+
+ database.close();
+
+ clearLotOccupantTypesCache();
+
+ return (result.changes > 0);
+ };
+
+
+export default deleteLotOccupantType;
\ No newline at end of file
diff --git a/helpers/lotOccupancyDB/getLotOccupantTypes.js b/helpers/lotOccupancyDB/getLotOccupantTypes.js
index 0160296d..0989e69d 100644
--- a/helpers/lotOccupancyDB/getLotOccupantTypes.js
+++ b/helpers/lotOccupancyDB/getLotOccupantTypes.js
@@ -1,15 +1,24 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
export const getLotOccupantTypes = () => {
- const database = sqlite(databasePath, {
- readonly: true
- });
+ const database = sqlite(databasePath);
const lotOccupantTypes = database
.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);
+ lotOccupantType.orderNumber = expectedOrderNumber;
+ }
+ expectedOrderNumber += 1;
+ }
database.close();
return lotOccupantTypes;
};
diff --git a/helpers/lotOccupancyDB/getLotOccupantTypes.ts b/helpers/lotOccupancyDB/getLotOccupantTypes.ts
index 28716180..2dd45341 100644
--- a/helpers/lotOccupancyDB/getLotOccupantTypes.ts
+++ b/helpers/lotOccupancyDB/getLotOccupantTypes.ts
@@ -9,9 +9,7 @@ import type * as recordTypes from "../../types/recordTypes";
export const getLotOccupantTypes = (): recordTypes.LotOccupantType[] => {
- const database = sqlite(databasePath, {
- readonly: true
- });
+ const database = sqlite(databasePath);
const lotOccupantTypes: recordTypes.LotOccupantType[] = database
.prepare("select lotOccupantTypeId, lotOccupantType" +
@@ -20,6 +18,24 @@ export const getLotOccupantTypes = (): recordTypes.LotOccupantType[] => {
" 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);
+
+ lotOccupantType.orderNumber = expectedOrderNumber;
+ }
+
+ expectedOrderNumber += 1;
+ }
+
database.close();
return lotOccupantTypes;
diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeDown.d.ts b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.d.ts
new file mode 100644
index 00000000..00db11d3
--- /dev/null
+++ b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.d.ts
@@ -0,0 +1,2 @@
+export declare const moveLotOccupantTypeDown: (lotOccupantTypeId: number | string) => boolean;
+export default moveLotOccupantTypeDown;
diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeDown.js b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.js
new file mode 100644
index 00000000..b95083c2
--- /dev/null
+++ b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.js
@@ -0,0 +1,26 @@
+import sqlite from "better-sqlite3";
+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" +
+ " from LotOccupantTypes" +
+ " where lotOccupantTypeId = ?")
+ .get(lotOccupantTypeId)
+ .orderNumber;
+ database
+ .prepare("update LotOccupantTypes" +
+ " set orderNumber = orderNumber - 1" +
+ " where recordDelete_timeMillis is null" +
+ " and orderNumber = ? + 1")
+ .run(currentOrderNumber);
+ const result = database
+ .prepare("update LotOccupantTypes" +
+ " set orderNumber = ? + 1" +
+ " where lotOccupantTypeId = ?")
+ .run(currentOrderNumber, lotOccupantTypeId);
+ database.close();
+ clearLotOccupantTypesCache();
+ return result.changes > 0;
+};
+export default moveLotOccupantTypeDown;
diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeDown.ts b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.ts
new file mode 100644
index 00000000..e2683c18
--- /dev/null
+++ b/helpers/lotOccupancyDB/moveLotOccupantTypeDown.ts
@@ -0,0 +1,44 @@
+import sqlite from "better-sqlite3";
+
+import {
+ lotOccupancyDB as databasePath
+} from "../../data/databasePaths.js";
+
+import {
+ clearLotOccupantTypesCache
+} from "../functions.cache.js";
+
+
+export const moveLotOccupantTypeDown =
+ (lotOccupantTypeId: number | string): boolean => {
+
+ const database = sqlite(databasePath);
+
+ const currentOrderNumber: number = database.prepare("select orderNumber" +
+ " from LotOccupantTypes" +
+ " where lotOccupantTypeId = ?")
+ .get(lotOccupantTypeId)
+ .orderNumber;
+
+ database
+ .prepare("update LotOccupantTypes" +
+ " set orderNumber = orderNumber - 1" +
+ " where recordDelete_timeMillis is null" +
+ " and orderNumber = ? + 1")
+ .run(currentOrderNumber);
+
+ const result = database
+ .prepare("update LotOccupantTypes" +
+ " set orderNumber = ? + 1" +
+ " where lotOccupantTypeId = ?")
+ .run(currentOrderNumber, lotOccupantTypeId);
+
+ database.close();
+
+ clearLotOccupantTypesCache();
+
+ return result.changes > 0;
+ };
+
+
+export default moveLotOccupantTypeDown;
\ No newline at end of file
diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeUp.d.ts b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.d.ts
new file mode 100644
index 00000000..50aaaaf3
--- /dev/null
+++ b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.d.ts
@@ -0,0 +1,2 @@
+export declare const moveLotOccupantTypeUp: (lotOccupantTypeId: number | string) => boolean;
+export default moveLotOccupantTypeUp;
diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeUp.js b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.js
new file mode 100644
index 00000000..c8cebf7b
--- /dev/null
+++ b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.js
@@ -0,0 +1,30 @@
+import sqlite from "better-sqlite3";
+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" +
+ " from LotOccupantTypes" +
+ " where lotOccupantTypeId = ?")
+ .get(lotOccupantTypeId)
+ .orderNumber;
+ if (currentOrderNumber <= 0) {
+ database.close();
+ return true;
+ }
+ database
+ .prepare("update LotOccupantTypes" +
+ " set orderNumber = orderNumber + 1" +
+ " where recordDelete_timeMillis is null" +
+ " and orderNumber = ? - 1")
+ .run(currentOrderNumber);
+ const result = database
+ .prepare("update LotOccupantTypes" +
+ " set orderNumber = ? - 1" +
+ " where lotOccupantTypeId = ?")
+ .run(currentOrderNumber, lotOccupantTypeId);
+ database.close();
+ clearLotOccupantTypesCache();
+ return result.changes > 0;
+};
+export default moveLotOccupantTypeUp;
diff --git a/helpers/lotOccupancyDB/moveLotOccupantTypeUp.ts b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.ts
new file mode 100644
index 00000000..0996b964
--- /dev/null
+++ b/helpers/lotOccupancyDB/moveLotOccupantTypeUp.ts
@@ -0,0 +1,49 @@
+import sqlite from "better-sqlite3";
+
+import {
+ lotOccupancyDB as databasePath
+} from "../../data/databasePaths.js";
+
+import {
+ clearLotOccupantTypesCache
+} from "../functions.cache.js";
+
+
+export const moveLotOccupantTypeUp =
+ (lotOccupantTypeId: number | string): boolean => {
+
+ const database = sqlite(databasePath);
+
+ const currentOrderNumber: number = database.prepare("select orderNumber" +
+ " from LotOccupantTypes" +
+ " where lotOccupantTypeId = ?")
+ .get(lotOccupantTypeId)
+ .orderNumber;
+
+ if (currentOrderNumber <= 0) {
+ database.close();
+ return true;
+ }
+
+ database
+ .prepare("update LotOccupantTypes" +
+ " set orderNumber = orderNumber + 1" +
+ " where recordDelete_timeMillis is null" +
+ " and orderNumber = ? - 1")
+ .run(currentOrderNumber);
+
+ const result = database
+ .prepare("update LotOccupantTypes" +
+ " set orderNumber = ? - 1" +
+ " where lotOccupantTypeId = ?")
+ .run(currentOrderNumber, lotOccupantTypeId);
+
+ database.close();
+
+ clearLotOccupantTypesCache();
+
+ return result.changes > 0;
+ };
+
+
+export default moveLotOccupantTypeUp;
\ No newline at end of file
diff --git a/helpers/lotOccupancyDB/updateLotOccupantType.d.ts b/helpers/lotOccupancyDB/updateLotOccupantType.d.ts
new file mode 100644
index 00000000..bd5a7c49
--- /dev/null
+++ b/helpers/lotOccupancyDB/updateLotOccupantType.d.ts
@@ -0,0 +1,7 @@
+import type * as recordTypes from "../../types/recordTypes";
+interface UpdateLotOccupantTypeForm {
+ lotOccupantTypeId: number | string;
+ lotOccupantType: string;
+}
+export declare const updateLotOccupantType: (lotOccupantTypeForm: UpdateLotOccupantTypeForm, requestSession: recordTypes.PartialSession) => boolean;
+export default updateLotOccupantType;
diff --git a/helpers/lotOccupancyDB/updateLotOccupantType.js b/helpers/lotOccupancyDB/updateLotOccupantType.js
new file mode 100644
index 00000000..7bdb4e27
--- /dev/null
+++ b/helpers/lotOccupancyDB/updateLotOccupantType.js
@@ -0,0 +1,19 @@
+import sqlite from "better-sqlite3";
+import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
+import { clearLotOccupantTypesCache } from "../functions.cache.js";
+export const updateLotOccupantType = (lotOccupantTypeForm, requestSession) => {
+ const database = sqlite(databasePath);
+ const rightNowMillis = Date.now();
+ 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);
+ database.close();
+ clearLotOccupantTypesCache();
+ return result.changes > 0;
+};
+export default updateLotOccupantType;
diff --git a/helpers/lotOccupancyDB/updateLotOccupantType.ts b/helpers/lotOccupancyDB/updateLotOccupantType.ts
new file mode 100644
index 00000000..4de68af7
--- /dev/null
+++ b/helpers/lotOccupancyDB/updateLotOccupantType.ts
@@ -0,0 +1,47 @@
+import sqlite from "better-sqlite3";
+
+import {
+ lotOccupancyDB as databasePath
+} from "../../data/databasePaths.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);
+
+ const rightNowMillis = Date.now();
+
+ 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);
+
+ database.close();
+
+ clearLotOccupantTypesCache();
+
+ return result.changes > 0;
+ };
+
+
+export default updateLotOccupantType;
\ No newline at end of file
diff --git a/public-typescript/adminTables.js b/public-typescript/adminTables.js
index 9195505e..bd031a07 100644
--- a/public-typescript/adminTables.js
+++ b/public-typescript/adminTables.js
@@ -352,4 +352,181 @@ Object.defineProperty(exports, "__esModule", { value: true });
});
});
renderLotStatuses();
+ let lotOccupantTypes = exports.lotOccupantTypes;
+ delete exports.lotOccupantTypes;
+ const updateLotOccupantType = (submitEvent) => {
+ submitEvent.preventDefault();
+ cityssm.postJSON(urlPrefix + "/admin/doUpdateLotOccupantType", submitEvent.currentTarget, (responseJSON) => {
+ if (responseJSON.success) {
+ lotOccupantTypes = responseJSON.lotOccupantTypes;
+ bulmaJS.alert({
+ message: exports.aliases.lot + " " + exports.aliases.occupant + " Type Updated Successfully",
+ contextualColorName: "success"
+ });
+ }
+ else {
+ bulmaJS.alert({
+ title: "Error Updating " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
+ message: responseJSON.errorMessage,
+ contextualColorName: "danger"
+ });
+ }
+ });
+ };
+ const deleteLotOccupantType = (clickEvent) => {
+ const tableRowElement = clickEvent.currentTarget.closest("tr");
+ const lotOccupantTypeId = tableRowElement.dataset.lotOccupantTypeId;
+ const doDelete = () => {
+ cityssm.postJSON(urlPrefix + "/admin/doDeleteLotOccupantType", {
+ lotOccupantTypeId
+ }, (responseJSON) => {
+ if (responseJSON.success) {
+ lotOccupantTypes = responseJSON.lotOccupantTypes;
+ if (lotOccupantTypes.length === 0) {
+ renderLotOccupantTypes();
+ }
+ else {
+ tableRowElement.remove();
+ }
+ bulmaJS.alert({
+ message: exports.aliases.lot + " " + exports.aliases.occupant + " Type Deleted Successfully",
+ contextualColorName: "success"
+ });
+ }
+ else {
+ bulmaJS.alert({
+ title: "Error Deleting " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
+ message: responseJSON.errorMessage,
+ contextualColorName: "danger"
+ });
+ }
+ });
+ };
+ bulmaJS.confirm({
+ title: "Delete " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
+ message: "Are you sure you want to delete this " + exports.aliases.lot.toLowerCase() + " " + exports.aliases.occupant.toLowerCase() + " type?
" +
+ "Note that no " + exports.aliases.lot.toLowerCase() + " " + exports.aliases.occupancy.toLowerCase() + " will be removed.",
+ messageIsHtml: true,
+ contextualColorName: "warning",
+ okButton: {
+ text: "Yes, Delete " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
+ callbackFunction: doDelete
+ }
+ });
+ };
+ const moveLotOccupantTypeUp = (clickEvent) => {
+ const tableRowElement = clickEvent.currentTarget.closest("tr");
+ const lotOccupantTypeId = tableRowElement.dataset.lotOccupantTypeId;
+ cityssm.postJSON(urlPrefix + "/admin/doMoveLotOccupantTypeUp", {
+ lotOccupantTypeId
+ }, (responseJSON) => {
+ if (responseJSON.success) {
+ lotOccupantTypes = responseJSON.lotOccupantTypes;
+ renderLotOccupantTypes();
+ }
+ else {
+ bulmaJS.alert({
+ title: "Error Moving " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
+ message: responseJSON.errorMessage,
+ contextualColorName: "danger"
+ });
+ }
+ });
+ };
+ const moveLotOccupantTypeDown = (clickEvent) => {
+ const tableRowElement = clickEvent.currentTarget.closest("tr");
+ const lotOccupantTypeId = tableRowElement.dataset.lotOccupantTypeId;
+ cityssm.postJSON(urlPrefix + "/admin/doMoveLotOccupantTypeDown", {
+ lotOccupantTypeId
+ }, (responseJSON) => {
+ if (responseJSON.success) {
+ lotOccupantTypes = responseJSON.lotOccupantTypes;
+ renderLotOccupantTypes();
+ }
+ else {
+ bulmaJS.alert({
+ title: "Error Moving " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
+ message: responseJSON.errorMessage,
+ contextualColorName: "danger"
+ });
+ }
+ });
+ };
+ const renderLotOccupantTypes = () => {
+ const containerElement = document.querySelector("#container--lotOccupantTypes");
+ if (workOrderTypes.length === 0) {
+ containerElement.innerHTML = "
| <%= configFunctions.getProperty("aliases.lot") %> <%= configFunctions.getProperty("aliases.occupant") %> Type | +Options | +
|---|---|
| + + | +|