Skip to content

Instantly share code, notes, and snippets.

@antidiestro
Created August 25, 2014 22:13
Show Gist options
  • Save antidiestro/a0d0e2a461ce3292b440 to your computer and use it in GitHub Desktop.
Save antidiestro/a0d0e2a461ce3292b440 to your computer and use it in GitHub Desktop.
// Server
Votes.allow({
insert: function (userId, vote){
var voteCheck = Votes.findOne({user_id: userId, video_id: vote.video_id});
if ( voteCheck ) {
return false;
} else {
if ( userId && vote.user_id === userId ) {
return true;
} else {
return false;
}
}
},
remove: function(userId, vote){
if ( userId && vote.user_id === userId ) {
return true;
} else {
return false;
}
}
});
// Template file
Template.roomPage.events({
'click .proposed-videos-list li': function(){
if ( !Meteor.userId() ) {
$('#loginModal').modal('show');
return;
}
var voteCheck = Votes.findOne({user_id: Meteor.userId(), video_id: this._id});
if ( voteCheck ) {
Votes.remove({_id: voteCheck._id});
} else {
Votes.insert({user_id: Meteor.userId(), video_id: this._id});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment