c2-mongoose 2.1.239 → 2.1.240

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.
@@ -8,6 +8,7 @@ declare class C2Flow<D> {
8
8
  createMany(data: Partial<D>[], options: Partial<Options>): Promise<Partial<D>[]>;
9
9
  updateById(_id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
10
10
  updateByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
11
+ updateMany(searcher: SearchFlow, data: D, options: Options): Promise<any>;
11
12
  deleteById(_id: Types.ObjectId, options: Partial<Options>): Promise<void>;
12
13
  deleteByModel(searcher: SearchFlow, options: Partial<Options>): Promise<void>;
13
14
  }
@@ -155,6 +155,35 @@ var C2Flow = /** @class */ (function () {
155
155
  });
156
156
  });
157
157
  };
158
+ C2Flow.prototype.updateMany = function (searcher, data, options) {
159
+ return __awaiter(this, void 0, void 0, function () {
160
+ var dataAfter, log;
161
+ return __generator(this, function (_a) {
162
+ switch (_a.label) {
163
+ case 0: return [4 /*yield*/, this.repository.updateMany(searcher.filters, data, { returnDocument: 'after', session: options.session })];
164
+ case 1:
165
+ dataAfter = _a.sent();
166
+ if (options.logger === false) {
167
+ if ((0, Utils_1.isEmpty)(dataAfter)) {
168
+ return [2 /*return*/, dataAfter];
169
+ }
170
+ return [2 /*return*/, dataAfter];
171
+ }
172
+ if ((0, Utils_1.isEmpty)(dataAfter)) {
173
+ return [2 /*return*/, dataAfter];
174
+ }
175
+ log = BuildLogFlowItem_1.default.build(options, __assign({ filters: searcher.filters }, data), Logger_1.TypeOfOperation.UPDATE, this.repository);
176
+ return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
177
+ case 2:
178
+ _a.sent();
179
+ if ((0, Utils_1.isEmpty)(dataAfter)) {
180
+ return [2 /*return*/, dataAfter];
181
+ }
182
+ return [2 /*return*/, dataAfter];
183
+ }
184
+ });
185
+ });
186
+ };
158
187
  C2Flow.prototype.deleteById = function (_id, options) {
159
188
  return __awaiter(this, void 0, void 0, function () {
160
189
  var dataAfter, log;
@@ -13,6 +13,8 @@ interface ILogger {
13
13
  createdAtDateTime: moment.Moment;
14
14
  operation: TypeOfOperation;
15
15
  data: any;
16
+ filters: any;
17
+ notes: string;
16
18
  }
17
19
  declare const LoggerModel: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.ResolveSchemaOptions<{
18
20
  timestamps: {
@@ -25,18 +27,24 @@ declare const LoggerModel: mongoose.Schema<any, mongoose.Model<any, any, any, an
25
27
  collectionName: string;
26
28
  operation: string;
27
29
  data?: any;
30
+ filters?: any;
31
+ notes?: string | undefined;
28
32
  }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
29
33
  owner: Types.ObjectId;
30
34
  user: Types.ObjectId;
31
35
  collectionName: string;
32
36
  operation: string;
33
37
  data?: any;
38
+ filters?: any;
39
+ notes?: string | undefined;
34
40
  }>> & Omit<mongoose.FlatRecord<{
35
41
  owner: Types.ObjectId;
36
42
  user: Types.ObjectId;
37
43
  collectionName: string;
38
44
  operation: string;
39
45
  data?: any;
46
+ filters?: any;
47
+ notes?: string | undefined;
40
48
  }> & {
41
49
  _id: Types.ObjectId;
42
50
  }, never>>;
@@ -57,7 +57,9 @@ var LoggerModel = new mongoose_1.Schema({
57
57
  user: { type: mongoose_1.default.Schema.Types.ObjectId, required: true, immutable: true },
58
58
  collectionName: { type: String, required: true, immutable: true },
59
59
  operation: { type: String, enum: TypeOfOperation, required: true, immutable: true },
60
- data: { type: mongoose_1.default.Schema.Types.Mixed, immutable: true }
60
+ data: { type: mongoose_1.default.Schema.Types.Mixed, immutable: true },
61
+ filters: { type: mongoose_1.default.Schema.Types.Mixed, immutable: true },
62
+ notes: { type: String, immutable: true }
61
63
  }, {
62
64
  timestamps: { createdAt: 'createdAtDateTime', updatedAt: 'updatedAtDateTime' }
63
65
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.239",
3
+ "version": "2.1.240",
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",
@@ -1,5 +1,5 @@
1
1
 
2
- import mongoose, { Types } from "mongoose"
2
+ import mongoose, { QueryWithHelpers, Types, UpdateWriteOpResult } from "mongoose"
3
3
  import { ILogger, TypeOfOperation } from "../model/Logger"
4
4
  import { Options } from "../types/Options"
5
5
  import BuildLogFlowItem from "./item/BuildLogFlowItem"
@@ -83,6 +83,27 @@ class C2Flow<D> {
83
83
  return dataAfter._doc
84
84
  }
85
85
 
86
+ async updateMany(searcher: SearchFlow, data: D, options: Options): Promise<any> {
87
+ let dataAfter = await this.repository.updateMany(searcher.filters, data as Partial<D>, { returnDocument: 'after', session: options.session })
88
+ if (options.logger === false) {
89
+ if (isEmpty(dataAfter)) {
90
+ return dataAfter
91
+ }
92
+ return dataAfter
93
+ }
94
+
95
+ if (isEmpty(dataAfter)) {
96
+ return dataAfter
97
+ }
98
+
99
+ let log: Partial<ILogger> = BuildLogFlowItem.build(options, { filters: searcher.filters, ...data }, TypeOfOperation.UPDATE, this.repository)
100
+ await (global as any).LoggerRepository.create([log], { session: options.session })
101
+ if (isEmpty(dataAfter)) {
102
+ return dataAfter
103
+ }
104
+ return dataAfter
105
+ }
106
+
86
107
 
87
108
  public async deleteById(_id: Types.ObjectId, options: Partial<Options>) {
88
109
 
@@ -16,6 +16,8 @@ interface ILogger {
16
16
  createdAtDateTime: moment.Moment
17
17
  operation: TypeOfOperation
18
18
  data: any
19
+ filters: any
20
+ notes: string
19
21
  }
20
22
 
21
23
  const LoggerModel = new Schema({
@@ -23,7 +25,9 @@ const LoggerModel = new Schema({
23
25
  user: { type: mongoose.Schema.Types.ObjectId, required: true, immutable: true },
24
26
  collectionName: { type: String, required: true, immutable: true },
25
27
  operation: { type: String, enum: TypeOfOperation, required: true, immutable: true },
26
- data: { type: mongoose.Schema.Types.Mixed, immutable: true }
28
+ data: { type: mongoose.Schema.Types.Mixed, immutable: true },
29
+ filters: { type: mongoose.Schema.Types.Mixed, immutable: true },
30
+ notes: { type: String, immutable: true }
27
31
  }, {
28
32
  timestamps: { createdAt: 'createdAtDateTime', updatedAt: 'updatedAtDateTime' }
29
33
  })