@resolveio/server-lib 4.6.9 → 4.6.11-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 +504 -482
- package/methods/report-builder.js +58 -18
- package/package.json +1 -1
|
@@ -144,12 +144,13 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
144
144
|
blackbox: true,
|
|
145
145
|
optional: true
|
|
146
146
|
},
|
|
147
|
-
|
|
147
|
+
filterArrayFields: {
|
|
148
148
|
type: Array,
|
|
149
149
|
optional: true
|
|
150
150
|
},
|
|
151
|
-
'
|
|
152
|
-
type:
|
|
151
|
+
'filterArrayFields.$': {
|
|
152
|
+
type: Object,
|
|
153
|
+
blackbox: true,
|
|
153
154
|
optional: true
|
|
154
155
|
},
|
|
155
156
|
selectedFields: {
|
|
@@ -195,11 +196,11 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
195
196
|
optional: true
|
|
196
197
|
}
|
|
197
198
|
}),
|
|
198
|
-
function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays,
|
|
199
|
+
function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayFields, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval, tabularDisplayType) {
|
|
199
200
|
var _this = this;
|
|
200
201
|
if (filters === void 0) { filters = []; }
|
|
201
202
|
if (filterArrays === void 0) { filterArrays = []; }
|
|
202
|
-
if (
|
|
203
|
+
if (filterArrayFields === void 0) { filterArrayFields = []; }
|
|
203
204
|
if (selectedFields === void 0) { selectedFields = []; }
|
|
204
205
|
if (groupsRow === void 0) { groupsRow = []; }
|
|
205
206
|
if (fieldsTotal === void 0) { fieldsTotal = []; }
|
|
@@ -208,14 +209,11 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
208
209
|
if (date_interval === void 0) { date_interval = ''; }
|
|
209
210
|
if (tabularDisplayType === void 0) { tabularDisplayType = ''; }
|
|
210
211
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
211
|
-
var
|
|
212
|
+
var modelCollection, query, initialQueryMatchCondition, sizes, divFields, queryMatchConditionLookup, queryGroup, queryProjection_1, res, err_1, tmpTotals, tmpRes;
|
|
212
213
|
var _this = this;
|
|
213
214
|
return __generator(this, function (_a) {
|
|
214
215
|
switch (_a.label) {
|
|
215
216
|
case 0:
|
|
216
|
-
uniqueSelectedFieldCollections = selectedFields.map(function (a) { return a.collection_name; }).filter(function (elem, index, self) {
|
|
217
|
-
return index === self.indexOf(elem);
|
|
218
|
-
});
|
|
219
217
|
modelCollection = index_1.ResolveIOServer.getMainDB().model(rootCollectionName);
|
|
220
218
|
query = [];
|
|
221
219
|
initialQueryMatchCondition = {
|
|
@@ -249,6 +247,34 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
249
247
|
// Add count
|
|
250
248
|
query.push({ $addFields: { count: { $sum: 1 } } });
|
|
251
249
|
sizes = [];
|
|
250
|
+
filterArrayFields.forEach(function (filterField) {
|
|
251
|
+
var _a, _b;
|
|
252
|
+
var fieldData = filterField.fieldPath.split('.$');
|
|
253
|
+
var fieldPath = '';
|
|
254
|
+
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
255
|
+
fieldPath += fieldData[i];
|
|
256
|
+
if (fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup)')) {
|
|
257
|
+
if (!query.some(function (a) { return a.$lookup && a.$lookup.as === filterField.lookup_as.replace(/\.\$/g, ''); })) {
|
|
258
|
+
query.push({ $lookup: {
|
|
259
|
+
from: filterField.lookup_collection,
|
|
260
|
+
localField: filterField.lookup_local_key,
|
|
261
|
+
foreignField: filterField.lookup_foreign_key,
|
|
262
|
+
as: filterField.lookup_as.replace(/\.\$/g, '')
|
|
263
|
+
} });
|
|
264
|
+
sizes.push(filterField.lookup_as.replace(/\.\$\./g, '_'));
|
|
265
|
+
query.push({ $addFields: (_a = {}, _a['size_' + filterField.lookup_as.replace(/\.\$\./g, '_')] = { $size: '$' + filterField.lookup_as.replace(/\.\$/g, '') }, _a) });
|
|
266
|
+
query.push({ '$unwind': { path: '$' + filterField.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
if (!query.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath.replace(/\./g, '_')); })) {
|
|
271
|
+
sizes.push(fieldPath.replace(/\./g, '_'));
|
|
272
|
+
query.push({ $addFields: (_b = {}, _b['size_' + fieldPath.replace(/\./g, '_')] = { $size: '$' + fieldPath }, _b) });
|
|
273
|
+
query.push({ '$unwind': { path: '$' + fieldPath, preserveNullAndEmptyArrays: true } });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
252
278
|
// Groups - Lookups / Sizes / Unwinds
|
|
253
279
|
groupsRow.forEach(function (row) {
|
|
254
280
|
var _a, _b;
|
|
@@ -321,7 +347,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
321
347
|
});
|
|
322
348
|
}
|
|
323
349
|
else {
|
|
324
|
-
sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
350
|
+
sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !filterArrayFields.some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
325
351
|
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
326
352
|
});
|
|
327
353
|
}
|
|
@@ -350,7 +376,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
350
376
|
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Sum'; }).forEach(function (field) {
|
|
351
377
|
var multFields = [];
|
|
352
378
|
if (field.fieldPath.includes('.$')) {
|
|
353
|
-
sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
379
|
+
sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').includes(a); }) && !filterArrayFields.some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
354
380
|
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
355
381
|
});
|
|
356
382
|
}
|
|
@@ -362,7 +388,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
362
388
|
});
|
|
363
389
|
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
364
390
|
var multFields = [];
|
|
365
|
-
sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
391
|
+
sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').includes(a); }) && !filterArrayFields.some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
366
392
|
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
367
393
|
});
|
|
368
394
|
if (multFields.length) {
|
|
@@ -382,6 +408,20 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
382
408
|
query.push({ $addFields: (_a = {}, _a[link.id] = { $cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')] }, _a) });
|
|
383
409
|
query.push({ $match: (_b = {}, _b[link.id] = 0, _b) });
|
|
384
410
|
});
|
|
411
|
+
queryMatchConditionLookup = {
|
|
412
|
+
$and: []
|
|
413
|
+
};
|
|
414
|
+
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) {
|
|
415
|
+
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) {
|
|
416
|
+
queryMatchConditionLookup['$and'].push(filter);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
filterArrays.forEach(function (filter) {
|
|
420
|
+
queryMatchConditionLookup['$and'].push(filter);
|
|
421
|
+
});
|
|
422
|
+
if (queryMatchConditionLookup.$and.length) {
|
|
423
|
+
query.push({ $match: queryMatchConditionLookup });
|
|
424
|
+
}
|
|
385
425
|
queryGroup = {
|
|
386
426
|
_id: {}
|
|
387
427
|
};
|
|
@@ -436,6 +476,12 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
436
476
|
else if (field.leafValueType === 'Last') {
|
|
437
477
|
queryGroup[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
438
478
|
}
|
|
479
|
+
else if (field.leafValueType === 'Last') {
|
|
480
|
+
queryGroup[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
481
|
+
}
|
|
482
|
+
else if (field.leafValueType === 'Unique') {
|
|
483
|
+
queryGroup[field.id] = { '$addToSet': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
484
|
+
}
|
|
439
485
|
else {
|
|
440
486
|
queryGroup[field.id] = { '$push': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
441
487
|
}
|
|
@@ -481,12 +527,6 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
481
527
|
queryProjection_1[field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
482
528
|
}
|
|
483
529
|
});
|
|
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
530
|
//Totals
|
|
491
531
|
if (fieldsTotal.length && (reportType === 'Tabular' || reportType === 'Dated')) {
|
|
492
532
|
fieldsTotal.forEach(function (total) {
|