<commit_before>const Game = require('../models').Game;

module.exports = {
  /**
   * Creates a new Game object on the server
   *
   * @route POST /games
   *
   * @param {*} req req.body.ATTRIBUTE
   * @param {*} res res.status
   */
  create(req, res) {
    return Game
      .create({
        rank: req.body.game.rank,
        outcome: req.body.game.outcome,
      })
      .then((game) => res.status(201).send({
        status: 201,
        message: 'Game created',
        game: game,
      }))
      .catch((error) => res.status(500).send({
        status: 500,
        message: 'Internal server error',
        errors: [error],
      }));
  },

  /**
   * Returns all entries from the server
   * Note: Should be changed to a findById in future multi-user versions
   *
   * @route GET /games
   *
   * @param {*} req
   * @param {*} res res.status
   */
  findAll(req, res) {
    return Game
      .findAll()
      .then(games => res.status(200).send({
        status: 200,
        message: 'Games found',
        games: games,
      }))
      .catch(error => res.status(500).send({
        status: 500,
        message: 'Internal server error',
        errors: [error],
      }));
  },

  /**
   * Returns one entry from the server
   *
   * @route GET /games/*
   *
   * @param {*} req
   * @param {*} res res.status
   */
  findOne(req, res) {
    return Game
      .findById(req.params.gameId)
      .then(games => res.status(200).send({
        status: 200,
        message: 'Games found',
        games: games,
      }))
      .catch(error => res.status(500).send({
        status: 500,
        message: 'Internal server error',
        errors: [error],
      }));
  },

  /**
   * Updates the database with new data from a put request by gameId
   *
   * @route PUT /games/:gameId
   *
   * @param {*} req req.params.gameId from the URL
   * @param {*} res
   */
  update(req, res) {
    return Game
      .findById(req.params.gameId)
      .then(game => {
        if (!game) {
          throw {
            status: 404,
            message: 'Game not found',
            errors: ['Game not found'],
          };
        }

        return game
          .update({
            rank: req.body.game.rank || game.rank,
            outcome: req.body.game.outcome || game.outcome,
          });
      })
      .then((game) => res.status(200).send({
        status: 200,
        message: 'Game updated',
        game: game,
      }))
      .catch((error) => {
        if (error.status) {
          res.status(error.status).send(error);
        }
        else {
          res.status(500).send({
            status: 500,
            message: 'Internal server error',
            errors: [error],
          });
        }
      });
  },
<commit_msg>add 404 error to findOne<commit_after>const Game = require('../models').Game;

module.exports = {
  /**
   * Creates a new Game object on the server
   *
   * @route POST /games
   *
   * @param {*} req req.body.ATTRIBUTE
   * @param {*} res res.status
   */
  create(req, res) {
    return Game
      .create({
        rank: req.body.game.rank,
        outcome: req.body.game.outcome,
      })
      .then((game) => res.status(201).send({
        status: 201,
        message: 'Game created',
        game: game,
      }))
      .catch((error) => res.status(500).send({
        status: 500,
        message: 'Internal server error',
        errors: [error],
      }));
  },

  /**
   * Returns all entries from the server
   * Note: Should be changed to a findById in future multi-user versions
   *
   * @route GET /games
   *
   * @param {*} req
   * @param {*} res res.status
   */
  findAll(req, res) {
    return Game
      .findAll()
      .then(games => res.status(200).send({
        status: 200,
        message: 'Games found',
        games: games,
      }))
      .catch(error => res.status(500).send({
        status: 500,
        message: 'Internal server error',
        errors: [error],
      }));
  },

  /**
   * Returns one entry from the server
   *
   * @route GET /games/:gameId
   *
   * @param {*} req
   * @param {*} res res.status
   */
  findOne(req, res) {
    return Game
      .findById(req.params.gameId)
      .then(games =>  {
        if (games){
          res.status(200).send({
            status: 200,
            message: 'Games found',
            games: games,
      })}else{
          throw {
            status: 404,
            message: 'Game not found',
            errors: ['Game not found'],
          };
      }})
      .catch((error) => {
        if (error.status) {
          res.status(error.status).send(error);
        }
        else {
          res.status(500).send({
            status: 500,
            message: 'Internal server error',
            errors: [error],
          });
        }
      });
  },

  /**
   * Updates the database with new data from a put request by gameId
   *
   * @route PUT /games/:gameId
   *
   * @param {*} req req.params.gameId from the URL
   * @param {*} res
   */
  update(req, res) {
    return Game
      .findById(req.params.gameId)
      .then(game => {
        if (!game) {
          throw {
            status: 404,
            message: 'Game not found',
            errors: ['Game not found'],
          };
        }
        return game
          .update({
            rank: req.body.game.rank || game.rank,
            outcome: req.body.game.outcome || game.outcome,
          });
      })
      .then((game) => res.status(200).send({
        status: 200,
        message: 'Game updated',
        game: game,
      }))
      .catch((error) => {
        if (error.status) {
          res.status(error.status).send(error);
        }
        else {
          res.status(500).send({
            status: 500,
            message: 'Internal server error',
            errors: [error],
          });
        }
      });
  },

{'fraction_non_alphanumeric': 0.15079229851763504, 'fraction_numerical': 0.018401772022491054, 'mean_word_length': 1.5499565595134666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '233829', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1805, 'n_words': 442}