@resolveio/server-lib 4.5.8 → 4.5.9
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/report-builder.js +55 -45
- package/package.json +1 -1
|
@@ -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,
|
|
199
|
+
var _a, uniqueSelectedFieldCollections, modelCollection, queryMatchCondition, initalLookups, initialProjection, tmpIndex_1, queryGroups, queryGroupUnwind, initialGroup, secondInitialGroup, zipLayers, initialNonSumFilterProj, initialNonSumElemAtProj, initialNonSumValueProj, cnt, _loop_1, group, 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:
|
|
@@ -236,11 +236,11 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
236
236
|
queryMatchCondition['$and'].push(filter);
|
|
237
237
|
// queryMatchConditionLookup['$and'].push(filter);
|
|
238
238
|
});
|
|
239
|
-
|
|
239
|
+
initalLookups = [];
|
|
240
240
|
// Lookup Groups
|
|
241
|
-
groupsRow.filter(function (a) { return a.treeItem.collection_name !== rootCollectionName; }).forEach(function (group) {
|
|
242
|
-
if (!
|
|
243
|
-
|
|
241
|
+
groupsRow.filter(function (a) { return a.treeItem.collection_name !== rootCollectionName && a.treeItem.fieldPath.split('.$').length === 2; }).forEach(function (group) {
|
|
242
|
+
if (!initalLookups.filter(function (a) { return a.as === group.treeItem.lookup_as.replace(/\.\$/g, ''); }).length) {
|
|
243
|
+
initalLookups.push({
|
|
244
244
|
from: group.treeItem.lookup_collection,
|
|
245
245
|
localField: group.treeItem.lookup_local_key,
|
|
246
246
|
foreignField: group.treeItem.lookup_foreign_key,
|
|
@@ -251,8 +251,8 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
251
251
|
// Lookup Selected Fields
|
|
252
252
|
uniqueSelectedFieldCollections.filter(function (a) { return a !== rootCollectionName; }).forEach(function (uniqueCollection) {
|
|
253
253
|
selectedFields.filter(function (a) { return a.collection_name === uniqueCollection; }).forEach(function (field) {
|
|
254
|
-
if (!
|
|
255
|
-
|
|
254
|
+
if (!initalLookups.filter(function (a) { return a.as === field.lookup_as.replace(/\.\$/g, ''); }).length && field.fieldPath.split('.$').length === 2) {
|
|
255
|
+
initalLookups.push({
|
|
256
256
|
from: field.lookup_collection,
|
|
257
257
|
localField: field.lookup_local_key,
|
|
258
258
|
foreignField: field.lookup_foreign_key,
|
|
@@ -261,37 +261,12 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
});
|
|
264
|
-
queryGroupUnwindCollectionPaths = [];
|
|
265
|
-
groupsRow.filter(function (a) { return a.treeItem.fieldPath.includes('$'); }).forEach(function (field) {
|
|
266
|
-
var arrayPartData = field.treeItem.fieldPath.split('.$');
|
|
267
|
-
var path = '$';
|
|
268
|
-
for (var i = 0; i < arrayPartData.length - 1; i++) {
|
|
269
|
-
path += arrayPartData[i];
|
|
270
|
-
if (!queryGroupUnwindCollectionPaths.filter(function (a) { return a === path; })[0]) {
|
|
271
|
-
queryGroupUnwindCollectionPaths.push(path);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
queryUnwindCollectionPaths = [];
|
|
276
|
-
selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field) {
|
|
277
|
-
var arrayPartData = field.fieldPath.split('.$');
|
|
278
|
-
var path = '$';
|
|
279
|
-
for (var i = 0; i < arrayPartData.length - 1; i++) {
|
|
280
|
-
path += arrayPartData[i];
|
|
281
|
-
if (!queryUnwindCollectionPaths.some(function (a) { return a === path; }) && !queryGroupUnwindCollectionPaths.some(function (a) { return a === path; })) {
|
|
282
|
-
queryUnwindCollectionPaths.push(path);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
264
|
initialProjection = { _id: 1, count: { $sum: 1 } };
|
|
287
265
|
// Projection
|
|
288
|
-
groupsRow.
|
|
289
|
-
initialProjection[row.treeItem.fieldPath] = 1;
|
|
290
|
-
});
|
|
291
|
-
selectedFields.filter(function (a) { return !a.fieldPath.includes('$'); }).forEach(function (field) {
|
|
292
|
-
initialProjection[field.fieldPath] = 1;
|
|
266
|
+
groupsRow.forEach(function (row) {
|
|
267
|
+
initialProjection[row.treeItem.fieldPath.split('.$')[0]] = 1;
|
|
293
268
|
});
|
|
294
|
-
selectedFields.
|
|
269
|
+
selectedFields.forEach(function (field) {
|
|
295
270
|
initialProjection[field.fieldPath.split('.$')[0]] = 1;
|
|
296
271
|
});
|
|
297
272
|
if (selectedFields.some(function (a) { return a.fieldPath.includes('$'); }) || groupsRow.some(function (a) { return a.field.includes('$') || a.field.includes('(Lookup)'); })) {
|
|
@@ -330,19 +305,21 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
330
305
|
}
|
|
331
306
|
}
|
|
332
307
|
};
|
|
333
|
-
|
|
308
|
+
tmpIndex_1 = 0;
|
|
309
|
+
groupsRow.filter(function (a) { return a.field.includes('$'); }).forEach(function (field) {
|
|
334
310
|
if (!initialProjection['rb_arrays_0'].$map.input.$zip.inputs.some(function (a) { return a === '$' + field.field.split('.$')[0]; })) {
|
|
335
311
|
initialProjection['rb_arrays_0'].$map.input.$zip.inputs.push('$' + field.field.split('.$')[0]);
|
|
336
|
-
initialProjection['rb_arrays_0'].$map.in[field.field.split('.$')[0]] = {
|
|
337
|
-
$arrayElemAt: ['$$zipped',
|
|
312
|
+
initialProjection['rb_arrays_0'].$map.in[field.field.split('.$')[0].replace(new RegExp(/\./g), '_')] = {
|
|
313
|
+
$arrayElemAt: ['$$zipped', tmpIndex_1++]
|
|
338
314
|
};
|
|
339
315
|
}
|
|
340
316
|
});
|
|
341
|
-
|
|
317
|
+
tmpIndex_1 = 0;
|
|
318
|
+
selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field) {
|
|
342
319
|
if (!initialProjection['rb_arrays_0'].$map.input.$zip.inputs.some(function (a) { return a === '$' + field.fieldPath.split('.$')[0]; })) {
|
|
343
320
|
initialProjection['rb_arrays_0'].$map.input.$zip.inputs.push('$' + field.fieldPath.split('.$')[0]);
|
|
344
|
-
initialProjection['rb_arrays_0'].$map.in[field.fieldPath.split('.$')[0]] = {
|
|
345
|
-
$arrayElemAt: ['$$zipped',
|
|
321
|
+
initialProjection['rb_arrays_0'].$map.in[field.fieldPath.split('.$')[0].replace(new RegExp(/\./g), '_')] = {
|
|
322
|
+
$arrayElemAt: ['$$zipped', tmpIndex_1++]
|
|
346
323
|
};
|
|
347
324
|
}
|
|
348
325
|
});
|
|
@@ -478,7 +455,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
478
455
|
initialNonSumElemAtProj = { $addFields: {} };
|
|
479
456
|
initialNonSumValueProj = { $addFields: {} };
|
|
480
457
|
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
|
|
481
|
-
initialNonSumElemAtProj.$addFields['rb_arrays_0_' + field.id] = '$rb_arrays_0_' + field.id + '.' + field.fieldPath.split('.$')[0];
|
|
458
|
+
initialNonSumElemAtProj.$addFields['rb_arrays_0_' + field.id] = '$rb_arrays_0_' + field.id + '.' + field.fieldPath.split('.$')[0].replace(new RegExp(/\./g), '_');
|
|
482
459
|
});
|
|
483
460
|
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
|
|
484
461
|
if (field.leafValueType === 'Count') {
|
|
@@ -503,6 +480,35 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
503
480
|
}
|
|
504
481
|
cnt = 1;
|
|
505
482
|
_loop_1 = function () {
|
|
483
|
+
// Lookups
|
|
484
|
+
var queryLookups = [];
|
|
485
|
+
// Lookup Groups
|
|
486
|
+
groupsRow.filter(function (a) { return a.treeItem.collection_name !== rootCollectionName && a.treeItem.fieldPath.split('.$').length === cnt + 2; }).forEach(function (group) {
|
|
487
|
+
if (!queryLookups.filter(function (a) { return a.as === group.treeItem.lookup_as.replace(/\.\$/g, ''); }).length) {
|
|
488
|
+
queryLookups.push({
|
|
489
|
+
from: group.treeItem.lookup_collection,
|
|
490
|
+
localField: 'rb_arrays_' + (cnt - 1) + '.' + group.treeItem.lookup_local_key,
|
|
491
|
+
foreignField: group.treeItem.lookup_foreign_key,
|
|
492
|
+
as: 'rb_arrays_' + (cnt - 1) + '.' + group.treeItem.lookup_as.replace(/\.\$/g, '')
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
// Lookup Selected Fields
|
|
497
|
+
uniqueSelectedFieldCollections.filter(function (a) { return a !== rootCollectionName; }).forEach(function (uniqueCollection) {
|
|
498
|
+
selectedFields.filter(function (a) { return a.collection_name === uniqueCollection; }).forEach(function (field) {
|
|
499
|
+
if (!queryLookups.filter(function (a) { return a.as === field.lookup_as.replace(/\.\$/g, ''); }).length && field.fieldPath.split('.$').length === cnt + 2) {
|
|
500
|
+
queryLookups.push({
|
|
501
|
+
from: field.lookup_collection,
|
|
502
|
+
localField: 'rb_arrays_' + (cnt - 1) + '.' + field.lookup_local_key,
|
|
503
|
+
foreignField: field.lookup_foreign_key,
|
|
504
|
+
as: 'rb_arrays_' + (cnt - 1) + '.' + field.lookup_as.replace(/\.\$/g, '')
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
queryLookups.forEach(function (lookup) {
|
|
510
|
+
zipLayers.push({ $lookup: lookup });
|
|
511
|
+
});
|
|
506
512
|
var proj = { $addFields: {} };
|
|
507
513
|
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 2; })) {
|
|
508
514
|
proj.$addFields['rb_arrays_' + cnt] = {
|
|
@@ -517,7 +523,8 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
517
523
|
in: {}
|
|
518
524
|
}
|
|
519
525
|
};
|
|
520
|
-
|
|
526
|
+
var indexCnt_1 = 0;
|
|
527
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
|
|
521
528
|
var fieldPath = field.fieldPath.split('.$')[0];
|
|
522
529
|
for (var i = 1; i < cnt + 1; i++) {
|
|
523
530
|
fieldPath += field.fieldPath.split('.$')[i];
|
|
@@ -525,8 +532,8 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
525
532
|
if (!proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$' + fieldPath; })) {
|
|
526
533
|
if (!proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$rb_arrays_' + (cnt - 1) + '.' + fieldPath; })) {
|
|
527
534
|
proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.push('$rb_arrays_' + (cnt - 1) + '.' + fieldPath);
|
|
528
|
-
proj.$addFields['rb_arrays_' + cnt].$map.in[field.fieldPath.split('.$.')[cnt]] = {
|
|
529
|
-
$arrayElemAt: ['$$zipped',
|
|
535
|
+
proj.$addFields['rb_arrays_' + cnt].$map.in[field.fieldPath.split('.$.')[cnt].replace(new RegExp(/\./g), '_')] = {
|
|
536
|
+
$arrayElemAt: ['$$zipped', indexCnt_1++]
|
|
530
537
|
};
|
|
531
538
|
}
|
|
532
539
|
}
|
|
@@ -850,6 +857,9 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
850
857
|
$match: queryMatchCondition
|
|
851
858
|
});
|
|
852
859
|
}
|
|
860
|
+
initalLookups.forEach(function (lookup) {
|
|
861
|
+
query.push({ $lookup: lookup });
|
|
862
|
+
});
|
|
853
863
|
// Group w/ root properties & all arrays needed
|
|
854
864
|
query.push({
|
|
855
865
|
$project: initialProjection
|