c2-mongoose 2.1.131 → 2.1.133

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.
@@ -0,0 +1,6 @@
1
+ import mongoose from "mongoose";
2
+ declare class BuildPipelineToCountJoinFlowItem {
3
+ build(joinWith: mongoose.Model<any>, fieldTarget: string): any[];
4
+ }
5
+ declare const _default: BuildPipelineToCountJoinFlowItem;
6
+ export default _default;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var BuildPipelineToCountJoinFlowItem = /** @class */ (function () {
4
+ function BuildPipelineToCountJoinFlowItem() {
5
+ }
6
+ BuildPipelineToCountJoinFlowItem.prototype.build = function (joinWith, fieldTarget) {
7
+ return [
8
+ {
9
+ $lookup: {
10
+ from: joinWith.collection.name,
11
+ let: { localField: '$_id' },
12
+ pipeline: [
13
+ {
14
+ $match: {
15
+ $expr: { $eq: ["$".concat(fieldTarget), '$$localField'] }
16
+ }
17
+ },
18
+ {
19
+ $count: 'totalCount'
20
+ }
21
+ ],
22
+ as: 'matchedDocuments'
23
+ }
24
+ },
25
+ {
26
+ $addFields: {
27
+ totalProducts: { $ifNull: [{ $arrayElemAt: ['$matchedDocuments.totalCount', 0] }, 0] }
28
+ }
29
+ },
30
+ {
31
+ $project: {
32
+ matchedDocuments: 0
33
+ }
34
+ }
35
+ ];
36
+ };
37
+ return BuildPipelineToCountJoinFlowItem;
38
+ }());
39
+ exports.default = new BuildPipelineToCountJoinFlowItem;
@@ -0,0 +1,6 @@
1
+ import mongoose from "mongoose";
2
+ declare class BuildPipelineToJoinFlowItem {
3
+ build(joinWith: mongoose.Model<any>, fieldTarget: string): any[];
4
+ }
5
+ declare const _default: BuildPipelineToJoinFlowItem;
6
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var BuildPipelineToJoinFlowItem = /** @class */ (function () {
4
+ function BuildPipelineToJoinFlowItem() {
5
+ }
6
+ BuildPipelineToJoinFlowItem.prototype.build = function (joinWith, fieldTarget) {
7
+ return [
8
+ {
9
+ $lookup: {
10
+ from: joinWith.collection.name,
11
+ let: { localField: '$_id' },
12
+ pipeline: [
13
+ {
14
+ $match: {
15
+ $expr: { $eq: ["$".concat(fieldTarget), '$$localField'] }
16
+ }
17
+ }
18
+ ],
19
+ as: "".concat(joinWith.collection.name)
20
+ }
21
+ }
22
+ ];
23
+ };
24
+ return BuildPipelineToJoinFlowItem;
25
+ }());
26
+ exports.default = new BuildPipelineToJoinFlowItem;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import C2Flow from "./flow/C2Flow";
2
2
  import CrudFlow from "./flow/CrudFlow";
3
3
  import SearchFlow from "./flow/SearchFlow";
4
+ import BuildPipelineToCountJoinFlowItem from "./flow/item/BuildPipelineToCountJoinFlowItem";
5
+ import BuildPipelineToJoinFlowItem from "./flow/item/BuildPipelineToJoinFlowItem";
4
6
  import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger";
5
7
  import { Options } from "./types/Options";
6
8
  import { Pagination, SearchResponse } from "./types/SearchResponse";
7
9
  import { initialize } from "./utils/Utils";
8
- export { C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize };
10
+ export { C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem };
package/dist/index.js CHANGED
@@ -3,13 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initialize = exports.TypeOfOperation = exports.SearchFlow = exports.LoggerSearch = exports.LoggerModel = exports.CrudFlow = exports.C2Flow = void 0;
6
+ exports.BuildPipelineToJoinFlowItem = exports.BuildPipelineToCountJoinFlowItem = exports.initialize = exports.TypeOfOperation = exports.SearchFlow = exports.LoggerSearch = exports.LoggerModel = exports.CrudFlow = exports.C2Flow = void 0;
7
7
  var C2Flow_1 = __importDefault(require("./flow/C2Flow"));
