User: Task: "Create Change Password Api for User"
    Description: "Generate a Node.js Change Password Api with given dependenceis"
    Requirements:
    - Database: mongoose
    - Authentication: None specified
    - Output needed: Return only the function code as specified in dependencies
    - Dependencies: Create a function for password change. Export the function: exports.changePassword = async () => {...}, 
Accept parameters: oldPassword, newPassword (in the request body)., 
Accept parameter: userId (from the authenticated user's token)., 
Validate required fields: Ensure both oldPassword and newPassword are provided., 
Use the User model to find the user by userId., 
Compare oldPassword with the stored hashed password using bcrypt., 
If oldPassword is incorrect, respond with an error message., 
Hash the newPassword and update it in the database., 
Respond with a success message indicating password change., 
Handle errors like incorrect oldPassword, weak newPassword, or database issues.
    - Previous Code 
const mongoose = require('mongoose');
// Assuming the User model is already defined and imported
const User = mongoose.model('User');

// Function to fetch user profile details
exports.getUserProfile = async (userId) => {
  try {
    // Find the user by userId in the database
    const user = await User.findById(userId).select('-password'); // Exclude password from the response

    // Check if user was found
    if (!user) {
      throw new Error('User not found');
    }

    // Return user details
    return {
      success: true,
      data: user,
    };
    
  } catch (error) {
    // Handle errors
    return {
      success: false,
      message: error.message || 'An error occurred while fetching the user profile',
    };
  }
};

// Assuming the User model is already defined and imported
const User = mongoose.model('User');

// Multer configuration for file upload
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/');
  },
  filename: function (req, file, cb) {
    cb(null, Date.now() + '-' + file.originalname);
  },
});

const upload = multer({ storage: storage });

exports.updateUserProfile = async (req, res) => {
  try {
    const { name, email, phone, profilePicture } = req.body;
    const userId = req.userId; // Assuming userId is extracted from the authenticated user's token

    // Ensure at least one field to update is provided
    if (!name && !email && !phone && !profilePicture) {
      return res.status(400).json({
        success: false,
        message: 'At least one field must be provided for update',
      });
    }

    // Find the user by userId in the database
    const user = await User.findById(userId);

    // Check if user was found
    if (!user) {
      return res.status(404).json({
        success: false,
        message: 'User not found',
      });
    }

    // Update fields
    if (name) user.name = name;
    if (phone) user.phone = phone;
    
    if (email) {
      // Check if the email is already used by another user
      const existingUser = await User.findOne({ email: email });
      if (existingUser && existingUser.id !== userId) {
        return res.status(400).json({
          success: false,
          message: 'Email is already in use by another user',
        });
      }
      user.email = email;
    }

    // Handle profilePicture upload
    if (req.file) {
      user.profilePicture = req.file.path;
    }

    // Save the updated user
    const updatedUser = await user.save();

    // Respond with updated user details (excluding sensitive data like password)
    res.json({
      success: true,
      data: {
        name: updatedUser.name,
        email: updatedUser.email,
        phone: updatedUser.phone,
        profilePicture: updatedUser.profilePicture,
      },
    });
  } catch (error) {
    // Handle errors
    res.status(500).json({
      success: false,
      message: error.message || 'An error occurred while updating the user profile',
    });
  }
};

// Usage of Multer in express routes would require this function to be called with `upload.single('profilePicture')`
// Example:
// app.put('/api/user/profile', upload.single('profilePicture'), updateUserProfile);

    - Supporting data 
    - Updating File undefined
    
    Please generate the code for this task, following the instructions and including comments for clarity.
    While creating router for specifict file your have to read supporing file data and create for that 

    **Output Formats**: 

Return dependencies like this `const bcrypt = require('bcrypt');`  in this formate
```dependencies
const bcrypt = require('bcrypt');
```

Ensure this format is consistently followed in responses.
    
User: 


    
Assistant: