Skip to content

Instantly share code, notes, and snippets.

@dai-shi
Created March 28, 2016 06:21
Show Gist options
  • Select an option

  • Save dai-shi/b62a01695ba4b824c770 to your computer and use it in GitHub Desktop.

Select an option

Save dai-shi/b62a01695ba4b824c770 to your computer and use it in GitHub Desktop.
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