git stash push -m "work in progress"
This commit is contained in:
1 parent
c30d6019df
commit
468a67f937
9 files changed
+230
-7
No files matched your search
@@ -456,6 +456,29 @@ class AuthController extends BaseController {
|
||||
SERVICE_NAME,
|
||||
"editUserById"
|
||||
);
|
||||
editUserPasswordById = this.asyncHandler(
|
||||
async (req, res) => {
|
||||
console.log("editUserPasswordById called");
|
||||
const roles = req?.user?.role;
|
||||
if (!roles.includes("superadmin")) {
|
||||
console.log("entro a error editUserPasswordById");
|
||||
throw createError("Unauthorized", 403);
|
||||
}
|
||||
|
||||
const userId = req.params.userId;
|
||||
console.log("userId param:", userId);
|
||||
const updates = { ...req.body };
|
||||
console.log("newPassword body:", req.body);
|
||||
await editUserByIdParamValidation.validateAsync(req.params);
|
||||
console.log("params validated");
|
||||
//await editUserPasswordByIdBodyValidation.validateAsync(req.body);
|
||||
console.log("body validated");
|
||||
await this.userService.setPasswordByUserId( userId, updates );
|
||||
return res.success({ msg: "Password reset successfully" });
|
||||
},
|
||||
SERVICE_NAME, "editUserPasswordById"
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
export default AuthController;
|
||||
@@ -25,6 +25,7 @@ class AuthRoutes {
|
||||
this.router.get("/users", verifyJWT, isAllowed(["admin", "superadmin"]), this.authController.getAllUsers);
|
||||
this.router.get("/users/:userId", verifyJWT, isAllowed(["superadmin"]), this.authController.getUserById);
|
||||
this.router.put("/users/:userId", verifyJWT, isAllowed(["superadmin"]), this.authController.editUserById);
|
||||
this.router.put("/users/:userId/password", verifyJWT, isAllowed(["superadmin"]), this.authController.editUserPasswordById);
|
||||
|
||||
this.router.put("/user", verifyJWT, upload.single("profileImage"), this.authController.editUser);
|
||||
this.router.delete("/user", verifyJWT, this.authController.deleteUser);
|
||||
|
||||
@@ -211,5 +211,10 @@ class UserService {
|
||||
editUserById = async (userId, user) => {
|
||||
await this.db.userModule.editUserById(userId, user);
|
||||
};
|
||||
setPasswordByUserId = async (userId, updates) => {
|
||||
const updatedUser = await this.db.userModule.updateUser({ userId: userId, user: updates, file: null });
|
||||
return updatedUser;
|
||||
}
|
||||
|
||||
}
|
||||
export default UserService;
|
||||
@@ -670,6 +670,10 @@ const editSuperadminUserByIdBodyValidation = joi.object({
|
||||
.required(),
|
||||
});
|
||||
|
||||
const editUserPasswordByIdBodyValidation = joi.object({
|
||||
newPassword: joi.string().min(8).required().pattern(passwordPattern),
|
||||
});
|
||||
|
||||
export {
|
||||
roleValidatior,
|
||||
loginValidation,
|
||||
@@ -739,4 +743,5 @@ export {
|
||||
editUserByIdParamValidation,
|
||||
editUserByIdBodyValidation,
|
||||
editSuperadminUserByIdBodyValidation,
|
||||
editUserPasswordByIdBodyValidation,
|
||||
};
|
||||
Reference in new issue
Block a user