{"size": 1062, "ext": "js", "max_stars_repo_path": "src/Controller.js", "max_stars_repo_name": "isaacbatst/fastexpress", "max_stars_repo_stars_event_min_datetime": "2018-10-25T11:16:57.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-22T03:25:45.000Z", "max_issues_repo_path": "src/Controller.js", "max_issues_repo_name": "isaacbatst/fastexpress", "max_issues_repo_issues_event_min_datetime": "2018-10-25T12:13:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-20T15:36:45.000Z", "max_forks_repo_path": "src/Controller.js", "max_forks_repo_name": "isaacbatst/fastexpress", "max_forks_repo_forks_event_min_datetime": "2018-10-29T20:17:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-30T13:27:00.000Z"}
{"max_stars_count": 17, "max_issues_count": 82, "max_forks_count": 5, "avg_line_length": 16.8571428571, "max_line_length": 56, "alphanum_fraction": 0.5790960452}
const { EXCEPTION_NOT_FOUND } = require('./lib/errors');

/**
 *
 * @param {object} req
 * @param {object} res
 * @param {function} service
 */
const defaultResponse = async (req, res, service) => {
  try {
    res.json(await service(req));
  } catch (e) {
    res.status(500).json({
      error: e.message,
    });
  }
};

const list = defaultResponse;
const create = defaultResponse;
const update = defaultResponse;

/**
 *
 * @param {object} req
 * @param {object} res
 * @param {function} service
 */
const get = async (req, res, service) => {
  try {
    res.json(await service(req));
  } catch (e) {
    if (e.message === EXCEPTION_NOT_FOUND) {
      res.status(404).send(e.message);
    } else {
      res.status(500).send(e);
    }
  }
};

/**
 *
 * @param {object} req
 * @param {object} res
 * @param {function} service
 */
const destroy = async (req, res, service) => {
  try {
    await service(req);
    res.status(204).send();
  } catch (e) {
    res.status(500).send(e);
  }
};

module.exports = {
  list,
  create,
  get,
  update,
  destroy,
};
