Created
December 18, 2019 00:26
-
-
Save paulobunga/c6e75b5a7a3e2c647bcf98693a3bd92d to your computer and use it in GitHub Desktop.
Delete single product by product 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
module.exports.deleteProduct = async (req, res, next) => { | |
let { productId } = req.params; | |
Product.findByIdAndDelete(productId, (error, result) => { | |
if (error) { | |
res.json({ status: 'ERROR', message: 'Error deleting product' }); | |
} | |
if (result) { | |
res.json({ status: 'SUCCESS', message: 'Product deleted' }); | |
} else { | |
res.json({ status: 'FAILURE', message: 'Failed to delete product' }); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment