c2-mongoose 2.1.151 → 2.1.153

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.
@@ -97,23 +97,23 @@ var SearchFlow = /** @class */ (function () {
97
97
  return;
98
98
  }
99
99
  var populates = [];
100
+ var _loop_1 = function () {
101
+ var _b = property.split('.'), first = _b[0], rest = _b.slice(1);
102
+ var nested = rest.join('.');
103
+ var populate = this_1.buildPath(first, nested);
104
+ if (Array.isArray(this_1.select)) {
105
+ var selects = this_1.select.filter(function (sel) { return sel.startsWith("".concat(first, ".")); });
106
+ var select = selects.map(function (sel) { return sel.split(".")[1]; }).join(" ");
107
+ if ((0, Utils_1.isNotEmpty)(select)) {
108
+ populate.select = select;
109
+ }
110
+ }
111
+ populates.push(populate);
112
+ };
113
+ var this_1 = this;
100
114
  for (var _i = 0, _a = this.populate; _i < _a.length; _i++) {
101
115
  var property = _a[_i];
102
- if (property.includes(".")) {
103
- continue;
104
- }
105
- populates.push(property);
106
- // let [first, ...rest] = property.split('.')
107
- // let nested = rest.join('.')
108
- // let populate = this.buildPath(first, nested)
109
- // if (Array.isArray(this.select)) {
110
- // let selects = (this.select as []).filter((sel: string) => sel.startsWith(`${first}.`))
111
- // let select = selects.map((sel: string) => sel.split(".")[1]).join(" ")
112
- // if (isNotEmpty(select)) {
113
- // populate.select = select
114
- // }
115
- // }
116
- // populates.push(populate)
116
+ _loop_1();
117
117
  }
118
118
  return populates;
119
119
  };
@@ -0,0 +1,7 @@
1
+ import { IFacet } from "../../model/Facet";
2
+ import SearchFlow from "../SearchFlow";
3
+ declare class GetStagePaginationFlowItem {
4
+ get(facet: IFacet, searcher: SearchFlow): IFacet;
5
+ }
6
+ declare const _default: GetStagePaginationFlowItem;
7
+ export default _default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var GetStagePaginationFlowItem = /** @class */ (function () {
4
+ function GetStagePaginationFlowItem() {
5
+ }
6
+ GetStagePaginationFlowItem.prototype.get = function (facet, searcher) {
7
+ var facetAfter = facet;
8
+ if (searcher.pageable === true) {
9
+ facetAfter.items.push({ $skip: ((searcher.page - 1) * searcher.limit) || 0 });
10
+ facetAfter.items.push({ $limit: searcher.limit });
11
+ facetAfter.paging = [
12
+ { $count: "total" },
13
+ { $addFields: { page: searcher.page || 1, limit: searcher.limit } }
14
+ ];
15
+ }
16
+ return facetAfter;
17
+ };
18
+ return GetStagePaginationFlowItem;
19
+ }());
20
+ exports.default = new GetStagePaginationFlowItem;
package/dist/index.d.ts CHANGED
@@ -3,8 +3,9 @@ import CrudFlow from "./flow/CrudFlow";
3
3
  import SearchFlow from "./flow/SearchFlow";
4
4
  import BuildPipelineToCountJoinFlowItem from "./flow/item/BuildPipelineToCountJoinFlowItem";
5
5
  import BuildPipelineToJoinFlowItem from "./flow/item/BuildPipelineToJoinFlowItem";
6
+ import { IFacet } from "./model/Facet";
6
7
  import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger";
7
8
  import { Options } from "./types/Options";
8
9
  import { Pagination, SearchResponse } from "./types/SearchResponse";
9
10
  import { initialize } from "./utils/Utils";
10
- export { C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem };
11
+ export { C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, IFacet };
@@ -0,0 +1,13 @@
1
+ interface IFacet {
2
+ items: {
3
+ [key: string]: any;
4
+ $skip?: number;
5
+ $limit?: number;
6
+ }[];
7
+ paging?: {
8
+ [key: string]: any;
9
+ $count?: string;
10
+ $addFields?: {};
11
+ }[];
12
+ }
13
+ export { IFacet };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.151",
3
+ "version": "2.1.153",
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",
@@ -74,21 +74,17 @@ abstract class SearchFlow {
74
74
 
75
75
  var populates = [] as any
76
76
  for (var property of this.populate) {
77
- if (property.includes(".")) {
78
- continue
77
+ let [first, ...rest] = property.split('.')
78
+ let nested = rest.join('.')
79
+ let populate = this.buildPath(first, nested)
80
+ if (Array.isArray(this.select)) {
81
+ let selects = (this.select as []).filter((sel: string) => sel.startsWith(`${first}.`))
82
+ let select = selects.map((sel: string) => sel.split(".")[1]).join(" ")
83
+ if (isNotEmpty(select)) {
84
+ populate.select = select
85
+ }
79
86
  }
80
- populates.push(property)
81
- // let [first, ...rest] = property.split('.')
82
- // let nested = rest.join('.')
83
- // let populate = this.buildPath(first, nested)
84
- // if (Array.isArray(this.select)) {
85
- // let selects = (this.select as []).filter((sel: string) => sel.startsWith(`${first}.`))
86
- // let select = selects.map((sel: string) => sel.split(".")[1]).join(" ")
87
- // if (isNotEmpty(select)) {
88
- // populate.select = select
89
- // }
90
- // }
91
- // populates.push(populate)
87
+ populates.push(populate)
92
88
  }
93
89
 
94
90
  return populates
@@ -0,0 +1,23 @@
1
+ import { IFacet } from "../../model/Facet"
2
+ import SearchFlow from "../SearchFlow"
3
+
4
+ class GetStagePaginationFlowItem {
5
+
6
+ get(facet: IFacet, searcher: SearchFlow): IFacet {
7
+ let facetAfter: IFacet = facet
8
+
9
+ if (searcher.pageable === true) {
10
+ facetAfter.items.push({ $skip: ((searcher.page - 1) * searcher.limit) || 0 })
11
+ facetAfter.items.push({ $limit: searcher.limit })
12
+
13
+ facetAfter.paging = [
14
+ { $count: "total" },
15
+ { $addFields: { page: searcher.page || 1, limit: searcher.limit } }
16
+ ]
17
+ }
18
+
19
+ return facetAfter
20
+ }
21
+ }
22
+
23
+ export default new GetStagePaginationFlowItem
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import CrudFlow from "./flow/CrudFlow"
3
3
  import SearchFlow from "./flow/SearchFlow"
4
4
  import BuildPipelineToCountJoinFlowItem from "./flow/item/BuildPipelineToCountJoinFlowItem"
5
5
  import BuildPipelineToJoinFlowItem from "./flow/item/BuildPipelineToJoinFlowItem"
6
+ import { IFacet } from "./model/Facet"
6
7
  import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger"
7
8
  import { Options } from "./types/Options"
8
9
  import { Pagination, SearchResponse } from "./types/SearchResponse"
@@ -12,6 +13,6 @@ import { initialize } from "./utils/Utils"
12
13
 
13
14
  export {
14
15
  C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize,
15
- BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem
16
+ BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, IFacet
16
17
  }
17
18
 
@@ -0,0 +1,15 @@
1
+ interface IFacet {
2
+ items: {
3
+ [key: string]: any,
4
+ $skip?: number,
5
+ $limit?: number,
6
+ }[],
7
+ paging?: {
8
+ [key: string]: any,
9
+ $count?: string,
10
+ $addFields?: {}
11
+ }[]
12
+ }
13
+
14
+
15
+ export { IFacet }