8
8
  exports.C2Flow = C2Flow_1.default;
9
9
  var CrudFlow_1 = __importDefault(require("./flow/CrudFlow"));
10
10
  exports.CrudFlow = CrudFlow_1.default;
11
11
  var SearchFlow_1 = __importDefault(require("./flow/SearchFlow"));
12
12
  exports.SearchFlow = SearchFlow_1.default;
13
+ var BuildPipelineToCountJoinFlowItem_1 = __importDefault(require("./flow/item/BuildPipelineToCountJoinFlowItem"));
14
+ exports.BuildPipelineToCountJoinFlowItem = BuildPipelineToCountJoinFlowItem_1.default;
15
+ var BuildPipelineToJoinFlowItem_1 = __importDefault(require("./flow/item/BuildPipelineToJoinFlowItem"));
16
+ exports.BuildPipelineToJoinFlowItem = BuildPipelineToJoinFlowItem_1.default;
13
17
  var Logger_1 = require("./model/Logger");
14
18
  Object.defineProperty(exports, "LoggerModel", { enumerable: true, get: function () { return Logger_1.LoggerModel; } });
15
19
  Object.defineProperty(exports, "LoggerSearch", { enumerable: true, get: function () { return Logger_1.LoggerSearch; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.131",
3
+ "version": "2.1.133",
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",
@@ -0,0 +1,37 @@
1
+ import mongoose from "mongoose"
2
+
3
+ class BuildPipelineToCountJoinFlowItem {
4
+ build(joinWith: mongoose.Model<any>, fieldTarget: string): any[] {
5
+ return [
6
+ {
7
+ $lookup: {
8
+ from: joinWith.collection.name,
9
+ let: { localField: '$_id' },
10
+ pipeline: [
11
+ {
12
+ $match: {
13
+ $expr: { $eq: [`$${fieldTarget}`, '$$localField'] }
14
+ }
15
+ },
16
+ {
17
+ $count: 'totalCount'
18
+ }
19
+ ],
20
+ as: 'matchedDocuments'
21
+ }
22
+ },
23
+ {
24
+ $addFields: {
25
+ totalProducts: { $ifNull: [{ $arrayElemAt: ['$matchedDocuments.totalCount', 0] }, 0] }
26
+ }
27
+ },
28
+ {
29
+ $project: {
30
+ matchedDocuments: 0
31
+ }
32
+ }
33
+ ]
34
+ }
35
+ }
36
+
37
+ export default new BuildPipelineToCountJoinFlowItem
@@ -0,0 +1,24 @@
1
+ import mongoose from "mongoose"
2
+
3
+ class BuildPipelineToJoinFlowItem {
4
+ build(joinWith: mongoose.Model<any>, fieldTarget: string): any[] {
5
+ return [
6
+ {
7
+ $lookup: {
8
+ from: joinWith.collection.name,
9
+ let: { localField: '$_id' },
10
+ pipeline: [
11
+ {
12
+ $match: {
13
+ $expr: { $eq: [`$${fieldTarget}`, '$$localField'] }
14
+ }
15
+ }
16
+ ],
17
+ as: `${joinWith.collection.name}`
18
+ }
19
+ }
20
+ ]
21
+ }
22
+ }
23
+
24
+ export default new BuildPipelineToJoinFlowItem
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import C2Flow from "./flow/C2Flow"
2
2
  import CrudFlow from "./flow/CrudFlow"
3
3
  import SearchFlow from "./flow/SearchFlow"
4
+ import BuildPipelineToCountJoinFlowItem from "./flow/item/BuildPipelineToCountJoinFlowItem"
5
+ import BuildPipelineToJoinFlowItem from "./flow/item/BuildPipelineToJoinFlowItem"
4
6
  import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger"
5
7
  import { Options } from "./types/Options"
6
8
  import { Pagination, SearchResponse } from "./types/SearchResponse"
@@ -8,5 +10,8 @@ import { initialize } from "./utils/Utils"
8
10
 
9
11
  (global as any).LoggerRepository = undefined
10
12
 
11
- export { C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize }
13
+ export {
14
+ C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize,
15
+ BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem
16
+ }
12
17