@resolveio/server-lib 9.2.19 → 9.2.20
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 +55 -1
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +40 -1
- package/collections/app-status.collection.js.map +1 -1
- package/collections/app-version.collection.js +40 -1
- package/collections/app-version.collection.js.map +1 -1
- package/collections/counter.collection.js +43 -1
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +71 -1
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +74 -1
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +55 -1
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +50 -1
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +62 -1
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +44 -1
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +53 -1
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +57 -1
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +72 -1
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +58 -1
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-call.collection.js +51 -1
- package/collections/method-call.collection.js.map +1 -1
- package/collections/method-response.collection.js +55 -1
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +57 -1
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-https-inbound.collection.js +66 -1
- package/collections/monitor-https-inbound.collection.js.map +1 -1
- package/collections/monitor-https-outbound.collection.js +74 -1
- package/collections/monitor-https-outbound.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +68 -1
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +62 -1
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +40 -1
- package/collections/notification.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +93 -1
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +76 -1
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +138 -1
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +79 -1
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +46 -1
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +248 -1
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +161 -1
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +72 -1
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +62 -1
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +697 -1
- package/http/auth.js.map +1 -1
- package/http/health.js +10 -1
- package/http/health.js.map +1 -1
- package/http/home.js +64 -1
- package/http/home.js.map +1 -1
- package/index.js +123 -1
- package/index.js.map +1 -1
- package/managers/cron.manager.js +205 -1
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +599 -1
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +1682 -1
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +334 -1
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +867 -1
- package/managers/subscription.manager.js.map +1 -1
- package/managers/subscription.performance.js +100 -1
- package/managers/subscription.performance.js.map +1 -1
- package/methods/accounts.js +224 -1
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +449 -1
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +214 -1
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +526 -1
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +121 -1
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +1284 -1
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +8 -1
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +370 -1
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +384 -1
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +685 -1
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +826 -1
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +263 -1
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +3 -1
- package/models/app-status.model.js.map +1 -1
- package/models/app-version.model.js +3 -1
- package/models/app-version.model.js.map +1 -1
- package/models/billing-logged-in-users.model.js +3 -1
- package/models/billing-logged-in-users.model.js.map +1 -1
- package/models/collection-document.model.js +3 -1
- package/models/collection-document.model.js.map +1 -1
- package/models/counter.model.js +3 -1
- package/models/counter.model.js.map +1 -1
- package/models/cron-job-history.model.js +3 -1
- package/models/cron-job-history.model.js.map +1 -1
- package/models/cron-job.model.js +3 -1
- package/models/cron-job.model.js.map +1 -1
- package/models/dialog.model.js +3 -1
- package/models/dialog.model.js.map +1 -1
- package/models/email-history.model.js +3 -1
- package/models/email-history.model.js.map +1 -1
- package/models/email-verified.model.js +3 -1
- package/models/email-verified.model.js.map +1 -1
- package/models/file.model.js +3 -1
- package/models/file.model.js.map +1 -1
- package/models/flag.model.js +3 -1
- package/models/flag.model.js.map +1 -1
- package/models/log-method-latency.model.js +3 -1
- package/models/log-method-latency.model.js.map +1 -1
- package/models/log-subscription.model.js +3 -1
- package/models/log-subscription.model.js.map +1 -1
- package/models/log.model.js +3 -1
- package/models/log.model.js.map +1 -1
- package/models/logged-in-users.model.js +3 -1
- package/models/logged-in-users.model.js.map +1 -1
- package/models/method-call.model.js +3 -1
- package/models/method-call.model.js.map +1 -1
- package/models/method-response.model.js +3 -1
- package/models/method-response.model.js.map +1 -1
- package/models/method.model.js +3 -1
- package/models/method.model.js.map +1 -1
- package/models/monitor-cpu.model.js +3 -1
- package/models/monitor-cpu.model.js.map +1 -1
- package/models/monitor-https-inbound.model.js +3 -1
- package/models/monitor-https-inbound.model.js.map +1 -1
- package/models/monitor-https-outbound.model.js +3 -1
- package/models/monitor-https-outbound.model.js.map +1 -1
- package/models/monitor-memory.model.js +3 -1
- package/models/monitor-memory.model.js.map +1 -1
- package/models/monitor-mongo.model.js +3 -1
- package/models/monitor-mongo.model.js.map +1 -1
- package/models/notification.model.js +3 -1
- package/models/notification.model.js.map +1 -1
- package/models/pagination.model.js +23 -1
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +3 -1
- package/models/permission.model.js.map +1 -1
- package/models/report-builder-dashboard-builder.model.js +3 -1
- package/models/report-builder-dashboard-builder.model.js.map +1 -1
- package/models/report-builder-library.model.js +3 -1
- package/models/report-builder-library.model.js.map +1 -1
- package/models/report-builder-report.model.js +3 -1
- package/models/report-builder-report.model.js.map +1 -1
- package/models/report-builder.model.js +3 -1
- package/models/report-builder.model.js.map +1 -1
- package/models/select-data-label.model.js +3 -1
- package/models/select-data-label.model.js.map +1 -1
- package/models/server-response.model.js +3 -1
- package/models/server-response.model.js.map +1 -1
- package/models/subscription.model.js +3 -1
- package/models/subscription.model.js.map +1 -1
- package/models/support-ticket.model.js +3 -1
- package/models/support-ticket.model.js.map +1 -1
- package/models/user-group.model.js +3 -1
- package/models/user-group.model.js.map +1 -1
- package/models/user-guide.model.js +3 -1
- package/models/user-guide.model.js.map +1 -1
- package/models/user.model.js +3 -1
- package/models/user.model.js.map +1 -1
- package/package.json +1 -2
- package/public_api.js +78 -1
- package/public_api.js.map +1 -1
- package/publications/app-status.js +16 -1
- package/publications/app-status.js.map +1 -1
- package/publications/app-version.js +16 -1
- package/publications/app-version.js.map +1 -1
- package/publications/cron-jobs.js +32 -1
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +36 -1
- package/publications/files.js.map +1 -1
- package/publications/flags.js +22 -1
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +90 -1
- package/publications/logs.js.map +1 -1
- package/publications/method-calls.js +16 -1
- package/publications/method-calls.js.map +1 -1
- package/publications/method-responses.js +16 -1
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +16 -1
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +42 -1
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +89 -1
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +50 -1
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +16 -1
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +16 -1
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +16 -1
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +682 -1
- package/server-app.js.map +1 -1
- package/util/common.js +498 -1
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +452 -1
- package/util/schema-report-builder.js.map +1 -1
|
@@ -1,2 +1,827 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,i,l,t){return new(l||(l=Promise))((function(r,n){function fulfilled(e){try{step(t.next(e))}catch(e){n(e)}}function rejected(e){try{step(t.throw(e))}catch(e){n(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof l?e:new l((function(i){i(e)}))}(e.value).then(fulfilled,rejected)}step((t=t.apply(e,i||[])).next())}))},__generator=this&&this.__generator||function(e,i){var l,t,r,n,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return n={next:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function verb(n){return function(u){return function step(n){if(l)throw new TypeError("Generator is already executing.");for(;o;)try{if(l=1,t&&(r=2&n[0]?t.return:n[0]?t.throw||((r=t.return)&&r.call(t),0):t.next)&&!(r=r.call(t,n[1])).done)return r;switch(t=0,r&&(n=[2&n[0],r.value]),n[0]){case 0:case 1:r=n;break;case 4:return o.label++,{value:n[1],done:!1};case 5:o.label++,t=n[1],n=[0];continue;case 7:n=o.ops.pop(),o.trys.pop();continue;default:if(!(r=o.trys,(r=r.length>0&&r[r.length-1])||6!==n[0]&&2!==n[0])){o=0;continue}if(3===n[0]&&(!r||n[1]>r[0]&&n[1]<r[3])){o.label=n[1];break}if(6===n[0]&&o.label<r[1]){o.label=r[1],r=n;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(n);break}r[2]&&o.ops.pop(),o.trys.pop();continue}n=i.call(e,o)}catch(e){n=[6,e],t=0}finally{l=r=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,u])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadReportBuilderMethods=void 0;var simpl_schema_1=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(e){var i=this;return new Promise((function(l,t){return __awaiter(i,void 0,void 0,(function(){var i,t,r;return __generator(this,(function(n){return i=schema_report_builder_1.getReportLookupSchemas(e).sort((function(e,i){return e.collection_name.localeCompare(i.collection_name)})),t=i.filter((function(e){return!0===e.is_root}))[0].tree,r=schema_report_builder_1.buildTree(e,t),Object.keys(t).filter((function(e){return e.endsWith("(Lookup)")})).forEach((function(e){var l=e.split("."),n=null;l.forEach((function(e){n=n?n.children.filter((function(i){return i.fieldName===e}))[0]:r.filter((function(i){return i.fieldName===e}))[0]})),n.children=schema_report_builder_1.buildTree(t[e].lookup_collection,i.filter((function(i){return i.collection_name===t[e].lookup_collection}))[0].tree,n)})),l({isLeaf:!1,children:r}),[2]}))}))}))}},reportBuilderGetDistinctValue:{check:new simpl_schema_1.default({treeLeaf:{type:Object,blackbox:!0}}),function:function(e){var i=this;return new Promise((function(l,t){return __awaiter(i,void 0,void 0,(function(){var i,t;return __generator(this,(function(r){switch(r.label){case 0:return"String"!==e.fieldType?[3,5]:e.fieldPath.includes("(Lookup)")?(i=l,[4,schema_report_builder_1.mongoCommand("distinct",e.collection_name,e.fieldPath.replace(/^.+\(.+\) \(Lookup\)\.\$\./g,"").replace(/\.\$/g,""))]):[3,2];case 1:return i.apply(void 0,[r.sent()]),[3,4];case 2:return t=l,[4,schema_report_builder_1.mongoCommand("distinct",e.collection_name,e.fieldPath.replace(/\.\$/g,""))];case 3:t.apply(void 0,[r.sent()]),r.label=4;case 4:return[3,6];case 5:l([]),r.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(e,i,l,t,r,n,o,u,a,d,c,s,f,p){var $=this;return void 0===t&&(t=[]),void 0===r&&(r=[]),void 0===n&&(n=[]),void 0===o&&(o=[]),void 0===u&&(u=[]),void 0===a&&(a=[]),void 0===d&&(d=[]),void 0===c&&(c=[]),void 0===s&&(s=""),void 0===f&&(f=""),void 0===p&&(p=""),new Promise((function(h,_){return __awaiter($,void 0,void 0,(function(){var $,g,m,y,v,k,F,b,E,I,T,P,O,w,z=this;return __generator(this,(function(V){switch(V.label){case 0:return($=index_1.ResolveIOServer.getMongoManager().collection(i))?[3,1]:(_("Invalid collection"),[3,6]);case 1:if(g=[],m={$and:[]},t.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&&t.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){m.$and.push(e)})),t.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&&g.push({$match:m}),g.push({$addFields:{count:{$sum:1}}}),y=[],n.filter((function(e){return e.fieldPath})).forEach((function(e){for(var i,l,t=e.fieldPath.split(".$"),r="",n=0;n<t.length-1;n++)(r+=t[n]).split(".$")[r.split(".$").length-1].includes("(Lookup)")?g.some((function(i){return i.$lookup&&i.$lookup.as===e.lookup_as.replace(/\.\$/g,"")}))||(g.push({$lookup:{from:e.lookup_collection,localField:e.lookup_local_key,foreignField:e.lookup_foreign_key,as:e.lookup_as.replace(/\.\$/g,"")}}),y.push(e.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")),g.push({$addFields:(i={},i["size_"+e.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")]={$size:{$ifNull:["$"+e.lookup_as.replace(/\.\$/g,"").replace(/\./g,"_"),[]]}},i)}),g.push({$unwind:{path:"$"+e.lookup_as.replace(/\.\$/g,""),preserveNullAndEmptyArrays:!0}})):g.some((function(e){return e.$addFields&&Object.keys(e.$addFields).includes("size_"+r.replace(/\./g,"_"))}))||(y.push(r.replace(/\./g,"_")),g.push({$addFields:(l={},l["size_"+r.replace(/\./g,"_")]={$size:{$ifNull:["$"+r,[]]}},l)}),g.push({$unwind:{path:"$"+r,preserveNullAndEmptyArrays:!0}}))})),a.forEach((function(e){var i,l;if(e.field.includes("$"))for(var t=e.field.split(".$"),r="",n=0;n<t.length-1;n++)(r+=t[n]).split(".$")[r.split(".$").length-1].includes("(Lookup)")?g.some((function(i){return i.$lookup&&i.$lookup.as===e.treeItem.lookup_as.replace(/\.\$/g,"")}))||(g.push({$lookup:{from:e.treeItem.lookup_collection,localField:e.treeItem.lookup_local_key,foreignField:e.treeItem.lookup_foreign_key,as:e.treeItem.lookup_as.replace(/\.\$/g,"")}}),y.push(e.treeItem.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")),g.push({$addFields:(i={},i["size_"+e.treeItem.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")]={$size:{$ifNull:["$"+e.treeItem.lookup_as.replace(/\.\$/g,"").replace(/\./g,"_"),[]]}},i)}),g.push({$unwind:{path:"$"+e.treeItem.lookup_as.replace(/\.\$/g,""),preserveNullAndEmptyArrays:!0}})):g.some((function(e){return e.$addFields&&Object.keys(e.$addFields).includes("size_"+r.replace(/\./g,"_"))}))||(y.push(r.replace(/\./g,"_")),g.push({$addFields:(l={},l["size_"+r.replace(/\./g,"_")]={$size:{$ifNull:["$"+r,[]]}},l)}),g.push({$unwind:{path:"$"+r,preserveNullAndEmptyArrays:!0}}))})),o.forEach((function(e){var i,l,t;if(e.fieldPath.includes("$"))for(var r=e.fieldPath.split(".$"),n="",o=0;o<r.length-1;o++)(n+=r[o]).split(".$")[n.split(".$").length-1].includes("(Lookup)")?g.some((function(i){return i.$lookup&&i.$lookup.as===e.lookup_as.replace(/\.\$/g,"")}))?r[o].includes("(Lookup)")||g.some((function(e){return e.$addFields&&Object.keys(e.$addFields).includes("size_"+n.replace(/\./g,"_"))}))||(y.push(n.replace(/\./g,"_")),g.push({$addFields:(l={},l["size_"+n.replace(/\./g,"_")]={$size:{$ifNull:["$"+n,[]]}},l)}),g.push({$unwind:{path:"$"+n,preserveNullAndEmptyArrays:!0}})):(g.push({$lookup:{from:e.lookup_collection,localField:e.lookup_local_key,foreignField:e.lookup_foreign_key,as:e.lookup_as.replace(/\.\$/g,"")}}),y.push(e.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")),g.push({$addFields:(i={},i["size_"+e.lookup_as.replace(/\.\$\./g,"_").replace(/\./g,"_")]={$size:{$ifNull:["$"+e.lookup_as.replace(/\.\$/g,"").replace(/\./g,"_"),[]]}},i)}),g.push({$unwind:{path:"$"+e.lookup_as.replace(/\.\$/g,""),preserveNullAndEmptyArrays:!0}})):(g.some((function(e){return e.$addFields&&Object.keys(e.$addFields).includes("size_"+n.replace(/\./g,"_"))}))||(y.push(n.replace(/\./g,"_")),g.push({$addFields:(t={},t["size_"+n.replace(/\./g,"_")]={$size:{$ifNull:["$"+n,[]]}},t)})),"Count"===e.leafValueType||g.some((function(e){return e.$unwind&&e.$unwind.path==="$"+n}))||g.push({$unwind:{path:"$"+n,preserveNullAndEmptyArrays:!0}}))})),v={$addFields:{}},d.filter((function(e){return"sum"===e.type})).forEach((function(e){o.filter((function(e){return"Number"===e.fieldType||"Count"===e.leafValueType})).forEach((function(i){var l=[];i.fieldPath.includes(".$")?y.filter((function(e){return!i.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(e)&&!n.filter((function(e){return e.fieldPath})).some((function(i){return i.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(e)}))&&!c.some((function(i){return i.field_first.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(e)||i.field_second.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(e)}))})).forEach((function(e){l.push({$cond:{if:{$gt:["$size_"+e,0]},then:"$size_"+e,else:1}})})):y.forEach((function(e){l.push({$cond:{if:{$gt:["$size_"+e,0]},then:"$size_"+e,else:1}})})),l.length?"Count"===i.leafValueType?v.$addFields[e.id+"_"+i.id]={$divide:["$count",{$multiply:l}]}:v.$addFields[e.id+"_"+i.id]={$divide:["$"+i.fieldPath.replace(/\.\$/g,""),{$multiply:l}]}:"Count"===i.leafValueType?v.$addFields[e.id+"_"+i.id]="$count":v.$addFields[e.id+"_"+i.id]="$"+i.fieldPath.replace(/\.\$/g,"")}))})),o.filter((function(e){return"Number"===e.fieldType&&"Sum"===e.leafValueType})).forEach((function(e){var i=[];y.filter((function(i){return!(e.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)||a.some((function(e){return e.field.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(i)}))||n.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&&(v.$addFields[e.fieldPath.replace(/\.\$/g,"")]={$divide:["$"+e.fieldPath.replace(/\.\$/g,""),{$multiply:i}]})})),o.filter((function(e){return"Count"===e.leafValueType})).forEach((function(i){var l=[];y.filter((function(e){return!(i.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(e)||a.some((function(i){return i.field.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(e)}))||n.filter((function(e){return e.fieldPath})).some((function(i){return i.fieldPath.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(e)}))||c.some((function(i){return i.field_first.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(e)||i.field_second.replace(/\.\$\./g,"_").replace(/\./g,"_").includes(e)})))})).forEach((function(e){l.push({$cond:{if:{$gt:["$size_"+e,0]},then:"$size_"+e,else:1}})})),l.length?v.$addFields["count_"+i.fieldPath.replace(/\.\$/g,"")]={$divide:["$count",{$multiply:l}]}:"Dated"!==e&&y.filter((function(e){return i.fieldPath.replace(/\.\$\./g,"_").includes(e)})).length?y.filter((function(e){return i.fieldPath.replace(/\.\$\./g,"_").includes(e)})).forEach((function(e){v.$addFields["count_"+i.fieldPath.replace(/\.\$/g,"")]="$size_"+e})):v.$addFields["count_"+i.fieldPath.replace(/\.\$/g,"")]="$count"})),d.filter((function(e){return"avg"===e.type})).forEach((function(e){o.filter((function(e){return"Number"===e.fieldType||"Count"===e.leafValueType})).forEach((function(i){v.$addFields[e.id+"_"+i.id]="$"+i.fieldPath.replace(/\.\$/g,"")}))})),Object.keys(v.$addFields).length>0&&g.push(v),c.filter((function(e){return e.field_first&&e.field_second})).forEach((function(e){var i,l;g.push({$addFields:(i={},i[e.id]={$cmp:["$"+e.field_first.replace(/\.\$/g,""),"$"+e.field_second.replace(/\.\$/g,"")]},i)}),g.push({$match:(l={},l[e.id]=0,l)})})),u.forEach((function(e){e.operations.filter((function(e){return e.operation&&!e.fields.some((function(e){return(null===e.field||""===e.field)&&null===e.value}))})).forEach((function(i,l){var t,r,n={};if("divide"===i.operation){var o=[];i.fields.filter((function(e){return e.field||null!==e.value})).forEach((function(e){e.field?(o.push({$eq:["$"+e.field.replace(/\.\$/g,""),0]}),o.push({$eq:["$"+e.field.replace(/\.\$/g,""),null]})):(o.push({$eq:[e.value,0]}),o.push({$eq:[e.value,null]}))})),l>0&&(o.push({$eq:["$"+e.selFieldId,0]}),o.push({$eq:["$"+e.selFieldId,null]}));var u=[];l>0&&u.push("$"+e.selFieldId),i.fields.filter((function(e){return e.field||null!==e.value})).forEach((function(e){e.field?u.push("$"+e.field.replace(/\.\$/g,"")):u.push(e.value)})),n[e.selFieldId]={$cond:{if:{$or:o},then:0,else:(t={},t["$"+i.operation]=u,t)}}}else{n[e.selFieldId]=((r={})["$"+i.operation]=[],r),l>0&&n[e.selFieldId]["$"+i.operation].push({$cond:{if:{$eq:["$"+e.selFieldId,null]},then:0,else:"$"+e.selFieldId}});var a=[];i.fields.filter((function(e){return e.field||null!==e.value})).forEach((function(e){e.field?a.push({$eq:["$"+e.field.replace(/\.\$/g,""),null]}):a.push({$eq:[e.value,null]})})),i.fields.filter((function(e){return e.field||null!==e.value})).forEach((function(l){l.field?n[e.selFieldId]["$"+i.operation].push({$cond:{if:{$or:a},then:0,else:"$"+l.field.replace(/\.\$/g,"")}}):n[e.selFieldId]["$"+i.operation].push({$cond:{if:{$or:a},then:0,else:l.value}})}))}g.push({$addFields:n})}))})),d.forEach((function(e){u.forEach((function(i){var l;g.push({$addFields:(l={},l[e.id+"_"+i.selFieldId]="$"+i.selFieldId,l)})}))})),k={$and:[]},t.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&&t.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){k.$and.push(e)})),r.forEach((function(e){k.$and.push(e)})),k.$and.length&&g.push({$match:k}),F={_id:{}},a.length||!p||"grouped"===p?(a.length||(F._id="$_id"),a.forEach((function(e){F._id[e.id]="$"+e.field.replace(/\.\$/g,""),s&&f&&("Daily"===f?(F._id.day={$dayOfMonth:{date:"$"+s.replace(/\.\$/g,""),timezone:z.serverConfig.TIMEZONE}},F._id.month={$month:{date:"$"+s.replace(/\.\$/g,""),timezone:z.serverConfig.TIMEZONE}},F._id.year={$year:{date:"$"+s.replace(/\.\$/g,""),timezone:z.serverConfig.TIMEZONE}}):"Weekly"===f?(F._id.week={$isoWeek:{date:"$"+s.replace(/\.\$/g,""),timezone:z.serverConfig.TIMEZONE}},F._id.year={$isoWeekYear:{date:"$"+s.replace(/\.\$/g,""),timezone:z.serverConfig.TIMEZONE}}):"Monthly"===f||"Quarterly"===f?(F._id.month={$month:{date:"$"+s.replace(/\.\$/g,""),timezone:z.serverConfig.TIMEZONE}},F._id.year={$year:{date:"$"+s.replace(/\.\$/g,""),timezone:z.serverConfig.TIMEZONE}}):"Yearly"===f&&(F._id.year={$year:{date:"$"+s.replace(/\.\$/g,""),timezone:z.serverConfig.TIMEZONE}}))})),o.forEach((function(i){"Average"===i.leafValueType?F[i.id]={$avg:"$"+i.fieldPath.replace(/\.\$/g,"")}:"Sum"===i.leafValueType?F[i.id]={$sum:"$"+i.fieldPath.replace(/\.\$/g,"")}:"Count"===i.leafValueType?F[i.id]="Dated"===e?{$sum:"$count_"+i.fieldPath.replace(/\.\$/g,"")}:{$push:"$count_"+i.fieldPath.replace(/\.\$/g,"")}:"Minimum"===i.leafValueType?F[i.id]={$min:"$"+i.fieldPath.replace(/\.\$/g,"")}:"Maximum"===i.leafValueType?F[i.id]={$max:"$"+i.fieldPath.replace(/\.\$/g,"")}:"First"!==i.leafValueType&&(a.length||i.fieldPath.includes(".$")&&!i.fieldPath.includes("(Lookup)"))?"Last"===i.leafValueType?F[i.id]={$last:"$"+i.fieldPath.replace(/\.\$/g,"")}:"Unique"===i.leafValueType?F[i.id]={$addToSet:"$"+i.fieldPath.replace(/\.\$/g,"")}:F[i.id]={$push:"$"+i.fieldPath.replace(/\.\$/g,"")}:F[i.id]={$first:"$"+i.fieldPath.replace(/\.\$/g,"")}})),u.forEach((function(i){"Average"===i.leafValueType?F[i.selFieldId]={$avg:"$"+i.selFieldId}:"Sum"===i.leafValueType?F[i.selFieldId]={$sum:"$"+i.selFieldId}:"Count"===i.leafValueType?F[i.selFieldId]="Dated"===e?{$sum:"$count_"+i.selFieldId}:{$push:"$count_"+i.selFieldId}:"Minimum"===i.leafValueType?F[i.selFieldId]={$min:"$"+i.selFieldId}:"Maximum"===i.leafValueType?F[i.selFieldId]={$max:"$"+i.selFieldId}:"First"===i.leafValueType?F[i.selFieldId]={$first:"$"+i.selFieldId}:"Last"===i.leafValueType?F[i.selFieldId]={$last:"$"+i.selFieldId}:"Unique"===i.leafValueType?F[i.selFieldId]={$addToSet:"$"+i.selFieldId}:F[i.selFieldId]={$push:"$"+i.selFieldId}})),d.length&&d.forEach((function(e){o.filter((function(e){return"Number"===e.fieldType||"Count"===e.leafValueType})).forEach((function(i){F[e.id+"_"+i.id]={$sum:"$"+e.id+"_"+i.id}})),u.forEach((function(i){F[e.id+"_"+i.selFieldId]={$sum:"$"+e.id+"_"+i.selFieldId}}))})),g.push({$group:F})):(b={_id:1},o.forEach((function(e){"Average"===e.leafValueType?b[e.id]={$avg:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Sum"===e.leafValueType?b[e.id]={$sum:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Count"===e.leafValueType?b[e.id]={$sum:1}:"Minimum"===e.leafValueType?b[e.id]={$min:"$"+e.fieldPath.replace(/\.\$/g,"")}:"Maximum"===e.leafValueType?b[e.id]={$max:"$"+e.fieldPath.replace(/\.\$/g,"")}:b[e.id]="$"+e.fieldPath.replace(/\.\$/g,"")})),u.forEach((function(e){b[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})),!d.length||"List"!==e&&"Dated"!==e||d.forEach((function(e){o.filter((function(e){return"Number"===e.fieldType||"Count"===e.leafValueType})).forEach((function(i){var l;b[e.id+"_"+i.id]=((l={})["$"+e.type]="$"+e.id+"_"+i.id,l)})),u.forEach((function(i){var l;b[e.id+"_"+i.selFieldId]=((l={})["$"+e.type]="$"+e.id+"_"+i.selFieldId,l)}))})),g.push({$project:b})),l.sort&&g.push({$sort:l.sort}),"Group"===e&&a.length>1)for(E=function(e){var i,t={_id:1};t[a[e].id]={_id:(i={},i[a[e].id]="$_id."+a[e].id,i)},e===a.length-1?(o.forEach((function(i){t[a[e].id][i.id]="$"+i.id})),u.forEach((function(i){t[a[e].id][i.selFieldId]="$"+i.selFieldId}))):t[a[e].id][a[e+1].id]="$"+a[e+1].id,d.forEach((function(i){o.filter((function(e){return"Number"===e.fieldType||"Count"===e.leafValueType})).forEach((function(l){t[i.id+"_"+l.id]=1,t[a[e].id][i.id+"_"+l.id]="$"+i.id+"_"+l.id})),u.forEach((function(l){t[a[e].id][i.id+"_"+l.selFieldId]="$"+i.id+"_"+l.selFieldId}))})),g.push({$project:t});for(var r={_id:{}},n=0;n<e;n++)r._id[a[n].id]="$_id."+a[n].id;if(r[a[e].id]={$push:"$"+a[e].id},d.forEach((function(e){o.filter((function(e){return"Number"===e.fieldType||"Count"===e.leafValueType})).forEach((function(i){var l;r[e.id+"_"+i.id]=((l={})["$"+e.type]="$"+e.id+"_"+i.id,l)})),u.forEach((function(i){var l;r[e.id+"_"+i.selFieldId]=((l={})["$"+e.type]="$"+e.id+"_"+i.selFieldId,l)}))})),g.push({$group:r}),l.sort){var c=Object.keys(l.sort),s={},f="";a.forEach((function(e,i){i>0&&(f+="gr_"+(i+1)+"."),c.includes("_id.gr_"+(i+1))?s[f+"_id.gr_"+(i+1)]=l.sort["_id.gr_"+(i+1)]:s[f+"_id.gr_"+(i+1)]=1})),c.filter((function(e){return!e.startsWith("_id.gr_")})).forEach((function(e){s[f+e]=l.sort[e]})),g.push({$sort:s})}},I=a.length-1;I>=1;I--)E(I);T=null,V.label=2;case 2:return V.trys.push([2,4,,5]),[4,$.aggregate(g,{allowDiskUse:!0,readPreference:"secondary"})];case 3:return T=V.sent(),[3,5];case 4:return P=V.sent(),console.log(P),[3,5];case 5:O={},T&&d.forEach((function(e){o.filter((function(e){return"Number"===e.fieldType||"Count"===e.leafValueType})).forEach((function(i){"sum"===e.type?O[e.id+"_"+i.id]=T.map((function(l){return l[e.id+"_"+i.id]||0})).reduce((function(e,i){return e+i}),0):"avg"===e.type&&(O[e.id+"_"+i.id]=Math.round(T.map((function(l){return l[e.id+"_"+i.id]||0})).reduce((function(e,i){return e+i}),0)/T.length))})),u.forEach((function(i){"sum"===e.type?O[e.id+"_"+i.selFieldId]=T.map((function(l){return l[e.id+"_"+i.selFieldId]||0})).reduce((function(e,i){return e+i}),0):"avg"===e.type&&(O[e.id+"_"+i.selFieldId]=Math.round(T.map((function(l){return l[e.id+"_"+i.selFieldId]||0})).reduce((function(e,i){return e+i}),0)/T.length))}))})),w=[{count:T?T.length:0,results:T?l.limit?T.splice(0,l.limit):T:[],totals:O}],h(w),V.label=6;case 6:return[2]}}))}))}))}}})}exports.loadReportBuilderMethods=loadReportBuilderMethods;
|
|
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 (_) 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 = 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 = 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 = 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*/, 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*/, 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, queryProjection_1, _loop_1, i, res_1, err_1, tmpTotals_1, tmpRes;
|
|
222
|
+
var _this = this;
|
|
223
|
+
return __generator(this, function (_a) {
|
|
224
|
+
switch (_a.label) {
|
|
225
|
+
case 0:
|
|
226
|
+
modelCollection = index_1.ResolveIOServer.getMongoManager().collection(rootCollectionName);
|
|
227
|
+
if (!!modelCollection) return [3 /*break*/, 1];
|
|
228
|
+
reject('Invalid collection');
|
|
229
|
+
return [3 /*break*/, 6];
|
|
230
|
+
case 1:
|
|
231
|
+
query_1 = [];
|
|
232
|
+
initialQueryMatchCondition_1 = {
|
|
233
|
+
$and: []
|
|
234
|
+
};
|
|
235
|
+
// selectedFields.filter(a => a.collection_name === rootCollectionName).forEach(field => {
|
|
236
|
+
// initialQueryMatchCondition['$and'].push({
|
|
237
|
+
// $and: [
|
|
238
|
+
// {[field.fieldPath.replace(/\.\$/g, '')]: {$exists: 1}},
|
|
239
|
+
// // {[field.fieldPath.replace(/\.\$/g, '')]: {$ne: ''}},
|
|
240
|
+
// {[field.fieldPath.replace(/\.\$/g, '')]: {$ne: null}},
|
|
241
|
+
// ]
|
|
242
|
+
// });
|
|
243
|
+
// });
|
|
244
|
+
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) {
|
|
245
|
+
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) {
|
|
246
|
+
initialQueryMatchCondition_1['$and'].push(filter);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
// Add filter to query
|
|
250
|
+
// 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) {
|
|
251
|
+
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) {
|
|
252
|
+
query_1.push({
|
|
253
|
+
$match: initialQueryMatchCondition_1
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
// Add count
|
|
257
|
+
query_1.push({ $addFields: { count: { $sum: 1 } } });
|
|
258
|
+
sizes_1 = [];
|
|
259
|
+
filterArrayFields.filter(function (a) { return a.fieldPath; }).forEach(function (filterField) {
|
|
260
|
+
var _a, _b;
|
|
261
|
+
var fieldData = filterField.fieldPath.split('.$');
|
|
262
|
+
var fieldPath = '';
|
|
263
|
+
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
264
|
+
fieldPath += fieldData[i];
|
|
265
|
+
if (fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup)')) {
|
|
266
|
+
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === filterField.lookup_as.replace(/\.\$/g, ''); })) {
|
|
267
|
+
query_1.push({ $lookup: {
|
|
268
|
+
from: filterField.lookup_collection,
|
|
269
|
+
localField: filterField.lookup_local_key,
|
|
270
|
+
foreignField: filterField.lookup_foreign_key,
|
|
271
|
+
as: filterField.lookup_as.replace(/\.\$/g, '')
|
|
272
|
+
} });
|
|
273
|
+
sizes_1.push(filterField.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
|
|
274
|
+
query_1.push({ $addFields: (_a = {}, _a['size_' + filterField.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_')] = { $size: { $ifNull: ['$' + filterField.lookup_as.replace(/\.\$/g, '').replace(/\./g, '_'), []] } }, _a) });
|
|
275
|
+
query_1.push({ '$unwind': { path: '$' + filterField.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath.replace(/\./g, '_')); })) {
|
|
280
|
+
sizes_1.push(fieldPath.replace(/\./g, '_'));
|
|
281
|
+
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath, []] } }, _b) });
|
|
282
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath, preserveNullAndEmptyArrays: true } });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
// Groups - Lookups / Sizes / Unwinds
|
|
288
|
+
groupsRow.forEach(function (row) {
|
|
289
|
+
var _a, _b;
|
|
290
|
+
if (row.field.includes('$')) {
|
|
291
|
+
var fieldData = row.field.split('.$');
|
|
292
|
+
var fieldPath_1 = '';
|
|
293
|
+
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
294
|
+
fieldPath_1 += fieldData[i];
|
|
295
|
+
if (fieldPath_1.split('.$')[fieldPath_1.split('.$').length - 1].includes('(Lookup)')) {
|
|
296
|
+
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === row.treeItem.lookup_as.replace(/\.\$/g, ''); })) {
|
|
297
|
+
query_1.push({ $lookup: {
|
|
298
|
+
from: row.treeItem.lookup_collection,
|
|
299
|
+
localField: row.treeItem.lookup_local_key,
|
|
300
|
+
foreignField: row.treeItem.lookup_foreign_key,
|
|
301
|
+
as: row.treeItem.lookup_as.replace(/\.\$/g, '')
|
|
302
|
+
} });
|
|
303
|
+
sizes_1.push(row.treeItem.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
|
|
304
|
+
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) });
|
|
305
|
+
query_1.push({ '$unwind': { path: '$' + row.treeItem.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_1.replace(/\./g, '_')); })) {
|
|
310
|
+
sizes_1.push(fieldPath_1.replace(/\./g, '_'));
|
|
311
|
+
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath_1.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_1, []] } }, _b) });
|
|
312
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath_1, preserveNullAndEmptyArrays: true } });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
// Selected Fields - Lookups / Sizes / Unwinds
|
|
319
|
+
selectedFields.forEach(function (field) {
|
|
320
|
+
var _a, _b, _c;
|
|
321
|
+
if (field.fieldPath.includes('$')) {
|
|
322
|
+
var fieldData = field.fieldPath.split('.$');
|
|
323
|
+
var fieldPath_2 = '';
|
|
324
|
+
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
325
|
+
fieldPath_2 += fieldData[i];
|
|
326
|
+
if (fieldPath_2.split('.$')[fieldPath_2.split('.$').length - 1].includes('(Lookup)')) {
|
|
327
|
+
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === field.lookup_as.replace(/\.\$/g, ''); })) {
|
|
328
|
+
query_1.push({ $lookup: {
|
|
329
|
+
from: field.lookup_collection,
|
|
330
|
+
localField: field.lookup_local_key,
|
|
331
|
+
foreignField: field.lookup_foreign_key,
|
|
332
|
+
as: field.lookup_as.replace(/\.\$/g, '')
|
|
333
|
+
} });
|
|
334
|
+
sizes_1.push(field.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
|
|
335
|
+
query_1.push({ $addFields: (_a = {}, _a['size_' + field.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_')] = { $size: { $ifNull: ['$' + field.lookup_as.replace(/\.\$/g, '').replace(/\./g, '_'), []] } }, _a) });
|
|
336
|
+
query_1.push({ '$unwind': { path: '$' + field.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
if (!fieldData[i].includes('(Lookup)')) {
|
|
340
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_2.replace(/\./g, '_')); })) {
|
|
341
|
+
sizes_1.push(fieldPath_2.replace(/\./g, '_'));
|
|
342
|
+
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath_2.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_2, []] } }, _b) });
|
|
343
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath_2, preserveNullAndEmptyArrays: true } });
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_2.replace(/\./g, '_')); })) {
|
|
350
|
+
sizes_1.push(fieldPath_2.replace(/\./g, '_'));
|
|
351
|
+
query_1.push({ $addFields: (_c = {}, _c['size_' + fieldPath_2.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_2, []] } }, _c) });
|
|
352
|
+
}
|
|
353
|
+
if (field.leafValueType !== 'Count' && !query_1.some(function (a) { return a.$unwind && a.$unwind.path === '$' + fieldPath_2; })) {
|
|
354
|
+
query_1.push({ '$unwind': { path: '$' + fieldPath_2, preserveNullAndEmptyArrays: true } });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
divFields_1 = { $addFields: {} };
|
|
361
|
+
fieldsTotal.filter(function (a) { return a.type === 'sum'; }).forEach(function (total) {
|
|
362
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
363
|
+
var multFields = [];
|
|
364
|
+
if (!field.fieldPath.includes('.$')) {
|
|
365
|
+
sizes_1.forEach(function (size) {
|
|
366
|
+
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
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) {
|
|
371
|
+
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
if (multFields.length) {
|
|
375
|
+
if (field.leafValueType === 'Count') {
|
|
376
|
+
divFields_1.$addFields[total.id + '_' + field.id] = {
|
|
377
|
+
$divide: ['$count', { $multiply: multFields }]
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
divFields_1.$addFields[total.id + '_' + field.id] = {
|
|
382
|
+
$divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
if (field.leafValueType === 'Count') {
|
|
388
|
+
divFields_1.$addFields[total.id + '_' + field.id] = '$count';
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
divFields_1.$addFields[total.id + '_' + field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Sum'; }).forEach(function (field) {
|
|
397
|
+
var multFields = [];
|
|
398
|
+
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) {
|
|
399
|
+
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
400
|
+
});
|
|
401
|
+
if (multFields.length) {
|
|
402
|
+
divFields_1.$addFields[field.fieldPath.replace(/\.\$/g, '')] = {
|
|
403
|
+
$divide: ['$' + field.fieldPath.replace(/\.\$/g, ''), { $multiply: multFields }]
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
selectedFields.filter(function (a) { return a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
408
|
+
var multFields = [];
|
|
409
|
+
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) {
|
|
410
|
+
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
411
|
+
});
|
|
412
|
+
if (multFields.length) {
|
|
413
|
+
divFields_1.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = {
|
|
414
|
+
$divide: ['$count', { $multiply: multFields }]
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
if (reportType !== 'Dated' && sizes_1.filter(function (a) { return field.fieldPath.replace(/\.\$\./g, '_').includes(a); }).length) {
|
|
419
|
+
sizes_1.filter(function (a) { return field.fieldPath.replace(/\.\$\./g, '_').includes(a); }).forEach(function (size) {
|
|
420
|
+
divFields_1.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = '$size_' + size;
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
divFields_1.$addFields['count_' + field.fieldPath.replace(/\.\$/g, '')] = '$count';
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
fieldsTotal.filter(function (a) { return a.type === 'avg'; }).forEach(function (total) {
|
|
429
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
430
|
+
divFields_1.$addFields[total.id + '_' + field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
if (Object.keys(divFields_1.$addFields).length > 0) {
|
|
434
|
+
query_1.push(divFields_1);
|
|
435
|
+
}
|
|
436
|
+
fieldsLink.filter(function (a) { return a.field_first && a.field_second; }).forEach(function (link) {
|
|
437
|
+
var _a, _b;
|
|
438
|
+
query_1.push({ $addFields: (_a = {}, _a[link.id] = { $cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')] }, _a) });
|
|
439
|
+
query_1.push({ $match: (_b = {}, _b[link.id] = 0, _b) });
|
|
440
|
+
});
|
|
441
|
+
customFields.forEach(function (cust) {
|
|
442
|
+
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) {
|
|
443
|
+
var _a, _b;
|
|
444
|
+
var custFieldGroup = {};
|
|
445
|
+
if (operation.operation === 'divide') {
|
|
446
|
+
var condCheck_1 = [];
|
|
447
|
+
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
448
|
+
if (field.field) {
|
|
449
|
+
condCheck_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), 0] });
|
|
450
|
+
condCheck_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), null] });
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
condCheck_1.push({ $eq: [field.value, 0] });
|
|
454
|
+
condCheck_1.push({ $eq: [field.value, null] });
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
if (opIndex > 0) {
|
|
458
|
+
condCheck_1.push({ $eq: ['$' + cust.selFieldId, 0] });
|
|
459
|
+
condCheck_1.push({ $eq: ['$' + cust.selFieldId, null] });
|
|
460
|
+
}
|
|
461
|
+
var tmpOperationFields_1 = [];
|
|
462
|
+
if (opIndex > 0) {
|
|
463
|
+
tmpOperationFields_1.push('$' + cust.selFieldId);
|
|
464
|
+
}
|
|
465
|
+
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
466
|
+
if (field.field) {
|
|
467
|
+
tmpOperationFields_1.push('$' + field.field.replace(/\.\$/g, ''));
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
tmpOperationFields_1.push(field.value);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
custFieldGroup[cust.selFieldId] = {
|
|
474
|
+
$cond: { if: { $or: condCheck_1 }, then: 0, else: (_a = {}, _a['$' + operation.operation] = tmpOperationFields_1, _a) }
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
custFieldGroup[cust.selFieldId] = (_b = {},
|
|
479
|
+
_b['$' + operation.operation] = [],
|
|
480
|
+
_b);
|
|
481
|
+
if (opIndex > 0) {
|
|
482
|
+
custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $eq: ['$' + cust.selFieldId, null] }, then: 0, else: '$' + cust.selFieldId } });
|
|
483
|
+
}
|
|
484
|
+
var condOr_1 = [];
|
|
485
|
+
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
486
|
+
if (field.field) {
|
|
487
|
+
condOr_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), null] });
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
condOr_1.push({ $eq: [field.value, null] });
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
494
|
+
if (field.field) {
|
|
495
|
+
custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $or: condOr_1 }, then: 0, else: '$' + field.field.replace(/\.\$/g, '') } });
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $or: condOr_1 }, then: 0, else: field.value } });
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
query_1.push({ $addFields: custFieldGroup });
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
fieldsTotal.forEach(function (total) {
|
|
506
|
+
customFields.forEach(function (field) {
|
|
507
|
+
var _a;
|
|
508
|
+
query_1.push({ $addFields: (_a = {}, _a[total.id + '_' + field.selFieldId] = '$' + field.selFieldId, _a) });
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
queryMatchConditionLookup_1 = {
|
|
512
|
+
$and: []
|
|
513
|
+
};
|
|
514
|
+
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) {
|
|
515
|
+
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) {
|
|
516
|
+
queryMatchConditionLookup_1['$and'].push(filter);
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
filterArrays.forEach(function (filter) {
|
|
520
|
+
queryMatchConditionLookup_1['$and'].push(filter);
|
|
521
|
+
});
|
|
522
|
+
if (queryMatchConditionLookup_1.$and.length) {
|
|
523
|
+
query_1.push({ $match: queryMatchConditionLookup_1 });
|
|
524
|
+
}
|
|
525
|
+
queryGroup_1 = {
|
|
526
|
+
_id: {}
|
|
527
|
+
};
|
|
528
|
+
if (groupsRow.length || !displayType || displayType === 'grouped') {
|
|
529
|
+
if (!groupsRow.length) {
|
|
530
|
+
queryGroup_1._id = '$_id';
|
|
531
|
+
}
|
|
532
|
+
groupsRow.forEach(function (row) {
|
|
533
|
+
queryGroup_1._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
534
|
+
if (date_field && date_interval) {
|
|
535
|
+
if (date_interval === 'Daily') {
|
|
536
|
+
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
537
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
538
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
539
|
+
}
|
|
540
|
+
else if (date_interval === 'Weekly') {
|
|
541
|
+
queryGroup_1._id['week'] = { '$isoWeek': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
542
|
+
queryGroup_1._id['year'] = { '$isoWeekYear': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
543
|
+
}
|
|
544
|
+
else if (date_interval === 'Monthly') {
|
|
545
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
546
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
547
|
+
}
|
|
548
|
+
else if (date_interval === 'Quarterly') {
|
|
549
|
+
queryGroup_1._id['month'] = { '$month': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
550
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
551
|
+
}
|
|
552
|
+
else if (date_interval === 'Yearly') {
|
|
553
|
+
queryGroup_1._id['year'] = { '$year': { 'date': '$' + date_field.replace(/\.\$/g, ''), 'timezone': _this.serverConfig['TIMEZONE'] } };
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
selectedFields.forEach(function (field) {
|
|
558
|
+
if (field.leafValueType === 'Average') {
|
|
559
|
+
queryGroup_1[field.id] = { '$avg': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
560
|
+
}
|
|
561
|
+
else if (field.leafValueType === 'Sum') {
|
|
562
|
+
queryGroup_1[field.id] = { '$sum': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
563
|
+
}
|
|
564
|
+
else if (field.leafValueType === 'Count') {
|
|
565
|
+
if (reportType === 'Dated') {
|
|
566
|
+
queryGroup_1[field.id] = { '$sum': '$count_' + field.fieldPath.replace(/\.\$/g, '') };
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
queryGroup_1[field.id] = { '$push': '$count_' + field.fieldPath.replace(/\.\$/g, '') };
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
else if (field.leafValueType === 'Minimum') {
|
|
573
|
+
queryGroup_1[field.id] = { '$min': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
574
|
+
}
|
|
575
|
+
else if (field.leafValueType === 'Maximum') {
|
|
576
|
+
queryGroup_1[field.id] = { '$max': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
577
|
+
}
|
|
578
|
+
else if (field.leafValueType === 'First' || (!groupsRow.length && (!field.fieldPath.includes('.$') || field.fieldPath.includes('(Lookup)')))) {
|
|
579
|
+
queryGroup_1[field.id] = { '$first': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
580
|
+
}
|
|
581
|
+
else if (field.leafValueType === 'Last') {
|
|
582
|
+
queryGroup_1[field.id] = { '$last': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
583
|
+
}
|
|
584
|
+
else if (field.leafValueType === 'Unique') {
|
|
585
|
+
queryGroup_1[field.id] = { '$addToSet': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
queryGroup_1[field.id] = { '$push': '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
customFields.forEach(function (cust) {
|
|
592
|
+
if (cust.leafValueType === 'Average') {
|
|
593
|
+
queryGroup_1[cust.selFieldId] = { '$avg': '$' + cust.selFieldId };
|
|
594
|
+
}
|
|
595
|
+
else if (cust.leafValueType === 'Sum') {
|
|
596
|
+
queryGroup_1[cust.selFieldId] = { '$sum': '$' + cust.selFieldId };
|
|
597
|
+
}
|
|
598
|
+
else if (cust.leafValueType === 'Count') {
|
|
599
|
+
if (reportType === 'Dated') {
|
|
600
|
+
queryGroup_1[cust.selFieldId] = { '$sum': '$count_' + cust.selFieldId };
|
|
601
|
+
}
|
|
602
|
+
else {
|
|
603
|
+
queryGroup_1[cust.selFieldId] = { '$push': '$count_' + cust.selFieldId };
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
else if (cust.leafValueType === 'Minimum') {
|
|
607
|
+
queryGroup_1[cust.selFieldId] = { '$min': '$' + cust.selFieldId };
|
|
608
|
+
}
|
|
609
|
+
else if (cust.leafValueType === 'Maximum') {
|
|
610
|
+
queryGroup_1[cust.selFieldId] = { '$max': '$' + cust.selFieldId };
|
|
611
|
+
}
|
|
612
|
+
else if (cust.leafValueType === 'First') {
|
|
613
|
+
queryGroup_1[cust.selFieldId] = { '$first': '$' + cust.selFieldId };
|
|
614
|
+
}
|
|
615
|
+
else if (cust.leafValueType === 'Last') {
|
|
616
|
+
queryGroup_1[cust.selFieldId] = { '$last': '$' + cust.selFieldId };
|
|
617
|
+
}
|
|
618
|
+
else if (cust.leafValueType === 'Unique') {
|
|
619
|
+
queryGroup_1[cust.selFieldId] = { '$addToSet': '$' + cust.selFieldId };
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
queryGroup_1[cust.selFieldId] = { '$push': '$' + cust.selFieldId };
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
// Totals
|
|
626
|
+
if (fieldsTotal.length) {
|
|
627
|
+
fieldsTotal.forEach(function (total) {
|
|
628
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
629
|
+
queryGroup_1[total.id + '_' + field.id] = { $sum: '$' + total.id + '_' + field.id };
|
|
630
|
+
});
|
|
631
|
+
customFields.forEach(function (field) {
|
|
632
|
+
queryGroup_1[total.id + '_' + field.selFieldId] = { $sum: '$' + total.id + '_' + field.selFieldId };
|
|
633
|
+
});
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
query_1.push({ $group: queryGroup_1 });
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
queryProjection_1 = {
|
|
640
|
+
_id: 1
|
|
641
|
+
};
|
|
642
|
+
selectedFields.forEach(function (field) {
|
|
643
|
+
if (field.leafValueType === 'Average') {
|
|
644
|
+
queryProjection_1[field.id] = { $avg: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
645
|
+
}
|
|
646
|
+
else if (field.leafValueType === 'Sum') {
|
|
647
|
+
queryProjection_1[field.id] = { $sum: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
648
|
+
}
|
|
649
|
+
else if (field.leafValueType === 'Count') {
|
|
650
|
+
queryProjection_1[field.id] = { $sum: 1 };
|
|
651
|
+
}
|
|
652
|
+
else if (field.leafValueType === 'Minimum') {
|
|
653
|
+
queryProjection_1[field.id] = { $min: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
654
|
+
}
|
|
655
|
+
else if (field.leafValueType === 'Maximum') {
|
|
656
|
+
queryProjection_1[field.id] = { $max: '$' + field.fieldPath.replace(/\.\$/g, '') };
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
queryProjection_1[field.id] = '$' + field.fieldPath.replace(/\.\$/g, '');
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
customFields.forEach(function (cust) {
|
|
663
|
+
if (cust === 'Average') {
|
|
664
|
+
queryProjection_1[cust.selFieldId] = { $avg: '$' + cust.selFieldId };
|
|
665
|
+
}
|
|
666
|
+
else if (cust === 'Sum') {
|
|
667
|
+
queryProjection_1[cust.selFieldId] = { $sum: '$' + cust.selFieldId };
|
|
668
|
+
}
|
|
669
|
+
else if (cust === 'Count') {
|
|
670
|
+
queryProjection_1[cust.selFieldId] = { $sum: 1 };
|
|
671
|
+
}
|
|
672
|
+
else if (cust === 'Minimum') {
|
|
673
|
+
queryProjection_1[cust.selFieldId] = { $min: '$' + cust.selFieldId };
|
|
674
|
+
}
|
|
675
|
+
else if (cust === 'Maximum') {
|
|
676
|
+
queryProjection_1[cust.selFieldId] = { $max: '$' + cust.selFieldId };
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
queryProjection_1[cust.selFieldId] = '$' + cust.selFieldId;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
//Totals
|
|
683
|
+
if (fieldsTotal.length && (reportType === 'List' || reportType === 'Dated')) {
|
|
684
|
+
fieldsTotal.forEach(function (total) {
|
|
685
|
+
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
686
|
+
var _a;
|
|
687
|
+
queryProjection_1[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.id, _a);
|
|
688
|
+
});
|
|
689
|
+
customFields.forEach(function (field) {
|
|
690
|
+
var _a;
|
|
691
|
+
queryProjection_1[total.id + '_' + field.selFieldId] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.selFieldId, _a);
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
query_1.push({ $project: queryProjection_1 });
|
|
696
|
+
}
|
|
697
|
+
// SORT
|
|
698
|
+
if (rootOptions.sort) {
|
|
699
|
+
query_1.push({
|
|
700
|
+
$sort: rootOptions.sort
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
if (reportType === 'Group' && groupsRow.length > 1) {
|
|
704
|
+
_loop_1 = function (i) {
|
|
705
|
+
var _a;
|
|
706
|
+
var projQuery = { _id: 1 };
|
|
707
|
+
projQuery[groupsRow[i].id] = {
|
|
708
|
+
_id: (_a = {}, _a[groupsRow[i].id] = '$_id.' + groupsRow[i].id, _a)
|
|
709
|
+
};
|
|
710
|
+
if (i === groupsRow.length - 1) {
|
|
711
|
+
selectedFields.forEach(function (field) {
|
|
712
|
+
projQuery[groupsRow[i].id][field.id] = '$' + field.id;
|
|
713
|
+
});
|
|
714
|
+
customFields.forEach(function (field) {
|
|
715
|
+
projQuery[groupsRow[i].id][field.selFieldId] = '$' + field.selFieldId;
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
else {
|
|
719
|
+
projQuery[groupsRow[i].id][groupsRow[i + 1].id] = '$' + groupsRow[i + 1].id;
|
|
720
|
+
}
|
|
721
|
+
fieldsTotal.forEach(function (totField) {
|
|
722
|
+
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
723
|
+
projQuery[totField.id + '_' + selField.id] = 1;
|
|
724
|
+
projQuery[groupsRow[i].id][totField.id + '_' + selField.id] = '$' + totField.id + '_' + selField.id;
|
|
725
|
+
});
|
|
726
|
+
customFields.forEach(function (field) {
|
|
727
|
+
projQuery[groupsRow[i].id][totField.id + '_' + field.selFieldId] = '$' + totField.id + '_' + field.selFieldId;
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
query_1.push({ $project: projQuery });
|
|
731
|
+
var grQuery = {
|
|
732
|
+
_id: {}
|
|
733
|
+
};
|
|
734
|
+
for (var j = 0; j < i; j++) {
|
|
735
|
+
grQuery._id[groupsRow[j].id] = '$_id.' + groupsRow[j].id;
|
|
736
|
+
}
|
|
737
|
+
grQuery[groupsRow[i].id] = {
|
|
738
|
+
$push: '$' + groupsRow[i].id
|
|
739
|
+
};
|
|
740
|
+
fieldsTotal.forEach(function (totField) {
|
|
741
|
+
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
742
|
+
var _a;
|
|
743
|
+
grQuery[totField.id + '_' + selField.id] = (_a = {}, _a['$' + totField.type] = '$' + totField.id + '_' + selField.id, _a);
|
|
744
|
+
});
|
|
745
|
+
customFields.forEach(function (field) {
|
|
746
|
+
var _a;
|
|
747
|
+
grQuery[totField.id + '_' + field.selFieldId] = (_a = {}, _a['$' + totField.type] = '$' + totField.id + '_' + field.selFieldId, _a);
|
|
748
|
+
});
|
|
749
|
+
});
|
|
750
|
+
query_1.push({ $group: grQuery });
|
|
751
|
+
if (rootOptions.sort) {
|
|
752
|
+
var sortKeys_1 = Object.keys(rootOptions.sort);
|
|
753
|
+
var sort_1 = {};
|
|
754
|
+
var groupString_1 = '';
|
|
755
|
+
groupsRow.forEach(function (row, groupIndex) {
|
|
756
|
+
if (groupIndex > 0) {
|
|
757
|
+
groupString_1 += 'gr_' + (groupIndex + 1) + '.';
|
|
758
|
+
}
|
|
759
|
+
if (sortKeys_1.includes('_id.gr_' + (groupIndex + 1))) {
|
|
760
|
+
sort_1[groupString_1 + '_id.gr_' + (groupIndex + 1)] = rootOptions.sort['_id.gr_' + (groupIndex + 1)];
|
|
761
|
+
}
|
|
762
|
+
else {
|
|
763
|
+
sort_1[groupString_1 + '_id.gr_' + (groupIndex + 1)] = 1;
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
sortKeys_1.filter(function (a) { return !a.startsWith('_id.gr_'); }).forEach(function (key) {
|
|
767
|
+
sort_1[groupString_1 + key] = rootOptions.sort[key];
|
|
768
|
+
});
|
|
769
|
+
query_1.push({ $sort: sort_1 });
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
for (i = groupsRow.length - 1; i >= 1; i--) {
|
|
773
|
+
_loop_1(i);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
res_1 = null;
|
|
777
|
+
_a.label = 2;
|
|
778
|
+
case 2:
|
|
779
|
+
_a.trys.push([2, 4, , 5]);
|
|
780
|
+
return [4 /*yield*/, modelCollection.aggregate(query_1, { allowDiskUse: true, readPreference: 'secondary' })];
|
|
781
|
+
case 3:
|
|
782
|
+
res_1 = _a.sent();
|
|
783
|
+
return [3 /*break*/, 5];
|
|
784
|
+
case 4:
|
|
785
|
+
err_1 = _a.sent();
|
|
786
|
+
console.log(err_1);
|
|
787
|
+
return [3 /*break*/, 5];
|
|
788
|
+
case 5:
|
|
789
|
+
tmpTotals_1 = {};
|
|
790
|
+
if (res_1) {
|
|
791
|
+
fieldsTotal.forEach(function (totField) {
|
|
792
|
+
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
793
|
+
if (totField.type === 'sum') {
|
|
794
|
+
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);
|
|
795
|
+
}
|
|
796
|
+
else if (totField.type === 'avg') {
|
|
797
|
+
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);
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
customFields.forEach(function (custField) {
|
|
801
|
+
if (totField.type === 'sum') {
|
|
802
|
+
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);
|
|
803
|
+
}
|
|
804
|
+
else if (totField.type === 'avg') {
|
|
805
|
+
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);
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
tmpRes = [{
|
|
811
|
+
count: res_1 ? res_1.length : 0,
|
|
812
|
+
results: res_1 ? (rootOptions.limit ? res_1.splice(0, rootOptions.limit) : res_1) : [],
|
|
813
|
+
totals: tmpTotals_1
|
|
814
|
+
}];
|
|
815
|
+
resolve(tmpRes);
|
|
816
|
+
_a.label = 6;
|
|
817
|
+
case 6: return [2 /*return*/];
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
}); });
|
|
821
|
+
},
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
exports.loadReportBuilderMethods = loadReportBuilderMethods;
|
|
826
|
+
|
|
2
827
|
//# sourceMappingURL=report-builder.js.map
|