Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jeromegn
Forked from landongn/gist:1777577
Created February 9, 2012 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeromegn/1777604 to your computer and use it in GitHub Desktop.
Save jeromegn/1777604 to your computer and use it in GitHub Desktop.
up_vote: function(data, callback){
data.type="upvote";
console.log(has_voted, 'has_voted, line 87');
mdb.collection('kudos_bank', function(err, coll){
coll.find({'target_hash':data.target_hash, 'id':data.id}, function(err, cursor){
cursor.toArray(function(err, docs){
console.log(docs);
if (docs.length == 0) {
console.log('row length was 0, user hasnt voted');
has_voted = false;
} else {
has_voted = true;
}
if (!has_voted) {
mdb.collection('content', function(err, content_db){
content_db.update({'hash':data.target_hash}, {"$inc":{"ups":1}});
});
mdb.collection('users', function(err, users_db){
users_db.update({'id':data.target_user}, {"$inc":{"kudos.ups":1, "kudos.total":1}});
});
mdb.collection('kudos_bank', function(err, kudos_db){
kudos_db.insert(data);
});
return callback(null, data);
} else {
console.log('user has already voted');
return callback(null, null);
}
});
});
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment