@resolveio/server-lib 4.5.5 → 4.5.6
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 +99 -72
- package/package.json +1 -1
|
@@ -294,49 +294,59 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
294
294
|
selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field) {
|
|
295
295
|
initialProjection[field.fieldPath.split('.$')[0]] = 1;
|
|
296
296
|
});
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
297
|
+
if (selectedFields.some(function (a) { return a.fieldPath.includes('$'); }) || groupsRow.some(function (a) { return a.field.includes('$') || a.field.includes('(Lookup)'); })) {
|
|
298
|
+
initialProjection['rb_arrays_0'] = {
|
|
299
|
+
$map: {
|
|
300
|
+
input: {
|
|
301
|
+
$zip: {
|
|
302
|
+
inputs: [
|
|
303
|
+
// '$chemicals',
|
|
304
|
+
// '$drivers',
|
|
305
|
+
// '$invoices'
|
|
306
|
+
],
|
|
307
|
+
useLongestLength: true
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
as: 'zipped',
|
|
311
|
+
in: {
|
|
312
|
+
// chemicals: {
|
|
313
|
+
// $arrayElemAt: [
|
|
314
|
+
// '$$zipped',
|
|
315
|
+
// 0
|
|
316
|
+
// ]
|
|
317
|
+
// },
|
|
318
|
+
// drivers: {
|
|
319
|
+
// $arrayElemAt: [
|
|
320
|
+
// '$$zipped',
|
|
321
|
+
// 1
|
|
322
|
+
// ]
|
|
323
|
+
// },
|
|
324
|
+
// invoices: {
|
|
325
|
+
// $arrayElemAt: [
|
|
326
|
+
// '$$zipped',
|
|
327
|
+
// 2
|
|
328
|
+
// ]
|
|
329
|
+
// }
|
|
307
330
|
}
|
|
308
|
-
},
|
|
309
|
-
as: 'zipped',
|
|
310
|
-
in: {
|
|
311
|
-
// chemicals: {
|
|
312
|
-
// $arrayElemAt: [
|
|
313
|
-
// '$$zipped',
|
|
314
|
-
// 0
|
|
315
|
-
// ]
|
|
316
|
-
// },
|
|
317
|
-
// drivers: {
|
|
318
|
-
// $arrayElemAt: [
|
|
319
|
-
// '$$zipped',
|
|
320
|
-
// 1
|
|
321
|
-
// ]
|
|
322
|
-
// },
|
|
323
|
-
// invoices: {
|
|
324
|
-
// $arrayElemAt: [
|
|
325
|
-
// '$$zipped',
|
|
326
|
-
// 2
|
|
327
|
-
// ]
|
|
328
|
-
// }
|
|
329
331
|
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
332
|
+
};
|
|
333
|
+
groupsRow.filter(function (a) { return a.field.includes('$'); }).forEach(function (field, index) {
|
|
334
|
+
if (!initialProjection['rb_arrays_0'].$map.input.$zip.inputs.some(function (a) { return a === '$' + field.field.split('.$')[0]; })) {
|
|
335
|
+
initialProjection['rb_arrays_0'].$map.input.$zip.inputs.push('$' + field.field.split('.$')[0]);
|
|
336
|
+
initialProjection['rb_arrays_0'].$map.in[field.field.split('.$')[0]] = {
|
|
337
|
+
$arrayElemAt: ['$$zipped', index]
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field, index) {
|
|
342
|
+
if (!initialProjection['rb_arrays_0'].$map.input.$zip.inputs.some(function (a) { return a === '$' + field.fieldPath.split('.$')[0]; })) {
|
|
343
|
+
initialProjection['rb_arrays_0'].$map.input.$zip.inputs.push('$' + field.fieldPath.split('.$')[0]);
|
|
344
|
+
initialProjection['rb_arrays_0'].$map.in[field.fieldPath.split('.$')[0]] = {
|
|
345
|
+
$arrayElemAt: ['$$zipped', index]
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
340
350
|
queryGroups = [];
|
|
341
351
|
queryGroupUnwind = [];
|
|
342
352
|
initialGroup = null;
|
|
@@ -388,8 +398,10 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
388
398
|
// project next layers
|
|
389
399
|
secondInitialGroup = { _id: {} };
|
|
390
400
|
groupsRow.forEach(function (row) {
|
|
391
|
-
secondInitialGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
392
|
-
|
|
401
|
+
secondInitialGroup._id[row.id] = '$rb_arrays_0.' + row.field.replace(/\.\$/g, '');
|
|
402
|
+
secondInitialGroup.rb_arrays_0 = { '$push': '$rb_arrays_0' };
|
|
403
|
+
secondInitialGroup.count = { '$sum': '$count' };
|
|
404
|
+
selectedFields.filter(function (a) { return !a.fieldPath.includes('$') && a.collection_name === rootCollectionName; }).forEach(function (field) {
|
|
393
405
|
if (field.leafValueType === 'Average') {
|
|
394
406
|
secondInitialGroup[field.id] = { '$avg': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
395
407
|
}
|
|
@@ -428,7 +440,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
428
440
|
initialNonSumFilterProj = null;
|
|
429
441
|
initialNonSumElemAtProj = null;
|
|
430
442
|
initialNonSumValueProj = null;
|
|
431
|
-
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === 2
|
|
443
|
+
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === 2; })) {
|
|
432
444
|
initialNonSumFilterProj = { $addFields: {} };
|
|
433
445
|
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
|
|
434
446
|
var _a;
|
|
@@ -444,9 +456,9 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
444
456
|
}
|
|
445
457
|
}
|
|
446
458
|
};
|
|
447
|
-
if (filterArrayPaths.some(function (a) { return a === field.fieldPath; })) {
|
|
459
|
+
if (filterArrayPaths.some(function (a) { return a.replace(new RegExp(/\.\w+$/g), '') === field.fieldPath.replace(new RegExp(/\.\w+$/g), ''); })) {
|
|
448
460
|
var tmpOr_1 = [];
|
|
449
|
-
var filter = common_1.deepCopy(filterArrays[filterArrayPaths.
|
|
461
|
+
var filter = common_1.deepCopy(filterArrays[filterArrayPaths.findIndex(function (a) { return a.replace(new RegExp(/\.\w+$/), '') === field.fieldPath.replace(new RegExp(/\.\w+$/), ''); })]);
|
|
450
462
|
if (filter['$or']) {
|
|
451
463
|
filter['$or'].forEach(function (orVal) {
|
|
452
464
|
var _a;
|
|
@@ -534,24 +546,37 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
534
546
|
}
|
|
535
547
|
}
|
|
536
548
|
};
|
|
537
|
-
var path = '$$this';
|
|
538
|
-
|
|
539
|
-
|
|
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; })) {
|
|
549
|
+
var path = '$$this' + '.' + field.fieldPath.split('.$.')[cnt];
|
|
550
|
+
proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push({ $ne: [path, null] });
|
|
551
|
+
if (filterArrayPaths.some(function (a) { return a.replace(new RegExp(/\.\w+$/), '') === field.fieldPath.replace(new RegExp(/\.\w+$/), ''); })) {
|
|
543
552
|
var tmpOr_2 = [];
|
|
544
|
-
var filter = common_1.deepCopy(filterArrays[filterArrayPaths.
|
|
553
|
+
var filter = common_1.deepCopy(filterArrays[filterArrayPaths.findIndex(function (a) { return a.replace(new RegExp(/\.\w+$/), '') === field.fieldPath.replace(new RegExp(/\.\w+$/), ''); })]);
|
|
545
554
|
if (filter['$or']) {
|
|
546
555
|
filter['$or'].forEach(function (orVal) {
|
|
547
556
|
var _a;
|
|
557
|
+
var tmpFilterPath = '';
|
|
558
|
+
for (var k = cnt; k < (Object.keys(orVal)[0]).split('.').length; k++) {
|
|
559
|
+
if (tmpFilterPath) {
|
|
560
|
+
tmpFilterPath += '.';
|
|
561
|
+
}
|
|
562
|
+
tmpFilterPath += (Object.keys(orVal)[0]).split('.')[k];
|
|
563
|
+
}
|
|
564
|
+
var filterPath = '$$this.' + tmpFilterPath;
|
|
548
565
|
tmpOr_2.push((_a = {},
|
|
549
|
-
_a[Object.keys(orVal[Object.keys(orVal)[0]])[0]] = [
|
|
566
|
+
_a[Object.keys(orVal[Object.keys(orVal)[0]])[0]] = [filterPath, orVal[Object.keys(orVal)[0]][Object.keys(orVal[Object.keys(orVal)[0]])[0]]],
|
|
550
567
|
_a));
|
|
551
568
|
});
|
|
552
569
|
}
|
|
553
570
|
else {
|
|
554
|
-
|
|
571
|
+
var tmpFilterPath = '';
|
|
572
|
+
for (var k = cnt; k < (Object.keys(filter)[0]).split('.').length; k++) {
|
|
573
|
+
if (tmpFilterPath) {
|
|
574
|
+
tmpFilterPath += '.';
|
|
575
|
+
}
|
|
576
|
+
tmpFilterPath += (Object.keys(filter)[0]).split('.')[k];
|
|
577
|
+
}
|
|
578
|
+
var filterPath = '$$this.' + tmpFilterPath;
|
|
579
|
+
proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push((_a = {}, _a[Object.keys(filter[Object.keys(filter)[0]])[0]] = [filterPath, filter[Object.keys(filter)[0]][Object.keys(filter[Object.keys(filter)[0]])[0]]], _a));
|
|
555
580
|
}
|
|
556
581
|
if (tmpOr_2.length) {
|
|
557
582
|
proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push({ $or: tmpOr_2 });
|
|
@@ -835,16 +860,16 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
835
860
|
});
|
|
836
861
|
}
|
|
837
862
|
if (secondInitialGroup) {
|
|
863
|
+
query.push({
|
|
864
|
+
$unwind: {
|
|
865
|
+
"path": "$rb_arrays_0",
|
|
866
|
+
"preserveNullAndEmptyArrays": true
|
|
867
|
+
}
|
|
868
|
+
});
|
|
838
869
|
query.push({
|
|
839
870
|
$group: secondInitialGroup
|
|
840
871
|
});
|
|
841
872
|
}
|
|
842
|
-
query.push({
|
|
843
|
-
$unwind: {
|
|
844
|
-
"path": "$rb_arrays_0",
|
|
845
|
-
"preserveNullAndEmptyArrays": true
|
|
846
|
-
}
|
|
847
|
-
});
|
|
848
873
|
if (initialNonSumFilterProj) {
|
|
849
874
|
query.push(initialNonSumFilterProj);
|
|
850
875
|
}
|
|
@@ -854,12 +879,14 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
854
879
|
if (initialNonSumValueProj) {
|
|
855
880
|
query.push(initialNonSumValueProj);
|
|
856
881
|
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
882
|
+
if (initialGroup) {
|
|
883
|
+
query.push({
|
|
884
|
+
$unwind: {
|
|
885
|
+
"path": "$rb_arrays_0",
|
|
886
|
+
"preserveNullAndEmptyArrays": true
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
}
|
|
863
890
|
for (i = 0; i < zipLayers.length; i++) {
|
|
864
891
|
query.push(zipLayers[i]);
|
|
865
892
|
}
|
|
@@ -974,11 +1001,11 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
974
1001
|
// }
|
|
975
1002
|
// }
|
|
976
1003
|
// // SORT
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1004
|
+
if (rootOptions.sort && reportType !== 'Tabular Group') {
|
|
1005
|
+
query.push({
|
|
1006
|
+
$sort: rootOptions.sort
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
982
1009
|
// Dated Grouping
|
|
983
1010
|
// if (date_field && date_interval) {
|
|
984
1011
|
// if (date_interval === 'Daily') {
|