Skip to content
Snippets Groups Projects
Commit 670fba3b authored by Ahmad, Rezwan (PG/T - Comp Sci & Elec Eng)'s avatar Ahmad, Rezwan (PG/T - Comp Sci & Elec Eng)
Browse files

getUser Controller Created

parent 089cc203
No related branches found
No related tags found
1 merge request!9Create endpoint for user-registration
......@@ -135,7 +135,22 @@ export async function login(req,res){
export async function getUser(req,res){
// const { username } = req.params;
const { username } = req.params;
res.json('getUser route')
try {
if(!username) return res.status(501).send({error: "Invalid Username"});
UserModel.findOne({username}, function(err, user){
if(err) return res.status(500).send({err});
if(!user) return res.status(501).send({ error: "Couldn't find the User"});
const { password, ...rest } = Object.assign({}, user.toJSON());
return res.status(201).send(rest)
})
}catch(err) {
return res.status(404).send({ error: "Cannot find User Data"});
}
}
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