-
-
Save jeromegn/1777604 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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