diff options
author | Giacomo Vespignani <giacomo.vespignani@acdsolutions.it> | 2020-05-27 11:13:09 +0200 |
---|---|---|
committer | Giacomo Vespignani <giacomo.vespignani@acdsolutions.it> | 2020-05-27 11:16:35 +0200 |
commit | c9a28db3ab5650178c933fc3d2284958dd0fd84d (patch) | |
tree | 05cb38e6bf8938798fb56b8e19973abd7f7e849b /models | |
parent | 1cfb6eee4beadbdb84f5a11eb040f63369903e75 (diff) | |
download | wekan-c9a28db3ab5650178c933fc3d2284958dd0fd84d.tar.gz wekan-c9a28db3ab5650178c933fc3d2284958dd0fd84d.tar.bz2 wekan-c9a28db3ab5650178c933fc3d2284958dd0fd84d.zip |
Added an API to get the cards for a specific custom field value
Diffstat (limited to 'models')
-rw-r--r-- | models/cards.js | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/models/cards.js b/models/cards.js index 939d1be3..b6cc27b7 100644 --- a/models/cards.js +++ b/models/cards.js @@ -1276,9 +1276,9 @@ Cards.mutations({ if (lastCardDom) sortIndex = Utils.calculateIndex(lastCardDom, null).base; return this.moveOptionalArgs({ - boardId: boardId, - swimlaneId: swimlaneId, - listId: listId, + boardId, + swimlaneId, + listId, sort: sortIndex, }); }, @@ -1293,8 +1293,7 @@ Cards.mutations({ swimlaneId = board.getDefaultSwimline()._id; } listId = listId || this.listId; - if (sort === undefined || sort === null) - sort = this.sort; + if (sort === undefined || sort === null) sort = this.sort; return this.move(boardId, swimlaneId, listId, sort); }, @@ -2683,6 +2682,52 @@ if (Meteor.isServer) { }); }, ); + + /** + * @operation get_cards_by_custom_field + * @summary Get all Cards that matchs a value of a specific custom field + * + * @param {string} boardId the board ID + * @param {string} customFieldId the list ID + * @param {string} customFieldValue the value to look for + * @return_type [{_id: string, + * title: string, + * description: string, + * listId: string + * swinlaneId: string}] + */ + JsonRoutes.add( + 'GET', + '/api/boards/:boardId/cardsByCustomField/:customFieldId/:customFieldValue', + function(req, res) { + const paramBoardId = req.params.boardId; + const paramCustomFieldId = req.params.customFieldId; + const paramCustomFieldValue = req.params.customFieldValue; + + Authentication.checkBoardAccess(req.userId, paramBoardId); + JsonRoutes.sendResult(res, { + code: 200, + data: Cards.find({ + boardId: paramBoardId, + customFields: { + $elemMatch: { + _id: paramCustomFieldId, + value: paramCustomFieldValue, + }, + }, + archived: false, + }).map(function(doc) { + return { + _id: doc._id, + title: doc.title, + description: doc.description, + listId: doc.listId, + swinlaneId: doc.swinlaneId, + }; + }), + }); + }, + ); } export default Cards; |