Hi, guys Iam button developer :))) now starting wi...
# orm-help
a
Hi, guys Iam button developer :))) now starting with BE. Come to an issue with prisma ? How do I validate if f.e
req.body
is empty ? after POST call Is there a best practice for express api project structure ? cannot find any diffrent then all routes in index.ts
n
Hey Adam 👋 Welcome to Prisma’s Slack! If you want to use a third-party library then lodash has methods like isEmpty which will check if an object is empty or not. In this case you can check
Copy code
_.isEmpty(req.body)
This will return
true
if req.body is empty. Another way could be by checking if there are any keys in the object, if there are none then it would mean that the
req.body
is empty.
Copy code
if (Object.keys(req.body).length === 0) {
   // Body is empty
}
a
Cool @Nurul but i dont wnat to do this in every regest ? also is there a way how to reg.send 400 with error f.e
"title is missing"
n
You could use middlewares for this, which framework are you using to create your APIs?
a
I am actaully just starting -> but planning to use Express. Let me clarify my question: is there a way how to validate the payload i know there is smth like express validator: but i would have to descripe the rules from schema again. is there a way how to validate payload and take advatge of already written prisma.schema