c2-mongoose 2.1.9 → 2.1.11

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.
@@ -13,5 +13,6 @@ declare class CrudFlow<D> {
13
13
  find(): Promise<SearchResponse<D>>;
14
14
  getOne(model: D, params?: any): Promise<D>;
15
15
  get(id: string, pop?: string, sel?: string, session?: ClientSession): Promise<D>;
16
+ sumBy(fieldToSum: string, fieldToGroup: string): Promise<any>;
16
17
  }
17
18
  export default CrudFlow;
@@ -134,6 +134,16 @@ var CrudFlow = /** @class */ (function () {
134
134
  });
135
135
  });
136
136
  };
137
+ CrudFlow.prototype.sumBy = function (fieldToSum, fieldToGroup) {
138
+ return __awaiter(this, void 0, void 0, function () {
139
+ return __generator(this, function (_a) {
140
+ switch (_a.label) {
141
+ case 0: return [4 /*yield*/, this.search.sumBy(this.repository, fieldToSum, fieldToGroup)];
142
+ case 1: return [2 /*return*/, _a.sent()];
143
+ }
144
+ });
145
+ });
146
+ };
137
147
  return CrudFlow;
138
148
  }());
139
149
  exports.default = CrudFlow;
@@ -241,7 +241,7 @@ var SearchFlow = /** @class */ (function () {
241
241
  var key = _a[0], value = _a[1];
242
242
  if ((0, Utils_1.isNotEmpty)(value)) {
243
243
  var condition = {};
244
- if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'searchText'].includes(key)) {
244
+ if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
245
245
  return;
246
246
  }
247
247
  if (key.endsWith('DateRange')) {
@@ -256,7 +256,6 @@ var SearchFlow = /** @class */ (function () {
256
256
  filters.$and.push(condition);
257
257
  }
258
258
  else if (key.endsWith('Like')) {
259
- console.log(key);
260
259
  var keyAux = key.replace('Like', '');
261
260
  condition[keyAux] = { $regex: value, $options: 'i' };
262
261
  filters.$and.push(condition);
@@ -282,6 +281,15 @@ var SearchFlow = /** @class */ (function () {
282
281
  SearchFlow.prototype.addFilterModel = function (model, filters) {
283
282
  Object.entries(model).forEach(function (_a) {
284
283
  var key = _a[0], value = _a[1];
284
+ if (key.endsWith('DateRange')) {
285
+ return;
286
+ }
287
+ if (key.endsWith('Like')) {
288
+ return;
289
+ }
290
+ if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
291
+ return;
292
+ }
285
293
  if ((0, Utils_1.isNotEmpty)(value)) {
286
294
  var condition = {};
287
295
  condition[key] = value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.9",
3
+ "version": "2.1.11",
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",
@@ -46,6 +46,10 @@ class CrudFlow<D> {
46
46
  const data = await this.repository.findById(id).populate(pop).select(sel).session(session!)
47
47
  return data as D
48
48
  }
49
+
50
+ public async sumBy(fieldToSum: string, fieldToGroup: string): Promise<any> {
51
+ return await this.search.sumBy(this.repository, fieldToSum, fieldToGroup)
52
+ }
49
53
  }
50
54
 
51
55
  export default CrudFlow
@@ -165,7 +165,7 @@ abstract class SearchFlow {
165
165
  Object.entries(objectSearch).forEach(([key, value]) => {
166
166
  if (isNotEmpty(value)) {
167
167
  let condition = {} as any
168
- if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'searchText'].includes(key)) {
168
+ if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
169
169
  return
170
170
  }
171
171
 
@@ -187,7 +187,6 @@ abstract class SearchFlow {
187
187
  }
188
188
  filters.$and.push(condition)
189
189
  } else if (key.endsWith('Like')) {
190
- console.log(key)
191
190
  var keyAux = key.replace('Like', '')
192
191
  condition[keyAux] = { $regex: value as any, $options: 'i' }
193
192
  filters.$and.push(condition)
@@ -215,6 +214,15 @@ abstract class SearchFlow {
215
214
 
216
215
  public addFilterModel(model: any, filters: any) {
217
216
  Object.entries(model).forEach(([key, value]) => {
217
+ if (key.endsWith('DateRange')) {
218
+ return
219
+ }
220
+ if (key.endsWith('Like')) {
221
+ return
222
+ }
223
+ if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
224
+ return
225
+ }
218
226
  if (isNotEmpty(value)) {
219
227
  let condition = {} as any
220
228
  condition[key] = value