update occupancy type
parent
a4abbc055c
commit
9928c5ed04
|
|
@ -0,0 +1,3 @@
|
|||
import type { RequestHandler } from "express";
|
||||
export declare const handler: RequestHandler;
|
||||
export default handler;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import { updateOccupancyType } from "../../helpers/lotOccupancyDB/updateOccupancyType.js";
|
||||
import { getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||
export const handler = async (request, response) => {
|
||||
const success = updateOccupancyType(request.body, request.session);
|
||||
const occupancyTypes = getOccupancyTypes();
|
||||
response.json({
|
||||
success,
|
||||
occupancyTypes
|
||||
});
|
||||
};
|
||||
export default handler;
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
import type { RequestHandler } from "express";
|
||||
|
||||
import { updateOccupancyType } from "../../helpers/lotOccupancyDB/updateOccupancyType.js";
|
||||
|
||||
import { getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||
|
||||
export const handler: RequestHandler = async (request, response) => {
|
||||
const success = updateOccupancyType(request.body, request.session);
|
||||
|
||||
const occupancyTypes = getOccupancyTypes();
|
||||
|
||||
response.json({
|
||||
success,
|
||||
occupancyTypes
|
||||
});
|
||||
};
|
||||
|
||||
export default handler;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import type * as recordTypes from "../../types/recordTypes";
|
||||
interface UpdateOccupancyTypeForm {
|
||||
occupancyTypeId: number | string;
|
||||
occupancyType: string;
|
||||
}
|
||||
export declare const updateOccupancyType: (occupancyTypeForm: UpdateOccupancyTypeForm, requestSession: recordTypes.PartialSession) => boolean;
|
||||
export default updateOccupancyType;
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import sqlite from "better-sqlite3";
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||
export const updateOccupancyType = (occupancyTypeForm, requestSession) => {
|
||||
const database = sqlite(databasePath);
|
||||
const rightNowMillis = Date.now();
|
||||
const result = database
|
||||
.prepare("update OccupancyTypes" +
|
||||
" set occupancyType = ?," +
|
||||
" recordUpdate_userName = ?," +
|
||||
" recordUpdate_timeMillis = ?" +
|
||||
" where occupancyTypeId = ?" +
|
||||
" and recordDelete_timeMillis is null")
|
||||
.run(occupancyTypeForm.occupancyType, requestSession.user.userName, rightNowMillis, occupancyTypeForm.occupancyTypeId);
|
||||
database.close();
|
||||
clearOccupancyTypesCache();
|
||||
return result.changes > 0;
|
||||
};
|
||||
export default updateOccupancyType;
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
import sqlite from "better-sqlite3";
|
||||
|
||||
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||
|
||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||
|
||||
import type * as recordTypes from "../../types/recordTypes";
|
||||
|
||||
interface UpdateOccupancyTypeForm {
|
||||
occupancyTypeId: number | string;
|
||||
occupancyType: string;
|
||||
}
|
||||
|
||||
export const updateOccupancyType = (
|
||||
occupancyTypeForm: UpdateOccupancyTypeForm,
|
||||
requestSession: recordTypes.PartialSession
|
||||
): boolean => {
|
||||
const database = sqlite(databasePath);
|
||||
|
||||
const rightNowMillis = Date.now();
|
||||
|
||||
const result = database
|
||||
.prepare(
|
||||
"update OccupancyTypes" +
|
||||
" set occupancyType = ?," +
|
||||
" recordUpdate_userName = ?," +
|
||||
" recordUpdate_timeMillis = ?" +
|
||||
" where occupancyTypeId = ?" +
|
||||
" and recordDelete_timeMillis is null"
|
||||
)
|
||||
.run(
|
||||
occupancyTypeForm.occupancyType,
|
||||
requestSession.user.userName,
|
||||
rightNowMillis,
|
||||
occupancyTypeForm.occupancyTypeId
|
||||
);
|
||||
|
||||
database.close();
|
||||
|
||||
clearOccupancyTypesCache();
|
||||
|
||||
return result.changes > 0;
|
||||
};
|
||||
|
||||
export default updateOccupancyType;
|
||||
|
|
@ -25,6 +25,50 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
panelBlockElement.classList.toggle("is-hidden");
|
||||
}
|
||||
};
|
||||
const openEditOccupancyType = (clickEvent) => {
|
||||
const occupancyTypeId = Number.parseInt(clickEvent.currentTarget.closest(".container--occupancyType").dataset.occupancyTypeId, 10);
|
||||
const occupancyType = occupancyTypes.find((currentOccupancyType) => {
|
||||
return occupancyTypeId === currentOccupancyType.occupancyTypeId;
|
||||
});
|
||||
let editCloseModalFunction;
|
||||
const doEdit = (submitEvent) => {
|
||||
submitEvent.preventDefault();
|
||||
cityssm.postJSON(urlPrefix + "/admin/doUpdateOccupancyType", submitEvent.currentTarget, (responseJSON) => {
|
||||
if (responseJSON.success) {
|
||||
editCloseModalFunction();
|
||||
occupancyTypes = responseJSON.occupancyTypes;
|
||||
renderOccupancyTypes();
|
||||
}
|
||||
else {
|
||||
bulmaJS.alert({
|
||||
title: "Error Updating " +
|
||||
exports.aliases.occupancy +
|
||||
" Type",
|
||||
message: responseJSON.errorMessage,
|
||||
contextualColorName: "danger"
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
cityssm.openHtmlModal("adminOccupancyTypes-editOccupancyType", {
|
||||
onshow: (modalElement) => {
|
||||
los.populateAliases(modalElement);
|
||||
modalElement.querySelector("#occupancyTypeEdit--occupancyTypeId").value = occupancyTypeId.toString();
|
||||
modalElement.querySelector("#occupancyTypeEdit--occupancyType").value = occupancyType.occupancyType;
|
||||
},
|
||||
onshown: (modalElement, closeModalFunction) => {
|
||||
editCloseModalFunction = closeModalFunction;
|
||||
modalElement.querySelector("#occupancyTypeEdit--occupancyType").focus();
|
||||
modalElement
|
||||
.querySelector("form")
|
||||
.addEventListener("submit", doEdit);
|
||||
bulmaJS.toggleHtmlClipped();
|
||||
},
|
||||
onremoved: () => {
|
||||
bulmaJS.toggleHtmlClipped();
|
||||
}
|
||||
});
|
||||
};
|
||||
const moveOccupancyTypeUp = (clickEvent) => {
|
||||
clickEvent.preventDefault();
|
||||
const occupancyTypeId = clickEvent.currentTarget.closest(".container--occupancyType").dataset.occupancyTypeId;
|
||||
|
|
@ -185,6 +229,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
occupancyTypeContainer
|
||||
.querySelector(".button--toggleOccupancyTypeFields")
|
||||
.addEventListener("click", toggleOccupancyTypeFields);
|
||||
occupancyTypeContainer
|
||||
.querySelector(".button--editOccupancyType")
|
||||
.addEventListener("click", openEditOccupancyType);
|
||||
occupancyTypeContainer
|
||||
.querySelector(".button--moveOccupancyTypeUp")
|
||||
.addEventListener("click", moveOccupancyTypeUp);
|
||||
|
|
|
|||
|
|
@ -57,6 +57,88 @@ declare const bulmaJS: BulmaJS;
|
|||
}
|
||||
};
|
||||
|
||||
const openEditOccupancyType = (clickEvent: Event) => {
|
||||
const occupancyTypeId = Number.parseInt(
|
||||
(
|
||||
(clickEvent.currentTarget as HTMLElement).closest(
|
||||
".container--occupancyType"
|
||||
) as HTMLElement
|
||||
).dataset.occupancyTypeId,
|
||||
10
|
||||
);
|
||||
|
||||
const occupancyType = occupancyTypes.find((currentOccupancyType) => {
|
||||
return occupancyTypeId === currentOccupancyType.occupancyTypeId;
|
||||
});
|
||||
|
||||
let editCloseModalFunction: () => void;
|
||||
|
||||
const doEdit = (submitEvent: SubmitEvent) => {
|
||||
submitEvent.preventDefault();
|
||||
|
||||
cityssm.postJSON(
|
||||
urlPrefix + "/admin/doUpdateOccupancyType",
|
||||
submitEvent.currentTarget,
|
||||
(responseJSON: {
|
||||
success: boolean;
|
||||
errorMessage?: string;
|
||||
occupancyTypes?: recordTypes.OccupancyType[];
|
||||
}) => {
|
||||
if (responseJSON.success) {
|
||||
editCloseModalFunction();
|
||||
occupancyTypes = responseJSON.occupancyTypes;
|
||||
renderOccupancyTypes();
|
||||
} else {
|
||||
bulmaJS.alert({
|
||||
title:
|
||||
"Error Updating " +
|
||||
exports.aliases.occupancy +
|
||||
" Type",
|
||||
message: responseJSON.errorMessage,
|
||||
contextualColorName: "danger"
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
cityssm.openHtmlModal("adminOccupancyTypes-editOccupancyType", {
|
||||
onshow: (modalElement) => {
|
||||
los.populateAliases(modalElement);
|
||||
|
||||
(
|
||||
modalElement.querySelector(
|
||||
"#occupancyTypeEdit--occupancyTypeId"
|
||||
) as HTMLInputElement
|
||||
).value = occupancyTypeId.toString();
|
||||
|
||||
(
|
||||
modalElement.querySelector(
|
||||
"#occupancyTypeEdit--occupancyType"
|
||||
) as HTMLInputElement
|
||||
).value = occupancyType.occupancyType;
|
||||
},
|
||||
onshown: (modalElement, closeModalFunction) => {
|
||||
editCloseModalFunction = closeModalFunction;
|
||||
|
||||
(
|
||||
modalElement.querySelector(
|
||||
"#occupancyTypeEdit--occupancyType"
|
||||
) as HTMLInputElement
|
||||
).focus();
|
||||
|
||||
modalElement
|
||||
.querySelector("form")
|
||||
.addEventListener("submit", doEdit);
|
||||
|
||||
bulmaJS.toggleHtmlClipped();
|
||||
},
|
||||
onremoved: () => {
|
||||
bulmaJS.toggleHtmlClipped();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const moveOccupancyTypeUp = (clickEvent: Event) => {
|
||||
clickEvent.preventDefault();
|
||||
|
||||
|
|
@ -270,6 +352,10 @@ declare const bulmaJS: BulmaJS;
|
|||
.querySelector(".button--toggleOccupancyTypeFields")
|
||||
.addEventListener("click", toggleOccupancyTypeFields);
|
||||
|
||||
occupancyTypeContainer
|
||||
.querySelector(".button--editOccupancyType")
|
||||
.addEventListener("click", openEditOccupancyType);
|
||||
|
||||
occupancyTypeContainer
|
||||
.querySelector(".button--moveOccupancyTypeUp")
|
||||
.addEventListener("click", moveOccupancyTypeUp);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
<div class="modal">
|
||||
<div class="modal-background"></div>
|
||||
<div class="modal-card" style="width:900px">
|
||||
<header class="modal-card-head">
|
||||
<h3 class="modal-card-title">
|
||||
Update <span class="alias" data-alias="Occupancy"></span> Type
|
||||
</h3>
|
||||
<button class="delete is-close-modal-button" aria-label="close" type="button"></button>
|
||||
</header>
|
||||
<section class="modal-card-body">
|
||||
<form id="form--occupancyTypeEdit">
|
||||
<input class="input" id="occupancyTypeEdit--occupancyTypeId" name="occupancyTypeId" type="hidden" />
|
||||
<div class="field">
|
||||
<label class="label" for="occupancyTypeEdit--occupancyType"><span class="alias" data-alias="Occupancy"></span> Type</label>
|
||||
<div class="control">
|
||||
<input class="input" id="occupancyTypeEdit--occupancyType" name="occupancyType" type="text" maxlength="100" required />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<footer class="modal-card-foot justify-right">
|
||||
<button class="button is-success" type="submit" form="form--occupancyTypeEdit">
|
||||
<span class="icon"><i class="fas fa-plus" aria-hidden="true"></i></span>
|
||||
<span>Update <span class="alias" data-alias="Occupancy"></span> Type</span>
|
||||
</button>
|
||||
<button class="button is-close-modal-button" type="button">Cancel</button>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -13,6 +13,7 @@ import handler_doMoveFeeDown from "../handlers/admin-post/doMoveFeeDown.js";
|
|||
import handler_doDeleteFee from "../handlers/admin-post/doDeleteFee.js";
|
||||
import handler_occupancyTypes from "../handlers/admin-get/occupancyTypes.js";
|
||||
import handler_doAddOccupancyType from "../handlers/admin-post/doAddOccupancyType.js";
|
||||
import handler_doUpdateOccupancyType from "../handlers/admin-post/doUpdateOccupancyType.js";
|
||||
import handler_doMoveOccupancyTypeUp from "../handlers/admin-post/doMoveOccupancyTypeUp.js";
|
||||
import handler_doMoveOccupancyTypeDown from "../handlers/admin-post/doMoveOccupancyTypeDown.js";
|
||||
import handler_tables from "../handlers/admin-get/tables.js";
|
||||
|
|
@ -45,6 +46,7 @@ router.post("/doMoveFeeDown", permissionHandlers.adminPostHandler, handler_doMov
|
|||
router.post("/doDeleteFee", permissionHandlers.adminPostHandler, handler_doDeleteFee);
|
||||
router.get("/occupancyTypes", permissionHandlers.adminGetHandler, handler_occupancyTypes);
|
||||
router.post("/doAddOccupancyType", permissionHandlers.adminPostHandler, handler_doAddOccupancyType);
|
||||
router.post("/doUpdateOccupancyType", permissionHandlers.adminPostHandler, handler_doUpdateOccupancyType);
|
||||
router.post("/doMoveOccupancyTypeUp", permissionHandlers.adminPostHandler, handler_doMoveOccupancyTypeUp);
|
||||
router.post("/doMoveOccupancyTypeDown", permissionHandlers.adminPostHandler, handler_doMoveOccupancyTypeDown);
|
||||
router.get("/tables", permissionHandlers.adminGetHandler, handler_tables);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import handler_doDeleteFee from "../handlers/admin-post/doDeleteFee.js";
|
|||
import handler_occupancyTypes from "../handlers/admin-get/occupancyTypes.js";
|
||||
|
||||
import handler_doAddOccupancyType from "../handlers/admin-post/doAddOccupancyType.js";
|
||||
import handler_doUpdateOccupancyType from "../handlers/admin-post/doUpdateOccupancyType.js";
|
||||
import handler_doMoveOccupancyTypeUp from "../handlers/admin-post/doMoveOccupancyTypeUp.js";
|
||||
import handler_doMoveOccupancyTypeDown from "../handlers/admin-post/doMoveOccupancyTypeDown.js";
|
||||
|
||||
|
|
@ -128,6 +129,12 @@ router.post(
|
|||
handler_doAddOccupancyType
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/doUpdateOccupancyType",
|
||||
permissionHandlers.adminPostHandler,
|
||||
handler_doUpdateOccupancyType
|
||||
);
|
||||
|
||||
router.post(
|
||||
"/doMoveOccupancyTypeUp",
|
||||
permissionHandlers.adminPostHandler,
|
||||
|
|
|
|||
Loading…
Reference in New Issue