quick update fee amounts

deepsource-autofix-76c6eb20
Dan Gowans 2024-07-02 11:17:28 -04:00
parent 18dbd282b6
commit 72d83f433a
12 changed files with 342 additions and 33 deletions

View File

@ -15,3 +15,8 @@ export interface UpdateFeeForm {
isRequired: '' | '1';
}
export default function updateFee(feeForm: UpdateFeeForm, user: User): Promise<boolean>;
export interface UpdateFeeAmountForm {
feeId: string;
feeAmount: string;
}
export declare function updateFeeAmount(feeAmountForm: UpdateFeeAmountForm, user: User): Promise<boolean>;

View File

@ -26,3 +26,16 @@ export default async function updateFee(feeForm, user) {
database.release();
return result.changes > 0;
}
export async function updateFeeAmount(feeAmountForm, user) {
const database = await acquireConnection();
const result = database
.prepare(`update Fees
set feeAmount = ?,
recordUpdate_userName = ?,
recordUpdate_timeMillis = ?
where recordDelete_timeMillis is null
and feeId = ?`)
.run(feeAmountForm.feeAmount, user.userName, Date.now(), feeAmountForm.feeId);
database.release();
return result.changes > 0;
}

View File

@ -69,3 +69,35 @@ export default async function updateFee(
return result.changes > 0
}
export interface UpdateFeeAmountForm {
feeId: string
feeAmount: string
}
export async function updateFeeAmount(
feeAmountForm: UpdateFeeAmountForm,
user: User
): Promise<boolean> {
const database = await acquireConnection()
const result = database
.prepare(
`update Fees
set feeAmount = ?,
recordUpdate_userName = ?,
recordUpdate_timeMillis = ?
where recordDelete_timeMillis is null
and feeId = ?`
)
.run(
feeAmountForm.feeAmount,
user.userName,
Date.now(),
feeAmountForm.feeId
)
database.release()
return result.changes > 0
}

View File

@ -0,0 +1,3 @@
/// <reference types="cookie-parser" />
import type { Request, Response } from 'express';
export default function handler(request: Request, response: Response): Promise<void>;

View File

@ -0,0 +1,12 @@
import getFeeCategories from '../../database/getFeeCategories.js';
import { updateFeeAmount } from '../../database/updateFee.js';
export default async function handler(request, response) {
const success = await updateFeeAmount(request.body, request.session.user);
const feeCategories = await getFeeCategories({}, {
includeFees: true
});
response.json({
success,
feeCategories
});
}

View File

@ -0,0 +1,29 @@
import type { Request, Response } from 'express'
import getFeeCategories from '../../database/getFeeCategories.js'
import {
type UpdateFeeAmountForm,
updateFeeAmount
} from '../../database/updateFee.js'
export default async function handler(
request: Request,
response: Response
): Promise<void> {
const success = await updateFeeAmount(
request.body as UpdateFeeAmountForm,
request.session.user as User
)
const feeCategories = await getFeeCategories(
{},
{
includeFees: true
}
)
response.json({
success,
feeCategories
})
}

View File

