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
(async () => {
const db = require('./src/models');
await db.sequelize.sync({ alter: true });
await db.sequelize.sync({
alter: true,
});
})();
// set up body POST parameters
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.urlencoded({
extended: true,
}));
// load the template engine
app.set('view engine', 'twig');

View File

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

View File

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

View File

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

View File

@ -25,9 +25,11 @@ exports.postAdd = async function (req, res) {
// GET - /item/{id}
exports.getItem = async function(req, res) {
const item = await Item.findAll({ where: {
const item = await Item.findAll({
where: {
id: req.params.id,
}});
},
});
res.render('item/view.twig', {
item: item[0],
@ -36,9 +38,11 @@ exports.getItem = async function (req, res) {
// GET - /item/{id}/edit
exports.getItemEdit = async function(req, res) {
const item = await Item.findAll({ where: {
const item = await Item.findAll({
where: {
id: req.params.id,
}});
},
});
res.render('item/edit.twig', {
item: item[0],
@ -48,12 +52,14 @@ exports.getItemEdit = async function (req, res) {
// POST - /item/{id}/edit
exports.postItemEdit = async function(req, res) {
// fetch item from DB
const itemSearch = await Item.findAll({ where: {
const itemSearch = await Item.findAll({
where: {
id: req.params.id,
}});
},
});
// retrieve the item record from the array for ease of use
let item = itemSearch[0];
const item = itemSearch[0];
// update item attributes
item.name = req.body.item_name;