Skip to content

Instantly share code, notes, and snippets.

@stemount
Created June 20, 2020 16:17
Show Gist options
  • Save stemount/ef6571db5ae5675041cce12dec6fe8a2 to your computer and use it in GitHub Desktop.
Save stemount/ef6571db5ae5675041cce12dec6fe8a2 to your computer and use it in GitHub Desktop.
const dot = require('dot-object');
exports.getProductsBySpecs = async(req,res,next) => {
try{
const q = req.query;
const specificationsInDotNotation = dot.dot(req.query.filter((key) => {
// Only allow size/color attributes.
return key === 'size' || 'color';
}));
// Ping over our specifications in dot notation.
const products = await Product.find(specificationsInDotNotation );
console.log("hopefully its in your console", q);
res.status(200).json({
products
});
}catch(err){
catchError(err,next)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment