summaryrefslogtreecommitdiffstats
path: root/models/lists.js
diff options
context:
space:
mode:
authorsoohwa <none@none.none>2017-10-15 07:39:48 +0200
committersoohwa <none@none.none>2017-10-15 07:39:48 +0200
commit97a23011dabe9727f9395794e2f3f6f213ffe21a (patch)
treeffc81555e39ba51bb00a0fe823ef7bc6ad96b9e8 /models/lists.js
parent624719974e578caa92217bb51d67a0a307f35ce6 (diff)
downloadwekan-97a23011dabe9727f9395794e2f3f6f213ffe21a.tar.gz
wekan-97a23011dabe9727f9395794e2f3f6f213ffe21a.tar.bz2
wekan-97a23011dabe9727f9395794e2f3f6f213ffe21a.zip
Add REST API better error output
Diffstat (limited to 'models/lists.js')
-rw-r--r--models/lists.js114
1 files changed, 73 insertions, 41 deletions
diff --git a/models/lists.js b/models/lists.js
index 1b999b07..75c39d2a 100644
--- a/models/lists.js
+++ b/models/lists.js
@@ -194,56 +194,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,
+ });
+ }
});
}