{"size": 725, "ext": "js", "max_stars_repo_path": "packages/cvtls2/server/routes/players.js", "max_stars_repo_name": "projectsf/perfect-league", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/cvtls2/server/routes/players.js", "max_issues_repo_name": "projectsf/perfect-league", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/cvtls2/server/routes/players.js", "max_forks_repo_name": "projectsf/perfect-league", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.8846153846, "max_line_length": 71, "alphanum_fraction": 0.6510344828}
'use strict';

var players = require('../controllers/players');

// Player authorization helpers
var hasAuthorization = function(req, res, next) {
    if (req.player.user.id !== req.user.id) {
        return res.send(401, 'User is not authorized');
    }
    next();
};

module.exports = function(Players, app, auth) {
    
    app.route('/players')
        .get(players.all)
        .post(auth.requiresLogin, players.create);
    app.route('/players/:playerId')
        .get(players.show)
        .put(auth.requiresLogin, hasAuthorization, players.update)
        .delete(auth.requiresLogin, hasAuthorization, players.destroy);

    // Finish with setting up the playerId param
    app.param('playerId', players.player);
};
