Product create - Test I was able to create a category, however when creating a product i tested it out using postman and got error: \"\", then i added the code which requires al
why not console log on every req i.e for example
exports.productById = (req, res, next, id) => {
console.log(req.body);
};
exports.read = (req, res) => {
console.log(req.body);
};
exports.create = (req, res) => {
console.log(req.body);
};
exports.remove = (req, res) => {
console.log(req.body);
};
you will get a clear picture whether your request are actually received by your backend.
your problem is on setting content type in postman. you send form-data to the server but your server not decoded it. by default, your server gets x-www-form-urlencoded and if you set postman on x-www-form-urlencoded your problem is gone. you must use form-data for upload file
if (
!name ||
!description ||
!price ||
!category ||
!quantity ||
!shipping
) {
return res.status(400).json({
error: "All fields are required"
});
}
you are sending shipping false from postman , obviously it will return that 400 status, make it :
if (
!name ||
!description ||
!price ||
!category ||
!quantity ||
shipping!== true || shipping !==false //something like that(or use something from formidable)
) {
return res.status(400).json({
error: "All fields are required"
});
}
```