Created
February 9, 2012 05:25
-
-
Save landongn/1777577 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){ | |
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); | |
}); | |
} else { | |
console.log('user has already voted'); | |
} | |
}); | |
}); | |
}); | |
if (has_voted) { | |
return null; | |
} else { | |
return data; | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment