mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
35 lines
884 B
JavaScript
35 lines
884 B
JavaScript
import {model as User} from '../../models/user';
|
|
|
|
let api = {};
|
|
|
|
|
|
api.getUsernameAutocompletes = {
|
|
method: 'GET',
|
|
url: '/members/find/:username',
|
|
middlewares: [],
|
|
async handler (req, res) {
|
|
req.checkParams('username', res.t('invalidReqParams')).notEmpty();
|
|
|
|
let validationErrors = req.validationErrors();
|
|
if (validationErrors) throw validationErrors;
|
|
|
|
let username = req.params.username.toLowerCase();
|
|
if (username[0] === '@') username = username.slice(1, username.length);
|
|
|
|
if (username.length < 2) {
|
|
res.respond(200, []);
|
|
return;
|
|
}
|
|
|
|
let members = await User
|
|
.find({'auth.local.lowerCaseUsername': {$regex: `.*${username}.*`}, 'flags.verifiedUsername': true})
|
|
.select(['profile.name', 'contributor', 'auth.local.username'])
|
|
.limit(20)
|
|
.exec();
|
|
|
|
res.respond(200, members);
|
|
},
|
|
};
|
|
|
|
module.exports = api;
|