c2-mongoose 2.1.133 → 2.1.135

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,6 +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
+ createMany(data: Partial<D>[], options: Partial<Options>): Promise<Partial<D>>;
8
9
  updateById(_id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
9
10
  updateByModel(searcher: SearchFlow, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>>;
10
11
  deleteById(_id: Types.ObjectId, options: Partial<Options>): Promise<void>;
@@ -76,6 +76,26 @@ var C2Flow = /** @class */ (function () {
76
76
  });
77
77
  });
78
78
  };
79
+ C2Flow.prototype.createMany = function (data, options) {
80
+ return __awaiter(this, void 0, void 0, function () {
81
+ var dataAfter, log;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0: return [4 /*yield*/, this.repository.create(data, { session: options.session })];
85
+ case 1:
86
+ dataAfter = _a.sent();
87
+ if (options.logger === false) {
88
+ return [2 /*return*/, dataAfter[0]._doc];
89
+ }
90
+ log = BuildLogFlowItem_1.default.build(options, dataAfter[0]._doc, Logger_1.TypeOfOperation.CREATE, this.repository);
91
+ return [4 /*yield*/, global.LoggerRepository.create([log], { session: options.session })];
92
+ case 2:
93
+ _a.sent();
94
+ return [2 /*return*/, dataAfter[0]._doc];
95
+ }
96
+ });
97
+ });
98
+ };
79
99
  C2Flow.prototype.updateById = function (_id, data, options) {
80
100
  return __awaiter(this, void 0, void 0, function () {
81
101
  var dataAfter, log;
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ var GetCamellCaseStringFlowItem_1 = __importDefault(require("./GetCamellCaseStringFlowItem"));
3
7
  var BuildPipelineToCountJoinFlowItem = /** @class */ (function () {
4
8
  function BuildPipelineToCountJoinFlowItem() {
5
9
  }
6
10
  BuildPipelineToCountJoinFlowItem.prototype.build = function (joinWith, fieldTarget) {
11
+ var _a;
7
12
  return [
8
13
  {
9
14
  $lookup: {
@@ -23,9 +28,9 @@ var BuildPipelineToCountJoinFlowItem = /** @class */ (function () {
23
28
  }
24
29
  },
25
30
  {
26
- $addFields: {
27
- totalProducts: { $ifNull: [{ $arrayElemAt: ['$matchedDocuments.totalCount', 0] }, 0] }
28
- }
31
+ $addFields: (_a = {},
32
+ _a["total".concat(GetCamellCaseStringFlowItem_1.default.get(joinWith.collection.name))] = { $ifNull: [{ $arrayElemAt: ['$matchedDocuments.totalCount', 0] }, 0] },
33
+ _a)
29
34
  },
30
35
  {
31
36
  $project: {
@@ -0,0 +1,5 @@
1
+ declare class GetCamellCaseStringFlowItem {
2
+ get(input: string): string;
3
+ }
4
+ declare const _default: GetCamellCaseStringFlowItem;
5
+ export default _default;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var GetCamellCaseStringFlowItem = /** @class */ (function () {
4
+ function GetCamellCaseStringFlowItem() {
5
+ }
6
+ GetCamellCaseStringFlowItem.prototype.get = function (input) {
7
+ return input.charAt(0).toUpperCase() + input.slice(1);
8
+ };
9
+ return GetCamellCaseStringFlowItem;
10
+ }());
11
+ exports.default = new GetCamellCaseStringFlowItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.133",
3
+ "version": "2.1.135",
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,6 +26,19 @@ class C2Flow<D> {
26
26
  return dataAfter[0]._doc
27
27
  }
28
28
 
29
+ async createMany(data: Partial<D>[], options: Partial<Options>): Promise<Partial<D>> {
30
+ let dataAfter = await this.repository.create(data, { session: options.session })
31
+
32
+ if (options.logger === false) {
33
+ return dataAfter[0]._doc
34
+ }
35
+
36
+ let log: Partial<ILogger> = BuildLogFlowItem.build(options, dataAfter[0]._doc, TypeOfOperation.CREATE, this.repository)
37
+ await (global as any).LoggerRepository.create([log], { session: options.session })
38
+
39
+ return dataAfter[0]._doc
40
+ }
41
+
29
42
  async updateById(_id: Types.ObjectId, data: Partial<D>, options: Partial<Options>): Promise<Partial<D>> {
30
43
  let dataAfter = await this.repository.findByIdAndUpdate(_id, data, { returnDocument: 'after', session: options.session })
31
44
 
@@ -1,4 +1,5 @@
1
1
  import mongoose from "mongoose"
2
+ import GetCamellCaseStringFlowItem from "./GetCamellCaseStringFlowItem"
2
3
 
3
4
  class BuildPipelineToCountJoinFlowItem {
4
5
  build(joinWith: mongoose.Model<any>, fieldTarget: string): any[] {
@@ -22,7 +23,7 @@ class BuildPipelineToCountJoinFlowItem {
22
23
  },
23
24
  {
24
25
  $addFields: {
25
- totalProducts: { $ifNull: [{ $arrayElemAt: ['$matchedDocuments.totalCount', 0] }, 0] }
26
+ [`total${GetCamellCaseStringFlowItem.get(joinWith.collection.name)}`]: { $ifNull: [{ $arrayElemAt: ['$matchedDocuments.totalCount', 0] }, 0] }
26
27
  }
27
28
  },
28
29
  {
@@ -0,0 +1,7 @@
1
+ class GetCamellCaseStringFlowItem {
2
+ get(input: string): string {
3
+ return input.charAt(0).toUpperCase() + input.slice(1);
4
+ }
5
+ }
6
+
7
+ export default new GetCamellCaseStringFlowItem