@ -8,8 +8,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
const feeCategoriesContainerElement = document.querySelector('#container--feeCategories');
let feeCategories = exports.feeCategories;
delete exports.feeCategories;
function getFeeCategory(feeCategoryId) {
return feeCategories.find((currentFeeCategory) => {
return currentFeeCategory.feeCategoryId === feeCategoryId;
});
}
function getFee(feeCategory, feeId) {
return feeCategory.fees.find((currentFee) => {
return currentFee.feeId === feeId;
});
}
function renderFeeCategories() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
if (feeCategories.length === 0) {
feeCategoriesContainerElement.innerHTML = `<div class="message is-warning">
<p class="message-body">There are no available fees.</p>
@ -87,7 +97,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
panelBlockElement.innerHTML = `<div class="columns">
<div class="column is-half">
<p>
<a class="has-text-weight-bold" href="#">${cityssm.escapeHTML((_e = fee.feeName) !== null && _e !== void 0 ? _e : '')}</a><br />
<a class="has-text-weight-bold a--editFee" href="#">${cityssm.escapeHTML((_e = fee.feeName) !== null && _e !== void 0 ? _e : '')}</a><br />
<small>
${
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
@ -122,8 +132,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
${fee.feeFunction
? `${cityssm.escapeHTML(fee.feeFunction)}<br />
<small>Fee Function</small>`
: `$${((_m = fee.feeAmount) !== null && _m !== void 0 ? _m : 0).toFixed(2)}<br />
<small>Fee</small>`}
: `<a class="a--editFeeAmount" href="#">
$${((_m = fee.feeAmount) !== null && _m !== void 0 ? _m : 0).toFixed(2)}<br />
<small>Fee</small>
</a>`}
</div>
<div class="column has-text-centered">
${fee.taxPercentage
@ -144,15 +156,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
</div>
</div>`;
(_q = panelBlockElement
.querySelector('a')) === null || _q === void 0 ? void 0 : _q.addEventListener('click', openEditFee);
.querySelector('.a--editFee')) === null || _q === void 0 ? void 0 : _q.addEventListener('click', openEditFee);
(_r = panelBlockElement
.querySelector('.a--editFeeAmount')) === null || _r === void 0 ? void 0 : _r.addEventListener('click', openEditFeeAmount);
panelBlockElement.querySelector('.button--moveFeeUp').addEventListener('click', moveFee);
panelBlockElement.querySelector('.button--moveFeeDown').addEventListener('click', moveFee);
feeCategoryContainerElement.append(panelBlockElement);
}
(_r = feeCategoryContainerElement
.querySelector('.button--editFeeCategory')) === null || _r === void 0 ? void 0 : _r.addEventListener('click', openEditFeeCategory);
(_s = feeCategoryContainerElement
.querySelector('.button--addFee')) === null || _s === void 0 ? void 0 : _s.addEventListener('click', openAddFee);
.querySelector('.button--editFeeCategory')) === null || _s === void 0 ? void 0 : _s.addEventListener('click', openEditFeeCategory);
(_t = feeCategoryContainerElement
.querySelector('.button--addFee')) === null || _t === void 0 ? void 0 : _t.addEventListener('click', openAddFee);
feeCategoryContainerElement.querySelector('.button--moveFeeCategoryUp').addEventListener('click', moveFeeCategory);
feeCategoryContainerElement.querySelector('.button--moveFeeCategoryDown').addEventListener('click', moveFeeCategory);
feeCategoriesContainerElement.append(feeCategoryContainerElement);
@ -201,9 +215,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
function openEditFeeCategory(clickEvent) {
var _a;
const feeCategoryId = Number.parseInt((_a = clickEvent.currentTarget.closest('.container--feeCategory').dataset.feeCategoryId) !== null && _a !== void 0 ? _a : '', 10);
const feeCategory = feeCategories.find((currentFeeCategory) => {
return currentFeeCategory.feeCategoryId === feeCategoryId;
});
const feeCategory = getFeeCategory(feeCategoryId);
let editCloseModalFunction;
function doUpdateFeeCategory(submitEvent) {
submitEvent.preventDefault();
@ -410,6 +422,54 @@ Object.defineProperty(exports, "__esModule", { value: true });
}
});
}
function openEditFeeAmount(clickEvent) {
var _a, _b;
clickEvent.preventDefault();
const feeContainerElement = clickEvent.currentTarget.closest('.container--fee');
const feeId = Number.parseInt((_a = feeContainerElement.dataset.feeId) !== null && _a !== void 0 ? _a : '', 10);
const feeCategoryId = Number.parseInt((_b = feeContainerElement.closest('.container--feeCategory')
.dataset.feeCategoryId) !== null && _b !== void 0 ? _b : '');
const feeCategory = getFeeCategory(feeCategoryId);
const fee = getFee(feeCategory, feeId);
let editCloseModalFunction;
function doUpdateFeeAmount(submitEvent) {
submitEvent.preventDefault();
cityssm.postJSON(`${los.urlPrefix}/admin/doUpdateFeeAmount`, submitEvent.currentTarget, (rawResponseJSON) => {
var _a;
const responseJSON = rawResponseJSON;
if (responseJSON.success) {
feeCategories = responseJSON.feeCategories;
editCloseModalFunction();
renderFeeCategories();
}
else {
bulmaJS.alert({
title: 'Error Updating Fee Amount',
message: (_a = responseJSON.errorMessage) !== null && _a !== void 0 ? _a : '',
contextualColorName: 'danger'
});
}
});
}
cityssm.openHtmlModal('adminFees-editFeeAmount', {
onshow(modalElement) {
var _a, _b, _c;
;
modalElement.querySelector('#feeAmountEdit--feeId').value = fee.feeId.toString();
modalElement.querySelector('#feeAmountEdit--feeCategory').textContent = feeCategory.feeCategory;
modalElement.querySelector('#feeAmountEdit--feeName').textContent = (_a = fee.feeName) !== null && _a !== void 0 ? _a : '';
modalElement.querySelector('#feeAmountEdit--feeAmount').value = (_c = (_b = fee.feeAmount) === null || _b === void 0 ? void 0 : _b.toFixed(2)) !== null && _c !== void 0 ? _c : '0';
},
onshown(modalElement, closeModalFunction) {
var _a;
;
modalElement.querySelector('#feeAmountEdit--feeAmount').select();
editCloseModalFunction = closeModalFunction;
(_a = modalElement
.querySelector('form')) === null || _a === void 0 ? void 0 : _a.addEventListener('submit', doUpdateFeeAmount);
}
});
}
function openEditFee(clickEvent) {
var _a, _b;
clickEvent.preventDefault();
@ -417,12 +477,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
const feeId = Number.parseInt((_a = feeContainerElement.dataset.feeId) !== null && _a !== void 0 ? _a : '', 10);
const feeCategoryId = Number.parseInt((_b = feeContainerElement.closest('.container--feeCategory')
.dataset.feeCategoryId) !== null && _b !== void 0 ? _b : '');
const feeCategory = feeCategories.find((currentFeeCategory) => {
return currentFeeCategory.feeCategoryId === feeCategoryId;
});
const fee = feeCategory.fees.find((currentFee) => {
return currentFee.feeId === feeId;
});
const feeCategory = getFeeCategory(feeCategoryId);
const fee = getFee(feeCategory, feeId);
let editCloseModalFunction;
let editModalElement;
function doUpdateFee(submitEvent) {

View File

@ -36,6 +36,18 @@ declare const exports: Record<string, unknown>
errorMessage: string
}
function getFeeCategory(feeCategoryId: number): FeeCategory {
return feeCategories.find((currentFeeCategory) => {
return currentFeeCategory.feeCategoryId === feeCategoryId
}) as FeeCategory
}
function getFee(feeCategory: FeeCategory, feeId: number): Fee {
return feeCategory.fees.find((currentFee) => {
return currentFee.feeId === feeId
}) as Fee
}
function renderFeeCategories(): void {
if (feeCategories.length === 0) {
feeCategoriesContainerElement.innerHTML = `<div class="message is-warning">
@ -140,7 +152,7 @@ declare const exports: Record<string, unknown>
panelBlockElement.innerHTML = `<div class="columns">
<div class="column is-half">
<p>
<a class="has-text-weight-bold" href="#">${cityssm.escapeHTML(fee.feeName ?? '')}</a><br />
<a class="has-text-weight-bold a--editFee" href="#">${cityssm.escapeHTML(fee.feeName ?? '')}</a><br />
<small>
${
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
@ -185,8 +197,10 @@ declare const exports: Record<string, unknown>
fee.feeFunction
? `${cityssm.escapeHTML(fee.feeFunction)}<br />
<small>Fee Function</small>`
: `$${(fee.feeAmount ?? 0).toFixed(2)}<br />
<small>Fee</small>`
: `<a class="a--editFeeAmount" href="#">
$${(fee.feeAmount ?? 0).toFixed(2)}<br />
<small>Fee</small>
</a>`
}
</div>
<div class="column has-text-centered">
@ -216,8 +230,12 @@ declare const exports: Record<string, unknown>
</div>`
panelBlockElement
.querySelector('a')
.querySelector('.a--editFee')
?.addEventListener('click', openEditFee)
panelBlockElement
.querySelector('.a--editFeeAmount')
?.addEventListener('click', openEditFeeAmount)
;(
panelBlockElement.querySelector(
'.button--moveFeeUp'
@ -322,9 +340,7 @@ declare const exports: Record<string, unknown>
10
)
const feeCategory = feeCategories.find((currentFeeCategory) => {
return currentFeeCategory.feeCategoryId === feeCategoryId
}) as FeeCategory
const feeCategory = getFeeCategory(feeCategoryId)
let editCloseModalFunction: () => void
@ -639,6 +655,85 @@ declare const exports: Record<string, unknown>
})
}
function openEditFeeAmount(clickEvent: Event): void {
clickEvent.preventDefault()
const feeContainerElement = (
clickEvent.currentTarget as HTMLElement
).closest('.container--fee') as HTMLElement
const feeId = Number.parseInt(feeContainerElement.dataset.feeId ?? '', 10)
const feeCategoryId = Number.parseInt(
(feeContainerElement.closest('.container--feeCategory') as HTMLElement)
.dataset.feeCategoryId ?? ''
)
const feeCategory = getFeeCategory(feeCategoryId)
const fee = getFee(feeCategory, feeId)
let editCloseModalFunction: () => void
function doUpdateFeeAmount(submitEvent: SubmitEvent): void {
submitEvent.preventDefault()
cityssm.postJSON(
`${los.urlPrefix}/admin/doUpdateFeeAmount`,
submitEvent.currentTarget,
(rawResponseJSON) => {
const responseJSON = rawResponseJSON as ResponseJSON
if (responseJSON.success) {
feeCategories = responseJSON.feeCategories
editCloseModalFunction()
renderFeeCategories()
} else {
bulmaJS.alert({
title: 'Error Updating Fee Amount',
message: responseJSON.errorMessage ?? '',
contextualColorName: 'danger'
})
}
}
)
}
cityssm.openHtmlModal('adminFees-editFeeAmount', {
onshow(modalElement) {
;(
modalElement.querySelector(
'#feeAmountEdit--feeId'
) as HTMLInputElement
).value = fee.feeId.toString()
;(
modalElement.querySelector(
'#feeAmountEdit--feeCategory'
) as HTMLElement
).textContent = feeCategory.feeCategory
;(
modalElement.querySelector('#feeAmountEdit--feeName') as HTMLElement
).textContent = fee.feeName ?? ''
;(
modalElement.querySelector(
'#feeAmountEdit--feeAmount'
) as HTMLInputElement
).value = fee.feeAmount?.toFixed(2) ?? '0'
},
onshown(modalElement, closeModalFunction) {
;(
modalElement.querySelector(
'#feeAmountEdit--feeAmount'
) as HTMLInputElement
).select()
editCloseModalFunction = closeModalFunction
modalElement
.querySelector('form')
?.addEventListener('submit', doUpdateFeeAmount)
}
})
}
function openEditFee(clickEvent: Event): void {
clickEvent.preventDefault()
@ -652,13 +747,9 @@ declare const exports: Record<string, unknown>
.dataset.feeCategoryId ?? ''
)
const feeCategory = feeCategories.find((currentFeeCategory) => {
return currentFeeCategory.feeCategoryId === feeCategoryId
}) as FeeCategory
const feeCategory = getFeeCategory(feeCategoryId)
const fee = feeCategory.fees.find((currentFee) => {
return currentFee.feeId === feeId
}) as Fee
const fee = getFee(feeCategory, feeId)
let editCloseModalFunction: () => void
let editModalElement: HTMLElement

