fix: rating type issues (#3638)

* fix: rating type issues

* fix: rebase

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Jérémy M
2024-01-30 09:57:30 +01:00
committed by GitHub
parent e7f2af6f0b
commit da8dd671d1
14 changed files with 137 additions and 43 deletions

View File

@ -0,0 +1,26 @@
import {
registerDecorator,
ValidationOptions,
ValidationArguments,
} 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: any) {
return typeof value === 'string' && graphQLEnumNameRegex.test(value);
},
defaultMessage(args: ValidationArguments) {
return `${args.property} must match the ${graphQLEnumNameRegex} format`;
},
},
});
};
}