From 85fdafbe8b756f85a41921b7b7b25c6e8435d3d3 Mon Sep 17 00:00:00 2001 From: Shaikh Rezwan Rafid Ahmad <sa03267@surrey.ac.uk> Date: Tue, 21 Mar 2023 16:41:50 +0000 Subject: [PATCH] Update User Implemented --- .../server/controllers/appController.js | 37 +++++++++++++++++++ .../server/router/route.js | 4 ++ 2 files changed, 41 insertions(+) diff --git a/daily-thought-user-service/server/controllers/appController.js b/daily-thought-user-service/server/controllers/appController.js index 7a681b0d..d0aba834 100644 --- a/daily-thought-user-service/server/controllers/appController.js +++ b/daily-thought-user-service/server/controllers/appController.js @@ -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 }); + } +} + diff --git a/daily-thought-user-service/server/router/route.js b/daily-thought-user-service/server/router/route.js index 42c2de1c..bf15b016 100644 --- a/daily-thought-user-service/server/router/route.js +++ b/daily-thought-user-service/server/router/route.js @@ -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 -- GitLab