Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty validation for articles #2

Closed
willianba opened this issue Aug 2, 2022 · 2 comments
Closed

Empty validation for articles #2

willianba opened this issue Aug 2, 2022 · 2 comments

Comments

@willianba
Copy link

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? 😄

@TasinIshmam
Copy link
Contributor

Hey @willianba

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

@willianba
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants