diff options
author | Lauri Ojansivu <x@xet7.org> | 2018-02-23 20:40:48 +0200 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2018-02-23 20:40:48 +0200 |
commit | a48630ffcfa5a5d96afad5960875da6e856ac079 (patch) | |
tree | 7fd0b4cbb66c3b09b4fe50e33dd6f9c38a0a8b9c /models/boards.js | |
parent | a9166d877ff8ffae382ce98b481e205cb465d832 (diff) | |
parent | fe1941008cbe2ad08576e9aad78fe15f68dd50d3 (diff) | |
download | wekan-a48630ffcfa5a5d96afad5960875da6e856ac079.tar.gz wekan-a48630ffcfa5a5d96afad5960875da6e856ac079.tar.bz2 wekan-a48630ffcfa5a5d96afad5960875da6e856ac079.zip |
Merge branch 'GhassenRjab-feature/search' into devel
Diffstat (limited to 'models/boards.js')
-rw-r--r-- | models/boards.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/models/boards.js b/models/boards.js index 84a715fb..55b0711c 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) { + const regex = new RegExp(term, 'i'); + + query = { + boardId: this._id, + $or: [ + { title: regex }, + { description: regex }, + ], + }; + } + + return Cards.find(query, projection); + }, }); Boards.mutations({ |