mirror of
https://gitlab.com/little-lines/backend.git
synced 2024-11-23 13:36:50 +00:00
getUserById
This commit is contained in:
parent
3ff828d9c9
commit
f413d01bd9
2 changed files with 22 additions and 1 deletions
|
@ -13,6 +13,25 @@ const getAllUser = asyncHandler(async (req, res) => {
|
|||
res.status(200).json(users);
|
||||
});
|
||||
|
||||
//Get single users => api/user/:id
|
||||
const getUserById = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
const foundUser = await user.findById(id);
|
||||
|
||||
if (!foundUser) {
|
||||
return res.status(404).json({ message: 'User not found' });
|
||||
}
|
||||
|
||||
res.status(200).json(foundUser);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Server Error' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Create new user => POST api/users/create
|
||||
const createUser = asyncHandler(async (req, res) => {
|
||||
try {
|
||||
|
@ -166,4 +185,4 @@ const googleAuth = asyncHandler(async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
module.exports = { getAllUser, createUser, deleteUser, updateUser, loginUser, logoutUser , googleAuth};
|
||||
module.exports = { getAllUser, getUserById, createUser, deleteUser, updateUser, loginUser, logoutUser , googleAuth};
|
|
@ -1,6 +1,7 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { getAllUser,
|
||||
getUserById,
|
||||
createUser,
|
||||
deleteUser,
|
||||
updateUser,
|
||||
|
@ -9,6 +10,7 @@ const { getAllUser,
|
|||
googleAuth} = require('../controllers/userController');
|
||||
|
||||
router.route('/').get(getAllUser);
|
||||
router.route('/:id').get(getUserById);
|
||||
router.route('/create').post(createUser);
|
||||
router.route('/delete/:id').delete(deleteUser);
|
||||
router.route('/update/:id').put(updateUser);
|
||||
|
|
Loading…
Reference in a new issue