From 0319bcf7bb090328e67766234723f5986c00bba2 Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Thu, 27 Apr 2017 20:49:24 +0300 Subject: REST API - Meteor 1.4 - first step issue --- models/lists.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'models/lists.js') diff --git a/models/lists.js b/models/lists.js index 0ae3ca5f..a10e23b6 100644 --- a/models/lists.js +++ b/models/lists.js @@ -76,15 +76,15 @@ Lists.helpers({ Lists.mutations({ rename(title) { - return { $set: { title }}; + return { $set: { title } }; }, archive() { - return { $set: { archived: true }}; + return { $set: { archived: true } }; }, restore() { - return { $set: { archived: false }}; + return { $set: { archived: false } }; }, }); @@ -128,3 +128,55 @@ 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; + JsonRoutes.sendResult(res, { + code: 200, + data: Lists.find({ boardId: paramBoardId, archived: false }).map(function (doc) { + return { + _id: doc._id, + title: doc.title, + }; + }), + }); + }); + + JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId', function (req, res, next) { + const paramBoardId = req.params.boardId; + const paramListId = req.params.listId; + JsonRoutes.sendResult(res, { + code: 200, + data: Lists.findOne({ _id: paramListId, boardId: paramBoardId, archived: false }), + }); + }); + + JsonRoutes.add('POST', '/api/boards/:boardId/lists', function (req, res, next) { + const paramBoardId = req.params.boardId; + const id = Lists.insert({ + title: req.body.title, + boardId: paramBoardId, + }); + JsonRoutes.sendResult(res, { + code: 200, + data: { + _id: id, + }, + }); + }); + + JsonRoutes.add('DELETE', '/api/boards/:boardId/lists/:listId', function (req, res, next) { + const paramBoardId = req.params.boardId; + const paramListId = req.params.listId; + Lists.remove({ _id: paramListId, boardId: paramBoardId }); + JsonRoutes.sendResult(res, { + code: 200, + data: { + _id: paramListId, + }, + }); + }); + +} -- cgit v1.2.3-1-g7c22