@resolveio/server-lib 4.6.10 → 4.6.11
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/methods/report-builder.js +35 -32
- package/package.json +1 -1
|
@@ -209,14 +209,11 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
209
209
|
if (date_interval === void 0) { date_interval = ''; }
|
|
210
210
|
if (tabularDisplayType === void 0) { tabularDisplayType = ''; }
|
|
211
211
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
212
|
-
var
|
|
212
|
+
var modelCollection, query, initialQueryMatchCondition, sizes, divFields, queryMatchConditionLookup, queryGroup, queryProjection_1, res, err_1, tmpTotals, tmpRes;
|
|
213
213
|
var _this = this;
|
|
214
214
|
return __generator(this, function (_a) {
|
|
215
215
|
switch (_a.label) {
|
|
216
216
|
case 0:
|
|
217
|
-
uniqueSelectedFieldCollections = selectedFields.map(function (a) { return a.collection_name; }).filter(function (elem, index, self) {
|
|
218
|
-
return index === self.indexOf(elem);
|
|
219
|
-
});
|
|
220
217
|
modelCollection = index_1.ResolveIOServer.getMainDB().model(rootCollectionName);
|
|
221
218
|
query = [];
|
|
222
219
|
initialQueryMatchCondition = {
|
|
@@ -250,6 +247,34 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
250
247
|
// Add count
|
|
251
248
|
query.push({ $addFields: { count: { $sum: 1 } } });
|
|
252
249
|
sizes = [];
|
|
250
|
+
filterArrayFields.forEach(function (filterField) {
|
|
251
|
+
var _a, _b;
|
|
252
|
+
var fieldData = filterField.fieldPath.split('.$');
|
|
253
|
+
var fieldPath = '';
|
|
254
|
+
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
255
|
+
fieldPath += fieldData[i];
|
|
256
|
+
if (fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup)')) {
|
|
257
|
+
if (!query.some(function (a) { return a.$lookup && a.$lookup.as === filterField.lookup_as.replace(/\.\$/g, ''); })) {
|
|
258
|
+
query.push({ $lookup: {
|
|
259
|
+
from: filterField.lookup_collection,
|
|
260
|
+
localField: filterField.lookup_local_key,
|
|
261
|
+
foreignField: filterField.lookup_foreign_key,
|
|
262
|
+
as: filterField.lookup_as.replace(/\.\$/g, '')
|
|
263
|
+
} });
|
|
264
|
+
sizes.push(filterField.lookup_as.replace(/\.\$\./g, '_'));
|
|
265
|
+
query.push({ $addFields: (_a = {}, _a['size_' + filterField.lookup_as.replace(/\.\$\./g, '_')] = { $size: '$' + filterField.lookup_as.replace(/\.\$/g, '') }, _a) });
|
|
266
|
+
query.push({ '$unwind': { path: '$' + filterField.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
if (!query.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath.replace(/\./g, '_')); })) {
|
|
271
|
+
sizes.push(fieldPath.replace(/\./g, '_'));
|
|
272
|
+
query.push({ $addFields: (_b = {}, _b['size_' + fieldPath.replace(/\./g, '_')] = { $size: '$' + fieldPath }, _b) });
|
|
273
|
+
query.push({ '$unwind': { path: '$' + fieldPath, preserveNullAndEmptyArrays: true } });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
253
278
|
// Groups - Lookups / Sizes / Unwinds
|
|
254
279
|
groupsRow.forEach(function (row) {
|
|
255
280
|
var _a, _b;
|
|
@@ -312,34 +337,6 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
312
337
|
}
|
|
313
338
|
}
|
|
314
339
|
});
|
|
315
|
-
filterArrayFields.forEach(function (filterField) {
|
|
316
|
-
var _a, _b;
|
|
317
|
-
var fieldData = filterField.fieldPath.split('.$');
|
|
318
|
-
var fieldPath = '';
|
|
319
|
-
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
320
|
-
fieldPath += fieldData[i];
|
|
321
|
-
if (fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup)')) {
|
|
322
|
-
if (!query.some(function (a) { return a.$lookup && a.$lookup.as === filterField.lookup_as.replace(/\.\$/g, ''); })) {
|
|
323
|
-
query.push({ $lookup: {
|
|
324
|
-
from: filterField.lookup_collection,
|
|
325
|
-
localField: filterField.lookup_local_key,
|
|
326
|
-
foreignField: filterField.lookup_foreign_key,
|
|
327
|
-
as: filterField.lookup_as.replace(/\.\$/g, '')
|
|
328
|
-
} });
|
|
329
|
-
sizes.push(filterField.lookup_as.replace(/\.\$\./g, '_'));
|
|
330
|
-
query.push({ $addFields: (_a = {}, _a['size_' + filterField.lookup_as.replace(/\.\$\./g, '_')] = { $size: '$' + filterField.lookup_as.replace(/\.\$/g, '') }, _a) });
|
|
331
|
-
query.push({ '$unwind': { path: '$' + filterField.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
if (!query.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath.replace(/\./g, '_')); })) {
|
|
336
|
-
sizes.push(fieldPath.replace(/\./g, '_'));
|
|
337
|
-
query.push({ $addFields: (_b = {}, _b['size_' + fieldPath.replace(/\./g, '_')] = { $size: '$' + fieldPath }, _b) });
|
|
338
|
-
query.push({ '$unwind': { path: '$' + fieldPath, preserveNullAndEmptyArrays: true } });
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
340
|
divFields = { $addFields: {} };
|
|
344
341
|
fieldsTotal.filter(function (a) { return a.type === 'sum'; }).forEach(function (total) {
|
|
345
342
|
selectedFields.filter(function (a) { return a.fieldType === 'Number'; }).forEach(function (field) {
|
|
@@ -479,6 +476,12 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
479
476
|
else if (field.leafValueType === 'Last') {
|
|
480
477
|
queryGroup[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
481
478
|
}
|
|
479
|
+
else if (field.leafValueType === 'Last') {
|
|
480
|
+
queryGroup[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
481
|
+
}
|
|
482
|
+
else if (field.leafValueType === 'Unique') {
|
|
483
|
+
queryGroup[field.id] = { '$addToSet': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
484
|
+
}
|
|
482
485
|
else {
|
|
483
486
|
queryGroup[field.id] = { '$push': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
484
487
|
}
|