c2-mongoose 2.1.124 → 2.1.126
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.
- package/dist/flow/CrudFlow.d.ts +1 -1
- package/dist/flow/SearchFlow.js +15 -14
- package/package.json +1 -1
- package/src/flow/CrudFlow.ts +1 -1
- package/src/flow/SearchFlow.ts +5 -5
package/dist/flow/CrudFlow.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare class CrudFlow<D> {
|
|
|
12
12
|
update(id: string, data: D, session?: any): Promise<D>;
|
|
13
13
|
updateAny(id: string, data: any, session?: any): Promise<D>;
|
|
14
14
|
updateByModel(filter: any, data: any, params: any): Promise<D>;
|
|
15
|
-
find(options
|
|
15
|
+
find(options: SearchOptions): Promise<SearchResponse<D>>;
|
|
16
16
|
getOne(model: D, session?: ClientSession): Promise<D>;
|
|
17
17
|
get(id: string, pop?: string, sel?: string, session?: ClientSession): Promise<D>;
|
|
18
18
|
getById(id: string, session?: ClientSession): Promise<Partial<D>>;
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -155,10 +155,11 @@ var SearchFlow = /** @class */ (function () {
|
|
|
155
155
|
return new RegExp("".concat(regexExpression), 'i');
|
|
156
156
|
};
|
|
157
157
|
SearchFlow.prototype.searchNoPageable = function (model, options) {
|
|
158
|
+
var _a;
|
|
158
159
|
return __awaiter(this, void 0, void 0, function () {
|
|
159
|
-
var stagesItems, stagesMetadata, facet, _i, stagesMetadata_1, metadata, result, items,
|
|
160
|
-
return __generator(this, function (
|
|
161
|
-
switch (
|
|
160
|
+
var stagesItems, stagesMetadata, facet, _i, stagesMetadata_1, metadata, result, items, _b, _c, populate, resultAux;
|
|
161
|
+
return __generator(this, function (_d) {
|
|
162
|
+
switch (_d.label) {
|
|
162
163
|
case 0:
|
|
163
164
|
stagesItems = [{ $match: this.filters }];
|
|
164
165
|
if ((0, Utils_1.isNotEmpty)(options.unions)) {
|
|
@@ -171,8 +172,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
171
172
|
stagesItems.push.apply(stagesItems, options.pipelines);
|
|
172
173
|
}
|
|
173
174
|
stagesItems.push({ $sort: this.sort });
|
|
174
|
-
stagesItems.push({ $
|
|
175
|
-
stagesItems.push({ $limit: this.limit });
|
|
175
|
+
stagesItems.push({ $limit: (_a = this.limit) !== null && _a !== void 0 ? _a : 50 });
|
|
176
176
|
stagesMetadata = [];
|
|
177
177
|
if ((0, Utils_1.isNotEmpty)(options.metadata)) {
|
|
178
178
|
stagesMetadata.push.apply(stagesMetadata, options.metadata);
|
|
@@ -190,20 +190,20 @@ var SearchFlow = /** @class */ (function () {
|
|
|
190
190
|
},
|
|
191
191
|
]).session(options === null || options === void 0 ? void 0 : options.session)];
|
|
192
192
|
case 1:
|
|
193
|
-
result =
|
|
193
|
+
result = _d.sent();
|
|
194
194
|
items = result[0].items;
|
|
195
195
|
if (!((0, Utils_1.isNotEmpty)(this.populate) && Array.isArray(this.populate))) return [3 /*break*/, 5];
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
_b = 0, _c = this.populate;
|
|
197
|
+
_d.label = 2;
|
|
198
198
|
case 2:
|
|
199
|
-
if (!(
|
|
200
|
-
populate = _b
|
|
199
|
+
if (!(_b < _c.length)) return [3 /*break*/, 5];
|
|
200
|
+
populate = _c[_b];
|
|
201
201
|
return [4 /*yield*/, model.populate(result[0].items, populate)];
|
|
202
202
|
case 3:
|
|
203
|
-
items =
|
|
204
|
-
|
|
203
|
+
items = _d.sent();
|
|
204
|
+
_d.label = 4;
|
|
205
205
|
case 4:
|
|
206
|
-
|
|
206
|
+
_b++;
|
|
207
207
|
return [3 /*break*/, 2];
|
|
208
208
|
case 5:
|
|
209
209
|
resultAux = this.transformObject(result[0]);
|
|
@@ -288,7 +288,8 @@ var SearchFlow = /** @class */ (function () {
|
|
|
288
288
|
transformedObject[key] = originalObject[key];
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
|
|
291
|
+
var hasPagination = (originalObject === null || originalObject === void 0 ? void 0 : originalObject.paging) ? true : false;
|
|
292
|
+
return __assign(__assign({}, transformedObject), { metadata: metadata, paging: hasPagination ? (originalObject === null || originalObject === void 0 ? void 0 : originalObject.paging[0]) || { total: 0, page: 1, limit: this.limit } : undefined });
|
|
292
293
|
};
|
|
293
294
|
SearchFlow.prototype.search = function (model, options) {
|
|
294
295
|
return __awaiter(this, void 0, void 0, function () {
|
package/package.json
CHANGED
package/src/flow/CrudFlow.ts
CHANGED
|
@@ -44,7 +44,7 @@ class CrudFlow<D> {
|
|
|
44
44
|
return dataAfter as D
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
public async find(options
|
|
47
|
+
public async find(options: SearchOptions): Promise<SearchResponse<D>> {
|
|
48
48
|
return await this.search.search(this.repository, options)
|
|
49
49
|
}
|
|
50
50
|
|
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import moment from "moment"
|
|
2
2
|
import mongoose, { ClientSession, Types } from "mongoose"
|
|
3
|
-
import {
|
|
4
|
-
import { Pagination, SearchOptions, SearchResponse } from "../types/SearchResponse"
|
|
3
|
+
import { SearchOptions, SearchResponse } from "../types/SearchResponse"
|
|
5
4
|
import { isEmpty, isNotEmpty } from "../utils/Utils"
|
|
6
5
|
|
|
7
6
|
abstract class SearchFlow {
|
|
@@ -139,8 +138,7 @@ abstract class SearchFlow {
|
|
|
139
138
|
}
|
|
140
139
|
|
|
141
140
|
stagesItems.push({ $sort: this.sort })
|
|
142
|
-
stagesItems.push({ $
|
|
143
|
-
stagesItems.push({ $limit: this.limit })
|
|
141
|
+
stagesItems.push({ $limit: this.limit ?? 50 })
|
|
144
142
|
|
|
145
143
|
let stagesMetadata: any[] = []
|
|
146
144
|
if (isNotEmpty(options.metadata)) {
|
|
@@ -253,10 +251,12 @@ abstract class SearchFlow {
|
|
|
253
251
|
}
|
|
254
252
|
}
|
|
255
253
|
|
|
254
|
+
let hasPagination = originalObject?.paging ? true : false
|
|
255
|
+
|
|
256
256
|
return {
|
|
257
257
|
...transformedObject,
|
|
258
258
|
metadata,
|
|
259
|
-
paging: originalObject?.paging[0] || { total: 0, page: 1, limit: this.limit },
|
|
259
|
+
paging: hasPagination ? originalObject?.paging[0] || { total: 0, page: 1, limit: this.limit } : undefined,
|
|
260
260
|
};
|
|
261
261
|
}
|
|
262
262
|
|