init
This commit is contained in:
35
controllers/customerController.js
Normal file
35
controllers/customerController.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const Customer = require('../models/customer');
|
||||
|
||||
exports.list = async (req, res) => {
|
||||
const customers = await Customer.findAll();
|
||||
res.render('index', { customers });
|
||||
};
|
||||
|
||||
exports.show = async (req, res) => {
|
||||
const customer = await Customer.findByPk(req.params.id);
|
||||
res.render('show', { customer });
|
||||
};
|
||||
|
||||
exports.createForm = (req, res) => {
|
||||
res.render('create');
|
||||
};
|
||||
|
||||
exports.create = async (req, res) => {
|
||||
await Customer.create(req.body);
|
||||
res.redirect('/customers');
|
||||
};
|
||||
|
||||
exports.editForm = async (req, res) => {
|
||||
const customer = await Customer.findByPk(req.params.id);
|
||||
res.render('edit', { customer });
|
||||
};
|
||||
|
||||
exports.update = async (req, res) => {
|
||||
await Customer.update(req.body, { where: { id: req.params.id } });
|
||||
res.redirect('/customers');
|
||||
};
|
||||
|
||||
exports.delete = async (req, res) => {
|
||||
await Customer.destroy({ where: { id: req.params.id } });
|
||||
res.redirect('/customers');
|
||||
};
|
||||
Reference in New Issue
Block a user