c2-mongoose 2.1.375 → 2.1.376

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.
@@ -54,6 +54,7 @@ var LookupArrayFlowItem = /** @class */ (function () {
54
54
  preserveNullAndEmptyArrays: true
55
55
  }
56
56
  });
57
+ populateClauses = __spreadArray(__spreadArray([], populateClauseLookup, true), LookupManyToOneFlowItem_1.default.execute("".concat(previousPath, ".").concat(currentField_1), othersFields, __spreadArray(__spreadArray([], populateClauses, true), populateClauseLookup, true), currentModel), true);
57
58
  }
58
59
  //end code here
59
60
  populateClauseLookup.push({
@@ -72,7 +73,6 @@ var LookupArrayFlowItem = /** @class */ (function () {
72
73
  }
73
74
  }
74
75
  });
75
- populateClauseLookup = __spreadArray(__spreadArray([], populateClauseLookup, true), LookupManyToOneFlowItem_1.default.execute(othersFields, __spreadArray(__spreadArray([], populateClauses, true), populateClauseLookup, true), currentModel), true);
76
76
  return __spreadArray([], populateClauseLookup, true);
77
77
  }
78
78
  catch (error) {
@@ -1,6 +1,6 @@
1
1
  import mongoose from "mongoose";
2
2
  declare class LookupManyToOneFlowItem {
3
- execute(othersFields: string[], previousClauses: any[], model: mongoose.Model<any>): any[];
3
+ execute(previousField: string | undefined, othersFields: string[], previousClauses: any[], model: mongoose.Model<any>): any[];
4
4
  }
5
5
  declare const _default: LookupManyToOneFlowItem;
6
6
  export default _default;
@@ -16,7 +16,8 @@ var GetFieldDefinitionFlowItem_1 = __importDefault(require("./GetFieldDefinition
16
16
  var LookupManyToOneFlowItem = /** @class */ (function () {
17
17
  function LookupManyToOneFlowItem() {
18
18
  }
19
- LookupManyToOneFlowItem.prototype.execute = function (othersFields, previousClauses, model) {
19
+ LookupManyToOneFlowItem.prototype.execute = function (previousField, othersFields, previousClauses, model) {
20
+ if (previousField === void 0) { previousField = ""; }
20
21
  var populateClauseLookup = [];
21
22
  try {
22
23
  var _loop_1 = function () {
@@ -36,15 +37,15 @@ var LookupManyToOneFlowItem = /** @class */ (function () {
36
37
  populateClauseLookup.push({
37
38
  $lookup: {
38
39
  from: collectionName,
39
- localField: nextField,
40
+ localField: "".concat(previousField, ".").concat(nextField),
40
41
  foreignField: "_id",
41
- as: nextField
42
+ as: "".concat(previousField, ".").concat(nextField)
42
43
  }
43
44
  });
44
45
  if (nextType !== 'Array') {
45
46
  populateClauseLookup.push({
46
47
  $addFields: (_a = {},
47
- _a["".concat(nextField)] = { $ifNull: [{ $arrayElemAt: ["$".concat(nextField), 0] }, undefined] },
48
+ _a["".concat(previousField, ".").concat(nextField)] = { $ifNull: [{ $arrayElemAt: ["$".concat(previousField, ".").concat(nextField), 0] }, undefined] },
48
49
  _a)
49
50
  });
50
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.375",
3
+ "version": "2.1.376",
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",
@@ -50,6 +50,11 @@ class LookupArrayFlowItem {
50
50
  preserveNullAndEmptyArrays: true
51
51
  }
52
52
  })
53
+
54
+ populateClauses = [
55
+ ...populateClauseLookup,
56
+ ...LookupManyToOneFlowItem.execute(`${previousPath}.${currentField}`, othersFields, [...populateClauses, ...populateClauseLookup], currentModel)
57
+ ]
53
58
  }
54
59
 
55
60
  //end code here
@@ -68,10 +73,6 @@ class LookupArrayFlowItem {
68
73
  }
69
74
  });
70
75
 
71
- populateClauseLookup = [
72
- ...populateClauseLookup,
73
- ...LookupManyToOneFlowItem.execute(othersFields, [...populateClauses, ...populateClauseLookup], currentModel)]
74
-
75
76
  return [...populateClauseLookup]
76
77
  } catch (error: any) {
77
78
  console.error(error.message)
@@ -2,7 +2,7 @@ import mongoose from "mongoose";
2
2
  import GetFieldDefinitionFlowItem from "./GetFieldDefinitionFlowItem";
3
3
 
4
4
  class LookupManyToOneFlowItem {
5
- execute(othersFields: string[], previousClauses: any[], model: mongoose.Model<any>): any[] {
5
+ execute(previousField: string = "", othersFields: string[], previousClauses: any[], model: mongoose.Model<any>): any[] {
6
6
 
7
7
  let populateClauseLookup = []
8
8
 
@@ -28,9 +28,9 @@ class LookupManyToOneFlowItem {
28
28
  {
29
29
  $lookup: {
30
30
  from: collectionName, // The collection where user data is stored
31
- localField: nextField,
31
+ localField: `${previousField}.${nextField}`,
32
32
  foreignField: "_id",
33
- as: nextField
33
+ as: `${previousField}.${nextField}`
34
34
  }
35
35
  },
36
36
  )
@@ -38,7 +38,7 @@ class LookupManyToOneFlowItem {
38
38
  populateClauseLookup.push(
39
39
  {
40
40
  $addFields: {
41
- [`${nextField}`]: { $ifNull: [{ $arrayElemAt: [`$${nextField}`, 0] }, undefined] },
41
+ [`${previousField}.${nextField}`]: { $ifNull: [{ $arrayElemAt: [`$${previousField}.${nextField}`, 0] }, undefined] },
42
42
  }
43
43
  }
44
44
  )