c2-mongoose 2.1.30 → 2.1.32
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
CHANGED
|
@@ -15,6 +15,6 @@ declare class CrudFlow<D> {
|
|
|
15
15
|
getOne(model: D, params?: any): Promise<D>;
|
|
16
16
|
get(id: string, pop?: string, sel?: string, session?: ClientSession): Promise<D>;
|
|
17
17
|
getById(id: string, session?: ClientSession): Promise<Partial<D>>;
|
|
18
|
-
sumBy(fieldToSum: string, fieldToGroup: string): Promise<any>;
|
|
18
|
+
sumBy(fieldToSum: string, fieldToGroup: string, addToSet: any): Promise<any>;
|
|
19
19
|
}
|
|
20
20
|
export default CrudFlow;
|
package/dist/flow/CrudFlow.js
CHANGED
|
@@ -169,11 +169,11 @@ var CrudFlow = /** @class */ (function () {
|
|
|
169
169
|
});
|
|
170
170
|
});
|
|
171
171
|
};
|
|
172
|
-
CrudFlow.prototype.sumBy = function (fieldToSum, fieldToGroup) {
|
|
172
|
+
CrudFlow.prototype.sumBy = function (fieldToSum, fieldToGroup, addToSet) {
|
|
173
173
|
return __awaiter(this, void 0, void 0, function () {
|
|
174
174
|
return __generator(this, function (_a) {
|
|
175
175
|
switch (_a.label) {
|
|
176
|
-
case 0: return [4 /*yield*/, this.search.sumBy(this.repository, fieldToSum, fieldToGroup)];
|
|
176
|
+
case 0: return [4 /*yield*/, this.search.sumBy(this.repository, fieldToSum, fieldToGroup, addToSet)];
|
|
177
177
|
case 1: return [2 /*return*/, _a.sent()];
|
|
178
178
|
}
|
|
179
179
|
});
|
|
@@ -21,7 +21,7 @@ declare abstract class SearchFlow {
|
|
|
21
21
|
private result;
|
|
22
22
|
count(model: mongoose.Model<any>): Promise<number>;
|
|
23
23
|
findOne(repository: mongoose.Model<any>, model: any, params?: any): Promise<any>;
|
|
24
|
-
sumBy(model: mongoose.Model<any>, _sum: any, _by: any, session?: ClientSession): Promise<any[]>;
|
|
24
|
+
sumBy(model: mongoose.Model<any>, _sum: any, _by: any, _addSet?: any, session?: ClientSession): Promise<any[]>;
|
|
25
25
|
buildDefaultFilters(objectSearch: any): any;
|
|
26
26
|
addFilterModel(model: any, filters: any): void;
|
|
27
27
|
}
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -210,23 +210,30 @@ var SearchFlow = /** @class */ (function () {
|
|
|
210
210
|
});
|
|
211
211
|
});
|
|
212
212
|
};
|
|
213
|
-
SearchFlow.prototype.sumBy = function (model, _sum, _by, session) {
|
|
213
|
+
SearchFlow.prototype.sumBy = function (model, _sum, _by, _addSet, session) {
|
|
214
|
+
if (_addSet === void 0) { _addSet = undefined; }
|
|
214
215
|
return __awaiter(this, void 0, void 0, function () {
|
|
215
|
-
var ret;
|
|
216
|
+
var sort, ret;
|
|
216
217
|
return __generator(this, function (_a) {
|
|
217
218
|
switch (_a.label) {
|
|
218
|
-
case 0:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
case 0:
|
|
220
|
+
sort = this.buildOrdenation();
|
|
221
|
+
return [4 /*yield*/, model.aggregate([
|
|
222
|
+
{
|
|
223
|
+
'$match': this.filters
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
$group: {
|
|
227
|
+
_id: _by,
|
|
228
|
+
totalValue: { "$sum": _sum },
|
|
229
|
+
count: { "$sum": 1 },
|
|
230
|
+
items: _addSet
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
$sort: sort
|
|
227
235
|
}
|
|
228
|
-
|
|
229
|
-
]).session(session)];
|
|
236
|
+
]).session(session)];
|
|
230
237
|
case 1:
|
|
231
238
|
ret = _a.sent();
|
|
232
239
|
return [2 /*return*/, ret];
|
|
@@ -240,7 +247,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
240
247
|
var key = _a[0], value = _a[1];
|
|
241
248
|
if ((0, Utils_1.isNotEmpty)(value)) {
|
|
242
249
|
var condition = {};
|
|
243
|
-
if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
250
|
+
if (['pageable', 'order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
244
251
|
return;
|
|
245
252
|
}
|
|
246
253
|
if (key.endsWith('DateRange') || key.endsWith('DateTimeRange')) {
|
|
@@ -278,9 +285,6 @@ var SearchFlow = /** @class */ (function () {
|
|
|
278
285
|
}
|
|
279
286
|
}
|
|
280
287
|
});
|
|
281
|
-
// if (isNotEmpty(objectSearch.model)) {
|
|
282
|
-
// this.addFilterModel(objectSearch.model, filters)
|
|
283
|
-
// }
|
|
284
288
|
if (filters.$and.length === 0)
|
|
285
289
|
delete filters['$and'];
|
|
286
290
|
return filters;
|
|
@@ -294,7 +298,7 @@ var SearchFlow = /** @class */ (function () {
|
|
|
294
298
|
if (key.endsWith('Like')) {
|
|
295
299
|
return;
|
|
296
300
|
}
|
|
297
|
-
if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
301
|
+
if (['pageable', 'order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
298
302
|
return;
|
|
299
303
|
}
|
|
300
304
|
if ((0, Utils_1.isNotEmpty)(value)) {
|
package/package.json
CHANGED
package/src/flow/CrudFlow.ts
CHANGED
|
@@ -65,8 +65,8 @@ class CrudFlow<D> {
|
|
|
65
65
|
return data as D
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
public async sumBy(fieldToSum: string, fieldToGroup: string): Promise<any> {
|
|
69
|
-
return await this.search.sumBy(this.repository, fieldToSum, fieldToGroup)
|
|
68
|
+
public async sumBy(fieldToSum: string, fieldToGroup: string, addToSet: any): Promise<any> {
|
|
69
|
+
return await this.search.sumBy(this.repository, fieldToSum, fieldToGroup, addToSet)
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -134,7 +134,8 @@ abstract class SearchFlow {
|
|
|
134
134
|
.populate(params.populate)
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
public async sumBy(model: mongoose.Model<any>, _sum: any, _by: any, session?: ClientSession): Promise<any[]> {
|
|
137
|
+
public async sumBy(model: mongoose.Model<any>, _sum: any, _by: any, _addSet: any = undefined, session?: ClientSession): Promise<any[]> {
|
|
138
|
+
const sort = this.buildOrdenation()
|
|
138
139
|
const ret = await model.aggregate(
|
|
139
140
|
[
|
|
140
141
|
{
|
|
@@ -144,8 +145,12 @@ abstract class SearchFlow {
|
|
|
144
145
|
$group: {
|
|
145
146
|
_id: _by,
|
|
146
147
|
totalValue: { "$sum": _sum },
|
|
147
|
-
count: { "$sum": 1 }
|
|
148
|
+
count: { "$sum": 1 },
|
|
149
|
+
items: _addSet
|
|
148
150
|
}
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
$sort: sort
|
|
149
154
|
}
|
|
150
155
|
]
|
|
151
156
|
).session(session!)
|
|
@@ -157,7 +162,7 @@ abstract class SearchFlow {
|
|
|
157
162
|
Object.entries(objectSearch.model).forEach(([key, value]) => {
|
|
158
163
|
if (isNotEmpty(value)) {
|
|
159
164
|
let condition = {} as any
|
|
160
|
-
if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
165
|
+
if (['pageable', 'order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
161
166
|
return
|
|
162
167
|
}
|
|
163
168
|
|
|
@@ -201,11 +206,6 @@ abstract class SearchFlow {
|
|
|
201
206
|
}
|
|
202
207
|
})
|
|
203
208
|
|
|
204
|
-
|
|
205
|
-
// if (isNotEmpty(objectSearch.model)) {
|
|
206
|
-
// this.addFilterModel(objectSearch.model, filters)
|
|
207
|
-
// }
|
|
208
|
-
|
|
209
209
|
if (filters.$and.length === 0)
|
|
210
210
|
delete filters['$and']
|
|
211
211
|
|
|
@@ -220,7 +220,7 @@ abstract class SearchFlow {
|
|
|
220
220
|
if (key.endsWith('Like')) {
|
|
221
221
|
return
|
|
222
222
|
}
|
|
223
|
-
if (['order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
223
|
+
if (['pageable', 'order', 'orderBy', 'properties', 'populate', 'page', 'limit', 'model', 'select', 'searchText', 'isPageable', 'searchPageable'].includes(key)) {
|
|
224
224
|
return
|
|
225
225
|
}
|
|
226
226
|
if (isNotEmpty(value)) {
|