Skip to content

Commit

Permalink
quick update fee amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Jul 2, 2024
1 parent 18dbd28 commit 72d83f4
Show file tree
Hide file tree
Showing 12 changed files with 342 additions and 33 deletions.
5 changes: 5 additions & 0 deletions database/updateFee.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
13 changes: 13 additions & 0 deletions database/updateFee.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
32 changes: 32 additions & 0 deletions database/updateFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions handlers/admin-post/doUpdateFeeAmount.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="cookie-parser" />
import type { Request, Response } from 'express';
export default function handler(request: Request, response: Response): Promise<void>;
12 changes: 12 additions & 0 deletions handlers/admin-post/doUpdateFeeAmount.js
Original file line number Diff line number Diff line change
@@ -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
});
}
29 changes: 29 additions & 0 deletions handlers/admin-post/doUpdateFeeAmount.ts
Original file line number Diff line number Diff line change
@@ -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
})
}
90 changes: 73 additions & 17 deletions public-typescript/adminFees.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -410,19 +422,63 @@ Object.defineProperty(exports, "__esModule", { value: true });
}
});
}
function openEditFee(clickEvent) {
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 = 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;
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();
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;
let editModalElement;
function doUpdateFee(submitEvent) {
Expand Down
Loading

0 comments on commit 72d83f4

Please sign in to comment.