diff --git a/client/components/main/globalSearch.js b/client/components/main/globalSearch.js index 133fa1433..50bc9ae7e 100644 --- a/client/components/main/globalSearch.js +++ b/client/components/main/globalSearch.js @@ -96,7 +96,7 @@ class GlobalSearchComponent extends CardSearchPagedComponent { // eslint-disable-next-line no-console // console.log('params:', query.getParams()); - this.queryParams = query.getParams(); + this.queryParams = query.getQueryParams().getParams(); if (query.hasErrors()) { this.searching.set(false); @@ -106,7 +106,7 @@ class GlobalSearchComponent extends CardSearchPagedComponent { return; } - this.runGlobalSearch(query.getParams()); + this.runGlobalSearch(query.getQueryParams()); } searchInstructions() { diff --git a/client/lib/cardSearch.js b/client/lib/cardSearch.js index 621b8bd3d..9d89f2447 100644 --- a/client/lib/cardSearch.js +++ b/client/lib/cardSearch.js @@ -99,13 +99,14 @@ export class CardSearchPagedComponent extends BlazeComponent { } } - runGlobalSearch(params) { + runGlobalSearch(queryParams) { this.searching.set(true); this.stopSubscription(); this.subscriptionHandle = Meteor.subscribe( 'globalSearch', this.sessionId, - params, + queryParams.params, + queryParams.text, this.subscriptionCallbacks, ); } diff --git a/config/query-classes.js b/config/query-classes.js index 3120dce71..2c8a49ee0 100644 --- a/config/query-classes.js +++ b/config/query-classes.js @@ -45,12 +45,15 @@ import moment from 'moment'; export class QueryParams { text = ''; - constructor(params = {}) { + constructor(params = {}, text = '') { this.params = params; + this.text = text; } hasOperator(operator) { - return this.params[operator]; + return ( + this.params[operator] !== undefined && this.params[operator].length > 0 + ); } addPredicate(operator, predicate) { @@ -189,8 +192,8 @@ export class Query { return this._errors.errorMessages(); } - getParams() { - return this.queryParams.getParams(); + getQueryParams() { + return this.queryParams; } addPredicate(operator, predicate) { diff --git a/server/publications/cards.js b/server/publications/cards.js index 99cc596a8..33314ef30 100644 --- a/server/publications/cards.js +++ b/server/publications/cards.js @@ -80,14 +80,15 @@ Meteor.publish('myCards', function(sessionId) { // return buildQuery(sessionId, queryParams); // }); -Meteor.publish('globalSearch', function(sessionId, params) { +Meteor.publish('globalSearch', function(sessionId, params, text) { check(sessionId, String); check(params, Object); + check(text, String); // eslint-disable-next-line no-console // console.log('queryParams:', params); - return findCards(sessionId, buildQuery(new QueryParams(params))); + return findCards(sessionId, buildQuery(new QueryParams(params, text))); }); function buildSelector(queryParams) { @@ -97,6 +98,9 @@ function buildSelector(queryParams) { let selector = {}; + // eslint-disable-next-line no-console + // console.log('queryParams:', queryParams); + if (queryParams.selector) { selector = queryParams.selector; } else { @@ -249,17 +253,13 @@ function buildSelector(queryParams) { queryUsers[OPERATOR_MEMBER] = []; if (queryParams.hasOperator(OPERATOR_USER)) { - queryParams.getPredicates(OPERATOR_USER).forEach(query => { - const users = Users.find({ - username: query, - }); - if (users.count()) { - users.forEach(user => { - queryUsers[OPERATOR_MEMBER].push(user._id); - queryUsers[OPERATOR_ASSIGNEE].push(user._id); - }); + queryParams.getPredicates(OPERATOR_USER).forEach(username => { + const user = Users.findOne({ username }); + if (user) { + queryUsers[OPERATOR_MEMBER].push(user._id); + queryUsers[OPERATOR_ASSIGNEE].push(user._id); } else { - errors.addNotFound(OPERATOR_USER, query); + errors.addNotFound(OPERATOR_USER, username); } }); }