c2-mongoose 2.1.19 → 2.1.21

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.
@@ -1,4 +1,4 @@
1
- import mongoose from "mongoose";
1
+ import mongoose, { ClientSession } from "mongoose";
2
2
  import { SearchResponse } from "../types/SearchResponse";
3
3
  declare abstract class SearchFlow {
4
4
  searchText: string;
@@ -21,7 +21,7 @@ declare abstract class SearchFlow {
21
21
  private result;
22
22
  count(model: mongoose.Model<any>): Promise<number>;
23
23
  findOne(repository: mongoose.Model<any>, model: any, params?: any): Promise<any>;
24
- sumBy(model: mongoose.Model<any>, _sum: any, _by: any): Promise<any[]>;
24
+ sumBy(model: mongoose.Model<any>, _sum: any, _by: any, session?: ClientSession): Promise<any[]>;
25
25
  buildDefaultFilters(objectSearch: any): any;
26
26
  addFilterModel(model: any, filters: any): void;
27
27
  }
@@ -91,8 +91,8 @@ var SearchFlow = /** @class */ (function () {
91
91
  this.orderBy = params.orderBy || "_id";
92
92
  this.select = params.select;
93
93
  this.populate = params.populate;
94
- this.page = params.page || undefined;
95
- this.limit = params.limit || 25;
94
+ this.page = Number(params.page || undefined);
95
+ this.limit = Number(params.limit || 25);
96
96
  this.buildPopulate();
97
97
  }
98
98
  SearchFlow.prototype.buildPopulate = function () {
@@ -181,8 +181,8 @@ var SearchFlow = /** @class */ (function () {
181
181
  total = _a.sent();
182
182
  paging = {};
183
183
  paging.total = total;
184
- paging.page = this.page;
185
- paging.limit = this.limit;
184
+ paging.page = Number(this.page);
185
+ paging.limit = Number(this.limit);
186
186
  searchResponse = {};
187
187
  searchResponse.items = items;
188
188
  searchResponse.paging = paging;
@@ -215,7 +215,7 @@ var SearchFlow = /** @class */ (function () {
215
215
  });
216
216
  });
217
217
  };
218
- SearchFlow.prototype.sumBy = function (model, _sum, _by) {
218
+ SearchFlow.prototype.sumBy = function (model, _sum, _by, session) {
219
219
  return __awaiter(this, void 0, void 0, function () {
220
220
  var ret;
221
221
  return __generator(this, function (_a) {
@@ -231,7 +231,7 @@ var SearchFlow = /** @class */ (function () {
231
231
  count: { "$sum": 1 }
232
232
  }
233
233
  }
234
- ])];
234
+ ]).session(session)];
235
235
  case 1:
236
236
  ret = _a.sent();
237
237
  return [2 /*return*/, ret];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.19",
3
+ "version": "2.1.21",
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",
@@ -1,5 +1,5 @@
1
1
  import moment from "moment"
2
- import mongoose from "mongoose"
2
+ import mongoose, { ClientSession } from "mongoose"
3
3
  import { dbCollation } from "../configuration/Environment"
4
4
  import { Pagination, SearchResponse } from "../types/SearchResponse"
5
5
  import { isEmpty, isNotEmpty } from "../utils/Utils"
@@ -20,8 +20,8 @@ abstract class SearchFlow {
20
20
  this.orderBy = params.orderBy || "_id"
21
21
  this.select = params.select
22
22
  this.populate = params.populate
23
- this.page = params.page || undefined
24
- this.limit = params.limit || 25
23
+ this.page = Number(params.page || undefined)
24
+ this.limit = Number(params.limit || 25)
25
25
  this.buildPopulate()
26
26
  }
27
27
 
@@ -122,8 +122,8 @@ abstract class SearchFlow {
122
122
 
123
123
  var paging: Pagination = {}
124
124
  paging.total = total
125
- paging.page = this.page
126
- paging.limit = this.limit
125
+ paging.page = Number(this.page)
126
+ paging.limit = Number(this.limit)
127
127
 
128
128
  var searchResponse: SearchResponse<any> = {}
129
129
  searchResponse.items = items
@@ -143,7 +143,7 @@ abstract class SearchFlow {
143
143
  .populate(params.populate)
144
144
  }
145
145
 
146
- public async sumBy(model: mongoose.Model<any>, _sum: any, _by: any): Promise<any[]> {
146
+ public async sumBy(model: mongoose.Model<any>, _sum: any, _by: any, session?: ClientSession): Promise<any[]> {
147
147
  const ret = await model.aggregate(
148
148
  [
149
149
  {
@@ -157,7 +157,7 @@ abstract class SearchFlow {
157
157
  }
158
158
  }
159
159
  ]
160
- )
160
+ ).session(session!)
161
161
  return ret
162
162
  }
163
163