mirror of
https://gitlab.com/little-lines/backend.git
synced 2025-07-07 13:31:05 +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};
|
Loading…
Add table
Add a link
Reference in a new issue