I want to make a query with multiple conditions but the like query is not working:
exports.getAllPeoduct = async (req, res) => {
var where = [];
if(Common.required(req.query.shopId)) where.push({shopId : req.query.shopId});
if(Common.required(req.query.categoryId)) where.push({categoryId : req.query.categoryId});
if(Common.required(req.query.price)) where.push({price : req.query.price});
if(Common.required(req.query.color)) where.push({availableColors :'/.*'+req.query.color+'.*/'});
console.log(where);
// if(Common.required(req.query.size)) where.availableSizes = req.query.size;
try{
// if(Common.required(shopId)) {
let getAllProduct = await product.find({$or : where});
if(getAllProduct.length){
Common.sendResponseBack(res, 200,message.OK ,message.getAllProductMessage, getAllProduct);
} else {
Common.sendResponseBack(res, 200, message.OK, message.NoRecordFoundMessage, getAllProduct);
}
// } else {
// Common.sendResponseBack(res, 403,message.FAIL, message.passAllReqFields, null);
// }
} catch (err){
logger.error( 'Error occured on '+new Date()+' with reason' + err);
Common.sendResponseBack(res, 403, message.FAIL, message.internalErrorMsg, null);
}
}