ValidationSchemaToMetadataTransformer.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ValidationSchemaToMetadataTransformer = void 0;
  4. const ValidationMetadata_1 = require("../metadata/ValidationMetadata");
  5. /**
  6. * Used to transform validation schemas to validation metadatas.
  7. */
  8. class ValidationSchemaToMetadataTransformer {
  9. transform(schema) {
  10. const metadatas = [];
  11. Object.keys(schema.properties).forEach(property => {
  12. schema.properties[property].forEach(validation => {
  13. const validationOptions = {
  14. message: validation.message,
  15. groups: validation.groups,
  16. always: validation.always,
  17. each: validation.each,
  18. };
  19. const args = {
  20. type: validation.type,
  21. name: validation.name,
  22. target: schema.name,
  23. propertyName: property,
  24. constraints: validation.constraints,
  25. validationTypeOptions: validation.options,
  26. validationOptions: validationOptions,
  27. };
  28. metadatas.push(new ValidationMetadata_1.ValidationMetadata(args));
  29. });
  30. });
  31. return metadatas;
  32. }
  33. }
  34. exports.ValidationSchemaToMetadataTransformer = ValidationSchemaToMetadataTransformer;
  35. //# sourceMappingURL=ValidationSchemaToMetadataTransformer.js.map