Added a basic item add page/route
This commit is contained in:
@ -1,4 +1,9 @@
|
||||
const db = require('../models');
|
||||
const Item = db.items;
|
||||
|
||||
// GET - /
|
||||
exports.getIndex = function (req, res) {
|
||||
exports.getIndex = async function (req, res) {
|
||||
let items = await Item.findAll({});
|
||||
console.log(items);
|
||||
res.render('index.twig');
|
||||
};
|
||||
|
20
src/routes/item.js
Normal file
20
src/routes/item.js
Normal file
@ -0,0 +1,20 @@
|
||||
const db = require('../models');
|
||||
const Item = db.items;
|
||||
|
||||
// GET - /item/add
|
||||
exports.getAdd = async function (req, res) {
|
||||
res.render('item/add.twig');
|
||||
};
|
||||
|
||||
// POST - /item/add
|
||||
exports.postAdd = async function (req, res) {
|
||||
const item = await Item.create({
|
||||
name: req.body.item_name,
|
||||
manufacturer: req.body.item_manufacturer,
|
||||
type: req.body.item_type,
|
||||
});
|
||||
|
||||
console.log(`Saved item ${item.name} to the database.`);
|
||||
|
||||
res.redirect('/');
|
||||
};
|
Reference in New Issue
Block a user