feat: add messaging toggles, password reset SMS, and payment discounts
Allow SuperAdmin to disable SMS, email, and bot from dashboard settings on top of env flags. Add admin password reset with credentials SMS, plus payment discounts, notes, and payable amount handling.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const NOTES_MAX_LENGTH = 5000;
|
||||
|
||||
const toNonNegativeNumber = (value) => {
|
||||
const n = Number(value);
|
||||
if (!Number.isFinite(n) || n < 0) return 0;
|
||||
return n;
|
||||
};
|
||||
|
||||
const normalizeDiscount = (discount, amount) => {
|
||||
return Math.min(toNonNegativeNumber(discount), toNonNegativeNumber(amount));
|
||||
};
|
||||
|
||||
const getPayableAmount = (payment = {}) => {
|
||||
const amount = toNonNegativeNumber(payment.amount);
|
||||
return amount - normalizeDiscount(payment.discount, amount);
|
||||
};
|
||||
|
||||
const sanitizeNotes = (notes) => {
|
||||
if (notes == null) return '';
|
||||
return String(notes).trim().slice(0, NOTES_MAX_LENGTH);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
NOTES_MAX_LENGTH,
|
||||
getPayableAmount,
|
||||
normalizeDiscount,
|
||||
sanitizeNotes
|
||||
};
|
||||
Reference in New Issue
Block a user