Added a page to view info about an item

This commit is contained in:
Gregory Ballantine 2022-11-02 23:23:20 -04:00
parent 1b46e7c3fb
commit 4a0241dd2b
4 changed files with 49 additions and 1 deletions

View File

@ -26,6 +26,7 @@ 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);

View File

@ -1,6 +1,17 @@
const db = require('../models');
const Item = db.items;
// GET - /item/{name}
exports.getItem = async function (req, res) {
const item = await Item.findAll({ where: {
id: req.params.id,
}});
res.render('item/view.twig', {
item: item[0],
});
};
// GET - /item/add
exports.getAdd = async function (req, res) {
res.render('item/add.twig');

View File

@ -39,7 +39,7 @@
<tbody>
{% for item in inventory %}
<tr>
<td>{{ item.name }}</td>
<td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
<td>{{ item.manufacturer }}</td>
<td>{{ item.type }}</td>
</tr>

36
views/item/view.twig Normal file
View File

@ -0,0 +1,36 @@
{% extends 'layout.twig' %}
{% block title %}{{ item.name }}{% endblock %}
{% block content %}
<!-- page header -->
<header class="row">
<div class="columns twelve">
<h1>{{ item.name }}</h1>
</div>
</header>
<!-- item information -->
<section class="row">
<table class="columns twelve">
<thead>
<tr>
<th>Name</th>
<th>Manufacturer</th>
<th>Type</th>
<th>Created date</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ item.name }}</td>
<td>{{ item.manufacturer }}</td>
<td>{{ item.type }}</td>
<td>{{ item.createdAt | date("m/d/Y h:i:s A") }}</td>
</tr>
</tbody>
</table>
</section>
{% endblock %}