@resolveio/server-lib 4.6.9 → 4.6.10

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.
@@ -144,12 +144,13 @@ function loadReportBuilderMethods(methodManager) {
144
144
  blackbox: true,
145
145
  optional: true
146
146
  },
147
- filterArrayPaths: {
147
+ filterArrayFields: {
148
148
  type: Array,
149
149
  optional: true
150
150
  },
151
- 'filterArrayPaths.$': {
152
- type: String,
151
+ 'filterArrayFields.$': {
152
+ type: Object,
153
+ blackbox: true,
153
154
  optional: true
154
155
  },
155
156
  selectedFields: {
@@ -195,11 +196,11 @@ function loadReportBuilderMethods(methodManager) {
195
196
  optional: true
196
197
  }
197
198
  }),
198
- function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayPaths, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval, tabularDisplayType) {
199
+ function: function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayFields, selectedFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval, tabularDisplayType) {
199
200
  var _this = this;
200
201
  if (filters === void 0) { filters = []; }
201
202
  if (filterArrays === void 0) { filterArrays = []; }
202
- if (filterArrayPaths === void 0) { filterArrayPaths = []; }
203
+ if (filterArrayFields === void 0) { filterArrayFields = []; }
203
204
  if (selectedFields === void 0) { selectedFields = []; }
204
205
  if (groupsRow === void 0) { groupsRow = []; }
205
206
  if (fieldsTotal === void 0) { fieldsTotal = []; }
@@ -208,7 +209,7 @@ function loadReportBuilderMethods(methodManager) {
208
209
  if (date_interval === void 0) { date_interval = ''; }
209
210
  if (tabularDisplayType === void 0) { tabularDisplayType = ''; }
210
211
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
211
- var uniqueSelectedFieldCollections, modelCollection, query, initialQueryMatchCondition, sizes, divFields, queryGroup, queryProjection_1, res, err_1, tmpTotals, tmpRes;
212
+ var uniqueSelectedFieldCollections, modelCollection, query, initialQueryMatchCondition, sizes, divFields, queryMatchConditionLookup, queryGroup, queryProjection_1, res, err_1, tmpTotals, tmpRes;
212
213
  var _this = this;
213
214
  return __generator(this, function (_a) {
214
215
  switch (_a.label) {
@@ -311,6 +312,34 @@ function loadReportBuilderMethods(methodManager) {
311
312
  }
312
313
  }
313
314
  });
315
+ filterArrayFields.forEach(function (filterField) {
316
+ var _a, _b;
317
+ var fieldData = filterField.fieldPath.split('.$');
318
+ var fieldPath = '';
319
+ for (var i = 0; i < fieldData.length - 1; i++) {
320
+ fieldPath += fieldData[i];
321
+ if (fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup)')) {
322
+ if (!query.some(function (a) { return a.$lookup && a.$lookup.as === filterField.lookup_as.replace(/\.\$/g, ''); })) {
323
+ query.push({ $lookup: {
324
+ from: filterField.lookup_collection,
325
+ localField: filterField.lookup_local_key,
326
+ foreignField: filterField.lookup_foreign_key,
327
+ as: filterField.lookup_as.replace(/\.\$/g, '')
328
+ } });
329
+ sizes.push(filterField.lookup_as.replace(/\.\$\./g, '_'));
330
+ query.push({ $addFields: (_a = {}, _a['size_' + filterField.lookup_as.replace(/\.\$\./g, '_')] = { $size: '$' + filterField.lookup_as.replace(/\.\$/g, '') }, _a) });
331
+ query.push({ '$unwind': { path: '$' + filterField.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
332
+ }
333
+ }
334
+ else {
335
+ if (!query.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath.replace(/\./g, '_')); })) {
336
+ sizes.push(fieldPath.replace(/\./g, '_'));
337
+ query.push({ $addFields: (_b = {}, _b['size_' + fieldPath.replace(/\./g, '_')] = { $size: '$' + fieldPath }, _b) });
338
+ query.push({ '$unwind': { path: '$' + fieldPath, preserveNullAndEmptyArrays: true } });
339
+ }
340
+ }
341
+ }
342
+ });
314
343
  divFields = { $addFields: {} };
315
344
  fieldsTotal.filter(function (a) { return a.type === 'sum'; }).forEach(function (total) {
316
345
  selectedFields.filter(function (a) { return a.fieldType === 'Number'; }).forEach(function (field) {
@@ -321,7 +350,7 @@ function loadReportBuilderMethods(methodManager) {
321
350
  });
322
351
  }
323
352
  else {
324
- sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
353
+ sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !filterArrayFields.some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
325
354
  multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
326
355
  });
327
356
  }
@@ -350,7 +379,7 @@ function loadReportBuilderMethods(methodManager) {
350
379
  selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Sum'; }).forEach(function (field) {
351
380
  var multFields = [];
352
381
  if (field.fieldPath.includes('.$')) {
353
- sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
382
+ sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').includes(a); }) && !filterArrayFields.some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
354
383
  multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
355
384
  });
356
385
  }
@@ -362,7 +391,7 @@ function loadReportBuilderMethods(methodManager) {
362
391
  });
363
392
  selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Count'; }).forEach(function (field) {
364
393
  var multFields = [];
365
- sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
394
+ sizes.filter(function (a) { return !field.fieldPath.replace(/\.\$\./g, '_').includes(a) && !groupsRow.some(function (b) { return b.field.replace(/\.\$\./g, '_').includes(a); }) && !filterArrayFields.some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').includes(a); }); }).forEach(function (size) {
366
395
  multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
367
396
  });
368
397
  if (multFields.length) {
@@ -382,6 +411,20 @@ function loadReportBuilderMethods(methodManager) {
382
411
  query.push({ $addFields: (_a = {}, _a[link.id] = { $cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')] }, _a) });
383
412
  query.push({ $match: (_b = {}, _b[link.id] = 0, _b) });
384
413
  });
414
+ queryMatchConditionLookup = {
415
+ $and: []
416
+ };
417
+ 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) {
418
+ 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) {
419
+ queryMatchConditionLookup['$and'].push(filter);
420
+ });
421
+ }
422
+ filterArrays.forEach(function (filter) {
423
+ queryMatchConditionLookup['$and'].push(filter);
424
+ });
425
+ if (queryMatchConditionLookup.$and.length) {
426
+ query.push({ $match: queryMatchConditionLookup });
427
+ }
385
428
  queryGroup = {
386
429
  _id: {}
387
430
  };
@@ -481,12 +524,6 @@ function loadReportBuilderMethods(methodManager) {
481
524
  queryProjection_1[field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
482
525
  }
483
526
  });
484
- //Links
485
- // if (fieldsLink.length) {
486
- // fieldsLink.filter(a => a.field_first && a.field_second).forEach(link => {
487
- // queryProjection[link.id] = {$cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')]};
488
- // });
489
- // }
490
527
  //Totals
491
528
  if (fieldsTotal.length && (reportType === 'Tabular' || reportType === 'Dated')) {
492
529
  fieldsTotal.forEach(function (total) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.6.9",
3
+ "version": "4.6.10",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {