c2-mongoose 2.0.5 → 2.0.6

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.
@@ -3,11 +3,11 @@ import SearchFlow from "./SearchFlow";
3
3
  declare class CrudFlow<D> extends SearchFlow {
4
4
  private repository;
5
5
  constructor(repository: mongoose.Model<any>, model?: any);
6
- create: (data: any, session?: any) => Promise<any[]>;
7
- delete: (id: string, session?: any) => Promise<void>;
8
- update: (id: string, data: D, session?: any) => Promise<D>;
9
- find: (search: SearchFlow) => Promise<SearchResponse<D>>;
10
- getOne: (model: D, params?: any) => Promise<D>;
11
- get: (id: string, pop?: string, sel?: string) => Promise<D>;
6
+ create(data: any, session?: any): Promise<any[]>;
7
+ delete(id: string, session?: any): Promise<void>;
8
+ update(id: string, data: D, session?: any): Promise<D>;
9
+ find(search: SearchFlow): Promise<SearchResponse<D>>;
10
+ getOne(model: D, params?: any): Promise<D>;
11
+ get(id: string, pop?: string, sel?: string): Promise<D>;
12
12
  }
13
13
  export default CrudFlow;
@@ -60,84 +60,86 @@ var CrudFlow = /** @class */ (function (_super) {
60
60
  function CrudFlow(repository, model) {
61
61
  if (model === void 0) { model = {}; }
62
62
  var _this = _super.call(this, model) || this;
63
- _this.create = function (data, session) {
64
- if (session === void 0) { session = undefined; }
65
- return __awaiter(_this, void 0, void 0, function () {
66
- return __generator(this, function (_a) {
67
- switch (_a.label) {
68
- case 0: return [4 /*yield*/, this.repository.create([data], { session: session })];
69
- case 1: return [2 /*return*/, _a.sent()];
70
- }
71
- });
63
+ _this.repository = repository;
64
+ return _this;
65
+ }
66
+ CrudFlow.prototype.create = function (data, session) {
67
+ if (session === void 0) { session = undefined; }
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ return __generator(this, function (_a) {
70
+ switch (_a.label) {
71
+ case 0: return [4 /*yield*/, this.repository.create([data], { session: session })];
72
+ case 1: return [2 /*return*/, _a.sent()];
73
+ }
72
74
  });
73
- };
74
- _this.delete = function (id, session) {
75
- if (session === void 0) { session = undefined; }
76
- return __awaiter(_this, void 0, void 0, function () {
77
- return __generator(this, function (_a) {
78
- switch (_a.label) {
79
- case 0: return [4 /*yield*/, this.repository.findByIdAndRemove(id, { session: session })];
80
- case 1:
81
- _a.sent();
82
- return [2 /*return*/];
83
- }
84
- });
75
+ });
76
+ };
77
+ CrudFlow.prototype.delete = function (id, session) {
78
+ if (session === void 0) { session = undefined; }
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0: return [4 /*yield*/, this.repository.findByIdAndRemove(id, { session: session })];
83
+ case 1:
84
+ _a.sent();
85
+ return [2 /*return*/];
86
+ }
85
87
  });
86
- };
87
- _this.update = function (id, data, session) {
88
- if (session === void 0) { session = undefined; }
89
- return __awaiter(_this, void 0, void 0, function () {
90
- var dataAfter;
91
- return __generator(this, function (_a) {
92
- switch (_a.label) {
93
- case 0: return [4 /*yield*/, this.repository.findByIdAndUpdate(id, { $set: data }, { returnDocument: 'after', session: session })];
94
- case 1:
95
- dataAfter = _a.sent();
96
- return [2 /*return*/, dataAfter];
97
- }
98
- });
88
+ });
89
+ };
90
+ CrudFlow.prototype.update = function (id, data, session) {
91
+ if (session === void 0) { session = undefined; }
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ var dataAfter;
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0: return [4 /*yield*/, this.repository.findByIdAndUpdate(id, { $set: data }, { returnDocument: 'after', session: session })];
97
+ case 1:
98
+ dataAfter = _a.sent();
99
+ return [2 /*return*/, dataAfter];
100
+ }
99
101
  });
