c2-mongoose 2.1.360 → 2.1.362

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.
@@ -1,6 +1,7 @@
1
1
  import mongoose from "mongoose";
2
+ import { IForeingData } from "../v3/item/OneToManyFlowItem";
2
3
  declare class GetOneByFilterFlow {
3
- exec(params: any, model: mongoose.Model<any>): Promise<any>;
4
+ exec(params: any, model: mongoose.Model<any>, oneToMany?: IForeingData[]): Promise<any>;
4
5
  }
5
6
  declare const _default: GetOneByFilterFlow;
6
7
  export default _default;
@@ -51,10 +51,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
51
51
  var MatchFlowItem_1 = __importDefault(require("./item/MatchFlowItem"));
52
52
  var PopulateFlowItem_1 = __importDefault(require("./item/PopulateFlowItem"));
53
53
  var ProjectFlowItem_1 = __importDefault(require("./item/ProjectFlowItem"));
54
+ var OneToManyFlowItem_1 = __importDefault(require("../v3/item/OneToManyFlowItem"));
54
55
  var GetOneByFilterFlow = /** @class */ (function () {
55
56
  function GetOneByFilterFlow() {
56
57
  }
57
- GetOneByFilterFlow.prototype.exec = function (params, model) {
58
+ GetOneByFilterFlow.prototype.exec = function (params, model, oneToMany) {
59
+ if (oneToMany === void 0) { oneToMany = []; }
58
60
  return __awaiter(this, void 0, void 0, function () {
59
61
  var pipeline, result;
60
62
  return __generator(this, function (_a) {
@@ -62,6 +64,7 @@ var GetOneByFilterFlow = /** @class */ (function () {
62
64
  case 0:
63
65
  pipeline = [];
64
66
  pipeline = __spreadArray(__spreadArray([], pipeline, true), PopulateFlowItem_1.default.exec(params.populate, model), true);
67
+ pipeline = __spreadArray(__spreadArray([], pipeline, true), OneToManyFlowItem_1.default.execute(oneToMany), true);
65
68
  pipeline = __spreadArray(__spreadArray([], pipeline, true), ProjectFlowItem_1.default.exec(params.select), true);
66
69
  return [4 /*yield*/, model.aggregate(__spreadArray(__spreadArray([], MatchFlowItem_1.default.exec(params, model), true), pipeline, true), {
67
70
  collation: {
@@ -0,0 +1,9 @@
1
+ export interface IForeingData {
2
+ collectionChild: string;
3
+ parentFieldOnChild: string;
4
+ }
5
+ declare class OneToManyFlowItem {
6
+ execute(foreings: IForeingData[]): any[];
7
+ }
8
+ declare const _default: OneToManyFlowItem;
9
+ export default _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ var OneToManyFlowItem = /** @class */ (function () {
13
+ function OneToManyFlowItem() {
14
+ }
15
+ OneToManyFlowItem.prototype.execute = function (foreings) {
16
+ var collection = [];
17
+ foreings === null || foreings === void 0 ? void 0 : foreings.forEach(function (foreing) {
18
+ var populateClauseLookup = [
19
+ {
20
+ $lookup: {
21
+ from: foreing.collectionChild,
22
+ localField: "_id",
23
+ foreignField: foreing.parentFieldOnChild,
24
+ as: foreing.collectionChild
25
+ }
26
+ },
27
+ ];
28
+ collection = __spreadArray(__spreadArray([], collection, true), populateClauseLookup, true);
29
+ });
30
+ return collection;
31
+ };
32
+ return OneToManyFlowItem;
33
+ }());
34
+ exports.default = new OneToManyFlowItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.360",
3
+ "version": "2.1.362",
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",
@@ -2,14 +2,16 @@ import mongoose from "mongoose"
2
2
  import MatchFlowItem from "./item/MatchFlowItem"
3
3
  import PopulateFlowItem from "./item/PopulateFlowItem"
4
4
  import ProjectFlowItem from "./item/ProjectFlowItem"
5
+ import OneToManyFlowItem, { IForeingData } from "../v3/item/OneToManyFlowItem"
5
6
 
6
7
 
7
8
  class GetOneByFilterFlow {
8
9
 
9
- async exec(params: any, model: mongoose.Model<any>) {
10
+ async exec(params: any, model: mongoose.Model<any>, oneToMany: IForeingData[] = []) {
10
11
 
11
12
  let pipeline: any[] = []
12
- pipeline = [...pipeline, ...PopulateFlowItem.exec(params.populate, model),]
13
+ pipeline = [...pipeline, ...PopulateFlowItem.exec(params.populate, model)]
14
+ pipeline = [...pipeline, ...OneToManyFlowItem.execute(oneToMany)]
13
15
  pipeline = [...pipeline, ...ProjectFlowItem.exec(params.select)]
14
16
 
15
17
  let result = await model.aggregate([
@@ -5,6 +5,7 @@ import PopulateFlowItem from "./item/PopulateFlowItem"
5
5
  import SortFlowItem from "./item/SortFlowItem"
6
6
  import ProjectFlowItem from "./item/ProjectFlowItem"
7
7
  import BuildPaginationDataFlowItem from "./item/BuildPaginationDataFlowItem"
8
+ import OneToManyFlowItem, { IForeingData } from "./item/OneToManyFlowItem"
8
9
 
9
10
  export interface IParams {
10
11
  [key: string]: any
@@ -23,7 +24,7 @@ class SearcherV3Flow {
23
24
  let pipelineFacetPaging: any[] = []
24
25
  let pipelineFacetItems: any[] = []
25
26
  pipelineFacetItems = [...pipelineFacetItems, ...GroupFlowItem.execute(params.groupBy, params.sumFields, params.groupDetailed, model)]
26
- pipelineFacetItems = [...pipelineFacetItems, ...PopulateFlowItem.execute(params.populate, model),]
27
+ pipelineFacetItems = [...pipelineFacetItems, ...PopulateFlowItem.execute(params.populate, model)]
27
28
  pipelineFacetItems = [...pipelineFacetItems, ...MatchFlowItem.execute(params, model)]
28
29
  pipelineFacetItems = [...pipelineFacetItems, ...SortFlowItem.execute(params.orderBy, params.orderSense)]
29
30
  pipelineFacetItems = [...pipelineFacetItems, ...ProjectFlowItem.execute(params.select)]
@@ -0,0 +1,30 @@
1
+ import mongoose from "mongoose";
2
+
3
+ export interface IForeingData {
4
+ collectionChild: string;
5
+ parentFieldOnChild: string;
6
+ }
7
+
8
+ class OneToManyFlowItem {
9
+ execute(foreings: IForeingData[]): any[] {
10
+ let collection: any[] = []
11
+ foreings?.forEach((foreing: IForeingData) => {
12
+ const populateClauseLookup: any[] = [
13
+ {
14
+ $lookup: {
15
+ from: foreing.collectionChild, // The collection where user data is stored
16
+ localField: "_id",
17
+ foreignField: foreing.parentFieldOnChild,
18
+ as: foreing.collectionChild
19
+ }
20
+ },
21
+ ]
22
+
23
+ collection = [...collection, ...populateClauseLookup]
24
+ })
25
+
26
+ return collection
27
+ }
28
+ }
29
+
30
+ export default new OneToManyFlowItem