c2-mongoose 2.1.246 → 2.1.247

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.
@@ -16,15 +16,14 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
16
16
  function BuildPopulateSingleFlowItem() {
17
17
  }
18
18
  BuildPopulateSingleFlowItem.prototype.buildPopulate = function (model, populatesStr, selectsStr) {
19
- var _a;
20
19
  var populateArray = [];
21
20
  if ((0, Utils_1.isEmpty)(populatesStr)) {
22
21
  return [];
23
22
  }
24
23
  var _loop_1 = function () {
25
- var _b = property.split('.'), first = _b[0], rest = _b.slice(1);
24
+ var _a = property.split('.'), first = _a[0], rest = _a.slice(1);
26
25
  var nested = rest.join('.');
27
- var existing2 = (_a = populateArray.find(function (populateAux) { return populateAux.path === first; })) !== null && _a !== void 0 ? _a : { path: '', populate: {} };
26
+ var existing2 = populateArray.find(function (populateAux) { return populateAux.path === first; });
28
27
  var populateLocal = this_1.buildPath(first, nested, existing2);
29
28
  //EXISTE UMA LIMITACAO DE SELECT A PARTIR DO 3 NIVEL DENTRO DOS CAMPO POPULATE, MELHORAR O CODIGO ABAIXO PARA PERCORRER MAIS NIVEIS
30
29
  if (Array.isArray(selectsStr)) {
@@ -62,8 +61,11 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
62
61
  };
63
62
  BuildPopulateSingleFlowItem.prototype.buildPath = function (target, nested, populateAcc) {
64
63
  // var populate = {} as IPopulate
65
- var _a, _b;
64
+ var _a;
66
65
  if (nested === void 0) { nested = ""; }
66
+ if (populateAcc === undefined) {
67
+ populateAcc = {};
68
+ }
67
69
  if (populateAcc.path === undefined) {
68
70
  populateAcc.path = target;
69
71
  }
@@ -72,9 +74,9 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
72
74
  populateAcc.path = populateAcc.path.trim();
73
75
  }
74
76
  if ((0, Utils_1.isNotEmpty)(nested)) {
75
- var _c = nested.split('.'), first = _c[0], rest = _c.slice(1);
77
+ var _b = nested.split('.'), first = _b[0], rest = _b.slice(1);
76
78
  var nested2 = rest.join('.');
77
- populateAcc.populate = __assign(__assign({}, populateAcc.populate), this.buildPath(first, nested2, (_b = populateAcc.populate) !== null && _b !== void 0 ? _b : {}));
79
+ populateAcc.populate = __assign(__assign({}, populateAcc.populate), this.buildPath(first, nested2, populateAcc.populate));
78
80
  }
79
81
  return populateAcc;
80
82
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.246",
3
+ "version": "2.1.247",
4
4
  "description": "Lib to make any search in database mongoose and use as basic crud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,7 +14,7 @@ class BuildPopulateSingleFlowItem {
14
14
  let [first, ...rest] = property.split('.')
15
15
  let nested = rest.join('.')
16
16
 
17
- const existing2 = populateArray.find((populateAux: IPopulate) => populateAux.path === first) ?? { path: '', populate: {} }
17
+ const existing2 = populateArray.find((populateAux: IPopulate) => populateAux.path === first)
18
18
 
19
19
  let populateLocal = this.buildPath(first, nested, existing2 as IPopulate)
20
20
 
@@ -55,6 +55,10 @@ class BuildPopulateSingleFlowItem {
55
55
  public buildPath(target: string, nested: string = "", populateAcc: IPopulate): IPopulate {
56
56
  // var populate = {} as IPopulate
57
57
 
58
+ if (populateAcc === undefined) {
59
+ populateAcc = {} as IPopulate
60
+ }
61
+
58
62
  if (populateAcc.path === undefined) {
59
63
  populateAcc.path = target
60
64
  } else if (!populateAcc.path?.includes(target)){
@@ -67,7 +71,7 @@ class BuildPopulateSingleFlowItem {
67
71
  let nested2 = rest.join('.')
68
72
  populateAcc.populate = {
69
73
  ...populateAcc.populate,
70
- ...this.buildPath(first, nested2, populateAcc.populate ?? {})
74
+ ...this.buildPath(first, nested2, populateAcc.populate)
71
75
  }
72
76
  }
73
77
  return populateAcc