c2-mongoose 2.1.143 → 2.1.144

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.
@@ -18,7 +18,6 @@ declare abstract class SearchFlow {
18
18
  buildProjections(): any;
19
19
  buildProjectionNested(projectCurrent: any, field: string, include: boolean): any;
20
20
  buildPopulate(): any;
21
- buildPopulateArray(): void;
22
21
  buildPath(target: string, nested?: string): any;
23
22
  buildOrdenation(): any;
24
23
  buildRegex(searchText: string): RegExp;
@@ -64,7 +64,7 @@ var SearchFlow = /** @class */ (function () {
64
64
  this.limit = Number(params.limit || 25);
65
65
  this.pageable = params.pageable == false || params.pageable == 'false' ? false : true;
66
66
  this.projection = this.buildProjections();
67
- this.buildPopulate();
67
+ this.populate = this.buildPopulate();
68
68
  this.buildOrdenation();
69
69
  }
70
70
  SearchFlow.prototype.buildProjections = function () {
@@ -81,7 +81,6 @@ var SearchFlow = /** @class */ (function () {
81
81
  return projection;
82
82
  };
83
83
  SearchFlow.prototype.buildProjectionNested = function (projectCurrent, field, include) {
84
- // var projectionAux: { [key: string]: any } = {}
85
84
  var _a = field.split('.'), first = _a[0], rest = _a.slice(1);
86
85
  if (rest.length === 0) {
87
86
  projectCurrent[first] = include ? 1 : 0;
@@ -94,22 +93,14 @@ var SearchFlow = /** @class */ (function () {
94
93
  if ((0, Utils_1.isEmpty)(this.populate)) {
95
94
  return;
96
95
  }
97
- if (Array.isArray(this.populate)) {
98
- return this.buildPopulateArray();
96
+ if (!Array.isArray(this.populate)) {
97
+ return;
99
98
  }
100
- var propertiesArray = this.populate.toString().split(',');
101
- var populates = [];
102
- for (var _i = 0, propertiesArray_1 = propertiesArray; _i < propertiesArray_1.length; _i++) {
103
- var property = propertiesArray_1[_i];
104
- var _a = property.split('.'), first = _a[0], rest = _a.slice(1);
105
- var nested = rest.join('.');
106
- populates.push(this.buildPath(first, nested));
107
- }
108
- this.populate = populates;
109
- };
110
- SearchFlow.prototype.buildPopulateArray = function () {
111
99
  var populates = [];
112
100
  var _loop_1 = function () {
101
+ if (property.include(".")) {
102
+ return "continue";
103
+ }
113
104
  var _b = property.split('.'), first = _b[0], rest = _b.slice(1);
114
105
  var nested = rest.join('.');
115
106
  var populate = this_1.buildPath(first, nested);
@@ -124,7 +115,7 @@ var SearchFlow = /** @class */ (function () {
124
115
  var property = _a[_i];
125
116
  _loop_1();
126
117
  }
127
- this.populate = populates;
118
+ return populates;
128
119
  };
129
120
  SearchFlow.prototype.buildPath = function (target, nested) {
130
121
  if (nested === void 0) { nested = ""; }
@@ -265,9 +256,7 @@ var SearchFlow = /** @class */ (function () {
265
256
  {
266
257
  $facet: facet
267
258
  },
268
- ]).session(options === null || options === void 0 ? void 0 : options.session)
269
- // var items = result[0].items
270
- ];
259
+ ]).session(options === null || options === void 0 ? void 0 : options.session)];
271
260
  case 1:
272
261
  result = _d.sent();
273
262
  if (!((0, Utils_1.isNotEmpty)(this.populate) && Array.isArray(this.populate))) return [3 /*break*/, 5];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.143",
3
+ "version": "2.1.144",
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",
@@ -26,7 +26,7 @@ abstract class SearchFlow {
26
26
  this.limit = Number(params.limit || 25)
27
27
  this.pageable = params.pageable == false || params.pageable == 'false' ? false : true
28
28
  this.projection = this.buildProjections()
29
- this.buildPopulate()
29
+ this.populate = this.buildPopulate()
30
30
  this.buildOrdenation()
31
31
  }
32
32
 
@@ -49,7 +49,6 @@ abstract class SearchFlow {
49
49
  }
50
50
 
51
51
  buildProjectionNested(projectCurrent: any, field: string, include: boolean) {
52
- // var projectionAux: { [key: string]: any } = {}
53
52
  let [first, ...rest] = field.split('.')
54
53
 
55
54
  if (rest.length === 0) {
@@ -64,34 +63,20 @@ abstract class SearchFlow {
64
63
  return projectCurrent
65
64
  }
66
65
 
67
-
68
-
69
-
70
-
71
-
72
66
  public buildPopulate(): any {
73
67
  if (isEmpty(this.populate)) {
74
68
  return
75
69
  }
76
70
 
77
- if (Array.isArray(this.populate)) {
78
- return this.buildPopulateArray()
79
- }
80
-
81
- var propertiesArray = (this.populate as string).toString().split(',')
82
- var populates = [] as any
83
- for (var property of propertiesArray) {
84
- let [first, ...rest] = property.split('.')
85
- let nested = rest.join('.')
86
- populates.push(this.buildPath(first, nested))
71
+ if (!Array.isArray(this.populate)) {
72
+ return
87
73
  }
88
74
 
89
- this.populate = populates
90
- }
91
-
92
- buildPopulateArray() {
93
75
  var populates = [] as any
94
76
  for (var property of this.populate) {
77
+ if (property.include(".")) {
78
+ continue
79
+ }
95
80
  let [first, ...rest] = property.split('.')
96
81
  let nested = rest.join('.')
97
82
  let populate = this.buildPath(first, nested)
@@ -102,7 +87,7 @@ abstract class SearchFlow {
102
87
  populates.push(populate)
103
88
  }
104
89
 
105
- this.populate = populates
90
+ return populates
106
91
  }
107
92
 
108
93
  public buildPath(target: string, nested: string = "") {
@@ -245,8 +230,6 @@ abstract class SearchFlow {
245
230
  facet[metadata.id] = metadata.conditions
246
231
  }
247
232
 
248
-
249
-
250
233
  const result = await model.aggregate(
251
234
  [
252
235
  {
@@ -255,8 +238,6 @@ abstract class SearchFlow {
255
238
  ]
256
239
  ).session(options?.session as ClientSession)
257
240
 
258
- // var items = result[0].items
259
-
260
241
  if (isNotEmpty(this.populate) && Array.isArray(this.populate)) {
261
242
  for (var populate of this.populate) {
262
243
  result[0].items = await model.populate(result[0].items, populate)