diff options
author | Lauri Ojansivu <x@xet7.org> | 2018-10-23 20:44:35 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2018-10-23 20:44:35 +0300 |
commit | 0de01356197d0317f538aa9a3c6e0213b5dfd396 (patch) | |
tree | 5a691082a3da622f0ccbef723f07619ed463b6e4 /models/boards.js | |
parent | fa548a4c3266beaaa8da1049dc76602bfd3676e7 (diff) | |
parent | dfdba25ea0b9c3bcca81a9c8ba6a3e9ed7f4eec7 (diff) | |
download | wekan-0de01356197d0317f538aa9a3c6e0213b5dfd396.tar.gz wekan-0de01356197d0317f538aa9a3c6e0213b5dfd396.tar.bz2 wekan-0de01356197d0317f538aa9a3c6e0213b5dfd396.zip |
Merge branch 'api-fixes' of https://github.com/bentiss/wekan into bentiss-api-fixes
Diffstat (limited to 'models/boards.js')
-rw-r--r-- | models/boards.js | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/models/boards.js b/models/boards.js index 52d0ca87..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 }); }, @@ -823,9 +827,9 @@ if (Meteor.isServer) { } }); - JsonRoutes.add('GET', '/api/boards/:id', function (req, res) { + JsonRoutes.add('GET', '/api/boards/:boardId', function (req, res) { try { - const id = req.params.id; + const id = req.params.boardId; Authentication.checkBoardAccess(req.userId, id); JsonRoutes.sendResult(res, { @@ -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); @@ -878,10 +910,10 @@ if (Meteor.isServer) { } }); - JsonRoutes.add('DELETE', '/api/boards/:id', function (req, res) { + JsonRoutes.add('DELETE', '/api/boards/:boardId', function (req, res) { try { Authentication.checkUserId(req.userId); - const id = req.params.id; + const id = req.params.boardId; Boards.remove({ _id: id }); JsonRoutes.sendResult(res, { code: 200, @@ -898,9 +930,9 @@ if (Meteor.isServer) { } }); - JsonRoutes.add('PUT', '/api/boards/:id/labels', function (req, res) { + JsonRoutes.add('PUT', '/api/boards/:boardId/labels', function (req, res) { Authentication.checkUserId(req.userId); - const id = req.params.id; + const id = req.params.boardId; try { if (req.body.hasOwnProperty('label')) { const board = Boards.findOne({ _id: id }); |