hiteshchoudhary / chai-backend

A video series on chai aur code youtube channel
5.06k stars 760 forks source link

Register controller not throwing error if any of the required field is undefined #32

Open chinmay9389 opened 10 months ago

chinmay9389 commented 10 months ago

Where: if ( [fullName, email, username, password].some((field) => field?.trim() === "") ) { throw new ApiError(400, "All fields are required") } Expected behaviour -> When request body doesn't contain any of the field then it should throw error. Actual behaviour -> It is not able to catch the undefined field hence error is missing

Sameercode660 commented 9 months ago

bro please make sure that you user.model and the key that you are sending from postman as well as key that you are desctructuring from the req.body are same

Abdullah-irshad commented 9 months ago

just add (field) => field?.trim() === "" || typeof field === "undefined")