diff --git a/server/index.js b/server/index.js index 5cb18ff..2014bce 100644 --- a/server/index.js +++ b/server/index.js @@ -166,6 +166,16 @@ router.get('/', async (req, res) => { .count('* as total_people'))[0] + // get latest pledges + let recentPledges = ( + await Pledge + .forge() + .orderBy('created_at', 'DESC') + .fetchPage({ limit: 5 }) + ).models + + if (DEBUG) console.log(`Listing ${recentPledges.length} pledges`) + twing.render('index.htm.twig', { 'goal_rupees': Number(goalRupees).toLocaleString('en-IN'), 'goal_people': Number(goalPeople).toLocaleString('en-IN'), @@ -173,6 +183,7 @@ router.get('/', async (req, res) => { 'progress_people': Number(total_people).toLocaleString('en-IN'), 'percent_rupees': `style="width: ${total_rupees/goalRupees*100}%"`, 'percent_people': `style="width: ${total_people/goalPeople*100}%"`, + 'recent_pledges': recentPledges, }).then((output) => { res.end(output) }) @@ -473,6 +484,32 @@ router.get('/thanks', async (req, res) => { return }) +router.get('/pledges', async (req, res) => { + if (DEBUG) console.debug('Returning pledges list') + + // count people + let { total_people, total_rupees } = (await knex('pledges') + .sum('amount as total_rupees') + .count('* as total_people'))[0] + + + // get latest pledges + let recentPledges = ( + await Pledge + .forge() + .orderBy('created_at', 'DESC') + .fetchPage({ limit: 5 }) + ).models + + if (DEBUG) console.log(`Listing ${recentPledges.length} pledges`) + + twing.render('pledges.htm.twig', { + 'recent_pledges': recentPledges, + }).then((output) => { + res.end(output) + }) +}) + router.use(express.static('src/assets')) // start the listener! diff --git a/src/index.htm.twig b/src/index.htm.twig index f8ed0c7..f4e6824 100644 --- a/src/index.htm.twig +++ b/src/index.htm.twig @@ -69,6 +69,43 @@ Add your Pledge + {% if recent_pledges %} +
+ {% endif %}{% if pledge.get('anonymous') %}Anonymous{% else %}{{ pledge.get('name') }}{% endif %}
+₹{{ pledge.get('amount') }}
+ {% if pledge.get('other_message') %} +{{ pledge.get('other_message')}}
+ {% endif %} +