This commit is contained in:
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,
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user