Nestjs IsUnique custom validation (with database query) for email, username, etc
Vložit
- čas přidán 25. 07. 2023
- Let's implement IsUnique custom validation in Nestjs to check if a value (e.g. email, username, etc.) is unique or not, by querying the database.
Blog post: zestmade.com/blog/nestjs-uniq...
Git repository for the project: github.com/ZestArinze/nestjs-... - Věda a technologie
You are awesome
thank you man
it give me this error : "Nest can't resolve dependencies of the IsUniqueConstraint (?). Please make sure that the argument EntityManager at index [0] is available in the AppModule context." please help me
i am getting user table already exists error? What is the solution to resolve this problem?
Thanks, I was just looking for this and it works perfectly. One thing i am struggeling with now is how can i put this unique constarint test into the unit test?
Thanks! It's a very practical solution. Is there no risk of sql injection if we use this decorator?
The developer specifies (in the code) the table and column for the database query. Do not use user-supplied data as the table and/or column names.
Disclaimer: I suggest you kindly consult your security expert for this question you've asked here and all your other security-related concerns.
Happy coding.
I have a question if user want to update their name using the update endpoint that time is how to manage the uniqueness of the name.
if we use this validation then it will not allow to update the name because it will check the name is already exists or not.
so how to manage this situation.
In the DTO file there is always a pair of create and update files. Now you can choose to inherit the createDto file or rewrite it in updateDto
You figure it out? Im having the same issue
why it give me this error ?
ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'getRepository')
TypeError: Cannot read properties of undefined (reading 'getRepository')
Please check if in your main.ts file there is the line:
useContainer(app.select(AppModule), { fallbackOnErrors: true });
Also, ensure that the module containing your service is resolving the validator within the providers array.
@@guilhermealbino8737 I am getting user table already exists error? WHat is the solution to resolve this issue?