c2-mongoose 2.1.21 → 2.1.22

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.
@@ -10,6 +10,7 @@ declare class CrudFlow<D> {
10
10
  delete(id: string, session?: any): Promise<void>;
11
11
  deleteMany(conditions: {}, session?: any): Promise<void>;
12
12
  update(id: string, data: D, session?: any): Promise<D>;
13
+ updateAny(id: string, data: any, session?: any): Promise<D>;
13
14
  find(): Promise<SearchResponse<D>>;
14
15
  getOne(model: D, params?: any): Promise<D>;
15
16
  get(id: string, pop?: string, sel?: string, session?: ClientSession): Promise<D>;
@@ -96,6 +96,20 @@ var CrudFlow = /** @class */ (function () {
96
96
  });
97
97
  });
98
98
  };
99
+ CrudFlow.prototype.updateAny = function (id, data, session) {
100
+ if (session === void 0) { session = undefined; }
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ var dataAfter;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0: return [4 /*yield*/, this.repository.findByIdAndUpdate(id, data, { returnDocument: 'after', session: session })];
106
+ case 1:
107
+ dataAfter = _a.sent();
108
+ return [2 /*return*/, dataAfter];
109
+ }
110
+ });
111
+ });
112
+ };
99
113
  CrudFlow.prototype.find = function () {
100
114
  return __awaiter(this, void 0, void 0, function () {
101
115
  return __generator(this, function (_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.21",
3
+ "version": "2.1.22",
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",
@@ -34,6 +34,11 @@ class CrudFlow<D> {
34
34
  return dataAfter as D
35
35
  }
36
36
 
37
+ public async updateAny(id: string, data: any, session: any = undefined): Promise<D> {
38
+ const dataAfter = await this.repository.findByIdAndUpdate(id, data, { returnDocument: 'after', session })
39
+ return dataAfter as D
40
+ }
41
+
37
42
  public async find(): Promise<SearchResponse<D>> {
38
43
  return await this.search.search(this.repository)
39
44
  }