c2-mongoose 2.1.240 → 2.1.242

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.
@@ -2,7 +2,7 @@ import mongoose from "mongoose";
2
2
  import { IPopulate } from "../SearcherFlow";
3
3
  declare class BuildPopulateSingleFlowItem {
4
4
  buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[];
5
- buildPath(target: string, nested?: string): IPopulate;
5
+ buildPath(target: string, nested: string | undefined, populateAcc: IPopulate): IPopulate;
6
6
  }
7
7
  declare const _default: BuildPopulateSingleFlowItem;
8
8
  export default _default;
@@ -16,15 +16,16 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
16
16
  function BuildPopulateSingleFlowItem() {
17
17
  }
18
18
  BuildPopulateSingleFlowItem.prototype.buildPopulate = function (model, populatesStr, selectsStr) {
19
- var _a, _b, _c, _d;
20
- var populate = [];
19
+ var _a;
20
+ var populateArray = [];
21
21
  if ((0, Utils_1.isEmpty)(populatesStr)) {
22
22
  return [];
23
23
  }
24
24
  var _loop_1 = function () {
25
- var _e = property.split('.'), first = _e[0], rest = _e.slice(1);
25
+ var _b = property.split('.'), first = _b[0], rest = _b.slice(1);
26
26
  var nested = rest.join('.');
27
- var populateLocal = this_1.buildPath(first, nested);
27
+ var existing2 = (_a = populateArray.find(function (populateAux) { return populateAux.path === first; })) !== null && _a !== void 0 ? _a : { path: '', populate: {} };
28
+ var populateLocal = this_1.buildPath(first, nested, existing2);
28
29
  //EXISTE UMA LIMITACAO DE SELECT A PARTIR DO 3 NIVEL DENTRO DOS CAMPO POPULATE, MELHORAR O CODIGO ABAIXO PARA PERCORRER MAIS NIVEIS
29
30
  if (Array.isArray(selectsStr)) {
30
31
  var allSelectOfPopulate = selectsStr.filter(function (sel) { return sel.startsWith("".concat(first, ".").concat(populateLocal.path)); });
@@ -35,31 +36,45 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
35
36
  }
36
37
  }
37
38
  //FIM
38
- var existing = populate.find(function (populateAux) { return populateAux.path === populateLocal.path; });
39
- if (existing) {
40
- var populateAux = __assign(__assign({}, existing === null || existing === void 0 ? void 0 : existing.populate), { path: "".concat((_b = (_a = existing.populate) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : "", " ").concat((_d = (_c = populateLocal.populate) === null || _c === void 0 ? void 0 : _c.path) !== null && _d !== void 0 ? _d : "").trim() });
41
- existing.populate = populateAux;
42
- return "continue";
43
- }
44
- populate.push(populateLocal);
39
+ // const existing = populateArray.find((populateAux: IPopulate) => populateAux.path === populateLocal.path)
40
+ // if (existing) {
41
+ // if (populateLocal.populate && existing.populate){
42
+ // if (!existing.populate.path.includes(populateLocal.populate.path)){
43
+ // existing.populate.path += populateLocal.populate.path
44
+ // }
45
+ // }
46
+ // const populateAux = {
47
+ // ...existing?.populate,
48
+ // path: `${existing.populate?.path ?? ``} ${populateLocal.populate?.path ?? ``}`.trim()
49
+ // }
50
+ // existing.populate = populateAux
51
+ // continue
52
+ // }
53
+ populateArray.push(populateLocal);
45
54
  };
46
55
  var this_1 = this;
47
56
  for (var _i = 0, populatesStr_1 = populatesStr; _i < populatesStr_1.length; _i++) {
48
57
  var property = populatesStr_1[_i];
49
58
  _loop_1();
50
59
  }
51
- return populate;
60
+ return populateArray;
52
61
  };