100
- };
101
- _this.find = function (search) { return __awaiter(_this, void 0, void 0, function () {
102
+ });
103
+ };
104
+ CrudFlow.prototype.find = function (search) {
105
+ return __awaiter(this, void 0, void 0, function () {
102
106
  return __generator(this, function (_a) {
103
107
  switch (_a.label) {
104
108
  case 0: return [4 /*yield*/, search.search(this.repository)];
105
109
  case 1: return [2 /*return*/, _a.sent()];
106
110
  }
107
111
  });
108
- }); };
109
- _this.getOne = function (model, params) {
110
- if (params === void 0) { params = {}; }
111
- return __awaiter(_this, void 0, void 0, function () {
112
- var data;
113
- return __generator(this, function (_a) {
114
- switch (_a.label) {
115
- case 0: return [4 /*yield*/, _super.prototype.findOne.call(this, this.repository, model, params)];
116
- case 1:
117
- data = _a.sent();
118
- return [2 /*return*/, data];
119
- }
120
- });
112
+ });
113
+ };
114
+ CrudFlow.prototype.getOne = function (model, params) {
115
+ if (params === void 0) { params = {}; }
116
+ return __awaiter(this, void 0, void 0, function () {
117
+ var data;
118
+ return __generator(this, function (_a) {
119
+ switch (_a.label) {
120
+ case 0: return [4 /*yield*/, _super.prototype.findOne.call(this, this.repository, model, params)];
121
+ case 1:
122
+ data = _a.sent();
123
+ return [2 /*return*/, data];
124
+ }
121
125
  });
122
- };
123
- _this.get = function (id, pop, sel) {
124
- if (pop === void 0) { pop = ""; }
125
- if (sel === void 0) { sel = ""; }
126
- return __awaiter(_this, void 0, void 0, function () {
127
- var data;
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0: return [4 /*yield*/, this.repository.findById(id).populate(pop).select(sel)];
131
- case 1:
132
- data = _a.sent();
133
- return [2 /*return*/, data];
134
- }
135
- });
126
+ });
127
+ };
128
+ CrudFlow.prototype.get = function (id, pop, sel) {
129
+ if (pop === void 0) { pop = ""; }
130
+ if (sel === void 0) { sel = ""; }
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var data;
133
+ return __generator(this, function (_a) {
134
+ switch (_a.label) {
135
+ case 0: return [4 /*yield*/, this.repository.findById(id).populate(pop).select(sel)];
136
+ case 1:
137
+ data = _a.sent();
138
+ return [2 /*return*/, data];
139
+ }
136
140
  });
137
- };
138
- _this.repository = repository;
139
- return _this;
140
- }
141
+ });
142
+ };
141
143
  return CrudFlow;
142
144
  }(SearchFlow_1.default));
143
145
  exports.default = CrudFlow;
@@ -9,19 +9,19 @@ declare abstract class SearchFlow {
9
9
  populate: string | [] | any;
10
10
  filters: any;
11
11
  constructor(params: any);
12
- buildPopulate: () => any;
13
- buildPath: (target: string, nested?: string) => any;
14
- buildOrdenation: () => any;
12
+ buildPopulate(): any;
13
+ buildPath(target: string, nested?: string): any;
14
+ buildOrdenation(): any;
15
15
  private isPageable;
16
- diacriticSensitiveRegex: (string?: string) => string;
17
- search: (model: mongoose.Model<any>) => Promise<SearchResponse<any>>;
16
+ diacriticSensitiveRegex(string?: string): string;
17
+ search(model: mongoose.Model<any>): Promise<SearchResponse<any>>;
18
18
  private searchPageable;
19
19
  private searchNoPageable;
20
20
  private result;
21
- count: (model: mongoose.Model<any>) => Promise<number>;
21
+ count(model: mongoose.Model<any>): Promise<number>;
22
22
  findOne(repository: mongoose.Model<any>, model: any, params?: any): Promise<any>;
23
- sumBy: (model: mongoose.Model<any>, _sum: any, _by: any) => Promise<any[]>;
24
- buildDefaultFilters: (objectSearch: any) => any;
25
- addFilterModel: (model: any, filters: any) => void;
23
+ sumBy(model: mongoose.Model<any>, _sum: any, _by: any): Promise<any[]>;
24
+ buildDefaultFilters(objectSearch: any): any;
25
+ addFilterModel(model: any, filters: any): void;
26
26
  }
27
27
  export default SearchFlow;
@@ -52,37 +52,6 @@ var Utils_1 = require("../utils/Utils");
52
52
  var SearchFlow = /** @class */ (function () {
53
53
  function SearchFlow(params) {
54
54
  var _this = this;
55
- this.buildPopulate = function () {
56
- if ((0, Utils_1.isEmpty)(_this.populate)) {
57
- return;
58
- }
59
- var propertiesArray = _this.populate.split(',');
60
- var populates = [];
61
- for (var _i = 0, propertiesArray_1 = propertiesArray; _i < propertiesArray_1.length; _i++) {
62
- var property = propertiesArray_1[_i];
63
- var _a = property.split('.'), first = _a[0], rest = _a.slice(1);
64
- var nested = rest.join('.');
65
- populates.push(_this.buildPath(first, nested));
66
- }
67
- _this.populate = populates;
68
- };
69
- this.buildPath = function (target, nested) {
70
- if (nested === void 0) { nested = ""; }
71
- var populate = {};
72
- populate.path = target;
73
- if ((0, Utils_1.isNotEmpty)(nested)) {
74
- var _a = nested.split('.'), first = _a[0], rest = _a.slice(1);
75
- var nested2 = rest.join('.');
76
- populate.populate = _this.buildPath(first, nested2);
77
- }
78
- return populate;
79
- };
80
- this.buildOrdenation = function () {
81
- var order = {};
82
- _this.orderBy = _this.orderBy || "_id";
83
- order[_this.orderBy] = _this.order === "desc" ? -1 : 1;
84
- return order;
85
- };
86
55
  this.isPageable = function () {
87
56
  if ((0, Utils_1.isEmpty)(_this.page)) {
88
57
  _this.page = 1;
@@ -92,28 +61,6 @@ var SearchFlow = /** @class */ (function () {
92
61
  }
93
62
  return false;
94
63
  };
95
- this.diacriticSensitiveRegex = function (string) {
96
- if (string === void 0) { string = ""; }
97
- return string
98
- .replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
99
- .replace(/[e|é|ë|è|E|É|Ë|È]/g, '[e,é,ë,è,E,É,Ë,È]')
100
- .replace(/[i|í|ï|ì|I|Í|Ï|Ì]/g, '[i,í,ï,ì,I,Í,Ï,Ì]')
101
- .replace(/[o|ó|ö|ò|õ|O|Ó|Ö|Ô|Õ]/g, '[o,ó,ö,ò,õ,O,Ó,Ö,Ô,Õ]')
102
- .replace(/[u|ü|ú|ù|U|Ú|Ü|Ù]/g, '[u,ü,ú,ù,U,Ú,Ü,Ù]')
103
- .replace(/[ç|Ç|c|C]/g, '[c,C,ç,Ç]');
104
- };
105
- this.search = function (model) { return __awaiter(_this, void 0, void 0, function () {
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0:
109
- if (!this.isPageable()) return [3 /*break*/, 2];
110
- return [4 /*yield*/, this.searchPageable(model)];
111
- case 1: return [2 /*return*/, _a.sent()];
112
- case 2: return [4 /*yield*/, this.searchNoPageable(model)];
113
- case 3: return [2 /*return*/, _a.sent()];
114
- }
115
- });
116
- }); };
117
64
  this.searchPageable = function (model) { return __awaiter(_this, void 0, void 0, function () {
118
65
  var sort, items;
119
66
  return __generator(this, function (_a) {
@@ -135,7 +82,72 @@ var SearchFlow = /** @class */ (function () {
135
82
  }
136
83
  });
137
84
  }); };
138
- this.searchNoPageable = function (model) { return __awaiter(_this, void 0, void 0, function () {
85
+ this.searchText = params.searchText || "";
86
+ this.order = params.order || "asc";
87
+ this.orderBy = params.orderBy || "_id";
88
+ this.select = params.select;
89
+ this.populate = params.populate;
90
+ this.page = params.page || undefined;
91
+ this.limit = params.limit || 25;
92
+ this.buildPopulate();
93
+ }
94
+ SearchFlow.prototype.buildPopulate = function () {
95
+ if ((0, Utils_1.isEmpty)(this.populate)) {
96
+ return;
97
+ }
98
+ var propertiesArray = this.populate.split(',');
99
+ var populates = [];
100
+ for (var _i = 0, propertiesArray_1 = propertiesArray; _i < propertiesArray_1.length; _i++) {
101
+ var property = propertiesArray_1[_i];
102
+ var _a = property.split('.'), first = _a[0], rest = _a.slice(1);
103
+ var nested = rest.join('.');
104
+ populates.push(this.buildPath(first, nested));
105
+ }
106
+ this.populate = populates;
107
+ };
108
+ SearchFlow.prototype.buildPath = function (target, nested) {
109
+ if (nested === void 0) { nested = ""; }
110
+ var populate = {};
111
+ populate.path = target;
112
+ if ((0, Utils_1.isNotEmpty)(nested)) {
113
+ var _a = nested.split('.'), first = _a[0], rest = _a.slice(1);
114
+ var nested2 = rest.join('.');
115
+ populate.populate = this.buildPath(first, nested2);
116
+ }
117
+ return populate;
118
+ };
119
+ SearchFlow.prototype.buildOrdenation = function () {
120
+ var order = {};
121
+ this.orderBy = this.orderBy || "_id";
122
+ order[this.orderBy] = this.order === "desc" ? -1 : 1;
123
+ return order;
124
+ };
125
+ SearchFlow.prototype.diacriticSensitiveRegex = function (string) {
126
+ if (string === void 0) { string = ""; }
127
+ return string
128
+ .replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
129
+ .replace(/[e|é|ë|è|E|É|Ë|È]/g, '[e,é,ë,è,E,É,Ë,È]')
130
+ .replace(/[i|í|ï|ì|I|Í|Ï|Ì]/g, '[i,í,ï,ì,I,Í,Ï,Ì]')
131
+ .replace(/[o|ó|ö|ò|õ|O|Ó|Ö|Ô|Õ]/g, '[o,ó,ö,ò,õ,O,Ó,Ö,Ô,Õ]')
132
+ .replace(/[u|ü|ú|ù|U|Ú|Ü|Ù]/g, '[u,ü,ú,ù,U,Ú,Ü,Ù]')
133
+ .replace(/[ç|Ç|c|C]/g, '[c,C,ç,Ç]');
134
+ };
135
+ SearchFlow.prototype.search = function (model) {
136
+ return __awaiter(this, void 0, void 0, function () {
137
+ return __generator(this, function (_a) {
138
+ switch (_a.label) {
139
+ case 0:
140
+ if (!this.isPageable()) return [3 /*break*/, 2];
141
+ return [4 /*yield*/, this.searchPageable(model)];
142
+ case 1: return [2 /*return*/, _a.sent()];
143
+ case 2: return [4 /*yield*/, this.searchNoPageable(model)];
144
+ case 3: return [2 /*return*/, _a.sent()];
145
+ }
146
+ });
147
+ });
148
+ };
149
+ SearchFlow.prototype.searchNoPageable = function (model) {
150
+ return __awaiter(this, void 0, void 0, function () {
139
151
  var sort, items;
140
152
  return __generator(this, function (_a) {
141
153
  switch (_a.label) {
@@ -153,8 +165,10 @@ var SearchFlow = /** @class */ (function () {
153
165
  return [2 /*return*/, this.result(model, items)];
154
166
  }
155
167
  });
156
- }); };
157
- this.result = function (model, items) { return __awaiter(_this, void 0, void 0, function () {
168
+ });
169
+ };
170
+ SearchFlow.prototype.result = function (model, items) {
171
+ return __awaiter(this, void 0, void 0, function () {
158
172
  var total, paging, searchResponse;
159
173
  return __generator(this, function (_a) {
160
174
  switch (_a.label) {
@@ -171,16 +185,34 @@ var SearchFlow = /** @class */ (function () {
171
185
  return [2 /*return*/, searchResponse];
172
186
  }
173
187
  });
174
- }); };
175
- this.count = function (model) { return __awaiter(_this, void 0, void 0, function () {
188
+ });
189
+ };
190
+ SearchFlow.prototype.count = function (model) {
191
+ return __awaiter(this, void 0, void 0, function () {
176
192
  return __generator(this, function (_a) {
177
193
  switch (_a.label) {
178
194
  case 0: return [4 /*yield*/, model.countDocuments(this.filters).exec()];
179
195
  case 1: return [2 /*return*/, _a.sent()];
180
196
  }
181
197
  });
182
- }); };
183
- this.sumBy = function (model, _sum, _by) { return __awaiter(_this, void 0, void 0, function () {
198
+ });
199
+ };
200
+ SearchFlow.prototype.findOne = function (repository, model, params) {
201
+ if (params === void 0) { params = {}; }
202
+ return __awaiter(this, void 0, void 0, function () {
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0: return [4 /*yield*/, repository.findOne(model)
206
+ .sort(params.sort)
207
+ .select(params.select)
208
+ .populate(params.populate)];
209
+ case 1: return [2 /*return*/, _a.sent()];
210
+ }
211
+ });
212
+ });
213
+ };
214
+ SearchFlow.prototype.sumBy = function (model, _sum, _by) {
215
+ return __awaiter(this, void 0, void 0, function () {
184
216
  var ret;
185
217
  return __generator(this, function (_a) {
186
218
  switch (_a.label) {
@@ -201,77 +233,55 @@ var SearchFlow = /** @class */ (function () {
201
233
  return [2 /*return*/, ret];
202
234
  }
203
235
  });
204
- }); };
205
- this.buildDefaultFilters = function (objectSearch) {
206
- var filters = { $and: [] };
207
- Object.entries(objectSearch).forEach(function (_a) {
208
- var key = _a[0], value = _a[1];
209
- if ((0, Utils_1.isNotEmpty)(value)) {
210
- var condition = {};
211
- if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'searchText'].includes(key)) {
212
- return;
236
+ });
237
+ };
238
+ SearchFlow.prototype.buildDefaultFilters = function (objectSearch) {
239
+ var filters = { $and: [] };
240
+ Object.entries(objectSearch).forEach(function (_a) {
241
+ var key = _a[0], value = _a[1];
242
+ if ((0, Utils_1.isNotEmpty)(value)) {
243
+ var condition = {};
244
+ if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'searchText'].includes(key)) {
245
+ return;
246
+ }
247
+ if (key.endsWith('DateRange')) {
248
+ var keyAux = key.replace('Range', '');
249
+ var values = value;
250
+ if ((0, Utils_1.isNotEmpty)(values[0])) {
251
+ condition[keyAux] = __assign(__assign({}, condition[keyAux]), { $gte: new Date(values[0]) });
213
252
  }
214
- if (key.endsWith('DateRange')) {
215
- var keyAux = key.replace('Range', '');
216
- var values = value;
217
- if ((0, Utils_1.isNotEmpty)(values[0])) {
218
- condition[keyAux] = __assign(__assign({}, condition[keyAux]), { $gte: new Date(values[0]) });
219
- }
220
- if ((0, Utils_1.isNotEmpty)(values[1])) {
221
- condition[keyAux] = __assign(__assign({}, condition[keyAux]), { $lte: new Date(values[1]) });
222
- }
253
+ if ((0, Utils_1.isNotEmpty)(values[1])) {
254
+ condition[keyAux] = __assign(__assign({}, condition[keyAux]), { $lte: new Date(values[1]) });
223
255
  }
224
- else {
225
- if (!Array.isArray(value)) {
226
- condition[key] = value;
227
- }
228
- else {
229
- condition[key] = { $in: value };
230
- }
256
+ }
257
+ else {
258
+ if (!Array.isArray(value)) {
259
+ condition[key] = value;
231
260
  }
232
- if ((0, Utils_1.isNotEmpty)(condition)) {
233
- filters.$and.push(condition);
261
+ else {
262
+ condition[key] = { $in: value };
234
263
  }
235
264
  }
236
- });
237
- if ((0, Utils_1.isNotEmpty)(objectSearch.model)) {
238
- _this.addFilterModel(objectSearch.model, filters);
239
- }
240
- if (filters.$and.length === 0)
241
- delete filters['$and'];
242
- return filters;
243
- };
244
- this.addFilterModel = function (model, filters) {
245
- Object.entries(model).forEach(function (_a) {
246
- var key = _a[0], value = _a[1];
247
- if ((0, Utils_1.isNotEmpty)(value)) {
248
- var condition = {};
249
- condition[key] = value;
265
+ if ((0, Utils_1.isNotEmpty)(condition)) {
250
266
  filters.$and.push(condition);
251
267
  }
252
- });
253
- };
254
- this.searchText = params.searchText || "";
255
- this.order = params.order || "asc";
256
- this.orderBy = params.orderBy || "_id";
257
- this.select = params.select;
258
- this.populate = params.populate;
259
- this.page = params.page || undefined;
260
- this.limit = params.limit || 25;
261
- this.buildPopulate();
262
- }
263
- SearchFlow.prototype.findOne = function (repository, model, params) {
264
- if (params === void 0) { params = {}; }
265
- return __awaiter(this, void 0, void 0, function () {
266
- return __generator(this, function (_a) {
267
- switch (_a.label) {
268
- case 0: return [4 /*yield*/, repository.findOne(model)
269
- .sort(params.sort)
270
- .select(params.select)
271
- .populate(params.populate)];
272
- case 1: return [2 /*return*/, _a.sent()];
273
- }
274
- });
268
+ }
269
+ });
270
+ if ((0, Utils_1.isNotEmpty)(objectSearch.model)) {
271
+ this.addFilterModel(objectSearch.model, filters);
272
+ }
273
+ if (filters.$and.length === 0)
274
+ delete filters['$and'];
275
+ return filters;
276
+ };
277
+ SearchFlow.prototype.addFilterModel = function (model, filters) {
278
+ Object.entries(model).forEach(function (_a) {
279
+ var key = _a[0], value = _a[1];
280
+ if ((0, Utils_1.isNotEmpty)(value)) {
281
+ var condition = {};
282
+ condition[key] = value;
283
+ filters.$and.push(condition);
284
+ }
275
285
  });
276
286
  };
277
287
  return SearchFlow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
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",
@@ -10,29 +10,29 @@ class CrudFlow<D> extends SearchFlow {
10
10
  this.repository = repository
11
11
  }
12
12
 
13
- public create = async (data: any, session: any = undefined) => {
13
+ public async create(data: any, session: any = undefined) {
14
14
  return await this.repository.create([data], { session })
15
15
  }
16
16
 
17
- public delete = async (id: string, session: any = undefined) => {
17
+ public async delete(id: string, session: any = undefined) {
18
18
  await this.repository.findByIdAndRemove(id, { session })
19
19
  }
20
20
 
21
- public update = async (id: string, data: D, session: any = undefined): Promise<D> => {
21
+ public async update(id: string, data: D, session: any = undefined): Promise<D> {
22
22
  const dataAfter = await this.repository.findByIdAndUpdate(id, { $set: data as any }, { returnDocument: 'after', session })
23
23
  return dataAfter as D
24
24
  }
25
25
 
26
- public find = async (search: SearchFlow): Promise<SearchResponse<D>> => {
26
+ public async find(search: SearchFlow): Promise<SearchResponse<D>> {
27
27
  return await search.search(this.repository)
28
28
  }
29
29
 
30
- public getOne = async (model: D, params: any = {}): Promise<D> => {
30
+ public async getOne(model: D, params: any = {}): Promise<D> {
31
31
  const data = await super.findOne(this.repository, model, params)
32
32
  return data as D
33
33
  }
34
34
 
35
- public get = async (id: string, pop = "", sel = ""): Promise<D> => {
35
+ public async get(id: string, pop = "", sel = ""): Promise<D> {
36
36
  const data = await this.repository.findById(id).populate(pop).select(sel)
37
37
  return data as D
38
38
  }
@@ -23,7 +23,7 @@ abstract class SearchFlow {
23
23
  this.buildPopulate()
24
24
  }
25
25
 
26
- public buildPopulate = (): any => {
26
+ public buildPopulate(): any {
27
27
  if (isEmpty(this.populate)) {
28
28
  return
29
29
  }
@@ -38,7 +38,7 @@ abstract class SearchFlow {
38
38
  this.populate = populates
39
39
  }
40
40
 
41
- public buildPath = (target: string, nested: string = "") => {
41
+ public buildPath(target: string, nested: string = "") {
42
42
  var populate = {} as any
43
43
  populate.path = target
44
44
  if (isNotEmpty(nested)) {
@@ -49,7 +49,7 @@ abstract class SearchFlow {
49
49
  return populate
50
50
  }
51
51
 
52
- public buildOrdenation = () => {
52
+ public buildOrdenation() {
53
53
  let order = {} as any
54
54
  this.orderBy = this.orderBy || "_id"
55
55
  order[this.orderBy] = this.order === "desc" ? -1 : 1
@@ -68,7 +68,7 @@ abstract class SearchFlow {
68
68
  return false
69
69
  }
70
70
 
71
- public diacriticSensitiveRegex = (string: string = ""): string => {
71
+ public diacriticSensitiveRegex(string: string = ""): string {
72
72
  return string
73
73
  .replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
74
74
  .replace(/[e|é|ë|è|E|É|Ë|È]/g, '[e,é,ë,è,E,É,Ë,È]')
@@ -78,7 +78,7 @@ abstract class SearchFlow {
78
78
  .replace(/[ç|Ç|c|C]/g, '[c,C,ç,Ç]')
79
79
  }
80
80
 
81
- public search = async (model: mongoose.Model<any>): Promise<SearchResponse<any>> => {
81
+ public async search(model: mongoose.Model<any>): Promise<SearchResponse<any>> {
82
82
  if (this.isPageable()) {
83
83
  return await this.searchPageable(model)
84
84
  }
@@ -101,7 +101,7 @@ abstract class SearchFlow {
101
101
  return this.result(model, items)
102
102
  }
103
103
 
104
- private searchNoPageable = async (model: mongoose.Model<any>): Promise<SearchResponse<any>> => {
104
+ private async searchNoPageable(model: mongoose.Model<any>): Promise<SearchResponse<any>> {
105
105
  const sort = this.buildOrdenation()
106
106
  var items = await model
107
107
  .find(this.filters, this.select)
@@ -114,7 +114,7 @@ abstract class SearchFlow {
114
114
  return this.result(model, items)
115
115
  }
116
116
 
117
- private result = async (model: mongoose.Model<any>, items: []): Promise<SearchResponse<any>> => {
117
+ private async result(model: mongoose.Model<any>, items: []): Promise<SearchResponse<any>> {
118
118
  var total = await this.count(model)
119
119
 
120
120
  var paging: Paging = {}
@@ -129,7 +129,7 @@ abstract class SearchFlow {
129
129
  return searchResponse
130
130
  }
131
131
 
132
- public count = async (model: mongoose.Model<any>): Promise<number> => {
132
+ public async count(model: mongoose.Model<any>): Promise<number> {
133
133
  return await model.countDocuments(this.filters).exec()
134
134
  }
135
135
 
@@ -140,7 +140,7 @@ abstract class SearchFlow {
140
140
  .populate(params.populate)
141
141
  }
142
142
 
143
- public sumBy = async (model: mongoose.Model<any>, _sum: any, _by: any): Promise<any[]> => {
143
+ public async sumBy(model: mongoose.Model<any>, _sum: any, _by: any): Promise<any[]> {
144
144
  const ret = await model.aggregate(
145
145
  [
146
146
  {
@@ -158,7 +158,7 @@ abstract class SearchFlow {
158
158
  return ret
159
159
  }
160
160
 
161
- public buildDefaultFilters = (objectSearch: any) => {
161
+ public buildDefaultFilters(objectSearch: any) {
162
162
  let filters = { $and: [] } as any
163
163
  Object.entries(objectSearch).forEach(([key, value]) => {
164
164
  if (isNotEmpty(value)) {
@@ -208,7 +208,7 @@ abstract class SearchFlow {
208
208
  return filters
209
209
  }
210
210
 
211
- public addFilterModel = (model: any, filters: any) => {
211
+ public addFilterModel(model: any, filters: any) {
212
212
  Object.entries(model).forEach(([key, value]) => {
213
213
  if (isNotEmpty(value)) {
214
214
  let condition = {} as any