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

Update User Implemented

parent 9af8a485
No related branches found
No related tags found
1 merge request!9Create endpoint for user-registration
......@@ -133,6 +133,7 @@ export async function login(req,res){
}
}
export async function getUser(req,res){
const { username } = req.params;
......@@ -154,3 +155,39 @@ export async function getUser(req,res){
return res.status(404).send({ error: "Cannot find User Data"});
}
}
/** PUT: http://localhost:8080/api/updateuser
*
. * @param: {
"header" : "<token>"
}
body: {
firstName: '',
address : '',
profile : ''
}
*/
export async function updateUser(req,res){
try {
const id = req.query.id;
if(id){
const body = req.body;
// update the data
UserModel.updateOne({ _id : id }, body, function(err, data){
if(err) throw err;
return res.status(201).send({ msg : "Record Updated...!"});
})
}else{
return res.status(401).send({ error : "User Not Found...!"});
}
} catch (error) {
return res.status(401).send({ error });
}
}
......@@ -10,4 +10,8 @@ router.route('/login').post(controller.verifyUser, controller.login); // Login
/** GET Methods */
router.route('/user/:username').get(controller.getUser); // GetUser
/** PUT Methods */
router.route('/updateuser').put(controller.updateUser); // is use to update the user profile
export default router;
\ No newline at end of file
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