@escapenavigator/utils 1.6.37 → 1.6.39

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.
@@ -5,12 +5,18 @@ const class_validator_1 = require("class-validator");
5
5
  function validateByDto(t) {
6
6
  const validate = (data) => {
7
7
  const errors = (0, class_validator_1.validateSync)(typeof data === 'object' ? data : {});
8
- console.log({ formErrors: errors });
9
- return Object.fromEntries(errors.map(({ property, constraints }) => {
10
- const err = constraints?.IsNotEmpty || Object.values(constraints)[0];
11
- const errorText = err.substr(err.indexOf(' ') + 1);
12
- return [property, `${t(`validationErrors:${errorText}`)}`];
13
- }));
8
+ const getErrors = (err = []) => err.reduce((acc, { property, constraints, children }) => {
9
+ if (children && typeof children === 'object' && children.length) {
10
+ return { ...acc, [property]: getErrors(children) };
11
+ }
12
+ const text = constraints?.IsNotEmpty || Object.values(constraints || {})[0];
13
+ const errorText = text.substr(text.indexOf(' ') + 1);
14
+ acc[property] = `${t(`validationErrors:${errorText}`)}`;
15
+ return acc;
16
+ }, {});
17
+ const res = getErrors(errors);
18
+ console.log(res);
19
+ return res;
14
20
  };
15
21
  return validate;
16
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escapenavigator/utils",
3
- "version": "1.6.37",
3
+ "version": "1.6.39",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,7 +14,7 @@
14
14
  "test": "jest"
15
15
  },
16
16
  "dependencies": {
17
- "@escapenavigator/types": "^1.6.37",
17
+ "@escapenavigator/types": "^1.6.39",
18
18
  "axios": "^0.21.4",
19
19
  "class-transformer": "^0.5.1",
20
20
  "class-validator": "^0.13.1",
@@ -55,5 +55,5 @@
55
55
  "node_modules"
56
56
  ]
57
57
  },
58
- "gitHead": "2d5a7df27a08c1d78c16df60decf4a37a5b84741"
58
+ "gitHead": "9789509165a0bd6ce223b5b735a52b556412731c"
59
59
  }