@resolveio/server-lib 4.5.0 → 4.5.2-newrole
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 +39 -32
- package/fixtures/init.js +1 -1
- package/methods/cron-jobs.js +4 -2
- package/methods/report-builder.js +473 -176
- package/package.json +1 -1
- package/server-app.js +10 -0
|
@@ -22,13 +22,6 @@ 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
|
-
},
|
|
32
25
|
attempts: {
|
|
33
26
|
type: Number,
|
|
34
27
|
optional: true
|
|
@@ -65,53 +58,67 @@ var schema = {
|
|
|
65
58
|
type: String
|
|
66
59
|
},
|
|
67
60
|
roles: {
|
|
61
|
+
type: Object
|
|
62
|
+
},
|
|
63
|
+
'roles.super_admin': {
|
|
64
|
+
type: Boolean
|
|
65
|
+
},
|
|
66
|
+
'roles.approvals': {
|
|
68
67
|
type: Array
|
|
69
68
|
},
|
|
70
|
-
'roles.$': {
|
|
69
|
+
'roles.approvals.$': {
|
|
70
|
+
type: Object
|
|
71
|
+
},
|
|
72
|
+
'roles.approvals.$.name': {
|
|
71
73
|
type: String
|
|
72
74
|
},
|
|
73
|
-
|
|
74
|
-
type: String
|
|
75
|
-
optional: true
|
|
75
|
+
'roles.approvals.$.type': {
|
|
76
|
+
type: String
|
|
76
77
|
},
|
|
77
|
-
|
|
78
|
-
type:
|
|
79
|
-
blackbox: true,
|
|
80
|
-
optional: true
|
|
78
|
+
'roles.approvals.$.accounting_code': {
|
|
79
|
+
type: String
|
|
81
80
|
},
|
|
82
|
-
|
|
83
|
-
type: Array
|
|
84
|
-
optional: true
|
|
81
|
+
'roles.groups': {
|
|
82
|
+
type: Array
|
|
85
83
|
},
|
|
86
|
-
'
|
|
84
|
+
'roles.groups.$': {
|
|
87
85
|
type: Object
|
|
88
86
|
},
|
|
89
|
-
'
|
|
87
|
+
'roles.groups.$.name': {
|
|
90
88
|
type: String
|
|
91
89
|
},
|
|
92
|
-
'
|
|
93
|
-
type:
|
|
90
|
+
'roles.groups.$.views': {
|
|
91
|
+
type: Array
|
|
94
92
|
},
|
|
95
|
-
'
|
|
93
|
+
'roles.groups.$.views.$': {
|
|
96
94
|
type: String
|
|
97
95
|
},
|
|
98
|
-
'
|
|
99
|
-
type: String
|
|
96
|
+
'roles.groups.$.yard': {
|
|
97
|
+
type: String,
|
|
98
|
+
optional: true
|
|
99
|
+
},
|
|
100
|
+
'roles.notifications': {
|
|
101
|
+
type: Array
|
|
100
102
|
},
|
|
101
|
-
'
|
|
103
|
+
'roles.notifications.$': {
|
|
102
104
|
type: String
|
|
103
105
|
},
|
|
104
|
-
'
|
|
105
|
-
type:
|
|
106
|
+
'roles.miscs': {
|
|
107
|
+
type: Array
|
|
106
108
|
},
|
|
107
|
-
'
|
|
108
|
-
type:
|
|
109
|
-
optional: true
|
|
109
|
+
'roles.miscs.$': {
|
|
110
|
+
type: String
|
|
110
111
|
},
|
|
111
|
-
|
|
112
|
+
active: Boolean,
|
|
113
|
+
phonenumber: {
|
|
112
114
|
type: String,
|
|
113
115
|
optional: true
|
|
114
116
|
},
|
|
117
|
+
other: {
|
|
118
|
+
type: Object,
|
|
119
|
+
optional: true,
|
|
120
|
+
blackbox: true
|
|
121
|
+
},
|
|
115
122
|
customers: {
|
|
116
123
|
type: Array,
|
|
117
124
|
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 active_subscription_collection_1 = require("../collections/active-subscription.collection");
|
|
41
40
|
var mongoose_1 = require("mongoose");
|
|
41
|
+
var active_subscription_collection_1 = require("../collections/active-subscription.collection");
|
|
42
42
|
function loadServerInit() {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function () {
|
|
44
44
|
var appVersion;
|
package/methods/cron-jobs.js
CHANGED
|
@@ -142,7 +142,7 @@ function loadCronJobMethods(methodManager) {
|
|
|
142
142
|
function: function (data) {
|
|
143
143
|
var _this = this;
|
|
144
144
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
145
|
-
var report, fieldsObj_1, count_1, sortObj_1, rootOptions, filters_1, filterArrays_1;
|
|
145
|
+
var report, fieldsObj_1, count_1, sortObj_1, rootOptions, filters_1, filterArrayPaths_1, filterArrays_1;
|
|
146
146
|
var _this = this;
|
|
147
147
|
return __generator(this, function (_a) {
|
|
148
148
|
switch (_a.label) {
|
|
@@ -292,10 +292,12 @@ function loadCronJobMethods(methodManager) {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
});
|
|
295
|
+
filterArrayPaths_1 = [];
|
|
295
296
|
filterArrays_1 = [];
|
|
296
297
|
report.fields_filter.filter(function (a) { return a.field.includes('.$.'); }).forEach(function (filter) {
|
|
297
298
|
var _a, _b, _c, _d, _e, _f;
|
|
298
299
|
if (filter.condition && filter.field && filter.value !== null) {
|
|
300
|
+
filterArrayPaths_1.push(filter.field);
|
|
299
301
|
if (filter.condition === 'bw') {
|
|
300
302
|
if (filter.fieldType === 'Date' && filter.is_rolling) {
|
|
301
303
|
var startDate = null;
|
|
@@ -387,7 +389,7 @@ function loadCronJobMethods(methodManager) {
|
|
|
387
389
|
}
|
|
388
390
|
}
|
|
389
391
|
});
|
|
390
|
-
this.callMethodInternal.call(this, 'reportBuilderGetResults', report.type, report.collection_root, rootOptions, filters_1, filterArrays_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, function (err, res) {
|
|
391
393
|
if (res && res[0]) {
|
|
392
394
|
var fields_1 = [];
|
|
393
395
|
var results_1 = res[0].results;
|
|
@@ -137,6 +137,14 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
137
137
|
blackbox: true,
|
|
138
138
|
optional: true
|
|
139
139
|
},
|
|
140
|
+
filterArrayPaths: {
|
|
141
|
+
type: Array,
|
|
142
|
+
optional: true
|
|
143
|
+
},
|
|
144
|
+
'filterArrayPaths.$': {
|
|
145
|
+
type: String,
|
|
146
|
+
optional: true
|
|
147
|
+
},
|
|
140
148
|
selectedFields: {
|
|
141
149
|
type: Array,
|
|
142
150
|
optional: true
|
|
@@ -176,10 +184,11 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
176
184
|
optional: true
|
|
177
185
|
}
|
|
178
186
|
}),
|
|
179
|
-
function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval) {
|
|
187
|
+
function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayPaths, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval) {
|
|
180
188
|
var _this = this;
|
|
181
189
|
if (filters === void 0) { filters = []; }
|
|
182
190
|
if (filterArrays === void 0) { filterArrays = []; }
|
|
191
|
+
if (filterArrayPaths === void 0) { filterArrayPaths = []; }
|
|
183
192
|
if (selectedFields === void 0) { selectedFields = []; }
|
|
184
193
|
if (groupsRow === void 0) { groupsRow = []; }
|
|
185
194
|
if (fieldsTotal === void 0) { fieldsTotal = []; }
|
|
@@ -187,10 +196,9 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
187
196
|
if (date_field === void 0) { date_field = ''; }
|
|
188
197
|
if (date_interval === void 0) { date_interval = ''; }
|
|
189
198
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
190
|
-
var _a,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
switch (_c.label) {
|
|
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;
|
|
200
|
+
return __generator(this, function (_b) {
|
|
201
|
+
switch (_b.label) {
|
|
194
202
|
case 0:
|
|
195
203
|
uniqueSelectedFieldCollections = selectedFields.map(function (a) { return a.collection_name; }).filter(function (elem, index, self) {
|
|
196
204
|
return index === self.indexOf(elem);
|
|
@@ -219,6 +227,15 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
219
227
|
queryMatchCondition['$and'].push(filter);
|
|
220
228
|
});
|
|
221
229
|
}
|
|
230
|
+
if (filters.filter(function (a) { return (!a['$or'] && Object.keys(a).some(function (b) { return b.includes('(Lookup)'); })) || (a['$or'] && a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup)'); }); })); }).length) {
|
|
231
|
+
filters.filter(function (a) { return (!a['$or'] && Object.keys(a).some(function (b) { return b.includes('(Lookup)'); })) || (a['$or'] && a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup)'); }); })); }).forEach(function (filter) {
|
|
232
|
+
queryMatchCondition['$and'].push(filter);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
filterArrays.forEach(function (filter) {
|
|
236
|
+
queryMatchCondition['$and'].push(filter);
|
|
237
|
+
// queryMatchConditionLookup['$and'].push(filter);
|
|
238
|
+
});
|
|
222
239
|
queryLookups = [];
|
|
223
240
|
// Lookup Groups
|
|
224
241
|
groupsRow.filter(function (a) { return a.treeItem.collection_name !== rootCollectionName; }).forEach(function (group) {
|
|
@@ -266,87 +283,337 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
266
283
|
}
|
|
267
284
|
}
|
|
268
285
|
});
|
|
286
|
+
initialProjection = { _id: 1, count: { $sum: 1 } };
|
|
287
|
+
// Projection
|
|
288
|
+
groupsRow.filter(function (a) { return !a.treeItem.fieldPath.includes('$'); }).forEach(function (row) {
|
|
289
|
+
initialProjection[row.treeItem.fieldPath] = 1;
|
|
290
|
+
});
|
|
291
|
+
selectedFields.filter(function (a) { return !a.fieldPath.includes('$'); }).forEach(function (field) {
|
|
292
|
+
initialProjection[field.fieldPath] = 1;
|
|
293
|
+
});
|
|
294
|
+
selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field) {
|
|
295
|
+
initialProjection[field.fieldPath.split('.$')[0]] = 1;
|
|
296
|
+
});
|
|
297
|
+
initialProjection['rb_arrays_0'] = {
|
|
298
|
+
$map: {
|
|
299
|
+
input: {
|
|
300
|
+
$zip: {
|
|
301
|
+
inputs: [
|
|
302
|
+
// '$chemicals',
|
|
303
|
+
// '$drivers',
|
|
304
|
+
// '$invoices'
|
|
305
|
+
],
|
|
306
|
+
useLongestLength: true
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
as: 'zipped',
|
|
310
|
+
in: {
|
|
311
|
+
// chemicals: {
|
|
312
|
+
// $arrayElemAt: [
|
|
313
|
+
// '$$zipped',
|
|
314
|
+
// 0
|
|
315
|
+
// ]
|
|
316
|
+
// },
|
|
317
|
+
// drivers: {
|
|
318
|
+
// $arrayElemAt: [
|
|
319
|
+
// '$$zipped',
|
|
320
|
+
// 1
|
|
321
|
+
// ]
|
|
322
|
+
// },
|
|
323
|
+
// invoices: {
|
|
324
|
+
// $arrayElemAt: [
|
|
325
|
+
// '$$zipped',
|
|
326
|
+
// 2
|
|
327
|
+
// ]
|
|
328
|
+
// }
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field, index) {
|
|
333
|
+
if (!initialProjection['rb_arrays_0'].$map.input.$zip.inputs.some(function (a) { return a === '$' + field.fieldPath.split('.$')[0]; })) {
|
|
334
|
+
initialProjection['rb_arrays_0'].$map.input.$zip.inputs.push('$' + field.fieldPath.split('.$')[0]);
|
|
335
|
+
initialProjection['rb_arrays_0'].$map.in[field.fieldPath.split('.$')[0]] = {
|
|
336
|
+
$arrayElemAt: ['$$zipped', index]
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
});
|
|
269
340
|
queryGroups = [];
|
|
270
341
|
queryGroupUnwind = [];
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
342
|
+
initialGroup = null;
|
|
343
|
+
secondInitialGroup = null;
|
|
344
|
+
zipLayers = [];
|
|
345
|
+
if (groupsRow.length && !groupsRow.some(function (a) { return a.treeItem.fieldPath.includes('$') || a.treeItem.collection_name !== rootCollectionName; })) {
|
|
346
|
+
initialGroup = { _id: {} };
|
|
275
347
|
groupsRow.forEach(function (row) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
348
|
+
initialGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
349
|
+
initialGroup.rb_arrays_0 = { '$first': '$rb_arrays_0' };
|
|
350
|
+
initialGroup.count = { '$sum': '$count' };
|
|
351
|
+
selectedFields.filter(function (a) { return !a.fieldPath.includes('$') && a.collection_name === rootCollectionName; }).forEach(function (field) {
|
|
352
|
+
if (field.leafValueType === 'Average') {
|
|
353
|
+
initialGroup[field.id] = { '$avg': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
282
354
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (date_field && date_interval) {
|
|
286
|
-
if (date_interval === 'Daily') {
|
|
287
|
-
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
288
|
-
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
289
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
355
|
+
else if (field.leafValueType === 'Sum') {
|
|
356
|
+
initialGroup[field.id] = { '$sum': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
290
357
|
}
|
|
291
|
-
else if (
|
|
292
|
-
|
|
293
|
-
// queryGroup._id['month'] = {'$month' : '$' + date_field.replace(/\.\$/g, '')};
|
|
294
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
358
|
+
else if (field.leafValueType === 'Count') {
|
|
359
|
+
initialGroup[field.id] = { '$sum': 1 };
|
|
295
360
|
}
|
|
296
|
-
else if (
|
|
297
|
-
|
|
298
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
361
|
+
else if (field.leafValueType === 'Minimum') {
|
|
362
|
+
initialGroup[field.id] = { '$min': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
299
363
|
}
|
|
300
|
-
else if (
|
|
301
|
-
|
|
302
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
364
|
+
else if (field.leafValueType === 'Maximum') {
|
|
365
|
+
initialGroup[field.id] = { '$max': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
303
366
|
}
|
|
304
|
-
else if (
|
|
305
|
-
|
|
367
|
+
else if (field.leafValueType === 'First') {
|
|
368
|
+
initialGroup[field.id] = { '$first': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
306
369
|
}
|
|
307
|
-
|
|
370
|
+
else if (field.leafValueType === 'Last') {
|
|
371
|
+
initialGroup[field.id] = { '$last': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
initialGroup[field.id] = { '$push': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
375
|
+
}
|
|
376
|
+
});
|
|
308
377
|
});
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
378
|
+
if (fieldsTotal.length) {
|
|
379
|
+
fieldsTotal.forEach(function (total) {
|
|
380
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && !a.fieldPath.includes('$'); }).forEach(function (field) {
|
|
381
|
+
var _a;
|
|
382
|
+
initialGroup[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + field.fieldPath.replace(/\.\$/g, ''), _a);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
else if (groupsRow.length) { //group has array or lookup
|
|
388
|
+
// project next layers
|
|
389
|
+
secondInitialGroup = { _id: {} };
|
|
390
|
+
groupsRow.forEach(function (row) {
|
|
391
|
+
secondInitialGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
392
|
+
selectedFields.filter(function (a) { return !a.fieldPath.includes('$') && a.collection_name !== rootCollectionName; }).forEach(function (field) {
|
|
393
|
+
if (field.leafValueType === 'Average') {
|
|
394
|
+
secondInitialGroup[field.id] = { '$avg': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
395
|
+
}
|
|
396
|
+
else if (field.leafValueType === 'Sum') {
|
|
397
|
+
secondInitialGroup[field.id] = { '$sum': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
398
|
+
}
|
|
399
|
+
else if (field.leafValueType === 'Count') {
|
|
400
|
+
secondInitialGroup[field.id] = { '$sum': 1 };
|
|
401
|
+
}
|
|
402
|
+
else if (field.leafValueType === 'Minimum') {
|
|
403
|
+
secondInitialGroup[field.id] = { '$min': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
404
|
+
}
|
|
405
|
+
else if (field.leafValueType === 'Maximum') {
|
|
406
|
+
secondInitialGroup[field.id] = { '$max': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
407
|
+
}
|
|
408
|
+
else if (field.leafValueType === 'First') {
|
|
409
|
+
secondInitialGroup[field.id] = { '$first': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
410
|
+
}
|
|
411
|
+
else if (field.leafValueType === 'Last') {
|
|
412
|
+
secondInitialGroup[field.id] = { '$last': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
secondInitialGroup[field.id] = { '$push': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, '')) };
|
|
416
|
+
}
|
|
417
|
+
});
|
|
334
418
|
});
|
|
335
|
-
//Totals
|
|
336
419
|
if (fieldsTotal.length) {
|
|
337
420
|
fieldsTotal.forEach(function (total) {
|
|
338
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number'; }).forEach(function (field) {
|
|
421
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && !a.fieldPath.includes('$'); }).forEach(function (field) {
|
|
339
422
|
var _a;
|
|
340
|
-
|
|
423
|
+
secondInitialGroup[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + field.fieldPath.replace(/\.\$/g, ''), _a);
|
|
341
424
|
});
|
|
342
425
|
});
|
|
343
426
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
427
|
+
}
|
|
428
|
+
cnt = 1;
|
|
429
|
+
_loop_1 = function () {
|
|
430
|
+
var group = { $group: { _id: {} } };
|
|
431
|
+
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 1 && (a.leafValueType === 'Average' || a.leafValueType === 'Sum'); })) {
|
|
432
|
+
groupsRow.forEach(function (row) {
|
|
433
|
+
group.$group._id[row.id] = '$_id.' + row.id;
|
|
434
|
+
});
|
|
435
|
+
group.$group['rb_arrays_' + (cnt - 1)] = { '$push': '$rb_arrays_' + (cnt - 1) };
|
|
436
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt; }).forEach(function (field) {
|
|
437
|
+
group.$group[field.id] = { $first: '$' + field.id };
|
|
438
|
+
});
|
|
439
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 1; }).forEach(function (field) {
|
|
440
|
+
var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
|
|
441
|
+
if (field.leafValueType === 'Average') {
|
|
442
|
+
group.$group[field.id] = { '$avg': '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
|
|
443
|
+
}
|
|
444
|
+
else if (field.leafValueType === 'Sum') {
|
|
445
|
+
group.$group[field.id] = { '$sum': '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
if (fieldsTotal.length) {
|
|
449
|
+
fieldsTotal.forEach(function (total) {
|
|
450
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === 1; }).forEach(function (field) {
|
|
451
|
+
group.$group[total.id + '_' + field.id] = { $first: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
452
|
+
});
|
|
453
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length < cnt + 1 && a.fieldPath.split('.$').length > 1; }).forEach(function (field) {
|
|
454
|
+
var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
|
|
455
|
+
group.$group[total.id + '_' + field.id] = { $first: '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
|
|
456
|
+
});
|
|
457
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === cnt + 1; }).forEach(function (field) {
|
|
458
|
+
var _a;
|
|
459
|
+
var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
|
|
460
|
+
group.$group[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$rb_arrays_' + (cnt - 1) + '.' + tmpPath, _a);
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
zipLayers.push(group);
|
|
465
|
+
}
|
|
466
|
+
var proj = { $project: { _id: 1, count: 1 } };
|
|
467
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt + 1; }).forEach(function (field) {
|
|
468
|
+
proj.$project[field.id] = 1;
|
|
469
|
+
});
|
|
470
|
+
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 2; })) {
|
|
471
|
+
proj.$project['rb_arrays_' + cnt] = {
|
|
472
|
+
$map: {
|
|
473
|
+
input: {
|
|
474
|
+
$zip: {
|
|
475
|
+
inputs: [],
|
|
476
|
+
useLongestLength: true
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
as: 'zipped',
|
|
480
|
+
in: {}
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field, index) {
|
|
484
|
+
var fieldPath = field.fieldPath.split('.$')[0];
|
|
485
|
+
for (var i = 1; i < cnt + 1; i++) {
|
|
486
|
+
fieldPath += field.fieldPath.split('.$')[i];
|
|
487
|
+
}
|
|
488
|
+
if (!proj.$project['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$' + fieldPath; })) {
|
|
489
|
+
if (!proj.$project['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$rb_arrays_' + (cnt - 1) + '.' + fieldPath; })) {
|
|
490
|
+
proj.$project['rb_arrays_' + cnt].$map.input.$zip.inputs.push('$rb_arrays_' + (cnt - 1) + '.' + fieldPath);
|
|
491
|
+
proj.$project['rb_arrays_' + cnt].$map.in[field.fieldPath.split('.$.')[cnt]] = {
|
|
492
|
+
$arrayElemAt: ['$$zipped', index]
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
zipLayers.push(proj);
|
|
498
|
+
zipLayers.push({ $unwind: {
|
|
499
|
+
path: '$rb_arrays_' + cnt,
|
|
500
|
+
preserveNullAndEmptyArrays: true
|
|
501
|
+
} });
|
|
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
|
+
}
|
|
348
528
|
});
|
|
529
|
+
tmpMatch.$match.$and = newfilterArrays_1;
|
|
530
|
+
if (tmpMatch.$match.$and.length) {
|
|
531
|
+
zipLayers.push(tmpMatch);
|
|
532
|
+
}
|
|
349
533
|
}
|
|
534
|
+
cnt++;
|
|
535
|
+
};
|
|
536
|
+
while (selectedFields.some(function (a) { return a.fieldPath.split('.$').length > cnt; })) {
|
|
537
|
+
_loop_1();
|
|
538
|
+
}
|
|
539
|
+
if (groupsRow.length) {
|
|
540
|
+
// groupsRow.forEach(row => {
|
|
541
|
+
// if (row.field.includes('$')) {
|
|
542
|
+
// let fieldData = row.field.split('.$');
|
|
543
|
+
// let fieldPath = '';
|
|
544
|
+
// for (let i = 0; i < fieldData.length - 1; i++) {
|
|
545
|
+
// fieldPath += fieldData[i];
|
|
546
|
+
// queryGroupUnwind.push({'$unwind': {path: '$' + fieldPath, preserveNullAndEmptyArrays: true}});
|
|
547
|
+
// }
|
|
548
|
+
// }
|
|
549
|
+
// initialGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
550
|
+
// if (date_field && date_interval) {
|
|
551
|
+
// if (date_interval === 'Daily') {
|
|
552
|
+
// initialGroup._id['day'] = {'$dayOfMonth' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
553
|
+
// initialGroup._id['month'] = {'$month' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
554
|
+
// initialGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
555
|
+
// }
|
|
556
|
+
// else if (date_interval === 'Weekly') {
|
|
557
|
+
// initialGroup._id['week'] = {'$week' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
558
|
+
// // queryGroup._id['month'] = {'$month' : '$' + date_field.replace(/\.\$/g, '')};
|
|
559
|
+
// initialGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
560
|
+
// }
|
|
561
|
+
// else if (date_interval === 'Monthly') {
|
|
562
|
+
// initialGroup._id['month'] = {'$month' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
563
|
+
// initialGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
564
|
+
// }
|
|
565
|
+
// else if (date_interval === 'Quarterly') {
|
|
566
|
+
// initialGroup._id['month'] = {'$month' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
567
|
+
// initialGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
568
|
+
// }
|
|
569
|
+
// else if (date_interval === 'Yearly') {
|
|
570
|
+
// initialGroup._id['year'] = {'$year' : {'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': this.serverConfig['TIMEZONE']}};
|
|
571
|
+
// }
|
|
572
|
+
// }
|
|
573
|
+
// });
|
|
574
|
+
// selectedFields.filter(a => !a.fieldPath.includes('$')).forEach(field => {
|
|
575
|
+
// if (field.leafValueType === 'Average') {
|
|
576
|
+
// initialGroup[field.id] = {'$avg': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, ''))};
|
|
577
|
+
// }
|
|
578
|
+
// else if (field.leafValueType === 'Sum') {
|
|
579
|
+
// initialGroup[field.id] = {'$sum': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, ''))};
|
|
580
|
+
// }
|
|
581
|
+
// else if (field.leafValueType === 'Count') {
|
|
582
|
+
// initialGroup[field.id] = {'$sum': 1};
|
|
583
|
+
// }
|
|
584
|
+
// else if (field.leafValueType === 'Minimum') {
|
|
585
|
+
// initialGroup[field.id] = {'$min': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, ''))};
|
|
586
|
+
// }
|
|
587
|
+
// else if (field.leafValueType === 'Maximum') {
|
|
588
|
+
// initialGroup[field.id] = {'$max': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, ''))};
|
|
589
|
+
// }
|
|
590
|
+
// else if (field.leafValueType === 'First') {
|
|
591
|
+
// initialGroup[field.id] = {'$first': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, ''))};
|
|
592
|
+
// }
|
|
593
|
+
// else if (field.leafValueType === 'Last') {
|
|
594
|
+
// initialGroup[field.id] = {'$last': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, ''))};
|
|
595
|
+
// }
|
|
596
|
+
// else {
|
|
597
|
+
// initialGroup[field.id] = {'$push': '$' + (field.collection_name === rootCollectionName ? field.fieldPath.replace(/\.\$/g, '') : field.fieldPath.replace(/\.\$/g, ''))};
|
|
598
|
+
// }
|
|
599
|
+
// });
|
|
600
|
+
//Totals
|
|
601
|
+
// if (fieldsTotal.length) {
|
|
602
|
+
// fieldsTotal.forEach(total => {
|
|
603
|
+
// selectedFields.filter(a => a.fieldType === 'Number' && !a.fieldPath.includes('$')).forEach(field => {
|
|
604
|
+
// initialGroup[total.id + '_' + field.id] = {['$' + total.type]: '$' + field.fieldPath.replace(/\.\$/g, '')};
|
|
605
|
+
// });
|
|
606
|
+
// });
|
|
607
|
+
// }
|
|
608
|
+
//Arrays
|
|
609
|
+
// selectedFields.filter(a => a.fieldPath.includes('$')).forEach(field => {
|
|
610
|
+
// });
|
|
611
|
+
//Links
|
|
612
|
+
// if (fieldsLink.length) {
|
|
613
|
+
// fieldsLink.filter(a => a.field_first && a.field_second).forEach(link => {
|
|
614
|
+
// queryGroup[link.id] = {$cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')]};
|
|
615
|
+
// });
|
|
616
|
+
// }
|
|
350
617
|
if (rootOptions.sort && reportType === 'Tabular Group') {
|
|
351
618
|
correctSort_1 = {};
|
|
352
619
|
Object.keys(rootOptions.sort).forEach(function (key) {
|
|
@@ -356,9 +623,8 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
356
623
|
$sort: correctSort_1
|
|
357
624
|
});
|
|
358
625
|
}
|
|
359
|
-
queryGroups.push({ $group: queryGroup_1 });
|
|
360
626
|
if (reportType === 'Tabular Group') {
|
|
361
|
-
|
|
627
|
+
_loop_2 = function (i) {
|
|
362
628
|
var _a, _b;
|
|
363
629
|
queryGroups.push({ $sort: (_a = {}, _a['_id.' + groupsRow[i].id] = 1, _a) });
|
|
364
630
|
var tmpQueryGroup = {
|
|
@@ -389,7 +655,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
389
655
|
queryGroups.push({ $group: tmpQueryGroup });
|
|
390
656
|
};
|
|
391
657
|
for (i = groupsRow.length - 1; i > 0; i--) {
|
|
392
|
-
|
|
658
|
+
_loop_2(i);
|
|
393
659
|
}
|
|
394
660
|
queryGroups.push({ $sort: (_a = {}, _a['_id.' + groupsRow[0].id] = 1, _a) });
|
|
395
661
|
}
|
|
@@ -463,117 +729,145 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
463
729
|
$match: queryMatchCondition
|
|
464
730
|
});
|
|
465
731
|
}
|
|
466
|
-
//
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
$unwind: {
|
|
470
|
-
path: path,
|
|
471
|
-
preserveNullAndEmptyArrays: true
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
queryGroupUnwindCollectionPaths.filter(function (a) { return !a.includes('(Lookup)'); }).forEach(function (path) {
|
|
476
|
-
query.push({
|
|
477
|
-
$unwind: {
|
|
478
|
-
path: path,
|
|
479
|
-
preserveNullAndEmptyArrays: false
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
});
|
|
483
|
-
// Look Ups
|
|
484
|
-
queryLookups.forEach(function (lookup) {
|
|
485
|
-
query.push({
|
|
486
|
-
$lookup: lookup
|
|
487
|
-
});
|
|
488
|
-
});
|
|
489
|
-
// Unwind Lookups
|
|
490
|
-
queryUnwindCollectionPaths.filter(function (a) { return a.includes('(Lookup)'); }).forEach(function (path) {
|
|
491
|
-
if (!query.filter(function (a) { return a.$unwind && a.$unwind.path === path; }).length) {
|
|
492
|
-
query.push({
|
|
493
|
-
$unwind: {
|
|
494
|
-
path: path,
|
|
495
|
-
preserveNullAndEmptyArrays: true
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
queryGroupUnwindCollectionPaths.filter(function (a) { return a.includes('(Lookup)'); }).forEach(function (path) {
|
|
501
|
-
if (!query.filter(function (a) { return a.$unwind && a.$unwind.path === path; }).length) {
|
|
502
|
-
query.push({
|
|
503
|
-
$unwind: {
|
|
504
|
-
path: path,
|
|
505
|
-
preserveNullAndEmptyArrays: false
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
// Group Unwinds
|
|
511
|
-
if (groupsRow.length) {
|
|
512
|
-
query = query.concat(queryGroupUnwind.filter(function (a) { return !query.some(function (b) { return b.$unwind && (b.$unwind.path === a.$unwind.path); }); }));
|
|
513
|
-
}
|
|
514
|
-
queryMatchConditionLookup = {
|
|
515
|
-
$and: []
|
|
516
|
-
};
|
|
517
|
-
if (filters.filter(function (a) { return (!a['$or'] && Object.keys(a).some(function (b) { return b.includes('(Lookup)'); })) || (a['$or'] && a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup)'); }); })); }).length) {
|
|
518
|
-
filters.filter(function (a) { return (!a['$or'] && Object.keys(a).some(function (b) { return b.includes('(Lookup)'); })) || (a['$or'] && a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup)'); }); })); }).forEach(function (filter) {
|
|
519
|
-
queryMatchConditionLookup['$and'].push(filter);
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
filterArrays.forEach(function (filter) {
|
|
523
|
-
queryMatchConditionLookup['$and'].push(filter);
|
|
732
|
+
// Group w/ root properties & all arrays needed
|
|
733
|
+
query.push({
|
|
734
|
+
$project: initialProjection
|
|
524
735
|
});
|
|
525
|
-
if (
|
|
736
|
+
if (initialGroup) {
|
|
526
737
|
query.push({
|
|
527
|
-
$
|
|
738
|
+
$group: initialGroup
|
|
528
739
|
});
|
|
529
740
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
});
|
|
535
|
-
if (reportType === 'Tabular Group') {
|
|
536
|
-
tmpProj_1 = common_1.deepCopy(queryGroups[queryGroups.length - 2].$group);
|
|
537
|
-
if (groupsRow.length === 1) {
|
|
538
|
-
tmpProj_1._id.gr_1 = '$_id.gr_1';
|
|
539
|
-
}
|
|
540
|
-
Object.keys(tmpProj_1).filter(function (a) { return a !== '_id'; }).forEach(function (key) {
|
|
541
|
-
tmpProj_1[key] = 1;
|
|
542
|
-
});
|
|
543
|
-
Object.assign(tmpProj_1, tmpProj_1['_id']);
|
|
544
|
-
tmpProj_1['_id'] = 0;
|
|
545
|
-
query.push({
|
|
546
|
-
$project: tmpProj_1
|
|
547
|
-
});
|
|
741
|
+
query.push({
|
|
742
|
+
$unwind: {
|
|
743
|
+
"path": "$rb_arrays_0",
|
|
744
|
+
"preserveNullAndEmptyArrays": true
|
|
548
745
|
}
|
|
549
|
-
}
|
|
550
|
-
|
|
746
|
+
});
|
|
747
|
+
if (secondInitialGroup) {
|
|
551
748
|
query.push({
|
|
552
|
-
$
|
|
749
|
+
$group: secondInitialGroup
|
|
553
750
|
});
|
|
554
751
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if (fieldsLink.length === 1 && fieldsLink[0].field_first && fieldsLink[0].field_second) {
|
|
558
|
-
query.push({ $match: (_b = {}, _b[fieldsLink[0].id] = 0, _b) });
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
tmpAnds_1 = [];
|
|
562
|
-
fieldsLink.filter(function (a) { return a.field_first && a.field_second; }).forEach(function (link) {
|
|
563
|
-
var _a;
|
|
564
|
-
tmpAnds_1.push((_a = {}, _a[link.id] = 0, _a));
|
|
565
|
-
});
|
|
566
|
-
if (tmpAnds_1.length) {
|
|
567
|
-
query.push({ $match: { $and: tmpAnds_1 } });
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
// SORT
|
|
572
|
-
if (rootOptions.sort && reportType !== 'Tabular Group') {
|
|
573
|
-
query.push({
|
|
574
|
-
$sort: rootOptions.sort
|
|
575
|
-
});
|
|
752
|
+
for (i = 0; i < zipLayers.length; i++) {
|
|
753
|
+
query.push(zipLayers[i]);
|
|
576
754
|
}
|
|
755
|
+
// START LOOP
|
|
756
|
+
// Project results and layer rb_arrays (for $sum)
|
|
757
|
+
// Unwind rb_arrays
|
|
758
|
+
// Group that layer's props ($sum) and keep next layer
|
|
759
|
+
// END LOOP
|
|
760
|
+
// Unwind Pre-Lookup Arrays
|
|
761
|
+
// queryUnwindCollectionPaths.filter(a => !a.includes('(Lookup)')).forEach(path => {
|
|
762
|
+
// query.push({
|
|
763
|
+
// $unwind: {
|
|
764
|
+
// path: path,
|
|
765
|
+
// preserveNullAndEmptyArrays: true
|
|
766
|
+
// }
|
|
767
|
+
// });
|
|
768
|
+
// });
|
|
769
|
+
// queryGroupUnwindCollectionPaths.filter(a => !a.includes('(Lookup)')).forEach(path => {
|
|
770
|
+
// query.push({
|
|
771
|
+
// $unwind: {
|
|
772
|
+
// path: path,
|
|
773
|
+
// preserveNullAndEmptyArrays: false
|
|
774
|
+
// }
|
|
775
|
+
// });
|
|
776
|
+
// });
|
|
777
|
+
// // Look Ups
|
|
778
|
+
// queryLookups.forEach(lookup => {
|
|
779
|
+
// query.push({
|
|
780
|
+
// $lookup: lookup
|
|
781
|
+
// });
|
|
782
|
+
// });
|
|
783
|
+
// // Unwind Lookups
|
|
784
|
+
// queryUnwindCollectionPaths.filter(a => a.includes('(Lookup)')).forEach(path => {
|
|
785
|
+
// if (!query.filter(a => a.$unwind && a.$unwind.path === path).length) {
|
|
786
|
+
// query.push({
|
|
787
|
+
// $unwind: {
|
|
788
|
+
// path: path,
|
|
789
|
+
// preserveNullAndEmptyArrays: true
|
|
790
|
+
// }
|
|
791
|
+
// });
|
|
792
|
+
// }
|
|
793
|
+
// });
|
|
794
|
+
// queryGroupUnwindCollectionPaths.filter(a => a.includes('(Lookup)')).forEach(path => {
|
|
795
|
+
// if (!query.filter(a => a.$unwind && a.$unwind.path === path).length) {
|
|
796
|
+
// query.push({
|
|
797
|
+
// $unwind: {
|
|
798
|
+
// path: path,
|
|
799
|
+
// preserveNullAndEmptyArrays: false
|
|
800
|
+
// }
|
|
801
|
+
// });
|
|
802
|
+
// }
|
|
803
|
+
// });
|
|
804
|
+
// // Group Unwinds
|
|
805
|
+
// if (groupsRow.length) {
|
|
806
|
+
// query = query.concat(queryGroupUnwind.filter(a => !query.some(b => b.$unwind && (b.$unwind.path === a.$unwind.path))));
|
|
807
|
+
// }
|
|
808
|
+
// // Array and Lookup Filters
|
|
809
|
+
// let queryMatchConditionLookup = {
|
|
810
|
+
// $and: []
|
|
811
|
+
// };
|
|
812
|
+
// if (filters.filter(a => (!a['$or'] && Object.keys(a).some(b => b.includes('(Lookup)'))) || (a['$or'] && a['$or'].some(b => Object.keys(b).some(c => c.includes('(Lookup)'))))).length) {
|
|
813
|
+
// filters.filter(a => (!a['$or'] && Object.keys(a).some(b => b.includes('(Lookup)'))) || (a['$or'] && a['$or'].some(b => Object.keys(b).some(c => c.includes('(Lookup)'))))).forEach(filter => {
|
|
814
|
+
// queryMatchConditionLookup['$and'].push(filter);
|
|
815
|
+
// });
|
|
816
|
+
// }
|
|
817
|
+
// filterArrays.forEach(filter => {
|
|
818
|
+
// queryMatchConditionLookup['$and'].push(filter);
|
|
819
|
+
// });
|
|
820
|
+
// if (queryMatchConditionLookup.$and.some(a => !a['$or'] || (a['$or'] && a['$or'].length)) || queryMatchConditionLookup.$and.length) {
|
|
821
|
+
// query.push({
|
|
822
|
+
// $match: queryMatchConditionLookup
|
|
823
|
+
// });
|
|
824
|
+
// }
|
|
825
|
+
// // Group Queries and Projection
|
|
826
|
+
// if (groupsRow.length) {
|
|
827
|
+
// queryGroups.forEach(group => {
|
|
828
|
+
// query.push(group);
|
|
829
|
+
// });
|
|
830
|
+
// if (reportType === 'Tabular Group') {
|
|
831
|
+
// let tmpProj = deepCopy(queryGroups[queryGroups.length - 2].$group);
|
|
832
|
+
// if (groupsRow.length === 1) {
|
|
833
|
+
// tmpProj._id.gr_1 = '$_id.gr_1';
|
|
834
|
+
// }
|
|
835
|
+
// Object.keys(tmpProj).filter(a => a !== '_id').forEach(key => {
|
|
836
|
+
// tmpProj[key] = 1;
|
|
837
|
+
// });
|
|
838
|
+
// Object.assign(tmpProj, tmpProj['_id']);
|
|
839
|
+
// tmpProj['_id'] = 0;
|
|
840
|
+
// query.push({
|
|
841
|
+
// $project: tmpProj
|
|
842
|
+
// });
|
|
843
|
+
// }
|
|
844
|
+
// }
|
|
845
|
+
// else {
|
|
846
|
+
// query.push({
|
|
847
|
+
// $project: queryProjection
|
|
848
|
+
// });
|
|
849
|
+
// }
|
|
850
|
+
// // Links
|
|
851
|
+
// if (fieldsLink.length) {
|
|
852
|
+
// if (fieldsLink.length === 1 && fieldsLink[0].field_first && fieldsLink[0].field_second) {
|
|
853
|
+
// query.push({$match: {[fieldsLink[0].id]: 0}});
|
|
854
|
+
// }
|
|
855
|
+
// else {
|
|
856
|
+
// let tmpAnds = [];
|
|
857
|
+
// fieldsLink.filter(a => a.field_first && a.field_second).forEach(link => {
|
|
858
|
+
// tmpAnds.push({[link.id]: 0});
|
|
859
|
+
// });
|
|
860
|
+
// if (tmpAnds.length) {
|
|
861
|
+
// query.push({$match: {$and: tmpAnds}});
|
|
862
|
+
// }
|
|
863
|
+
// }
|
|
864
|
+
// }
|
|
865
|
+
// // SORT
|
|
866
|
+
// if (rootOptions.sort && reportType !== 'Tabular Group') {
|
|
867
|
+
// query.push({
|
|
868
|
+
// $sort: rootOptions.sort
|
|
869
|
+
// });
|
|
870
|
+
// }
|
|
577
871
|
// Dated Grouping
|
|
578
872
|
// if (date_field && date_interval) {
|
|
579
873
|
// if (date_interval === 'Daily') {
|
|
@@ -674,16 +968,19 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
674
968
|
}
|
|
675
969
|
});
|
|
676
970
|
}
|
|
971
|
+
console.log('_____________ query __________');
|
|
972
|
+
console.log(query);
|
|
973
|
+
console.log(JSON.stringify(query, null, 2));
|
|
677
974
|
res = null;
|
|
678
|
-
|
|
975
|
+
_b.label = 1;
|
|
679
976
|
case 1:
|
|
680
|
-
|
|
977
|
+
_b.trys.push([1, 3, , 4]);
|
|
681
978
|
return [4 /*yield*/, modelCollection.aggregate(query).allowDiskUse(true)];
|
|
682
979
|
case 2:
|
|
683
|
-
res =
|
|
980
|
+
res = _b.sent();
|
|
684
981
|
return [3 /*break*/, 4];
|
|
685
982
|
case 3:
|
|
686
|
-
err_1 =
|
|
983
|
+
err_1 = _b.sent();
|
|
687
984
|
console.log(err_1);
|
|
688
985
|
return [3 /*break*/, 4];
|
|
689
986
|
case 4:
|
package/package.json
CHANGED
package/server-app.js
CHANGED
|
@@ -64,6 +64,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
64
64
|
function ResolveIOMainServer(mainServer, serverConfig, clientDir) {
|
|
65
65
|
this._msgQueue = [];
|
|
66
66
|
this._msgQueueRunning = false;
|
|
67
|
+
console.log('Starting ResolveIO Server');
|
|
67
68
|
this._resolveioServer = mainServer;
|
|
68
69
|
this._serverConfig = serverConfig;
|
|
69
70
|
this._clientDir = clientDir;
|
|
@@ -75,8 +76,10 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
75
76
|
this._app.use(bodyParser.urlencoded({ limit: '5mb', extended: true }));
|
|
76
77
|
// Set port
|
|
77
78
|
this._port = process.env.PORT || serverConfig['PORT'];
|
|
79
|
+
console.log('Setup ports');
|
|
78
80
|
// Create http server and websock server
|
|
79
81
|
this.createServer();
|
|
82
|
+
console.log('Create server');
|
|
80
83
|
// Set CORS
|
|
81
84
|
this._app.use(function (req, res, next) {
|
|
82
85
|
// Website you wish to allow to connect
|
|
@@ -93,9 +96,11 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
93
96
|
// Pass to next layer of middleware
|
|
94
97
|
next();
|
|
95
98
|
});
|
|
99
|
+
console.log('Setup cors');
|
|
96
100
|
// Set up http login route
|
|
97
101
|
auth_1.setupAuthRoutes(this, this._app, serverConfig);
|
|
98
102
|
health_1.setupHealthRoutes(this._app, serverConfig);
|
|
103
|
+
console.log('Setup express routes');
|
|
99
104
|
}
|
|
100
105
|
ResolveIOMainServer.prototype.getWS = function (id_ws) {
|
|
101
106
|
var res = null;
|
|
@@ -140,6 +145,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
140
145
|
var infoData, token;
|
|
141
146
|
var _this = this;
|
|
142
147
|
return __generator(this, function (_a) {
|
|
148
|
+
console.log('Verify Client', info, cb);
|
|
143
149
|
infoData = info.req.headers['sec-websocket-protocol'].split(/,/);
|
|
144
150
|
if (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {
|
|
145
151
|
cb(false, 401, 'Unauthorized');
|
|
@@ -208,12 +214,14 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
208
214
|
__setOptions.apply(this, arguments);
|
|
209
215
|
return this;
|
|
210
216
|
};
|
|
217
|
+
console.log('Start Managers');
|
|
211
218
|
// Start Managers
|
|
212
219
|
this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this._wss, this._serverConfig);
|
|
213
220
|
this._methodManager = new method_manager_1.MethodManager(this, this._serverConfig, this._clientDir);
|
|
214
221
|
this._supportManager = new support_manager_1.SupportManager(this, this._serverConfig, this._clientDir);
|
|
215
222
|
this._cronManager = new cron_manager_1.CronManager(this);
|
|
216
223
|
this._queueManager = new queue_method_manager_1.QueueMethodManager(this);
|
|
224
|
+
console.log('End Managers');
|
|
217
225
|
this.listen();
|
|
218
226
|
mongoose.set('useFindAndModify', false);
|
|
219
227
|
// mongoose.set('useCreateIndexes', true);
|
|
@@ -240,6 +248,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
240
248
|
ws['user_readonly'] = req.user_readonly;
|
|
241
249
|
ws['id_socket'] = uuid();
|
|
242
250
|
ws['retryCnt'] = 0;
|
|
251
|
+
console.log('Connection from: ' + req.user);
|
|
243
252
|
// Use for keeping connection alive (ping/pong)
|
|
244
253
|
ws['isAlive'] = true;
|
|
245
254
|
ws.on('pong', function () {
|
|
@@ -257,6 +266,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
257
266
|
var _a, _b, socketData, data, messageDate, messageId, type, subType, pub;
|
|
258
267
|
var _this = this;
|
|
259
268
|
return __generator(this, function (_c) {
|
|
269
|
+
console.log('Message from: ' + ws['user'], message);
|
|
260
270
|
socketData = JSON.parse(message, common_1.dateReviver);
|
|
261
271
|
data = common_2.deepCopy(socketData);
|
|
262
272
|
if (data[0] === 'ping') {
|