Skip to content

Commit

Permalink
fix nonprofits totalSavings errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Jul 27, 2015
1 parent b9d544d commit 1b9608f
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions server/boot/nonprofits.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var Rx = require('rx');
var debug = require('debug')('freecc:nonprofits');
var observeMethod = require('../utils/rx').observeMethod;
var unDasherize = require('../utils').unDasherize;
Expand All @@ -15,18 +16,19 @@ module.exports = function(app) {
app.use(router);

function nonprofitsDirectory(req, res, next) {
var sum = 0;
findNonprofits({}).subscribe(
function(nonprofits) {
nonprofits = nonprofits.sort(function(a, b) {
return b.moneySaved - a.moneySaved;
});
totalSavings = function() {
for(i = 0; i < nonprofits.length; i++) {
sum += nonprofits[i].moneySaved;
}
return sum;
}();
findNonprofits({
order: 'moneySaved DESC'
})
.flatMap(
(nonprofits = []) => {
// turn array of nonprofits into observable array
return Rx.Observable.from(nonprofits)
.pluck('moneySaved')
.reduce((sum, moneySaved = 0) => sum + moneySaved, 0);
},
(nonprofits = [], totalSavings) => ({ nonprofits, totalSavings })
)
.subscribe(({ nonprofits, totalSavings }) => {
res.render('nonprofits/directory', {
title: 'Nonprofits we help',
nonprofits: nonprofits,
Expand Down Expand Up @@ -78,8 +80,6 @@ module.exports = function(app) {
}
}



res.render('nonprofits/show', {
dashedName: dashedNameFull,
title: nonprofit.name,
Expand Down

0 comments on commit 1b9608f

Please sign in to comment.