Added image bytes to update user profile
This commit is contained in:
1 parent
9532fa6fb5
commit
da1e8ee5d9
3 files changed
+15
-3
No files matched your search
@@ -88,9 +88,16 @@ const getUserByEmail = async (req, res) => {
|
|||||||
|
|
||||||
const updateUser = async (req, res) => {
|
const updateUser = async (req, res) => {
|
||||||
const candidateUserId = req.params.userId;
|
const candidateUserId = req.params.userId;
|
||||||
const candidateUser = req.body;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const candidateUser = { ...req.body };
|
||||||
|
if (req.file) {
|
||||||
|
candidateUser.profileImage = {
|
||||||
|
data: req.file.buffer,
|
||||||
|
contentType: req.file.mimetype,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const updatedUser = await UserModel.findByIdAndUpdate(
|
const updatedUser = await UserModel.findByIdAndUpdate(
|
||||||
candidateUserId,
|
candidateUserId,
|
||||||
candidateUser,
|
candidateUser,
|
||||||
|
|||||||
@@ -16,7 +16,12 @@ const {
|
|||||||
//Auth routes
|
//Auth routes
|
||||||
router.post("/register", upload.single("profileImage"), registerController);
|
router.post("/register", upload.single("profileImage"), registerController);
|
||||||
router.post("/login", loginController);
|
router.post("/login", loginController);
|
||||||
router.post("/user/:userId", verifyJWT, userEditController);
|
router.post(
|
||||||
|
"/user/:userId",
|
||||||
|
upload.single("profileImage"),
|
||||||
|
verifyJWT,
|
||||||
|
userEditController
|
||||||
|
);
|
||||||
router.get("/users/admin", checkAdminController);
|
router.get("/users/admin", checkAdminController);
|
||||||
|
|
||||||
//Recovery routes
|
//Recovery routes
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const editUserParamValidation = joi.object({
|
|||||||
const editUserBodyValidation = joi.object({
|
const editUserBodyValidation = joi.object({
|
||||||
firstname: joi.string(),
|
firstname: joi.string(),
|
||||||
lastname: joi.string(),
|
lastname: joi.string(),
|
||||||
profilePicUrl: joi.string(),
|
profileImage: joi.any(),
|
||||||
role: joi.string(),
|
role: joi.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user