53
- BuildPopulateSingleFlowItem.prototype.buildPath = function (target, nested) {
62
+ BuildPopulateSingleFlowItem.prototype.buildPath = function (target, nested, populateAcc) {
63
+ // var populate = {} as IPopulate
64
+ var _a;
54
65
  if (nested === void 0) { nested = ""; }
55
- var populate = {};
56
- populate.path = target;
66
+ if (populateAcc.path === undefined) {
67
+ populateAcc.path = "";
68
+ }
69
+ else if (!((_a = populateAcc.path) === null || _a === void 0 ? void 0 : _a.includes(target))) {
70
+ populateAcc.path += " ".concat(target).trim();
71
+ }
57
72
  if ((0, Utils_1.isNotEmpty)(nested)) {
58
- var _a = nested.split('.'), first = _a[0], rest = _a.slice(1);
73
+ var _b = nested.split('.'), first = _b[0], rest = _b.slice(1);
59
74
  var nested2 = rest.join('.');
60
- populate.populate = this.buildPath(first, nested2);
75
+ populateAcc.populate = __assign(__assign({}, populateAcc.populate), this.buildPath(first, nested2, populateAcc.populate));
61
76
  }
62
- return populate;
77
+ return populateAcc;
63
78
  };
64
79
  return BuildPopulateSingleFlowItem;
65
80
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.240",
3
+ "version": "2.1.242",
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",
@@ -5,7 +5,7 @@ import { IPopulate } from "../SearcherFlow";
5
5
  class BuildPopulateSingleFlowItem {
6
6
 
7
7
  public buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[] {
8
- var populate = [] as IPopulate[]
8
+ var populateArray = [] as IPopulate[]
9
9
  if (isEmpty(populatesStr)) {
10
10
  return []
11
11
  }
@@ -14,7 +14,9 @@ class BuildPopulateSingleFlowItem {
14
14
  let [first, ...rest] = property.split('.')
15
15
  let nested = rest.join('.')
16
16
 
17
- let populateLocal = this.buildPath(first, nested)
17
+ const existing2 = populateArray.find((populateAux: IPopulate) => populateAux.path === first) ?? { path: '', populate: {} }
18
+
19
+ let populateLocal = this.buildPath(first, nested, existing2 as IPopulate)
18
20
 
19
21
  //EXISTE UMA LIMITACAO DE SELECT A PARTIR DO 3 NIVEL DENTRO DOS CAMPO POPULATE, MELHORAR O CODIGO ABAIXO PARA PERCORRER MAIS NIVEIS
20
22
  if (Array.isArray(selectsStr)) {
@@ -27,31 +29,47 @@ class BuildPopulateSingleFlowItem {
27
29
  }
28
30
  //FIM
29
31
 
30
- const existing = populate.find((populateAux: IPopulate) => populateAux.path === populateLocal.path)
31
- if (existing) {
32
- const populateAux = {
33
- ...existing?.populate,
34
- path: `${existing.populate?.path ?? ``} ${populateLocal.populate?.path ?? ``}`.trim()
35
- }
36
- existing.populate = populateAux
37
- continue
38
- }
32
+ // const existing = populateArray.find((populateAux: IPopulate) => populateAux.path === populateLocal.path)
33
+ // if (existing) {
34
+
35
+ // if (populateLocal.populate && existing.populate){
36
+ // if (!existing.populate.path.includes(populateLocal.populate.path)){
37
+ // existing.populate.path += populateLocal.populate.path
38
+ // }
39
+ // }
39
40
 
40
- populate.push(populateLocal)
41
+ // const populateAux = {
42
+ // ...existing?.populate,
43
+ // path: `${existing.populate?.path ?? ``} ${populateLocal.populate?.path ?? ``}`.trim()
44
+ // }
45
+ // existing.populate = populateAux
46
+ // continue
47
+ // }
48
+
49
+ populateArray.push(populateLocal)
41
50
  }
42
51
 
43
- return populate
52
+ return populateArray
44
53
  }
45
54
 
46
- public buildPath(target: string, nested: string = ""): IPopulate {
47
- var populate = {} as IPopulate
48
- populate.path = target
55
+ public buildPath(target: string, nested: string = "", populateAcc: IPopulate): IPopulate {
56
+ // var populate = {} as IPopulate
57
+
58
+ if (populateAcc.path === undefined) {
59
+ populateAcc.path = ``
60
+ } else if (!populateAcc.path?.includes(target)){
61
+ populateAcc.path += ` ${target}`.trim()
62
+ }
63
+
49
64
  if (isNotEmpty(nested)) {
50
65
  let [first, ...rest] = nested.split('.')
51
66
  let nested2 = rest.join('.')
52
- populate.populate = this.buildPath(first, nested2)
67
+ populateAcc.populate = {
68
+ ...populateAcc.populate,
69
+ ...this.buildPath(first, nested2, populateAcc.populate)
70
+ }
53
71
  }
54
- return populate
72
+ return populateAcc
55
73
  }
56
74
  }
57
75