[Feature] @IsOptionaIf()
See original GitHub issueIt would be nice if we could have conditional decorator for required/non-required properties.
Example use case:
I want to insert or update a record.
When inserting a new row the title is required, but when updating the releaseYear on existing row the title column is not required.
I could get around this by creating two different classes InsertRecordParameters and UpdateRecordParamaeters but it would be nice to have eveything in one class when insert and update do not differ in terms of the parameters used.
class SaveRecordParameters {
@IsOptional()
@IsPositive()
id?: number;
@IsOptionaIf( self => !!self.id )
@MaxLength(5)
@MinLength(50)
title?: string;
@IsOptional()
@IsNumber()
releaseYear?: number;
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
2021年04月_weixin_39829166的博客_CSDN博客
[Feature Request] Add support for UltiGCode. 2021-01-12. [Feature] @IsOptionaIf(). 2021-01-12 ... Feature Request: Automate the "I made one" on Thingiverse.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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

You can achieve this by creating your own decorator that wraps
@ValidateIf.Can someone make this PR merged?? this will be so helpful!!