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

exports.create = function(req, res) {
  var game = new Game({
    challenger: req.user._id,
    size: req.body.size,
    color: req.body.color,
    komi: req.body.komi,
    name: req.body.name,
    private: !!req.body.private
  });

  game.save(function(err, game) {
    if (err) {
      return res.send(500, err);
    }
    res.send(game);
    req.io.sockets.emit('list');
  });
};

exports.list = function(req, res) {
  // TODO: No private, unless its the game of the user
  //.where('private').eq(false)
  Game
    .find()
    .where('state').ne('over')
    .populate('challenger')
    .populate('challengee')
    .exec(function(err, games) {
      if (err || !games) {
        return res.send(404, err);
      }
      res.send(games);
    });
};

exports.get = function(req, res) {
  Game.
    findOne({_id: req.params.id}).
    populate('challenger').
    populate('challengee').
    exec(function(err, game) {
      if (err || !game) {
        res.send(404, err);
      }<commit_msg>Updated GET /games to incorporate only own filter<commit_after>var Game = require('../models/game');

exports.create = function(req, res) {
  var game = new Game({
    challenger: req.user._id,
    size: req.body.size,
    color: req.body.color,
    komi: req.body.komi,
    name: req.body.name,
    private: !!req.body.private
  });

  game.save(function(err, game) {
    if (err) {
      return res.send(500, err);
    }
    res.send(game);
    req.io.sockets.emit('list');
  });
};

exports.list = function(req, res) {
  var query = Game.find().populate('challenger').populate('challengee');

  if (req.query.own !== undefined) {
    query.or([{challenger: req.user._id}, {challengee: req.user._id}]);
  } else {
    // TODO: No private, unless its the game of the user
    //.where('private').eq(false)
    query.where('state').ne('over');
  }

  query.exec(function(err, games) {
    if (err || !games) {
      return res.send(404, err);
    }
    res.send(games);
  });
};

exports.get = function(req, res) {
  Game.
    findOne({_id: req.params.id}).
    populate('challenger').
    populate('challengee').
    exec(function(err, game) {
      if (err || !game) {
        res.send(404, err);
      }
{'fraction_non_alphanumeric': 0.18674966651845265, 'fraction_numerical': 0.008003557136505114, 'mean_word_length': 2.6704730831973897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1636309', 'n_tokens_mistral': 834, 'n_tokens_neox': 803, 'n_words': 162}