Skip to content

Instantly share code, notes, and snippets.

@AdamBrodzinski
Created December 8, 2014 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamBrodzinski/74136d11d4bc4f3cbbe0 to your computer and use it in GitHub Desktop.
Save AdamBrodzinski/74136d11d4bc4f3cbbe0 to your computer and use it in GitHub Desktop.
Meteor Model
Post = {
create: function(data, callback) {
return Meteor.call('Post.create', data, callback);
},
update: function(docId, data, callback) {
return Meteor.call('Post.update', docId, data, callback);
},
destroy: function(docId, callback) {
return Meteor.call('Post.destroy', docId, callback);
}
};
Meteor.methods({
...
// Returns {Number} of documents updated
'Post.update': function(docId, data) {
check(docId, String);
check(data, { title: String, desc: String });
if (!this.userId) throw new Meteor.Error(503, "You must be logged in");
// if caller doesn't own document this should fail because the query field will not match
return db.posts.update({_id: docId, ownerId: this.userId}, {$set: data});
},
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment