Skip to content

Commit

Permalink
models: boards: add PUT members entry point
Browse files Browse the repository at this point in the history
Allows to change the members from the API.
  • Loading branch information
bentiss committed Oct 23, 2018
1 parent 33d4ad7 commit f61942e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions models/boards.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ Boards.helpers({
return Users.find({ _id: { $in: _.pluck(this.members, 'userId') } });
},

getMember(id) {
return _.findWhere(this.members, { userId: id });
},

getLabel(name, color) {
return _.findWhere(this.labels, { name, color });
},
Expand Down Expand Up @@ -841,6 +845,34 @@ if (Meteor.isServer) {
}
});

JsonRoutes.add('PUT', '/api/boards/:boardId/members', function (req, res) {
Authentication.checkUserId(req.userId);
try {
const boardId = req.params.boardId;
const board = Boards.findOne({ _id: boardId });
const userId = req.body.userId;
const user = Users.findOne({ _id: userId });

if (!board.getMember(userId)) {
user.addInvite(boardId);
board.addMember(userId);
JsonRoutes.sendResult(res, {
code: 200,
data: id,
});
} else {
JsonRoutes.sendResult(res, {
code: 200,
});
}
}
catch (error) {
JsonRoutes.sendResult(res, {
data: error,
});
}
});

JsonRoutes.add('POST', '/api/boards', function (req, res) {
try {
Authentication.checkUserId(req.userId);
Expand Down

0 comments on commit f61942e

Please sign in to comment.