View File

@ -0,0 +1,59 @@
<div class="modal" role="dialog">
<div class="modal-background"></div>
<div class="modal-card" style="width:500px">
<header class="modal-card-head">
<h3 class="modal-card-title">
Update Fee Amount
</h3>
<button
class="delete is-close-modal-button"
aria-label="close"
type="button"
></button>
</header>
<section class="modal-card-body">
<form id="form--feeAmountEdit">
<input id="feeAmountEdit--feeId" name="feeId" type="hidden" />
<p class="mb-2">
<strong>Fee Category</strong><br />
<span id="feeAmountEdit--feeCategory"></span>
</p>
<p class="mb-2">
<strong>Fee Name</strong><br />
<span id="feeAmountEdit--feeName"></span>
</p>
<div class="field">
<label class="label" for="feeAmountEdit--feeAmount">Fee Amount</label>
<div class="control has-icons-left">
<input
class="input has-text-right"
id="feeAmountEdit--feeAmount"
name="feeAmount"
type="number"
step="0.01"
min="0"
max="999999.99"
value="0"
onwheel="return false"
required
/>
<span class="icon is-small is-left">
<i class="fas fa-dollar-sign" aria-hidden="true"></i>
</span>
</div>
</div>
</form>
</section>
<footer class="modal-card-foot justify-right">
<button class="button is-success" type="submit" form="form--feeAmountEdit">
<span class="icon"><i class="fas fa-save" aria-hidden="true"></i></span>
<span>Update Fee Amount</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

