summaryrefslogtreecommitdiffstats
path: root/models/boards.js
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2018-06-26 11:55:11 +0200
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>2018-10-23 18:48:05 +0200
commitf61942e5cb672d3e0fd4df6c5ff9b3f15f7cb778 (patch)
treeb7f89a1804dd52def53616baed628dc428c55cf8 /models/boards.js
parent33d4ad76caefede0680a7868b9772f9917fd4d90 (diff)
downloadwekan-f61942e5cb672d3e0fd4df6c5ff9b3f15f7cb778.tar.gz
wekan-f61942e5cb672d3e0fd4df6c5ff9b3f15f7cb778.tar.bz2
wekan-f61942e5cb672d3e0fd4df6c5ff9b3f15f7cb778.zip
models: boards: add PUT members entry point
Allows to change the members from the API.
Diffstat (limited to 'models/boards.js')
-rw-r--r--models/boards.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/models/boards.js b/models/boards.js
index a44de8fa..cae6cf9f 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -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 });
},
@@ -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);