feat: add decorator to check if two properties match
See original GitHub issueFirst of all, thanks for the awesome validation solution! I use class-validator in my NestJS setup. Now I want to know if and how it is possible to check if two values match with eachother. Let’s say I have a dto
setup like this:
export class UserCreateDto {
@IsString()
@IsNotEmpty()
firstName: string;
@IsEmail()
emailAddress: string;
@DoesMatch(o => o.emailAddress === o.emailAddressConfirm) // <---- check if email's match
@IsEmail()
emailAddressConfirm: string;
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:17
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Is it possible to validate that one of 2 parameters are present ...
First, you must add a custom validation class (read document) and then define a custom decorator for that (read document).
Read more >PythonDecoratorLibrary - Python Wiki
This page is meant to be a central repository of decorator code pieces, whether useful or not <wink>. It is NOT a page...
Read more >The @property Decorator in Python: Its Use Cases ...
2️⃣ Intro to Decorators It lets us add new functionality to an existing function without modifying it. Let's analyze these elements in detail:...
Read more >Python Property Decorator - GeeksforGeeks
Which is used to return the property attributes of a class from the stated getter, setter and deleter as parameters. Now, lets see...
Read more >API — Flask Documentation (2.2.x)
Once it is created it will act as a central registry for the view functions, the URL rules, ... you should create it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi! I am posting there the solution I found to implement this control. It refers to my question/answer on StackOverflow. I am going to provide a suitable solution for this particular issue.
user-create.dto.ts
match.decorator.ts
I managed to solve a similar problem on my personal project. Hope it helps!
@mrpharderwijk and @pieromacaluso, it’s works for me. Thanks!!
Full code: