From ed717b22dbf7de87b58fa3dae36b57a100d162fd Mon Sep 17 00:00:00 2001 From: Noor Salim <24814579+mrlazyg@users.noreply.github.com> Date: Thu, 7 Mar 2024 18:46:18 +0530 Subject: [PATCH] user route --- controllers/UserController.js | 9 +++++++++ routes/UserRoutes.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/controllers/UserController.js b/controllers/UserController.js index 7e0c6f0..a067a51 100644 --- a/controllers/UserController.js +++ b/controllers/UserController.js @@ -9,8 +9,17 @@ const getAllUsers = (req, res) => { }; const getUser = (req, res) => { + const { userId } = req.params; + const user = users.find((id) => userId === id.email || userId === id._id); + if (!user) { + return res.status(404).send({ + status: 'error', + message: 'user not found', + }); + } res.send({ status: 'success', + user: user || 'User not found', }); }; diff --git a/routes/UserRoutes.js b/routes/UserRoutes.js index 6a08585..2ee8cac 100644 --- a/routes/UserRoutes.js +++ b/routes/UserRoutes.js @@ -8,7 +8,7 @@ router .get(UserController.getAllUsers) .post(UserController.createUser); router - .route('/:id') + .route('/:userId') .get(UserController.getUser) .patch(UserController.updateUser) .delete(UserController.deleteUser);