From f077e40c4c7f4d8e8dd658d918c61f9336baedbc Mon Sep 17 00:00:00 2001 From: jbusa22 <41833473+jbusa22@users.noreply.github.com> Date: Mon, 30 Nov 2020 14:05:58 -0500 Subject: [PATCH] use or clause for display name and username search (#12820) * use or clause for display name and username search * update styling * More style fix * update comment and regex --- website/server/controllers/api-v3/members.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/website/server/controllers/api-v3/members.js b/website/server/controllers/api-v3/members.js index bdd6f9020a..def73153d9 100644 --- a/website/server/controllers/api-v3/members.js +++ b/website/server/controllers/api-v3/members.js @@ -322,9 +322,12 @@ function _getMembersForItem (type) { } if (req.query.search) { - // Creates a RegExp expression when querying for profile.name + // Creates a RegExp expression when querying for profile.name and auth.local.username const escapedSearch = escapeRegExp(req.query.search); - query['profile.name'] = { $regex: new RegExp(escapedSearch, 'i') }; + query.$or = [ + { 'profile.name': { $regex: new RegExp(escapedSearch, 'i') } }, + { 'auth.local.username': { $regex: new RegExp(req.query.search, 'i') } }, + ]; } } else if (type === 'group-invites') { if (group.type === 'guild') { // eslint-disable-line no-lonely-if