Added getUserName route and controller

master
parent 418c1da9ac
commit a3f1a510b6

@ -182,3 +182,24 @@ module.exports.updateProfile = async (req, res) => {
res.status(500).json({ error: 'Internal Server Error' }); res.status(500).json({ error: 'Internal Server Error' });
} }
}; };
// getting user name by id
exports.getUserName = async (req, res) => {
try {
const { userId } = req.body;
// Find the product by userId
const user = await User.findOne({ _id: userId });
if (!user) {
return res.status(404).json({ error: 'User not found' });
}
// Send the user name in the response
res.json(user);
} catch (error) {
console.error('Error getting user name:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
};

@ -34,4 +34,7 @@ router.post(`/reset-password`, verify, userControllers.resetPassword);
// Route for updating profile // Route for updating profile
router.put('/update-profile', verify, userControllers.updateProfile); router.put('/update-profile', verify, userControllers.updateProfile);
// Route for getting user name by id
router.post('/getUserName', userControllers.getUserName);
module.exports = router; module.exports = router;
Loading…
Cancel
Save