瀏覽代碼

Step 11.3: Add setPrivate method.

Frederic G. MARAND 8 年之前
父節點
當前提交
5d95340afd
共有 1 個文件被更改,包括 11 次插入0 次删除
  1. 11 0
      simple-todos-react.jsx

+ 11 - 0
simple-todos-react.jsx

@@ -46,5 +46,16 @@ Meteor.methods({
     // Without checking user ?
     Meteor._debug("setCheck", taskId, setChecked);
     Tasks.update(taskId, { $set: { checked: setChecked }});
+  },
+
+  setPrivate(taskId, setToPrivate) {
+    const task = Tasks.findOne(taskId);
+
+    // Make sure only the task owneer can make a task private.
+    if (task.owner !== Meteor.userId()) {
+      throw new Meteor.Error("not-authorized");
+    }
+
+    Tasks.update(taskId, { $set: { private: setToPrivate }});
   }
 });