View File

@ -52,6 +52,7 @@ import handler_doMoveWorkOrderMilestoneTypeUp from '../handlers/admin-post/doMov
import handler_doMoveWorkOrderTypeDown from '../handlers/admin-post/doMoveWorkOrderTypeDown.js';
import handler_doMoveWorkOrderTypeUp from '../handlers/admin-post/doMoveWorkOrderTypeUp.js';
import handler_doUpdateFee from '../handlers/admin-post/doUpdateFee.js';
import handler_doUpdateFeeAmount from '../handlers/admin-post/doUpdateFeeAmount.js';
import handler_doUpdateFeeCategory from '../handlers/admin-post/doUpdateFeeCategory.js';
import handler_doUpdateLotOccupantType from '../handlers/admin-post/doUpdateLotOccupantType.js';
import handler_doUpdateLotStatus from '../handlers/admin-post/doUpdateLotStatus.js';
@ -74,6 +75,7 @@ router.post('/doMoveFeeCategoryDown', handler_doMoveFeeCategoryDown);
router.post('/doDeleteFeeCategory', handler_doDeleteFeeCategory);
router.post('/doAddFee', handler_doAddFee);
router.post('/doUpdateFee', handler_doUpdateFee);
router.post('/doUpdateFeeAmount', handler_doUpdateFeeAmount);
router.post('/doMoveFeeUp', handler_doMoveFeeUp);
router.post('/doMoveFeeDown', handler_doMoveFeeDown);
router.post('/doDeleteFee', handler_doDeleteFee);
@ -140,7 +142,9 @@ router.post('/doUpdateLotOccupantType', handler_doUpdateLotOccupantType);
router.post('/doMoveLotOccupantTypeUp', handler_doMoveLotOccupantTypeUp);
router.post('/doMoveLotOccupantTypeDown', handler_doMoveLotOccupantTypeDown);
router.post('/doDeleteLotOccupantType', handler_doDeleteLotOccupantType);
// Database Maintenance
/*
* Database Maintenance
*/
router.get('/database', handler_database);
router.post('/doBackupDatabase', handler_doBackupDatabase);
router.post('/doCleanupDatabase', handler_doCleanupDatabase);

