@resolveio/server-lib 4.5.2-newrole → 4.5.3
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/report-builder.js +92 -44
- 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;
|
|
@@ -196,7 +196,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
196
196
|
if (date_field === void 0) { date_field = ''; }
|
|
197
197
|
if (date_interval === void 0) { date_interval = ''; }
|
|
198
198
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
199
|
-
var _a, uniqueSelectedFieldCollections, modelCollection, queryMatchCondition, queryLookups, queryGroupUnwindCollectionPaths, queryUnwindCollectionPaths, initialProjection, queryGroups, queryGroupUnwind, initialGroup, secondInitialGroup, zipLayers, cnt, _loop_1, correctSort_1, _loop_2, i, queryProjection, queryTotals, query, i, res, err_1;
|
|
199
|
+
var _a, uniqueSelectedFieldCollections, modelCollection, queryMatchCondition, queryLookups, queryGroupUnwindCollectionPaths, queryUnwindCollectionPaths, initialProjection, queryGroups, queryGroupUnwind, initialGroup, secondInitialGroup, zipLayers, initialNonSumFilterProj, initialNonSumElemAtProj, initialNonSumValueProj, cnt, _loop_1, correctSort_1, _loop_2, i, queryProjection, queryTotals, query, i, res, err_1;
|
|
200
200
|
return __generator(this, function (_b) {
|
|
201
201
|
switch (_b.label) {
|
|
202
202
|
case 0:
|
|
@@ -346,7 +346,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
346
346
|
initialGroup = { _id: {} };
|
|
347
347
|
groupsRow.forEach(function (row) {
|
|
348
348
|
initialGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
349
|
-
initialGroup.rb_arrays_0 = { '$
|
|
349
|
+
initialGroup.rb_arrays_0 = { '$push': '$rb_arrays_0' };
|
|
350
350
|
initialGroup.count = { '$sum': '$count' };
|
|
351
351
|
selectedFields.filter(function (a) { return !a.fieldPath.includes('$') && a.collection_name === rootCollectionName; }).forEach(function (field) {
|
|
352
352
|
if (field.leafValueType === 'Average') {
|
|
@@ -425,6 +425,70 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
425
425
|
});
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
|
+
initialNonSumFilterProj = null;
|
|
429
|
+
initialNonSumElemAtProj = null;
|
|
430
|
+
initialNonSumValueProj = null;
|
|
431
|
+
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === 2 && (a.leafValueType !== 'Average' && a.leafValueType !== 'Sum'); })) {
|
|
432
|
+
initialNonSumFilterProj = { $addFields: {} };
|
|
433
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
|
|
434
|
+
var _a;
|
|
435
|
+
initialNonSumFilterProj.$addFields['rb_arrays_0_' + field.id] = {
|
|
436
|
+
$filter: {
|
|
437
|
+
input: '$rb_arrays_0',
|
|
438
|
+
cond: {
|
|
439
|
+
$and: [
|
|
440
|
+
{ $ne: ['$$this', null] },
|
|
441
|
+
{ $ne: ['$$this.' + field.fieldPath.split('.$.')[0], null] },
|
|
442
|
+
{ $ne: ['$$this.' + field.fieldPath.split('.$.')[0] + field.fieldPath.split('.$')[1], null] }
|
|
443
|
+
]
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
if (filterArrayPaths.some(function (a) { return a === field.fieldPath; })) {
|
|
448
|
+
var tmpOr_1 = [];
|
|
449
|
+
var filter = common_1.deepCopy(filterArrays[filterArrayPaths.indexOf(field.fieldPath)]);
|
|
450
|
+
if (filter['$or']) {
|
|
451
|
+
filter['$or'].forEach(function (orVal) {
|
|
452
|
+
var _a;
|
|
453
|
+
tmpOr_1.push((_a = {},
|
|
454
|
+
_a[Object.keys(orVal[Object.keys(orVal)[0]])[0]] = ['$$this.' + field.fieldPath.split('.$.')[0] + field.fieldPath.split('.$')[1], orVal[Object.keys(orVal)[0]][Object.keys(orVal[Object.keys(orVal)[0]])[0]]],
|
|
455
|
+
_a));
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
initialNonSumFilterProj.$addFields['rb_arrays_0_' + field.id].$filter.cond.$and.push((_a = {}, _a[Object.keys(filter[Object.keys(filter)[0]])[0]] = ['$$this.' + field.fieldPath.split('.$.')[0] + field.fieldPath.split('.$')[1], filter[Object.keys(filter)[0]][Object.keys(filter[Object.keys(filter)[0]])[0]]], _a));
|
|
460
|
+
}
|
|
461
|
+
if (tmpOr_1.length) {
|
|
462
|
+
initialNonSumFilterProj.$addFields['rb_arrays_0_' + field.id].$filter.cond.$and.push({ $or: tmpOr_1 });
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
initialNonSumElemAtProj = { $addFields: {} };
|
|
467
|
+
initialNonSumValueProj = { $addFields: {} };
|
|
468
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
|
|
469
|
+
initialNonSumElemAtProj.$addFields['rb_arrays_0_' + field.id] = '$rb_arrays_0_' + field.id + '.' + field.fieldPath.split('.$')[0];
|
|
470
|
+
});
|
|
471
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
|
|
472
|
+
if (field.leafValueType === 'Count') {
|
|
473
|
+
initialNonSumValueProj.$addFields[field.id] = { '$size': '$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1] };
|
|
474
|
+
}
|
|
475
|
+
else if (field.leafValueType === 'Minimum') {
|
|
476
|
+
initialNonSumValueProj.$addFields[field.id] = { '$min': '$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1] };
|
|
477
|
+
}
|
|
478
|
+
else if (field.leafValueType === 'Maximum') {
|
|
479
|
+
initialNonSumValueProj.$addFields[field.id] = { '$max': '$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1] };
|
|
480
|
+
}
|
|
481
|
+
else if (field.leafValueType === 'First') {
|
|
482
|
+
initialNonSumValueProj.$addFields[field.id] = { '$arrayElemAt': ['$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1], 0] };
|
|
483
|
+
}
|
|
484
|
+
else if (field.leafValueType === 'Last') {
|
|
485
|
+
initialNonSumValueProj.$addFields[field.id] = { '$arrayElemAt': ['$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1], -1] };
|
|
486
|
+
}
|
|
487
|
+
else { //push
|
|
488
|
+
initialNonSumValueProj.$addFields[field.id] = '$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1];
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
428
492
|
cnt = 1;
|
|
429
493
|
_loop_1 = function () {
|
|
430
494
|
var group = { $group: { _id: {} } };
|
|
@@ -463,12 +527,12 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
463
527
|
}
|
|
464
528
|
zipLayers.push(group);
|
|
465
529
|
}
|
|
466
|
-
var proj = { $
|
|
530
|
+
var proj = { $addFields: {} };
|
|
467
531
|
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt + 1; }).forEach(function (field) {
|
|
468
|
-
proj.$
|
|
532
|
+
proj.$addFields[field.id] = 1;
|
|
469
533
|
});
|
|
470
534
|
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 2; })) {
|
|
471
|
-
proj.$
|
|
535
|
+
proj.$addFields['rb_arrays_' + cnt] = {
|
|
472
536
|
$map: {
|
|
473
537
|
input: {
|
|
474
538
|
$zip: {
|
|
@@ -485,10 +549,10 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
485
549
|
for (var i = 1; i < cnt + 1; i++) {
|
|
486
550
|
fieldPath += field.fieldPath.split('.$')[i];
|
|
487
551
|
}
|
|
488
|
-
if (!proj.$
|
|
489
|
-
if (!proj.$
|
|
490
|
-
proj.$
|
|
491
|
-
proj.$
|
|
552
|
+
if (!proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$' + fieldPath; })) {
|
|
553
|
+
if (!proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$rb_arrays_' + (cnt - 1) + '.' + fieldPath; })) {
|
|
554
|
+
proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.push('$rb_arrays_' + (cnt - 1) + '.' + fieldPath);
|
|
555
|
+
proj.$addFields['rb_arrays_' + cnt].$map.in[field.fieldPath.split('.$.')[cnt]] = {
|
|
492
556
|
$arrayElemAt: ['$$zipped', index]
|
|
493
557
|
};
|
|
494
558
|
}
|
|
@@ -499,37 +563,6 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
499
563
|
path: '$rb_arrays_' + cnt,
|
|
500
564
|
preserveNullAndEmptyArrays: true
|
|
501
565
|
} });
|
|
502
|
-
var tmpMatch = {
|
|
503
|
-
"$match": {
|
|
504
|
-
$and: []
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
var newfilterArrays_1 = [];
|
|
508
|
-
filterArrayPaths.forEach(function (filterPath, index) {
|
|
509
|
-
var _a;
|
|
510
|
-
var tmpOr = [];
|
|
511
|
-
if (filterPath.split('.$').length === cnt + 2) {
|
|
512
|
-
var filter = common_1.deepCopy(filterArrays[index]);
|
|
513
|
-
if (filter['$or']) {
|
|
514
|
-
filter['$or'].forEach(function (orVal) {
|
|
515
|
-
var _a;
|
|
516
|
-
var filterProp = '$rb_arrays_' + cnt + '.' + Object.keys(orVal)[0];
|
|
517
|
-
tmpOr.push((_a = {}, _a[filterProp] = orVal[Object.keys(orVal)[0]], _a));
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
var filterProp = '$rb_arrays_' + cnt + '.' + Object.keys(filter)[0];
|
|
522
|
-
newfilterArrays_1.push((_a = {}, _a[filterProp] = filter[Object.keys(filter)[0]], _a));
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
if (tmpOr.length) {
|
|
526
|
-
newfilterArrays_1.push({ $or: tmpOr });
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
tmpMatch.$match.$and = newfilterArrays_1;
|
|
530
|
-
if (tmpMatch.$match.$and.length) {
|
|
531
|
-
zipLayers.push(tmpMatch);
|
|
532
|
-
}
|
|
533
566
|
}
|
|
534
567
|
cnt++;
|
|
535
568
|
};
|
|
@@ -738,17 +771,32 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
738
771
|
$group: initialGroup
|
|
739
772
|
});
|
|
740
773
|
}
|
|
774
|
+
if (secondInitialGroup) {
|
|
775
|
+
query.push({
|
|
776
|
+
$group: secondInitialGroup
|
|
777
|
+
});
|
|
778
|
+
}
|
|
741
779
|
query.push({
|
|
742
780
|
$unwind: {
|
|
743
781
|
"path": "$rb_arrays_0",
|
|
744
782
|
"preserveNullAndEmptyArrays": true
|
|
745
783
|
}
|
|
746
784
|
});
|
|
747
|
-
if (
|
|
748
|
-
query.push(
|
|
749
|
-
$group: secondInitialGroup
|
|
750
|
-
});
|
|
785
|
+
if (initialNonSumFilterProj) {
|
|
786
|
+
query.push(initialNonSumFilterProj);
|
|
751
787
|
}
|
|
788
|
+
if (initialNonSumElemAtProj) {
|
|
789
|
+
query.push(initialNonSumElemAtProj);
|
|
790
|
+
}
|
|
791
|
+
if (initialNonSumValueProj) {
|
|
792
|
+
query.push(initialNonSumValueProj);
|
|
793
|
+
}
|
|
794
|
+
query.push({
|
|
795
|
+
$unwind: {
|
|
796
|
+
"path": "$rb_arrays_0",
|
|
797
|
+
"preserveNullAndEmptyArrays": true
|
|
798
|
+
}
|
|
799
|
+
});
|
|
752
800
|
for (i = 0; i < zipLayers.length; i++) {
|
|
753
801
|
query.push(zipLayers[i]);
|
|
754
802
|
}
|