How to use the class-validator.validateSync function in class-validator

To help you get started, we’ve selected a few class-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NationalBankBelgium / stark / packages / stark-core / src / validation / decorators / is-isin / is-isin.validator.decorator.spec.ts View on Github external
it("should fail if isin is empty", () => {
		const errors: ValidationError[] = validateSync(myClass);

		expect(errors.length).toBe(1);
		expect(errors[0].constraints).toBeDefined();
		expect(errors[0].constraints[validatorConstraintName]).toBeDefined();
	});
github NationalBankBelgium / stark / packages / stark-core / src / validation / decorators / is-isin / is-isin.validator.decorator.spec.ts View on Github external
it("should fail if the object to validate is not a string", () => {
		const errors: ValidationError[] = validateSync(simpleClass);

		expect(errors.length).toBe(1);
		expect(errors[0].constraints).toBeDefined();
		expect(errors[0].constraints[validatorConstraintName]).toBeDefined();
	});
github NationalBankBelgium / stark / packages / stark-core / src / configuration / entities / application / app-config.entity.ts View on Github external
public addBackend(backend: StarkBackend): void {
		if (!backend) {
			throw new Error("A backend instance must be provided");
		}

		const backendInstance: StarkBackendImpl = backend instanceof StarkBackendImpl ? backend : Deserialize(backend, StarkBackendImpl);

		StarkValidationErrorsUtil.throwOnError(validateSync(backendInstance), "The backend instance provided is not valid.");

		this.backends.set(backend.name, backend);
	}
github rucken / todo-nestjs / src / libs / core / entities / content-type.entity.ts View on Github external
doBeforeUpdate() {
    const errors = validateSync(this, { validationError: { target: false } });
    if (errors.length > 0) {
      throw new CustomValidationError(errors);
    }
  }
}
github rucken / todo-nestjs / libs / rucken / todo-nestjs / src / migrations_entities / 1552133567377 / task.entity.ts View on Github external
doBeforeUpdate() {
    const errors = validateSync(this, { validationError: { target: false } });
    if (errors.length > 0) {
      throw new CustomValidationError(errors);
    }
  }
}
github rucken / core-nestjs / libs / rucken / auth-nestjs / src / entities / oauth-tokens-accesstoken.entity.ts View on Github external
doBeforeUpdate() {
    const errors = validateSync(this, { validationError: { target: false } });
    if (errors.length > 0) {
      throw new CustomValidationError(errors);
    }
  }
}
github rucken / todo-nestjs / libs / rucken / todo-nestjs / src / entities / project.entity.ts View on Github external
doBeforeUpdate() {
    const errors = validateSync(this, { validationError: { target: false } });
    if (errors.length > 0) {
      throw new CustomValidationError(errors);
    }
  }
}
github rucken / todo-nestjs / libs / rucken / todo-nestjs / src / migrations_entities / 1552133567377 / project.entity.ts View on Github external
doBeforeInsertion() {
    const errors = validateSync(this, { validationError: { target: false } });
    if (errors.length > 0) {
      throw new CustomValidationError(errors);
    }
  }
github EndyKaufman / nest-permissions-seed / src / libs / core / entities / group.entity.ts View on Github external
doBeforeUpdate() {
        const errors = validateSync(this, { validationError: { target: false } });
        if (errors.length > 0) {
            throw new CustomValidationError(errors)
        }
    }
}
github rucken / core-nestjs / libs / rucken / core-nestjs / src / entities / user.entity.ts View on Github external
doBeforeUpdate() {
    const errors = validateSync(this, { validationError: { target: false } });
    if (errors.length > 0) {
      throw new CustomValidationError(errors);
    }
  }