prisma/blog-backend-rest-api-nestjs-prisma

Empty validation for articles

willianba opened this issue ยท 2 comments

Hi @TasinIshmam!

I was following another tutorial on the blog and found yours, which is the newest one, and decided to follow along.

I want to raise a point and see what you think about it. The CreateArticleDto has the IsOptional() decorator in the description property, which means it validates if the field is present or not. Then you have the IsString() decorator to validate if the property is a string. But at any moment you're validating if the string is "valid" or not.

Generally, I (personally) like to also add an IsNotEmpty() decorator, to ignore "" (empty strings) values as well. This way you enforce that description is optional, but if present, it cannot be empty.

Not a really big problem, but it can avoid, in a big db table, for example, the need to write SELECT * FROM ARTICLES WHERE description IS NOT NULL AND description <> ''.

Any thoughts? ๐Ÿ˜„

Hey @willianba

This is a really good point, thanks for mentioning it. I'll modify the tutorial with these suggestions ๐Ÿ‘

great! thanks for the answer. looking forward to the next chapters!