The code which i have written takes id from url and then gives me the output. api?category=4556 here 4556 is the id. I have one Products controller having
- product_name
- price
- category_id:i am passing category id manually from category generated.
and in category controller i have category_name.
here i want to get in this way api?category=games is there any way to do so.
exports.getProducts = function(req, res) {
// Use the Prod model to find all products
/*
Prod.find(function(err, prods) {
if (err)
res.send(err);
res.json(prods);
next();
});
*/
var cat=req.query.category;
var condition = {};
if (cat) {
condition.cat_id = cat;
}
Prod.find(condition).then(function(cat) {
res.json({cat});
})
.catch((err) => {
console.log('error', err);
res.status(500).send();
});
};
This code checks for the products having cat_id similar to the id provided by url as ?category=4556 i want to check it as ?category=games , if there is some way please help it would be great pleasure.thanks in advance