c2-mongoose 2.1.139 → 2.1.140

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.
@@ -15,9 +15,8 @@ declare abstract class SearchFlow {
15
15
  [key: string]: number;
16
16
  } | undefined;
17
17
  constructor(params: any);
18
- buildProjections(): {
19
- [key: string]: number;
20
- } | undefined;
18
+ buildProjections(): any;
19
+ buildProjectionNested(projectCurrent: any, field: string, include: boolean): any;
21
20
  buildPopulate(): any;
22
21
  buildPopulateArray(): void;
23
22
  buildPath(target: string, nested?: string): any;
@@ -72,19 +72,29 @@ var SearchFlow = /** @class */ (function () {
72
72
  return undefined;
73
73
  }
74
74
  var projection = {};
75
- var found = false;
76
75
  for (var _i = 0, _a = this.select; _i < _a.length; _i++) {
77
76
  var field = _a[_i];
78
- if (field.startsWith("-")) {
79
- field = field.substring(1);
80
- projection[field] = 0;
81
- }
82
- else {
83
- projection[field] = 1;
84
- }
77
+ var include = field.startsWith("-") ? false : true;
78
+ projection = __assign(__assign({}, projection), this.buildProjectionNested({}, field, include));
79
+ // if (field.startsWith("-")) {
80
+ // field = field.substring(1)
81
+ // projection[field] = 0;
82
+ // } else {
83
+ // projection[field] = 1;
84
+ // }
85
85
  }
86
86
  return projection;
87
87
  };
88
+ SearchFlow.prototype.buildProjectionNested = function (projectCurrent, field, include) {
89
+ // var projectionAux: { [key: string]: any } = {}
90
+ var _a = field.split('.'), first = _a[0], rest = _a.slice(1);
91
+ if (rest.length === 0) {
92
+ projectCurrent[first] = include ? 1 : 0;
93
+ return projectCurrent;
94
+ }
95
+ projectCurrent[first] = this.buildProjectionNested({}, rest.join("."), include);
96
+ return projectCurrent;
97
+ };
88
98
  SearchFlow.prototype.buildPopulate = function () {
89
99
  if ((0, Utils_1.isEmpty)(this.populate)) {
90
100
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.139",
3
+ "version": "2.1.140",
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",
@@ -35,20 +35,43 @@ abstract class SearchFlow {
35
35
  return undefined
36
36
  }
37
37
 
38
- let projection: { [key: string]: number } = {}
39
- let found = false
38
+ let projection: any = {}
40
39
  for (var field of this.select) {
41
- if (field.startsWith("-")) {
42
- field = field.substring(1)
43
- projection[field] = 0;
44
- } else {
45
- projection[field] = 1;
40
+ let include = field.startsWith("-") ? false : true
41
+ projection = {
42
+ ...projection,
43
+ ...this.buildProjectionNested({}, field, include)
46
44
  }
45
+ // if (field.startsWith("-")) {
46
+ // field = field.substring(1)
47
+ // projection[field] = 0;
48
+ // } else {
49
+ // projection[field] = 1;
50
+ // }
47
51
 
48
52
  }
49
53
  return projection;
50
54
  }
51
55
 
56
+ buildProjectionNested(projectCurrent: any, field: string, include: boolean) {
57
+ // var projectionAux: { [key: string]: any } = {}
58
+ let [first, ...rest] = field.split('.')
59
+
60
+ if (rest.length === 0) {
61
+ projectCurrent[first] = include ? 1 : 0
62
+ return projectCurrent
63
+ }
64
+
65
+ projectCurrent[first] = this.buildProjectionNested({}, rest.join("."), include)
66
+
67
+ return projectCurrent
68
+ }
69
+
70
+
71
+
72
+
73
+
74
+
52
75
  public buildPopulate(): any {
53
76
  if (isEmpty(this.populate)) {
54
77
  return