c2-mongoose 2.1.399 → 2.1.401

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.
@@ -22,23 +22,32 @@ var OneToManyFlowItem = /** @class */ (function () {
22
22
  var collection = [];
23
23
  foreings === null || foreings === void 0 ? void 0 : foreings.forEach(function (foreing) {
24
24
  var labeled = (0, lodash_1.camelCase)(foreing.collectionChild);
25
- var populateClauseLookup = [
26
- {
25
+ var populateClauseLookup = [];
26
+ if (foreing.match) {
27
+ populateClauseLookup.push({
27
28
  $lookup: {
28
29
  from: foreing.collectionChild,
29
30
  let: { localField: '$_id' },
30
31
  localField: "_id",
31
32
  foreignField: foreing.parentFieldOnChild,
33
+ as: labeled,
34
+ pipeline: [
35
+ {
36
+ $match: foreing.match
37
+ },
38
+ ]
39
+ }
40
+ });
41
+ }
42
+ else {
43
+ populateClauseLookup.push({
44
+ $lookup: {
45
+ from: foreing.collectionChild,
46
+ localField: "_id",
47
+ foreignField: foreing.parentFieldOnChild,
32
48
  as: labeled
33
49
  }
34
- },
35
- ];
36
- if (foreing.match) {
37
- populateClauseLookup[0].$lookup.pipeline = [
38
- {
39
- $match: foreing.match
40
- },
41
- ];
50
+ });
42
51
  }
43
52
  collection = __spreadArray(__spreadArray([], collection, true), populateClauseLookup, true);
44
53
  var model = global.connectionMongoose.models[Object.keys(global.connectionMongoose.models).find(function (key) { return global.connectionMongoose.models[key].collection.name === foreing.collectionChild; })];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.399",
3
+ "version": "2.1.401",
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,6 +1,5 @@
1
1
  import { camelCase } from "lodash";
2
2
  import LookupArrayFlowItem from "./LookupArrayFlowItem";
3
- import MatchFlowItem from "./MatchFlowItem";
4
3
  export interface IForeingData {
5
4
  collectionChild: string;
6
5
  parentFieldOnChild: string;
@@ -13,26 +12,35 @@ class OneToManyFlowItem {
13
12
  foreings?.forEach((foreing: IForeingData) => {
14
13
 
15
14
  const labeled = camelCase(foreing.collectionChild)
16
- const populateClauseLookup: any[] = [
17
- {
15
+ const populateClauseLookup: any[] = []
16
+
17
+ if (foreing.match) {
18
+ populateClauseLookup.push({
18
19
  $lookup: {
19
20
  from: foreing.collectionChild, // The collection where user data is stored
20
21
  let: { localField: '$_id' },
21
22
  localField: "_id",
22
23
  foreignField: foreing.parentFieldOnChild,
24
+ as: labeled,
25
+ pipeline: [
26
+ {
27
+ $match:
28
+ foreing.match
29
+ },
30
+ ]
31
+ }
32
+ })
33
+ } else {
34
+ populateClauseLookup.push({
35
+ $lookup: {
36
+ from: foreing.collectionChild, // The collection where user data is stored
37
+ localField: "_id",
38
+ foreignField: foreing.parentFieldOnChild,
23
39
  as: labeled
24
40
  }
25
- },
26
- ]
27
-
28
- if (foreing.match) {
29
- populateClauseLookup[0].$lookup.pipeline = [
30
- {
31
- $match:
32
- foreing.match
33
- },
34
- ]
41
+ })
35
42
  }
43
+
36
44
  collection = [...collection, ...populateClauseLookup]
37
45
 
38
46
  let model = (global as any).connectionMongoose.models[