Merge branch 'master' of github.com:SachaG/Telescope

This commit is contained in:
Sacha Greif 2012-09-18 08:29:10 +09:00
commit 5c49ade0ad
2 changed files with 21 additions and 22 deletions

21
lib/vote.js Normal file
View file

@ -0,0 +1,21 @@
Meteor.methods({
voteForPost: function(post){
console.log('voting for ' + post._id);
var userId = this.userId();
if(!userId) return false;
// atomically update the post's votes
var query = {_id: post._id, voters: {$ne: userId}};
var update = {$push: {voters: userId}, $inc: {votes: 1}};
Posts.update(query, update);
if (!this.is_simulation) {
// now update the post's score
post = Posts.findOne(post._id);
Scoring.updateObject(post);
Posts.update(post._id, {$set: {score: post.score}});
}
return true;
}
});

View file

@ -30,25 +30,3 @@ var Scoring = {
});
}
}
Meteor.methods({
voteForPost: function(post){
var userId = this.userId();
if(!userId) return false;
// atomically update the post's votes
var query = {_id: post._id, voters: {$ne: userId}};
var update = {$push: {voters: userId}, $inc: {votes: 1}};
Posts.update(query, update);
// now update the post's score
post = Posts.findOne(post._id);
Scoring.updateObject(post);
Posts.update(post._id, {$set: {score: post.score}});
return true;
}
});