@resolveio/server-lib 6.4.3-newrole → 6.4.4

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.
@@ -163,6 +163,15 @@ function loadReportBuilderMethods(methodManager) {
163
163
  optional: true,
164
164
  blackbox: true
165
165
  },
166
+ customFields: {
167
+ type: Array,
168
+ optional: true
169
+ },
170
+ 'customFields.$': {
171
+ type: Object,
172
+ optional: true,
173
+ blackbox: true
174
+ },
166
175
  groupsRow: {
167
176
  type: Array
168
177
  },
@@ -197,12 +206,13 @@ function loadReportBuilderMethods(methodManager) {
197
206
  optional: true
198
207
  }
199
208
  }),
200
- function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayFields, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval, tabularDisplayType) {
209
+ function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayFields, selectedFields, customFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval, tabularDisplayType) {
201
210
  var _this = this;
202
211
  if (filters === void 0) { filters = []; }
203
212
  if (filterArrays === void 0) { filterArrays = []; }
204
213
  if (filterArrayFields === void 0) { filterArrayFields = []; }
205
214
  if (selectedFields === void 0) { selectedFields = []; }
215
+ if (customFields === void 0) { customFields = []; }
206
216
  if (groupsRow === void 0) { groupsRow = []; }
207
217
  if (fieldsTotal === void 0) { fieldsTotal = []; }
208
218
  if (fieldsLink === void 0) { fieldsLink = []; }
@@ -276,6 +286,61 @@ function loadReportBuilderMethods(methodManager) {
276
286
  }
277
287
  }
278
288
  });
289
+ customFields.forEach(function (cust) {
290
+ cust.operations.filter(function (a) { return a.operation && !a.fields.some(function (b) { return (b.field === null || b.field === '') && b.value === null; }); }).forEach(function (operation, opIndex) {
291
+ var _a, _b;
292
+ var custFieldGroup = {};
293
+ if (operation.operation === 'divide') {
294
+ var condCheck_1 = [];
295
+ operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
296
+ if (field.field) {
297
+ condCheck_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), 0] });
298
+ condCheck_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), null] });
299
+ }
300
+ else {
301
+ condCheck_1.push({ $eq: [field.value, 0] });
302
+ condCheck_1.push({ $eq: [field.value, null] });
303
+ }
304
+ });
305
+ if (opIndex > 0) {
306
+ condCheck_1.push({ $eq: ['$' + cust.selFieldId, 0] });
307
+ condCheck_1.push({ $eq: ['$' + cust.selFieldId, null] });
308
+ }
309
+ var tmpOperationFields_1 = [];
310
+ if (opIndex > 0) {
311
+ tmpOperationFields_1.push('$' + cust.selFieldId);
312
+ }
313
+ operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
314
+ if (field.field) {
315
+ tmpOperationFields_1.push('$' + field.field.replace(/\.\$/g, ''));
316
+ }
317
+ else {
318
+ tmpOperationFields_1.push(field.value);
319
+ }
320
+ });
321
+ custFieldGroup[cust.selFieldId] = {
322
+ $cond: { if: { $or: condCheck_1 }, then: 0, else: (_a = {}, _a['$' + operation.operation] = tmpOperationFields_1, _a) }
323
+ };
324
+ }
325
+ else {
326
+ custFieldGroup[cust.selFieldId] = (_b = {},
327
+ _b['$' + operation.operation] = [],
328
+ _b);
329
+ if (opIndex > 0) {
330
+ custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $eq: ['$' + cust.selFieldId, null] }, then: 0, else: '$' + cust.selFieldId } });
331
+ }
332
+ operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
333
+ if (field.field) {
334
+ custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $eq: ['$' + field.field.replace(/\.\$/g, ''), null] }, then: 0, else: '$' + field.field.replace(/\.\$/g, '') } });
335
+ }
336
+ else {
337
+ custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $eq: [field.value, null] }, then: 0, else: field.value } });
338
+ }
339
+ });
340
+ }
341
+ query.push({ $addFields: custFieldGroup });
342
+ });
343
+ });
279
344
  // Groups - Lookups / Sizes / Unwinds
280
345
  groupsRow.forEach(function (row) {
281
346
  var _a, _b;
@@ -373,6 +438,20 @@ function loadReportBuilderMethods(methodManager) {
373
438
  }
374
439
  }
375
440
  });
441
+ customFields.forEach(function (field) {
442
+ var multFields = [];
443
+ sizes.forEach(function (size) {
444
+ multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
445
+ });
446
+ if (multFields.length) {
447
+ divFields.$addFields[total.id + '_' + field.id] = {
448
+ $divide: ['$' + field.selFieldId, { $multiply: multFields }]
449
+ };
450
+ }
451
+ else {
452
+ divFields.$addFields[total.id + '_' + field.selFieldId] = '$' + field.selFieldId;
453
+ }
454
+ });
376
455
  });
377
456
  selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Sum'; }).forEach(function (field) {
378
457
  var multFields = [];
@@ -485,13 +564,18 @@ function loadReportBuilderMethods(methodManager) {
485
564
  queryGroup[field.id] = { '$push': '$' + field.fieldPath.replace(/\.\$/g, '') };
486
565
  }
487
566
  });
567
+ customFields.forEach(function (cust) {
568
+ queryGroup[cust.selFieldId] = { '$first': '$' + cust.selFieldId };
569
+ });
488
570
  // Totals
489
571
  if (fieldsTotal.length) {
490
572
  fieldsTotal.forEach(function (total) {
491
573
  selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
492
- // queryGroup[total.id + '_' + field.id] = {['$' + total.type]: '$' + total.id + '_' + field.id};
493
574
  queryGroup[total.id + '_' + field.id] = { $sum: '$' + total.id + '_' + field.id };
494
575
  });
576
+ customFields.forEach(function (field) {
577
+ queryGroup[total.id + '_' + field.selFieldId] = { $sum: '$' + total.id + '_' + field.selFieldId };
578
+ });
495
579
  });
496
580
  }
