From 1b1e1e8b5eedd9a330cd1eb007e0660c8b395eda Mon Sep 17 00:00:00 2001 From: Akram Khan Date: Wed, 4 Aug 2021 18:48:36 +0600 Subject: [PATCH] replaced condition by loop in product search --- router/product.js | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/router/product.js b/router/product.js index 0fc98c5..42268d0 100644 --- a/router/product.js +++ b/router/product.js @@ -19,23 +19,8 @@ product_router.get('/:name', (req, res) => { name: req.params.name, } let q = req.query - if (q.price) { - query.price = q.price - } - if (q.brand) { - query.brand = q.brand - } - if (q.quantity) { - query.quantity = q.quantity - } - if (q.size) { - query.size = q.size - } - if (q.unit) { - query.unit = q.unit - } - if (q.color) { - query.color = q.color + for (let property in q) { + query[property] = q[property]; } productModel.findOne(query, (err, result) => { if (err) { @@ -114,4 +99,4 @@ product_router.delete('/:product_id', (req, res) => { }) }) -module.exports = product_router \ No newline at end of file +module.exports = product_router