@resolveio/server-lib 4.6.5 → 4.6.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.
@@ -389,7 +389,7 @@ function loadCronJobMethods(methodManager) {
389
389
  }
390
390
  }
391
391
  });
392
- this.callMethodInternal.call(this, 'reportBuilderGetResults', report.type, report.collection_root, rootOptions, filters_1, filterArrays_1, filterArrayPaths_1, report.fields_selected, report.groups_row, report.fields_total, report.fields_link, report.id_date_field || null, report.date_interval || null, function (err, res) {
392
+ this.callMethodInternal.call(this, 'reportBuilderGetResults', report.type, report.collection_root, rootOptions, filters_1, filterArrays_1, filterArrayPaths_1, report.fields_selected, report.groups_row, report.fields_total, report.fields_link, report.id_date_field || null, report.date_interval || null, null, function (err, res) {
393
393
  if (res && res[0]) {
394
394
  var fields_1 = [];
395
395
  var results_1 = res[0].results;
@@ -181,9 +181,13 @@ function loadReportBuilderMethods(methodManager) {
181
181
  date_interval: {
182
182
  type: String,
183
183
  optional: true
184
+ },
185
+ tabularDisplayType: {
186
+ type: String,
187
+ optional: true
184
188
  }
185
189
  }),
186
- function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayPaths, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval) {
190
+ function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayPaths, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval, tabularDisplayType) {
187
191
  var _this = this;
188
192
  if (filters === void 0) { filters = []; }
189
193
  if (filterArrays === void 0) { filterArrays = []; }
@@ -194,8 +198,9 @@ function loadReportBuilderMethods(methodManager) {
194
198
  if (fieldsLink === void 0) { fieldsLink = []; }
195
199
  if (date_field === void 0) { date_field = ''; }
196
200
  if (date_interval === void 0) { date_interval = ''; }
201
+ if (tabularDisplayType === void 0) { tabularDisplayType = ''; }
197
202
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
198
- var uniqueSelectedFieldCollections, modelCollection, query, initialQueryMatchCondition, sizes, divFields, queryGroup, res, err_1, tmpTotals, tmpRes;
203
+ var uniqueSelectedFieldCollections, modelCollection, query, initialQueryMatchCondition, sizes, divFields, queryGroup, queryProjection_1, queryTotals_1, res, err_1, tmpTotals, tmpRes;
199
204
  var _this = this;
200
205
  return __generator(this, function (_a) {
201
206
  switch (_a.label) {
@@ -372,70 +377,116 @@ function loadReportBuilderMethods(methodManager) {
372
377
  queryGroup = {
373
378
  _id: {}
374
379
  };
375
- if (!groupsRow.length) {
376
- queryGroup._id = '$_id';
377
- }
378
- groupsRow.forEach(function (row) {
379
- queryGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
380
- if (date_field && date_interval) {
381
- if (date_interval === 'Daily') {
382
- queryGroup._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
383
- queryGroup._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
384
- queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
380
+ if (groupsRow.length || !tabularDisplayType || tabularDisplayType === 'grouped') {
381
+ if (!groupsRow.length) {
382
+ queryGroup._id = '$_id';
383
+ }
384
+ groupsRow.forEach(function (row) {
385
+ queryGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
386
+ if (date_field && date_interval) {
387
+ if (date_interval === 'Daily') {
388
+ queryGroup._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
389
+ queryGroup._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
390
+ queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
391
+ }
392
+ else if (date_interval === 'Weekly') {
393
+ queryGroup._id['week'] = { '$week': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
394
+ queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
395
+ }
396
+ else if (date_interval === 'Monthly') {
397
+ queryGroup._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
398
+ queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
399
+ }
400
+ else if (date_interval === 'Quarterly') {
401
+ queryGroup._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
402
+ queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
403
+ }
404
+ else if (date_interval === 'Yearly') {
405
+ queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
406
+ }
385
407
  }
386
- else if (date_interval === 'Weekly') {
387
- queryGroup._id['week'] = { '$week': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
388
- queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
408
+ });
409
+ selectedFields.forEach(function (field) {
410
+ if (field.leafValueType === 'Average') {
411
+ queryGroup[field.id] = { '$avg': '$' + field.fieldPath.replace(/\.\$/g, '') };
389
412
  }
390
- else if (date_interval === 'Monthly') {
391
- queryGroup._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
392
- queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
413
+ else if (field.leafValueType === 'Sum') {
414
+ queryGroup[field.id] = { '$sum': '$' + field.fieldPath.replace(/\.\$/g, '') };
393
415
  }
394
- else if (date_interval === 'Quarterly') {
395
- queryGroup._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
396
- queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
416
+ else if (field.leafValueType === 'Count') {
417
+ queryGroup[field.id] = { '$sum': '$count_' + field.fieldPath.replace(/\.\$/g, '') };
397
418
  }
398
- else if (date_interval === 'Yearly') {
399
- queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
419
+ else if (field.leafValueType === 'Minimum') {
420
+ queryGroup[field.id] = { '$min': '$' + field.fieldPath.replace(/\.\$/g, '') };
400
421
  }
401
- }
402
- });
403
- selectedFields.forEach(function (field) {
404
- if (field.leafValueType === 'Average') {
405
- queryGroup[field.id] = { '$avg': '$' + field.fieldPath.replace(/\.\$/g, '') };
406
- }
407
- else if (field.leafValueType === 'Sum') {
408
- queryGroup[field.id] = { '$sum': '$' + field.fieldPath.replace(/\.\$/g, '') };
409
- }
410
- else if (field.leafValueType === 'Count') {
411
- queryGroup[field.id] = { '$sum': '$count_' + field.fieldPath.replace(/\.\$/g, '') };
412
- }
413
- else if (field.leafValueType === 'Minimum') {
414
- queryGroup[field.id] = { '$min': '$' + field.fieldPath.replace(/\.\$/g, '') };
415
- }
416
- else if (field.leafValueType === 'Maximum') {
417
- queryGroup[field.id] = { '$max': '$' + field.fieldPath.replace(/\.\$/g, '') };
418
- }
419
- else if (field.leafValueType === 'First' || (!groupsRow.length && !field.fieldPath.includes('.$'))) {
420
- queryGroup[field.id] = { '$first': '$' + field.fieldPath.replace(/\.\$/g, '') };
421
- }
422
- else if (field.leafValueType === 'Last') {
423
- queryGroup[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
424
- }
425
- else {
426
- queryGroup[field.id] = { '$push': '$' + field.fieldPath.replace(/\.\$/g, '') };
427
- }
428
- });
429
- // Totals
430
- if (fieldsTotal.length) {
431
- fieldsTotal.forEach(function (total) {
432
- selectedFields.filter(function (a) { return a.fieldType === 'Number'; }).forEach(function (field) {
433
- // queryGroup[total.id + '_' + field.id] = {['$' + total.type]: '$' + total.id + '_' + field.id};
434
- queryGroup[total.id + '_' + field.id] = { $sum: '$' + total.id + '_' + field.id };
422
+ else if (field.leafValueType === 'Maximum') {
423
+ queryGroup[field.id] = { '$max': '$' + field.fieldPath.replace(/\.\$/g, '') };
424
+ }
425
+ else if (field.leafValueType === 'First' || (!groupsRow.length && !field.fieldPath.includes('.$'))) {
426
+ queryGroup[field.id] = { '$first': '$' + field.fieldPath.replace(/\.\$/g, '') };
427
+ }
428
+ else if (field.leafValueType === 'Last') {
429
+ queryGroup[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
430
+ }
431
+ else {
432
+ queryGroup[field.id] = { '$push': '$' + field.fieldPath.replace(/\.\$/g, '') };
433
+ }
434
+ });
435
+ // Totals
436
+ if (fieldsTotal.length) {
437
+ fieldsTotal.forEach(function (total) {
438
+ selectedFields.filter(function (a) { return a.fieldType === 'Number'; }).forEach(function (field) {
439
+ // queryGroup[total.id + '_' + field.id] = {['$' + total.type]: '$' + total.id + '_' + field.id};
440
+ queryGroup[total.id + '_' + field.id] = { $sum: '$' + total.id + '_' + field.id };
441
+ });
435
442
  });
443
+ }
444
+ query.push({ $group: queryGroup });
445
+ }
446
+ else {
447
+ queryProjection_1 = {
448
+ _id: 1
449
+ };
450
+ selectedFields.forEach(function (field) {
451
+ if (field.leafValueType === 'Average') {
452
+ queryProjection_1[field.id] = { $avg: '$' + field.fieldPath.replace(/\.\$/g, '') };
453
+ }
454
+ else if (field.leafValueType === 'Sum') {
455
+ queryProjection_1[field.id] = { $sum: '$' + field.fieldPath.replace(/\.\$/g, '') };
456
+ }
457
+ else if (field.leafValueType === 'Count') {
458
+ queryProjection_1[field.id] = { $sum: 1 };
459
+ }
460
+ else if (field.leafValueType === 'Minimum') {
461
+ queryProjection_1[field.id] = { $min: '$' + field.fieldPath.replace(/\.\$/g, '') };
462
+ }
463
+ else if (field.leafValueType === 'Maximum') {
464
+ queryProjection_1[field.id] = { $max: '$' + field.fieldPath.replace(/\.\$/g, '') };
465
+ }
466
+ else if (field.leafValueType === 'First') {
467
+ queryProjection_1[field.id] = { $slice: ['$' + field.fieldPath.replace(/\.\$/g, ''), 0] };
468
+ }
469
+ else if (field.leafValueType === 'Last') {
470
+ queryProjection_1[field.id] = { $slice: ['$' + field.fieldPath.replace(/\.\$/g, ''), -1] };
471
+ }
472
+ else {
473
+ queryProjection_1[field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
474
+ }
436
475
  });
476
+ queryTotals_1 = null;
477
+ if (fieldsTotal.length && (reportType === 'Tabular' || reportType === 'Dated')) {
478
+ fieldsTotal.forEach(function (total) {
479
+ selectedFields.filter(function (a) { return a.fieldType === 'Number'; }).forEach(function (field) {
480
+ var _a;
481
+ if (!queryTotals_1) {
482
+ queryTotals_1 = {};
483
+ }
484
+ queryTotals_1[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$results.' + total.id + '_' + field.id, _a);
485
+ });
486
+ });
487
+ }
488
+ query.push({ $project: queryProjection_1 });
437
489
  }
438
- query.push({ $group: queryGroup });
439
490
  // SORT
440
491
  if (rootOptions.sort && reportType !== 'Tabular Group') {
441
492
  query.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.6.5",
3
+ "version": "4.6.6",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {