Procházet zdrojové kódy

Add search cards helper to boards model

Ghassen Rjab před 7 roky
rodič
revize
2001c01b4d
1 změnil soubory, kde provedl 21 přidání a 0 odebrání
  1. 21 0
      models/boards.js

+ 21 - 0
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({