const Hapi = require('hapi');
const server = new Hapi.Server();

require('./setup_mongoose');

// const bodyParser = require('body-parser').json();
const Player = require('./models/player');


server.connection({
    host: 'localhost',
    port: 3000
});

server.start((err) => {

    if (err) {
        throw err;
    }
    console.log('Server listening at:', server.info.uri);
});

server.route({
    method: 'GET',
    path:'/api/players',
    handler: function (request, reply) {
        Player.find()
            .select('playerName position')
            .lean()
            .then(players => reply(players))
            .catch();
    }
});

server.route({
    method: 'GET',
    path:'/api/players/{id}',
    handler: function (request, reply) {
        Player.findById(request.params.id)
            .then(player => reply(player))
            .catch();
    }
});

server.route({
    method: 'DELETE',
    path:'/api/players/{id}',
    handler: function (request, reply) {
        Player.findByIdAndRemove(request.params.id)
            .then(removed => reply(removed))
            .catch();
    }
});

server.route({
    method: 'POST',
    path:'/api/players',
    handler: function (request, reply) {
        new Player(request.payload).save()
            .then(saved => reply(saved))
            .catch();
    }
});

server.route({
    method: 'PUT',
    path:'/api/players/{id}',
    handler: function (request, reply) {
        Player.findByIdAndUpdate(request.params.id, request.payload, {new: true})
        .then(updated => reply(updated))
        .catch();
    }
});

module.exports = server;

@@ -92,61 +92,8 @@
 );%0A%0A
-// const bodyParser = require('body-parser').json();%0A
 cons
@@ -132,17 +132,16 @@
 yer');%0A%0A
-%0A
 server.c

clean up