@resolveio/server-lib 4.5.13 → 4.6.0-newrole

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,13 +22,6 @@ var schema = {
22
22
  type: Date,
23
23
  optional: true
24
24
  },
25
- readonly: {
26
- type: Boolean,
27
- optional: true
28
- },
29
- active: {
30
- type: Boolean
31
- },
32
25
  attempts: {
33
26
  type: Number,
34
27
  optional: true
@@ -65,53 +58,67 @@ var schema = {
65
58
  type: String
66
59
  },
67
60
  roles: {
61
+ type: Object
62
+ },
63
+ 'roles.super_admin': {
64
+ type: Boolean
65
+ },
66
+ 'roles.approvals': {
68
67
  type: Array
69
68
  },
70
- 'roles.$': {
69
+ 'roles.approvals.$': {
70
+ type: Object
71
+ },
72
+ 'roles.approvals.$.name': {
71
73
  type: String
72
74
  },
73
- phonenumber: {
74
- type: String,
75
- optional: true
75
+ 'roles.approvals.$.type': {
76
+ type: String
76
77
  },
77
- other: {
78
- type: Object,
79
- blackbox: true,
80
- optional: true
78
+ 'roles.approvals.$.accounting_code': {
79
+ type: String
81
80
  },
82
- assets: {
83
- type: Array,
84
- optional: true
81
+ 'roles.groups': {
82
+ type: Array
85
83
  },
86
- 'assets.$': {
84
+ 'roles.groups.$': {
87
85
  type: Object
88
86
  },
89
- 'assets.$.type': {
87
+ 'roles.groups.$.name': {
90
88
  type: String
91
89
  },
92
- 'assets.$.id_asset': {
93
- type: String
90
+ 'roles.groups.$.views': {
91
+ type: Array
94
92
  },
95
- 'assets.$.asset_number': {
93
+ 'roles.groups.$.views.$': {
96
94
  type: String
97
95
  },
98
- 'assets.$.ownership': {
99
- type: String
96
+ 'roles.groups.$.yard': {
97
+ type: String,
98
+ optional: true
99
+ },
100
+ 'roles.notifications': {
101
+ type: Array
100
102
  },
101
- 'assets.$.ownership_driver': {
103
+ 'roles.notifications.$': {
102
104
  type: String
103
105
  },
104
- 'assets.$.date_start': {
105
- type: Date
106
+ 'roles.miscs': {
107
+ type: Array
106
108
  },
107
- 'assets.$.date_end': {
108
- type: Date,
109
- optional: true
109
+ 'roles.miscs.$': {
110
+ type: String
110
111
  },
111
- id_function: {
112
+ active: Boolean,
113
+ phonenumber: {
112
114
  type: String,
113
115
  optional: true
114
116
  },
117
+ other: {
118
+ type: Object,
119
+ optional: true,
120
+ blackbox: true
121
+ },
115
122
  customers: {
116
123
  type: Array,
117
124
  optional: true,
package/fixtures/init.js CHANGED
@@ -37,8 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  var app_version_collection_1 = require("../collections/app-version.collection");
39
39
  var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
40
- var active_subscription_collection_1 = require("../collections/active-subscription.collection");
41
40
  var mongoose_1 = require("mongoose");
41
+ var active_subscription_collection_1 = require("../collections/active-subscription.collection");
42
42
  function loadServerInit() {
43
43
  return __awaiter(this, void 0, void 0, function () {
44
44
  var appVersion;
@@ -233,6 +233,8 @@ function loadReportBuilderMethods(methodManager) {
233
233
  $match: initialQueryMatchCondition
234
234
  });
235
235
  }
236
+ // Add count
237
+ query.push({ $addFields: { count: { $sum: 1 } } });
236
238
  sizes = [];
237
239
  // Groups - Lookups / Sizes / Unwinds
238
240
  groupsRow.forEach(function (row) {
@@ -266,56 +268,103 @@ function loadReportBuilderMethods(methodManager) {
266
268
  var _a, _b;
267
269
  if (field.fieldPath.includes('$')) {
268
270
  var fieldData = field.fieldPath.split('.$');
269
- var fieldPath = '';
271
+ var fieldPath_1 = '';
270
272
  for (var i = 0; i < fieldData.length - 1; i++) {
271
- fieldPath += fieldData[i];
272
- if (fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup)')) {
273
- query.push({ $lookup: {
274
- from: field.lookup_collection,
275
- localField: field.lookup_local_key,
276
- foreignField: field.lookup_foreign_key,
277
- as: field.lookup_as.replace(/\.\$/g, '')
278
- } });
279
- sizes.push(field.lookup_as.replace(/\.\$\./g, '_'));
280
- query.push({ $addFields: (_a = {}, _a['size_' + field.lookup_as.replace(/\.\$\./g, '_')] = { $size: '$' + field.lookup_as.replace(/\.\$/g, '') }, _a) });
281
- query.push({ '$unwind': { path: '$' + field.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
273
+ fieldPath_1 += fieldData[i];
274
+ if (fieldPath_1.split('.$')[fieldPath_1.split('.$').length - 1].includes('(Lookup)')) {
275
+ if (!query.some(function (a) { return a.$lookup && a.$lookup.as === field.lookup_as.replace(/\.\$/g, ''); })) {
276
+ query.push({ $lookup: {
277
+ from: field.lookup_collection,
278
+ localField: field.lookup_local_key,
279
+ foreignField: field.lookup_foreign_key,
280
+ as: field.lookup_as.replace(/\.\$/g, '')
281
+ } });
282
+ sizes.push(field.lookup_as.replace(/\.\$\./g, '_'));
283
+ query.push({ $addFields: (_a = {}, _a['size_' + field.lookup_as.replace(/\.\$\./g, '_')] = { $size: '$' + field.lookup_as.replace(/\.\$/g, '') }, _a) });
284
+ query.push({ '$unwind': { path: '$' + field.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
285
+ }
282
286
  }
283
287
  else {
284
- sizes.push(fieldPath.replace(/\./g, '_'));
285
- query.push({ $addFields: (_b = {}, _b['size_' + fieldPath.replace(/\./g, '_')] = { $size: '$' + fieldPath }, _b) });
286
- query.push({ '$unwind': { path: '$' + fieldPath, preserveNullAndEmptyArrays: true } });
288
+ if (!query.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_1.replace(/\./g, '_')); })) {
289
+ sizes.push(fieldPath_1.replace(/\./g, '_'));
290
+ query.push({ $addFields: (_b = {}, _b['size_' + fieldPath_1.replace(/\./g, '_')] = { $size: '$' + fieldPath_1 }, _b) });
291
+ query.push({ '$unwind': { path: '$' + fieldPath_1, preserveNullAndEmptyArrays: true } });
292
+ }
287
293
  }
288
294
  }
289
295
  }
290
296
  });
291
297
  divFields = { $addFields: {} };
292
298
  fieldsTotal.filter(function (a) { return a.type === 'sum'; }).forEach(function (total) {
293
- selectedFields.filter(function (a) { return !a.fieldPath.includes('.$') && a.fieldType === 'Number'; }).forEach(function (field) {
299
+ selectedFields.filter(function (a) { return a.fieldType === 'Number'; }).forEach(function (field) {
294
300
  var multFields = [];
295
- sizes.forEach(function (size) {
296
- multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
297
- });
301
+ if (!field.fieldPath.includes('.$')) {
302
+ sizes.forEach(function (size) {
303
+ multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
304
+ });
305
+ }
306
+ else {
307
+ 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) {
308
+ multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
309
+ });
310
+ }
298
311
  if (multFields.length) {
299
- divFields.$addFields[total.id + '_' + field.id] = {
300
- $divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
301
- };
312
+ if (field.leafValueType === 'Count') {
313
+ divFields.$addFields[total.id + '_' + field.id] = {
314
+ $divide: ['$count', { $multiply: multFields }]
315
+ };
316
+ }
317
+ else {
318
+ divFields.$addFields[total.id + '_' + field.id] = {
319
+ $divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
320
+ };
321
+ }
322
+ }
323
+ else {
324
+ if (field.leafValueType === 'Count') {
325
+ divFields.$addFields[total.id + '_' + field.id] = '$count';
326
+ }
327
+ else {
328
+ divFields.$addFields[total.id + '_' + field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
329
+ }
302
330
  }
303
331
  });
304
- selectedFields.filter(function (a) { return a.fieldPath.includes('.$') && a.fieldType === 'Number'; }).forEach(function (field) {
305
- var multFields = [];
306
- sizes.filter(function (a) { return !field.fieldPath.includes(a); }).forEach(function (size) {
332
+ });
333
+ selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Sum'; }).forEach(function (field) {
334
+ var multFields = [];
335
+ if (field.fieldPath.includes('.$')) {
336
+ 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) {
307
337
  multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
308
338
  });
309
- if (multFields.length) {
310
- divFields.$addFields[total.id + '_' + field.id] = {
311
- $divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
312
- };
313
- }
339
+ }
340
+ if (multFields.length) {
341
+ divFields.$addFields[field.fieldPath.replace(/\.\$/g, '')] = {
342
+ $divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
343
+ };
344
+ }
345
+ });
346
+ selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Count'; }).forEach(function (field) {
347
+ var multFields = [];
348
+ 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) {
349
+ multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
314
350
  });
351
+ if (multFields.length) {
352
+ divFields.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = {
353
+ $divide: ['$count', { $multiply: multFields }]
354
+ };
355
+ }
356
+ else {
357
+ divFields.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = '$count';
358
+ }
315
359
  });
316
360
  if (Object.keys(divFields.$addFields).length > 0) {
317
361
  query.push(divFields);
318
362
  }
363
+ fieldsLink.filter(function (a) { return a.field_first && a.field_second; }).forEach(function (link) {
364
+ var _a, _b;
365
+ query.push({ $addFields: (_a = {}, _a[link.id] = { $cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')] }, _a) });
366
+ query.push({ $match: (_b = {}, _b[link.id] = 0, _b) });
367
+ });
319
368
  queryGroup = {
320
369
  _id: {}
321
370
  };
@@ -355,7 +404,7 @@ function loadReportBuilderMethods(methodManager) {
355
404
  queryGroup[field.id] = { '$sum': '$' + field.fieldPath.replace(/\.\$/g, '') };
356
405
  }
357
406
  else if (field.leafValueType === 'Count') {
358
- queryGroup[field.id] = { '$sum': 1 };
407
+ queryGroup[field.id] = { '$sum': '$count_' + field.fieldPath.replace(/\.\$/g, '') };
359
408
  }
360
409
  else if (field.leafValueType === 'Minimum') {
361
410
  queryGroup[field.id] = { '$min': '$' + field.fieldPath.replace(/\.\$/g, '') };
@@ -363,7 +412,7 @@ function loadReportBuilderMethods(methodManager) {
363
412
  else if (field.leafValueType === 'Maximum') {
364
413
  queryGroup[field.id] = { '$max': '$' + field.fieldPath.replace(/\.\$/g, '') };
365
414
  }
366
- else if (field.leafValueType === 'First') {
415
+ else if (field.leafValueType === 'First' || (!groupsRow.length && !field.fieldPath.includes('.$'))) {
367
416
  queryGroup[field.id] = { '$first': '$' + field.fieldPath.replace(/\.\$/g, '') };
368
417
  }
369
418
  else if (field.leafValueType === 'Last') {
@@ -409,10 +458,10 @@ function loadReportBuilderMethods(methodManager) {
409
458
  fieldsTotal.forEach(function (totField) {
410
459
  selectedFields.filter(function (b) { return b.fieldType === 'Number'; }).forEach(function (selField) {
411
460
  if (totField.type === 'sum') {
412
- tmpTotals[totField.id + '_' + selField.id] = res.reduce(function (a, b) { return (a[totField.id + '_' + selField.id] || 0) + (b[totField.id + '_' + selField.id] || 0); }, 0);
461
+ tmpTotals[totField.id + '_' + selField.id] = res.map(function (a) { return a[totField.id + '_' + selField.id] || 0; }).reduce(function (a, b) { return a + b; }, 0);
413
462
  }
414
463
  else if (totField.type === 'avg') {
415
- tmpTotals[totField.id + '_' + selField.id] = Math.round(res.reduce(function (a, b) { return (a[totField.id + '_' + selField.id] || 0) + (b[totField.id + '_' + selField.id] || 0); }, 0) / res.length);
464
+ tmpTotals[totField.id + '_' + selField.id] = Math.round(res.map(function (a) { return a[totField.id + '_' + selField.id] || 0; }).reduce(function (a, b) { return a + b; }, 0) / res.length);
416
465
  }
417
466
  });
418
467
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.5.13",
3
+ "version": "4.6.0-newrole",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {