Created
December 18, 2019 00:24
-
-
Save paulobunga/51324f94431075eb4b97d723b7c388e7 to your computer and use it in GitHub Desktop.
Update single product using 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.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