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 +16 -4
- package/dist/index.mjs +16 -4
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
56
|
+
console.log(JSON.stringify(instance));
|
|
57
|
+
const errors = await validate(instance);
|
|
57
58
|
console.log(errors);
|
|
58
59
|
if (errors.length > 0) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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(
|