Started work on adding license tracking
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2022-11-06 01:37:56 -05:00
parent b98fbddd9e
commit 4167130f0c
8 changed files with 162 additions and 25 deletions

View File

@ -1,8 +1,10 @@
const db = require('../models');
const Item = db.items;
const License = db.licenses;
// GET - /
exports.getIndex = async function(req, res) {
// fetch inventory items from database
const items = await Item.findAll({
limit: 10,
order: [
@ -10,9 +12,18 @@ exports.getIndex = async function(req, res) {
],
});
// fetch licenses from database
const licenses = await License.findAll({
limit: 10,
order: [
['updatedAt', 'DESC'],
],
});
// req.flash('info', 'This is a test flash message.');
res.render('index.twig', {
inventory: items,
licenses: licenses,
});
};

22
src/routes/license.js Normal file
View File

@ -0,0 +1,22 @@
const db = require('../models');
const License = db.licenses;
// GET - /license/add
exports.getAdd = async function(req, res) {
res.render('license/add.twig');
};
// POST - /license/add
exports.postAdd = async function(req, res) {
const license = await License.create({
name: req.body.license_name,
key: req.body.license_key,
manufacturer: req.body.license_manufacturer,
purchasedFrom: req.body.license_purchase_from,
purchasedAt: req.body.license_purchase_date,
});
console.log(`Saved license ${license.name} to the database.`);
res.redirect('/');
};