mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
Merge branch 'master' of github.com:SachaG/Telescope
This commit is contained in:
commit
5c49ade0ad
2 changed files with 21 additions and 22 deletions
21
lib/vote.js
Normal file
21
lib/vote.js
Normal 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;
|
||||
}
|
||||
});
|
|
@ -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;
|
||||
}
|
||||
});
|
Loading…
Add table
Reference in a new issue