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();
|
return await User.findById(id).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets a user by name
|
// Gets a user by name (ignore case)
|
||||||
module.exports.getUserByName = async (username) => {
|
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
|
// Creates a new user account
|
||||||
@ -30,7 +37,7 @@ module.exports.updateAccount = async (user_id, changes) => {
|
|||||||
module.exports.updateUserSocials = async (user_id, socials) => {
|
module.exports.updateUserSocials = async (user_id, socials) => {
|
||||||
let updatedSocials = {};
|
let updatedSocials = {};
|
||||||
for (let social in socials)
|
for (let social in socials)
|
||||||
updatedSocials["socials."+social] = socials[social];
|
updatedSocials["socials." + social] = socials[social];
|
||||||
|
|
||||||
if (!mongo.ObjectId.isValid(user_id)) return;
|
if (!mongo.ObjectId.isValid(user_id)) return;
|
||||||
return await User.findByIdAndUpdate(user_id, {$set: updatedSocials}).exec();
|
return await User.findByIdAndUpdate(user_id, {$set: updatedSocials}).exec();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user