var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {

  var leaderboard = [];
  var CombatGame = require('../models/combatGame.js');

  // CombatGame.find({}, function(err, docs) {
  CombatGame.find({over:true}, null, {sort: {creationDate: -1}}, function(err, docs) {
    if (err) {
      console.log(err);
    }
    else {
      leaderboard = docs;
      res.render('combat', {
        documentTitle: 'Combat',
        h1: 'Combat',
        leaderboard: leaderboard
      });
    }
  });

});

module.exports = router;
