c2-mongoose 2.1.384 → 2.1.385

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,6 @@
1
1
  import mongoose from "mongoose";
2
2
  declare class LookupArrayFlowItem {
3
- execute(previousPath: string, remainingPath: string[], populateClauses: any[], model: mongoose.Model<any>): any[];
3
+ execute(previousPath: string, remainingPath: string[], populateClauses: any[], model: mongoose.Model<any>, considerPreviousPath?: boolean): any[];
4
4
  }
5
5
  declare const _default: LookupArrayFlowItem;
6
6
  export default _default;
@@ -17,8 +17,9 @@ var LookupManyToOneFlowItem_1 = __importDefault(require("./LookupManyToOneFlowIt
17
17
  var LookupArrayFlowItem = /** @class */ (function () {
18
18
  function LookupArrayFlowItem() {
19
19
  }
20
- LookupArrayFlowItem.prototype.execute = function (previousPath, remainingPath, populateClauses, model) {
20
+ LookupArrayFlowItem.prototype.execute = function (previousPath, remainingPath, populateClauses, model, considerPreviousPath) {
21
21
  var _a, _b;
22
+ if (considerPreviousPath === void 0) { considerPreviousPath = true; }
22
23
  var populateClauseLookup = [];
23
24
  try {
24
25
  populateClauseLookup.push({
@@ -32,9 +33,9 @@ var LookupArrayFlowItem = /** @class */ (function () {
32
33
  if (!currentField_1) {
33
34
  return [];
34
35
  }
35
- var currentFieldDefinition = GetFieldDefinitionFlowItem_1.default.execute(model, "".concat(previousPath, ".").concat(currentField_1));
36
+ var currentFieldDefinition = GetFieldDefinitionFlowItem_1.default.execute(model, "".concat(considerPreviousPath ? "".concat(previousPath, ".") : "").concat(currentField_1));
36
37
  if (!currentFieldDefinition || !currentFieldDefinition.options || !currentFieldDefinition.options.ref) {
37
- throw new Error("[1]No reference found for populate field: ".concat([previousPath, currentField_1]));
38
+ throw new Error("[1]No reference found for populate field: ".concat([considerPreviousPath ? "".concat(previousPath, ".") : "", currentField_1]));
38
39
  }
39
40
  var currentType = currentFieldDefinition.instance;
40
41
  if (currentType === 'Array' && !(othersFields === null || othersFields === void 0 ? void 0 : othersFields.length))
@@ -41,7 +41,7 @@ var OneToManyFlowItem = /** @class */ (function () {
41
41
  var populate_1 = populates_1[_i];
42
42
  var _a = populate_1.split('.'), first = _a[0], rest = _a.slice(1);
43
43
  // collection = [...collection, ...PopulateFlowItem.execute(populates, model)]
44
- collection = __spreadArray(__spreadArray([], collection, true), LookupArrayFlowItem_1.default.execute(first, rest, collection, model), true);
44
+ collection = __spreadArray(__spreadArray([], collection, true), LookupArrayFlowItem_1.default.execute(first, rest, collection, model, false), true);
45
45
  }
46
46
  }
47
47
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.384",
3
+ "version": "2.1.385",
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",
@@ -3,7 +3,7 @@ import GetFieldDefinitionFlowItem from "./GetFieldDefinitionFlowItem";
3
3
  import LookupManyToOneFlowItem from "./LookupManyToOneFlowItem";
4
4
 
5
5
  class LookupArrayFlowItem {
6
- execute(previousPath: string, remainingPath: string[], populateClauses: any[], model: mongoose.Model<any>): any[] {
6
+ execute(previousPath: string, remainingPath: string[], populateClauses: any[], model: mongoose.Model<any>, considerPreviousPath: boolean = true): any[] {
7
7
 
8
8
  let populateClauseLookup = []
9
9
 
@@ -23,9 +23,9 @@ class LookupArrayFlowItem {
23
23
  return []
24
24
  }
25
25
 
26
- let currentFieldDefinition = GetFieldDefinitionFlowItem.execute(model, `${previousPath}.${currentField}`);
26
+ let currentFieldDefinition = GetFieldDefinitionFlowItem.execute(model, `${considerPreviousPath ? `${previousPath}.` : ""}${currentField}`);
27
27
  if (!currentFieldDefinition || !currentFieldDefinition.options || !currentFieldDefinition.options.ref) {
28
- throw new Error(`[1]No reference found for populate field: ${[previousPath, currentField]}`);
28
+ throw new Error(`[1]No reference found for populate field: ${[considerPreviousPath ? `${previousPath}.` : "", currentField]}`);
29
29
  }
30
30
 
31
31
 
@@ -36,7 +36,7 @@ class OneToManyFlowItem {
36
36
  for (const populate of populates) {
37
37
  let [first, ...rest] = populate.split('.')
38
38
  // collection = [...collection, ...PopulateFlowItem.execute(populates, model)]
39
- collection = [...collection, ...LookupArrayFlowItem.execute(first, rest, collection, model)]
39
+ collection = [...collection, ...LookupArrayFlowItem.execute(first, rest, collection, model, false)]
40
40
  }
41
41
  }
42
42