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

View File

@ -9,9 +9,25 @@ module.exports = (sequelize, Sequelize) => {
manufacturer: {
type: Sequelize.STRING
},
serialNumber: {
type: Sequelize.STRING
},
skuNumber: {
type: Sequelize.STRING
},
type: {
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) {
const item = await Item.create({
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,
type: req.body.item_type,
});

View File

@ -21,6 +21,30 @@
</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="six columns">
<label for="item_manufacturer">Manufacturer:</label>