{"size": 570, "ext": "js", "max_stars_repo_path": "src/handlers/user/changeCape.js", "max_stars_repo_name": "superhooman/simurgh", "max_stars_repo_stars_event_min_datetime": "2021-01-10T19:50:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T12:53:03.000Z", "max_issues_repo_path": "src/handlers/user/changeCape.js", "max_issues_repo_name": "uenify/simurgh", "max_issues_repo_issues_event_min_datetime": "2021-05-11T07:25:28.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T07:25:28.000Z", "max_forks_repo_path": "src/handlers/user/changeCape.js", "max_forks_repo_name": "superhooman/simurgh", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 18.3870967742, "max_line_length": 52, "alphanum_fraction": 0.5438596491}
const User = require("../../models/user");

module.exports = async (req, res) => {
  if (!req.body.texture) {
    return res.json({
      success: false,
      message: "No file"
    });
  }
  if (req.body.texture.type !== "cape") {
    return res.json({
      success: false,
      message: "Wrong file"
    });
  }
  const user = await User.findByIdAndUpdate(
    // eslint-disable-next-line no-underscore-dangle
    req.user._id,
    {
      cape: req.body.texture.file
    },
    {
      new: true
    }
  );
  return res.json({
    success: true,
    user
  });
};
