sigo-entities 0.0.128 → 0.0.130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -253,12 +253,24 @@ async function validateAndFormatData(data, dtoClass, propertiesToValidate) {
253
253
  );
254
254
  }
255
255
  const instance = (0, import_class_transformer2.plainToInstance)(dtoClass, data, { excludeExtraneousValues: true });
256
- const errors = await (0, import_class_validator2.validate)(instance, { skipMissingProperties: !!propertiesToValidate });
256
+ console.log(JSON.stringify(instance));
257
+ const errors = await (0, import_class_validator2.validate)(instance);
257
258
  console.log(errors);
258
259
  if (errors.length > 0) {
259
- const formattedErrors = formatErrors(errors);
260
- const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
261
- throw new Error(errorMessage);
260
+ if (propertiesToValidate) {
261
+ const property = errors.map((e) => e.property);
262
+ propertiesToValidate.forEach((element) => {
263
+ if (property.some((e) => e === element)) {
264
+ const errorsAux = errors.filter((e) => e.property === element);
265
+ const formattedErrors = formatErrors(errorsAux);
266
+ throw new Error(`Response validation failed: ${formattedErrors[0]}`);
267
+ }
268
+ });
269
+ } else {
270
+ const formattedErrors = formatErrors(errors);
271
+ const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
272
+ throw new Error(errorMessage);
273
+ }
262
274
  }
263
275
  if (propertiesToValidate) {
264
276
  const result = Object.fromEntries(
package/dist/index.mjs CHANGED
@@ -53,12 +53,24 @@ async function validateAndFormatData(data, dtoClass, propertiesToValidate) {
53
53
  );
54
54
  }
55
55
  const instance = plainToInstance(dtoClass, data, { excludeExtraneousValues: true });
56
- const errors = await validate(instance, { skipMissingProperties: !!propertiesToValidate });
56
+ console.log(JSON.stringify(instance));
57
+ const errors = await validate(instance);
57
58
  console.log(errors);
58
59
  if (errors.length > 0) {
59
- const formattedErrors = formatErrors(errors);
60
- const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
61
- throw new Error(errorMessage);
60
+ if (propertiesToValidate) {
61
+ const property = errors.map((e) => e.property);
62
+ propertiesToValidate.forEach((element) => {
63
+ if (property.some((e) => e === element)) {
64
+ const errorsAux = errors.filter((e) => e.property === element);
65
+ const formattedErrors = formatErrors(errorsAux);
66
+ throw new Error(`Response validation failed: ${formattedErrors[0]}`);
67
+ }
68
+ });
69
+ } else {
70
+ const formattedErrors = formatErrors(errors);
71
+ const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
72
+ throw new Error(errorMessage);
73
+ }
62
74
  }
63
75
  if (propertiesToValidate) {
64
76
  const result = Object.fromEntries(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sigo-entities",
3
- "version": "0.0.128",
3
+ "version": "0.0.130",
4
4
  "description": "Desarrollo de modelos de datos SIGO",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",