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