c2-mongoose 2.1.456 → 2.1.458

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.
@@ -25,8 +25,8 @@ var PopulateV3FlowItem = /** @class */ (function () {
25
25
  var populateClauses = [];
26
26
  populatesFields === null || populatesFields === void 0 ? void 0 : populatesFields.forEach(function (populateField) {
27
27
  var _a, _b;
28
- var _c, _d, _e, _f, _g, _h;
29
- var _j = populateField.split('.'), first = _j[0], rest = _j.slice(1);
28
+ var _c, _d, _e, _f, _g, _h, _j, _k;
29
+ var _l = populateField.split('.'), first = _l[0], rest = _l.slice(1);
30
30
  var fieldDefinition = GetFieldDefinitionFlowItem_1.default.execute(modelRoot, first);
31
31
  if (!fieldDefinition)
32
32
  return;
@@ -74,6 +74,7 @@ var PopulateV3FlowItem = /** @class */ (function () {
74
74
  }
75
75
  if ((rest === null || rest === void 0 ? void 0 : rest.length) > 0) {
76
76
  var pathRelativeCurrent_1 = first;
77
+ // let typeFirst = fieldDefinition.instance
77
78
  for (var _i = 0, rest_1 = rest; _i < rest_1.length; _i++) {
78
79
  var nextField = rest_1[_i];
79
80
  pathRelativeCurrent_1 += ".".concat(nextField);
@@ -84,7 +85,10 @@ var PopulateV3FlowItem = /** @class */ (function () {
84
85
  if (!fieldDefinition || !fieldDefinition.options || !((_h = fieldDefinition.options.type[0]) === null || _h === void 0 ? void 0 : _h.ref)) {
85
86
  throw new Error("[1]No reference found for populate field: ".concat(populateField));
86
87
  }
87
- modelName = fieldDefinition.options.ref;
88
+ if (!fieldDefinition)
89
+ return;
90
+ typeFirst = fieldDefinition.instance;
91
+ modelName = (_j = fieldDefinition.options.ref) !== null && _j !== void 0 ? _j : (_k = fieldDefinition.options.type[0]) === null || _k === void 0 ? void 0 : _k.ref;
88
92
  refModel = global.connectionMongoose.model(modelName);
89
93
  collectionName = refModel.collection.name;
90
94
  var populateClauseLookup = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.456",
3
+ "version": "2.1.458",
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",
@@ -73,6 +73,7 @@ class PopulateV3FlowItem {
73
73
 
74
74
  if (rest?.length > 0) {
75
75
  let pathRelativeCurrent = first
76
+ // let typeFirst = fieldDefinition.instance
76
77
  for (const nextField of rest) {
77
78
  pathRelativeCurrent += `.${nextField}`
78
79
  if (populateClauses.some((populateClause: any) => populateClause?.$lookup?.localField.startsWith(pathRelativeCurrent))) {
@@ -83,7 +84,11 @@ class PopulateV3FlowItem {
83
84
  if (!fieldDefinition || !fieldDefinition.options || !fieldDefinition.options.type[0]?.ref) {
84
85
  throw new Error(`[1]No reference found for populate field: ${populateField}`);
85
86
  }
86
- modelName = fieldDefinition.options.ref;
87
+
88
+ if (!fieldDefinition) return;
89
+ typeFirst = fieldDefinition.instance
90
+
91
+ modelName = fieldDefinition.options.ref ?? fieldDefinition.options.type[0]?.ref;
87
92
  refModel = (global as any).connectionMongoose.model(modelName);
88
93
  collectionName = refModel.collection.name;
89
94