User: Task: "Create view Profile Api for User"
    Description: "Generate a Node.js View User Profile 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 to fetch user profile details. Export the function: exports.getUserProfile = async () => {...}, 
Accept parameter: userId (from the authenticated user's token)., 
Use the User model to find the user by userId., 
Respond with user details (excluding sensitive information like password)., 
Handle errors like user not found or database errors.
    - 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);

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

exports.changePassword = async (req, res) => {
  try {
    const { oldPassword, newPassword } = req.body;
    const userId = req.userId; // Assuming userId is extracted from the authenticated user's token

    // Validate required fields
    if (!oldPassword || !newPassword) {
      return res.status(400).json({
        success: false,
        message: 'Both old and new passwords are required',
      });
    }

    // 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',
      });
    }

    // Compare oldPassword with the stored hashed password
    const isMatch = await bcrypt.compare(oldPassword, user.password);
    if (!isMatch) {
      return res.status(400).json({
        success: false,
        message: 'Incorrect old password',
      });
    }

    // Hash the newPassword
    const hashedPassword = await bcrypt.hash(newPassword, 10);

    // Update the user's password in the database
    user.password = hashedPassword;
    await user.save();

    // Respond with a success message indicating password change
    res.json({
      success: true,
      message: 'Password changed successfully',
    });
  } catch (error) {
    // Handle errors like weak newPassword or database issues
    res.status(500).json({
      success: false,
      message: error.message || 'An error occurred while changing the password',
    });
  }
};

    - 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 

   
    
User:  **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.
    
Assistant: