This commit is contained in:
parent
4cfffbd219
commit
43e70e243c
27
src/routes/search.js
Normal file
27
src/routes/search.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
const db = require('../models');
|
||||||
|
const Item = db.items;
|
||||||
|
const License = db.licenses;
|
||||||
|
|
||||||
|
// GET - /search
|
||||||
|
exports.getIndex = async function(req, res) {
|
||||||
|
// decode URL search query
|
||||||
|
let query = req.params.query;
|
||||||
|
|
||||||
|
// fetch inventory items from database based on search query
|
||||||
|
const results = await Item.find({
|
||||||
|
where: {
|
||||||
|
name: {
|
||||||
|
[Op.like]: query,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
limit: 10,
|
||||||
|
order: [
|
||||||
|
['updatedAt', 'DESC'],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
res.render('search.twig', {
|
||||||
|
query: query,
|
||||||
|
results: results,
|
||||||
|
});
|
||||||
|
};
|
@ -27,7 +27,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<form id="search-form" action="/search" method="GET">
|
<form id="search-form" action="/search" method="GET">
|
||||||
<input type="text" name="search" placeholder="enter a search query...">
|
<input type="text" name="query" placeholder="enter a search query...">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<button id="search-button" type="submit" for="search-form"><i class="fa-solid fa-magnifying-glass"></i></button>
|
<button id="search-button" type="submit" for="search-form"><i class="fa-solid fa-magnifying-glass"></i></button>
|
||||||
|
37
views/search.twig
Normal file
37
views/search.twig
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{% extends 'layout.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Search{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<!-- page header -->
|
||||||
|
<header class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<h1>Searching for "{{ query }}"</h1>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section id="search-results" class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<table class="u-full-width">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Updated at</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for item in results %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
|
||||||
|
<td>{{ item.type }}</td>
|
||||||
|
<td>{{ item.updatedAt | date("m/d/Y h:i:s A") }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user