diff options
author | Lauri Ojansivu <x@xet7.org> | 2017-11-19 10:45:04 +0200 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2017-11-19 10:45:04 +0200 |
commit | eceaac799884ded6586940b0716a3020fa36022d (patch) | |
tree | f9deb9762c3fa855d50e11c37fbd9eaab6ca91ba /models/lists.js | |
parent | 9353d785ea86b37cc83c88fec1b5b0a29cd9a888 (diff) | |
parent | c01335ee29b525cdc06938e15958c74c1fe11bf3 (diff) | |
download | wekan-eceaac799884ded6586940b0716a3020fa36022d.tar.gz wekan-eceaac799884ded6586940b0716a3020fa36022d.tar.bz2 wekan-eceaac799884ded6586940b0716a3020fa36022d.zip |
Merge branch 'soohwa-add-rest-api-bettor-error-output' into devel
REST API better error output. Thanks to soohwa ! Related #1037
Diffstat (limited to 'models/lists.js')
-rw-r--r-- | models/lists.js | 114 |
1 files changed, 73 insertions, 41 deletions
diff --git a/models/lists.js b/models/lists.js index efda9c3f..a5f4791b 100644 --- a/models/lists.js +++ b/models/lists.js @@ -198,56 +198,88 @@ if (Meteor.isServer) { //LISTS REST API if (Meteor.isServer) { JsonRoutes.add('GET', '/api/boards/:boardId/lists', function (req, res, next) { - const paramBoardId = req.params.boardId; - Authentication.checkBoardAccess( req.userId, paramBoardId); - - JsonRoutes.sendResult(res, { - code: 200, - data: Lists.find({ boardId: paramBoardId, archived: false }).map(function (doc) { - return { - _id: doc._id, - title: doc.title, - }; - }), - }); + try { + const paramBoardId = req.params.boardId; + Authentication.checkBoardAccess( req.userId, paramBoardId); + + JsonRoutes.sendResult(res, { + code: 200, + data: Lists.find({ boardId: paramBoardId, archived: false }).map(function (doc) { + return { + _id: doc._id, + title: doc.title, + }; + }), + }); + } + catch (error) { + JsonRoutes.sendResult(res, { + code: 200, + data: error, + }); + } }); JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId', function (req, res, next) { - const paramBoardId = req.params.boardId; - const paramListId = req.params.listId; - Authentication.checkBoardAccess( req.userId, paramBoardId); - JsonRoutes.sendResult(res, { - code: 200, - data: Lists.findOne({ _id: paramListId, boardId: paramBoardId, archived: false }), - }); + try { + const paramBoardId = req.params.boardId; + const paramListId = req.params.listId; + Authentication.checkBoardAccess( req.userId, paramBoardId); + JsonRoutes.sendResult(res, { + code: 200, + data: Lists.findOne({ _id: paramListId, boardId: paramBoardId, archived: false }), + }); + } + catch (error) { + JsonRoutes.sendResult(res, { + code: 200, + data: error, + }); + } }); JsonRoutes.add('POST', '/api/boards/:boardId/lists', function (req, res, next) { - Authentication.checkUserId( req.userId); - const paramBoardId = req.params.boardId; - const id = Lists.insert({ - title: req.body.title, - boardId: paramBoardId, - }); - JsonRoutes.sendResult(res, { - code: 200, - data: { - _id: id, - }, - }); + try { + Authentication.checkUserId( req.userId); + const paramBoardId = req.params.boardId; + const id = Lists.insert({ + title: req.body.title, + boardId: paramBoardId, + }); + JsonRoutes.sendResult(res, { + code: 200, + data: { + _id: id, + }, + }); + } + catch (error) { + JsonRoutes.sendResult(res, { + code: 200, + data: error, + }); + } }); JsonRoutes.add('DELETE', '/api/boards/:boardId/lists/:listId', function (req, res, next) { - Authentication.checkUserId( req.userId); - const paramBoardId = req.params.boardId; - const paramListId = req.params.listId; - Lists.remove({ _id: paramListId, boardId: paramBoardId }); - JsonRoutes.sendResult(res, { - code: 200, - data: { - _id: paramListId, - }, - }); + try { + Authentication.checkUserId( req.userId); + const paramBoardId = req.params.boardId; + const paramListId = req.params.listId; + Lists.remove({ _id: paramListId, boardId: paramBoardId }); + JsonRoutes.sendResult(res, { + code: 200, + data: { + _id: paramListId, + }, + }); + } + catch (error) { + JsonRoutes.sendResult(res, { + code: 200, + data: error, + }); + } }); } |