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
}
});
return Item;
type: Sequelize.DATE,
},
});
return Item;
};

View File

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

View File

@ -2,12 +2,12 @@ const db = require('../models');
const Item = db.items;
// GET - /item/add
exports.getAdd = async function (req, res) {
exports.getAdd = async function(req, res) {
res.render('item/add.twig');
};
// POST - /item/add
exports.postAdd = async function (req, res) {
exports.postAdd = async function(req, res) {
const item = await Item.create({
name: req.body.item_name,
serialNumber: req.body.item_serial,
@ -24,10 +24,12 @@ exports.postAdd = async function (req, res) {
};
// GET - /item/{id}
exports.getItem = async function (req, res) {
const item = await Item.findAll({ where: {
id: req.params.id,
}});
exports.getItem = async function(req, res) {
const item = await Item.findAll({
where: {
id: req.params.id,
},
});
res.render('item/view.twig', {
item: item[0],
@ -35,10 +37,12 @@ exports.getItem = async function (req, res) {
};
// GET - /item/{id}/edit
exports.getItemEdit = async function (req, res) {
const item = await Item.findAll({ where: {
id: req.params.id,
}});
exports.getItemEdit = async function(req, res) {
const item = await Item.findAll({
where: {
id: req.params.id,
},
});
res.render('item/edit.twig', {
item: item[0],
@ -46,14 +50,16 @@ exports.getItemEdit = async function (req, res) {
};
// POST - /item/{id}/edit
exports.postItemEdit = async function (req, res) {
exports.postItemEdit = async function(req, res) {
// fetch item from DB
const itemSearch = await Item.findAll({ where: {
id: req.params.id,
}});
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;