Fixed code style errors
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-11-03 22:28:01 -04:00
parent bfb8d751b8
commit 5e895aa3ca
5 changed files with 47 additions and 39 deletions

View File

@ -7,12 +7,16 @@ const port = 3000;
// initialize database connection // initialize database connection
(async () => { (async () => {
const db = require('./src/models'); const db = require('./src/models');
await db.sequelize.sync({ alter: true }); await db.sequelize.sync({
alter: true,
});
})(); })();
// set up body POST parameters // set up body POST parameters
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ extended: true })); app.use(express.urlencoded({
extended: true,
}));
// load the template engine // load the template engine
app.set('view engine', 'twig'); app.set('view engine', 'twig');

View File

@ -1,9 +1,9 @@
const dbConfig = require('config').get('database'); const dbConfig = require('config').get('database');
const Sequelize = require("sequelize"); const Sequelize = require('sequelize');
const sequelize = new Sequelize({ const sequelize = new Sequelize({
dialect: dbConfig.get('driver'), dialect: dbConfig.get('driver'),
storage: dbConfig.get('connection_string') storage: dbConfig.get('connection_string'),
}); });
const db = {}; const db = {};
@ -11,6 +11,6 @@ const db = {};
db.Sequelize = Sequelize; db.Sequelize = Sequelize;
db.sequelize = sequelize; db.sequelize = sequelize;
db.items = require("./item.js")(sequelize, Sequelize); db.items = require('./item.js')(sequelize, Sequelize);
module.exports = db; module.exports = db;

View File

@ -1,37 +1,35 @@
module.exports = (sequelize, Sequelize) => { module.exports = (sequelize, Sequelize) => {
const Item = sequelize.define('item', {
const Item = sequelize.define("item", {
name: { name: {
type: Sequelize.STRING type: Sequelize.STRING,
}, },
manufacturer: { manufacturer: {
type: Sequelize.STRING type: Sequelize.STRING,
}, },
serialNumber: { serialNumber: {
type: Sequelize.STRING type: Sequelize.STRING,
}, },
skuNumber: { skuNumber: {
type: Sequelize.STRING type: Sequelize.STRING,
}, },
type: { type: {
type: Sequelize.STRING type: Sequelize.STRING,
}, },
purchasedFrom: { purchasedFrom: {
type: Sequelize.STRING type: Sequelize.STRING,
}, },
purchasedAt: { purchasedAt: {
type: Sequelize.DATE type: Sequelize.DATE,
} },
}); });
return Item; return Item;
}; };

View File

@ -2,12 +2,12 @@ const db = require('../models');
const Item = db.items; const Item = db.items;
// GET - / // GET - /
exports.getIndex = async function (req, res) { exports.getIndex = async function(req, res) {
let items = await Item.findAll({ const items = await Item.findAll({
limit: 10, limit: 10,
order: [ order: [
['updatedAt', 'DESC'], ['updatedAt', 'DESC'],
] ],
}); });
res.render('index.twig', { res.render('index.twig', {

View File

@ -2,12 +2,12 @@ const db = require('../models');
const Item = db.items; const Item = db.items;
// GET - /item/add // GET - /item/add
exports.getAdd = async function (req, res) { exports.getAdd = async function(req, res) {
res.render('item/add.twig'); res.render('item/add.twig');
}; };
// POST - /item/add // POST - /item/add
exports.postAdd = async function (req, res) { exports.postAdd = async function(req, res) {
const item = await Item.create({ const item = await Item.create({
name: req.body.item_name, name: req.body.item_name,
serialNumber: req.body.item_serial, serialNumber: req.body.item_serial,
@ -24,10 +24,12 @@ exports.postAdd = async function (req, res) {
}; };
// GET - /item/{id} // GET - /item/{id}
exports.getItem = async function (req, res) { exports.getItem = async function(req, res) {
const item = await Item.findAll({ where: { const item = await Item.findAll({
id: req.params.id, where: {
}}); id: req.params.id,
},
});
res.render('item/view.twig', { res.render('item/view.twig', {
item: item[0], item: item[0],
@ -35,10 +37,12 @@ exports.getItem = async function (req, res) {
}; };
// GET - /item/{id}/edit // GET - /item/{id}/edit
exports.getItemEdit = async function (req, res) { exports.getItemEdit = async function(req, res) {
const item = await Item.findAll({ where: { const item = await Item.findAll({
id: req.params.id, where: {
}}); id: req.params.id,
},
});
res.render('item/edit.twig', { res.render('item/edit.twig', {
item: item[0], item: item[0],
@ -46,14 +50,16 @@ exports.getItemEdit = async function (req, res) {
}; };
// POST - /item/{id}/edit // POST - /item/{id}/edit
exports.postItemEdit = async function (req, res) { exports.postItemEdit = async function(req, res) {
// fetch item from DB // fetch item from DB
const itemSearch = await Item.findAll({ where: { const itemSearch = await Item.findAll({
id: req.params.id, where: {
}}); id: req.params.id,
},
});
// retrieve the item record from the array for ease of use // retrieve the item record from the array for ease of use
let item = itemSearch[0]; const item = itemSearch[0];
// update item attributes // update item attributes
item.name = req.body.item_name; item.name = req.body.item_name;