Six site improvements picked from a "what could be better" review, plus a Jest test suite covering the two areas with the trickiest money-handling history in this project (early-bird pricing tranches, donation-leg accounting): - "Add to calendar" .ics download on event pages and in confirmation emails - sitemap.xml, robots.txt, and Open Graph/Twitter metadata for public pages - Sentry error monitoring (backend + frontend), a no-op until SENTRY_DSN is set - Nightly local pg_dump backups with a Site Settings tab to browse/trigger/download - Admin audit trail for refunds, donations, manual registrations, event and settings changes, and staff-initiated cancellations - Jest tests reproducing and guarding against the 1.8.0 tranche-pricing bug and the 1.4.2 donation-balance-inflation bug Wallet passes (Google/Apple) were scoped out of this round — Apple Wallet needs a paid Apple Developer account the project doesn't have yet, and the user preferred shipping both together later rather than Google alone now. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
19 lines
951 B
JavaScript
19 lines
951 B
JavaScript
/**
|
|
* Donations are never mutated once created — their remaining balance is the original
|
|
* amount minus every "leg" (a Payment row with isDonation:false and originalPaymentId
|
|
* pointing back at this donation) already allocated from it. A refund of the donation
|
|
* itself also creates a leg, with a negative amount — Math.abs() so a refund reduces
|
|
* the remaining balance (money that's left the building) instead of increasing it
|
|
* (which a raw signed sum would do, since subtracting a negative adds).
|
|
*
|
|
* @param {number} originalAmount - the donation payment's own amount
|
|
* @param {Array<{amount: number}>} legs - Payment rows with originalPaymentId === donation.id
|
|
* @returns {number}
|
|
*/
|
|
function computeDonationRemaining(originalAmount, legs) {
|
|
const alreadyUsed = (legs || []).reduce((sum, leg) => sum + Math.abs(leg.amount), 0);
|
|
return Number(originalAmount || 0) - alreadyUsed;
|
|
}
|
|
|
|
module.exports = { computeDonationRemaining };
|