@resolveio/server-lib 4.6.5 → 4.6.7
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 +129 -67
- package/package.json +1 -1
- package/server-app.js +5 -0
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;
|
|
@@ -87,20 +87,28 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
87
87
|
function: function (treeLeaf) {
|
|
88
88
|
var _this = this;
|
|
89
89
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
90
|
-
var _a;
|
|
91
|
-
return __generator(this, function (
|
|
92
|
-
switch (
|
|
90
|
+
var _a, _b;
|
|
91
|
+
return __generator(this, function (_c) {
|
|
92
|
+
switch (_c.label) {
|
|
93
93
|
case 0:
|
|
94
|
-
if (!(treeLeaf.fieldType === 'String')) return [3 /*break*/,
|
|
94
|
+
if (!(treeLeaf.fieldType === 'String')) return [3 /*break*/, 5];
|
|
95
|
+
if (!treeLeaf.fieldPath.includes('(Lookup)')) return [3 /*break*/, 2];
|
|
95
96
|
_a = resolve;
|
|
96
|
-
return [4 /*yield*/, schema_report_builder_1.mongoCommand('distinct', treeLeaf.collection_name, treeLeaf.fieldPath.replace(/\.\$/g, ''))];
|
|
97
|
+
return [4 /*yield*/, schema_report_builder_1.mongoCommand('distinct', treeLeaf.collection_name, treeLeaf.fieldPath.replace(/\.\$/g, '').replace(/^.+\(Lookup\)\.\$\./g, ''))];
|
|
97
98
|
case 1:
|
|
98
|
-
_a.apply(void 0, [
|
|
99
|
-
return [3 /*break*/,
|
|
99
|
+
_a.apply(void 0, [_c.sent()]);
|
|
100
|
+
return [3 /*break*/, 4];
|
|
100
101
|
case 2:
|
|
102
|
+
_b = resolve;
|
|
103
|
+
return [4 /*yield*/, schema_report_builder_1.mongoCommand('distinct', treeLeaf.collection_name, treeLeaf.fieldPath.replace(/\.\$/g, ''))];
|
|
104
|
+
case 3:
|
|
105
|
+
_b.apply(void 0, [_c.sent()]);
|
|
106
|
+
_c.label = 4;
|
|
107
|
+
case 4: return [3 /*break*/, 6];
|
|
108
|
+
case 5:
|
|
101
109
|
resolve([]);
|
|
102
|
-
|
|
103
|
-
case
|
|
110
|
+
_c.label = 6;
|
|
111
|
+
case 6: return [2 /*return*/];
|
|
104
112
|
}
|
|
105
113
|
});
|
|
106
114
|
}); });
|
|
@@ -181,9 +189,13 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
181
189
|
date_interval: {
|
|
182
190
|
type: String,
|
|
183
191
|
optional: true
|
|
192
|
+
},
|
|
193
|
+
tabularDisplayType: {
|
|
194
|
+
type: String,
|
|
195
|
+
optional: true
|
|
184
196
|
}
|
|
185
197
|
}),
|
|
186
|
-
function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayPaths, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval) {
|
|
198
|
+
function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayPaths, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval, tabularDisplayType) {
|
|
187
199
|
var _this = this;
|
|
188
200
|
if (filters === void 0) { filters = []; }
|
|
189
201
|
if (filterArrays === void 0) { filterArrays = []; }
|
|
@@ -194,8 +206,9 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
194
206
|
if (fieldsLink === void 0) { fieldsLink = []; }
|
|
195
207
|
if (date_field === void 0) { date_field = ''; }
|
|
196
208
|
if (date_interval === void 0) { date_interval = ''; }
|
|
209
|
+
if (tabularDisplayType === void 0) { tabularDisplayType = ''; }
|
|
197
210
|
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;
|
|
211
|
+
var uniqueSelectedFieldCollections, modelCollection, query, initialQueryMatchCondition, sizes, divFields, queryGroup, queryProjection_1, res, err_1, tmpTotals, tmpRes;
|
|
199
212
|
var _this = this;
|
|
200
213
|
return __generator(this, function (_a) {
|
|
201
214
|
switch (_a.label) {
|
|
@@ -372,70 +385,119 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
372
385
|
queryGroup = {
|
|
373
386
|
_id: {}
|
|
374
387
|
};
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
388
|
+
if (groupsRow.length || !tabularDisplayType || tabularDisplayType === 'grouped') {
|
|
389
|
+
if (!groupsRow.length) {
|
|
390
|
+
queryGroup._id = '$_id';
|
|
391
|
+
}
|
|
392
|
+
groupsRow.forEach(function (row) {
|
|
393
|
+
queryGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
394
|
+
if (date_field && date_interval) {
|
|
395
|
+
if (date_interval === 'Daily') {
|
|
396
|
+
queryGroup._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
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 === 'Weekly') {
|
|
401
|
+
queryGroup._id['week'] = { '$week': { '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 === 'Monthly') {
|
|
405
|
+
queryGroup._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
406
|
+
queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
407
|
+
}
|
|
408
|
+
else if (date_interval === 'Quarterly') {
|
|
409
|
+
queryGroup._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
410
|
+
queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
411
|
+
}
|
|
412
|
+
else if (date_interval === 'Yearly') {
|
|
413
|
+
queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
414
|
+
}
|
|
385
415
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
416
|
+
});
|
|
417
|
+
selectedFields.forEach(function (field) {
|
|
418
|
+
if (field.leafValueType === 'Average') {
|
|
419
|
+
queryGroup[field.id] = { '$avg': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
389
420
|
}
|
|
390
|
-
else if (
|
|
391
|
-
queryGroup.
|
|
392
|
-
queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
421
|
+
else if (field.leafValueType === 'Sum') {
|
|
422
|
+
queryGroup[field.id] = { '$sum': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
393
423
|
}
|
|
394
|
-
else if (
|
|
395
|
-
queryGroup.
|
|
396
|
-
queryGroup._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
424
|
+
else if (field.leafValueType === 'Count') {
|
|
425
|
+
queryGroup[field.id] = { '$sum': '$count_' + field.fieldPath.replace(/\.\$/g, '') };
|
|
397
426
|
}
|
|
398
|
-
else if (
|
|
399
|
-
queryGroup.
|
|
427
|
+
else if (field.leafValueType === 'Minimum') {
|
|
428
|
+
queryGroup[field.id] = { '$min': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
400
429
|
}
|
|
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 };
|
|
430
|
+
else if (field.leafValueType === 'Maximum') {
|
|
431
|
+
queryGroup[field.id] = { '$max': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
432
|
+
}
|
|
433
|
+
else if (field.leafValueType === 'First' || (!groupsRow.length && !field.fieldPath.includes('.$'))) {
|
|
434
|
+
queryGroup[field.id] = { '$first': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
435
|
+
}
|
|
436
|
+
else if (field.leafValueType === 'Last') {
|
|
437
|
+
queryGroup[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
queryGroup[field.id] = { '$push': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
// Totals
|
|
444
|
+
if (fieldsTotal.length) {
|
|
445
|
+
fieldsTotal.forEach(function (total) {
|
|
446
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number'; }).forEach(function (field) {
|
|
447
|
+
// queryGroup[total.id + '_' + field.id] = {['$' + total.type]: '$' + total.id + '_' + field.id};
|
|
448
|
+
queryGroup[total.id + '_' + field.id] = { $sum: '$' + total.id + '_' + field.id };
|
|
449
|
+
});
|
|
435
450
|
});
|
|
451
|
+
}
|
|
452
|
+
query.push({ $group: queryGroup });
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
queryProjection_1 = {
|
|
456
|
+
_id: 1
|
|
457
|
+
};
|
|
458
|
+
selectedFields.forEach(function (field) {
|
|
459
|
+
if (field.leafValueType === 'Average') {
|
|
460
|
+
queryProjection_1[field.id] = { $avg: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
461
|
+
}
|
|
462
|
+
else if (field.leafValueType === 'Sum') {
|
|
463
|
+
queryProjection_1[field.id] = { $sum: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
464
|
+
}
|
|
465
|
+
else if (field.leafValueType === 'Count') {
|
|
466
|
+
queryProjection_1[field.id] = { $sum: 1 };
|
|
467
|
+
}
|
|
468
|
+
else if (field.leafValueType === 'Minimum') {
|
|
469
|
+
queryProjection_1[field.id] = { $min: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
470
|
+
}
|
|
471
|
+
else if (field.leafValueType === 'Maximum') {
|
|
472
|
+
queryProjection_1[field.id] = { $max: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
473
|
+
}
|
|
474
|
+
else if (field.leafValueType === 'First') {
|
|
475
|
+
queryProjection_1[field.id] = { $slice: ['$' + field.fieldPath.replace(/\.\$/g, ''), 0] };
|
|
476
|
+
}
|
|
477
|
+
else if (field.leafValueType === 'Last') {
|
|
478
|
+
queryProjection_1[field.id] = { $slice: ['$' + field.fieldPath.replace(/\.\$/g, ''), -1] };
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
queryProjection_1[field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
482
|
+
}
|
|
436
483
|
});
|
|
484
|
+
//Links
|
|
485
|
+
// if (fieldsLink.length) {
|
|
486
|
+
// fieldsLink.filter(a => a.field_first && a.field_second).forEach(link => {
|
|
487
|
+
// queryProjection[link.id] = {$cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')]};
|
|
488
|
+
// });
|
|
489
|
+
// }
|
|
490
|
+
//Totals
|
|
491
|
+
if (fieldsTotal.length && (reportType === 'Tabular' || reportType === 'Dated')) {
|
|
492
|
+
fieldsTotal.forEach(function (total) {
|
|
493
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number'; }).forEach(function (field) {
|
|
494
|
+
var _a;
|
|
495
|
+
queryProjection_1[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.id, _a);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
query.push({ $project: queryProjection_1 });
|
|
437
500
|
}
|
|
438
|
-
query.push({ $group: queryGroup });
|
|
439
501
|
// SORT
|
|
440
502
|
if (rootOptions.sort && reportType !== 'Tabular Group') {
|
|
441
503
|
query.push({
|
package/package.json
CHANGED
package/server-app.js
CHANGED
|
@@ -328,6 +328,11 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
328
328
|
ws.on('close', function () {
|
|
329
329
|
_this.unsubscribeWS(ws);
|
|
330
330
|
});
|
|
331
|
+
ws.on('error', function (error) {
|
|
332
|
+
console.log(error);
|
|
333
|
+
_this.unsubscribeWS(ws);
|
|
334
|
+
ws.terminate();
|
|
335
|
+
});
|
|
331
336
|
});
|
|
332
337
|
// Keep alive timer to ping/pong
|
|
333
338
|
setInterval(function () {
|