@resolveio/server-lib 4.6.5-newrole → 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/collections/user.collection.js +32 -39
- package/fixtures/init.js +1 -1
- package/methods/cron-jobs.js +1 -1
- package/methods/report-builder.js +109 -58
- package/package.json +1 -1
|
@@ -22,6 +22,13 @@ var schema = {
|
|
|
22
22
|
type: Date,
|
|
23
23
|
optional: true
|
|
24
24
|
},
|
|
25
|
+
readonly: {
|
|
26
|
+
type: Boolean,
|
|
27
|
+
optional: true
|
|
28
|
+
},
|
|
29
|
+
active: {
|
|
30
|
+
type: Boolean
|
|
31
|
+
},
|
|
25
32
|
attempts: {
|
|
26
33
|
type: Number,
|
|
27
34
|
optional: true
|
|
@@ -58,67 +65,53 @@ var schema = {
|
|
|
58
65
|
type: String
|
|
59
66
|
},
|
|
60
67
|
roles: {
|
|
61
|
-
type: Object
|
|
62
|
-
},
|
|
63
|
-
'roles.super_admin': {
|
|
64
|
-
type: Boolean
|
|
65
|
-
},
|
|
66
|
-
'roles.approvals': {
|
|
67
68
|
type: Array
|
|
68
69
|
},
|
|
69
|
-
'roles
|
|
70
|
-
type: Object
|
|
71
|
-
},
|
|
72
|
-
'roles.approvals.$.name': {
|
|
70
|
+
'roles.$': {
|
|
73
71
|
type: String
|
|
74
72
|
},
|
|
75
|
-
|
|
76
|
-
type: String
|
|
73
|
+
phonenumber: {
|
|
74
|
+
type: String,
|
|
75
|
+
optional: true
|
|
77
76
|
},
|
|
78
|
-
|
|
79
|
-
type:
|
|
77
|
+
other: {
|
|
78
|
+
type: Object,
|
|
79
|
+
blackbox: true,
|
|
80
|
+
optional: true
|
|
80
81
|
},
|
|
81
|
-
|
|
82
|
-
type: Array
|
|
82
|
+
assets: {
|
|
83
|
+
type: Array,
|
|
84
|
+
optional: true
|
|
83
85
|
},
|
|
84
|
-
'
|
|
86
|
+
'assets.$': {
|
|
85
87
|
type: Object
|
|
86
88
|
},
|
|
87
|
-
'
|
|
89
|
+
'assets.$.type': {
|
|
88
90
|
type: String
|
|
89
91
|
},
|
|
90
|
-
'
|
|
91
|
-
type: Array
|
|
92
|
-
},
|
|
93
|
-
'roles.groups.$.views.$': {
|
|
92
|
+
'assets.$.id_asset': {
|
|
94
93
|
type: String
|
|
95
94
|
},
|
|
96
|
-
'
|
|
97
|
-
type: String
|
|
98
|
-
optional: true
|
|
95
|
+
'assets.$.asset_number': {
|
|
96
|
+
type: String
|
|
99
97
|
},
|
|
100
|
-
'
|
|
101
|
-
type:
|
|
98
|
+
'assets.$.ownership': {
|
|
99
|
+
type: String
|
|
102
100
|
},
|
|
103
|
-
'
|
|
101
|
+
'assets.$.ownership_driver': {
|
|
104
102
|
type: String
|
|
105
103
|
},
|
|
106
|
-
'
|
|
107
|
-
type:
|
|
104
|
+
'assets.$.date_start': {
|
|
105
|
+
type: Date
|
|
108
106
|
},
|
|
109
|
-
'
|
|
110
|
-
type:
|
|
107
|
+
'assets.$.date_end': {
|
|
108
|
+
type: Date,
|
|
109
|
+
optional: true
|
|
111
110
|
},
|
|
112
|
-
|
|
113
|
-
phonenumber: {
|
|
111
|
+
id_function: {
|
|
114
112
|
type: String,
|
|
115
113
|
optional: true
|
|
116
114
|
},
|
|
117
|
-
other: {
|
|
118
|
-
type: Object,
|
|
119
|
-
optional: true,
|
|
120
|
-
blackbox: true
|
|
121
|
-
},
|
|
122
115
|
customers: {
|
|
123
116
|
type: Array,
|
|
124
117
|
optional: true,
|
package/fixtures/init.js
CHANGED
|
@@ -37,8 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
var app_version_collection_1 = require("../collections/app-version.collection");
|
|
39
39
|
var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
|
|
40
|
-
var mongoose_1 = require("mongoose");
|
|
41
40
|
var active_subscription_collection_1 = require("../collections/active-subscription.collection");
|
|
41
|
+
var mongoose_1 = require("mongoose");
|
|
42
42
|
function loadServerInit() {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function () {
|
|
44
44
|
var appVersion;
|
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({
|