c2-mongoose 2.1.114 → 2.1.116

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.
@@ -5,7 +5,7 @@ declare class C2Flow<D> {
5
5
  private repository;
6
6
  constructor(repository: mongoose.Model<any>);
7
7
  create(data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
8
- updateById(id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
8
+ updateById(_id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
9
9
  updateByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
10
10
  }
11
11
  export default C2Flow;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -65,18 +76,18 @@ var C2Flow = /** @class */ (function () {
65
76
  });
66
77
  });
67
78
  };
68
- C2Flow.prototype.updateById = function (id, data, options) {
79
+ C2Flow.prototype.updateById = function (_id, data, options) {
69
80
  return __awaiter(this, void 0, void 0, function () {
70
81
  var dataAfter, log;
71
82
  return __generator(this, function (_a) {
72
83
  switch (_a.label) {
73
- case 0: return [4 /*yield*/, this.repository.findByIdAndUpdate(id, data, { returnDocument: 'after', session: options.session })];
84
+ case 0: return [4 /*yield*/, this.repository.findByIdAndUpdate(_id, data, { returnDocument: 'after', session: options.session })];
74
85
  case 1:
75
86
  dataAfter = _a.sent();
76
87
  if (options.logger === false) {
77
88
  return [2 /*return*/, dataAfter._doc];
78
89
  }
79
- log = BuildLogFlowItem_1.default.build(options, dataAfter._doc, Logger_1.TypeOfOperation.UPDATE, this.repository);
90
+ log = BuildLogFlowItem_1.default.build(options, __assign({ _id: _id }, data), Logger_1.TypeOfOperation.UPDATE, this.repository);
80
91
  return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
81
92
  case 2:
82
93
  _a.sent();
@@ -96,7 +107,7 @@ var C2Flow = /** @class */ (function () {
96
107
  if (options.logger === false) {
97
108
  return [2 /*return*/, dataAfter._doc];
98
109
  }
99
- log = BuildLogFlowItem_1.default.build(options, dataAfter._doc, Logger_1.TypeOfOperation.UPDATE, this.repository);
110
+ log = BuildLogFlowItem_1.default.build(options, __assign({ _id: dataAfter._id }, data), Logger_1.TypeOfOperation.UPDATE, this.repository);
100
111
  return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
101
112
  case 2:
102
113
  _a.sent();
@@ -2,7 +2,7 @@ import { ILogger, TypeOfOperation } from "../../model/Logger";
2
2
  import { Options } from "../../types/Options";
3
3
  import mongoose from "mongoose";
4
4
  declare class BuildLogFlowItem {
5
- build(options: Partial<Options>, dataAfter: any[], operation: TypeOfOperation, repository: mongoose.Model<any>): Partial<ILogger>;
5
+ build(options: Partial<Options>, dataAfter: any, operation: TypeOfOperation, repository: mongoose.Model<any>): Partial<ILogger>;
6
6
  }
7
7
  declare const _default: BuildLogFlowItem;
8
8
  export default _default;
@@ -17,6 +17,7 @@ interface ILogger {
17
17
  declare const LoggerModel: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.ResolveSchemaOptions<{
18
18
  timestamps: {
19
19
  createdAt: string;
20
+ updatedAt: string;
20
21
  };
21
22
  }>, {
22
23
  owner: {
@@ -59,7 +59,7 @@ var LoggerModel = new mongoose_1.Schema({
59
59
  operation: { type: String, enum: TypeOfOperation, required: true, immutable: true },
60
60
  data: { type: mongoose_1.default.Schema.Types.Mixed, immutable: true }
61
61
  }, {
62
- timestamps: { createdAt: 'createdAtDateTime' }
62
+ timestamps: { createdAt: 'createdAtDateTime', updatedAt: 'updatedAtDateTime' }
63
63
  });
64
64
  exports.LoggerModel = LoggerModel;
65
65
  var LoggerSearch = /** @class */ (function (_super) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.114",
3
+ "version": "2.1.116",
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",
@@ -26,14 +26,14 @@ class C2Flow<D> {
26
26
  return dataAfter[0]._doc
27
27
  }
28
28
 
29
- async updateById(id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>> {
30
- let dataAfter = await this.repository.findByIdAndUpdate(id, data, { returnDocument: 'after', session: options.session })
29
+ async updateById(_id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>> {
30
+ let dataAfter = await this.repository.findByIdAndUpdate(_id, data, { returnDocument: 'after', session: options.session })
31
31
 
32
32
  if (options.logger === false) {
33
33
  return dataAfter._doc
34
34
  }
35
35
 
36
- let log: Partial<ILogger> = BuildLogFlowItem.build(options, dataAfter._doc, TypeOfOperation.UPDATE, this.repository)
36
+ let log: Partial<ILogger> = BuildLogFlowItem.build(options, { _id, ...data }, TypeOfOperation.UPDATE, this.repository)
37
37
  await (global as any).LoggerRepository.create([log], { session: options.session })
38
38
 
39
39
  return dataAfter._doc
@@ -46,7 +46,7 @@ class C2Flow<D> {
46
46
  return dataAfter._doc
47
47
  }
48
48
 
49
- let log: Partial<ILogger> = BuildLogFlowItem.build(options, dataAfter._doc, TypeOfOperation.UPDATE, this.repository)
49
+ let log: Partial<ILogger> = BuildLogFlowItem.build(options, { _id: dataAfter._id, ...data }, TypeOfOperation.UPDATE, this.repository)
50
50
  await (global as any).LoggerRepository.create([log], { session: options.session })
51
51
 
52
52
  return dataAfter._doc
@@ -4,7 +4,7 @@ import { Options } from "../../types/Options"
4
4
  import mongoose from "mongoose"
5
5
 
6
6
  class BuildLogFlowItem {
7
- build(options: Partial<Options>, dataAfter: any[], operation: TypeOfOperation, repository: mongoose.Model<any>): Partial<ILogger> {
7
+ build(options: Partial<Options>, dataAfter: any, operation: TypeOfOperation, repository: mongoose.Model<any>): Partial<ILogger> {
8
8
  return {
9
9
  user: options.user ?? httpContext.get("user")._id,
10
10
  owner: options.owner,
@@ -25,7 +25,7 @@ const LoggerModel = new Schema({
25
25
  operation: { type: String, enum: TypeOfOperation, required: true, immutable: true },
26
26
  data: { type: mongoose.Schema.Types.Mixed, immutable: true }
27
27
  }, {
28
- timestamps: { createdAt: 'createdAtDateTime' }
28
+ timestamps: { createdAt: 'createdAtDateTime', updatedAt: 'updatedAtDateTime' }
29
29
  })
30
30
 
31
31
  class LoggerSearch extends SearchFlow {