Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ const signInUser = async (req, res) => {
//update user profile

const updateUserProfile = async (req, res) => {

//recieve user object from the request body

const user = await User.findById(req.user._id);

const user = await User.findById(req.body.userId);
if (user) {

//updating user data if it's in the request body, otherwise, keep the old data

user.username = req.body.username || user.username;
user.email = req.body.email || user.email;
user.role = req.body.role || user.role;
Expand All @@ -104,13 +102,13 @@ const signInUser = async (req, res) => {
if (req.body.password) {
user.password = req.body.password;
}

//saving updated user data into the database

const updatedUser = await user.save();

//sending new user data back to the client

res
.json({
_id: updatedUser._id,
Expand All @@ -120,7 +118,6 @@ const signInUser = async (req, res) => {
fullName: updatedUser.fullName,
phone: updatedUser.phone,
address: updatedUser.address,
token: generateToken(updatedUser._id),
})
.status(200);
} else {
Expand Down