Added some more fields to track for inventory; fixed routing issues with the /item/:id route

This commit is contained in:
Gregory Ballantine 2022-11-03 12:26:45 -04:00
parent 4a0241dd2b
commit 6751d832fd
4 changed files with 46 additions and 2 deletions

View File

@ -7,7 +7,7 @@ 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(); await db.sequelize.sync({ alter: true });
})(); })();
// set up body POST parameters // set up body POST parameters
@ -26,9 +26,9 @@ const itemRoutes = require('./src/routes/item');
// register route handlers // register route handlers
app.get('/', homeRoutes.getIndex); app.get('/', homeRoutes.getIndex);
app.get('/item/:id', itemRoutes.getItem);
app.get('/item/add', itemRoutes.getAdd); app.get('/item/add', itemRoutes.getAdd);
app.post('/item/add', itemRoutes.postAdd); app.post('/item/add', itemRoutes.postAdd);
app.get('/item/:id', itemRoutes.getItem);
// start app // start app
app.listen(port, () => { app.listen(port, () => {

View File

@ -9,9 +9,25 @@ module.exports = (sequelize, Sequelize) => {
manufacturer: { manufacturer: {
type: Sequelize.STRING type: Sequelize.STRING
}, },
serialNumber: {
type: Sequelize.STRING
},
skuNumber: {
type: Sequelize.STRING
},
type: { type: {
type: Sequelize.STRING type: Sequelize.STRING
},
purchasedFrom: {
type: Sequelize.STRING
},
purchasedAt: {
type: Sequelize.DATE
} }
}); });

View File

@ -21,6 +21,10 @@ exports.getAdd = async function (req, res) {
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,
skuNumber: req.body.item_sku,
purchasedFrom: req.body.item_purchase_from,
purchasedAt: req.body.item_purchase_date,
manufacturer: req.body.item_manufacturer, manufacturer: req.body.item_manufacturer,
type: req.body.item_type, type: req.body.item_type,
}); });

View File

@ -21,6 +21,30 @@
</div> </div>
</div> </div>
<div class="row">
<div class="six columns">
<label for="item_serial">Serial number:</label>
<input class="u-full-width" type="text" placeholder="0123456789" id="item_serial" name="item_serial">
</div>
<div class="six columns">
<label for="item_sku">SKU number:</label>
<input class="u-full-width" type="text" placeholder="ABC12345678" id="item_sku" name="item_sku">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="item_purchase_from">Purchased from:</label>
<input class="u-full-width" type="text" placeholder="Newegg" id="item_purchase_from" name="item_purchase_from">
</div>
<div class="six columns">
<label for="item_purchase_date">Purchased at:</label>
<input class="u-full-width" type="datetime-local" id="item_purchase_date" name="item_purchase_date">
</div>
</div>
<div class="row"> <div class="row">
<div class="six columns"> <div class="six columns">
<label for="item_manufacturer">Manufacturer:</label> <label for="item_manufacturer">Manufacturer:</label>