const cal = require('./calendar'); function computeUserTable(user, callback) { let result = {}; cal.getTotal(user, (table) => { let courses = []; let total = { name: "Total", type: "", time: 0, tdEquivalent: 0, } for (let key in table) { courses.push({ name: key, type: table[key].type, time: table[key].time, tdEquivalent: table[key].tdEquivalent, }); total.time += table[key].time; total.tdEquivalent += table[key].tdEquivalent; } result.courses = courses; result.total = total; callback(result); }); } module.exports.total = function(req, res, render) { render('total.pug'); } module.exports.totalTable = function(req, res, render) { computeUserTable(req.session.user, (result) => { res.locals.courses = result.courses; res.locals.total = result.total; render('totalTable.pug'); }); }