c2-mongoose 2.1.74 → 2.1.76

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.
@@ -15,7 +15,9 @@ declare abstract class SearchFlow {
15
15
  [key: string]: number;
16
16
  } | undefined;
17
17
  constructor(params: any);
18
- buildProjections(): any;
18
+ buildProjections(): {
19
+ [key: string]: number;
20
+ } | undefined;
19
21
  buildPopulate(): any;
20
22
  buildPopulateArray(): void;
21
23
  buildPath(target: string, nested?: string): any;
@@ -109,14 +109,18 @@ var SearchFlow = /** @class */ (function () {
109
109
  if (!Array.isArray(this.select)) {
110
110
  return undefined;
111
111
  }
112
- var projection = undefined;
112
+ var projection = {};
113
+ var found = false;
113
114
  for (var _i = 0, _a = this.select; _i < _a.length; _i++) {
114
115
  var field = _a[_i];
115
- if (!field.indexOf(".")) {
116
+ if (field.indexOf(".") < 0) {
116
117
  projection[field] = 1;
118
+ found = true;
117
119
  }
118
120
  }
119
- return projection;
121
+ if (found)
122
+ return projection;
123
+ return undefined;
120
124
  };
121
125
  SearchFlow.prototype.buildPopulate = function () {
122
126
  if ((0, Utils_1.isEmpty)(this.populate)) {
@@ -191,7 +195,7 @@ var SearchFlow = /** @class */ (function () {
191
195
  stagesItems = __spreadArray([
192
196
  { $match: this.filters },
193
197
  { $sort: this.sort },
194
- { $skip: (this.page - 1) * this.limit },
198
+ { $skip: ((this.page - 1) * this.limit) || 0 },
195
199
  { $limit: this.limit },
196
200
  this.projection ? { $project: this.projection } : { $addFields: {} }
197
201
  ], options.pipelines, true);
@@ -204,7 +208,7 @@ var SearchFlow = /** @class */ (function () {
204
208
  { $count: "total" },
205
209
  {
206
210
  $addFields: {
207
- page: this.page,
211
+ page: this.page || 1,
208
212
  limit: this.limit
209
213
  }
210
214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.74",
3
+ "version": "2.1.76",
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",
@@ -36,14 +36,18 @@ abstract class SearchFlow {
36
36
  return undefined
37
37
  }
38
38
 
39
- let projection: any = undefined
39
+ let projection: { [key: string]: number } = {}
40
+ let found = false
40
41
  for (var field of this.select) {
41
- if (!field.indexOf(".")) {
42
+ if (field.indexOf(".") < 0) {
42
43
  projection[field] = 1
44
+ found = true
43
45
  }
44
46
  }
45
47
 
46
- return projection
48
+ if (found)
49
+ return projection;
50
+ return undefined
47
51
  }
48
52
 
49
53
  public buildPopulate(): any {
@@ -115,7 +119,7 @@ abstract class SearchFlow {
115
119
  let stagesItems = [
116
120
  { $match: this.filters },
117
121
  { $sort: this.sort },
118
- { $skip: (this.page - 1) * this.limit },
122
+ { $skip: ((this.page - 1) * this.limit) || 0 },
119
123
  { $limit: this.limit },
120
124
  this.projection ? { $project: this.projection } : { $addFields: {} },
121
125
  ...options.pipelines
@@ -132,7 +136,7 @@ abstract class SearchFlow {
132
136
  {
133
137
  $addFields:
134
138
  {
135
- page: this.page,
139
+ page: this.page || 1,
136
140
  limit: this.limit
137
141
  }
138
142
  }