Nodejs CRUD + Test using Postman

后端 未结 3 899

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

3条回答
  •  忘了有多久
    2021-01-27 15:28

     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"
                });
            }
        ```
    
    
    

提交回复
热议问题