Skip to content

Instantly share code, notes, and snippets.

@crtr0
Last active December 11, 2015 00:09
Show Gist options
  • Select an option

  • Save crtr0/4514708 to your computer and use it in GitHub Desktop.

Select an option

Save crtr0/4514708 to your computer and use it in GitHub Desktop.
voteCounts = exports.voteCounts = function(event, callback) {
db.view('event', 'all', {startkey: [event._id], endkey: [event._id, {}, {}], group_level: 2}, function(err, body) {
if (err) {
callback(err);
}
else {
// populate count for voteoptions
event.voteoptions.forEach(function(vo, i){
var found = _und.find(body.rows, function(x) {return x.key[1] == vo.id});
vo['votes'] = (found? found.value : 0);
});
callback();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment