Permalink
Browse files

Fix day off by one issue

  • Loading branch information...
jim-clark
jim-clark committed Feb 15, 2019
1 parent 4aeb0f4 commit 290135112e68239b582939efe9a26a7c8d4be0ee
Showing with 15 additions and 7 deletions.
  1. +6 −3 README.md
  2. +9 −4 final-code/mongoose-movies/controllers/performers.js
@@ -423,7 +423,6 @@
---
#### Creating _Performers_
<br>
- In **controllers/performers.js**:
@@ -432,8 +431,12 @@
new: newPerformer,
create
};
function create(req, res) {
// need to "fix" date formatting to prevent day off by 1
var s = req.body.born;
req.body.born =
`${s.substr(5,2)}-${s.substr(8,2)}-${s.substr(0,4)}`;
Performer.create(req.body, function(err, performer) {
res.redirect('/performers/new');
});
@@ -537,7 +540,7 @@
The log will show we are retrieving the _performers_ - a good sign at this point.
---
#### Refactor _show.ejs>
#### Refactor _show.ejs_
<br>
- The next slide has some refactored markup in **movies/show.ejs**.
@@ -8,22 +8,27 @@ module.exports = {
};

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

function create(req, res) {
Performer.create(req.body, function(err, performer) {
// Need to "fix" date formatting to prevent day off by 1
// This is due to the <input type="date"> returning the date
// string in this format: "YYYY-MM-DD"
var s = req.body.born;
req.body.born = `${s.substr(5, 2)}-${s.substr(8, 2)}-${s.substr(0, 4)}`;
Performer.create(req.body, function (err, performer) {
res.redirect('/performers/new');
});
}

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

0 comments on commit 2901351

Please sign in to comment.