View File

@ -53,6 +53,7 @@ import handler_doMoveWorkOrderMilestoneTypeUp from '../handlers/admin-post/doMov
import handler_doMoveWorkOrderTypeDown from '../handlers/admin-post/doMoveWorkOrderTypeDown.js'
import handler_doMoveWorkOrderTypeUp from '../handlers/admin-post/doMoveWorkOrderTypeUp.js'
import handler_doUpdateFee from '../handlers/admin-post/doUpdateFee.js'
import handler_doUpdateFeeAmount from '../handlers/admin-post/doUpdateFeeAmount.js'
import handler_doUpdateFeeCategory from '../handlers/admin-post/doUpdateFeeCategory.js'
import handler_doUpdateLotOccupantType from '../handlers/admin-post/doUpdateLotOccupantType.js'
import handler_doUpdateLotStatus from '../handlers/admin-post/doUpdateLotStatus.js'
@ -99,6 +100,8 @@ router.post('/doAddFee', handler_doAddFee as RequestHandler)
router.post('/doUpdateFee', handler_doUpdateFee as RequestHandler)
router.post('/doUpdateFeeAmount', handler_doUpdateFeeAmount as RequestHandler)
router.post('/doMoveFeeUp', handler_doMoveFeeUp as RequestHandler)
router.post('/doMoveFeeDown', handler_doMoveFeeDown as RequestHandler)
@ -321,7 +324,9 @@ router.post(
handler_doDeleteLotOccupantType as RequestHandler
)
// Database Maintenance
/*
* Database Maintenance
*/
router.get('/database', handler_database)