sigo-entities 0.0.129 → 0.0.131
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 +15 -4
- package/dist/index.mjs +15 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -253,12 +253,23 @@ async function validateAndFormatData(data, dtoClass, propertiesToValidate) {
|
|
|
253
253
|
);
|
|
254
254
|
}
|
|
255
255
|
const instance = (0, import_class_transformer2.plainToInstance)(dtoClass, data, { excludeExtraneousValues: true });
|
|
256
|
+
console.log(JSON.stringify(instance));
|
|
256
257
|
const errors = await (0, import_class_validator2.validate)(instance);
|
|
257
|
-
console.log(errors);
|
|
258
258
|
if (errors.length > 0) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
if (propertiesToValidate) {
|
|
260
|
+
const property = errors.map((e) => e.property);
|
|
261
|
+
propertiesToValidate.forEach((element) => {
|
|
262
|
+
if (property.some((e) => e === element)) {
|
|
263
|
+
const errorsAux = errors.filter((e) => e.property === element);
|
|
264
|
+
const formattedErrors = formatErrors(errorsAux);
|
|
265
|
+
throw new Error(`Response validation failed: ${formattedErrors[0]}`);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
} else {
|
|
269
|
+
const formattedErrors = formatErrors(errors);
|
|
270
|
+
const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
|
|
271
|
+
throw new Error(errorMessage);
|
|
272
|
+
}
|
|
262
273
|
}
|
|
263
274
|
if (propertiesToValidate) {
|
|
264
275
|
const result = Object.fromEntries(
|
package/dist/index.mjs
CHANGED
|
@@ -53,12 +53,23 @@ async function validateAndFormatData(data, dtoClass, propertiesToValidate) {
|
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
55
|
const instance = plainToInstance(dtoClass, data, { excludeExtraneousValues: true });
|
|
56
|
+
console.log(JSON.stringify(instance));
|
|
56
57
|
const errors = await validate(instance);
|
|
57
|
-
console.log(errors);
|
|
58
58
|
if (errors.length > 0) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
if (propertiesToValidate) {
|
|
60
|
+
const property = errors.map((e) => e.property);
|
|
61
|
+
propertiesToValidate.forEach((element) => {
|
|
62
|
+
if (property.some((e) => e === element)) {
|
|
63
|
+
const errorsAux = errors.filter((e) => e.property === element);
|
|
64
|
+
const formattedErrors = formatErrors(errorsAux);
|
|
65
|
+
throw new Error(`Response validation failed: ${formattedErrors[0]}`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
const formattedErrors = formatErrors(errors);
|
|
70
|
+
const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
|
|
71
|
+
throw new Error(errorMessage);
|
|
72
|
+
}
|
|
62
73
|
}
|
|
63
74
|
if (propertiesToValidate) {
|
|
64
75
|
const result = Object.fromEntries(
|