Added a method to get a user by id or name
This commit is contained in:
parent
20755e4063
commit
b1b6cea0c8
@ -8,9 +8,16 @@ module.exports.getUserById = async (id) => {
|
||||
return await User.findById(id).exec();
|
||||
}
|
||||
|
||||
// Gets a user by name
|
||||
// Gets a user by name (ignore case)
|
||||
module.exports.getUserByName = async (username) => {
|
||||
return await User.findOne({username: {$regex: username, $options: 'i'}}).exec();
|
||||
return User.findOne({username}).collation({locale: "en", strength: 2});
|
||||
}
|
||||
|
||||
// Gets a user by name or id
|
||||
module.exports.getUser = async (usernameOrId) => {
|
||||
if (!mongo.ObjectId.isValid(usernameOrId)) return await this.getUserByName(usernameOrId);
|
||||
|
||||
return await User.findOne({$or: [{_id: usernameOrId}, {username: usernameOrId}]}).exec();
|
||||
}
|
||||
|
||||
// Creates a new user account
|
||||
|
Loading…
x
Reference in New Issue
Block a user