c2-mongoose 2.1.182 → 2.1.184

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.
@@ -52,6 +52,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
53
  var Logger_1 = require("../model/Logger");
54
54
  var BuildLogFlowItem_1 = __importDefault(require("./item/BuildLogFlowItem"));
55
+ var Utils_1 = require("../utils/Utils");
55
56
  var C2Flow = /** @class */ (function () {
56
57
  function C2Flow(repository) {
57
58
  this.repository = repository;
@@ -105,12 +106,18 @@ var C2Flow = /** @class */ (function () {
105
106
  case 1:
106
107
  dataAfter = _a.sent();
107
108
  if (options.logger === false) {
109
+ if ((0, Utils_1.isEmpty)(dataAfter)) {
110
+ return [2 /*return*/, dataAfter];
111
+ }
108
112
  return [2 /*return*/, dataAfter._doc];
109
113
  }
110
114
  log = BuildLogFlowItem_1.default.build(options, __assign({ _id: _id }, data), Logger_1.TypeOfOperation.UPDATE, this.repository);
111
115
  return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
112
116
  case 2:
113
117
  _a.sent();
118
+ if ((0, Utils_1.isEmpty)(dataAfter)) {
119
+ return [2 /*return*/, dataAfter];
120
+ }
114
121
  return [2 /*return*/, dataAfter._doc];
115
122
  }
116
123
  });
@@ -125,12 +132,18 @@ var C2Flow = /** @class */ (function () {
125
132
  case 1:
126
133
  dataAfter = _a.sent();
127
134
  if (options.logger === false) {
135
+ if ((0, Utils_1.isEmpty)(dataAfter)) {
136
+ return [2 /*return*/, dataAfter];
137
+ }
128
138
  return [2 /*return*/, dataAfter._doc];
129
139
  }
130
140
  log = BuildLogFlowItem_1.default.build(options, __assign({ _id: dataAfter._id }, data), Logger_1.TypeOfOperation.UPDATE, this.repository);
131
141
  return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
132
142
  case 2:
133
143
  _a.sent();
144
+ if ((0, Utils_1.isEmpty)(dataAfter)) {
145
+ return [2 /*return*/, dataAfter];
146
+ }
134
147
  return [2 /*return*/, dataAfter._doc];
135
148
  }
136
149
  });
@@ -55,6 +55,10 @@ var mongoose_1 = require("mongoose");
55
55
  var Utils_1 = require("../utils/Utils");
56
56
  var SearchFlow = /** @class */ (function () {
57
57
  function SearchFlow(params) {
58
+ // Incluir as propriedades adicionais de 'params' como propriedades da classe
59
+ for (var key in params) {
60
+ this[key] = params[key];
61
+ }
58
62
  this.searchText = params.searchText || "";
59
63
  this.orderSense = params.orderSense || "asc";
60
64
  this.orderBy = params.orderBy || "_id";
@@ -11,6 +11,9 @@ var isNotEmpty = function (obj) {
11
11
  };
12
12
  exports.isNotEmpty = isNotEmpty;
13
13
  var isEmpty = function (obj) {
14
+ if (obj === null) {
15
+ return true;
16
+ }
14
17
  if (!obj) {
15
18
  return true;
16
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.182",
3
+ "version": "2.1.184",
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",
@@ -4,6 +4,7 @@ import { ILogger, TypeOfOperation } from "../model/Logger"
4
4
  import { Options } from "../types/Options"
5
5
  import BuildLogFlowItem from "./item/BuildLogFlowItem"
6
6
  import SearchFlow from "./SearchFlow"
7
+ import { isEmpty } from "../utils/Utils"
7
8
 
8
9
  class C2Flow<D> {
9
10
 
@@ -43,12 +44,17 @@ class C2Flow<D> {
43
44
  let dataAfter = await this.repository.findByIdAndUpdate(_id, data, { returnDocument: 'after', session: options.session })
44
45
 
45
46
  if (options.logger === false) {
47
+ if (isEmpty(dataAfter)) {
48
+ return dataAfter
49
+ }
46
50
  return dataAfter._doc
47
51
  }
48
52
 
49
53
  let log: Partial<ILogger> = BuildLogFlowItem.build(options, { _id, ...data }, TypeOfOperation.UPDATE, this.repository)
50
54
  await (global as any).LoggerRepository.create([log], { session: options.session })
51
-
55
+ if (isEmpty(dataAfter)) {
56
+ return dataAfter
57
+ }
52
58
  return dataAfter._doc
53
59
  }
54
60
 
@@ -56,12 +62,17 @@ class C2Flow<D> {
56
62
  let dataAfter = await this.repository.findOneAndUpdate(searcher.filters, data, { session: options.session })
57
63
 
58
64
  if (options.logger === false) {
65
+ if (isEmpty(dataAfter)) {
66
+ return dataAfter
67
+ }
59
68
  return dataAfter._doc
60
69
  }
61
70
 
62
71
  let log: Partial<ILogger> = BuildLogFlowItem.build(options, { _id: dataAfter._id, ...data }, TypeOfOperation.UPDATE, this.repository)
63
72
  await (global as any).LoggerRepository.create([log], { session: options.session })
64
-
73
+ if (isEmpty(dataAfter)) {
74
+ return dataAfter
75
+ }
65
76
  return dataAfter._doc
66
77
  }
67
78
 
@@ -19,6 +19,11 @@ abstract class SearchFlow {
19
19
  projection: { [key: string]: number } | undefined
20
20
 
21
21
  constructor(params: any) {
22
+ // Incluir as propriedades adicionais de 'params' como propriedades da classe
23
+ for (const key in params) {
24
+ this[key] = params[key];
25
+ }
26
+
22
27
  this.searchText = params.searchText || ""
23
28
  this.orderSense = params.orderSense || "asc"
24
29
  this.orderBy = params.orderBy || "_id"
@@ -383,20 +388,20 @@ abstract class SearchFlow {
383
388
  if (isNotEmpty(value)) {
384
389
  let condition = {} as any
385
390
  if ([
386
- 'onlyMetadata',
387
- 'projection',
388
- 'pageable',
389
- 'orderSense',
390
- 'orderBy',
391
- 'properties',
392
- 'populate',
393
- 'page',
394
- 'limit',
395
- 'model',
396
- 'select',
397
- 'searchText',
391
+ 'onlyMetadata',
392
+ 'projection',
393
+ 'pageable',
394
+ 'orderSense',
395
+ 'orderBy',
396
+ 'properties',
397
+ 'populate',
398
+ 'page',
399
+ 'limit',
400
+ 'model',
401
+ 'select',
402
+ 'searchText',
398
403
  'sort',
399
- 'isPageable',
404
+ 'isPageable',
400
405
  'searchPageable'].includes(key)) {
401
406
  return
402
407
  }
@@ -11,6 +11,9 @@ export const isNotEmpty = (obj: any) => {
11
11
  }
12
12
 
13
13
  export const isEmpty = (obj: any) => {
14
+ if (obj === null) {
15
+ return true
16
+ }
14
17
  if (!obj) {
15
18
  return true
16
19
  }