c2-mongoose 2.1.202 → 2.1.204

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.
@@ -96,7 +96,7 @@ var SearchFlow = /** @class */ (function () {
96
96
  return projectCurrent;
97
97
  };
98
98
  SearchFlow.prototype.buildPopulate = function () {
99
- var _a, _b;
99
+ var _a, _b, _c, _d;
100
100
  if ((0, Utils_1.isEmpty)(this.populate)) {
101
101
  return;
102
102
  }
@@ -105,7 +105,7 @@ var SearchFlow = /** @class */ (function () {
105
105
  }
106
106
  var populates = [];
107
107
  var _loop_1 = function () {
108
- var _d = property.split('.'), first = _d[0], rest = _d.slice(1);
108
+ var _f = property.split('.'), first = _f[0], rest = _f.slice(1);
109
109
  var nested = rest.join('.');
110
110
  var populate = this_1.buildPath(first, nested);
111
111
  if (Array.isArray(this_1.select)) {
@@ -117,15 +117,15 @@ var SearchFlow = /** @class */ (function () {
117
117
  }
118
118
  var existing = populates.find(function (populateAux) { return populateAux.path === populate.path; });
119
119
  if (existing !== undefined) {
120
- var populateAux = __assign(__assign({}, existing === null || existing === void 0 ? void 0 : existing.populate), { path: "".concat((_a = existing.populate) === null || _a === void 0 ? void 0 : _a.path, " ").concat((_b = populate.populate) === null || _b === void 0 ? void 0 : _b.path).trim() });
120
+ 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 = populate.populate) === null || _c === void 0 ? void 0 : _c.path) !== null && _d !== void 0 ? _d : "").trim() });
121
121
  existing.populate = populateAux;
122
122
  return "continue";
123
123
  }
124
124
  populates.push(populate);
125
125
  };
126
126
  var this_1 = this;
127
- for (var _i = 0, _c = this.populate; _i < _c.length; _i++) {
128
- var property = _c[_i];
127
+ for (var _i = 0, _e = this.populate; _i < _e.length; _i++) {
128
+ var property = _e[_i];
129
129
  _loop_1();
130
130
  }
131
131
  return populates;
@@ -256,7 +256,21 @@ var SearchFlow = /** @class */ (function () {
256
256
  }
257
257
  stagesPaging.push({ $match: this.filters });
258
258
  stagesPaging.push({ $count: "total" });
259
- stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } });
259
+ stagesPaging.push({
260
+ $addFields: {
261
+ page: this.page || 1,
262
+ limit: this.limit,
263
+ totalPages: {
264
+ $cond: {
265
+ if: { $eq: ['$total', 0] },
266
+ then: 0,
267
+ else: { $ceil: { $divide: ['$total', this.limit] } }
268
+ }
269
+ },
270
+ startIndex: { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit] },
271
+ endIndex: { $multiply: [this.page, this.limit] }
272
+ }
273
+ });
260
274
  stagesMetadata = [];
261
275
  if ((0, Utils_1.isNotEmpty)(options.metadata)) {
262
276
  stagesMetadata.push.apply(stagesMetadata, options.metadata);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.202",
3
+ "version": "2.1.204",
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",
@@ -103,7 +103,7 @@ abstract class SearchFlow {
103
103
  if (existing !== undefined) {
104
104
  const populateAux = {
105
105
  ...existing?.populate,
106
- path: `${(existing as IPopulate).populate?.path} ${populate.populate?.path}`.trim()
106
+ path: `${(existing as IPopulate).populate?.path ?? ``} ${populate.populate?.path ?? ``}`.trim()
107
107
  }
108
108
  existing.populate = populateAux
109
109
  continue
@@ -243,7 +243,22 @@ abstract class SearchFlow {
243
243
  }
244
244
  stagesPaging.push({ $match: this.filters })
245
245
  stagesPaging.push({ $count: "total" })
246
- stagesPaging.push({ $addFields: { page: this.page || 1, limit: this.limit } })
246
+ stagesPaging.push(
247
+ {
248
+ $addFields: {
249
+ page: this.page || 1,
250
+ limit: this.limit,
251
+ totalPages: {
252
+ $cond: {
253
+ if: { $eq: ['$total', 0] },
254
+ then: 0,
255
+ else: { $ceil: { $divide: ['$total', this.limit] } }
256
+ }
257
+ },
258
+ startIndex: { $subtract: [ { $multiply: [this.page, this.limit] }, this.limit ] },
259
+ endIndex: { $multiply: [this.page, this.limit] }
260
+ }
261
+ })
247
262
 
248
263
  let stagesMetadata: any[] = []
249
264
  if (isNotEmpty(options.metadata)) {