From 2001c01b4ddcf49e830a754e8b451308d78c3783 Mon Sep 17 00:00:00 2001 From: Ghassen Rjab Date: Fri, 23 Feb 2018 01:09:25 +0100 Subject: Add search cards helper to boards model --- models/boards.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'models') diff --git a/models/boards.js b/models/boards.js index 84a715fb..61a9c87c 100644 --- a/models/boards.js +++ b/models/boards.js @@ -264,6 +264,27 @@ Boards.helpers({ Boards.direct.update(this._id, { $push: { labels: { _id, name, color } } }); return _id; }, + + searchCards(term) { + check(term, Match.OneOf(String, null, undefined)); + + let query = { boardId: this._id }; + const projection = { limit: 10, sort: { createdAt: -1 } }; + + if (term) { + let regex = new RegExp(term, 'i'); + + query = { + boardId: this._id, + $or: [ + { title: regex }, + { description: regex }, + ], + }; + } + + return Cards.find(query, projection); + }, }); Boards.mutations({ -- cgit v1.2.3-1-g7c22 From ab2884cae0dab07c2fbc279e4917113c32a22921 Mon Sep 17 00:00:00 2001 From: Ghassen Rjab Date: Fri, 23 Feb 2018 01:38:12 +0100 Subject: Fix lint error related to this feature --- models/boards.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models') diff --git a/models/boards.js b/models/boards.js index 61a9c87c..55b0711c 100644 --- a/models/boards.js +++ b/models/boards.js @@ -272,7 +272,7 @@ Boards.helpers({ const projection = { limit: 10, sort: { createdAt: -1 } }; if (term) { - let regex = new RegExp(term, 'i'); + const regex = new RegExp(term, 'i'); query = { boardId: this._id, -- cgit v1.2.3-1-g7c22