c2-mongoose 2.1.250 → 2.1.252

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.
@@ -105,10 +105,6 @@ var SearcherFlow = /** @class */ (function () {
105
105
  }
106
106
  stagesItems.push({ $sort: this.buildOrdenation() });
107
107
  }
108
- if (this.pageable === true) {
109
- stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 });
110
- stagesItems.push({ $limit: this.limit });
111
- }
112
108
  stagesPaging = [];
113
109
  if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
114
110
  stagesPaging.push.apply(stagesPaging, options.pipelines);
@@ -116,23 +112,32 @@ var SearcherFlow = /** @class */ (function () {
116
112
  if ((0, Utils_1.isNotEmpty)(options.unions)) {
117
113
  stagesPaging.push.apply(stagesPaging, options.unions);
118
114
  }
119
- stagesPaging.push({ $match: this.filters });
120
- stagesPaging.push({ $count: "total" });
121
- stagesPaging.push({
122
- $addFields: {
123
- page: this.pageable === true ? this.page : 1,
124
- limit: this.pageable === true ? this.limit : '$total',
125
- totalPages: this.pageable === true ? {
126
- $cond: {
127
- if: { $eq: ['$total', 0] },
128
- then: 0,
129
- else: { $ceil: { $divide: ['$total', this.limit] } }
130
- }
131
- } : 1,
132
- startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
133
- endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
134
- }
135
- });
115
+ if ((0, Utils_1.isEmpty)(options.paging)) {
116
+ stagesPaging.push({ $match: this.filters });
117
+ stagesPaging.push({ $count: "total" });
118
+ stagesPaging.push({
119
+ $addFields: {
120
+ page: this.pageable === true ? this.page : 1,
121
+ limit: this.pageable === true ? this.limit : '$total',
122
+ totalPages: this.pageable === true ? {
123
+ $cond: {
124
+ if: { $eq: ['$total', 0] },
125
+ then: 0,
126
+ else: { $ceil: { $divide: ['$total', this.limit] } }
127
+ }
128
+ } : 1,
129
+ startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
130
+ endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
131
+ }
132
+ });
133
+ }
134
+ else {
135
+ stagesPaging = __spreadArray(__spreadArray([], stagesPaging, true), options.paging, true);
136
+ }
137
+ if (this.pageable === true) {
138
+ stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 });
139
+ stagesItems.push({ $limit: this.limit });
140
+ }
136
141
  stagesMetadata = [];
137
142
  if ((0, Utils_1.isNotEmpty)(options.metadata)) {
138
143
  stagesMetadata.push.apply(stagesMetadata, options.metadata);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.250",
3
+ "version": "2.1.252",
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",
@@ -44,7 +44,7 @@ class SearcherFlow<D> {
44
44
  async search(options: SearchOptions): Promise<SearchResponse<D>> {
45
45
 
46
46
  let stagesItems: any[] = []
47
-
47
+
48
48
  if (isNotEmpty(options.pipelines)) {
49
49
  stagesItems.push(...options.pipelines)
50
50
  }
@@ -52,21 +52,16 @@ class SearcherFlow<D> {
52
52
  stagesItems.push(...options.unions)
53
53
  }
54
54
 
55
- if (isEmpty(options.pipelines)){
55
+ if (isEmpty(options.pipelines)) {
56
56
  stagesItems.push({ $match: this.filters })
57
-
57
+
58
58
  if (isNotEmpty(this.select)) {
59
59
  stagesItems.push({ $project: BuildSelectSingleFlowItem.build(this.model, this.select) })
60
60
  }
61
61
  stagesItems.push({ $sort: this.buildOrdenation() })
62
62
  }
63
-
64
- if (this.pageable === true) {
65
- stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 })
66
- stagesItems.push({ $limit: this.limit })
67
- }
68
-
69
-
63
+
64
+ ///
70
65
  let stagesPaging: any[] = []
71
66
  if (isNotEmpty(options.pipelines)) {
72
67
  stagesPaging.push(...options.pipelines)
@@ -75,23 +70,33 @@ class SearcherFlow<D> {
75
70
  stagesPaging.push(...options.unions)
76
71
  }
77
72
 
78
- stagesPaging.push({ $match: this.filters })
79
- stagesPaging.push({ $count: "total" })
80
- stagesPaging.push({
81
- $addFields: {
82
- page: this.pageable === true ? this.page : 1,
83
- limit: this.pageable === true ? this.limit : '$total',
84
- totalPages: this.pageable === true ? {
85
- $cond: {
86
- if: { $eq: ['$total', 0] },
87
- then: 0,
88
- else: { $ceil: { $divide: ['$total', this.limit] } }
89
- }
90
- } : 1,
91
- startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
92
- endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
93
- }
94
- })
73
+
74
+ if (isEmpty(options.paging)) {
75
+ stagesPaging.push({ $match: this.filters })
76
+ stagesPaging.push({ $count: "total" })
77
+ stagesPaging.push({
78
+ $addFields: {
79
+ page: this.pageable === true ? this.page : 1,
80
+ limit: this.pageable === true ? this.limit : '$total',
81
+ totalPages: this.pageable === true ? {
82
+ $cond: {
83
+ if: { $eq: ['$total', 0] },
84
+ then: 0,
85
+ else: { $ceil: { $divide: ['$total', this.limit] } }
86
+ }
87
+ } : 1,
88
+ startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
89
+ endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
90
+ }
91
+ })
92
+ } else {
93
+ stagesPaging = [...stagesPaging, ...options.paging]
94
+ }
95
+
96
+ if (this.pageable === true) {
97
+ stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 })
98
+ stagesItems.push({ $limit: this.limit })
99
+ }
95
100
 
96
101
  let stagesMetadata: any[] = []
97
102
  if (isNotEmpty(options.metadata)) {
@@ -154,7 +159,7 @@ class SearcherFlow<D> {
154
159
  };
155
160
  }
156
161
 
157
- extractFieldsOfType(schema: Schema, typing = 'String', parent = ''): string[]{
162
+ extractFieldsOfType(schema: Schema, typing = 'String', parent = ''): string[] {
158
163
  let fieldsTyped: string[] = []
159
164
  Object.keys(schema.paths).forEach((field: string) => {
160
165
  if (schema.paths[field].instance === typing) {
@@ -19,6 +19,7 @@ declare interface PipelineStage {
19
19
  declare interface SearchOptions {
20
20
  unions: PipelineStage[],
21
21
  pipelines: PipelineStage[],
22
+ paging: PipelineStage[],
22
23
  metadata: PipelineStage[],
23
24
  session?: ClientSession
24
25
  }