Browse Source

Fix invites

Justin Reynolds 5 years ago
parent
commit
66b45ed35c
2 changed files with 15 additions and 2 deletions
  1. 2 2
      client/components/boards/boardsList.js
  2. 13 0
      models/boards.js

+ 2 - 2
client/components/boards/boardsList.js

@@ -82,13 +82,13 @@ BlazeComponent.extendComponent({
         },
         'click .js-accept-invite'() {
           const boardId = this.currentData()._id;
-          Meteor.user().removeInvite(boardId);
+          Meteor.call('acceptInvite', boardId);
         },
         'click .js-decline-invite'() {
           const boardId = this.currentData()._id;
           Meteor.call('quitBoard', boardId, (err, ret) => {
             if (!err && ret) {
-              Meteor.user().removeInvite(boardId);
+              Meteor.call('acceptInvite', boardId);
               FlowRouter.go('home');
             }
           });

+ 13 - 0
models/boards.js

@@ -952,6 +952,19 @@ if (Meteor.isServer) {
         } else throw new Meteor.Error('error-board-notAMember');
       } else throw new Meteor.Error('error-board-doesNotExist');
     },
+    acceptInvite(boardId) {
+      check(boardId, String);
+      const board = Boards.findOne(boardId);
+      if (!board) {
+        throw new Meteor.Error('error-board-doesNotExist');
+      }
+
+      Meteor.users.update(Meteor.userId(), {
+        $pull: {
+          'profile.invitedBoards': boardId,
+        },
+      });
+    },
   });
 
   Meteor.methods({