@resolveio/server-lib 12.5.54 → 12.5.55
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/client-server-app.d.ts +1 -0
- package/client-server-app.js +48 -0
- package/client-server-app.js.map +1 -0
- package/collections/app-status.collection.d.ts +3 -0
- package/collections/app-status.collection.js +51 -0
- package/collections/app-status.collection.js.map +1 -0
- package/collections/counter.collection.d.ts +3 -0
- package/collections/counter.collection.js +54 -0
- package/collections/counter.collection.js.map +1 -0
- package/collections/cron-job-history.collection.d.ts +3 -0
- package/collections/cron-job-history.collection.js +82 -0
- package/collections/cron-job-history.collection.js.map +1 -0
- package/collections/cron-job.collection.d.ts +3 -0
- package/collections/cron-job.collection.js +85 -0
- package/collections/cron-job.collection.js.map +1 -0
- package/collections/email-history.collection.d.ts +3 -0
- package/collections/email-history.collection.js +66 -0
- package/collections/email-history.collection.js.map +1 -0
- package/collections/email-verified.collection.d.ts +3 -0
- package/collections/email-verified.collection.js +61 -0
- package/collections/email-verified.collection.js.map +1 -0
- package/collections/file.collection.d.ts +3 -0
- package/collections/file.collection.js +73 -0
- package/collections/file.collection.js.map +1 -0
- package/collections/flag.collection.d.ts +3 -0
- package/collections/flag.collection.js +56 -0
- package/collections/flag.collection.js.map +1 -0
- package/collections/log-method-latency.collection.d.ts +3 -0
- package/collections/log-method-latency.collection.js +64 -0
- package/collections/log-method-latency.collection.js.map +1 -0
- package/collections/log-subscription.collection.d.ts +3 -0
- package/collections/log-subscription.collection.js +68 -0
- package/collections/log-subscription.collection.js.map +1 -0
- package/collections/log-ts.collection.d.ts +3 -0
- package/collections/log-ts.collection.js +78 -0
- package/collections/log-ts.collection.js.map +1 -0
- package/collections/log.collection.d.ts +3 -0
- package/collections/log.collection.js +77 -0
- package/collections/log.collection.js.map +1 -0
- package/collections/logged-in-users.collection.d.ts +3 -0
- package/collections/logged-in-users.collection.js +65 -0
- package/collections/logged-in-users.collection.js.map +1 -0
- package/collections/method-response.collection.d.ts +3 -0
- package/collections/method-response.collection.js +66 -0
- package/collections/method-response.collection.js.map +1 -0
- package/collections/monitor-cpu.collection.d.ts +3 -0
- package/collections/monitor-cpu.collection.js +63 -0
- package/collections/monitor-cpu.collection.js.map +1 -0
- package/collections/monitor-memory.collection.d.ts +3 -0
- package/collections/monitor-memory.collection.js +75 -0
- package/collections/monitor-memory.collection.js.map +1 -0
- package/collections/monitor-mongo.collection.d.ts +3 -0
- package/collections/monitor-mongo.collection.js +69 -0
- package/collections/monitor-mongo.collection.js.map +1 -0
- package/collections/notification.collection.d.ts +3 -0
- package/collections/notification.collection.js +51 -0
- package/collections/notification.collection.js.map +1 -0
- package/collections/report-builder-dashboard-builder.collection.d.ts +3 -0
- package/collections/report-builder-dashboard-builder.collection.js +109 -0
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -0
- package/collections/report-builder-library.collection.d.ts +3 -0
- package/collections/report-builder-library.collection.js +87 -0
- package/collections/report-builder-library.collection.js.map +1 -0
- package/collections/report-builder-report.collection.d.ts +4 -0
- package/collections/report-builder-report.collection.js +149 -0
- package/collections/report-builder-report.collection.js.map +1 -0
- package/collections/user-group.collection.d.ts +4 -0
- package/collections/user-group.collection.js +90 -0
- package/collections/user-group.collection.js.map +1 -0
- package/collections/user-guide.collection.d.ts +3 -0
- package/collections/user-guide.collection.js +57 -0
- package/collections/user-guide.collection.js.map +1 -0
- package/collections/user.collection.d.ts +4 -0
- package/collections/user.collection.js +259 -0
- package/collections/user.collection.js.map +1 -0
- package/cron/cron.d.ts +5 -0
- package/cron/cron.js +162 -0
- package/cron/cron.js.map +1 -0
- package/fixtures/cron-jobs.d.ts +1 -0
- package/fixtures/cron-jobs.js +73 -0
- package/fixtures/cron-jobs.js.map +1 -0
- package/fixtures/init.d.ts +1 -0
- package/fixtures/init.js +59 -0
- package/fixtures/init.js.map +1 -0
- package/http/auth.d.ts +2 -0
- package/http/auth.js +763 -0
- package/http/auth.js.map +1 -0
- package/http/health.d.ts +1 -0
- package/http/health.js +12 -0
- package/http/health.js.map +1 -0
- package/http/home.d.ts +2 -0
- package/http/home.js +66 -0
- package/http/home.js.map +1 -0
- package/index.d.ts +23 -0
- package/index.js +127 -0
- package/index.js.map +1 -0
- package/managers/cron.manager.d.ts +17 -0
- package/managers/cron.manager.js +242 -0
- package/managers/cron.manager.js.map +1 -0
- package/managers/method.manager.d.ts +38 -0
- package/managers/method.manager.js +595 -0
- package/managers/method.manager.js.map +1 -0
- package/managers/mongo.manager.d.ts +178 -0
- package/managers/mongo.manager.js +2221 -0
- package/managers/mongo.manager.js.map +1 -0
- package/managers/monitor.manager.d.ts +59 -0
- package/managers/monitor.manager.js +351 -0
- package/managers/monitor.manager.js.map +1 -0
- package/managers/subscription.manager.d.ts +50 -0
- package/managers/subscription.manager.js +1091 -0
- package/managers/subscription.manager.js.map +1 -0
- package/managers/subscription.performance.d.ts +1 -0
- package/{src/managers/subscription.performance.ts → managers/subscription.performance.js} +33 -68
- package/managers/subscription.performance.js.map +1 -0
- package/methods/accounts.d.ts +2 -0
- package/methods/accounts.js +274 -0
- package/methods/accounts.js.map +1 -0
- package/methods/aws.d.ts +2 -0
- package/methods/aws.js +617 -0
- package/methods/aws.js.map +1 -0
- package/methods/collections.d.ts +2 -0
- package/methods/collections.js +499 -0
- package/methods/collections.js.map +1 -0
- package/methods/counters.d.ts +2 -0
- package/methods/counters.js +122 -0
- package/methods/counters.js.map +1 -0
- package/methods/cron-jobs.d.ts +2 -0
- package/methods/cron-jobs.js +1315 -0
- package/methods/cron-jobs.js.map +1 -0
- package/methods/flags.d.ts +2 -0
- package/methods/flags.js +9 -0
- package/methods/flags.js.map +1 -0
- package/methods/logs.d.ts +2 -0
- package/methods/logs.js +371 -0
- package/methods/logs.js.map +1 -0
- package/methods/monitor.d.ts +2 -0
- package/methods/monitor.js +565 -0
- package/methods/monitor.js.map +1 -0
- package/methods/pdf.d.ts +2 -0
- package/methods/pdf.js +468 -0
- package/methods/pdf.js.map +1 -0
- package/methods/report-builder.d.ts +2 -0
- package/methods/report-builder.js +858 -0
- package/methods/report-builder.js.map +1 -0
- package/methods/support.d.ts +2 -0
- package/methods/support.js +246 -0
- package/methods/support.js.map +1 -0
- package/{src/models/app-status.model.ts → models/app-status.model.d.ts} +2 -3
- package/models/app-status.model.js +4 -0
- package/models/app-status.model.js.map +1 -0
- package/{src/models/billing-logged-in-users.model.ts → models/billing-logged-in-users.model.d.ts} +4 -5
- package/models/billing-logged-in-users.model.js +4 -0
- package/models/billing-logged-in-users.model.js.map +1 -0
- package/models/collection-document.model.d.ts +19 -0
- package/models/collection-document.model.js +4 -0
- package/models/collection-document.model.js.map +1 -0
- package/{src/models/counter.model.ts → models/counter.model.d.ts} +3 -4
- package/models/counter.model.js +4 -0
- package/models/counter.model.js.map +1 -0
- package/models/cron-job-history.model.d.ts +12 -0
- package/models/cron-job-history.model.js +4 -0
- package/models/cron-job-history.model.js.map +1 -0
- package/models/cron-job.model.d.ts +13 -0
- package/models/cron-job.model.js +4 -0
- package/models/cron-job.model.js.map +1 -0
- package/models/dialog.model.d.ts +23 -0
- package/models/dialog.model.js +4 -0
- package/models/dialog.model.js.map +1 -0
- package/{src/models/email-history.model.ts → models/email-history.model.d.ts} +7 -8
- package/models/email-history.model.js +4 -0
- package/models/email-history.model.js.map +1 -0
- package/{src/models/email-verified.model.ts → models/email-verified.model.d.ts} +5 -6
- package/models/email-verified.model.js +4 -0
- package/models/email-verified.model.js.map +1 -0
- package/{src/models/file.model.ts → models/file.model.d.ts} +7 -8
- package/models/file.model.js +4 -0
- package/models/file.model.js.map +1 -0
- package/{src/models/flag.model.ts → models/flag.model.d.ts} +3 -4
- package/models/flag.model.js +4 -0
- package/models/flag.model.js.map +1 -0
- package/{src/models/log-method-latency.model.ts → models/log-method-latency.model.d.ts} +4 -5
- package/models/log-method-latency.model.js +4 -0
- package/models/log-method-latency.model.js.map +1 -0
- package/{src/models/log-subscription.model.ts → models/log-subscription.model.d.ts} +6 -8
- package/models/log-subscription.model.js +4 -0
- package/models/log-subscription.model.js.map +1 -0
- package/{src/models/log.model.ts → models/log.model.d.ts} +10 -12
- package/models/log.model.js +4 -0
- package/models/log.model.js.map +1 -0
- package/{src/models/logged-in-users.model.ts → models/logged-in-users.model.d.ts} +5 -6
- package/models/logged-in-users.model.js +4 -0
- package/models/logged-in-users.model.js.map +1 -0
- package/{src/models/method-response.model.ts → models/method-response.model.d.ts} +6 -7
- package/models/method-response.model.js +4 -0
- package/models/method-response.model.js.map +1 -0
- package/models/method.model.d.ts +9 -0
- package/models/method.model.js +4 -0
- package/models/method.model.js.map +1 -0
- package/{src/models/monitor-cpu.model.ts → models/monitor-cpu.model.d.ts} +7 -9
- package/models/monitor-cpu.model.js +4 -0
- package/models/monitor-cpu.model.js.map +1 -0
- package/models/monitor-memory.model.d.ts +15 -0
- package/models/monitor-memory.model.js +4 -0
- package/models/monitor-memory.model.js.map +1 -0
- package/models/monitor-mongo.model.d.ts +13 -0
- package/models/monitor-mongo.model.js +4 -0
- package/models/monitor-mongo.model.js.map +1 -0
- package/{src/models/notification.model.ts → models/notification.model.d.ts} +2 -3
- package/models/notification.model.js +4 -0
- package/models/notification.model.js.map +1 -0
- package/models/pagination.model.d.ts +10 -0
- package/models/pagination.model.js +24 -0
- package/models/pagination.model.js.map +1 -0
- package/models/permission.model.d.ts +12 -0
- package/models/permission.model.js +4 -0
- package/models/permission.model.js.map +1 -0
- package/models/report-builder-dashboard-builder.model.d.ts +25 -0
- package/models/report-builder-dashboard-builder.model.js +4 -0
- package/models/report-builder-dashboard-builder.model.js.map +1 -0
- package/models/report-builder-library.model.d.ts +17 -0
- package/models/report-builder-library.model.js +4 -0
- package/models/report-builder-library.model.js.map +1 -0
- package/models/report-builder-report.model.d.ts +98 -0
- package/models/report-builder-report.model.js +4 -0
- package/models/report-builder-report.model.js.map +1 -0
- package/models/report-builder.model.d.ts +61 -0
- package/models/report-builder.model.js +4 -0
- package/models/report-builder.model.js.map +1 -0
- package/models/select-data-label.model.d.ts +9 -0
- package/models/select-data-label.model.js +4 -0
- package/models/select-data-label.model.js.map +1 -0
- package/models/server-response.model.d.ts +5 -0
- package/models/server-response.model.js +4 -0
- package/models/server-response.model.js.map +1 -0
- package/models/subscription.model.d.ts +23 -0
- package/models/subscription.model.js +4 -0
- package/models/subscription.model.js.map +1 -0
- package/models/support-ticket.model.d.ts +72 -0
- package/models/support-ticket.model.js +4 -0
- package/models/support-ticket.model.js.map +1 -0
- package/models/user-group.model.d.ts +19 -0
- package/models/user-group.model.js +4 -0
- package/models/user-group.model.js.map +1 -0
- package/{src/models/user-guide.model.ts → models/user-guide.model.d.ts} +4 -5
- package/models/user-guide.model.js +4 -0
- package/models/user-guide.model.js.map +1 -0
- package/models/user.model.d.ts +70 -0
- package/models/user.model.js +4 -0
- package/models/user.model.js.map +1 -0
- package/package.json +1 -1
- package/{src/public_api.ts → public_api.d.ts} +1 -1
- package/public_api.js +75 -0
- package/public_api.js.map +1 -0
- package/publications/app-status.d.ts +2 -0
- package/publications/app-status.js +17 -0
- package/publications/app-status.js.map +1 -0
- package/publications/cron-jobs.d.ts +2 -0
- package/publications/cron-jobs.js +33 -0
- package/publications/cron-jobs.js.map +1 -0
- package/publications/files.d.ts +2 -0
- package/publications/files.js +37 -0
- package/publications/files.js.map +1 -0
- package/publications/flags.d.ts +2 -0
- package/publications/flags.js +23 -0
- package/publications/flags.js.map +1 -0
- package/publications/logs.d.ts +2 -0
- package/publications/logs.js +165 -0
- package/publications/logs.js.map +1 -0
- package/publications/method-responses.d.ts +2 -0
- package/publications/method-responses.js +17 -0
- package/publications/method-responses.js.map +1 -0
- package/publications/notifications.d.ts +2 -0
- package/publications/notifications.js +17 -0
- package/publications/notifications.js.map +1 -0
- package/publications/report-builder-dashboard-builders.d.ts +2 -0
- package/publications/report-builder-dashboard-builders.js +43 -0
- package/publications/report-builder-dashboard-builders.js.map +1 -0
- package/publications/report-builder-libraries.d.ts +2 -0
- package/publications/report-builder-libraries.js +90 -0
- package/publications/report-builder-libraries.js.map +1 -0
- package/publications/report-builder-reports.d.ts +2 -0
- package/publications/report-builder-reports.js +51 -0
- package/publications/report-builder-reports.js.map +1 -0
- package/publications/super-admin.d.ts +2 -0
- package/publications/super-admin.js +17 -0
- package/publications/super-admin.js.map +1 -0
- package/publications/user-groups.d.ts +1 -0
- package/publications/user-groups.js +17 -0
- package/publications/user-groups.js.map +1 -0
- package/publications/user-guides.d.ts +1 -0
- package/publications/user-guides.js +17 -0
- package/publications/user-guides.js.map +1 -0
- package/server-app.d.ts +52 -0
- package/server-app.js +739 -0
- package/server-app.js.map +1 -0
- package/util/common.d.ts +24 -0
- package/util/common.js +511 -0
- package/util/common.js.map +1 -0
- package/util/schema-report-builder.d.ts +6 -0
- package/util/schema-report-builder.js +453 -0
- package/util/schema-report-builder.js.map +1 -0
- package/.nodemon.json +0 -5
- package/.vscode/settings.json +0 -3
- package/README.md +0 -22
- package/compileDTS.pl +0 -64
- package/gulpfile.js +0 -127
- package/mongodbensurers.js +0 -2
- package/mongostop.js +0 -3
- package/settings.development.json +0 -13
- package/src/client-server-app.ts +0 -7
- package/src/collections/app-status.collection.ts +0 -51
- package/src/collections/counter.collection.ts +0 -54
- package/src/collections/cron-job-history.collection.ts +0 -82
- package/src/collections/cron-job.collection.ts +0 -85
- package/src/collections/email-history.collection.ts +0 -66
- package/src/collections/email-verified.collection.ts +0 -61
- package/src/collections/file.collection.ts +0 -73
- package/src/collections/flag.collection.ts +0 -56
- package/src/collections/log-method-latency.collection.ts +0 -64
- package/src/collections/log-subscription.collection.ts +0 -68
- package/src/collections/log-ts.collection.ts +0 -78
- package/src/collections/log.collection.ts +0 -77
- package/src/collections/logged-in-users.collection.ts +0 -65
- package/src/collections/method-response.collection.ts +0 -66
- package/src/collections/monitor-cpu.collection.ts +0 -63
- package/src/collections/monitor-memory.collection.ts +0 -75
- package/src/collections/monitor-mongo.collection.ts +0 -69
- package/src/collections/notification.collection.ts +0 -51
- package/src/collections/report-builder-dashboard-builder.collection.ts +0 -109
- package/src/collections/report-builder-library.collection.ts +0 -89
- package/src/collections/report-builder-report.collection.ts +0 -149
- package/src/collections/user-group.collection.ts +0 -90
- package/src/collections/user-guide.collection.ts +0 -57
- package/src/collections/user.collection.ts +0 -259
- package/src/cron/cron.ts +0 -188
- package/src/fixtures/cron-jobs.ts +0 -25
- package/src/fixtures/init.ts +0 -10
- package/src/http/auth.ts +0 -732
- package/src/http/health.ts +0 -7
- package/src/http/home.ts +0 -71
- package/src/index.ts +0 -71
- package/src/managers/cron.manager.ts +0 -208
- package/src/managers/method.manager.ts +0 -607
- package/src/managers/mongo.manager.ts +0 -2282
- package/src/managers/monitor.manager.ts +0 -323
- package/src/managers/subscription.manager.ts +0 -1196
- package/src/methods/accounts.ts +0 -202
- package/src/methods/aws.ts +0 -507
- package/src/methods/collections.ts +0 -512
- package/src/methods/counters.ts +0 -75
- package/src/methods/cron-jobs.ts +0 -1454
- package/src/methods/flags.ts +0 -7
- package/src/methods/logs.ts +0 -327
- package/src/methods/monitor.ts +0 -548
- package/src/methods/pdf.ts +0 -615
- package/src/methods/report-builder.ts +0 -876
- package/src/methods/support.ts +0 -146
- package/src/models/collection-document.model.ts +0 -22
- package/src/models/cron-job-history.model.ts +0 -13
- package/src/models/cron-job.model.ts +0 -14
- package/src/models/dialog.model.ts +0 -25
- package/src/models/method.model.ts +0 -11
- package/src/models/monitor-memory.model.ts +0 -17
- package/src/models/monitor-mongo.model.ts +0 -15
- package/src/models/pagination.model.ts +0 -30
- package/src/models/permission.model.ts +0 -14
- package/src/models/report-builder-dashboard-builder.model.ts +0 -29
- package/src/models/report-builder-library.model.ts +0 -20
- package/src/models/report-builder-report.model.ts +0 -110
- package/src/models/report-builder.model.ts +0 -68
- package/src/models/select-data-label.model.ts +0 -9
- package/src/models/server-response.model.ts +0 -5
- package/src/models/subscription.model.ts +0 -64
- package/src/models/support-ticket.model.ts +0 -81
- package/src/models/user-group.model.ts +0 -23
- package/src/models/user.model.ts +0 -79
- package/src/publications/app-status.ts +0 -13
- package/src/publications/cron-jobs.ts +0 -30
- package/src/publications/files.ts +0 -34
- package/src/publications/flags.ts +0 -20
- package/src/publications/logs.ts +0 -164
- package/src/publications/method-responses.ts +0 -13
- package/src/publications/notifications.ts +0 -13
- package/src/publications/report-builder-dashboard-builders.ts +0 -39
- package/src/publications/report-builder-libraries.ts +0 -41
- package/src/publications/report-builder-reports.ts +0 -48
- package/src/publications/super-admin.ts +0 -13
- package/src/publications/user-groups.ts +0 -12
- package/src/publications/user-guides.ts +0 -12
- package/src/server-app.ts +0 -769
- package/src/util/common.ts +0 -519
- package/src/util/schema-report-builder.ts +0 -413
- package/tsconfig.json +0 -30
- package/tslint.json +0 -143
- /package/{src/private → private}/email-templates/enrollment.html +0 -0
- /package/{src/private → private}/email-templates/forgot-password.html +0 -0
- /package/{src/private → private}/email-templates/support-ticket-deleted.html +0 -0
- /package/{src/private → private}/email-templates/support-ticket-modified.html +0 -0
- /package/{src/private → private}/email-templates/support-ticket.html +0 -0
- /package/{src/private → private}/images/ResolveIO.png +0 -0
|
@@ -0,0 +1,858 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.loadReportBuilderMethods = void 0;
|
|
40
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
41
|
+
var pagination_model_1 = require("../models/pagination.model");
|
|
42
|
+
var index_1 = require("../index");
|
|
43
|
+
var schema_report_builder_1 = require("../util/schema-report-builder");
|
|
44
|
+
function loadReportBuilderMethods(methodManager) {
|
|
45
|
+
methodManager.methods({
|
|
46
|
+
reportBuilderBuildTree: {
|
|
47
|
+
check: new simpl_schema_1.default({
|
|
48
|
+
collection_root: {
|
|
49
|
+
type: String
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
function: function (collection_root) {
|
|
53
|
+
var _this = this;
|
|
54
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
55
|
+
var lookupSchemaData, lookupSchemaTree, treeItems;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
lookupSchemaData = (0, schema_report_builder_1.getReportLookupSchemas)(collection_root).sort(function (a, b) { return a.collection_name.localeCompare(b.collection_name); });
|
|
58
|
+
lookupSchemaTree = lookupSchemaData.filter(function (a) { return a.is_root === true; })[0].tree;
|
|
59
|
+
treeItems = (0, schema_report_builder_1.buildTree)(collection_root, lookupSchemaTree);
|
|
60
|
+
Object.keys(lookupSchemaTree).filter(function (a) { return a.endsWith('(Lookup)'); }).forEach(function (lookup) {
|
|
61
|
+
var fieldPath = lookup.split('.');
|
|
62
|
+
var field = null;
|
|
63
|
+
fieldPath.forEach(function (path) {
|
|
64
|
+
if (!field) {
|
|
65
|
+
field = treeItems.filter(function (a) { return a.fieldName === path; })[0];
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
field = field.children.filter(function (a) { return a.fieldName === path; })[0];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
field.children = (0, schema_report_builder_1.buildTree)(lookupSchemaTree[lookup].lookup_collection, lookupSchemaData.filter(function (a) { return a.collection_name === lookupSchemaTree[lookup].lookup_collection; })[0].tree, field);
|
|
72
|
+
});
|
|
73
|
+
// console.log('----------- Tree Items -----------', treeItems);
|
|
74
|
+
resolve({ isLeaf: false, children: treeItems });
|
|
75
|
+
return [2 /*return*/];
|
|
76
|
+
});
|
|
77
|
+
}); });
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
reportBuilderGetDistinctValue: {
|
|
81
|
+
check: new simpl_schema_1.default({
|
|
82
|
+
treeLeaf: {
|
|
83
|
+
type: Object,
|
|
84
|
+
blackbox: true
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
function: function (treeLeaf) {
|
|
88
|
+
var _this = this;
|
|
89
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
return __generator(this, function (_c) {
|
|
92
|
+
switch (_c.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
if (!(treeLeaf.fieldType === 'String')) return [3 /*break*/, 5];
|
|
95
|
+
if (!treeLeaf.fieldPath.includes('(Lookup)')) return [3 /*break*/, 2];
|
|
96
|
+
_a = resolve;
|
|
97
|
+
return [4 /*yield*/, (0, schema_report_builder_1.mongoCommand)('distinct', treeLeaf.collection_name, treeLeaf.fieldPath.replace(/^.+\(.+\) \(Lookup\)\.\$\./g, '').replace(/\.\$/g, ''))];
|
|
98
|
+
case 1:
|
|
99
|
+
_a.apply(void 0, [_c.sent()]);
|
|
100
|
+
return [3 /*break*/, 4];
|
|
101
|
+
case 2:
|
|
102
|
+
_b = resolve;
|
|
103
|
+
return [4 /*yield*/, (0, schema_report_builder_1.mongoCommand)('distinct', treeLeaf.collection_name, treeLeaf.fieldPath.replace(/\.\$/g, ''))];
|
|
104
|
+
case 3:
|
|
105
|
+
_b.apply(void 0, [_c.sent()]);
|
|
106
|
+
_c.label = 4;
|
|
107
|
+
case 4: return [3 /*break*/, 6];
|
|
108
|
+
case 5:
|
|
109
|
+
resolve([]);
|
|
110
|
+
_c.label = 6;
|
|
111
|
+
case 6: return [2 /*return*/];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}); });
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
reportBuilderGetResults: {
|
|
118
|
+
check: new simpl_schema_1.default({
|
|
119
|
+
reportType: {
|
|
120
|
+
type: String
|
|
121
|
+
},
|
|
122
|
+
rootCollectionName: {
|
|
123
|
+
type: String
|
|
124
|
+
},
|
|
125
|
+
options: {
|
|
126
|
+
type: pagination_model_1.PaginationOptionsSchema
|
|
127
|
+
},
|
|
128
|
+
filters: {
|
|
129
|
+
type: Array,
|
|
130
|
+
optional: true
|
|
131
|
+
},
|
|
132
|
+
'filters.$': {
|
|
133
|
+
type: Object,
|
|
134
|
+
blackbox: true,
|
|
135
|
+
optional: true
|
|
136
|
+
},
|
|
137
|
+
filterArrays: {
|
|
138
|
+
type: Array,
|
|
139
|
+
optional: true
|
|
140
|
+
},
|
|
141
|
+
'filterArrays.$': {
|
|
142
|
+
type: Object,
|
|
143
|
+
blackbox: true,
|
|
144
|
+
optional: true
|
|
145
|
+
},
|
|
146
|
+
filterArrayFields: {
|
|
147
|
+
type: Array,
|
|
148
|
+
optional: true
|
|
149
|
+
},
|
|
150
|
+
'filterArrayFields.$': {
|
|
151
|
+
type: Object,
|
|
152
|
+
blackbox: true,
|
|
153
|
+
optional: true
|
|
154
|
+
},
|
|
155
|
+
selectedFields: {
|
|
156
|
+
type: Array,
|
|
157
|
+
optional: true
|
|
158
|
+
},
|
|
159
|
+
'selectedFields.$': {
|
|
160
|
+
type: Object,
|
|
161
|
+
optional: true,
|
|
162
|
+
blackbox: true
|
|
163
|
+
},
|
|
164
|
+
customFields: {
|
|
165
|
+
type: Array,
|
|
166
|
+
optional: true
|
|
167
|
+
},
|
|
168
|
+
'customFields.$': {
|
|
169
|
+
type: Object,
|
|
170
|
+
optional: true,
|
|
171
|
+
blackbox: true
|
|
172
|
+
},
|
|
173
|
+
groupsRow: {
|
|
174
|
+
type: Array
|
|
175
|
+
},
|
|
176
|
+
'groupsRow.$': {
|
|
177
|
+
type: Object,
|
|
178
|
+
blackbox: true
|
|
179
|
+
},
|
|
180
|
+
fieldsTotal: {
|
|
181
|
+
type: Array
|
|
182
|
+
},
|
|
183
|
+
'fieldsTotal.$': {
|
|
184
|
+
type: Object,
|
|
185
|
+
blackbox: true
|
|
186
|
+
},
|
|
187
|
+
fieldsLink: {
|
|
188
|
+
type: Array
|
|
189
|
+
},
|
|
190
|
+
'fieldsLink.$': {
|
|
191
|
+
type: Object,
|
|
192
|
+
blackbox: true
|
|
193
|
+
},
|
|
194
|
+
date_field: {
|
|
195
|
+
type: String,
|
|
196
|
+
optional: true
|
|
197
|
+
},
|
|
198
|
+
date_interval: {
|
|
199
|
+
type: String,
|
|
200
|
+
optional: true
|
|
201
|
+
},
|
|
202
|
+
displayType: {
|
|
203
|
+
type: String,
|
|
204
|
+
optional: true
|
|
205
|
+
}
|
|
206
|
+
}),
|
|
207
|
+
function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayFields, selectedFields, customFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval, displayType) {
|
|
208
|
+
var _this = this;
|
|
209
|
+
if (filters === void 0) { filters = []; }
|
|
210
|
+
if (filterArrays === void 0) { filterArrays = []; }
|
|
211
|
+
if (filterArrayFields === void 0) { filterArrayFields = []; }
|
|
212
|
+
if (selectedFields === void 0) { selectedFields = []; }
|
|
213
|
+
if (customFields === void 0) { customFields = []; }
|
|
214
|
+
if (groupsRow === void 0) { groupsRow = []; }
|
|
215
|
+
if (fieldsTotal === void 0) { fieldsTotal = []; }
|
|
216
|
+
if (fieldsLink === void 0) { fieldsLink = []; }
|
|
217
|
+
if (date_field === void 0) { date_field = ''; }
|
|
218
|
+
if (date_interval === void 0) { date_interval = ''; }
|
|
219
|
+
if (displayType === void 0) { displayType = ''; }
|
|
220
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
221
|
+
var modelCollection, query_1, initialQueryMatchCondition_1, sizes_1, divFields_1, queryMatchConditionLookup_1, queryGroup_1, groupedSorts_1, queryProjection_1, _loop_1, i, res_1, err_1, tmpTotals_1, tmpRes;
|
|
222
|
+
return __generator(this, function (_a) {
|
|
223
|
+
switch (_a.label) {
|
|
224
|
+
case 0:
|
|
225
|
+
modelCollection = index_1.ResolveIOServer.getMongoManager().collection(rootCollectionName);
|
|
226
|
+
if (!!modelCollection) return [3 /*break*/, 1];
|
|
227
|
+
reject('Invalid collection');
|
|
228
|
+
return [3 /*break*/, 6];
|
|
229
|
+
case 1:
|
|
230
|
+
query_1 = [];
|
|
231
|
+
initialQueryMatchCondition_1 = {
|
|
232
|
+
$and: []
|
|
233
|
+
};
|
|
234
|
+
// selectedFields.filter(a => a.collection_name === rootCollectionName).forEach(field => {
|
|
235
|
+
// initialQueryMatchCondition['$and'].push({
|
|
236
|
+
// $and: [
|
|
237
|
+
// {[field.fieldPath.replace(/\.\$/g, '')]: {$exists: 1}},
|
|
238
|
+
// // {[field.fieldPath.replace(/\.\$/g, '')]: {$ne: ''}},
|
|
239
|
+
// {[field.fieldPath.replace(/\.\$/g, '')]: {$ne: null}},
|
|
240
|
+
// ]
|
|
241
|
+
// });
|
|
242
|
+
// });
|
|
243
|
+
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
|
+
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
|
+
initialQueryMatchCondition_1['$and'].push(filter);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
// Add filter to query
|
|
249
|
+
// 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
|
+
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
|
+
query_1.push({
|
|
252
|
+
$match: initialQueryMatchCondition_1
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
// Add count
|
|
256
|
+
query_1.push({ $addFields: { count: { $sum: 1 } } });
|
|
257
|
+
sizes_1 = [];
|
|
258
|
+
filterArrayFields.filter(function (a) { return a.fieldPath; }).forEach(function (filterField) {
|
|
259
|
+
var _a, _b;
|
|
260
|
+
var fieldData = filterField.fieldPath.split('.$');
|
|
261
|
+
var fieldPath = '';
|
|
262
|
+
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
263
|
+
fieldPath += fieldData[i];
|
|
264
|
+
if (fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup)')) {
|
|
265
|
+
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === filterField.lookup_as.replace(/\.\$/g, ''); })) {
|
|
266
|
+
query_1.push({ $lookup: {
|
|
267
|
+
from: filterField.lookup_collection,
|
|
268
|
+
localField: filterField.lookup_local_key,
|
|
269
|
+
foreignField: filterField.lookup_foreign_key,
|
|
270
|
+
as: filterField.lookup_as.replace(/\.\$/g, '')
|
|
271
|
+
} });
|
|
272
|
+
sizes_1.push(filterField.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
|
|
273
|
+
query_1.push({ $addFields: (_a = {}, _a['size_' + filterField.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_')] = { $size: { $ifNull: ['$' + filterField.lookup_as.replace(/\.\$/g, '').replace(/\./g, '_'), []] } }, _a) });
|
|
274
|
+
query_1.push({ '$unwind': { path: '$' + filterField.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath.replace(/\./g, '_')); })) {
|
|
279
|
+
sizes_1.push(fieldPath.replace(/\./g, '_'));
|
|
280
|
+
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath, []] } }, _b) });
|
|
281
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath, preserveNullAndEmptyArrays: true } });
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
// Groups - Lookups / Sizes / Unwinds
|
|
287
|
+
groupsRow.forEach(function (row) {
|
|
288
|
+
var _a, _b;
|
|
289
|
+
if (row.field.includes('$')) {
|
|
290
|
+
var fieldData = row.field.split('.$');
|
|
291
|
+
var fieldPath_1 = '';
|
|
292
|
+
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
293
|
+
fieldPath_1 += fieldData[i];
|
|
294
|
+
if (fieldPath_1.split('.$')[fieldPath_1.split('.$').length - 1].includes('(Lookup)')) {
|
|
295
|
+
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === row.treeItem.lookup_as.replace(/\.\$/g, ''); })) {
|
|
296
|
+
query_1.push({ $lookup: {
|
|
297
|
+
from: row.treeItem.lookup_collection,
|
|
298
|
+
localField: row.treeItem.lookup_local_key,
|
|
299
|
+
foreignField: row.treeItem.lookup_foreign_key,
|
|
300
|
+
as: row.treeItem.lookup_as.replace(/\.\$/g, '')
|
|
301
|
+
} });
|
|
302
|
+
sizes_1.push(row.treeItem.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
|
|
303
|
+
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) });
|
|
304
|
+
query_1.push({ '$unwind': { path: '$' + row.treeItem.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_1.replace(/\./g, '_')); })) {
|
|
309
|
+
sizes_1.push(fieldPath_1.replace(/\./g, '_'));
|
|
310
|
+
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath_1.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_1, []] } }, _b) });
|
|
311
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath_1, preserveNullAndEmptyArrays: true } });
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
// Selected Fields - Lookups / Sizes / Unwinds
|
|
318
|
+
selectedFields.forEach(function (field) {
|
|
319
|
+
var _a, _b, _c;
|
|
320
|
+
if (field.fieldPath.includes('$')) {
|
|
321
|
+
var fieldData = field.fieldPath.split('.$');
|
|
322
|
+
var fieldPath_2 = '';
|
|
323
|
+
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
324
|
+
fieldPath_2 += fieldData[i];
|
|
325
|
+
if (fieldPath_2.split('.$')[fieldPath_2.split('.$').length - 1].includes('(Lookup)')) {
|
|
326
|
+
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === field.lookup_as.replace(/\.\$/g, ''); })) {
|
|
327
|
+
query_1.push({ $lookup: {
|
|
328
|
+
from: field.lookup_collection,
|
|
329
|
+
localField: field.lookup_local_key,
|
|
330
|
+
foreignField: field.lookup_foreign_key,
|
|
331
|
+
as: field.lookup_as.replace(/\.\$/g, '')
|
|
332
|
+
} });
|
|
333
|
+
sizes_1.push(field.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
|
|
334
|
+
query_1.push({ $addFields: (_a = {}, _a['size_' + field.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_')] = { $size: { $ifNull: ['$' + field.lookup_as.replace(/\.\$/g, '').replace(/\./g, '_'), []] } }, _a) });
|
|
335
|
+
query_1.push({ '$unwind': { path: '$' + field.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
if (!fieldData[i].includes('(Lookup)')) {
|
|
339
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_2.replace(/\./g, '_')); })) {
|
|
340
|
+
sizes_1.push(fieldPath_2.replace(/\./g, '_'));
|
|
341
|
+
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath_2.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_2, []] } }, _b) });
|
|
342
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath_2, preserveNullAndEmptyArrays: true } });
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_2.replace(/\./g, '_')); })) {
|
|
349
|
+
sizes_1.push(fieldPath_2.replace(/\./g, '_'));
|
|
350
|
+
query_1.push({ $addFields: (_c = {}, _c['size_' + fieldPath_2.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_2, []] } }, _c) });
|
|
351
|
+
}
|
|
352
|
+
if (field.leafValueType !== 'Count' && !query_1.some(function (a) { return a.$unwind && a.$unwind.path === '$' + fieldPath_2; })) {
|
|
353
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath_2, preserveNullAndEmptyArrays: true } });
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
divFields_1 = { $addFields: {} };
|
|
360
|
+
fieldsTotal.filter(function (a) { return a.type === 'sum'; }).forEach(function (total) {
|
|
361
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
362
|
+
var multFields = [];
|
|
363
|
+
if (!field.fieldPath.includes('.$')) {
|
|
364
|
+
sizes_1.forEach(function (size) {
|
|
365
|
+
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
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
|
+
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (multFields.length) {
|
|
374
|
+
if (field.leafValueType === 'Count') {
|
|
375
|
+
divFields_1.$addFields[total.id + '_' + field.id] = {
|
|
376
|
+
$divide: ['$count', { $multiply: multFields }]
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
divFields_1.$addFields[total.id + '_' + field.id] = {
|
|
381
|
+
$divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
if (field.leafValueType === 'Count') {
|
|
387
|
+
divFields_1.$addFields[total.id + '_' + field.id] = '$count';
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
divFields_1.$addFields[total.id + '_' + field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Sum'; }).forEach(function (field) {
|
|
396
|
+
var multFields = [];
|
|
397
|
+
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
|
+
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
399
|
+
});
|
|
400
|
+
if (multFields.length) {
|
|
401
|
+
divFields_1.$addFields[field.fieldPath.replace(/\.\$/g, '')] = {
|
|
402
|
+
$divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
selectedFields.filter(function (a) { return a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
407
|
+
var multFields = [];
|
|
408
|
+
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
|
+
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
410
|
+
});
|
|
411
|
+
if (multFields.length) {
|
|
412
|
+
divFields_1.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = {
|
|
413
|
+
$divide: ['$count', { $multiply: multFields }]
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
if (reportType !== 'Dated' && sizes_1.filter(function (a) { return field.fieldPath.replace(/\.\$\./g, '_').includes(a); }).length) {
|
|
418
|
+
sizes_1.filter(function (a) { return field.fieldPath.replace(/\.\$\./g, '_').includes(a); }).forEach(function (size) {
|
|
419
|
+
divFields_1.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = '$size_' + size;
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
divFields_1.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = '$count';
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
fieldsTotal.filter(function (a) { return a.type === 'avg'; }).forEach(function (total) {
|
|
428
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
429
|
+
divFields_1.$addFields[total.id + '_' + field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
if (Object.keys(divFields_1.$addFields).length > 0) {
|
|
433
|
+
query_1.push(divFields_1);
|
|
434
|
+
}
|
|
435
|
+
fieldsLink.filter(function (a) { return a.field_first && a.field_second; }).forEach(function (link) {
|
|
436
|
+
var _a, _b;
|
|
437
|
+
query_1.push({ $addFields: (_a = {}, _a[link.id] = { $cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')] }, _a) });
|
|
438
|
+
query_1.push({ $match: (_b = {}, _b[link.id] = 0, _b) });
|
|
439
|
+
});
|
|
440
|
+
customFields.forEach(function (cust) {
|
|
441
|
+
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) {
|
|
442
|
+
var _a, _b;
|
|
443
|
+
var custFieldGroup = {};
|
|
444
|
+
if (operation.operation === 'divide') {
|
|
445
|
+
var condCheck_1 = [];
|
|
446
|
+
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
447
|
+
if (field.field) {
|
|
448
|
+
condCheck_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), 0] });
|
|
449
|
+
condCheck_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), null] });
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
condCheck_1.push({ $eq: [field.value, 0] });
|
|
453
|
+
condCheck_1.push({ $eq: [field.value, null] });
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
if (opIndex > 0) {
|
|
457
|
+
condCheck_1.push({ $eq: ['$' + cust.selFieldId, 0] });
|
|
458
|
+
condCheck_1.push({ $eq: ['$' + cust.selFieldId, null] });
|
|
459
|
+
}
|
|
460
|
+
var tmpOperationFields_1 = [];
|
|
461
|
+
if (opIndex > 0) {
|
|
462
|
+
tmpOperationFields_1.push('$' + cust.selFieldId);
|
|
463
|
+
}
|
|
464
|
+
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
465
|
+
if (field.field) {
|
|
466
|
+
tmpOperationFields_1.push('$' + field.field.replace(/\.\$/g, ''));
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
tmpOperationFields_1.push(field.value);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
custFieldGroup[cust.selFieldId] = {
|
|
473
|
+
$cond: { if: { $or: condCheck_1 }, then: 0, else: (_a = {}, _a['$' + operation.operation] = tmpOperationFields_1, _a) }
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
custFieldGroup[cust.selFieldId] = (_b = {},
|
|
478
|
+
_b['$' + operation.operation] = [],
|
|
479
|
+
_b);
|
|
480
|
+
if (opIndex > 0) {
|
|
481
|
+
custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $eq: ['$' + cust.selFieldId, null] }, then: 0, else: '$' + cust.selFieldId } });
|
|
482
|
+
}
|
|
483
|
+
var condOr_1 = [];
|
|
484
|
+
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
485
|
+
if (field.field) {
|
|
486
|
+
condOr_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), null] });
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
condOr_1.push({ $eq: [field.value, null] });
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
493
|
+
if (field.field) {
|
|
494
|
+
custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $or: condOr_1 }, then: 0, else: '$' + field.field.replace(/\.\$/g, '') } });
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $or: condOr_1 }, then: 0, else: field.value } });
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
query_1.push({ $addFields: custFieldGroup });
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
fieldsTotal.forEach(function (total) {
|
|
505
|
+
customFields.forEach(function (field) {
|
|
506
|
+
var _a;
|
|
507
|
+
query_1.push({ $addFields: (_a = {}, _a[total.id + '_' + field.selFieldId] = '$' + field.selFieldId, _a) });
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
queryMatchConditionLookup_1 = {
|
|
511
|
+
$and: []
|
|
512
|
+
};
|
|
513
|
+
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
|
+
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
|
+
queryMatchConditionLookup_1['$and'].push(filter);
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
filterArrays.forEach(function (filter) {
|
|
519
|
+
queryMatchConditionLookup_1['$and'].push(filter);
|
|
520
|
+
});
|
|
521
|
+
if (queryMatchConditionLookup_1.$and.length) {
|
|
522
|
+
query_1.push({ $match: queryMatchConditionLookup_1 });
|
|
523
|
+
}
|
|
524
|
+
queryGroup_1 = {
|
|
525
|
+
_id: {}
|
|
526
|
+
};
|
|
527
|
+
if (groupsRow.length || !displayType || displayType === 'grouped') {
|
|
528
|
+
if (!groupsRow.length) {
|
|
529
|
+
queryGroup_1._id = '$_id';
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
if (rootOptions.sort) {
|
|
533
|
+
groupedSorts_1 = {};
|
|
534
|
+
Object.keys(rootOptions.sort).forEach(function (sortField) {
|
|
535
|
+
var selField = selectedFields.filter(function (a) { return a.id === sortField; })[0];
|
|
536
|
+
if (selField) {
|
|
537
|
+
groupedSorts_1[selField.fieldPath.replace(/\.\$/g, '')] = rootOptions.sort[sortField];
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
if (Object.keys(groupedSorts_1).length > 0) {
|
|
541
|
+
query_1.push({
|
|
542
|
+
$sort: groupedSorts_1
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
groupsRow.forEach(function (row) {
|
|
548
|
+
queryGroup_1._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
549
|
+
if (date_field && date_interval) {
|
|
550
|
+
if (date_interval === 'Seconds') {
|
|
551
|
+
queryGroup_1._id['second'] = { '$second': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
552
|
+
queryGroup_1._id['minute'] = { '$minute': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
553
|
+
queryGroup_1._id['hour'] = { '$hour': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
554
|
+
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
555
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
556
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
557
|
+
}
|
|
558
|
+
else if (date_interval === 'Minutes') {
|
|
559
|
+
queryGroup_1._id['minute'] = { '$minute': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
560
|
+
queryGroup_1._id['hour'] = { '$hour': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
561
|
+
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
562
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
563
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
564
|
+
}
|
|
565
|
+
else if (date_interval === 'Hours') {
|
|
566
|
+
queryGroup_1._id['hour'] = { '$hour': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
567
|
+
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
568
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
569
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
570
|
+
}
|
|
571
|
+
else if (date_interval === 'Daily') {
|
|
572
|
+
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
573
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
574
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
575
|
+
}
|
|
576
|
+
else if (date_interval === 'Weekly') {
|
|
577
|
+
queryGroup_1._id['week'] = { '$isoWeek': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
578
|
+
queryGroup_1._id['year'] = { '$isoWeekYear': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
579
|
+
}
|
|
580
|
+
else if (date_interval === 'Monthly') {
|
|
581
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
582
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
583
|
+
}
|
|
584
|
+
else if (date_interval === 'Quarterly') {
|
|
585
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
586
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
587
|
+
}
|
|
588
|
+
else if (date_interval === 'Yearly') {
|
|
589
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ } };
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
selectedFields.forEach(function (field) {
|
|
594
|
+
if (field.leafValueType === 'Average') {
|
|
595
|
+
queryGroup_1[field.id] = { '$avg': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
596
|
+
}
|
|
597
|
+
else if (field.leafValueType === 'Sum') {
|
|
598
|
+
queryGroup_1[field.id] = { '$sum': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
599
|
+
}
|
|
600
|
+
else if (field.leafValueType === 'Count') {
|
|
601
|
+
queryGroup_1[field.id] = { '$sum': '$count_' + field.fieldPath.replace(/\.\$/g, '') };
|
|
602
|
+
}
|
|
603
|
+
else if (field.leafValueType === 'Minimum') {
|
|
604
|
+
queryGroup_1[field.id] = { '$min': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
605
|
+
}
|
|
606
|
+
else if (field.leafValueType === 'Maximum') {
|
|
607
|
+
queryGroup_1[field.id] = { '$max': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
608
|
+
}
|
|
609
|
+
else if (field.leafValueType === 'First' || (!groupsRow.length && (!field.fieldPath.includes('.$') || field.fieldPath.includes('(Lookup)')))) {
|
|
610
|
+
queryGroup_1[field.id] = { '$first': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
611
|
+
}
|
|
612
|
+
else if (field.leafValueType === 'Last') {
|
|
613
|
+
queryGroup_1[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
614
|
+
}
|
|
615
|
+
else if (field.leafValueType === 'Unique') {
|
|
616
|
+
queryGroup_1[field.id] = { '$addToSet': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
queryGroup_1[field.id] = { '$push': { $ifNull: ['$' + field.fieldPath.replace(/\.\$/g, ''), null] } };
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
customFields.forEach(function (cust) {
|
|
623
|
+
if (cust.leafValueType === 'Average') {
|
|
624
|
+
queryGroup_1[cust.selFieldId] = { '$avg': '$' + cust.selFieldId };
|
|
625
|
+
}
|
|
626
|
+
else if (cust.leafValueType === 'Sum') {
|
|
627
|
+
queryGroup_1[cust.selFieldId] = { '$sum': '$' + cust.selFieldId };
|
|
628
|
+
}
|
|
629
|
+
else if (cust.leafValueType === 'Count') {
|
|
630
|
+
if (reportType === 'Dated') {
|
|
631
|
+
queryGroup_1[cust.selFieldId] = { '$sum': '$count_' + cust.selFieldId };
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
queryGroup_1[cust.selFieldId] = { '$push': '$count_' + cust.selFieldId };
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
else if (cust.leafValueType === 'Minimum') {
|
|
638
|
+
queryGroup_1[cust.selFieldId] = { '$min': '$' + cust.selFieldId };
|
|
639
|
+
}
|
|
640
|
+
else if (cust.leafValueType === 'Maximum') {
|
|
641
|
+
queryGroup_1[cust.selFieldId] = { '$max': '$' + cust.selFieldId };
|
|
642
|
+
}
|
|
643
|
+
else if (cust.leafValueType === 'First') {
|
|
644
|
+
queryGroup_1[cust.selFieldId] = { '$first': '$' + cust.selFieldId };
|
|
645
|
+
}
|
|
646
|
+
else if (cust.leafValueType === 'Last') {
|
|
647
|
+
queryGroup_1[cust.selFieldId] = { '$last': '$' + cust.selFieldId };
|
|
648
|
+
}
|
|
649
|
+
else if (cust.leafValueType === 'Unique') {
|
|
650
|
+
queryGroup_1[cust.selFieldId] = { '$addToSet': '$' + cust.selFieldId };
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
queryGroup_1[cust.selFieldId] = { '$push': { $ifNull: ['$' + cust.selFieldId, null] } };
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
// Totals
|
|
657
|
+
if (fieldsTotal.length) {
|
|
658
|
+
fieldsTotal.forEach(function (total) {
|
|
659
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
660
|
+
queryGroup_1[total.id + '_' + field.id] = { $sum: '$' + total.id + '_' + field.id };
|
|
661
|
+
});
|
|
662
|
+
customFields.forEach(function (field) {
|
|
663
|
+
queryGroup_1[total.id + '_' + field.selFieldId] = { $sum: '$' + total.id + '_' + field.selFieldId };
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
query_1.push({ $group: queryGroup_1 });
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
queryProjection_1 = {
|
|
671
|
+
_id: 1
|
|
672
|
+
};
|
|
673
|
+
selectedFields.forEach(function (field) {
|
|
674
|
+
if (field.leafValueType === 'Average') {
|
|
675
|
+
queryProjection_1[field.id] = { $avg: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
676
|
+
}
|
|
677
|
+
else if (field.leafValueType === 'Sum') {
|
|
678
|
+
queryProjection_1[field.id] = { $sum: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
679
|
+
}
|
|
680
|
+
else if (field.leafValueType === 'Count') {
|
|
681
|
+
queryProjection_1[field.id] = { $sum: 1 };
|
|
682
|
+
}
|
|
683
|
+
else if (field.leafValueType === 'Minimum') {
|
|
684
|
+
queryProjection_1[field.id] = { $min: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
685
|
+
}
|
|
686
|
+
else if (field.leafValueType === 'Maximum') {
|
|
687
|
+
queryProjection_1[field.id] = { $max: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
queryProjection_1[field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
customFields.forEach(function (cust) {
|
|
694
|
+
if (cust === 'Average') {
|
|
695
|
+
queryProjection_1[cust.selFieldId] = { $avg: '$' + cust.selFieldId };
|
|
696
|
+
}
|
|
697
|
+
else if (cust === 'Sum') {
|
|
698
|
+
queryProjection_1[cust.selFieldId] = { $sum: '$' + cust.selFieldId };
|
|
699
|
+
}
|
|
700
|
+
else if (cust === 'Count') {
|
|
701
|
+
queryProjection_1[cust.selFieldId] = { $sum: 1 };
|
|
702
|
+
}
|
|
703
|
+
else if (cust === 'Minimum') {
|
|
704
|
+
queryProjection_1[cust.selFieldId] = { $min: '$' + cust.selFieldId };
|
|
705
|
+
}
|
|
706
|
+
else if (cust === 'Maximum') {
|
|
707
|
+
queryProjection_1[cust.selFieldId] = { $max: '$' + cust.selFieldId };
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
queryProjection_1[cust.selFieldId] = '$' + cust.selFieldId;
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
//Totals
|
|
714
|
+
if (fieldsTotal.length && (reportType === 'List' || reportType === 'Dated')) {
|
|
715
|
+
fieldsTotal.forEach(function (total) {
|
|
716
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
717
|
+
var _a;
|
|
718
|
+
queryProjection_1[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.id, _a);
|
|
719
|
+
});
|
|
720
|
+
customFields.forEach(function (field) {
|
|
721
|
+
var _a;
|
|
722
|
+
queryProjection_1[total.id + '_' + field.selFieldId] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.selFieldId, _a);
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
query_1.push({ $project: queryProjection_1 });
|
|
727
|
+
}
|
|
728
|
+
// SORT
|
|
729
|
+
if (rootOptions.sort) {
|
|
730
|
+
query_1.push({
|
|
731
|
+
$sort: rootOptions.sort
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
if (reportType === 'Group' && groupsRow.length > 1) {
|
|
735
|
+
_loop_1 = function (i) {
|
|
736
|
+
var _b;
|
|
737
|
+
var projQuery = { _id: 1 };
|
|
738
|
+
projQuery[groupsRow[i].id] = {
|
|
739
|
+
_id: (_b = {}, _b[groupsRow[i].id] = '$_id.' + groupsRow[i].id, _b)
|
|
740
|
+
};
|
|
741
|
+
if (i === groupsRow.length - 1) {
|
|
742
|
+
selectedFields.forEach(function (field) {
|
|
743
|
+
projQuery[groupsRow[i].id][field.id] = '$' + field.id;
|
|
744
|
+
});
|
|
745
|
+
customFields.forEach(function (field) {
|
|
746
|
+
projQuery[groupsRow[i].id][field.selFieldId] = '$' + field.selFieldId;
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
projQuery[groupsRow[i].id][groupsRow[i + 1].id] = '$' + groupsRow[i + 1].id;
|
|
751
|
+
}
|
|
752
|
+
fieldsTotal.forEach(function (totField) {
|
|
753
|
+
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
754
|
+
projQuery[totField.id + '_' + selField.id] = 1;
|
|
755
|
+
projQuery[groupsRow[i].id][totField.id + '_' + selField.id] = '$' + totField.id + '_' + selField.id;
|
|
756
|
+
});
|
|
757
|
+
customFields.forEach(function (field) {
|
|
758
|
+
projQuery[groupsRow[i].id][totField.id + '_' + field.selFieldId] = '$' + totField.id + '_' + field.selFieldId;
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
query_1.push({ $project: projQuery });
|
|
762
|
+
var grQuery = {
|
|
763
|
+
_id: {}
|
|
764
|
+
};
|
|
765
|
+
for (var j = 0; j < i; j++) {
|
|
766
|
+
grQuery._id[groupsRow[j].id] = '$_id.' + groupsRow[j].id;
|
|
767
|
+
}
|
|
768
|
+
grQuery[groupsRow[i].id] = {
|
|
769
|
+
$push: '$' + groupsRow[i].id
|
|
770
|
+
};
|
|
771
|
+
fieldsTotal.forEach(function (totField) {
|
|
772
|
+
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
773
|
+
var _a;
|
|
774
|
+
grQuery[totField.id + '_' + selField.id] = (_a = {}, _a['$' + totField.type] = '$' + totField.id + '_' + selField.id, _a);
|
|
775
|
+
});
|
|
776
|
+
customFields.forEach(function (field) {
|
|
777
|
+
var _a;
|
|
778
|
+
grQuery[totField.id + '_' + field.selFieldId] = (_a = {}, _a['$' + totField.type] = '$' + totField.id + '_' + field.selFieldId, _a);
|
|
779
|
+
});
|
|
780
|
+
});
|
|
781
|
+
query_1.push({ $group: grQuery });
|
|
782
|
+
if (rootOptions.sort) {
|
|
783
|
+
var sortKeys_1 = Object.keys(rootOptions.sort);
|
|
784
|
+
var sort_1 = {};
|
|
785
|
+
var groupString_1 = '';
|
|
786
|
+
groupsRow.forEach(function (row, groupIndex) {
|
|
787
|
+
if (groupIndex > 0) {
|
|
788
|
+
groupString_1 += 'gr_' + (groupIndex + 1) + '.';
|
|
789
|
+
}
|
|
790
|
+
if (sortKeys_1.includes('_id.gr_' + (groupIndex + 1))) {
|
|
791
|
+
sort_1[groupString_1 + '_id.gr_' + (groupIndex + 1)] = rootOptions.sort['_id.gr_' + (groupIndex + 1)];
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
sort_1[groupString_1 + '_id.gr_' + (groupIndex + 1)] = 1;
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
sortKeys_1.filter(function (a) { return !a.startsWith('_id.gr_'); }).forEach(function (key) {
|
|
798
|
+
sort_1[groupString_1 + key] = rootOptions.sort[key];
|
|
799
|
+
});
|
|
800
|
+
query_1.push({ $sort: sort_1 });
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
for (i = groupsRow.length - 1; i >= 1; i--) {
|
|
804
|
+
_loop_1(i);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
res_1 = null;
|
|
808
|
+
_a.label = 2;
|
|
809
|
+
case 2:
|
|
810
|
+
_a.trys.push([2, 4, , 5]);
|
|
811
|
+
return [4 /*yield*/, modelCollection.aggregate(query_1, { allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary' }, true)];
|
|
812
|
+
case 3:
|
|
813
|
+
res_1 = _a.sent();
|
|
814
|
+
return [3 /*break*/, 5];
|
|
815
|
+
case 4:
|
|
816
|
+
err_1 = _a.sent();
|
|
817
|
+
console.log(err_1);
|
|
818
|
+
return [3 /*break*/, 5];
|
|
819
|
+
case 5:
|
|
820
|
+
tmpTotals_1 = {};
|
|
821
|
+
if (res_1) {
|
|
822
|
+
fieldsTotal.forEach(function (totField) {
|
|
823
|
+
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
824
|
+
if (totField.type === 'sum') {
|
|
825
|
+
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);
|
|
826
|
+
}
|
|
827
|
+
else if (totField.type === 'avg') {
|
|
828
|
+
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);
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
customFields.forEach(function (custField) {
|
|
832
|
+
if (totField.type === 'sum') {
|
|
833
|
+
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);
|
|
834
|
+
}
|
|
835
|
+
else if (totField.type === 'avg') {
|
|
836
|
+
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);
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
tmpRes = [{
|
|
842
|
+
count: res_1 ? res_1.length : 0,
|
|
843
|
+
results: res_1 ? (rootOptions.limit ? res_1.splice(0, rootOptions.limit) : res_1) : [],
|
|
844
|
+
totals: tmpTotals_1
|
|
845
|
+
}];
|
|
846
|
+
resolve(tmpRes);
|
|
847
|
+
_a.label = 6;
|
|
848
|
+
case 6: return [2 /*return*/];
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
}); });
|
|
852
|
+
},
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
exports.loadReportBuilderMethods = loadReportBuilderMethods;
|
|
857
|
+
|
|
858
|
+
//# sourceMappingURL=report-builder.js.map
|