diff --git a/daily-thought-user-service/server/controllers/appController.js b/daily-thought-user-service/server/controllers/appController.js index 7a681b0d39299c58c72d4921f1b2ff2e76aed994..d0aba8340c647888c09365bc8964b1e0a69225db 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 42c2de1cee354e304212ebf83842fdb6093239d0..bf15b01685ea18a906f6d407761c8fb961e08c84 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