Created
March 28, 2016 06:21
-
-
Save dai-shi/b62a01695ba4b824c770 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| diff --git a/imports/api/tasks.js b/imports/api/tasks.js | |
| index 3bed819..0201eb4 100644 | |
| --- a/imports/api/tasks.js | |
| +++ b/imports/api/tasks.js | |
| @@ -1,3 +1,34 @@ | |
| +import { Meteor } from 'meteor/meteor'; | |
| import { Mongo } from 'meteor/mongo'; | |
| +import { check } from 'meteor/check'; | |
| export const Tasks = new Mongo.Collection('tasks'); | |
| + | |
| +Meteor.methods({ | |
| + 'tasks.insert'(text) { | |
| + check(text, String); | |
| + | |
| + // Make sure the user is logged in before inserting a task | |
| + if (! Meteor.userId()) { | |
| + throw new Meteor.Error('not-authorized'); | |
| + } | |
| + | |
| + Tasks.insert({ | |
| + text, | |
| + createdAt: new Date(), | |
| + owner: Meteor.userId(), | |
| + username: Meteor.user().username, | |
| + }); | |
| + }, | |
| + 'tasks.remove'(taskId) { | |
| + check(taskId, String); | |
| + | |
| + Tasks.remove(taskId); | |
| + }, | |
| + 'tasks.setChecked'(taskId, setChecked) { | |
| + check(taskId, String); | |
| + check(setChecked, Boolean); | |
| + | |
| + Tasks.update(taskId, { $set: { checked: setChecked } }); | |
| + }, | |
| +}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment