{"size": 703, "ext": "js", "max_stars_repo_path": "db/dataHelpers/comments/update.js", "max_stars_repo_name": "classroom-angel/labs11_prop_mngmt-BE", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "db/dataHelpers/comments/update.js", "max_issues_repo_name": "classroom-angel/labs11_prop_mngmt-BE", "max_issues_repo_issues_event_min_datetime": "2019-03-20T18:27:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-08T09:49:19.000Z", "max_forks_repo_path": "db/dataHelpers/comments/update.js", "max_forks_repo_name": "classroom-angel/labs11_prop_mngmt-BE", "max_forks_repo_forks_event_min_datetime": "2019-04-19T19:16:37.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-19T19:16:37.000Z"}
{"max_stars_count": null, "max_issues_count": 51, "max_forks_count": 1, "avg_line_length": 21.96875, "max_line_length": 70, "alphanum_fraction": 0.5320056899}
const db = require('../../dbConfig');
const { keysToCamelCase } = require('../');

const update = async (req, res) => {
  try {
    const { content, userId, issueId } = req.body;
    const { id } = req.params;

    let [comment] = await db('comments')
      .where({ id })
      .update({
        content,
        user_id: userId,
        issue_id: issueId
      })
      .returning('*');

    if (comment) {
      comment = keysToCamelCase(comment);
      res.status(200).json({ comment });
    } else {
      res
        .status(400)
        .json({ error: 'Could not update the comment in database.' });
    }
  } catch (error) {
    res.status(500).json({ error });
  }
};

module.exports = update;
