2.12 Customer - search
- Update 'models/ProductDAO.js' file
... | |
var ProductDAO = { | |
..., | |
async selectByKeyword(keyword) { | |
var query = { name: { $regex: new RegExp(keyword, "i") } }; | |
var products = await Models.Product.find(query).exec(); | |
return products; | |
} | |
}; | |
... |
- Update 'controllers/customer.js' file
... | |
// product | |
router.post('/search', async function (req, res) { | |
var categories = await CategoryDAO.selectAll(); | |
var keyword = req.body.txtKeyword; | |
var products = await ProductDAO.selectByKeyword(keyword); | |
res.render('../views/customer/listproduct.ejs', { cats: categories, prods: products }); | |
}); | |
... |