497
581
  query.push({ $group: queryGroup });
@@ -526,6 +610,9 @@ function loadReportBuilderMethods(methodManager) {
526
610
  queryProjection_1[field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
527
611
  }
528
612
  });
613
+ customFields.forEach(function (cust) {
614
+ queryProjection_1[cust.selFieldId] = '$' + cust.selFieldId;
615
+ });
529
616
  //Totals
530
617
  if (fieldsTotal.length && (reportType === 'Tabular' || reportType === 'Dated')) {
531
618
  fieldsTotal.forEach(function (total) {
@@ -533,6 +620,10 @@ function loadReportBuilderMethods(methodManager) {
533
620
  var _a;
534
621
  queryProjection_1[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.id, _a);
535
622
  });
623
+ customFields.forEach(function (field) {
624
+ var _a;
625
+ queryProjection_1[total.id + '_' + field.selFieldId] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.selFieldId, _a);
626
+ });
536
627
  });
537
628
  }
538
629
  query.push({ $project: queryProjection_1 });
@@ -586,6 +677,9 @@ function loadReportBuilderMethods(methodManager) {
586
677
  _loop_1(i);
587
678
  }
588
679
  }
680
+ console.log('_____________ query __________');
681
+ console.log(query);
682
+ console.log(JSON.stringify(query, null, 2));
589
683
  res = null;
590
684
  _a.label = 1;
591
685
  case 1:
@@ -610,6 +704,14 @@ function loadReportBuilderMethods(methodManager) {
610
704
  tmpTotals[totField.id + '_' + selField.id] = Math.round(res.map(function (a) { return a[totField.id + '_' + selField.id] || 0; }).reduce(function (a, b) { return a + b; }, 0) / res.length);
611
705
  }
612
706
  });
707
+ customFields.forEach(function (custField) {
708
+ if (totField.type === 'sum') {
709
+ tmpTotals[totField.id + '_' + custField.selFieldId] = res.map(function (a) { return a[totField.id + '_' + custField.selFieldId] || 0; }).reduce(function (a, b) { return a + b; }, 0);
710
+ }
711
+ else if (totField.type === 'avg') {
712
+ tmpTotals[totField.id + '_' + custField.selFieldId] = Math.round(res.map(function (a) { return a[totField.id + '_' + custField.selFieldId] || 0; }).reduce(function (a, b) { return a + b; }, 0) / res.length);
713
+ }
714
+ });
613
715
  });
614
716
  }
615
717
  tmpRes = [{
@@ -627,808 +729,5 @@ function loadReportBuilderMethods(methodManager) {
627
729
  });
628
730
  }
629
731
  exports.loadReportBuilderMethods = loadReportBuilderMethods;
