Skip to content

Commit

Permalink
Step 12.18: Add searchString to parties publication
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Kisiela authored and Dotan Simha committed Nov 22, 2016
1 parent 74d6635 commit 189a5f9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion imports/api/parties/publish.js
Expand Up @@ -4,7 +4,7 @@ import { Counts } from 'meteor/tmeasday:publish-counts';
import { Parties } from './collection';

if (Meteor.isServer) {
Meteor.publish('parties', function(options) {
Meteor.publish('parties', function(options, searchString) {
const selector = {
$or: [{
// the public parties
Expand All @@ -27,6 +27,13 @@ if (Meteor.isServer) {
}]
};

if (typeof searchString === 'string' && searchString.length) {
selector.name = {
$regex: `.*${searchString}.*`,
$options : 'i'
};
}

Counts.publish(this, 'numberOfParties', Parties.find(selector), {
noReady: true
});
Expand Down

0 comments on commit 189a5f9

Please sign in to comment.