c2-mongoose 2.1.18 → 2.1.20

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
  }
@@ -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];
@@ -253,11 +253,17 @@ var SearchFlow = /** @class */ (function () {
253
253
  var values = value;
254
254
  if ((0, Utils_1.isNotEmpty)(values[0])) {
255
255
  var momentValue = (0, moment_1.default)(values[0]);
256
- condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $gte: momentValue.toDate().setHours(0, 0, 0) });
256
+ momentValue.hour(0);
257
+ momentValue.minute(0);
258
+ momentValue.second(0);
259
+ condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $gte: momentValue.toDate() });
257
260
  }
258
261
  if ((0, Utils_1.isNotEmpty)(values[1])) {
259
262
  var momentValue = (0, moment_1.default)(values[1]);
260
- condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $lte: momentValue.toDate().setHours(23, 59, 59) });
263
+ momentValue.hour(23);
264
+ momentValue.minute(59);
265
+ momentValue.second(59);
266
+ condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $lte: momentValue.toDate() });
261
267
  }
262
268
  filters.$and.push(condition);
263
269
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.18",
3
+ "version": "2.1.20",
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"
@@ -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
 
@@ -175,17 +175,23 @@ abstract class SearchFlow {
175
175
  var values = value as any
176
176
  if (isNotEmpty(values[0])) {
177
177
  var momentValue = moment(values[0])
178
+ momentValue.hour(0)
179
+ momentValue.minute(0)
180
+ momentValue.second(0)
178
181
  condition[fieldName] = {
179
182
  ...condition[fieldName],
180
- $gte: momentValue.toDate().setHours(0, 0, 0)
183
+ $gte: momentValue.toDate()
181
184
  }
182
185
  }
183
186
 
184
187
  if (isNotEmpty(values[1])) {
185
188
  var momentValue = moment(values[1])
189
+ momentValue.hour(23)
190
+ momentValue.minute(59)
191
+ momentValue.second(59)
186
192
  condition[fieldName] = {
187
193
  ...condition[fieldName],
188
- $lte: momentValue.toDate().setHours(23, 59, 59)
194
+ $lte: momentValue.toDate()
189
195
  }
190
196
  }
191
197
  filters.$and.push(condition)