From ac52a3ae70a52d467475ff1c7c68f682ae1ac18d Mon Sep 17 00:00:00 2001 From: Olivier BYIRINGIRO Date: Sun, 17 Mar 2024 07:26:33 +0200 Subject: [PATCH] Returned all the users after updating a user --- src/controllers/authController.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/authController.ts b/src/controllers/authController.ts index 280a51a..fa81899 100644 --- a/src/controllers/authController.ts +++ b/src/controllers/authController.ts @@ -114,8 +114,9 @@ module.exports.updateUserRole = async(req: Request, res: Response) => { const userNewRole = (user.role === 'admin') ? 'user' : 'admin'; await User.findByIdAndUpdate(userId, { role: userNewRole }); + const users = await User.find({}, '-password'); - res.status(200).json({ message: "User role updated successfully" }); + res.status(200).json({ message: "User role updated successfully", users }); } catch (error) { console.error("Error updating user role:", error); res.status(500).json({ message: "Internal server error" });