From 67fc393f1575123c5c51e6159f54650f50544a83 Mon Sep 17 00:00:00 2001 From: alireza bonab Date: Sun, 14 Mar 2021 01:16:17 +0100 Subject: [PATCH] update readme --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 546c20e..00e2a28 100644 --- a/README.md +++ b/README.md @@ -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', +}; +``` \ No newline at end of file