Created
June 20, 2020 16:17
-
-
Save stemount/ef6571db5ae5675041cce12dec6fe8a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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