Skip to content

Instantly share code, notes, and snippets.

@paulobunga
Created December 18, 2019 00:05
Show Gist options
  • Save paulobunga/631e2a1dc4f26973fd02b8fb1fa4d130 to your computer and use it in GitHub Desktop.
Save paulobunga/631e2a1dc4f26973fd02b8fb1fa4d130 to your computer and use it in GitHub Desktop.
Code for creating a single product
module.exports.createProduct = async (req, res, next) => {
const { name, sale_price, cost_price, quantity } = req.body;
const newProduct = new Product({
name,
sale_price,
cost_price,
quantity,
});
newProduct.save((error, result) => {
if (error) {
res.json({ status: 'ERROR', message: 'Error creating product' });
}
if (result) {
res.json({ status: 'SUCCESS', message: 'Product created' });
} else {
res.json({ status: 'FAILURE', message: 'Failed to create product' });
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment