Last active
May 13, 2020 14:00
-
-
Save ejnshtein/29d5b82967a2cf30f6abcc8c8275eb08 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
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