make it bett
This commit is contained in:
parent
463dce8695
commit
081769c0e2
@ -171,7 +171,22 @@ export const getUserDetails = catchAsyncErrors(async (req, res, next) => {
|
||||
});
|
||||
});
|
||||
|
||||
// 7.update User password
|
||||
// 7.Get single user (admin)
|
||||
exports.getSingleUser = catchAsyncErrors(async (req, res, next) => {
|
||||
const user = await User.findById(req.params.id);
|
||||
|
||||
if (!user) {
|
||||
return next(
|
||||
new ErrorHander(`User does not exist with Id: ${req.params.id}`)
|
||||
);
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
user,
|
||||
});
|
||||
});
|
||||
// 8.update User password
|
||||
export const updatePassword = catchAsyncErrors(async (req, res, next) => {
|
||||
const user = await User.findById(req.user.id).select("+password");
|
||||
|
||||
@ -192,7 +207,7 @@ export const updatePassword = catchAsyncErrors(async (req, res, next) => {
|
||||
sendToken(user, 200, res);
|
||||
});
|
||||
|
||||
// 8.update User Profile
|
||||
// 9.update User Profile
|
||||
export const updateProfile = catchAsyncErrors(async (req, res, next) => {
|
||||
const newUserData = {
|
||||
name: req.body.name,
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
getUserDetails,
|
||||
updatePassword,
|
||||
updateProfile,
|
||||
getSingleUser
|
||||
} from "../controllers/userController.js"
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../middlewares/auth.js"
|
||||
|
||||
@ -24,6 +25,11 @@ router.route("/user/password/reset/:token").put(resetPassword);
|
||||
router.route("/user/logout").get(logout);
|
||||
|
||||
router.route("/user/details").get(isAuthenticatedUser, getUserDetails);
|
||||
router
|
||||
.route("/admin/user/:id")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getSingleUser)
|
||||
|
||||
|
||||
|
||||
router.route("/user/password/update").put(isAuthenticatedUser, updatePassword);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user