@resolveio/server-lib 20.0.26 → 20.0.28
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.js +1 -47
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +1 -50
- package/collections/app-status.collection.js.map +1 -1
- package/collections/counter.collection.js +1 -53
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +1 -88
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +1 -84
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +1 -65
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +1 -60
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +1 -72
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +1 -55
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +1 -63
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +1 -67
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log-ts.collection.js +1 -77
- package/collections/log-ts.collection.js.map +1 -1
- package/collections/log.collection.js +1 -76
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +1 -64
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-response.collection.js +1 -65
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +1 -62
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +1 -74
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +1 -68
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +1 -55
- package/collections/notification.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +1 -108
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +1 -86
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +1 -148
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +1 -93
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +1 -56
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +1 -265
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +1 -101
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +1 -87
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +1 -58
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +1 -763
- package/http/auth.js.map +1 -1
- package/http/health.js +1 -11
- package/http/health.js.map +1 -1
- package/http/home.js +1 -65
- package/http/home.js.map +1 -1
- package/index.js +1 -126
- package/index.js.map +1 -1
- package/managers/cron.manager.js +1 -322
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +1 -593
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +1 -2259
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +1 -350
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +1 -1110
- package/managers/subscription.manager.js.map +1 -1
- package/managers/subscription.performance.js +1 -102
- package/managers/subscription.performance.js.map +1 -1
- package/methods/accounts.js +1 -291
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +1 -616
- package/methods/aws.js.map +1 -1
- package/methods/collections.js +1 -499
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +1 -121
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +1 -1337
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +1 -8
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +1 -370
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +1 -564
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +1 -731
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +1 -859
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +1 -245
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +1 -3
- package/models/app-status.model.js.map +1 -1
- package/models/billing-logged-in-users.model.js +1 -3
- package/models/billing-logged-in-users.model.js.map +1 -1
- package/models/collection-document.model.js +1 -3
- package/models/collection-document.model.js.map +1 -1
- package/models/counter.model.js +1 -3
- package/models/counter.model.js.map +1 -1
- package/models/cron-job-history.model.js +1 -3
- package/models/cron-job-history.model.js.map +1 -1
- package/models/cron-job.model.js +1 -3
- package/models/cron-job.model.js.map +1 -1
- package/models/dialog.model.js +1 -3
- package/models/dialog.model.js.map +1 -1
- package/models/email-history.model.js +1 -3
- package/models/email-history.model.js.map +1 -1
- package/models/email-verified.model.js +1 -3
- package/models/email-verified.model.js.map +1 -1
- package/models/file.model.js +1 -3
- package/models/file.model.js.map +1 -1
- package/models/flag.model.js +1 -3
- package/models/flag.model.js.map +1 -1
- package/models/log-method-latency.model.js +1 -3
- package/models/log-method-latency.model.js.map +1 -1
- package/models/log-subscription.model.js +1 -3
- package/models/log-subscription.model.js.map +1 -1
- package/models/log.model.js +1 -3
- package/models/log.model.js.map +1 -1
- package/models/logged-in-users.model.js +1 -3
- package/models/logged-in-users.model.js.map +1 -1
- package/models/method-response.model.js +1 -3
- package/models/method-response.model.js.map +1 -1
- package/models/method.model.js +1 -3
- package/models/method.model.js.map +1 -1
- package/models/monitor-cpu.model.js +1 -3
- package/models/monitor-cpu.model.js.map +1 -1
- package/models/monitor-memory.model.js +1 -3
- package/models/monitor-memory.model.js.map +1 -1
- package/models/monitor-mongo.model.js +1 -3
- package/models/monitor-mongo.model.js.map +1 -1
- package/models/notification.model.js +1 -3
- package/models/notification.model.js.map +1 -1
- package/models/pagination.model.js +1 -23
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +1 -3
- package/models/permission.model.js.map +1 -1
- package/models/report-builder-dashboard-builder.model.js +1 -3
- package/models/report-builder-dashboard-builder.model.js.map +1 -1
- package/models/report-builder-library.model.js +1 -3
- package/models/report-builder-library.model.js.map +1 -1
- package/models/report-builder-report.model.js +1 -3
- package/models/report-builder-report.model.js.map +1 -1
- package/models/report-builder.model.js +1 -3
- package/models/report-builder.model.js.map +1 -1
- package/models/select-data-label.model.js +1 -3
- package/models/select-data-label.model.js.map +1 -1
- package/models/server-response.model.js +1 -3
- package/models/server-response.model.js.map +1 -1
- package/models/subscription.model.js +1 -3
- package/models/subscription.model.js.map +1 -1
- package/models/support-ticket.model.js +1 -3
- package/models/support-ticket.model.js.map +1 -1
- package/models/user-group.model.js +1 -3
- package/models/user-group.model.js.map +1 -1
- package/models/user-guide.model.js +1 -3
- package/models/user-guide.model.js.map +1 -1
- package/models/user.model.js +1 -3
- package/models/user.model.js.map +1 -1
- package/package.json +6 -4
- package/public_api.js +1 -74
- package/public_api.js.map +1 -1
- package/publications/app-status.js +1 -16
- package/publications/app-status.js.map +1 -1
- package/publications/cron-jobs.js +1 -32
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +1 -36
- package/publications/files.js.map +1 -1
- package/publications/flags.js +1 -22
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +1 -164
- package/publications/logs.js.map +1 -1
- package/publications/method-responses.js +1 -16
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +1 -16
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +1 -42
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +1 -89
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +1 -50
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +1 -16
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +1 -16
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +1 -16
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +1 -770
- package/server-app.js.map +1 -1
- package/util/common.js +1 -546
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +1 -452
- package/util/schema-report-builder.js.map +1 -1
|
@@ -1,860 +1,2 @@
|
|
|
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_CLIENT || 'America/Chicago' } };
|
|
552
|
-
queryGroup_1._id['minute'] = { '$minute': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
553
|
-
queryGroup_1._id['hour'] = { '$hour': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
554
|
-
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
555
|
-
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
556
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
557
|
-
}
|
|
558
|
-
else if (date_interval === 'Minutes') {
|
|
559
|
-
queryGroup_1._id['minute'] = { '$minute': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
560
|
-
queryGroup_1._id['hour'] = { '$hour': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
561
|
-
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
562
|
-
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
563
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
564
|
-
}
|
|
565
|
-
else if (date_interval === 'Hours') {
|
|
566
|
-
queryGroup_1._id['hour'] = { '$hour': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
567
|
-
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
568
|
-
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
569
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
570
|
-
}
|
|
571
|
-
else if (date_interval === 'Daily') {
|
|
572
|
-
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
573
|
-
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
574
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
575
|
-
}
|
|
576
|
-
else if (date_interval === 'Weekly') {
|
|
577
|
-
queryGroup_1._id['week'] = { '$isoWeek': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
578
|
-
queryGroup_1._id['year'] = { '$isoWeekYear': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
579
|
-
}
|
|
580
|
-
else if (date_interval === 'Monthly') {
|
|
581
|
-
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
582
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
583
|
-
}
|
|
584
|
-
else if (date_interval === 'Quarterly') {
|
|
585
|
-
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
586
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
587
|
-
}
|
|
588
|
-
else if (date_interval === 'Yearly') {
|
|
589
|
-
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': process.env.TZ_CLIENT || 'America/Chicago' } };
|
|
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') {
|
|
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
|
-
var _a;
|
|
661
|
-
queryGroup_1[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.id, _a);
|
|
662
|
-
});
|
|
663
|
-
customFields.forEach(function (field) {
|
|
664
|
-
var _a;
|
|
665
|
-
queryGroup_1[total.id + '_' + field.selFieldId] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.selFieldId, _a);
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
query_1.push({ $group: queryGroup_1 });
|
|
670
|
-
}
|
|
671
|
-
else {
|
|
672
|
-
queryProjection_1 = {
|
|
673
|
-
_id: 1
|
|
674
|
-
};
|
|
675
|
-
selectedFields.forEach(function (field) {
|
|
676
|
-
if (field.leafValueType === 'Average') {
|
|
677
|
-
queryProjection_1[field.id] = { $avg: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
678
|
-
}
|
|
679
|
-
else if (field.leafValueType === 'Sum') {
|
|
680
|
-
queryProjection_1[field.id] = { $sum: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
681
|
-
}
|
|
682
|
-
else if (field.leafValueType === 'Count') {
|
|
683
|
-
queryProjection_1[field.id] = { $sum: 1 };
|
|
684
|
-
}
|
|
685
|
-
else if (field.leafValueType === 'Minimum') {
|
|
686
|
-
queryProjection_1[field.id] = { $min: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
687
|
-
}
|
|
688
|
-
else if (field.leafValueType === 'Maximum') {
|
|
689
|
-
queryProjection_1[field.id] = { $max: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
690
|
-
}
|
|
691
|
-
else {
|
|
692
|
-
queryProjection_1[field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
693
|
-
}
|
|
694
|
-
});
|
|
695
|
-
customFields.forEach(function (cust) {
|
|
696
|
-
if (cust === 'Average') {
|
|
697
|
-
queryProjection_1[cust.selFieldId] = { $avg: '$' + cust.selFieldId };
|
|
698
|
-
}
|
|
699
|
-
else if (cust === 'Sum') {
|
|
700
|
-
queryProjection_1[cust.selFieldId] = { $sum: '$' + cust.selFieldId };
|
|
701
|
-
}
|
|
702
|
-
else if (cust === 'Count') {
|
|
703
|
-
queryProjection_1[cust.selFieldId] = { $sum: 1 };
|
|
704
|
-
}
|
|
705
|
-
else if (cust === 'Minimum') {
|
|
706
|
-
queryProjection_1[cust.selFieldId] = { $min: '$' + cust.selFieldId };
|
|
707
|
-
}
|
|
708
|
-
else if (cust === 'Maximum') {
|
|
709
|
-
queryProjection_1[cust.selFieldId] = { $max: '$' + cust.selFieldId };
|
|
710
|
-
}
|
|
711
|
-
else {
|
|
712
|
-
queryProjection_1[cust.selFieldId] = '$' + cust.selFieldId;
|
|
713
|
-
}
|
|
714
|
-
});
|
|
715
|
-
//Totals
|
|
716
|
-
if (fieldsTotal.length && (reportType === 'List' || reportType === 'Dated')) {
|
|
717
|
-
fieldsTotal.forEach(function (total) {
|
|
718
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
719
|
-
var _a;
|
|
720
|
-
queryProjection_1[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.id, _a);
|
|
721
|
-
});
|
|
722
|
-
customFields.forEach(function (field) {
|
|
723
|
-
var _a;
|
|
724
|
-
queryProjection_1[total.id + '_' + field.selFieldId] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.selFieldId, _a);
|
|
725
|
-
});
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
query_1.push({ $project: queryProjection_1 });
|
|
729
|
-
}
|
|
730
|
-
// SORT
|
|
731
|
-
if (rootOptions.sort) {
|
|
732
|
-
query_1.push({
|
|
733
|
-
$sort: rootOptions.sort
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
if (reportType === 'Group' && groupsRow.length > 1) {
|
|
737
|
-
_loop_1 = function (i) {
|
|
738
|
-
var _b;
|
|
739
|
-
var projQuery = { _id: 1 };
|
|
740
|
-
projQuery[groupsRow[i].id] = {
|
|
741
|
-
_id: (_b = {}, _b[groupsRow[i].id] = '$_id.' + groupsRow[i].id, _b)
|
|
742
|
-
};
|
|
743
|
-
if (i === groupsRow.length - 1) {
|
|
744
|
-
selectedFields.forEach(function (field) {
|
|
745
|
-
projQuery[groupsRow[i].id][field.id] = '$' + field.id;
|
|
746
|
-
});
|
|
747
|
-
customFields.forEach(function (field) {
|
|
748
|
-
projQuery[groupsRow[i].id][field.selFieldId] = '$' + field.selFieldId;
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
else {
|
|
752
|
-
projQuery[groupsRow[i].id][groupsRow[i + 1].id] = '$' + groupsRow[i + 1].id;
|
|
753
|
-
}
|
|
754
|
-
fieldsTotal.forEach(function (totField) {
|
|
755
|
-
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
756
|
-
projQuery[totField.id + '_' + selField.id] = 1;
|
|
757
|
-
projQuery[groupsRow[i].id][totField.id + '_' + selField.id] = '$' + totField.id + '_' + selField.id;
|
|
758
|
-
});
|
|
759
|
-
customFields.forEach(function (field) {
|
|
760
|
-
projQuery[groupsRow[i].id][totField.id + '_' + field.selFieldId] = '$' + totField.id + '_' + field.selFieldId;
|
|
761
|
-
});
|
|
762
|
-
});
|
|
763
|
-
query_1.push({ $project: projQuery });
|
|
764
|
-
var grQuery = {
|
|
765
|
-
_id: {}
|
|
766
|
-
};
|
|
767
|
-
for (var j = 0; j < i; j++) {
|
|
768
|
-
grQuery._id[groupsRow[j].id] = '$_id.' + groupsRow[j].id;
|
|
769
|
-
}
|
|
770
|
-
grQuery[groupsRow[i].id] = {
|
|
771
|
-
$push: '$' + groupsRow[i].id
|
|
772
|
-
};
|
|
773
|
-
fieldsTotal.forEach(function (totField) {
|
|
774
|
-
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
775
|
-
var _a;
|
|
776
|
-
grQuery[totField.id + '_' + selField.id] = (_a = {}, _a['$' + totField.type] = '$' + totField.id + '_' + selField.id, _a);
|
|
777
|
-
});
|
|
778
|
-
customFields.forEach(function (field) {
|
|
779
|
-
var _a;
|
|
780
|
-
grQuery[totField.id + '_' + field.selFieldId] = (_a = {}, _a['$' + totField.type] = '$' + totField.id + '_' + field.selFieldId, _a);
|
|
781
|
-
});
|
|
782
|
-
});
|
|
783
|
-
query_1.push({ $group: grQuery });
|
|
784
|
-
if (rootOptions.sort) {
|
|
785
|
-
var sortKeys_1 = Object.keys(rootOptions.sort);
|
|
786
|
-
var sort_1 = {};
|
|
787
|
-
var groupString_1 = '';
|
|
788
|
-
groupsRow.forEach(function (row, groupIndex) {
|
|
789
|
-
if (groupIndex > 0) {
|
|
790
|
-
groupString_1 += 'gr_' + (groupIndex + 1) + '.';
|
|
791
|
-
}
|
|
792
|
-
if (sortKeys_1.includes('_id.gr_' + (groupIndex + 1))) {
|
|
793
|
-
sort_1[groupString_1 + '_id.gr_' + (groupIndex + 1)] = rootOptions.sort['_id.gr_' + (groupIndex + 1)];
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
sort_1[groupString_1 + '_id.gr_' + (groupIndex + 1)] = 1;
|
|
797
|
-
}
|
|
798
|
-
});
|
|
799
|
-
sortKeys_1.filter(function (a) { return !a.startsWith('_id.gr_'); }).forEach(function (key) {
|
|
800
|
-
sort_1[groupString_1 + key] = rootOptions.sort[key];
|
|
801
|
-
});
|
|
802
|
-
query_1.push({ $sort: sort_1 });
|
|
803
|
-
}
|
|
804
|
-
};
|
|
805
|
-
for (i = groupsRow.length - 1; i >= 1; i--) {
|
|
806
|
-
_loop_1(i);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
res_1 = null;
|
|
810
|
-
_a.label = 2;
|
|
811
|
-
case 2:
|
|
812
|
-
_a.trys.push([2, 4, , 5]);
|
|
813
|
-
return [4 /*yield*/, modelCollection.aggregate(query_1, { allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary' }, true)];
|
|
814
|
-
case 3:
|
|
815
|
-
res_1 = _a.sent();
|
|
816
|
-
return [3 /*break*/, 5];
|
|
817
|
-
case 4:
|
|
818
|
-
err_1 = _a.sent();
|
|
819
|
-
console.log(err_1);
|
|
820
|
-
return [3 /*break*/, 5];
|
|
821
|
-
case 5:
|
|
822
|
-
tmpTotals_1 = {};
|
|
823
|
-
if (res_1) {
|
|
824
|
-
fieldsTotal.forEach(function (totField) {
|
|
825
|
-
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
826
|
-
if (totField.type === 'sum') {
|
|
827
|
-
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);
|
|
828
|
-
}
|
|
829
|
-
else if (totField.type === 'avg') {
|
|
830
|
-
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);
|
|
831
|
-
}
|
|
832
|
-
});
|
|
833
|
-
customFields.forEach(function (custField) {
|
|
834
|
-
if (totField.type === 'sum') {
|
|
835
|
-
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);
|
|
836
|
-
}
|
|
837
|
-
else if (totField.type === 'avg') {
|
|
838
|
-
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);
|
|
839
|
-
}
|
|
840
|
-
});
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
tmpRes = [{
|
|
844
|
-
count: res_1 ? res_1.length : 0,
|
|
845
|
-
results: res_1 ? (rootOptions.limit ? res_1.splice(0, rootOptions.limit) : res_1) : [],
|
|
846
|
-
totals: tmpTotals_1
|
|
847
|
-
}];
|
|
848
|
-
resolve(tmpRes);
|
|
849
|
-
_a.label = 6;
|
|
850
|
-
case 6: return [2 /*return*/];
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
}); });
|
|
854
|
-
},
|
|
855
|
-
}
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
exports.loadReportBuilderMethods = loadReportBuilderMethods;
|
|
859
|
-
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,a,u){return new(a=a||Promise)(function(l,i){function r(e){try{n(u.next(e))}catch(e){i(e)}}function t(e){try{n(u.throw(e))}catch(e){i(e)}}function n(e){var i;e.done?l(e.value):((i=e.value)instanceof a?i:new a(function(e){e(i)})).then(r,t)}n((u=u.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(r,t){var n,o,a,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},d={next:e(0),throw:e(1),return:e(2)};return"function"==typeof Symbol&&(d[Symbol.iterator]=function(){return this}),d;function e(l){return function(e){var i=[l,e];if(n)throw new TypeError("Generator is already executing.");for(;u=d&&i[d=0]?0:u;)try{if(n=1,o&&(a=2&i[0]?o.return:i[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,i[1])).done)return a;switch(o=0,(i=a?[2&i[0],a.value]:i)[0]){case 0:case 1:a=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,o=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(a=0<(a=u.trys).length&&a[a.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3]))u.label=i[1];else if(6===i[0]&&u.label<a[1])u.label=a[1],a=i;else{if(!(a&&u.label<a[2])){a[2]&&u.ops.pop(),u.trys.pop();continue}u.label=a[2],u.ops.push(i)}}i=t.call(r,u)}catch(e){i=[6,e],o=0}finally{n=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}}},simpl_schema_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadReportBuilderMethods=void 0,require("simpl-schema")),pagination_model_1=require("../models/pagination.model"),index_1=require("../index"),schema_report_builder_1=require("../util/schema-report-builder");function loadReportBuilderMethods(e){e.methods({reportBuilderBuildTree:{check:new simpl_schema_1.default({collection_root:{type:String}}),function:function(l){var r=this;return new Promise(function(i,e){return __awaiter(r,void 0,void 0,function(){var r,t,n;return __generator(this,function(e){return r=(0,schema_report_builder_1.getReportLookupSchemas)(l).sort(function(e,i){return e.collection_name.localeCompare(i.collection_name)}),t=r.filter(function(e){return!0===e.is_root})[0].tree,n=(0,schema_report_builder_1.buildTree)(l,t),Object.keys(t).filter(function(e){return e.endsWith("(Lookup)")}).forEach(function(i){var e=i.split("."),l=null;e.forEach(function(i){l=(l?l.children.filter(function(e){return e.fieldName===i}):n.filter(function(e){return e.fieldName===i}))[0]}),l.children=(0,schema_report_builder_1.buildTree)(t[i].lookup_collection,r.filter(function(e){return e.collection_name===t[i].lookup_collection})[0].tree,l)}),i({isLeaf:!1,children:n}),[2]})})})}},reportBuilderGetDistinctValue:{check:new simpl_schema_1.default({treeLeaf:{type:Object,blackbox:!0}}),function:function(t){var i=this;return new Promise(function(r,e){return __awaiter(i,void 0,void 0,function(){var i,l;return __generator(this,function(e){switch(e.label){case 0:return"String"!==t.fieldType?[3,5]:t.fieldPath.includes("(Lookup)")?(i=r,[4,(0,schema_report_builder_1.mongoCommand)("distinct",t.collection_name,t.fieldPath.replace(/^.+\(.+\) \(Lookup\)\.\$\./g,"").replace(/\.\$/g,""))]):[3,2];case 1:return i.apply(void 0,[e.sent()]),[3,4];case 2:return l=r,[4,(0,schema_report_builder_1.mongoCommand)("distinct",t.collection_name,t.fieldPath.replace(/\.\$/g,""))];case 3:l.apply(void 0,[e.sent()]),e.label=4;case 4:return[3,6];case 5:r([]),e.label=6;case 6:return[2]}})})})}},reportBuilderGetResults:{check:new simpl_schema_1.default({reportType:{type:String},rootCollectionName:{type:String},options:{type:pagination_model_1.PaginationOptionsSchema},filters:{type:Array,optional:!0},"filters.$":{type:Object,blackbox:!0,optional:!0},filterArrays:{type:Array,optional:!0},"filterArrays.$":{type:Object,blackbox:!0,optional:!0},filterArrayFields:{type:Array,optional:!0},"filterArrayFields.$":{type:Object,blackbox:!0,optional:!0},selectedFields:{type:Array,optional:!0},"selectedFields.$":{type:Object,optional:!0,blackbox:!0},customFields:{type:Array,optional:!0},"customFields.$":{type:Object,optional:!0,blackbox:!0},groupsRow:{type:Array},"groupsRow.$":{type:Object,blackbox:!0},fieldsTotal:{type:Array},"fieldsTotal.$":{type:Object,blackbox:!0},fieldsLink:{type:Array},"fieldsLink.$":{type:Object,blackbox:!0},date_field:{type:String,optional:!0},date_interval:{type:String,optional:!0},displayType:{type:String,optional:!0}}),function:function(g,m,y,v,k,T,F,I,E,b,C,A,z,N){var e=this;return void 0===v&&(v=[]),void 0===k&&(k=[]),void 0===T&&(T=[]),void 0===F&&(F=[]),void 0===I&&(I=[]),void 0===E&&(E=[]),void 0===b&&(b=[]),void 0===C&&(C=[]),void 0===A&&(A=""),void 0===z&&(z=""),void 0===N&&(N=""),new Promise(function(h,_){return __awaiter(e,void 0,void 0,function(){var i,u,l,o,r,t,n,a,d,c,s,p,f,$;return __generator(this,function(e){switch(e.label){case 0:return(i=index_1.ResolveIOServer.getMongoManager().collection(m))?[3,1]:(_("Invalid collection"),[3,6]);case 1:if(u=[],l={$and:[]},v.filter(function(e){return!e.$or&&!Object.keys(e).some(function(e){return e.includes("(Lookup)")})||e.$or&&!e.$or.some(function(e){return Object.keys(e).some(function(e){return e.includes("(Lookup)")})})}).length&&v.filter(function(e){return!e.$or&&!Object.keys(e).some(function(e){return e.includes("(Lookup)")})||e.$or&&!e.$or.some(function(e){return Object.keys(e).some(function(e){return e.includes("(Lookup)")})})}).forEach(function(e){l.$and.push(e)}),v.filter(function(e){return!e.$or&&!Object.keys(e).some(function(e){return e.includes("(Lookup)")})||e.$or&&!e.$or.some(function(e){return Object.keys(e).some(function(e){return e.includes("(Lookup)")})})}).length&&u.push({$match:l}),u.push({$addFields:{count:{$sum:1}}}),o=[],T.filter(function(e){return e.fieldPath}).forEach(function(i){for(var e,l=i.fieldPath.split(".$"),r="",t=0;t<l.length-1;t++)(r+=l[t]).split(".$")[r.split(".$").length-1].includes("(Lookup)")?u.some(function(e){return e.$lookup&&e.$lookup.as===i.lookup_as.replace(/\.\$/g,"")})||(u.push({$lookup:{from:i.lookup_collection,localField:i.lookup_local_key,foreignField:i.lookup_foreign_key,as:i.lookup_as.replace(/\.\$/g,"")}}),o.push(i.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")),u.push({$addFields:((e={})["size_"+i.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")]={$size:{$ifNull:["$"+i.lookup_as.replace(/\.\$/g,"").replace(/\./g,"_"),[]]}},e)}),u.push({$unwind:{path:"$"+i.lookup_as.replace(/\.\$/g,""),preserveNullAndEmptyArrays:!0}})):u.some(function(e){return e.$addFields&&Object.keys(e.$addFields).includes("size_"+r.replace(/\./g,"_"))})||(o.push(r.replace(/\./g,"_")),u.push({$addFields:((e={})["size_"+r.replace(/\./g,"_")]={$size:{$ifNull:["$"+r,[]]}},e)}),u.push({$unwind:{path:"$"+r,preserveNullAndEmptyArrays:!0}}))}),E.forEach(function(i){var e;if(i.field.includes("$"))for(var l=i.field.split(".$"),r="",t=0;t<l.length-1;t++)(r+=l[t]).split(".$")[r.split(".$").length-1].includes("(Lookup)")?u.some(function(e){return e.$lookup&&e.$lookup.as===i.treeItem.lookup_as.replace(/\.\$/g,"")})||(u.push({$lookup:{from:i.treeItem.lookup_collection,localField:i.treeItem.lookup_local_key,foreignField:i.treeItem.lookup_foreign_key,as:i.treeItem.lookup_as.replace(/\.\$/g,"")}}),o.push(i.treeItem.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")),u.push({$addFields:((e={})["size_"+i.treeItem.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")]={$size:{$ifNull:["$"+i.treeItem.lookup_as.replace(/\.\$/g,"").replace(/\./g,"_"),[]]}},e)}),u.push({$unwind:{path:"$"+i.treeItem.lookup_as.replace(/\.\$/g,""),preserveNullAndEmptyArrays:!0}})):u.some(function(e){return e.$addFields&&Object.keys(e.$addFields).includes("size_"+r.replace(/\./g,"_"))})||(o.push(r.replace(/\./g,"_")),u.push({$addFields:((e={})["size_"+r.replace(/\./g,"_")]={$size:{$ifNull:["$"+r,[]]}},e)}),u.push({$unwind:{path:"$"+r,preserveNullAndEmptyArrays:!0}}))}),F.forEach(function(i){var e,l;if(i.fieldPath.includes("$"))for(var r=i.fieldPath.split(".$"),t="",n=0;n<r.length-1;n++)(t+=r[n]).split(".$")[t.split(".$").length-1].includes("(Lookup)")?u.some(function(e){return e.$lookup&&e.$lookup.as===i.lookup_as.replace(/\.\$/g,"")})?r[n].includes("(Lookup)")||u.some(function(e){return e.$addFields&&Object.keys(e.$addFields).includes("size_"+t.replace(/\./g,"_"))})||(o.push(t.replace(/\./g,"_")),u.push({$addFields:((e={})["size_"+t.replace(/\./g,"_")]={$size:{$ifNull:["$"+t,[]]}},e)}),u.push({$unwind:{path:"$"+t,preserveNullAndEmptyArrays:!0}})):(u.push({$lookup:{from:i.lookup_collection,localField:i.lookup_local_key,foreignField:i.lookup_foreign_key,as:i.lookup_as.replace(/\.\$/g,"")}}),o.push(i.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")),u.push({$addFields:((e={})["size_"+i.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")]={$size:{$ifNull:["$"+i.lookup_as.replace(/\.\$/g,"").replace(/\./g,"_"),[]]}},e)}),u.push({$unwind:{path:"$"+i.lookup_as.replace(/\.\$/g,""),preserveNullAndEmptyArrays:!0}})):(u.some(function(e){return e.$addFields&&Object.keys(e.$addFields).includes("size_"+t.replace(/\./g,"_"))})||(o.push(t.replace(/\./g,"_")),u.push({$addFields:((l={})["size_"+t.replace(/\./g,"_")]={$size:{$ifNull:["$"+t,[]]}},l)})),"Count"===i.leafValueType||u.some(function(e){return e.$unwind&&e.$unwind.path==="$"+t})||u.push({$unwind:{path:"$"+t,preserveNullAndEmptyArrays:!0}}))}),r={$addFields:{}},b.filter(function(e){return"sum"===e.type}).forEach(function(l){F.filter(function(e){return"Number"===e.fieldType||"Count"===e.leafValueType}).forEach(function(e){var i=[];e.fieldPath.includes(".$")?o.filter(function(i){return!e.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)&&!T.filter(function(e){return e.fieldPath}).some(function(e){return e.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)})&&!C.some(function(e){return e.field_first.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)||e.field_second.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)})}).forEach(function(e){i.push({$cond:{if:{$gt:["$size_"+e,0]},then:"$size_"+e,else:1}})}):o.forEach(function(e){i.push({$cond:{if:{$gt:["$size_"+e,0]},then:"$size_"+e,else:1}})}),i.length?"Count"===e.leafValueType?r.$addFields[l.id+"_"+e.id]={$divide:["$count",{$multiply:i}]}:r.$addFields[l.id+"_"+e.id]={$divide:["$"+e.fieldPath.replace(/\.\$/g,""),{$multiply:i}]}:"Count"===e.leafValueType?r.$addFields[l.id+"_"+e.id]="$count":r.$addFields[l.id+"_"+e.id]="$"+e.fieldPath.replace(/\.\$/g,"")})}),F.filter(function(e){return"Number"===e.fieldType&&"Sum"===e.leafValueType}).forEach(function(e){var i=[];o.filter(function(i){return!(e.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)||E.some(function(e){return e.field.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)})||T.filter(function(e){return e.fieldPath}).some(function(e){return e.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)})||C.some(function(e){return e.field_first.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)||e.field_second.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)}))}).forEach(function(e){i.push({$cond:{if:{$gt:["$size_"+e,0]},then:"$size_"+e,else:1}})}),i.length&&(r.$addFields[e.fieldPath.replace(/\.\$/g,"")]={$divide:["$"+e.fieldPath.replace(/\.\$/g,""),{$multiply:i}]})}),F.filter(function(e){return"Count"===e.leafValueType}).forEach(function(l){var i=[];o.filter(function(i){return!(l.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)||E.some(function(e){return e.field.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)})||T.filter(function(e){return e.fieldPath}).some(function(e){return e.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)})||C.some(function(e){return e.field_first.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)||e.field_second.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)}))}).forEach(function(e){i.push({$cond:{if:{$gt:["$size_"+e,0]},then:"$size_"+e,else:1}})}),i.length?r.$addFields["count_"+l.fieldPath.replace(/\.\$/g,"")]={$divide:["$count",{$multiply:i}]}:"Dated"!==g&&o.filter(function(e){return l.fieldPath.replace(/\.\$\./g,"_").includes(e)}).length?o.filter(function(e){return l.fieldPath.replace(/\.\$\./g,"_").includes(e)}).forEach(function(e){r.$addFields["count_"+l.fieldPath.replace(/\.\$/g,"")]="$size_"+e}):r.$addFields["count_"+l.fieldPath.replace(/\.\$/g,"")]="$count"}),b.filter(function(e){return"avg"===e.type}).forEach(function(i){F.filter(function(e){return"Number"===e.fieldType||"Count"===e.leafValueType}).forEach(function(e){r.$addFields[i.id+"_"+e.id]="$"+e.fieldPath.replace(/\.\$/g,"")})}),0<Object.keys(r.$addFields).length&&u.push(r),C.filter(function(e){return e.field_first&&e.field_second}).forEach(function(e){var i;u.push({$addFields:((i={})[e.id]={$cmp:["$"+e.field_first.replace(/\.\$/g,""),"$"+e.field_second.replace(/\.\$/g,"")]},i)}),u.push({$match:((i={})[e.id]=0,i)})}),I.forEach(function(a){a.operations.filter(function(e){return e.operation&&!e.fields.some(function(e){return(null===e.field||""===e.field)&&null===e.value})}).forEach(function(i,e){var l,r,t,n,o={};"divide"===i.operation?(r=[],i.fields.filter(function(e){return e.field||null!==e.value}).forEach(function(e){e.field?(r.push({$eq:["$"+e.field.replace(/\.\$/g,""),0]}),r.push({$eq:["$"+e.field.replace(/\.\$/g,""),null]})):(r.push({$eq:[e.value,0]}),r.push({$eq:[e.value,null]}))}),0<e&&(r.push({$eq:["$"+a.selFieldId,0]}),r.push({$eq:["$"+a.selFieldId,null]})),t=[],0<e&&t.push("$"+a.selFieldId),i.fields.filter(function(e){return e.field||null!==e.value}).forEach(function(e){e.field?t.push("$"+e.field.replace(/\.\$/g,"")):t.push(e.value)}),o[a.selFieldId]={$cond:{if:{$or:r},then:0,else:((l={})["$"+i.operation]=t,l)}}):(o[a.selFieldId]=((l={})["$"+i.operation]=[],l),0<e&&o[a.selFieldId]["$"+i.operation].push({$cond:{if:{$eq:["$"+a.selFieldId,null]},then:0,else:"$"+a.selFieldId}}),n=[],i.fields.filter(function(e){return e.field||null!==e.value}).forEach(function(e){e.field?n.push({$eq:["$"+e.field.replace(/\.\$/g,""),null]}):n.push({$eq:[e.value,null]})}),i.fields.filter(function(e){return e.field||null!==e.value}).forEach(function(e){e.field?o[a.selFieldId]["$"+i.operation].push({$cond:{if:{$or:n},then:0,else:"$"+e.field.replace(/\.\$/g,"")}}):o[a.selFieldId]["$"+i.operation].push({$cond:{if:{$or:n},then:0,else:e.value}})})),u.push({$addFields:o})})}),b.forEach(function(l){I.forEach(function(e){var i;u.push({$addFields:((i={})[l.id+"_"+e.selFieldId]="$"+e.selFieldId,i)})})}),t={$and:[]},v.filter(function(e){return!e.$or&&Object.keys(e).some(function(e){return e.includes("(Lookup)")})||e.$or&&e.$or.some(function(e){return Object.keys(e).some(function(e){return e.includes("(Lookup)")})})}).length&&v.filter(function(e){return!e.$or&&Object.keys(e).some(function(e){return e.includes("(Lookup)")})||e.$or&&e.$or.some(function(e){return Object.keys(e).some(function(e){return e.includes("(Lookup)")})})}).forEach(function(e){t.$and.push(e)}),k.forEach(function(e){t.$and.push(e)}),t.$and.length&&u.push({$match:t}),n={_id:{}},E.length||!N||"grouped"===N?(E.length?y.sort&&(a={},Object.keys(y.sort).forEach(function(i){var e=F.filter(function(e){return e.id===i})[0];e&&(a[e.fieldPath.replace(/\.\$/g,"")]=y.sort[i])}),0<Object.keys(a).length)&&u.push({$sort:a}):n._id="$_id",E.forEach(function(e){n._id[e.id]="$"+e.field.replace(/\.\$/g,""),A&&z&&("Seconds"===z?(n._id.second={$second:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.minute={$minute:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.hour={$hour:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.day={$dayOfMonth:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.month={$month:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.year={$year:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}}):"Minutes"===z?(n._id.minute={$minute:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.hour={$hour:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.day={$dayOfMonth:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.month={$month:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.year={$year:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}}):"Hours"===z?(n._id.hour={$hour:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.day={$dayOfMonth:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.month={$month:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.year={$year:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}}):"Daily"===z?(n._id.day={$dayOfMonth:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.month={$month:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.year={$year:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}}):"Weekly"===z?(n._id.week={$isoWeek:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.year={$isoWeekYear:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}}):"Monthly"===z||"Quarterly"===z?(n._id.month={$month:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}},n._id.year={$year:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}}):"Yearly"===z&&(n._id.year={$year:{date:"$"+A.replace(/\.\$/g,""),timezone:process.env.TZ_CLIENT||"America/Chicago"}}))}),F.forEach(function(e){"Average"===e.leafValueType?n[e.id]={$avg:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Sum"===e.leafValueType?n[e.id]={$sum:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Count"===e.leafValueType?n[e.id]={$sum:"$count_"+e.fieldPath.replace(/\.\$/g,"")}:"Minimum"===e.leafValueType?n[e.id]={$min:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Maximum"===e.leafValueType?n[e.id]={$max:"$"+e.fieldPath.replace(/\.\$/g,"")}:"First"===e.leafValueType?n[e.id]={$first:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Last"===e.leafValueType?n[e.id]={$last:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Unique"===e.leafValueType?n[e.id]={$addToSet:"$"+e.fieldPath.replace(/\.\$/g,"")}:n[e.id]={$push:{$ifNull:["$"+e.fieldPath.replace(/\.\$/g,""),null]}}}),I.forEach(function(e){"Average"===e.leafValueType?n[e.selFieldId]={$avg:"$"+e.selFieldId}:"Sum"===e.leafValueType?n[e.selFieldId]={$sum:"$"+e.selFieldId}:"Count"===e.leafValueType?n[e.selFieldId]="Dated"===g?{$sum:"$count_"+e.selFieldId}:{$push:"$count_"+e.selFieldId}:"Minimum"===e.leafValueType?n[e.selFieldId]={$min:"$"+e.selFieldId}:"Maximum"===e.leafValueType?n[e.selFieldId]={$max:"$"+e.selFieldId}:"First"===e.leafValueType?n[e.selFieldId]={$first:"$"+e.selFieldId}:"Last"===e.leafValueType?n[e.selFieldId]={$last:"$"+e.selFieldId}:"Unique"===e.leafValueType?n[e.selFieldId]={$addToSet:"$"+e.selFieldId}:n[e.selFieldId]={$push:{$ifNull:["$"+e.selFieldId,null]}}}),b.length&&b.forEach(function(l){F.filter(function(e){return"Number"===e.fieldType||"Count"===e.leafValueType}).forEach(function(e){var i;n[l.id+"_"+e.id]=((i={})["$"+l.type]="$"+l.id+"_"+e.id,i)}),I.forEach(function(e){var i;n[l.id+"_"+e.selFieldId]=((i={})["$"+l.type]="$"+l.id+"_"+e.selFieldId,i)})}),u.push({$group:n})):(d={_id:1},F.forEach(function(e){"Average"===e.leafValueType?d[e.id]={$avg:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Sum"===e.leafValueType?d[e.id]={$sum:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Count"===e.leafValueType?d[e.id]={$sum:1}:"Minimum"===e.leafValueType?d[e.id]={$min:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Maximum"===e.leafValueType?d[e.id]={$max:"$"+e.fieldPath.replace(/\.\$/g,"")}:d[e.id]="$"+e.fieldPath.replace(/\.\$/g,"")}),I.forEach(function(e){d[e.selFieldId]="Average"===e?{$avg:"$"+e.selFieldId}:"Sum"===e?{$sum:"$"+e.selFieldId}:"Count"===e?{$sum:1}:"Minimum"===e?{$min:"$"+e.selFieldId}:"Maximum"===e?{$max:"$"+e.selFieldId}:"$"+e.selFieldId}),!b.length||"List"!==g&&"Dated"!==g||b.forEach(function(l){F.filter(function(e){return"Number"===e.fieldType||"Count"===e.leafValueType}).forEach(function(e){var i;d[l.id+"_"+e.id]=((i={})["$"+l.type]="$"+l.id+"_"+e.id,i)}),I.forEach(function(e){var i;d[l.id+"_"+e.selFieldId]=((i={})["$"+l.type]="$"+l.id+"_"+e.selFieldId,i)})}),u.push({$project:d})),y.sort&&u.push({$sort:y.sort}),"Group"===g&&1<E.length)for(c=function(l){for(var e,r,t,n,o={_id:1},a=(o[E[l].id]={_id:((e={})[E[l].id]="$_id."+E[l].id,e)},l===E.length-1?(F.forEach(function(e){o[E[l].id][e.id]="$"+e.id}),I.forEach(function(e){o[E[l].id][e.selFieldId]="$"+e.selFieldId})):o[E[l].id][E[l+1].id]="$"+E[l+1].id,b.forEach(function(i){F.filter(function(e){return"Number"===e.fieldType||"Count"===e.leafValueType}).forEach(function(e){o[i.id+"_"+e.id]=1,o[E[l].id][i.id+"_"+e.id]="$"+i.id+"_"+e.id}),I.forEach(function(e){o[E[l].id][i.id+"_"+e.selFieldId]="$"+i.id+"_"+e.selFieldId})}),u.push({$project:o}),{_id:{}}),i=0;i<l;i++)a._id[E[i].id]="$_id."+E[i].id;a[E[l].id]={$push:"$"+E[l].id},b.forEach(function(l){F.filter(function(e){return"Number"===e.fieldType||"Count"===e.leafValueType}).forEach(function(e){var i;a[l.id+"_"+e.id]=((i={})["$"+l.type]="$"+l.id+"_"+e.id,i)}),I.forEach(function(e){var i;a[l.id+"_"+e.selFieldId]=((i={})["$"+l.type]="$"+l.id+"_"+e.selFieldId,i)})}),u.push({$group:a}),y.sort&&(r=Object.keys(y.sort),t={},n="",E.forEach(function(e,i){0<i&&(n+="gr_"+(i+1)+"."),r.includes("_id.gr_"+(i+1))?t[n+"_id.gr_"+(i+1)]=y.sort["_id.gr_"+(i+1)]:t[n+"_id.gr_"+(i+1)]=1}),r.filter(function(e){return!e.startsWith("_id.gr_")}).forEach(function(e){t[n+e]=y.sort[e]}),u.push({$sort:t}))},s=E.length-1;1<=s;s--)c(s);p=null,e.label=2;case 2:return e.trys.push([2,4,,5]),[4,i.aggregate(u,{allowDiskUse:!0,readPreference:"http://localhost:4200"!==this.serverConfig.ROOT_URL?"secondary":"primary"},!0)];case 3:return p=e.sent(),[3,5];case 4:return $=e.sent(),console.log($),[3,5];case 5:f={},p&&b.forEach(function(l){F.filter(function(e){return"Number"===e.fieldType||"Count"===e.leafValueType}).forEach(function(i){"sum"===l.type?f[l.id+"_"+i.id]=p.map(function(e){return e[l.id+"_"+i.id]||0}).reduce(function(e,i){return e+i},0):"avg"===l.type&&(f[l.id+"_"+i.id]=Math.round(p.map(function(e){return e[l.id+"_"+i.id]||0}).reduce(function(e,i){return e+i},0)/p.length))}),I.forEach(function(i){"sum"===l.type?f[l.id+"_"+i.selFieldId]=p.map(function(e){return e[l.id+"_"+i.selFieldId]||0}).reduce(function(e,i){return e+i},0):"avg"===l.type&&(f[l.id+"_"+i.selFieldId]=Math.round(p.map(function(e){return e[l.id+"_"+i.selFieldId]||0}).reduce(function(e,i){return e+i},0)/p.length))})}),$=[{count:p?p.length:0,results:p?y.limit?p.splice(0,y.limit):p:[],totals:f}],h($),e.label=6;case 6:return[2]}})})})}}})}exports.loadReportBuilderMethods=loadReportBuilderMethods;
|
|
860
2
|
//# sourceMappingURL=report-builder.js.map
|