var inspect  = require('eyes').inspector({ stream: null });

module.exports = {

  index: function(req, res, next){
    var project_id = req.query.project_id;

    process.database.games.find({project_id: project_id}, function(error, games){
      if(error){res.send(error); return false;}

      games.toArray(function(err, results){
        if(err){res.send(err); return false;}

        res.send(results);
      });

    });

  },

  create: function(game){
    process.database.games.save(game, function(error, savedGame){
      if(error){
        process.io.sockets.emit('error', error);
        return false;
      }

      process.io.sockets.emit('populate game', null, game);
    });
  },

  update: function(game){
    process.database.games.update({_id: game._id},{ $set: {name: game.name} },  function(error, savedGame){
      if(error){
        process.io.sockets.emit('error', error);
        return false;
      }

      process.io.sockets.emit('updated game', null, game);
    });
  },

  remove: function(req, res, next){
    var _id = req.body._id;

    process.database.games.remove({_id: _id},  function(error, deletedGame){
      if(error){res.send(error); return false;}
      res.send({sucess: true});
    });

  }

};

@@ -997,21 +997,21 @@
   %7D,%0A%0A  
-remov
+delet
 e: funct
@@ -1018,53 +1018,13 @@
 ion(
-req, res, next)%7B%0A    var _id = req.body._id;%0A
+_id)%7B
 %0A   
@@ -1117,69 +1117,147 @@
 or)%7B
-res.send(error); return false;%7D%0A      res.send(%7Bsucess: true%7D
+%0A        process.io.sockets.emit('error', error);%0A        return false;%0A      %7D%0A%0A      process.io.sockets.emit('unpopulate game', null, _id
 );%0A 
@@ -1263,17 +1263,16 @@
     %7D);%0A
-%0A
   %7D%0A%0A%7D;%0A

migrate delete game to use sockets