-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alireza bonab
committed
Mar 14, 2021
1 parent
0280fee
commit 67fc393
Showing
1 changed file
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,47 @@ | ||
# class-validator-is-compatible-with | ||
IsCompatibleWith is a decorator for class-validator that checks if siblings are not exist on object. | ||
# InCompatibleWith | ||
InCompatibleWith is a decorator for class-validator that checks if siblings are not exist on object. | ||
|
||
### Use case: | ||
|
||
InCompatibleWith checks if other properties exist on an object or not. | ||
In this case we want to have either `status` or `deleted` on the instance of class. If both exist it will complain. | ||
|
||
```typescript | ||
class UpdateUserDTO { | ||
@IsString() | ||
@IncompatibleWith(['deleted']) | ||
readonly status: string; | ||
|
||
@IsBoolean() | ||
@IncompatibleWith(['status']) | ||
readonly deleted: boolean; | ||
|
||
@IsString() | ||
readonly name: string; | ||
} | ||
``` | ||
|
||
|
||
### Invalid Object | ||
```json | ||
const obj = { | ||
status: 'test', | ||
deleted: true, | ||
name: 'john', | ||
}; | ||
``` | ||
|
||
### Valid Object | ||
```json | ||
const obj = { | ||
deleted: true, | ||
name: 'john', | ||
}; | ||
``` | ||
Or | ||
```json | ||
const obj = { | ||
status: 'test', | ||
name: 'john', | ||
}; | ||
``` |