Created
December 18, 2019 00:05
-
-
Save paulobunga/631e2a1dc4f26973fd02b8fb1fa4d130 to your computer and use it in GitHub Desktop.
Code for creating a single product
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.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