Skip to content

Instantly share code, notes, and snippets.

@debbysa
Created May 10, 2020 11:51
Show Gist options
  • Save debbysa/75fb7537392f9f788fd49f8f8ab44c69 to your computer and use it in GitHub Desktop.
Save debbysa/75fb7537392f9f788fd49f8f8ab44c69 to your computer and use it in GitHub Desktop.
// controllers/movieController.js
const Movie = require("../models/Movie")
module.exports = {
index: function(req, res) {
Movie.findAll().then(function(rows) {
res.render("movie/index", { data: rows })
})
},
store: function(req, res) {
Movie.create(req.body).then(function (rows) {
res.json(rows)
})
},
update: function(req, res) {
Movie.findByPrimary(req.params.id).then(function(row) {
row.update(req.body)
res.redirect("/movie")
})
},
destroy: function(req, res) {
Movie.findByPrimary(req.params.id).then(function(row) {
row.destroy()
res.redirect("/movie")
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment