Move composite types to twenty-shared (#15741)
This commit is contained in:
-26
@@ -1,26 +0,0 @@
|
||||
import {
|
||||
type ValidationArguments,
|
||||
type ValidationOptions,
|
||||
registerDecorator,
|
||||
} from 'class-validator';
|
||||
|
||||
const graphQLEnumNameRegex = /^[_A-Za-z][_0-9A-Za-z]*$/;
|
||||
|
||||
export function IsValidGraphQLEnumName(validationOptions?: ValidationOptions) {
|
||||
return function (object: object, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: 'isValidGraphQLEnumName',
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate(value: unknown) {
|
||||
return typeof value === 'string' && graphQLEnumNameRegex.test(value);
|
||||
},
|
||||
defaultMessage(args: ValidationArguments) {
|
||||
return `${args.property} must match the ${graphQLEnumNameRegex} format`;
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user