diff --git a/src/shared/custom-validation.ts b/src/shared/custom-validation.ts index a920e717e08a6981f5f2e82ddc5cf237ecddba11..13b96372e0b76a2897364baa15562edf383a2d81 100644 --- a/src/shared/custom-validation.ts +++ b/src/shared/custom-validation.ts @@ -30,3 +30,23 @@ export class RoleValidation implements ValidatorConstraintInterface { return 'Not valid uuid'; } } + +// checks for valid JSON for center +@ValidatorConstraint({ name: 'centerJSON', async: true }) +export class CenterJSON implements ValidatorConstraintInterface { + validate(center: JSON, args: ValidationArguments) { + const validator = new Validator(); + return ( + validator.isNumber(center['lat']) && + validator.isNumber(center['lng']) && + validator.min(center['lat'], -90) && + validator.max(center['lat'], 90) && + validator.min(center['lng'], -180) && + validator.max(center['lng'], 180) + ); + } + + defaultMessage(args: ValidationArguments) { + return 'Error with center JSON'; + } +}