text: import default from '../repository';
  const { updateUserInfo } = default;
  import { UPDATE_INFO_SUCCESS_MESSAGE, UPDATE_INFO_ERROR_MESSAGE } from '../constants';
  
  async function updateUser(req, res) {
    let user = {};
    const {
      user: { id },
    } = req;
    const profileSuccessMessage = UPDATE_INFO_SUCCESS_MESSAGE;
    try {
      user = await updateUserInfo({ ...req.body, id });
    } catch (error) {
      user = error;
    }
  
    if (user.email) {
      req.session.messages = { success: profileSuccessMessage };
      req.session.userInfo = { ...user };
      res.redirect('/profile');
    }
  
    const databaseError = UPDATE_INFO_ERROR_MESSAGE;
    req.session.messages = { errors: { databaseError } };
    res.redirect('/profile');
  }
  
  export default updateUser;
  