Skip to content

Instantly share code, notes, and snippets.

@zemd
Created February 21, 2023 19:50
Show Gist options
  • Save zemd/e065ad2e689e35bdd52ce680072d229c to your computer and use it in GitHub Desktop.
Save zemd/e065ad2e689e35bdd52ce680072d229c to your computer and use it in GitHub Desktop.
class-validator compose
// import {validate, IsEmail, MinLength} from "class-validator";
//
// const EmailProperty = createProperty(
// IsEmail({host_blacklist: ["example.com"]}, {message: "EMAIL IS NOT VALID."}),
// MinLength(40)
// );
//
// class User {
// @EmailProperty()
// email?: string;
// }
//
// await validate(new User());
export const createProperty = (
...validators: PropertyDecorator[]
) => {
return () => {
return function (object: Object, propertyName: string) {
validators.forEach((validator) => {
validator(object, propertyName);
});
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment