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

Implemented new userlist endpoint

parent 581badad
No related branches found
No related tags found
1 merge request!16Add additional GET endpoints to user service
......@@ -70,7 +70,17 @@ export async function register(req,res){
// return save result as a response
user.save()
.then(result => res.status(201).send({ msg: "User Registered Successfully"}))
.then(async (result) => {
const user = await UserModel.findOne({username: username})
// create jwt token
const token = jwt.sign({
userId: user._id,
username : user.username
}, ENV.JWT_SECRET , { expiresIn : "24h"});
res.status(201).send({ msg: "User Registered Successfully", username: user.username, token })
})
.catch(error => res.status(500).send({error}))
}).catch(error => {
......@@ -195,3 +205,22 @@ export async function updateUser(req,res){
}
}
/**
* GET /userlist
* This DOES NOT return emails and passwords
* @param {*} req
* @param {*} res
* @returns
*
* body: {userIdList: []}
*/
export const GetUserList = async (req,res) => {
try {
const {userIdList} = req.body;
const users = await UserModel.find({ '_id': { $in: userIdList } }, {password: 0, email: 0});
return res.status(201).send({ userList: users});
} catch(error){
return res.status(401).send({ error });
}
}
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