630
- // let queryGroupUnwindCollectionPaths = [];
631
- // groupsRow.filter(a => a.treeItem.fieldPath.includes('$')).forEach(field => {
632
- // let arrayPartData = field.treeItem.fieldPath.split('.$');
633
- // let path = '$';
634
- // for (let i = 0; i < arrayPartData.length - 1; i++) {
635
- // path += arrayPartData[i];
636
- // if (!queryGroupUnwindCollectionPaths.filter(a => a === path)[0]) {
637
- // queryGroupUnwindCollectionPaths.push(path);
638
- // }
639
- // }
640
- // });
641
- // // Unwind
642
- // let queryUnwindCollectionPaths = [];
643
- // selectedFields.filter(a => a.fieldPath.includes('$')).forEach(field => {
644
- // let arrayPartData = field.fieldPath.split('.$');
645
- // let path = '$';
646
- // for (let i = 0; i < arrayPartData.length - 1; i++) {
647
- // path += arrayPartData[i];
648
- // if (!queryUnwindCollectionPaths.some(a => a === path) && !queryGroupUnwindCollectionPaths.some(a => a === path)) {
649
- // queryUnwindCollectionPaths.push(path);
650
- // }
651
- // }
652
- // });
653
- // //Links
654
- // if (fieldsLink.length) {
655
- // fieldsLink.filter(a => a.field_first && a.field_second).forEach(link => {
656
- // queryGroup[link.id] = {$cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')]};
657
- // });
658
- // }
659
- // if (rootOptions.sort && reportType === 'Tabular Group') {
660
- // let correctSort = {};
661
- // Object.keys(rootOptions.sort).forEach(key => {
662
- // correctSort[selectedFields.filter(a => a.id === key)[0].fieldPath.replace(/\.\$/g, '')] = rootOptions.sort[key];
663
- // });
664
- // queryGroups.push({
665
- // $sort: correctSort
666
- // });
667
- // }
668
- /* --------------------- START IF GROUP ---------------------- */
669
- // Lookups for Groups
670
- // let groupQueries = [];
671
- // groupsRow.forEach(row => {
672
- // if (row.field.includes('$')) {
673
- // let fieldData = row.field.split('.$');
674
- // let fieldPath = '';
675
- // for (let i = 0; i < fieldData.length - 1; i++) {
676
- // fieldPath += fieldData[i];
677
- // if (fieldPath.includes('(Lookup)')) {
678
- // groupQueries.push({$lookup: {
679
- // from: row.treeItem.lookup_collection,
680
- // localField: row.treeItem.lookup_local_key,
681
- // foreignField: row.treeItem.lookup_foreign_key,
682
- // as: row.treeItem.lookup_as.replace(/\.\$/g, '')
683
- // }});
684
- // if (i === 0) {
685
- // if (fieldsTotal.length) {
686
- // let addFields = {$addFields: {}};
687
- // fieldsTotal.forEach(total => {
688
- // selectedFields.filter(a => !a.fieldPath.include('.$') && a.fieldType === 'Number').forEach(field => {
689
- // addFields.$addFields[total.id + '_' + field.id] = {
690
- // $divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), {$multiply: [{$cond: { if: { $gt: [{$size: '$' + row.treeItem.lookup_as.replace(/\.\$/g, '')} , 0 ] }, then: {$size: '$' + row.treeItem.lookup_as.replace(/\.\$/g, '')}, else: 1 }}]}]
691
- // };
692
- // });
693
- // });
694
- // if (Object.entries(addFields.$addFields).length > 0) {
695
- // groupQueries.push(addFields);
696
- // }
697
- // }
698
- // }
699
- // // total_1_f_0: {
700
- // // $divide: ['$loaded_miles.loaded_miles', {$multiply: [{$size: '$chemicals'}] } ]
701
- // // },
702
- // // total_1_f_1: {
703
- // // $divide: ['$wo_number', {$size: '$chemicals'}]
704
- // // }
705
- // // groupQueries.push({'$unwind': {path: '$' + row.treeItem.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true}});
706
- // }
707
- // if (i === 0) {
708
- // if (fieldsTotal.length) {
709
- // let addFields = {$addFields: {}};
710
- // fieldsTotal.forEach(total => {
711
- // selectedFields.filter(a => !a.fieldPath.includes('.$') && a.fieldType === 'Number' && !groupQueries.some(b => b.$addFields && Object.keys(b.$addFields).includes(total.id + '_' + a.id))).forEach(field => {
712
- // addFields.$addFields[total.id + '_' + field.id] = {
713
- // $divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), {$multiply: [{$cond: { if: { $gt: [{$size: '$' + fieldPath} , 0 ] }, then: {$size: '$' + fieldPath}, else: 1 }}]}]
714
- // };
715
- // });
716
- // });
717
- // if (Object.entries(addFields.$addFields).length > 0) {
718
- // groupQueries.push(addFields);
719
- // }
720
- // }
721
- // }
722
- // groupQueries.push({'$unwind': {path: '$' + fieldPath, preserveNullAndEmptyArrays: true}});
723
- // if (fieldsTotal.length) {
724
- // let addFields = {$addFields: {}};
725
- // fieldsTotal.forEach(total => {
726
- // selectedFields.filter(a => a.fieldPath.replace(/\.\$/g, '').includes(fieldPath) && a.fieldPath.split('.$').length === 2 && a.fieldType === 'Number').forEach(field => {
727
- // addFields.$addFields[total.id + '_' + field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
728
- // });
729
- // });
730
- // if (Object.entries(addFields.$addFields).length > 0) {
731
- // groupQueries.push(addFields);
732
- // }
733
- // }
734
- // }
735
- // }
736
- // });
737
- // if (!groupsRow.length) {
738
- // selectedFields.forEach(field => {
739
- // let fieldData = field.fieldPath.split('.$');
740
- // let fieldPath = '';
741
- // for (let i = 0; i < fieldData.length - 1; i++) {
742
- // fieldPath += fieldData[i];
743
- // if (fieldPath.includes('(Lookup)')) {
744
- // groupQueries.push({$lookup: {
745
- // from: field.lookup_collection,
746
- // localField: field.lookup_local_key,
747
- // foreignField: field.lookup_foreign_key,
748
- // as: field.lookup_as.replace(/\.\$/g, '')
749
- // }});
750
- // if (i === 0) {
751
- // if (fieldsTotal.length) {
752
- // let addFields = {$addFields: {}};
753
- // fieldsTotal.forEach(total => {
754
- // selectedFields.filter(a => !a.fieldPath.include('.$') && a.fieldType === 'Number').forEach(field => {
755
- // addFields.$addFields[total.id + '_' + field.id] = {
756
- // $divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), {$multiply: [{$cond: { if: { $gt: [{$size: '$' + field.lookup_as.replace(/\.\$/g, '')} , 0 ] }, then: {$size: '$' + field.lookup_as.replace(/\.\$/g, '')}, else: 1 }}]}]
757
- // };
758
- // });
759
- // });
760
- // if (Object.entries(addFields.$addFields).length > 0) {
761
- // groupQueries.push(addFields);
762
- // }
763
- // }
764
- // }
765
- // // total_1_f_0: {
766
- // // $divide: ['$loaded_miles.loaded_miles', {$multiply: [{$size: '$chemicals'}] } ]
767
- // // },
768
- // // total_1_f_1: {
769
- // // $divide: ['$wo_number', {$size: '$chemicals'}]
770
- // // }
771
- // // groupQueries.push({'$unwind': {path: '$' + field.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true}});
772
- // }
773
- // if (i === 0) {
774
- // if (fieldsTotal.length) {
775
- // let addFields = {$addFields: {}};
776
- // fieldsTotal.forEach(total => {
777
- // selectedFields.filter(a => !a.fieldPath.includes('.$') && a.fieldType === 'Number' && !groupQueries.some(b => b.$addFields && Object.keys(b.$addFields).includes(total.id + '_' + a.id))).forEach(field => {
778
- // addFields.$addFields[total.id + '_' + field.id] = {
779
- // $divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), {$multiply: [{$cond: { if: { $gt: [{$size: '$' + fieldPath} , 0 ] }, then: {$size: '$' + fieldPath}, else: 1 }}]}]
780
- // };
781
- // });
782
- // });
783
- // if (Object.entries(addFields.$addFields).length > 0) {
784
- // groupQueries.push(addFields);
785
- // }
786
- // }
787
- // }
788
- // groupQueries.push({'$unwind': {path: '$' + fieldPath, preserveNullAndEmptyArrays: true}});
789
- // if (fieldsTotal.length) {
790
- // let addFields = {$addFields: {}};
791
- // fieldsTotal.forEach(total => {
792
- // selectedFields.filter(a => a.fieldPath.replace(/\.\$/g, '').includes(fieldPath) && a.fieldPath.split('.$').length === 2 && a.fieldType === 'Number').forEach(field => {
793
- // addFields.$addFields[total.id + '_' + field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
794
- // });
795
- // });
796
- // if (Object.entries(addFields.$addFields).length > 0) {
797
- // groupQueries.push(addFields);
798
- // }
799
- // }
800
- // }
801
- // });
802
- // }
803
- // // Add group lookups and unwinds to query
804
- // query = query.concat(groupQueries);
805
- // // GROUP
806
- // if (groupsRow.length) {
807
- // let queryGroup = {
808
- // _id: {}
809
- // };
810
- // groupsRow.forEach(row => {
811
- // queryGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
812
- // if (date_field && date_interval) {
813
- // if (date_interval === 'Daily') {
814
- // queryGroup._id['day'] = {'$dayOfMonth' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
815
- // queryGroup._id['month'] = {'$month' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
816
- // queryGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
817
- // }
818
- // else if (date_interval === 'Weekly') {
819
- // queryGroup._id['week'] = {'$isoWeek' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
820
- // // queryGroup._id['month'] = {'$month' : '$' + date_field.replace(/\.\$/g, '')};
821
- // queryGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
822
- // }
823
- // else if (date_interval === 'Monthly') {
824
- // queryGroup._id['month'] = {'$month' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
825
- // queryGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
826
- // }
827
- // else if (date_interval === 'Quarterly') {
828
- // queryGroup._id['month'] = {'$month' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
829
- // queryGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
830
- // }
831
- // else if (date_interval === 'Yearly') {
832
- // queryGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
833
- // }
834
- // // queryGroup[date_field.replace(/\.\$/g, '')] = {$first: '$' + date_field.replace(/\.\$/g, '')};
835
- // }
836
- // });
837
- // selectedFields.forEach(field => {
838
- // if (field.leafValueType === 'Average') {
839
- // queryGroup[field.id] = {'$avg': '$' + field.fieldPath.replace(/\.\$/g, '')};
840
- // }
841
- // else if (field.leafValueType === 'Sum') {
842
- // queryGroup[field.id] = {'$sum': '$' + field.fieldPath.replace(/\.\$/g, '')};
843
- // }
844
- // else if (field.leafValueType === 'Count') {
845
- // queryGroup[field.id] = {'$sum': 1};
846
- // }
847
- // else if (field.leafValueType === 'Minimum') {
848
- // queryGroup[field.id] = {'$min': '$' + field.fieldPath.replace(/\.\$/g, '')};
849
- // }
850
- // else if (field.leafValueType === 'Maximum') {
851
- // queryGroup[field.id] = {'$max': '$' + field.fieldPath.replace(/\.\$/g, '')};
852
- // }
853
- // else if (field.leafValueType === 'First') {
854
- // queryGroup[field.id] = {'$first': '$' + field.fieldPath.replace(/\.\$/g, '')};
855
- // }
856
- // else if (field.leafValueType === 'Last') {
857
- // queryGroup[field.id] = {'$last': '$' + field.fieldPath.replace(/\.\$/g, '')};
858
- // }
859
- // else {
860
- // queryGroup[field.id] = {'$push': '$' + field.fieldPath.replace(/\.\$/g, '')};
861
- // }
862
- // // if (field.fieldPath.includes('.$') && ) {
863
- // // }
864
- // });
865
- // //Totals
866
- // if (fieldsTotal.length) {
867
- // fieldsTotal.forEach(total => {
868
- // selectedFields.filter(a => a.fieldType === 'Number').forEach(field => {
869
- // queryGroup[total.id + '_' + field.id] = {['$' + total.type]: '$' + total.id + '_' + field.id};
870
- // });
871
- // });
872
- // }
873
- // // Copy Group Arrays Moving Forward
874
- // groupsRow.filter(a => a.field.includes('.$')).forEach(row => {
875
- // queryGroup[row.field.split('.$')[0]] = {$first: '$' + row.field.split('.$')[0]};
876
- // });
877
- // selectedFields.filter(a => a.fieldPath.includes('.$')).forEach(field => {
878
- // if (!queryGroup[field.fieldPath.split('.$')[0]]) {
879
- // queryGroup[field.fieldPath.split('.$')[0]] = {$push: '$' + field.fieldPath.split('.$')[0]};
880
- // }
881
- // });
882
- // query.push({$group: queryGroup});
883
- // }
884
- // else {
885
- // let queryGroup = {
886
- // _id: '$_id'
887
- // };
888
- // selectedFields.filter(a => !a.fieldPath.includes('.$')).forEach(field => {
889
- // if (field.leafValueType === 'Average') {
890
- // queryGroup[field.id] = {'$avg': '$' + field.fieldPath.replace(/\.\$/g, '')};
891
- // }
892
- // else if (field.leafValueType === 'Sum') {
893
- // queryGroup[field.id] = {'$sum': '$' + field.fieldPath.replace(/\.\$/g, '')};
894
- // }
895
- // else if (field.leafValueType === 'Count') {
896
- // queryGroup[field.id] = {'$sum': 1};
897
- // }
898
- // else if (field.leafValueType === 'Minimum') {
899
- // queryGroup[field.id] = {'$min': '$' + field.fieldPath.replace(/\.\$/g, '')};
900
- // }
901
- // else if (field.leafValueType === 'Maximum') {
902
- // queryGroup[field.id] = {'$max': '$' + field.fieldPath.replace(/\.\$/g, '')};
903
- // }
904
- // else if (field.leafValueType === 'First') {
905
- // queryGroup[field.id] = {'$first': '$' + field.fieldPath.replace(/\.\$/g, '')};
906
- // }
907
- // else if (field.leafValueType === 'Last') {
908
- // queryGroup[field.id] = {'$last': '$' + field.fieldPath.replace(/\.\$/g, '')};
909
- // }
910
- // else {
911
- // queryGroup[field.id] = {'$push': '$' + field.fieldPath.replace(/\.\$/g, '')};
912
- // }
913
- // });
914
- // //Totals
915
- // if (fieldsTotal.length) {
916
- // fieldsTotal.forEach(total => {
917
- // selectedFields.filter(a => a.fieldType === 'Number').forEach(field => {
918
- // queryGroup[total.id + '_' + field.id] = {['$' + total.type]: '$' + total.id + '_' + field.id};
919
- // });
920
- // });
921
- // }
922
- // // Copy Group Arrays Moving Forward
923
- // groupsRow.filter(a => a.field.includes('.$')).forEach(row => {
924
- // queryGroup[row.field.split('.$')[0]] = {$first: '$' + row.field.split('.$')[0]};
925
- // });
926
- // selectedFields.filter(a => a.fieldPath.includes('.$')).forEach(field => {
927
- // if (!queryGroup[field.fieldPath.split('.$')[0]]) {
928
- // queryGroup[field.fieldPath.split('.$')[0]] = {$push: '$' + field.fieldPath.split('.$')[0]};
929
- // }
930
- // });
931
- // query.push({$group: queryGroup});
932
- // }
933
- // /* --------------------- END IF GROUP ---------------------- */
934
- // // Lookup Selected Fields
935
- // selectedFields.filter(a => a.fieldPath.includes('.$')).forEach(field => {
936
- // // Unwind if from group
937
- // if (groupsRow.length && !groupsRow.some(a => a.field.split('.$')[0] === field.fieldPath.split('.$')[0])) {
938
- // query.push({$unwind: {
939
- // path: '$' + field.fieldPath.split('.$')[0],
940
- // preserveNullAndEmptyArrays: true
941
- // }});
942
- // }
943
- // let path = '$';
944
- // // Loop for each array value (Not Grouped!)
945
- // for (let i = 0; i < field.fieldPath.split('.$').length; i++) {
946
- // path += field.fieldPath.split('.$')[i];
947
- // // Unwind
948
- // if (i < field.fieldPath.split('.$').length - 1 && !groupsRow.some(a => a.field.split('.$')[0] === field.fieldPath.split('.$')[0])) {
949
- // query.push({$unwind: {
950
- // path: path,
951
- // preserveNullAndEmptyArrays: true
952
- // }});
953
- // }
954
- // // Link
955
- // if (!groupsRow.some(a => a.field.split('.$')[0] === field.fieldPath.split('.$')[0])) {
956
- // fieldsLink.filter(a => a.field_first && a.field_second).forEach(link => {
957
- // let firstLink = link.field_first.split('.$.');
958
- // firstLink.pop();
959
- // firstLink = firstLink.join('.');
960
- // let secondLink = link.field_second.split('.$.');
961
- // secondLink.pop();
962
- // secondLink = secondLink.join('.');
963
- // if ('$' + firstLink === path || '$' + secondLink === path) {
964
- // query.push(
965
- // {
966
- // $addFields: {
967
- // [link.id]: {
968
- // $cmp: [
969
- // '$' + link.field_first.replace(/\.\$/g, ''),
970
- // '$' + link.field_second.replace(/\.\$/g, '')
971
- // ]
972
- // }
973
- // }
974
- // },
975
- // {
976
- // $match: {
977
- // [link.id]: 0
978
- // }
979
- // }
980
- // );
981
- // }
982
- // });
983
- // }
984
- // //Totals
985
- // if (i === field.fieldPath.split('.$').length - 1 && field.fieldType === 'Number') {
986
- // fieldsTotal.forEach(total => {
987
- // query.push({$addFields: {[total.id + '_' + field.id]: path}});
988
- // });
989
- // }
990
- // }
991
- // // Regroup
992
- // let queryLoopGroup = {
993
- // _id: {}
994
- // };
995
- // if (!groupsRow.length) {
996
- // queryLoopGroup._id = '$_id';
997
- // }
998
- // groupsRow.forEach(row => {
999
- // queryLoopGroup._id[row.id] = '$_id.' + row.id;
1000
- // if (date_field && date_interval) {
1001
- // if (date_interval === 'Daily') {
1002
- // queryLoopGroup._id['day'] = '$_id.day';
1003
- // queryLoopGroup._id['month'] = '$_id.month';
1004
- // queryLoopGroup._id['year'] = '$_id.year';
1005
- // }
1006
- // else if (date_interval === 'Weekly') {
1007
- // queryLoopGroup._id['week'] = '$_id.week';
1008
- // // queryGroup._id['month'] = {'$month' : '$' + date_field.replace(/\.\$/g, '')};
1009
- // queryLoopGroup._id['year'] = '$_id.year';
1010
- // }
1011
- // else if (date_interval === 'Monthly') {
1012
- // queryLoopGroup._id['month'] = '$_id.month';
1013
- // queryLoopGroup._id['year'] = '$_id.year';
1014
- // }
1015
- // else if (date_interval === 'Quarterly') {
1016
- // queryLoopGroup._id['month'] = '$_id.month';
1017
- // queryLoopGroup._id['year'] = '$_id.year';
1018
- // }
1019
- // else if (date_interval === 'Yearly') {
1020
- // queryLoopGroup._id['year'] = '$_id.year';
1021
- // }
1022
- // }
1023
- // });
1024
- // selectedFields.forEach(selField => {
1025
- // if (selField.id === field.id) {
1026
- // if (selField.leafValueType === 'Average') {
1027
- // queryLoopGroup[selField.id] = {'$avg': '$' + (selField.collection_name === rootCollectionName ? selField.fieldPath.replace(/\.\$/g, '') : selField.fieldPath.replace(/\.\$/g, ''))};
1028
- // }
1029
- // else if (selField.leafValueType === 'Sum') {
1030
- // queryLoopGroup[selField.id] = {'$sum': '$' + (selField.collection_name === rootCollectionName ? selField.fieldPath.replace(/\.\$/g, '') : selField.fieldPath.replace(/\.\$/g, ''))};
1031
- // }
1032
- // else if (selField.leafValueType === 'Count') {
1033
- // queryLoopGroup[selField.id] = {'$sum': 1};
1034
- // }
1035
- // else if (selField.leafValueType === 'Minimum') {
1036
- // queryLoopGroup[selField.id] = {'$min': '$' + (selField.collection_name === rootCollectionName ? selField.fieldPath.replace(/\.\$/g, '') : selField.fieldPath.replace(/\.\$/g, ''))};
1037
- // }
1038
- // else if (selField.leafValueType === 'Maximum') {
1039
- // queryLoopGroup[selField.id] = {'$max': '$' + (selField.collection_name === rootCollectionName ? selField.fieldPath.replace(/\.\$/g, '') : selField.fieldPath.replace(/\.\$/g, ''))};
1040
- // }
1041
- // else if (selField.leafValueType === 'First') {
1042
- // queryLoopGroup[selField.id] = {'$first': '$' + (selField.collection_name === rootCollectionName ? selField.fieldPath.replace(/\.\$/g, '') : selField.fieldPath.replace(/\.\$/g, ''))};
1043
- // }
1044
- // else if (selField.leafValueType === 'Last') {
1045
- // queryLoopGroup[selField.id] = {'$last': '$' + (selField.collection_name === rootCollectionName ? selField.fieldPath.replace(/\.\$/g, '') : selField.fieldPath.replace(/\.\$/g, ''))};
1046
- // }
1047
- // else {
1048
- // queryLoopGroup[selField.id] = {'$push': '$' + (selField.collection_name === rootCollectionName ? selField.fieldPath.replace(/\.\$/g, '') : selField.fieldPath.replace(/\.\$/g, ''))};
1049
- // }
1050
- // }
1051
- // else {
1052
- // queryLoopGroup[selField.id] = {'$first': '$' + selField.id};
1053
- // }
1054
- // });
1055
- // //Totals
1056
- // if (fieldsTotal.length) {
1057
- // fieldsTotal.forEach(total => {
1058
- // selectedFields.filter(a => a.fieldType === 'Number').forEach(selField => {
1059
- // if (selField.id === field.id) {
1060
- // queryLoopGroup[total.id + '_' + selField.id] = {['$' + total.type]: '$' + total.id + '_' + selField.id};
1061
- // }
1062
- // else {
1063
- // queryLoopGroup[total.id + '_' + selField.id] = {$first: '$' + total.id + '_' + selField.id};
1064
- // }
1065
- // });
1066
- // });
1067
- // }
1068
- // // Copy Group Arrays Moving Forward
1069
- // groupsRow.filter(a => a.field.includes('.$')).forEach(row => {
1070
- // queryLoopGroup[row.field.split('.$')[0]] = {$first: '$' + row.field.split('.$')[0]};
1071
- // });
1072
- // selectedFields.filter(a => a.fieldPath.includes('.$')).forEach(selField => {
1073
- // if (selField.id === field.id) {
1074
- // if (!queryLoopGroup[selField.fieldPath.split('.$')[0]]) {
1075
- // queryLoopGroup[selField.fieldPath.split('.$')[0]] = {$push: '$' + selField.fieldPath.split('.$')[0]};
1076
- // }
1077
- // }
1078
- // else {
1079
- // if (!queryLoopGroup[selField.fieldPath.split('.$')[0]]) {
1080
- // queryLoopGroup[selField.fieldPath.split('.$')[0]] = {$first: '$' + selField.fieldPath.split('.$')[0]};
1081
- // }
1082
- // }
1083
- // });
1084
- // query.push({$group: queryLoopGroup});
1085
- // // Sort
1086
- // });
1087
- // uniqueSelectedFieldCollections.filter(a => a !== rootCollectionName).forEach(uniqueCollection => {
1088
- // selectedFields.filter(a => a.collection_name === uniqueCollection).forEach(field => {
1089
- // if (!queryLookups.filter(a => a.as === field.lookup_as.replace(/\.\$/g, '')).length) {
1090
- // queryLookups.push({
1091
- // from: field.lookup_collection,
1092
- // localField: field.lookup_local_key,
1093
- // foreignField: field.lookup_foreign_key,
1094
- // as: field.lookup_as.replace(/\.\$/g, '')
1095
- // });
1096
- // }
1097
- // });
1098
- // });
1099
- // let queryGroupUnwindCollectionPaths = [];
1100
- // groupsRow.filter(a => a.treeItem.fieldPath.includes('$')).forEach(field => {
1101
- // let arrayPartData = field.treeItem.fieldPath.split('.$');
1102
- // let path = '$';
1103
- // for (let i = 0; i < arrayPartData.length - 1; i++) {
1104
- // path += arrayPartData[i];
1105
- // if (!queryGroupUnwindCollectionPaths.filter(a => a === path)[0]) {
1106
- // queryGroupUnwindCollectionPaths.push(path);
1107
- // }
1108
- // }
1109
- // });
1110
- // // Unwind
1111
- // let queryUnwindCollectionPaths = [];
1112
- // selectedFields.filter(a => a.fieldPath.includes('$')).forEach(field => {
1113
- // let arrayPartData = field.fieldPath.split('.$');
1114
- // let path = '$';
1115
- // for (let i = 0; i < arrayPartData.length - 1; i++) {
1116
- // path += arrayPartData[i];
1117
- // if (!queryUnwindCollectionPaths.some(a => a === path) && !queryGroupUnwindCollectionPaths.some(a => a === path)) {
1118
- // queryUnwindCollectionPaths.push(path);
1119
- // }
1120
- // }
1121
- // });
1122
- // //Links
1123
- // if (fieldsLink.length) {
1124
- // fieldsLink.filter(a => a.field_first && a.field_second).forEach(link => {
1125
- // queryGroup[link.id] = {$cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')]};
1126
- // });
1127
- // }
1128
- // if (rootOptions.sort && reportType === 'Tabular Group') {
1129
- // let correctSort = {};
1130
- // Object.keys(rootOptions.sort).forEach(key => {
1131
- // correctSort[selectedFields.filter(a => a.id === key)[0].fieldPath.replace(/\.\$/g, '')] = rootOptions.sort[key];
1132
- // });
1133
- // queryGroups.push({
1134
- // $sort: correctSort
1135
- // });
1136
- // }
1137
- // queryGroups.push({$group: queryGroup});
1138
- // if (reportType === 'Tabular Group') {
1139
- // for (let i = groupsRow.length - 1; i > 0; i--) {
1140
- // queryGroups.push({$sort: {['_id.' + groupsRow[i].id]: 1}});
1141
- // let tmpQueryGroup = {
1142
- // _id: {}
1143
- // };
1144
- // for (let j = 0; j < i; j++) {
1145
- // tmpQueryGroup._id[groupsRow[j].id] = '$_id.' + groupsRow[j].id;
1146
- // }
1147
- // let tmpQueryGroupObj = {
1148
- // [groupsRow[i].id]: '$_id.' + [groupsRow[i].id]
1149
- // };
1150
- // if (i === groupsRow.length - 1) {
1151
- // selectedFields.forEach(field => {
1152
- // tmpQueryGroupObj[field.id] = '$' + field.id;
1153
- // });
1154
- // }
1155
- // else {
1156
- // tmpQueryGroupObj[groupsRow[i + 1].id] = '$' + [groupsRow[i + 1].id];
1157
- // }
1158
- // fieldsTotal.forEach(total => {
1159
- // selectedFields.filter(a => a.fieldType === 'Number').forEach(field => {
1160
- // tmpQueryGroupObj[total.id + '_' + field.id] = '$' + total.id + '_' + field.id;
1161
- // tmpQueryGroup[total.id + '_' + field.id] = {['$' + total.type]: '$' + total.id + '_' + field.id};
1162
- // });
1163
- // });
1164
- // tmpQueryGroup[groupsRow[i].id] = {'$push': tmpQueryGroupObj};
1165
- // queryGroups.push({$group: tmpQueryGroup});
1166
- // }
1167
- // queryGroups.push({$sort: {['_id.' + groupsRow[0].id]: 1}});
1168
- // }
1169
- // else if (reportType === 'Dated') {
1170
- // // db.collection.aggregate([
1171
- // // { "$group": {
1172
- // // "_id": {
1173
- // // "$toDate": {
1174
- // // "$subtract": [
1175
- // // { "$toLong": "$created_at" },
1176
- // // { "$mod": [ { "$toLong": "$created_at" }, 1000 * 60 * 15 ] }
1177
- // // ]
1178
- // // }
1179
- // // },
1180
- // // "count": { "$sum": 1 }
1181
- // // }}
1182
- // // ])
1183
- // }
1184
- // }
1185
- // //Projection
1186
- // let queryProjection = {
1187
- // _id: 1
1188
- // };
1189
- // selectedFields.forEach(field => {
1190
- // if (field.leafValueType === 'Average') {
1191
- // queryProjection[field.id] = {$avg: '$' + field.fieldPath.replace(/\.\$/g, '')};
1192
- // }
1193
- // else if (field.leafValueType === 'Sum') {
1194
- // queryProjection[field.id] = {$sum: '$' + field.fieldPath.replace(/\.\$/g, '')};
1195
- // }
1196
- // else if (field.leafValueType === 'Count') {
1197
- // queryProjection[field.id] = {$sum: 1};
1198
- // }
1199
- // else if (field.leafValueType === 'Minimum') {
1200
- // queryProjection[field.id] = {$min: '$' + field.fieldPath.replace(/\.\$/g, '')};
1201
- // }
1202
- // else if (field.leafValueType === 'Maximum') {
1203
- // queryProjection[field.id] = {$max: '$' + field.fieldPath.replace(/\.\$/g, '')};
1204
- // }
1205
- // else if (field.leafValueType === 'First') {
1206
- // queryProjection[field.id] = {$slice: ['$' + field.fieldPath.replace(/\.\$/g, ''), 0]};
1207
- // }
1208
- // else if (field.leafValueType === 'Last') {
1209
- // queryProjection[field.id] = {$slice: ['$' + field.fieldPath.replace(/\.\$/g, ''), -1]};
1210
- // }
1211
- // else {
1212
- // queryProjection[field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
1213
- // }
1214
- // });
1215
- // //Links
1216
- // if (fieldsLink.length) {
1217
- // fieldsLink.filter(a => a.field_first && a.field_second).forEach(link => {
1218
- // queryProjection[link.id] = {$cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')]};
1219
- // });
1220
- // }
1221
- // //Totals
1222
- // let queryTotals = null;
1223
- // if (fieldsTotal.length && (reportType === 'Tabular' || reportType === 'Dated')) {
1224
- // fieldsTotal.forEach(total => {
1225
- // selectedFields.filter(a => a.fieldType === 'Number').forEach(field => {
1226
- // if (!queryTotals) {
1227
- // queryTotals = {};
1228
- // }
1229
- // queryTotals[total.id + '_' + field.id] = {['$' + total.type]: '$results.' + total.id + '_' + field.id};
1230
- // });
1231
- // });
1232
- // }
1233
- // // ---------------------------------------------------------------
1234
- // // Unwind Pre-Lookup Arrays
1235
- // queryUnwindCollectionPaths.filter(a => !a.includes('(Lookup)')).forEach(path => {
1236
- // query.push({
1237
- // $unwind: {
1238
- // path: path,
1239
- // preserveNullAndEmptyArrays: true
1240
- // }
1241
- // });
1242
- // });
1243
- // queryGroupUnwindCollectionPaths.filter(a => !a.includes('(Lookup)')).forEach(path => {
1244
- // query.push({
1245
- // $unwind: {
1246
- // path: path,
1247
- // preserveNullAndEmptyArrays: false
1248
- // }
1249
- // });
1250
- // });
1251
- // // Unwind Lookups
1252
- // queryUnwindCollectionPaths.filter(a => a.includes('(Lookup)')).forEach(path => {
1253
- // if (!query.filter(a => a.$unwind && a.$unwind.path === path).length) {
1254
- // query.push({
1255
- // $unwind: {
1256
- // path: path,
1257
- // preserveNullAndEmptyArrays: true
1258
- // }
1259
- // });
1260
- // }
1261
- // });
1262
- // queryGroupUnwindCollectionPaths.filter(a => a.includes('(Lookup)')).forEach(path => {
1263
- // if (!query.filter(a => a.$unwind && a.$unwind.path === path).length) {
1264
- // query.push({
1265
- // $unwind: {
1266
- // path: path,
1267
- // preserveNullAndEmptyArrays: false
1268
- // }
1269
- // });
1270
- // }
1271
- // });
1272
- // // Group Unwinds
1273
- // if (groupsRow.length) {
1274
- // query = query.concat(queryGroupUnwind.filter(a => !query.some(b => b.$unwind && (b.$unwind.path === a.$unwind.path))));
1275
- // }
1276
- // // Array and Lookup Filters
1277
- // let queryMatchConditionLookup = {
1278
- // $and: []
1279
- // };
1280
- // if (filters.filter(a => (!a['$or'] && Object.keys(a).some(b => b.includes('(Lookup)'))) || (a['$or'] && a['$or'].some(b => Object.keys(b).some(c => c.includes('(Lookup)'))))).length) {
1281
- // filters.filter(a => (!a['$or'] && Object.keys(a).some(b => b.includes('(Lookup)'))) || (a['$or'] && a['$or'].some(b => Object.keys(b).some(c => c.includes('(Lookup)'))))).forEach(filter => {
1282
- // queryMatchConditionLookup['$and'].push(filter);
1283
- // });
1284
- // }
1285
- // filterArrays.forEach(filter => {
1286
- // queryMatchConditionLookup['$and'].push(filter);
1287
- // });
1288
- // if (queryMatchConditionLookup.$and.some(a => !a['$or'] || (a['$or'] && a['$or'].length)) || queryMatchConditionLookup.$and.length) {
1289
- // query.push({
1290
- // $match: queryMatchConditionLookup
1291
- // });
1292
- // }
1293
- // // Group Queries and Projection
1294
- // if (groupsRow.length) {
1295
- // queryGroups.forEach(group => {
1296
- // query.push(group);
1297
- // });
1298
- // if (reportType === 'Tabular Group') {
1299
- // let tmpProj = deepCopy(queryGroups[queryGroups.length - 2].$group);
1300
- // if (groupsRow.length === 1) {
1301
- // tmpProj._id.gr_1 = '$_id.gr_1';
1302
- // }
1303
- // Object.keys(tmpProj).filter(a => a !== '_id').forEach(key => {
1304
- // tmpProj[key] = 1;
1305
- // });
1306
- // Object.assign(tmpProj, tmpProj['_id']);
1307
- // tmpProj['_id'] = 0;
1308
- // query.push({
1309
- // $project: tmpProj
1310
- // });
1311
- // }
1312
- // }
1313
- // else {
1314
- // query.push({
1315
- // $project: queryProjection
1316
- // });
1317
- // }
1318
- // // Links
1319
- // if (fieldsLink.length) {
1320
- // if (fieldsLink.length === 1 && fieldsLink[0].field_first && fieldsLink[0].field_second) {
1321
- // query.push({$match: {[fieldsLink[0].id]: 0}});
1322
- // }
1323
- // else {
1324
- // let tmpAnds = [];
1325
- // fieldsLink.filter(a => a.field_first && a.field_second).forEach(link => {
1326
- // tmpAnds.push({[link.id]: 0});
1327
- // });
1328
- // if (tmpAnds.length) {
1329
- // query.push({$match: {$and: tmpAnds}});
1330
- // }
1331
- // }
1332
- // }
1333
- // Dated Grouping
1334
- // if (date_field && date_interval) {
1335
- // if (date_interval === 'Daily') {
1336
- // query.push({
1337
- // $group: {
1338
- // _id: {
1339
- // day: '$_id.day',
1340
- // month: '$_id.month',
1341
- // year: '$_id.year'
1342
- // },
1343
- // results: {
1344
- // '$push': '$$ROOT'
1345
- // }
1346
- // }
1347
- // });
1348
- // }
1349
- // else if (date_interval === 'Weekly') {
1350
- // query.push({
1351
- // $group: {
1352
- // _id: {
1353
- // week: '$_id.week',
1354
- // // month: '$_id.month',
1355
- // year: '$_id.year'
1356
- // },
1357
- // results: {
1358
- // '$push': '$$ROOT'
1359
- // }
1360
- // }
1361
- // });
1362
- // }
1363
- // else if (date_interval === 'Monthly') {
1364
- // query.push({
1365
- // $group: {
1366
- // _id: {
1367
- // month: '$_id.month',
1368
- // year: '$_id.year'
1369
- // },
1370
- // results: {
1371
- // '$push': '$$ROOT'
1372
- // }
1373
- // }
1374
- // });
1375
- // }
1376
- // else if (date_interval === 'Quarterly') {
1377
- // query.push({
1378
- // $group: {
1379
- // _id: {
1380
- // month: '$_id.month',
1381
- // year: '$_id.year'
1382
- // },
1383
- // results: {
1384
- // '$push': '$$ROOT'
1385
- // }
1386
- // }
1387
- // });
1388
- // }
1389
- // else if (date_interval === 'Yearly') {
1390
- // query.push({
1391
- // $group: {
1392
- // _id: {
1393
- // year: '$_id.year'
1394
- // },
1395
- // results: {
1396
- // '$push': '$$ROOT'
1397
- // }
1398
- // }
1399
- // });
1400
- // }
1401
- // }
1402
- // GROUP TO GET TOTAL COUNT
1403
- // query.push({
1404
- // $group: {
1405
- // _id: null,
1406
- // count: {$sum: 1},
1407
- // results: {$push: '$$ROOT'}
1408
- // }
1409
- // });
1410
- // if (rootOptions.limit) {
1411
- // // PROJECT TO SKIP/LIMIT
1412
- // query.push({
1413
- // $project: {
1414
- // count: 1,
1415
- // results: {
1416
- // $slice: ['$results', rootOptions.skip, rootOptions.limit]
1417
- // }
1418
- // }
1419
- // });
1420
- // if (queryTotals !== null) {
1421
- // query[query.length - 1].$project['totals'] = queryTotals;
1422
- // }
1423
- // }
1424
- // else if (queryTotals !== null) {
1425
- // query.push({
1426
- // $project: {
1427
- // count: 1,
1428
- // results: 1,
1429
- // totals: queryTotals
1430
- // }
1431
- // });
1432
- // }
1433
732
 
1434
733
  //# sourceMappingURL=report-builder.js.map