@resolveio/server-lib 9.0.10 → 9.0.12
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 +2 -1
- package/collections/user.collection.js.map +1 -1
- package/managers/mongo.manager.d.ts +1 -1
- package/managers/mongo.manager.js +4 -4
- package/managers/mongo.manager.js.map +1 -1
- package/methods/accounts.js +2 -29
- package/methods/accounts.js.map +1 -1
- package/methods/collections.js +694 -626
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +16 -2
- package/methods/counters.js.map +1 -1
- package/methods/report-builder.js +132 -127
- package/methods/report-builder.js.map +1 -1
- package/models/user.model.d.ts +4 -4
- package/models/user.model.js.map +1 -1
- package/package.json +1 -1
|
@@ -221,14 +221,18 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
221
221
|
if (date_interval === void 0) { date_interval = ''; }
|
|
222
222
|
if (displayType === void 0) { displayType = ''; }
|
|
223
223
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
224
|
-
var modelCollection,
|
|
224
|
+
var modelCollection, query_1, initialQueryMatchCondition_1, sizes_1, divFields_1, queryMatchConditionLookup_1, queryGroup_1, queryProjection_1, _loop_1, i, res_1, err_1, tmpTotals_1, tmpRes;
|
|
225
225
|
var _this = this;
|
|
226
226
|
return __generator(this, function (_a) {
|
|
227
227
|
switch (_a.label) {
|
|
228
228
|
case 0:
|
|
229
229
|
modelCollection = index_1.ResolveIOServer.getMainServer().getMongoServer().collection(rootCollectionName);
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
if (!!modelCollection) return [3 /*break*/, 1];
|
|
231
|
+
reject('Invalid collection');
|
|
232
|
+
return [3 /*break*/, 6];
|
|
233
|
+
case 1:
|
|
234
|
+
query_1 = [];
|
|
235
|
+
initialQueryMatchCondition_1 = {
|
|
232
236
|
$and: []
|
|
233
237
|
};
|
|
234
238
|
// selectedFields.filter(a => a.collection_name === rootCollectionName).forEach(field => {
|
|
@@ -242,19 +246,19 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
242
246
|
// });
|
|
243
247
|
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) {
|
|
244
248
|
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) {
|
|
245
|
-
|
|
249
|
+
initialQueryMatchCondition_1['$and'].push(filter);
|
|
246
250
|
});
|
|
247
251
|
}
|
|
248
252
|
// Add filter to query
|
|
249
253
|
// 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 || selectedFields.filter(a => !a.fieldPath.includes('(Lookup')).length) {
|
|
250
254
|
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) {
|
|
251
|
-
|
|
252
|
-
$match:
|
|
255
|
+
query_1.push({
|
|
256
|
+
$match: initialQueryMatchCondition_1
|
|
253
257
|
});
|
|
254
258
|
}
|
|
255
259
|
// Add count
|
|
256
|
-
|
|
257
|
-
|
|
260
|
+
query_1.push({ $addFields: { count: { $sum: 1 } } });
|
|
261
|
+
sizes_1 = [];
|
|
258
262
|
filterArrayFields.filter(function (a) { return a.fieldPath; }).forEach(function (filterField) {
|
|
259
263
|
var _a, _b;
|
|
260
264
|
var fieldData = filterField.fieldPath.split('.$');
|
|
@@ -262,23 +266,23 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
262
266
|
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
263
267
|
fieldPath += fieldData[i];
|
|
264
268
|
if (fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup)')) {
|
|
265
|
-
if (!
|
|
266
|
-
|
|
269
|
+
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === filterField.lookup_as.replace(/\.\$/g, ''); })) {
|
|
270
|
+
query_1.push({ $lookup: {
|
|
267
271
|
from: filterField.lookup_collection,
|
|
268
272
|
localField: filterField.lookup_local_key,
|
|
269
273
|
foreignField: filterField.lookup_foreign_key,
|
|
270
274
|
as: filterField.lookup_as.replace(/\.\$/g, '')
|
|
271
275
|
} });
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
276
|
+
sizes_1.push(filterField.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
|
|
277
|
+
query_1.push({ $addFields: (_a = {}, _a['size_' + filterField.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_')] = { $size: { $ifNull: ['$' + filterField.lookup_as.replace(/\.\$/g, '').replace(/\./g, '_'), []] } }, _a) });
|
|
278
|
+
query_1.push({ '$unwind': { path: '$' + filterField.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
275
279
|
}
|
|
276
280
|
}
|
|
277
281
|
else {
|
|
278
|
-
if (!
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath.replace(/\./g, '_')); })) {
|
|
283
|
+
sizes_1.push(fieldPath.replace(/\./g, '_'));
|
|
284
|
+
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath, []] } }, _b) });
|
|
285
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath, preserveNullAndEmptyArrays: true } });
|
|
282
286
|
}
|
|
283
287
|
}
|
|
284
288
|
}
|
|
@@ -292,23 +296,23 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
292
296
|
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
293
297
|
fieldPath_1 += fieldData[i];
|
|
294
298
|
if (fieldPath_1.split('.$')[fieldPath_1.split('.$').length - 1].includes('(Lookup)')) {
|
|
295
|
-
if (!
|
|
296
|
-
|
|
299
|
+
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === row.treeItem.lookup_as.replace(/\.\$/g, ''); })) {
|
|
300
|
+
query_1.push({ $lookup: {
|
|
297
301
|
from: row.treeItem.lookup_collection,
|
|
298
302
|
localField: row.treeItem.lookup_local_key,
|
|
299
303
|
foreignField: row.treeItem.lookup_foreign_key,
|
|
300
304
|
as: row.treeItem.lookup_as.replace(/\.\$/g, '')
|
|
301
305
|
} });
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
306
|
+
sizes_1.push(row.treeItem.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
|
|
307
|
+
query_1.push({ $addFields: (_a = {}, _a['size_' + row.treeItem.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_')] = { $size: { $ifNull: ['$' + row.treeItem.lookup_as.replace(/\.\$/g, '').replace(/\./g, '_'), []] } }, _a) });
|
|
308
|
+
query_1.push({ '$unwind': { path: '$' + row.treeItem.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
305
309
|
}
|
|
306
310
|
}
|
|
307
311
|
else {
|
|
308
|
-
if (!
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_1.replace(/\./g, '_')); })) {
|
|
313
|
+
sizes_1.push(fieldPath_1.replace(/\./g, '_'));
|
|
314
|
+
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath_1.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_1, []] } }, _b) });
|
|
315
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath_1, preserveNullAndEmptyArrays: true } });
|
|
312
316
|
}
|
|
313
317
|
}
|
|
314
318
|
}
|
|
@@ -323,119 +327,119 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
323
327
|
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
324
328
|
fieldPath_2 += fieldData[i];
|
|
325
329
|
if (fieldPath_2.split('.$')[fieldPath_2.split('.$').length - 1].includes('(Lookup)')) {
|
|
326
|
-
if (!
|
|
327
|
-
|
|
330
|
+
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === field.lookup_as.replace(/\.\$/g, ''); })) {
|
|
331
|
+
query_1.push({ $lookup: {
|
|
328
332
|
from: field.lookup_collection,
|
|
329
333
|
localField: field.lookup_local_key,
|
|
330
334
|
foreignField: field.lookup_foreign_key,
|
|
331
335
|
as: field.lookup_as.replace(/\.\$/g, '')
|
|
332
336
|
} });
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
337
|
+
sizes_1.push(field.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
|
|
338
|
+
query_1.push({ $addFields: (_a = {}, _a['size_' + field.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_')] = { $size: { $ifNull: ['$' + field.lookup_as.replace(/\.\$/g, '').replace(/\./g, '_'), []] } }, _a) });
|
|
339
|
+
query_1.push({ '$unwind': { path: '$' + field.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
336
340
|
}
|
|
337
341
|
else {
|
|
338
342
|
if (!fieldData[i].includes('(Lookup)')) {
|
|
339
|
-
if (!
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_2.replace(/\./g, '_')); })) {
|
|
344
|
+
sizes_1.push(fieldPath_2.replace(/\./g, '_'));
|
|
345
|
+
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath_2.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_2, []] } }, _b) });
|
|
346
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath_2, preserveNullAndEmptyArrays: true } });
|
|
343
347
|
}
|
|
344
348
|
}
|
|
345
349
|
}
|
|
346
350
|
}
|
|
347
351
|
else {
|
|
348
|
-
if (!
|
|
349
|
-
|
|
350
|
-
|
|
352
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_2.replace(/\./g, '_')); })) {
|
|
353
|
+
sizes_1.push(fieldPath_2.replace(/\./g, '_'));
|
|
354
|
+
query_1.push({ $addFields: (_c = {}, _c['size_' + fieldPath_2.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_2, []] } }, _c) });
|
|
351
355
|
}
|
|
352
|
-
if (field.leafValueType !== 'Count' && !
|
|
353
|
-
|
|
356
|
+
if (field.leafValueType !== 'Count' && !query_1.some(function (a) { return a.$unwind && a.$unwind.path === '$' + fieldPath_2; })) {
|
|
357
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath_2, preserveNullAndEmptyArrays: true } });
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
360
|
}
|
|
357
361
|
}
|
|
358
362
|
});
|
|
359
|
-
|
|
363
|
+
divFields_1 = { $addFields: {} };
|
|
360
364
|
fieldsTotal.filter(function (a) { return a.type === 'sum'; }).forEach(function (total) {
|
|
361
365
|
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
362
366
|
var multFields = [];
|
|
363
367
|
if (!field.fieldPath.includes('.$')) {
|
|
364
|
-
|
|
368
|
+
sizes_1.forEach(function (size) {
|
|
365
369
|
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
366
370
|
});
|
|
367
371
|
}
|
|
368
372
|
else {
|
|
369
|
-
|
|
373
|
+
sizes_1.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) && !filterArrayFields.filter(function (a) { return a.fieldPath; }).some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
370
374
|
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
371
375
|
});
|
|
372
376
|
}
|
|
373
377
|
if (multFields.length) {
|
|
374
378
|
if (field.leafValueType === 'Count') {
|
|
375
|
-
|
|
379
|
+
divFields_1.$addFields[total.id + '_' + field.id] = {
|
|
376
380
|
$divide: ['$count', { $multiply: multFields }]
|
|
377
381
|
};
|
|
378
382
|
}
|
|
379
383
|
else {
|
|
380
|
-
|
|
384
|
+
divFields_1.$addFields[total.id + '_' + field.id] = {
|
|
381
385
|
$divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
|
|
382
386
|
};
|
|
383
387
|
}
|
|
384
388
|
}
|
|
385
389
|
else {
|
|
386
390
|
if (field.leafValueType === 'Count') {
|
|
387
|
-
|
|
391
|
+
divFields_1.$addFields[total.id + '_' + field.id] = '$count';
|
|
388
392
|
}
|
|
389
393
|
else {
|
|
390
|
-
|
|
394
|
+
divFields_1.$addFields[total.id + '_' + field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
391
395
|
}
|
|
392
396
|
}
|
|
393
397
|
});
|
|
394
398
|
});
|
|
395
399
|
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Sum'; }).forEach(function (field) {
|
|
396
400
|
var multFields = [];
|
|
397
|
-
|
|
401
|
+
sizes_1.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !filterArrayFields.filter(function (a) { return a.fieldPath; }).some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
398
402
|
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
399
403
|
});
|
|
400
404
|
if (multFields.length) {
|
|
401
|
-
|
|
405
|
+
divFields_1.$addFields[field.fieldPath.replace(/\.\$/g, '')] = {
|
|
402
406
|
$divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
|
|
403
407
|
};
|
|
404
408
|
}
|
|
405
409
|
});
|
|
406
410
|
selectedFields.filter(function (a) { return a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
407
411
|
var multFields = [];
|
|
408
|
-
|
|
412
|
+
sizes_1.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !filterArrayFields.filter(function (a) { return a.fieldPath; }).some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
409
413
|
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
410
414
|
});
|
|
411
415
|
if (multFields.length) {
|
|
412
|
-
|
|
416
|
+
divFields_1.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = {
|
|
413
417
|
$divide: ['$count', { $multiply: multFields }]
|
|
414
418
|
};
|
|
415
419
|
}
|
|
416
420
|
else {
|
|
417
|
-
if (reportType !== 'Dated' &&
|
|
418
|
-
|
|
419
|
-
|
|
421
|
+
if (reportType !== 'Dated' && sizes_1.filter(function (a) { return field.fieldPath.replace(/\.\$\./g, '_').includes(a); }).length) {
|
|
422
|
+
sizes_1.filter(function (a) { return field.fieldPath.replace(/\.\$\./g, '_').includes(a); }).forEach(function (size) {
|
|
423
|
+
divFields_1.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = '$size_' + size;
|
|
420
424
|
});
|
|
421
425
|
}
|
|
422
426
|
else {
|
|
423
|
-
|
|
427
|
+
divFields_1.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = '$count';
|
|
424
428
|
}
|
|
425
429
|
}
|
|
426
430
|
});
|
|
427
431
|
fieldsTotal.filter(function (a) { return a.type === 'avg'; }).forEach(function (total) {
|
|
428
432
|
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
429
|
-
|
|
433
|
+
divFields_1.$addFields[total.id + '_' + field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
430
434
|
});
|
|
431
435
|
});
|
|
432
|
-
if (Object.keys(
|
|
433
|
-
|
|
436
|
+
if (Object.keys(divFields_1.$addFields).length > 0) {
|
|
437
|
+
query_1.push(divFields_1);
|
|
434
438
|
}
|
|
435
439
|
fieldsLink.filter(function (a) { return a.field_first && a.field_second; }).forEach(function (link) {
|
|
436
440
|
var _a, _b;
|
|
437
|
-
|
|
438
|
-
|
|
441
|
+
query_1.push({ $addFields: (_a = {}, _a[link.id] = { $cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')] }, _a) });
|
|
442
|
+
query_1.push({ $match: (_b = {}, _b[link.id] = 0, _b) });
|
|
439
443
|
});
|
|
440
444
|
customFields.forEach(function (cust) {
|
|
441
445
|
cust.operations.filter(function (a) { return a.operation && !a.fields.some(function (b) { return (b.field === null || b.field === '') && b.value === null; }); }).forEach(function (operation, opIndex) {
|
|
@@ -498,141 +502,141 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
498
502
|
}
|
|
499
503
|
});
|
|
500
504
|
}
|
|
501
|
-
|
|
505
|
+
query_1.push({ $addFields: custFieldGroup });
|
|
502
506
|
});
|
|
503
507
|
});
|
|
504
508
|
fieldsTotal.forEach(function (total) {
|
|
505
509
|
customFields.forEach(function (field) {
|
|
506
510
|
var _a;
|
|
507
|
-
|
|
511
|
+
query_1.push({ $addFields: (_a = {}, _a[total.id + '_' + field.selFieldId] = '$' + field.selFieldId, _a) });
|
|
508
512
|
});
|
|
509
513
|
});
|
|
510
|
-
|
|
514
|
+
queryMatchConditionLookup_1 = {
|
|
511
515
|
$and: []
|
|
512
516
|
};
|
|
513
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) {
|
|
514
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) {
|
|
515
|
-
|
|
519
|
+
queryMatchConditionLookup_1['$and'].push(filter);
|
|
516
520
|
});
|
|
517
521
|
}
|
|
518
522
|
filterArrays.forEach(function (filter) {
|
|
519
|
-
|
|
523
|
+
queryMatchConditionLookup_1['$and'].push(filter);
|
|
520
524
|
});
|
|
521
|
-
if (
|
|
522
|
-
|
|
525
|
+
if (queryMatchConditionLookup_1.$and.length) {
|
|
526
|
+
query_1.push({ $match: queryMatchConditionLookup_1 });
|
|
523
527
|
}
|
|
524
|
-
|
|
528
|
+
queryGroup_1 = {
|
|
525
529
|
_id: {}
|
|
526
530
|
};
|
|
527
531
|
if (groupsRow.length || !displayType || displayType === 'grouped') {
|
|
528
532
|
if (!groupsRow.length) {
|
|
529
|
-
|
|
533
|
+
queryGroup_1._id = '$_id';
|
|
530
534
|
}
|
|
531
535
|
groupsRow.forEach(function (row) {
|
|
532
|
-
|
|
536
|
+
queryGroup_1._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
533
537
|
if (date_field && date_interval) {
|
|
534
538
|
if (date_interval === 'Daily') {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
539
|
+
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
540
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
541
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
538
542
|
}
|
|
539
543
|
else if (date_interval === 'Weekly') {
|
|
540
|
-
|
|
541
|
-
|
|
544
|
+
queryGroup_1._id['week'] = { '$isoWeek': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
545
|
+
queryGroup_1._id['year'] = { '$isoWeekYear': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
542
546
|
}
|
|
543
547
|
else if (date_interval === 'Monthly') {
|
|
544
|
-
|
|
545
|
-
|
|
548
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
549
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
546
550
|
}
|
|
547
551
|
else if (date_interval === 'Quarterly') {
|
|
548
|
-
|
|
549
|
-
|
|
552
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
553
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
550
554
|
}
|
|
551
555
|
else if (date_interval === 'Yearly') {
|
|
552
|
-
|
|
556
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
553
557
|
}
|
|
554
558
|
}
|
|
555
559
|
});
|
|
556
560
|
selectedFields.forEach(function (field) {
|
|
557
561
|
if (field.leafValueType === 'Average') {
|
|
558
|
-
|
|
562
|
+
queryGroup_1[field.id] = { '$avg': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
559
563
|
}
|
|
560
564
|
else if (field.leafValueType === 'Sum') {
|
|
561
|
-
|
|
565
|
+
queryGroup_1[field.id] = { '$sum': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
562
566
|
}
|
|
563
567
|
else if (field.leafValueType === 'Count') {
|
|
564
568
|
if (reportType === 'Dated') {
|
|
565
|
-
|
|
569
|
+
queryGroup_1[field.id] = { '$sum': '$count_' + field.fieldPath.replace(/\.\$/g, '') };
|
|
566
570
|
}
|
|
567
571
|
else {
|
|
568
|
-
|
|
572
|
+
queryGroup_1[field.id] = { '$push': '$count_' + field.fieldPath.replace(/\.\$/g, '') };
|
|
569
573
|
}
|
|
570
574
|
}
|
|
571
575
|
else if (field.leafValueType === 'Minimum') {
|
|
572
|
-
|
|
576
|
+
queryGroup_1[field.id] = { '$min': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
573
577
|
}
|
|
574
578
|
else if (field.leafValueType === 'Maximum') {
|
|
575
|
-
|
|
579
|
+
queryGroup_1[field.id] = { '$max': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
576
580
|
}
|
|
577
581
|
else if (field.leafValueType === 'First' || (!groupsRow.length && (!field.fieldPath.includes('.$') || field.fieldPath.includes('(Lookup)')))) {
|
|
578
|
-
|
|
582
|
+
queryGroup_1[field.id] = { '$first': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
579
583
|
}
|
|
580
584
|
else if (field.leafValueType === 'Last') {
|
|
581
|
-
|
|
585
|
+
queryGroup_1[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
582
586
|
}
|
|
583
587
|
else if (field.leafValueType === 'Unique') {
|
|
584
|
-
|
|
588
|
+
queryGroup_1[field.id] = { '$addToSet': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
585
589
|
}
|
|
586
590
|
else {
|
|
587
|
-
|
|
591
|
+
queryGroup_1[field.id] = { '$push': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
588
592
|
}
|
|
589
593
|
});
|
|
590
594
|
customFields.forEach(function (cust) {
|
|
591
595
|
if (cust.leafValueType === 'Average') {
|
|
592
|
-
|
|
596
|
+
queryGroup_1[cust.selFieldId] = { '$avg': '$' + cust.selFieldId };
|
|
593
597
|
}
|
|
594
598
|
else if (cust.leafValueType === 'Sum') {
|
|
595
|
-
|
|
599
|
+
queryGroup_1[cust.selFieldId] = { '$sum': '$' + cust.selFieldId };
|
|
596
600
|
}
|
|
597
601
|
else if (cust.leafValueType === 'Count') {
|
|
598
602
|
if (reportType === 'Dated') {
|
|
599
|
-
|
|
603
|
+
queryGroup_1[cust.selFieldId] = { '$sum': '$count_' + cust.selFieldId };
|
|
600
604
|
}
|
|
601
605
|
else {
|
|
602
|
-
|
|
606
|
+
queryGroup_1[cust.selFieldId] = { '$push': '$count_' + cust.selFieldId };
|
|
603
607
|
}
|
|
604
608
|
}
|
|
605
609
|
else if (cust.leafValueType === 'Minimum') {
|
|
606
|
-
|
|
610
|
+
queryGroup_1[cust.selFieldId] = { '$min': '$' + cust.selFieldId };
|
|
607
611
|
}
|
|
608
612
|
else if (cust.leafValueType === 'Maximum') {
|
|
609
|
-
|
|
613
|
+
queryGroup_1[cust.selFieldId] = { '$max': '$' + cust.selFieldId };
|
|
610
614
|
}
|
|
611
615
|
else if (cust.leafValueType === 'First') {
|
|
612
|
-
|
|
616
|
+
queryGroup_1[cust.selFieldId] = { '$first': '$' + cust.selFieldId };
|
|
613
617
|
}
|
|
614
618
|
else if (cust.leafValueType === 'Last') {
|
|
615
|
-
|
|
619
|
+
queryGroup_1[cust.selFieldId] = { '$last': '$' + cust.selFieldId };
|
|
616
620
|
}
|
|
617
621
|
else if (cust.leafValueType === 'Unique') {
|
|
618
|
-
|
|
622
|
+
queryGroup_1[cust.selFieldId] = { '$addToSet': '$' + cust.selFieldId };
|
|
619
623
|
}
|
|
620
624
|
else {
|
|
621
|
-
|
|
625
|
+
queryGroup_1[cust.selFieldId] = { '$push': '$' + cust.selFieldId };
|
|
622
626
|
}
|
|
623
627
|
});
|
|
624
628
|
// Totals
|
|
625
629
|
if (fieldsTotal.length) {
|
|
626
630
|
fieldsTotal.forEach(function (total) {
|
|
627
631
|
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
628
|
-
|
|
632
|
+
queryGroup_1[total.id + '_' + field.id] = { $sum: '$' + total.id + '_' + field.id };
|
|
629
633
|
});
|
|
630
634
|
customFields.forEach(function (field) {
|
|
631
|
-
|
|
635
|
+
queryGroup_1[total.id + '_' + field.selFieldId] = { $sum: '$' + total.id + '_' + field.selFieldId };
|
|
632
636
|
});
|
|
633
637
|
});
|
|
634
638
|
}
|
|
635
|
-
|
|
639
|
+
query_1.push({ $group: queryGroup_1 });
|
|
636
640
|
}
|
|
637
641
|
else {
|
|
638
642
|
queryProjection_1 = {
|
|
@@ -691,11 +695,11 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
691
695
|
});
|
|
692
696
|
});
|
|
693
697
|
}
|
|
694
|
-
|
|
698
|
+
query_1.push({ $project: queryProjection_1 });
|
|
695
699
|
}
|
|
696
700
|
// SORT
|
|
697
701
|
if (rootOptions.sort) {
|
|
698
|
-
|
|
702
|
+
query_1.push({
|
|
699
703
|
$sort: rootOptions.sort
|
|
700
704
|
});
|
|
701
705
|
}
|
|
@@ -726,7 +730,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
726
730
|
projQuery[groupsRow[i].id][totField.id + '_' + field.selFieldId] = '$' + totField.id + '_' + field.selFieldId;
|
|
727
731
|
});
|
|
728
732
|
});
|
|
729
|
-
|
|
733
|
+
query_1.push({ $project: projQuery });
|
|
730
734
|
var grQuery = {
|
|
731
735
|
_id: {}
|
|
732
736
|
};
|
|
@@ -746,7 +750,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
746
750
|
grQuery[totField.id + '_' + field.selFieldId] = (_a = {}, _a['$' + totField.type] = '$' + totField.id + '_' + field.selFieldId, _a);
|
|
747
751
|
});
|
|
748
752
|
});
|
|
749
|
-
|
|
753
|
+
query_1.push({ $group: grQuery });
|
|
750
754
|
if (rootOptions.sort) {
|
|
751
755
|
var sortKeys_1 = Object.keys(rootOptions.sort);
|
|
752
756
|
var sort_1 = {};
|
|
@@ -765,54 +769,55 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
765
769
|
sortKeys_1.filter(function (a) { return !a.startsWith('_id.gr_'); }).forEach(function (key) {
|
|
766
770
|
sort_1[groupString_1 + key] = rootOptions.sort[key];
|
|
767
771
|
});
|
|
768
|
-
|
|
772
|
+
query_1.push({ $sort: sort_1 });
|
|
769
773
|
}
|
|
770
774
|
};
|
|
771
775
|
for (i = groupsRow.length - 1; i >= 1; i--) {
|
|
772
776
|
_loop_1(i);
|
|
773
777
|
}
|
|
774
778
|
}
|
|
775
|
-
|
|
776
|
-
_a.label =
|
|
777
|
-
case 1:
|
|
778
|
-
_a.trys.push([1, 3, , 4]);
|
|
779
|
-
return [4 /*yield*/, modelCollection.aggregate(query, { allowDiskUse: true })];
|
|
779
|
+
res_1 = null;
|
|
780
|
+
_a.label = 2;
|
|
780
781
|
case 2:
|
|
781
|
-
|
|
782
|
-
return [
|
|
782
|
+
_a.trys.push([2, 4, , 5]);
|
|
783
|
+
return [4 /*yield*/, modelCollection.aggregate(query_1, { allowDiskUse: true })];
|
|
783
784
|
case 3:
|
|
785
|
+
res_1 = _a.sent();
|
|
786
|
+
return [3 /*break*/, 5];
|
|
787
|
+
case 4:
|
|
784
788
|
err_1 = _a.sent();
|
|
785
789
|
console.log(err_1);
|
|
786
|
-
return [3 /*break*/,
|
|
787
|
-
case
|
|
788
|
-
|
|
789
|
-
if (
|
|
790
|
+
return [3 /*break*/, 5];
|
|
791
|
+
case 5:
|
|
792
|
+
tmpTotals_1 = {};
|
|
793
|
+
if (res_1) {
|
|
790
794
|
fieldsTotal.forEach(function (totField) {
|
|
791
795
|
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
792
796
|
if (totField.type === 'sum') {
|
|
793
|
-
|
|
797
|
+
tmpTotals_1[totField.id + '_' + selField.id] = res_1.map(function (a) { return a[totField.id + '_' + selField.id] || 0; }).reduce(function (a, b) { return a + b; }, 0);
|
|
794
798
|
}
|
|
795
799
|
else if (totField.type === 'avg') {
|
|
796
|
-
|
|
800
|
+
tmpTotals_1[totField.id + '_' + selField.id] = Math.round(res_1.map(function (a) { return a[totField.id + '_' + selField.id] || 0; }).reduce(function (a, b) { return a + b; }, 0) / res_1.length);
|
|
797
801
|
}
|
|
798
802
|
});
|
|
799
803
|
customFields.forEach(function (custField) {
|
|
800
804
|
if (totField.type === 'sum') {
|
|
801
|
-
|
|
805
|
+
tmpTotals_1[totField.id + '_' + custField.selFieldId] = res_1.map(function (a) { return a[totField.id + '_' + custField.selFieldId] || 0; }).reduce(function (a, b) { return a + b; }, 0);
|
|
802
806
|
}
|
|
803
807
|
else if (totField.type === 'avg') {
|
|
804
|
-
|
|
808
|
+
tmpTotals_1[totField.id + '_' + custField.selFieldId] = Math.round(res_1.map(function (a) { return a[totField.id + '_' + custField.selFieldId] || 0; }).reduce(function (a, b) { return a + b; }, 0) / res_1.length);
|
|
805
809
|
}
|
|
806
810
|
});
|
|
807
811
|
});
|
|
808
812
|
}
|
|
809
813
|
tmpRes = [{
|
|
810
|
-
count:
|
|
811
|
-
results:
|
|
812
|
-
totals:
|
|
814
|
+
count: res_1 ? res_1.length : 0,
|
|
815
|
+
results: res_1 ? (rootOptions.limit ? res_1.splice(0, rootOptions.limit) : res_1) : [],
|
|
816
|
+
totals: tmpTotals_1
|
|
813
817
|
}];
|
|
814
818
|
resolve(tmpRes);
|
|
815
|
-
|
|
819
|
+
_a.label = 6;
|
|
820
|
+
case 6: return [2 /*return*/];
|
|
816
821
|
}
|
|
817
822
|
});
|
|
818
823
|
}); });
|