Added a basic item add page/route

This commit is contained in:
2022-11-02 13:45:40 -04:00
parent 3c0ebc7001
commit aa980948d8
11 changed files with 2405 additions and 63 deletions

View File

@ -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
View 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('/');
};