Created
December 18, 2019 00:19
-
-
Save paulobunga/b4ec0bc02989e2789a2fb318c1d5af56 to your computer and use it in GitHub Desktop.
Code to return single product details based on the ID
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
Product.findOne({ _id: req.params.productId }).exec((error, result) => { | |
if (error) { | |
res.json({ status: 'ERROR', message: 'Error getting product' }); | |
} | |
if (result) { | |
res.json({ | |
status: 'SUCCESS', | |
message: 'Product found', | |
product: result, | |
}); | |
} else { | |
res.json({ status: 'NO_PRODUCT', message: 'No product with specified product ID found' }); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment