c2-mongoose 2.1.269 → 2.1.274

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.
@@ -85,7 +85,7 @@ var C2Flow = /** @class */ (function () {
85
85
  case 0: return [4 /*yield*/, this.repository.create(data, { session: options.session })];
86
86
  case 1:
87
87
  dataAfter = _a.sent();
88
- if (options.logger === false) {
88
+ if (options.logger === false || (0, Utils_1.isEmpty)(dataAfter)) {
89
89
  return [2 /*return*/, dataAfter];
90
90
  }
91
91
  log = BuildLogFlowItem_1.default.build(options, dataAfter[0]._doc, Logger_1.TypeOfOperation.CREATE, this.repository);
@@ -109,7 +109,7 @@ var C2Flow = /** @class */ (function () {
109
109
  if ((0, Utils_1.isEmpty)(dataAfter)) {
110
110
  return [2 /*return*/, dataAfter];
111
111
  }
112
- return [2 /*return*/, dataAfter._doc];
112
+ return [2 /*return*/, dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter._doc];
113
113
  }
114
114
  if ((0, Utils_1.isEmpty)(dataAfter)) {
115
115
  return [2 /*return*/, dataAfter];
@@ -121,7 +121,7 @@ var C2Flow = /** @class */ (function () {
121
121
  if ((0, Utils_1.isEmpty)(dataAfter)) {
122
122
  return [2 /*return*/, dataAfter];
123
123
  }
124
- return [2 /*return*/, dataAfter._doc];
124
+ return [2 /*return*/, dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter._doc];
125
125
  }
126
126
  });
127
127
  });
@@ -138,7 +138,7 @@ var C2Flow = /** @class */ (function () {
138
138
  if ((0, Utils_1.isEmpty)(dataAfter)) {
139
139
  return [2 /*return*/, dataAfter];
140
140
  }
141
- return [2 /*return*/, dataAfter._doc];
141
+ return [2 /*return*/, dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter._doc];
142
142
  }
143
143
  if ((0, Utils_1.isEmpty)(dataAfter)) {
144
144
  return [2 /*return*/, dataAfter];
@@ -150,7 +150,7 @@ var C2Flow = /** @class */ (function () {
150
150
  if ((0, Utils_1.isEmpty)(dataAfter)) {
151
151
  return [2 /*return*/, dataAfter];
152
152
  }
153
- return [2 /*return*/, dataAfter._doc];
153
+ return [2 /*return*/, dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter._doc];
154
154
  }
155
155
  });
156
156
  });
@@ -224,7 +224,7 @@ var C2Flow = /** @class */ (function () {
224
224
  if (options.logger === false) {
225
225
  return [2 /*return*/];
226
226
  }
227
- log = BuildLogFlowItem_1.default.build(options, __assign({ _id: _id }, dataAfter._doc), Logger_1.TypeOfOperation.DELETE, this.repository);
227
+ log = BuildLogFlowItem_1.default.build(options, __assign({ _id: _id }, dataAfter === null || dataAfter === void 0 ? void 0 : dataAfter._doc), Logger_1.TypeOfOperation.DELETE, this.repository);
228
228
  return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
229
229
  case 2:
230
230
  _a.sent();
@@ -10,6 +10,7 @@ declare class SearcherFlow<D> {
10
10
  model: mongoose.Model<any>;
11
11
  [key: string]: any;
12
12
  searchText: string;
13
+ searchTextFields: string[];
13
14
  orderSense: string;
14
15
  orderBy: string;
15
16
  page: number;
@@ -67,6 +67,7 @@ var BuildSelectSingleFlowItem_1 = __importDefault(require("./item/BuildSelectSin
67
67
  var SearcherFlow = /** @class */ (function () {
68
68
  function SearcherFlow(repository) {
69
69
  this.searchText = "";
70
+ this.searchTextFields = [];
70
71
  this.orderSense = "desc";
71
72
  this.orderBy = "_id";
72
73
  this.page = 1;
@@ -213,7 +214,7 @@ var SearcherFlow = /** @class */ (function () {
213
214
  SearcherFlow.prototype.buildDefaultFilters = function (objectSearch) {
214
215
  var _this = this;
215
216
  // Recuperar todos os campos do tipo String
216
- var camposString = this.extractFieldsOfType(this.model.schema, 'String');
217
+ var camposString = (0, Utils_1.isEmpty)(this.searchTextFields) ? this.extractFieldsOfType(this.model.schema, 'String') : this.searchTextFields;
217
218
  var filters = { $and: [] };
218
219
  Object.entries(objectSearch).forEach(function (_a) {
219
220
  var _b, _c, _d;
@@ -235,6 +236,7 @@ var SearcherFlow = /** @class */ (function () {
235
236
  'model',
236
237
  'select',
237
238
  'searchText',
239
+ 'searchTextFields',
238
240
  'sort',
239
241
  'isPageable',
240
242
  'searchPageable'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.269",
3
+ "version": "2.1.274",
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",
@@ -30,7 +30,7 @@ class C2Flow<D> {
30
30
  async createMany(data: Partial<D>[], options: Partial<Options>): Promise<Partial<D>[]> {
31
31
  let dataAfter = await this.repository.create(data, { session: options.session })
32
32
 
33
- if (options.logger === false) {
33
+ if (options.logger === false || isEmpty(dataAfter)) {
34
34
  return dataAfter
35
35
  }
36
36
 
@@ -47,7 +47,7 @@ class C2Flow<D> {
47
47
  if (isEmpty(dataAfter)) {
48
48
  return dataAfter
49
49
  }
50
- return dataAfter._doc
50
+ return dataAfter?._doc
51
51
  }
52
52
  if (isEmpty(dataAfter)) {
53
53
  return dataAfter
@@ -58,7 +58,7 @@ class C2Flow<D> {
58
58
  if (isEmpty(dataAfter)) {
59
59
  return dataAfter
60
60
  }
61
- return dataAfter._doc
61
+ return dataAfter?._doc
62
62
  }
63
63
 
64
64
  async updateByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>> {
@@ -68,7 +68,7 @@ class C2Flow<D> {
68
68
  if (isEmpty(dataAfter)) {
69
69
  return dataAfter
70
70
  }
71
- return dataAfter._doc
71
+ return dataAfter?._doc
72
72
  }
73
73
 
74
74
  if (isEmpty(dataAfter)) {
@@ -80,7 +80,7 @@ class C2Flow<D> {
80
80
  if (isEmpty(dataAfter)) {
81
81
  return dataAfter
82
82
  }
83
- return dataAfter._doc
83
+ return dataAfter?._doc
84
84
  }
85
85
 
86
86
  async updateByFilters(filters: any, data: D, options: Partial<Options>): Promise<any> {
@@ -135,7 +135,7 @@ class C2Flow<D> {
135
135
  return
136
136
  }
137
137
 
138
- let log: Partial<ILogger> = BuildLogFlowItem.build(options, { _id, ...dataAfter._doc }, TypeOfOperation.DELETE, this.repository)
138
+ let log: Partial<ILogger> = BuildLogFlowItem.build(options, { _id, ...dataAfter?._doc }, TypeOfOperation.DELETE, this.repository)
139
139
  await (global as any).LoggerRepository.create([log], { session: options.session })
140
140
  }
141
141
 
@@ -17,6 +17,7 @@ class SearcherFlow<D> {
17
17
 
18
18
  [key: string]: any
19
19
  public searchText: string = ""
20
+ public searchTextFields: string[] = []
20
21
  public orderSense: string = "desc"
21
22
  public orderBy: string = "_id"
22
23
  public page: number = 1
@@ -175,7 +176,7 @@ class SearcherFlow<D> {
175
176
  public buildDefaultFilters(objectSearch: any) {
176
177
 
177
178
  // Recuperar todos os campos do tipo String
178
- const camposString = this.extractFieldsOfType(this.model.schema, 'String')
179
+ const camposString = isEmpty(this.searchTextFields) ? this.extractFieldsOfType(this.model.schema, 'String') : this.searchTextFields
179
180
 
180
181
 
181
182
  let filters = { $and: [] } as any
@@ -197,6 +198,7 @@ class SearcherFlow<D> {
197
198
  'model',
198
199
  'select',
199
200
  'searchText',
201
+ 'searchTextFields',
200
202
  'sort',
201
203
  'isPageable',
202
204
  'searchPageable'].includes(key)) {