summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorGhassen Rjab <rjab.ghassen@gmail.com>2018-02-23 01:09:25 +0100
committerGhassen Rjab <rjab.ghassen@gmail.com>2018-02-23 01:09:25 +0100
commit2001c01b4ddcf49e830a754e8b451308d78c3783 (patch)
tree781d95ad876070f98528b4f773ab3839e7a7392a /models
parenta9166d877ff8ffae382ce98b481e205cb465d832 (diff)
downloadwekan-2001c01b4ddcf49e830a754e8b451308d78c3783.tar.gz
wekan-2001c01b4ddcf49e830a754e8b451308d78c3783.tar.bz2
wekan-2001c01b4ddcf49e830a754e8b451308d78c3783.zip
Add search cards helper to boards model
Diffstat (limited to 'models')
-rw-r--r--models/boards.js21
1 files changed, 21 insertions, 0 deletions
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({