Skip to content

Instantly share code, notes, and snippets.

@paulobunga
Created December 18, 2019 00:26
Show Gist options
  • Save paulobunga/c6e75b5a7a3e2c647bcf98693a3bd92d to your computer and use it in GitHub Desktop.
Save paulobunga/c6e75b5a7a3e2c647bcf98693a3bd92d to your computer and use it in GitHub Desktop.
Delete single product by product ID
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