@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.
- package/methods/cron-jobs.js +1 -1
- package/methods/report-builder.js +109 -58
- package/package.json +1 -1
package/methods/cron-jobs.js
CHANGED
|
@@ -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 (
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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 (
|
|
391
|
-
queryGroup.
|
|
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 (
|
|
395
|
-
queryGroup.
|
|
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 (
|
|
399
|
-
queryGroup.
|
|
419
|
+
else if (field.leafValueType === 'Minimum') {
|
|
420
|
+
queryGroup[field.id] = { '$min': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
400
421
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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({
|