Skip to content

Instantly share code, notes, and snippets.

@paulobunga
Created December 18, 2019 00:24
Show Gist options
  • Save paulobunga/51324f94431075eb4b97d723b7c388e7 to your computer and use it in GitHub Desktop.
Save paulobunga/51324f94431075eb4b97d723b7c388e7 to your computer and use it in GitHub Desktop.
Update single product using product ID
module.exports.updateProduct = async (req, res, next) => {
Product.findOneAndUpdate(
{ _id: req.params.productId },
{
name: req.body.name,
sale_price: req.body.sale_price,
cost_price: req.body.cost_price,
quantity: req.body.quantity,
}
).exec((error, result) => {
if (error) {
res.json({ status: 'ERROR', message: 'Error updating product' });
}
if (result) {
res.json({
status: 'SUCCESS',
message: 'Product details updated successfully',
});
} else {
res.json({
status: 'FAILURE',
message: 'Failed to update product details',
});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment