Skip to content

Instantly share code, notes, and snippets.

@ejnshtein
Last active May 13, 2020 14:00
Show Gist options
  • Save ejnshtein/29d5b82967a2cf30f6abcc8c8275eb08 to your computer and use it in GitHub Desktop.
Save ejnshtein/29d5b82967a2cf30f6abcc8c8275eb08 to your computer and use it in GitHub Desktop.
exports.getProducts = async (req, res, next) => {
const docs = await Product.find()
.select('_id price productImage')
const response = {
count: docs.length,
docs: docs.map(doc => ({
_id: doc._id,
price: doc.price,
request: {
type: 'get',
url: `https://localhost:3100/${doc._id}`
},
...(
doc.productImage
? {
productImage: `https://localhost:3100/${doc.productImage}`,
}
: {}
)
})
)
}
return res.json(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment