@resolveio/server-lib 4.5.4 → 4.5.5
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 +107 -44
- package/package.json +1 -1
|
@@ -196,7 +196,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
196
196
|
if (date_field === void 0) { date_field = ''; }
|
|
197
197
|
if (date_interval === void 0) { date_interval = ''; }
|
|
198
198
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
199
|
-
var _a, uniqueSelectedFieldCollections, modelCollection, queryMatchCondition, queryLookups, queryGroupUnwindCollectionPaths, queryUnwindCollectionPaths, initialProjection, queryGroups, queryGroupUnwind, initialGroup, secondInitialGroup, zipLayers, initialNonSumFilterProj, initialNonSumElemAtProj, initialNonSumValueProj, cnt, _loop_1, correctSort_1, _loop_2, i, queryProjection, queryTotals, query, i, res, err_1;
|
|
199
|
+
var _a, uniqueSelectedFieldCollections, modelCollection, queryMatchCondition, queryLookups, queryGroupUnwindCollectionPaths, queryUnwindCollectionPaths, initialProjection, queryGroups, queryGroupUnwind, initialGroup, secondInitialGroup, zipLayers, initialNonSumFilterProj, initialNonSumElemAtProj, initialNonSumValueProj, cnt, _loop_1, group, correctSort_1, _loop_2, i, queryProjection, queryTotals, query, i, res, err_1;
|
|
200
200
|
return __generator(this, function (_b) {
|
|
201
201
|
switch (_b.label) {
|
|
202
202
|
case 0:
|
|
@@ -491,46 +491,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
491
491
|
}
|
|
492
492
|
cnt = 1;
|
|
493
493
|
_loop_1 = function () {
|
|
494
|
-
var group = { $group: { _id: {} } };
|
|
495
|
-
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 1 && (a.leafValueType === 'Average' || a.leafValueType === 'Sum'); })) {
|
|
496
|
-
groupsRow.forEach(function (row) {
|
|
497
|
-
group.$group._id[row.id] = '$_id.' + row.id;
|
|
498
|
-
});
|
|
499
|
-
group.$group['rb_arrays_' + (cnt - 1)] = { '$push': '$rb_arrays_' + (cnt - 1) };
|
|
500
|
-
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt; }).forEach(function (field) {
|
|
501
|
-
group.$group[field.id] = { $first: '$' + field.id };
|
|
502
|
-
});
|
|
503
|
-
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 1; }).forEach(function (field) {
|
|
504
|
-
var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
|
|
505
|
-
if (field.leafValueType === 'Average') {
|
|
506
|
-
group.$group[field.id] = { '$avg': '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
|
|
507
|
-
}
|
|
508
|
-
else if (field.leafValueType === 'Sum') {
|
|
509
|
-
group.$group[field.id] = { '$sum': '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
if (fieldsTotal.length) {
|
|
513
|
-
fieldsTotal.forEach(function (total) {
|
|
514
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === 1; }).forEach(function (field) {
|
|
515
|
-
group.$group[total.id + '_' + field.id] = { $first: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
516
|
-
});
|
|
517
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length < cnt + 1 && a.fieldPath.split('.$').length > 1; }).forEach(function (field) {
|
|
518
|
-
var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
|
|
519
|
-
group.$group[total.id + '_' + field.id] = { $first: '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
|
|
520
|
-
});
|
|
521
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === cnt + 1; }).forEach(function (field) {
|
|
522
|
-
var _a;
|
|
523
|
-
var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
|
|
524
|
-
group.$group[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$rb_arrays_' + (cnt - 1) + '.' + tmpPath, _a);
|
|
525
|
-
});
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
zipLayers.push(group);
|
|
529
|
-
}
|
|
530
494
|
var proj = { $addFields: {} };
|
|
531
|
-
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt + 1; }).forEach(function (field) {
|
|
532
|
-
proj.$addFields[field.id] = 1;
|
|
533
|
-
});
|
|
534
495
|
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 2; })) {
|
|
535
496
|
proj.$addFields['rb_arrays_' + cnt] = {
|
|
536
497
|
$map: {
|
|
@@ -559,10 +520,112 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
559
520
|
}
|
|
560
521
|
});
|
|
561
522
|
zipLayers.push(proj);
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
523
|
+
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 2; })) {
|
|
524
|
+
var proj_1 = { $addFields: {} };
|
|
525
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
|
|
526
|
+
var _a;
|
|
527
|
+
proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id] = {
|
|
528
|
+
$filter: {
|
|
529
|
+
input: '$rb_arrays_' + cnt,
|
|
530
|
+
cond: {
|
|
531
|
+
$and: [
|
|
532
|
+
{ $ne: ['$$this', null] }
|
|
533
|
+
]
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
var path = '$$this';
|
|
538
|
+
for (var k = 0; k <= cnt; k++) {
|
|
539
|
+
path += '.' + field.fieldPath.split('.$.')[k];
|
|
540
|
+
proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push({ $ne: [path, null] });
|
|
541
|
+
}
|
|
542
|
+
if (filterArrayPaths.some(function (a) { return a === field.fieldPath; })) {
|
|
543
|
+
var tmpOr_2 = [];
|
|
544
|
+
var filter = common_1.deepCopy(filterArrays[filterArrayPaths.indexOf(field.fieldPath)]);
|
|
545
|
+
if (filter['$or']) {
|
|
546
|
+
filter['$or'].forEach(function (orVal) {
|
|
547
|
+
var _a;
|
|
548
|
+
tmpOr_2.push((_a = {},
|
|
549
|
+
_a[Object.keys(orVal[Object.keys(orVal)[0]])[0]] = [path, orVal[Object.keys(orVal)[0]][Object.keys(orVal[Object.keys(orVal)[0]])[0]]],
|
|
550
|
+
_a));
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push((_a = {}, _a[Object.keys(filter[Object.keys(filter)[0]])[0]] = [path, filter[Object.keys(filter)[0]][Object.keys(filter[Object.keys(filter)[0]])[0]]], _a));
|
|
555
|
+
}
|
|
556
|
+
if (tmpOr_2.length) {
|
|
557
|
+
proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push({ $or: tmpOr_2 });
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
zipLayers.push(proj_1);
|
|
561
|
+
});
|
|
562
|
+
proj_1 = { $addFields: {} };
|
|
563
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
|
|
564
|
+
proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id] = '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt];
|
|
565
|
+
});
|
|
566
|
+
zipLayers.push(proj_1);
|
|
567
|
+
proj_1 = { $addFields: {} };
|
|
568
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
|
|
569
|
+
if (field.leafValueType === 'Count') {
|
|
570
|
+
proj_1.$addFields[field.id] = { '$size': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
|
|
571
|
+
}
|
|
572
|
+
else if (field.leafValueType === 'Minimum') {
|
|
573
|
+
proj_1.$addFields[field.id] = { '$min': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
|
|
574
|
+
}
|
|
575
|
+
else if (field.leafValueType === 'Maximum') {
|
|
576
|
+
proj_1.$addFields[field.id] = { '$max': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
|
|
577
|
+
}
|
|
578
|
+
else if (field.leafValueType === 'First') {
|
|
579
|
+
proj_1.$addFields[field.id] = { '$arrayElemAt': ['$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1], 0] };
|
|
580
|
+
}
|
|
581
|
+
else if (field.leafValueType === 'Last') {
|
|
582
|
+
proj_1.$addFields[field.id] = { '$arrayElemAt': ['$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1], -1] };
|
|
583
|
+
}
|
|
584
|
+
else if (field.leafValueType === 'Sum') {
|
|
585
|
+
proj_1.$addFields[field.id] = { '$sum': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
|
|
586
|
+
}
|
|
587
|
+
else if (field.leafValueType === 'Average') {
|
|
588
|
+
proj_1.$addFields[field.id] = { '$avg': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
|
|
589
|
+
}
|
|
590
|
+
else { //push
|
|
591
|
+
proj_1.$addFields[field.id] = '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1];
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
zipLayers.push(proj_1);
|
|
595
|
+
group = { $group: { _id: {} } };
|
|
596
|
+
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length > cnt + 1; })) {
|
|
597
|
+
groupsRow.forEach(function (row) {
|
|
598
|
+
group.$group._id[row.id] = '$_id.' + row.id;
|
|
599
|
+
});
|
|
600
|
+
group.$group['rb_arrays_' + (cnt - 1)] = { '$push': '$rb_arrays_' + (cnt - 1) };
|
|
601
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt + 2; }).forEach(function (field) {
|
|
602
|
+
group.$group[field.id] = { $first: '$' + field.id };
|
|
603
|
+
});
|
|
604
|
+
if (fieldsTotal.length) {
|
|
605
|
+
fieldsTotal.forEach(function (total) {
|
|
606
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === 1; }).forEach(function (field) {
|
|
607
|
+
group.$group[total.id + '_' + field.id] = { $first: '$' + total.id + '_' + field.id };
|
|
608
|
+
});
|
|
609
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length < cnt + 2 && a.fieldPath.split('.$').length > 1; }).forEach(function (field) {
|
|
610
|
+
var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
|
|
611
|
+
group.$group[total.id + '_' + field.id] = { $first: '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
|
|
612
|
+
});
|
|
613
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
|
|
614
|
+
var _a;
|
|
615
|
+
var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
|
|
616
|
+
group.$group[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + field.id, _a);
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
zipLayers.push(group);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length > cnt + 2; })) {
|
|
624
|
+
zipLayers.push({ $unwind: {
|
|
625
|
+
path: '$rb_arrays_' + cnt,
|
|
626
|
+
preserveNullAndEmptyArrays: true
|
|
627
|
+
} });
|
|
628
|
+
}
|
|
566
629
|
}
|
|
567
630
|
cnt++;
|
|
568
631
|
};
|