From 33fbb46c04cf10a43620b5de00247e09ebd32faf Mon Sep 17 00:00:00 2001 From: haripermadi Date: Thu, 1 Mar 2018 09:32:02 +0700 Subject: [PATCH 1/7] seeding --- .gitignore | 2 + config/config.json | 23 ++++++++ .../20180301021312-create-restaurant.js | 30 +++++++++++ migrations/20180301021506-create-menu.js | 36 +++++++++++++ migrations/20180301021718-add_restaurantId.js | 26 ++++++++++ models/index.js | 36 +++++++++++++ models/menu.js | 15 ++++++ models/restaurant.js | 13 +++++ seeders/20180301022328-restaurant.js | 43 +++++++++++++++ seeders/20180301022705-menu.js | 52 +++++++++++++++++++ 10 files changed, 276 insertions(+) create mode 100644 .gitignore create mode 100644 config/config.json create mode 100644 migrations/20180301021312-create-restaurant.js create mode 100644 migrations/20180301021506-create-menu.js create mode 100644 migrations/20180301021718-add_restaurantId.js create mode 100644 models/index.js create mode 100644 models/menu.js create mode 100644 models/restaurant.js create mode 100644 seeders/20180301022328-restaurant.js create mode 100644 seeders/20180301022705-menu.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91dfed8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +node_modules \ No newline at end of file diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000..9c61b45 --- /dev/null +++ b/config/config.json @@ -0,0 +1,23 @@ +{ + "development": { + "username": "postgres", + "password": "hari2018", + "database": "platinum_livecode4", + "host": "127.0.0.1", + "dialect": "postgres" + }, + "test": { + "username": "root", + "password": null, + "database": "database_test", + "host": "127.0.0.1", + "dialect": "mysql" + }, + "production": { + "username": "root", + "password": null, + "database": "database_production", + "host": "127.0.0.1", + "dialect": "mysql" + } +} diff --git a/migrations/20180301021312-create-restaurant.js b/migrations/20180301021312-create-restaurant.js new file mode 100644 index 0000000..b83df0f --- /dev/null +++ b/migrations/20180301021312-create-restaurant.js @@ -0,0 +1,30 @@ +'use strict'; +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.createTable('Restaurants', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + name: { + type: Sequelize.STRING + }, + address: { + type: Sequelize.STRING + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.dropTable('Restaurants'); + } +}; \ No newline at end of file diff --git a/migrations/20180301021506-create-menu.js b/migrations/20180301021506-create-menu.js new file mode 100644 index 0000000..11fb538 --- /dev/null +++ b/migrations/20180301021506-create-menu.js @@ -0,0 +1,36 @@ +'use strict'; +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.createTable('Menus', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + name: { + type: Sequelize.STRING + }, + menu_type: { + type: Sequelize.STRING + }, + rating: { + type: Sequelize.INTEGER + }, + price: { + type: Sequelize.INTEGER + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: (queryInterface, Sequelize) => { + return queryInterface.dropTable('Menus'); + } +}; \ No newline at end of file diff --git a/migrations/20180301021718-add_restaurantId.js b/migrations/20180301021718-add_restaurantId.js new file mode 100644 index 0000000..04bec2a --- /dev/null +++ b/migrations/20180301021718-add_restaurantId.js @@ -0,0 +1,26 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + /* + Add altering commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.createTable('users', { id: Sequelize.INTEGER }); + */ + return queryInterface.addColumn('Menus','RestaurantId',Sequelize.INTEGER, {}); + }, + + down: (queryInterface, Sequelize) => { + /* + Add reverting commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.dropTable('users'); + */ + return queryInterface.removeColumn('Menus','RestaurantId',null, {}); + } +}; + diff --git a/models/index.js b/models/index.js new file mode 100644 index 0000000..5662f10 --- /dev/null +++ b/models/index.js @@ -0,0 +1,36 @@ +'use strict'; + +var fs = require('fs'); +var path = require('path'); +var Sequelize = require('sequelize'); +var basename = path.basename(__filename); +var env = process.env.NODE_ENV || 'development'; +var config = require(__dirname + '/../config/config.json')[env]; +var db = {}; + +if (config.use_env_variable) { + var sequelize = new Sequelize(process.env[config.use_env_variable], config); +} else { + var sequelize = new Sequelize(config.database, config.username, config.password, config); +} + +fs + .readdirSync(__dirname) + .filter(file => { + return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'); + }) + .forEach(file => { + var model = sequelize['import'](path.join(__dirname, file)); + db[model.name] = model; + }); + +Object.keys(db).forEach(modelName => { + if (db[modelName].associate) { + db[modelName].associate(db); + } +}); + +db.sequelize = sequelize; +db.Sequelize = Sequelize; + +module.exports = db; diff --git a/models/menu.js b/models/menu.js new file mode 100644 index 0000000..4cb34a0 --- /dev/null +++ b/models/menu.js @@ -0,0 +1,15 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + var Menu = sequelize.define('Menu', { + name: DataTypes.STRING, + menu_type: DataTypes.STRING, + rating: DataTypes.INTEGER, + price: DataTypes.INTEGER, + RestaurantId : DataTypes.INTEGER, + }); + + Menu.associate = function(models){ + Menu.belongsTo(models.Restaurant,{foreignKey: 'RestaurantId'}) + }; + return Menu; +}; \ No newline at end of file diff --git a/models/restaurant.js b/models/restaurant.js new file mode 100644 index 0000000..ef1715d --- /dev/null +++ b/models/restaurant.js @@ -0,0 +1,13 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + var Restaurant = sequelize.define('Restaurant', { + name: DataTypes.STRING, + address: DataTypes.STRING + }); + + Restaurant.associate = function(models){ + Restaurant.hasMany(models.Menu,{foreignKey: 'RestaurantId'}) + }; + + return Restaurant; +}; \ No newline at end of file diff --git a/seeders/20180301022328-restaurant.js b/seeders/20180301022328-restaurant.js new file mode 100644 index 0000000..95035a3 --- /dev/null +++ b/seeders/20180301022328-restaurant.js @@ -0,0 +1,43 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + /* + Add altering commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.bulkInsert('Person', [{ + name: 'John Doe', + isBetaMember: false + }], {}); + */ + return queryInterface.bulkInsert('Restaurants', [{ + name: 'Hokben', + address: 'Pondok indah mall 1', + createdAt : new Date(), + updatedAt : new Date() + },{ + name: 'KFC', + address: 'Pondok indah mall 2', + createdAt : new Date(), + updatedAt : new Date() + },{ + name: 'Yoshinoya', + address: 'Gandaria City', + createdAt : new Date(), + updatedAt : new Date() + }], {}); + }, + + down: (queryInterface, Sequelize) => { + /* + Add reverting commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.bulkDelete('Person', null, {}); + */ + return queryInterface.bulkDelete('Person', null, {}); + } +}; diff --git a/seeders/20180301022705-menu.js b/seeders/20180301022705-menu.js new file mode 100644 index 0000000..b8ec82c --- /dev/null +++ b/seeders/20180301022705-menu.js @@ -0,0 +1,52 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + /* + Add altering commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.bulkInsert('Person', [{ + name: 'John Doe', + isBetaMember: false + }], {}); + */ + return queryInterface.bulkInsert('Menus', [{ + name: 'Beef Teryaki', + menu_type:'food', + rating:7, + price: 45000, + RestaurantId :1, + createdAt :new Date(), + updatedAt : new Date() + },{ + name: 'Grilled Chicken', + menu_type:'food', + rating:9, + price: 40000, + RestaurantId :1, + createdAt :new Date(), + updatedAt : new Date() + },{ + name: 'Coca cola', + menu_type:'drink', + rating:7, + price: 10000, + RestaurantId :2, + createdAt :new Date(), + updatedAt : new Date() + }], {}); + }, + + down: (queryInterface, Sequelize) => { + /* + Add reverting commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.bulkDelete('Person', null, {}); + */ + return queryInterface.bulkDelete('Menus', null, {}); + } +}; From e7f6aa14e7ab2cbd7cb45315cf2e02a983cdb1e1 Mon Sep 17 00:00:00 2001 From: haripermadi Date: Thu, 1 Mar 2018 10:29:02 +0700 Subject: [PATCH 2/7] challange 6 --- app.js | 16 ++++++++++ helpers/currency.js | 4 +++ routes/menus.js | 65 +++++++++++++++++++++++++++++++++++++++ views/menu/edit_menu.ejs | 38 +++++++++++++++++++++++ views/menu/list_menu.ejs | 66 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 app.js create mode 100644 helpers/currency.js create mode 100644 routes/menus.js create mode 100644 views/menu/edit_menu.ejs create mode 100644 views/menu/list_menu.ejs diff --git a/app.js b/app.js new file mode 100644 index 0000000..be82e8f --- /dev/null +++ b/app.js @@ -0,0 +1,16 @@ +const express = require('express'); +const app = express(); +const bodyParser = require('body-parser'); + +const menus = require('./routes/menus') + + + +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: true })); + +app.set('view engine', 'ejs'); +app.use('/menus',menus) + + +app.listen(3000, () => console.log('connected!')) \ No newline at end of file diff --git a/helpers/currency.js b/helpers/currency.js new file mode 100644 index 0000000..eafc3e1 --- /dev/null +++ b/helpers/currency.js @@ -0,0 +1,4 @@ +function format_currency (number){ + return 'Rp. '+number.toLocaleString(); +} +module.exports = {format_currency} \ No newline at end of file diff --git a/routes/menus.js b/routes/menus.js new file mode 100644 index 0000000..8406b2f --- /dev/null +++ b/routes/menus.js @@ -0,0 +1,65 @@ +const express = require('express'); +const app = express(); +const router = express.Router() +const models = require('../models') +const Menu = models.Menu +const Restaurant = models.Restaurant +const currency = require('../helpers/currency') + +router.get('/',function(req,res){ + Menu.findAll({ + include:[Restaurant] + }).then(data=>{ + Restaurant.findAll().then(listRestaurant=>{ + // res.send(data) + res.render('menu/list_menu',{dataMenu:data,dataResto:listRestaurant,format:currency}) + }) + }).catch(err=>{ + res.send(err) + }) +}) + +router.post('/',function(req,res){ + console.log(req.body) + Menu.create(req.body).then(data=>{ + res.redirect('/menus') + }).catch(err=>{ + res.send(err) + }) +}) + +router.get('/:id/edit',function(req,res){ + let id = req.params.id + Menu.findById(id).then(data=>{ + // res.send(data) + Restaurant.findAll().then(detail=>{ + res.render('menu/edit_menu',{menu:data,dataResto:detail}) + }) + + }).catch(err=>{ + res.send(err) + }) +}) + +router.post('/:id/edit',function(req,res){ + let id = req.params.id + console.log(id) + Menu.update(req.body,{ + where:{id:id} + }).then(data=>{ + res.redirect('/menus') + }).catch(err=>{ + res.send(err) + }) +}) +router.get('/:id/delete',function(req,res){ + let id = req.params.id + Menu.destroy({ + where:{id:id}}) + .then(()=>{ + res.redirect('/menus') + }) +}) + +module.exports = router + diff --git a/views/menu/edit_menu.ejs b/views/menu/edit_menu.ejs new file mode 100644 index 0000000..9a4a05c --- /dev/null +++ b/views/menu/edit_menu.ejs @@ -0,0 +1,38 @@ + + + + + + + + + Menu + + +
+

List Products

+
+
+
+
+
+
+
+
+
+
+ +
+ +
+ +
+ + + + diff --git a/views/menu/list_menu.ejs b/views/menu/list_menu.ejs new file mode 100644 index 0000000..a1adc88 --- /dev/null +++ b/views/menu/list_menu.ejs @@ -0,0 +1,66 @@ + + + + + + + + + Menu + + +
+

List Products

+ + + + + + + + + + + + + + <%dataMenu.forEach(data => {%> + + + + + + + + + + <%})%> + +
IDNameMenu TypeRatingPriceRestaurant IDAction
<%=data.id%><%=data.name%><%=data.menu_type%><%=data.rating%><%=format.format_currency(data.price)%><%=data.Restaurant.name%>
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+ +
+ + + + From 6ed7b05b1fd6b50c4918b794e4769fea0b45943d Mon Sep 17 00:00:00 2001 From: haripermadi Date: Thu, 1 Mar 2018 11:50:55 +0700 Subject: [PATCH 3/7] search --- app.js | 2 ++ models/menu.js | 23 ++++++++++++++-- models/restaurant.js | 8 ++++++ routes/menus.js | 16 ++++++++--- routes/restaurants.js | 49 +++++++++++++++++++++++++++++++++ views/menu/list_menu.ejs | 7 +++-- views/resto/list_resto.ejs | 39 +++++++++++++++++++++++++++ views/resto/view_menu.ejs | 55 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 192 insertions(+), 7 deletions(-) create mode 100644 routes/restaurants.js create mode 100644 views/resto/list_resto.ejs create mode 100644 views/resto/view_menu.ejs diff --git a/app.js b/app.js index be82e8f..5314399 100644 --- a/app.js +++ b/app.js @@ -3,6 +3,7 @@ const app = express(); const bodyParser = require('body-parser'); const menus = require('./routes/menus') +const resto = require('./routes/restaurants') @@ -11,6 +12,7 @@ app.use(bodyParser.urlencoded({ extended: true })); app.set('view engine', 'ejs'); app.use('/menus',menus) +app.use('/restaurants',resto) app.listen(3000, () => console.log('connected!')) \ No newline at end of file diff --git a/models/menu.js b/models/menu.js index 4cb34a0..58e917f 100644 --- a/models/menu.js +++ b/models/menu.js @@ -2,14 +2,33 @@ module.exports = (sequelize, DataTypes) => { var Menu = sequelize.define('Menu', { name: DataTypes.STRING, - menu_type: DataTypes.STRING, + menu_type:{ + type:DataTypes.STRING, + validate:{ + isIn: { + args: [['food', 'drink']], + msg: "Isi menu type dengan food / drink" + } + } + } , rating: DataTypes.INTEGER, price: DataTypes.INTEGER, RestaurantId : DataTypes.INTEGER, + },{ + hooks:{ + beforeCreate:function(Menu,options){ + console.log(Menu) + if(Menu.menu_type === 'food'&& Menu.price === 0 || Menu.price === null){ + this.price = 15000 + } + else if(Menu.menu_type === 'food'&& Menu.price === 0 || Menu.price === null){ + this.price = 10000 + } + }} }); Menu.associate = function(models){ Menu.belongsTo(models.Restaurant,{foreignKey: 'RestaurantId'}) }; return Menu; -}; \ No newline at end of file +}; diff --git a/models/restaurant.js b/models/restaurant.js index ef1715d..2329465 100644 --- a/models/restaurant.js +++ b/models/restaurant.js @@ -3,6 +3,14 @@ module.exports = (sequelize, DataTypes) => { var Restaurant = sequelize.define('Restaurant', { name: DataTypes.STRING, address: DataTypes.STRING + },{ + validate:{ + maxFood:function(resto,menu){ + sequelize.models.Restaurant.findOne({ + where:{id:id} + }) + } + } }); Restaurant.associate = function(models){ diff --git a/routes/menus.js b/routes/menus.js index 8406b2f..23352f2 100644 --- a/routes/menus.js +++ b/routes/menus.js @@ -12,7 +12,7 @@ router.get('/',function(req,res){ }).then(data=>{ Restaurant.findAll().then(listRestaurant=>{ // res.send(data) - res.render('menu/list_menu',{dataMenu:data,dataResto:listRestaurant,format:currency}) + res.render('menu/list_menu',{dataMenu:data,dataResto:listRestaurant,format:currency,error:null}) }) }).catch(err=>{ res.send(err) @@ -21,10 +21,20 @@ router.get('/',function(req,res){ router.post('/',function(req,res){ console.log(req.body) - Menu.create(req.body).then(data=>{ + Menu.create(req.body,{ + individualHook:true + }).then(data=>{ res.redirect('/menus') }).catch(err=>{ - res.send(err) + Menu.findAll({ + include:[Restaurant] + }).then(data=>{ + Restaurant.findAll().then(listRestaurant=>{ + // res.send(data) + res.render('menu/list_menu',{dataMenu:data,dataResto:listRestaurant,format:currency,error:err.errors[0].message}) + }) + }) + // res.render('menu/list_menu',{dataMenu:data,error:err.errors[0].message}) }) }) diff --git a/routes/restaurants.js b/routes/restaurants.js new file mode 100644 index 0000000..37e1720 --- /dev/null +++ b/routes/restaurants.js @@ -0,0 +1,49 @@ +const express = require('express'); +const app = express(); +const router = express.Router() +const models = require('../models') +const Menu = models.Menu +const Restaurant = models.Restaurant +const currency = require('../helpers/currency') +const Op = require('sequelize').Op + +router.get('/',function(req,res){ + Restaurant.findAll().then(data=>{ + res.render('resto/list_resto',{resto:data}) + }).catch(err=>{ + res.send(err) + }) +}) +router.get('/:id/view_menu',function(req,res){ + Restaurant.findOne({ + include:[Menu] + }).then(data=>{ + // res.send(data) + res.render('resto/view_menu',{menu:data,format:currency}) + }).catch(err=>{ + res.send(err) + }) +}) +router.post('/:id/search',function(req,res){ + let keyword = req.body.keyword + let category = req.body.category + // let obj={}; + // obj[category] + + // console.log(obj) + console.log(category) + Restaurant.findOne({ + include:[{model:Menu,where:{[category]:{[Op.iLike]:`%${keyword}%`}}}], + where:{ + id:req.params.id + } + }).then(data=>{ + // res.send(data) + res.render('resto/view_menu',{menu:data,format:currency}) + + }).catch(err=>{ + res.send(err) + }) +}) +module.exports = router + diff --git a/views/menu/list_menu.ejs b/views/menu/list_menu.ejs index a1adc88..0bf4a7e 100644 --- a/views/menu/list_menu.ejs +++ b/views/menu/list_menu.ejs @@ -40,6 +40,11 @@

+ <%if(error !== null){%> +
+ Validation Error! <%=error%> +
+ <%}%>


@@ -62,5 +67,3 @@ - - diff --git a/views/resto/list_resto.ejs b/views/resto/list_resto.ejs new file mode 100644 index 0000000..978f1ec --- /dev/null +++ b/views/resto/list_resto.ejs @@ -0,0 +1,39 @@ + + + + + + + + + Restaurant + + +
+

List Restaurants

+ + + + + + + + + + + <%resto.forEach(data => {%> + + + + + + <%})%> + +
IDNameAddressAction
<%=data.id%><%=data.name%><%=data.address%> +
+
+
+ +
+ + diff --git a/views/resto/view_menu.ejs b/views/resto/view_menu.ejs new file mode 100644 index 0000000..78a7aea --- /dev/null +++ b/views/resto/view_menu.ejs @@ -0,0 +1,55 @@ + + + + + + + + + Restaurant + + +
+

Menu Restaurant : <%=menu.name%>

+ + + + +
+ + + +
+ + + + + + + + + + + + <%menu.Menus.forEach(data => {%> + + + + + + + + <%})%> + +
IDNameMenu TypeRatingPrice
<%=data.id%><%=data.name%><%=data.menu_type%><%=data.rating%><%=format.format_currency(data.price)%>
+
+
+ +
+ + From 7b6b9c39259f69dd7a2b51aa7efbf3043fc63c62 Mon Sep 17 00:00:00 2001 From: haripermadi Date: Thu, 1 Mar 2018 11:52:08 +0700 Subject: [PATCH 4/7] live code --- models/restaurant.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/restaurant.js b/models/restaurant.js index 2329465..6e932b6 100644 --- a/models/restaurant.js +++ b/models/restaurant.js @@ -5,9 +5,9 @@ module.exports = (sequelize, DataTypes) => { address: DataTypes.STRING },{ validate:{ - maxFood:function(resto,menu){ + maxFood:function(idresto,menu){ sequelize.models.Restaurant.findOne({ - where:{id:id} + where:{id:idresto} }) } } From 6abfd415cfd051eb9f5d05d8407064f28e592f8b Mon Sep 17 00:00:00 2001 From: haripermadi Date: Thu, 1 Mar 2018 12:04:21 +0700 Subject: [PATCH 5/7] live code --- models/menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/menu.js b/models/menu.js index 58e917f..14c4157 100644 --- a/models/menu.js +++ b/models/menu.js @@ -16,7 +16,7 @@ module.exports = (sequelize, DataTypes) => { RestaurantId : DataTypes.INTEGER, },{ hooks:{ - beforeCreate:function(Menu,options){ + afterCreate:function(Menu,options){ console.log(Menu) if(Menu.menu_type === 'food'&& Menu.price === 0 || Menu.price === null){ this.price = 15000 From ee906c2f10ebb3e5db71d38c6c3ebe1fcb20cf29 Mon Sep 17 00:00:00 2001 From: haripermadi Date: Thu, 1 Mar 2018 23:41:11 +0700 Subject: [PATCH 6/7] hook create --- models/menu.js | 21 ++++++++++++++++----- routes/menus.js | 4 +--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/models/menu.js b/models/menu.js index 14c4157..10a6449 100644 --- a/models/menu.js +++ b/models/menu.js @@ -16,13 +16,24 @@ module.exports = (sequelize, DataTypes) => { RestaurantId : DataTypes.INTEGER, },{ hooks:{ - afterCreate:function(Menu,options){ + beforeCreate:function(Menu,options){ console.log(Menu) - if(Menu.menu_type === 'food'&& Menu.price === 0 || Menu.price === null){ - this.price = 15000 + if(Menu.price == 0 || Menu.price === null){ + if(Menu.menu_type === 'food'){ + Menu.price = 15000 + }else{ + Menu.price = 10000 + } } - else if(Menu.menu_type === 'food'&& Menu.price === 0 || Menu.price === null){ - this.price = 10000 + }, + beforeUpdate:function(Menu,options){ + console.log(Menu) + if(Menu.price == 0 || Menu.price === null){ + if(Menu.menu_type === 'food'){ + Menu.price = 15000 + }else{ + Menu.price = 10000 + } } }} }); diff --git a/routes/menus.js b/routes/menus.js index 23352f2..ce66aba 100644 --- a/routes/menus.js +++ b/routes/menus.js @@ -21,9 +21,7 @@ router.get('/',function(req,res){ router.post('/',function(req,res){ console.log(req.body) - Menu.create(req.body,{ - individualHook:true - }).then(data=>{ + Menu.create(req.body).then(data=>{ res.redirect('/menus') }).catch(err=>{ Menu.findAll({ From a3373c840fddb61a2b04a3ee18473e5da271a590 Mon Sep 17 00:00:00 2001 From: haripermadi Date: Thu, 1 Mar 2018 23:43:28 +0700 Subject: [PATCH 7/7] hook update --- routes/menus.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routes/menus.js b/routes/menus.js index ce66aba..51f4070 100644 --- a/routes/menus.js +++ b/routes/menus.js @@ -53,7 +53,8 @@ router.post('/:id/edit',function(req,res){ let id = req.params.id console.log(id) Menu.update(req.body,{ - where:{id:id} + where:{id:id}, + individualHooks:true }).then(data=>{ res.redirect('/menus') }).catch(err=>{