Created
December 8, 2014 01:09
-
-
Save AdamBrodzinski/74136d11d4bc4f3cbbe0 to your computer and use it in GitHub Desktop.
Meteor Model
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
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