Skip to content

Commit

Permalink
clase 35 final
Browse files Browse the repository at this point in the history
  • Loading branch information
andreybejarano committed Sep 14, 2022
1 parent f32b390 commit 08f5477
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions clase35/src/controllers/api/moviesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,41 @@ const db = require('../../database/models');
const Movies = db.Movie;

const moviesController = {
create: function (req,res) {
create: function (req, res) {
Movies
.create(
{
title: req.body.title,
rating: req.body.rating,
awards: req.body.awards,
release_date: req.body.release_date,
length: req.body.length,
genre_id: req.body.genre_id
}
)
.then((movieCreated)=> {
return res.json(movieCreated);
})
.catch(error => res.send(error))
.create(
{
title: req.body.title,
rating: req.body.rating,
awards: req.body.awards,
release_date: req.body.release_date,
length: req.body.length,
genre_id: req.body.genre_id
}
)
.then((movieCreated) => {
return res.json(movieCreated);
})
.catch(error => res.send(error))
},
destroy: function (req,res) {
destroy: async function (req, res) {
let movieId = req.params.id;
Movies
.destroy({where: {id: movieId}, force: true}) // force: true es para asegurar que se ejecute la acción
.then(()=>{
// Remplazar
return res.redirect('/movies');
})
.catch(error => res.send(error))
try {
const movie = await Movies.findByPk(movieId);
await Movies.destroy({ where: { id: movieId }, force: true });
return res.json(movie);
} catch (error) {
return res.send(error);
}
// Movies.findByPk(movieId)
// .then(movie => {
// Movies.destroy({ where: { id: movieId }, force: true }) // force: true es para asegurar que se ejecute la acción
// .then(() => {
// return res.json(movie);
// })
// .catch(error => res.send(error));
// })
// .catch(error => res.send(error))
}
}

Expand Down

0 comments on commit 08f5477

Please sign in to comment.