mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
Modified user search to include whole word search
This commit is contained in:
+10
-4
@@ -24,6 +24,7 @@ const ActionsService = require('./actions');
|
||||
const MailerService = require('./mailer');
|
||||
const Wordlist = require('./wordlist');
|
||||
const Domainlist = require('./domainlist');
|
||||
const {escapeRegExp} = require('./regex');
|
||||
|
||||
const EMAIL_CONFIRM_JWT_SUBJECT = 'email_confirm';
|
||||
const PASSWORD_RESET_JWT_SUBJECT = 'password_reset';
|
||||
@@ -630,14 +631,19 @@ module.exports = class UsersService {
|
||||
* @return {Promise}
|
||||
*/
|
||||
static search(value) {
|
||||
if (!value || typeof value !== 'string' || value.length === 0) {
|
||||
return UserModel.find({});
|
||||
}
|
||||
|
||||
value = escapeRegExp(value);
|
||||
|
||||
return UserModel.find({
|
||||
$or: [
|
||||
|
||||
// Search by a prefix match on the username.
|
||||
{
|
||||
'username': {
|
||||
$regex: new RegExp(`^${value}`),
|
||||
$options: 'i'
|
||||
'lowercaseUsername': {
|
||||
$regex: new RegExp(value.toLowerCase())
|
||||
}
|
||||
},
|
||||
|
||||
@@ -646,7 +652,7 @@ module.exports = class UsersService {
|
||||
'profiles': {
|
||||
$elemMatch: {
|
||||
id: {
|
||||
$regex: new RegExp(`^${value}`),
|
||||
$regex: new RegExp(value),
|
||||
$options: 'i'
|
||||
},
|
||||
provider: 'local'
|
||||
|
||||
Reference in New Issue
Block a user