diff --git a/src/routes/search.js b/src/routes/search.js index 4ba13fb..ec7db7b 100644 --- a/src/routes/search.js +++ b/src/routes/search.js @@ -9,7 +9,20 @@ exports.getSearch = async function(req, res) { let query = req.query.query; // fetch inventory items from database based on search query - const results = await Item.findAll({ + const item_results = await Item.findAll({ + where: { + name: { + [Op.like]: '%' + query + '%', + } + }, + limit: 10, + order: [ + ['updatedAt', 'DESC'], + ], + }); + + // fetch licenses from database based on search query + const license_results = await License.findAll({ where: { name: { [Op.like]: '%' + query + '%', @@ -23,6 +36,7 @@ exports.getSearch = async function(req, res) { res.render('search.twig', { query: query, - results: results, + item_results: item_results, + license_results: license_results, }); }; diff --git a/views/search.twig b/views/search.twig index 3fe2eb6..775722b 100644 --- a/views/search.twig +++ b/views/search.twig @@ -11,27 +11,56 @@ -
-
- - - - - - - - - - {% for item in results %} +{% if item_results|len > 0 %} +
+
+

Hardware components:

+
NameTypeUpdated at
+ - - - + + + - {% endfor %} - -
{{ item.name }}{{ item.type }}{{ item.updatedAt | date("m/d/Y h:i:s A") }}NameTypeUpdated at
-
-
+ + + {% for item in item_results %} + + {{ item.name }} + {{ item.type }} + {{ item.updatedAt | date("m/d/Y h:i:s A") }} + + {% endfor %} + + + + +{% endif %} + +{% if license_results|len > 0 %} +
+
+

Software licenses:

+ + + + + + + + + + {% for license in license_results %} + + + + + + {% endfor %} + +
NameVendorUpdated at
{{ license.name }}{{ license.manufacturer }}{{ license.updatedAt | date("m/d/Y h:i:s A") }}
+
+
+{% endif %} {% endblock %}