c2-mongoose 2.1.95 → 2.1.96

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.
@@ -41,6 +41,7 @@ declare abstract class SearchFlow {
41
41
  findOne(repository: mongoose.Model<any>, model: any, params?: any): Promise<any>;
42
42
  sumBy(model: mongoose.Model<any>, _sum: any, _by: any, items?: any, session?: ClientSession): Promise<any[]>;
43
43
  sumByPaging(model: mongoose.Model<any>, fieldToSum: any, fieldToGroup: any, items?: any): Promise<SearchResponse<any>>;
44
+ isValidObjectId(value: string): boolean;
44
45
  buildDefaultFilters(objectSearch: any): any;
45
46
  addFilterModel(model: any, filters: any): void;
46
47
  }
@@ -404,6 +404,10 @@ var SearchFlow = /** @class */ (function () {
404
404
  });
405
405
  });
406
406
  };
407
+ SearchFlow.prototype.isValidObjectId = function (value) {
408
+ var objectIdPattern = /^[0-9a-fA-F]{24}$/;
409
+ return objectIdPattern.test(value);
410
+ };
407
411
  SearchFlow.prototype.buildDefaultFilters = function (objectSearch) {
408
412
  var _this = this;
409
413
  var filters = { $and: [] };
@@ -414,7 +418,7 @@ var SearchFlow = /** @class */ (function () {
414
418
  if (['projection', 'pageable', 'order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
415
419
  return;
416
420
  }
417
- if (typeof value === 'string' && mongoose_1.Types.ObjectId.isValid(value)) {
421
+ if (typeof value === 'string' && _this.isValidObjectId(value)) {
418
422
  value = new mongoose_1.Types.ObjectId(value);
419
423
  }
420
424
  if (value === 'true') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.95",
3
+ "version": "2.1.96",
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",
@@ -321,6 +321,11 @@ abstract class SearchFlow {
321
321
  }
322
322
  }
323
323
 
324
+ public isValidObjectId(value: string) {
325
+ const objectIdPattern = /^[0-9a-fA-F]{24}$/;
326
+ return objectIdPattern.test(value);
327
+ }
328
+
324
329
  public buildDefaultFilters(objectSearch: any) {
325
330
  let filters = { $and: [] } as any
326
331
  Object.entries(objectSearch.model).forEach(([key, value]) => {
@@ -330,7 +335,7 @@ abstract class SearchFlow {
330
335
  return
331
336
  }
332
337
 
333
- if (typeof value === 'string' && Types.ObjectId.isValid(value as any)) {
338
+ if (typeof value === 'string' && this.isValidObjectId(value as string)) {
334
339
  value = new Types.ObjectId(value as string)
335
340
  }
336
341