From 7af8572672bd5258283cf205e3f015826a8692da Mon Sep 17 00:00:00 2001 From: patrickjieraldjuan Date: Sun, 28 Jan 2024 11:47:18 +0800 Subject: [PATCH] Added controller and route for user update profile --- controllers/userControllers.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/controllers/userControllers.js b/controllers/userControllers.js index 9216cb4..0c48437 100644 --- a/controllers/userControllers.js +++ b/controllers/userControllers.js @@ -160,4 +160,23 @@ module.exports.resetPassword = async (req, res) => { console.error(error); res.status(500).json(false); } +}; + +// update profile controller +module.exports.updateProfile = async (req, res) => { + try { + // Get user ID from the JWT token passed in the authorization headers + const userId = req.user.id; + + // Get updated profile information from the request body + const { firstName, lastName, mobileNo } = req.body; + + // Update the user's profile in the database + await User.findByIdAndUpdate(userId, { firstName, lastName, mobileNo }); + + res.status(200).json({ message: 'Profile updated successfully.' }); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal Server Error' }); + } }; \ No newline at end of file