{"size": 686, "ext": "js", "max_stars_repo_path": "Exercises/W05D02_Exercise_04_REST_API_Lab/controllers/performers.js", "max_stars_repo_name": "Roger-Takeshita/Software_Engineer", "max_stars_repo_stars_event_min_datetime": "2019-12-27T06:15:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-21T17:37:12.000Z", "max_issues_repo_path": "Exercises/W05D02_Exercise_04_REST_API_Lab/controllers/performers.js", "max_issues_repo_name": "Roger-Takeshita/Bootcamp-Software-Engineer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exercises/W05D02_Exercise_04_REST_API_Lab/controllers/performers.js", "max_forks_repo_name": "Roger-Takeshita/Bootcamp-Software-Engineer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.7878787879, "max_line_length": 55, "alphanum_fraction": 0.6370262391}
var Performer = require('../models/performer');
var Movie = require('../models/movie');

module.exports = {
  new: newPerformer,
  create,
  addToCast
};

function addToCast(req, res) {
  Movie.findById(req.params.id, function(err, movie) {
    movie.cast.push(req.body.performerId);
    movie.save(function(err) {
      res.redirect(`/movies/${movie._id}`);
    });
  });
}

function create(req, res) {
  Performer.create(req.body, function(err, performer) {
    res.redirect('/performers/new');
  });
}

function newPerformer(req, res) {
  Performer.find({}, function(err, performers) {
    res.render('performers/new', {
      title: 'Add Performer',
      performers
    });
  })
}
