Skip to content
Snippets Groups Projects
Commit c6246bfa authored by Matt Kirby's avatar Matt Kirby
Browse files

Omit password and email fields

parent 4382f89e
No related branches found
No related tags found
1 merge request!16Add additional GET endpoints to user service
......@@ -225,7 +225,8 @@ export const GetUserList = async (req,res) => {
}
/**
* GET /searchuser
* GET /search
* This endpoint OMITS the password and email fields
* @param {*} req
* @param {*} res
* @returns
......@@ -239,8 +240,9 @@ export const GetUserList = async (req,res) => {
if(query === undefined || query.length === 0){
throw new Error("Please provide a valid query!")
}
const usersWithMatchingId = await UserModel.find({"username": {"$regex": `^${query}`}})
const usersWithMatchingName = await UserModel.find({$or: [{"firstName": {"$regex": `^${query}`}}, {"lastName": {"$regex": `^${query}`}}]})
const usersWithMatchingId = await UserModel.find({"username": {"$regex": `^${query}`}}, {password: 0, email: 0})
const usersWithMatchingName = await UserModel.find({$or: [{"firstName": {"$regex": `^${query}`}}, {"lastName": {"$regex": `^${query}`}}]}, {password: 0, email: 0})
return res.status(201).send({ usersById: usersWithMatchingId, usersByName: usersWithMatchingName});
} catch(error){
return res.status(401).send({ error: error.message });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment