Skip to content

Commit

Permalink
Merge pull request #12 from adnan-mujagic/adnan-mujagic/search-produc…
Browse files Browse the repository at this point in the history
…t-support

Support for product searching
  • Loading branch information
amarell authored Jun 20, 2022
2 parents 464060b + 0000ce8 commit 8a45630
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions controllers/productController.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ module.exports.getProduct = async (req, res) => {
};

module.exports.getProducts = async (req, res) => {
const { page = 1, pageSize = 25 } = req.query;
Product.find({})
const { page = 1, pageSize = 25, search = null } = req.query;
let criteria = {};
if (search != null) {
let reg = {
$regex: search,
$options: "i", // makes the search criteria case insensitive
};
criteria["name"] = reg;
}

Product.find(criteria)
.skip((page - 1) * pageSize)
.limit(pageSize)
.exec((err, products) => {
Expand Down

0 comments on commit 8a45630

Please sign in to comment.