Last active
January 26, 2023 21:11
-
-
Save pauloendoh/f7d3194bae2ff121e78ce45589bd4ab2 to your computer and use it in GitHub Desktop.
Wrapper decorators for class-validators and class-transformer's "Expose", so we can exclude extra fields without adding "Expose" on every field
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
import { Expose } from 'class-transformer' | |
import { | |
IsArray, | |
IsDateString, | |
IsNumber, | |
IsNumberString, | |
IsString, | |
} from 'class-validator' | |
type IsStringParams = Parameters<typeof IsString> | |
export function IsStringExpose(...options: IsStringParams) { | |
return function (target: any, key: string) { | |
Expose()(target, key) | |
IsString(...options)(target, key) | |
} | |
} | |
export function IsDateStringExpose(...options: IsDateStringParams) { | |
return function (target: any, key: string) { | |
Expose()(target, key) | |
IsDateString(...options)(target, key) | |
} | |
} | |
type IsDateStringParams = Parameters<typeof IsDateString> | |
// create a wrapper for IsNumberString and Expose | |
type IsNumberStringParams = Parameters<typeof IsNumberString> | |
export function IsNumberStringExpose(...options: IsNumberStringParams) { | |
return function (target: any, key: string) { | |
Expose()(target, key) | |
IsNumberString(...options)(target, key) | |
} | |
} | |
// create a wrapper for IsArray and Expose | |
type IsArrayParams = Parameters<typeof IsArray> | |
export function IsArrayExpose(...options: IsArrayParams) { | |
return function (target: any, key: string) { | |
Expose()(target, key) | |
IsArray(...options)(target, key) | |
} | |
} | |
// create a wrapper for IsNumber and Expose | |
type IsNumberParams = Parameters<typeof IsNumber> | |
export function IsNumberExpose(...options: IsNumberParams) { | |
return function (target: any, key: string) { | |
Expose()(target, key) | |
IsNumber(...options)(target, key) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment