c2-mongoose 2.1.46 → 2.1.48

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,7 +15,7 @@ declare class CrudFlow<D> {
15
15
  update(id: string, data: D, session?: any): Promise<D>;
16
16
  updateAny(id: string, data: any, session?: any): Promise<D>;
17
17
  updateByModel(filter: any, data: any, params: any): Promise<D>;
18
- find(...pipelineStages: PipelineStage[]): Promise<SearchResponse<D>>;
18
+ find(pipelineStages?: PipelineStage[]): Promise<SearchResponse<D>>;
19
19
  getOne(model: D, params?: any): Promise<D>;
20
20
  get(id: string, pop?: string, sel?: string, session?: ClientSession): Promise<D>;
21
21
  getById(id: string, session?: ClientSession): Promise<Partial<D>>;
@@ -123,11 +123,7 @@ var CrudFlow = /** @class */ (function () {
123
123
  });
124
124
  });
125
125
  };
126
- CrudFlow.prototype.find = function () {
127
- var pipelineStages = [];
128
- for (var _i = 0; _i < arguments.length; _i++) {
129
- pipelineStages[_i] = arguments[_i];
130
- }
126
+ CrudFlow.prototype.find = function (pipelineStages) {
131
127
  return __awaiter(this, void 0, void 0, function () {
132
128
  return __generator(this, function (_a) {
133
129
  switch (_a.label) {
@@ -46,6 +46,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
49
58
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
60
  };
@@ -138,32 +147,33 @@ var SearchFlow = /** @class */ (function () {
138
147
  };
139
148
  SearchFlow.prototype.searchPageable = function (model, pipeline) {
140
149
  return __awaiter(this, void 0, void 0, function () {
141
- var result;
150
+ var stagesItems, result;
142
151
  return __generator(this, function (_a) {
143
152
  switch (_a.label) {
144
- case 0: return [4 /*yield*/, model.aggregate([
145
- {
146
- $facet: {
147
- items: [
148
- { $match: this.filters },
149
- { $sort: this.sort },
150
- { $skip: (this.page - 1) * this.limit },
151
- { $limit: this.limit },
152
- pipeline
153
- ],
154
- paging: [
155
- { $match: this.filters },
156
- { $count: "total" },
157
- {
158
- $addFields: {
159
- page: this.page,
160
- limit: this.limit
153
+ case 0:
154
+ stagesItems = __spreadArray([
155
+ { $match: this.filters },
156
+ { $sort: this.sort },
157
+ { $skip: (this.page - 1) * this.limit },
158
+ { $limit: this.limit }
159
+ ], pipeline, true);
160
+ return [4 /*yield*/, model.aggregate([
161
+ {
162
+ $facet: {
163
+ items: stagesItems,
164
+ paging: [
165
+ { $match: this.filters },
166
+ { $count: "total" },
167
+ {
168
+ $addFields: {
169
+ page: this.page,
170
+ limit: this.limit
171
+ }
161
172
  }
162
- }
163
- ]
173
+ ]
174
+ }
164
175
  }
165
- }
166
- ])];
176
+ ])];
167
177
  case 1:
168
178
  result = _a.sent();
169
179
  return [2 /*return*/, result[0]];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.46",
3
+ "version": "2.1.48",
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",
@@ -47,7 +47,7 @@ class CrudFlow<D> {
47
47
  return dataAfter as D
48
48
  }
49
49
 
50
- public async find(...pipelineStages: PipelineStage[]): Promise<SearchResponse<D>> {
50
+ public async find(pipelineStages?: PipelineStage[]): Promise<SearchResponse<D>> {
51
51
  return await this.search.search(this.repository, pipelineStages)
52
52
  }
53
53
 
@@ -75,17 +75,19 @@ abstract class SearchFlow {
75
75
  }
76
76
 
77
77
  async searchPageable(model: mongoose.Model<any>, pipeline: any) {
78
+ let stagesItems = [
79
+ { $match: this.filters },
80
+ { $sort: this.sort },
81
+ { $skip: (this.page - 1) * this.limit },
82
+ { $limit: this.limit },
83
+ ...pipeline
84
+ ]
85
+
78
86
  const result = await model.aggregate(
79
87
  [
80
88
  {
81
89
  $facet: {
82
- items: [
83
- { $match: this.filters },
84
- { $sort: this.sort },
85
- { $skip: (this.page - 1) * this.limit },
86
- { $limit: this.limit },
87
- pipeline
88
- ],
90
+ items: stagesItems,
89
91
  paging: [
90
92
  { $match: this.filters },
91
93
  { $count: "total" },