Built motion from commit f861bcb808219e66da88ba48b61bddb35224a65e. Version 3.0.0...
[motion-next.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
1 'use strict';const a6_0x2550=['clone','preview','keyBy','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','info','MetricId','@mysqldb','csv','rawAttributes','index','DATE(%s)','cdr','COUNT(*)','417421yJDaPu','sort','field','endDate','IS\x20EMPTY','2217uaCRnn','json','SUM(%s)','16KxlYBw','lodash','IS\x20NULL','Reports','groupBy','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','end','COUNT(DISTINCT\x20%s)','key','SEC_TO_TIME(%s)','AnalyticCustomReport','metric','function','value','debug','49521tXiiJN','where','type','catch','userProfileId','model','Unable\x20to\x20retrieve\x20the\x20current\x20user','then','set','select','filters','pick','table','attributes','alias','output','update','from','GROUP_CONCAT(%s)','status','AnalyticMetric','AVG(%s)','67vTsVAF','merge','limit','sequelize','Limited\x20Query:','getFields','randomstring','right_join','group','name','rows','SELECT','DESC','include','fullPath','operator','path','HOUR(%s)','error','generate','UserProfileSection','toString','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','left_join','includeAll','format','1867hyChRW','stack','.calldate\x20BETWEEN\x20?\x20AND\x20?','role','runReport','IS\x20NOT\x20EMPTY','%s.%s\x20=\x20%s.%s','AnalyticExtractedReport','cross_join','savename','389109LHWLgY','query','@components/parsers/qs','5FQAiId','conditions','CustomReports','fieldName','util','IS\x20NOT\x20NULL','send','params','show','user','Content-Range','foreignKey','@components/export/fork-export-process','destroy','289bGcGyS','orderBy','joins','replace','squel','length','UserProfileResource','MAX(%s)','map','count','options','undefined','parse','join','extname','COUNT(%s)','@utils/filter-attributes','keys','body','UNIX_TIMESTAMP(%s)','Run\x20Query:','files/reports','get','MIN(%s)','rules','32213gtRrRP','ROUND(%s)','foreignTable','order','autoAssociation','custom','109gwYjpT','findAll','includes','Please\x20insert\x20at\x20least\x20one\x20field','5pdfJiq','offset','QueryTypes','intersection','startDate','condition','parentKey','findOne','create'];const a6_0x2d06=function(_0x32194a,_0xca701c){_0x32194a=_0x32194a-0x156;let _0x255023=a6_0x2550[_0x32194a];return _0x255023;};const a6_0x2a5e75=a6_0x2d06;(function(_0x16b194,_0xdc7461){const _0x2a423b=a6_0x2d06;while(!![]){try{const _0x2979bc=parseInt(_0x2a423b(0x1cd))+parseInt(_0x2a423b(0x166))*parseInt(_0x2a423b(0x15c))+parseInt(_0x2a423b(0x162))*-parseInt(_0x2a423b(0x181))+-parseInt(_0x2a423b(0x1c3))*parseInt(_0x2a423b(0x184))+parseInt(_0x2a423b(0x17c))+parseInt(_0x2a423b(0x1de))*-parseInt(_0x2a423b(0x1a9))+parseInt(_0x2a423b(0x1d0))*-parseInt(_0x2a423b(0x193));if(_0x2979bc===_0xdc7461)break;else _0x16b194['push'](_0x16b194['shift']());}catch(_0x5ad825){_0x16b194['push'](_0x16b194['shift']());}}}(a6_0x2550,0x68c2e));const util=require(a6_0x2a5e75(0x1d4)),path=require(a6_0x2a5e75(0x1b9)),_=require(a6_0x2a5e75(0x185)),squel=require(a6_0x2a5e75(0x1e2)),qs=require(a6_0x2a5e75(0x1cf)),logger=require('@config/logger')('api'),{db,dbH}=require(a6_0x2a5e75(0x175)),{ValidationError,ValidationErrorItem,QueryTypes}=require('sequelize'),{filterAttributes}=require(a6_0x2a5e75(0x1ee)),{forkExportProcess}=require(a6_0x2a5e75(0x1dc));function respondWithResult(_0x111edc,_0x1be8bd){return _0x1be8bd=_0x1be8bd||0xc8,function(_0x4525a0){const _0x31656e=a6_0x2d06;if(_0x4525a0)return _0x111edc['status'](_0x1be8bd)[_0x31656e(0x182)](_0x4525a0);};}function respondWithFilteredResult(_0x17abe1,_0x5b324d){return function(_0x28ae02){const _0x148e42=a6_0x2d06;if(_0x28ae02){const _0x2a8826=_0x28ae02[_0x148e42(0x1e7)],_0x539b45=_0x5b324d[_0x148e42(0x167)];let _0x4ce0e3=_0x5b324d[_0x148e42(0x167)]+_0x5b324d['limit'],_0x56d2b7;return _0x4ce0e3>=_0x2a8826?(_0x4ce0e3=_0x2a8826,_0x56d2b7=0xc8):_0x56d2b7=0xce,_0x17abe1[_0x148e42(0x1a6)](_0x56d2b7),_0x17abe1[_0x148e42(0x19b)](_0x148e42(0x1da),_0x539b45+'-'+_0x4ce0e3+'/'+_0x2a8826)[_0x148e42(0x182)](_0x28ae02);}return null;};}function saveUpdates(_0x42082b){return function(_0x56c836){if(_0x56c836)return _0x56c836['update'](_0x42082b)['then'](function(_0x2966e0){return _0x2966e0;});return null;};}function removeEntity(_0x32f849){return function(_0x57cbc4){const _0x13c0d9=a6_0x2d06;if(_0x57cbc4)return _0x57cbc4[_0x13c0d9(0x1dd)]()[_0x13c0d9(0x19a)](function(){const _0x3af573=_0x13c0d9,_0x15690d=_0x57cbc4[_0x3af573(0x159)]({'plain':!![]}),_0x14c91d=_0x3af573(0x1d2);return db['UserProfileResource'][_0x3af573(0x1dd)]({'where':{'type':_0x14c91d,'resourceId':_0x15690d['id']}})[_0x3af573(0x19a)](function(){return _0x57cbc4;});})[_0x13c0d9(0x19a)](function(){const _0xfa16ff=_0x13c0d9;_0x32f849[_0xfa16ff(0x1a6)](0xcc)[_0xfa16ff(0x18a)]();});};}function handleEntityNotFound(_0x47f7e4){return function(_0x13f8bf){return!_0x13f8bf&&_0x47f7e4['sendStatus'](0x194),_0x13f8bf;};}function handleError(_0x34968f,_0x173f09){return function(_0x71c992){const _0x156a39=a6_0x2d06;logger[_0x156a39(0x1bb)](_0x71c992[_0x156a39(0x1c4)]);const _0x1172ec=_0x71c992 instanceof ValidationError||_0x71c992 instanceof ValidationErrorItem,_0x352c97=_0x173f09?_0x173f09:_0x1172ec?0x190:0x1f4;_0x71c992['name']&&delete _0x71c992[_0x156a39(0x1b2)],_0x34968f[_0x156a39(0x1a6)](_0x352c97)[_0x156a39(0x1d6)](_0x71c992);};}exports[a6_0x2a5e75(0x178)]=function(_0x265dc4,_0x2e19db){const _0x34ee21=a6_0x2a5e75;let _0xece760={};const _0x2547a0={},_0x297a2b={'count':0x0,'rows':[]},_0x2330c2=_['map'](db['AnalyticCustomReport']['rawAttributes'],function(_0x48faf0){const _0x577859=a6_0x2d06;return{'name':_0x48faf0[_0x577859(0x1d3)],'type':_0x48faf0[_0x577859(0x195)][_0x577859(0x18c)]};});_0x2547a0[_0x34ee21(0x198)]=_[_0x34ee21(0x1e6)](_0x2330c2,_0x34ee21(0x1b2)),_0x2547a0[_0x34ee21(0x1ce)]=_[_0x34ee21(0x1ef)](_0x265dc4[_0x34ee21(0x1ce)]),_0x2547a0['filters']=_[_0x34ee21(0x169)](_0x2547a0[_0x34ee21(0x198)],_0x2547a0['query']),_0xece760[_0x34ee21(0x1a0)]=_[_0x34ee21(0x169)](_0x2547a0[_0x34ee21(0x198)],qs['fields'](_0x265dc4[_0x34ee21(0x1ce)]['fields'])),_0xece760['attributes']=_0xece760[_0x34ee21(0x1a0)]['length']?_0xece760[_0x34ee21(0x1a0)]:_0x2547a0[_0x34ee21(0x198)];typeof _0x265dc4[_0x34ee21(0x1ce)]['nolimit']===_0x34ee21(0x1e9)&&(_0xece760[_0x34ee21(0x1ab)]=qs['limit'](_0x265dc4[_0x34ee21(0x1ce)][_0x34ee21(0x1ab)]),_0xece760['offset']=qs[_0x34ee21(0x167)](_0x265dc4[_0x34ee21(0x1ce)][_0x34ee21(0x167)]));_0xece760[_0x34ee21(0x15f)]=qs[_0x34ee21(0x17d)](_0x265dc4[_0x34ee21(0x1ce)][_0x34ee21(0x17d)]),_0xece760[_0x34ee21(0x194)]=qs[_0x34ee21(0x19d)](_[_0x34ee21(0x19e)](_0x265dc4[_0x34ee21(0x1ce)],_0x2547a0['filters']),_0x2330c2),_0xece760=filterAttributes(_0xece760,_0x265dc4[_0x34ee21(0x1ce)]['filter'],_0x2330c2,_0x265dc4[_0x34ee21(0x1e8)]);const _0x4aec15={'where':_0xece760[_0x34ee21(0x194)]};return db[_0x34ee21(0x18e)][_0x34ee21(0x1e7)](_0x4aec15)[_0x34ee21(0x19a)](function(_0x3dbcc4){const _0x16521f=_0x34ee21;return _0x297a2b[_0x16521f(0x1e7)]=_0x3dbcc4,_0x265dc4['query'][_0x16521f(0x1c1)]&&(_0xece760[_0x16521f(0x1b6)]=[{'all':!![]}]),db[_0x16521f(0x18e)][_0x16521f(0x163)](_0xece760);})[_0x34ee21(0x19a)](function(_0x22c53d){const _0x1a79e9=_0x34ee21;return _0x297a2b[_0x1a79e9(0x1b3)]=_0x22c53d,_0x297a2b;})['then'](respondWithFilteredResult(_0x2e19db,_0xece760))[_0x34ee21(0x196)](handleError(_0x2e19db,null));},exports[a6_0x2a5e75(0x1d8)]=function(_0x292a84,_0x595f56){const _0xe188d0=a6_0x2a5e75;let _0x236071={'raw':![],'where':{'id':_0x292a84[_0xe188d0(0x1d7)]['id']}};const _0x1061f3={};return _0x1061f3['model']=_[_0xe188d0(0x1ef)](db['AnalyticCustomReport'][_0xe188d0(0x177)]),_0x1061f3[_0xe188d0(0x1ce)]=_[_0xe188d0(0x1ef)](_0x292a84[_0xe188d0(0x1ce)]),_0x1061f3['filters']=_[_0xe188d0(0x169)](_0x1061f3[_0xe188d0(0x198)],_0x1061f3['query']),_0x236071[_0xe188d0(0x1a0)]=_[_0xe188d0(0x169)](_0x1061f3[_0xe188d0(0x198)],qs['fields'](_0x292a84[_0xe188d0(0x1ce)]['fields'])),_0x236071[_0xe188d0(0x1a0)]=_0x236071[_0xe188d0(0x1a0)][_0xe188d0(0x1e3)]?_0x236071['attributes']:_0x1061f3[_0xe188d0(0x198)],_0x292a84[_0xe188d0(0x1ce)]['includeAll']&&(_0x236071[_0xe188d0(0x1b6)]=[{'all':!![]}]),_0x236071=_[_0xe188d0(0x1aa)]({},_0x236071,_0x292a84[_0xe188d0(0x1e8)]),db[_0xe188d0(0x18e)][_0xe188d0(0x16d)](_0x236071)[_0xe188d0(0x19a)](handleEntityNotFound(_0x595f56,null))[_0xe188d0(0x19a)](respondWithResult(_0x595f56,null))[_0xe188d0(0x196)](handleError(_0x595f56,null));},exports[a6_0x2a5e75(0x16e)]=function(_0x5f97ac,_0x175172){const _0x19a246=a6_0x2a5e75;return db['AnalyticCustomReport'][_0x19a246(0x16e)](_0x5f97ac['body'],{})[_0x19a246(0x19a)](function(_0x314a1e){const _0x4ca8d8=_0x19a246,_0x42ae8e=_0x5f97ac[_0x4ca8d8(0x1d9)]['get']({'plain':!![]});if(!_0x42ae8e)throw new Error(_0x4ca8d8(0x199));if(_0x42ae8e[_0x4ca8d8(0x1c6)]===_0x4ca8d8(0x1d9)){const _0x4a8999=_0x314a1e[_0x4ca8d8(0x159)]({'plain':!![]}),_0x27a397=_0x4ca8d8(0x187);return db[_0x4ca8d8(0x1bd)]['findOne']({'where':{'name':_0x27a397,'userProfileId':_0x42ae8e[_0x4ca8d8(0x197)]},'raw':!![]})['then'](function(_0x5ca9b5){const _0x42baa0=_0x4ca8d8;return _0x5ca9b5&&_0x5ca9b5[_0x42baa0(0x160)]===0x0?db[_0x42baa0(0x1e4)]['create']({'name':_0x4a8999[_0x42baa0(0x1b2)],'resourceId':_0x4a8999['id'],'type':'CustomReports','sectionId':_0x5ca9b5['id']},{})['then'](function(){return _0x314a1e;}):_0x314a1e;})[_0x4ca8d8(0x196)](function(_0x1c6071){const _0x4e58c0=_0x4ca8d8;logger[_0x4e58c0(0x1bb)](_0x4e58c0(0x189),_0x1c6071);throw _0x1c6071;});}return _0x314a1e;})[_0x19a246(0x19a)](respondWithResult(_0x175172,0xc9))['catch'](handleError(_0x175172,null));},exports[a6_0x2a5e75(0x1a3)]=function(_0x57f5d6,_0x2feff1){const _0x4fe655=a6_0x2a5e75;return _0x57f5d6[_0x4fe655(0x1f0)]['id']&&delete _0x57f5d6[_0x4fe655(0x1f0)]['id'],db[_0x4fe655(0x18e)][_0x4fe655(0x16d)]({'where':{'id':_0x57f5d6[_0x4fe655(0x1d7)]['id']}})[_0x4fe655(0x19a)](handleEntityNotFound(_0x2feff1,null))[_0x4fe655(0x19a)](saveUpdates(_0x57f5d6[_0x4fe655(0x1f0)],null))[_0x4fe655(0x19a)](respondWithResult(_0x2feff1,null))[_0x4fe655(0x196)](handleError(_0x2feff1,null));},exports['destroy']=function(_0x6ce836,_0x45a0d9){const _0x1c2cac=a6_0x2a5e75;return db['AnalyticCustomReport'][_0x1c2cac(0x16d)]({'where':{'id':_0x6ce836[_0x1c2cac(0x1d7)]['id']}})['then'](handleEntityNotFound(_0x45a0d9,null))['then'](removeEntity(_0x45a0d9,null))[_0x1c2cac(0x196)](handleError(_0x45a0d9,null));},exports[a6_0x2a5e75(0x170)]=function(_0x2b0b0e,_0x5d98b5){const _0x23ffba=a6_0x2a5e75,_0x17579a=0xa,_0x3d0519=['join','left_join',_0x23ffba(0x1b0),_0x23ffba(0x1cb)],_0x29eeff={'SUM':_0x23ffba(0x183),'COUNT':'COUNT(%s)','COUNT\x20DISTINCT':_0x23ffba(0x18b),'MAX':_0x23ffba(0x1e5),'MIN':_0x23ffba(0x15a),'AVG':_0x23ffba(0x1a8),'GROUP_CONCAT':_0x23ffba(0x1a5),'GROUP_CONCAT\x20ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT\x20DESC':_0x23ffba(0x172)},_0x37ba03={'SEC_TO_TIME':_0x23ffba(0x18d),'DATE':'DATE(%s)','HOUR':_0x23ffba(0x1ba),'ROUND':_0x23ffba(0x15d),'UNIX_TIMESTAMP':_0x23ffba(0x156)},_0x5ccac7=function(_0xe6b420){const _0x3697c2=_0x23ffba;return!_['includes']([_0x3697c2(0x186),_0x3697c2(0x1d5),_0x3697c2(0x180),_0x3697c2(0x1c8)],_0xe6b420);},_0xe40250=function(_0x4479e5){const _0x3d6190=_0x23ffba;if(!_0x4479e5||!_0x4479e5[_0x3d6190(0x15b)][_0x3d6190(0x1e3)])return'';let _0xd204a4='(';for(let _0x5d237a=0x0;_0x5d237a<_0x4479e5['rules']['length'];_0x5d237a+=0x1){_0x5d237a>0x0&&(_0xd204a4+='\x20'+_0x4479e5[_0x3d6190(0x1b8)]+'\x20'),_0xd204a4+=_0x4479e5[_0x3d6190(0x15b)][_0x5d237a]['group']?_0xe40250(_0x4479e5[_0x3d6190(0x15b)][_0x5d237a][_0x3d6190(0x1b1)]):_0x4479e5[_0x3d6190(0x15b)][_0x5d237a][_0x3d6190(0x17e)]+'\x20'+_0x4479e5['rules'][_0x5d237a]['condition']+(_0x5ccac7(_0x4479e5['rules'][_0x5d237a]['condition'])?'\x20'+_0x4479e5['rules'][_0x5d237a]['value']:'');}return _0xd204a4+')';};let _0x44de4c={'where':{'id':_0x2b0b0e[_0x23ffba(0x1d7)]['id']}},_0x1a0b1b,_0x5c35f0,_0x406238;return _0x44de4c=_[_0x23ffba(0x1aa)]({},_0x44de4c,_0x2b0b0e[_0x23ffba(0x1e8)]),db[_0x23ffba(0x18e)][_0x23ffba(0x16d)](_0x44de4c)[_0x23ffba(0x19a)](function(_0x2fb5c6){const _0x346bdf=_0x23ffba;if(_0x2fb5c6)return _0x1a0b1b=_0x2fb5c6,_0x2fb5c6[_0x346bdf(0x1ae)]();return null;})[_0x23ffba(0x19a)](function(_0x147874){const _0x3693c1=_0x23ffba;if(_0x147874){if(!_0x147874[_0x3693c1(0x1e3)])throw new ValidationErrorItem(_0x3693c1(0x165),0x193);return _0x5c35f0=_0x147874,db[_0x3693c1(0x1a7)]['findAll']({'raw':!![]});}return null;})['then'](function(_0x3bd95e){const _0x2d061b=_0x23ffba;if(_0x3bd95e){_0x406238=_['keyBy'](_0x3bd95e,'id');let _0x1ff748;const _0x2a0cb4=squel[_0x2d061b(0x19c)]();_0x2a0cb4[_0x2d061b(0x1a4)](_0x1a0b1b[_0x2d061b(0x19f)]);for(let _0x94d9f8=0x0;_0x94d9f8<_0x5c35f0[_0x2d061b(0x1e3)];_0x94d9f8+=0x1){_0x1ff748=_0x5c35f0[_0x94d9f8][_0x2d061b(0x174)]?_0x406238[_0x5c35f0[_0x94d9f8][_0x2d061b(0x174)]][_0x2d061b(0x18f)]:_0x5c35f0[_0x94d9f8]['field'],_0x1ff748=_0x5c35f0[_0x94d9f8][_0x2d061b(0x190)]?_[_0x2d061b(0x1e1)](_0x29eeff[_0x5c35f0[_0x94d9f8][_0x2d061b(0x190)]],'%s',_0x1ff748):_0x1ff748,_0x1ff748=_0x5c35f0[_0x94d9f8]['format']?_[_0x2d061b(0x1e1)](_0x37ba03[_0x5c35f0[_0x94d9f8][_0x2d061b(0x1c2)]],'%s',_0x1ff748):_0x1ff748,_0x5c35f0[_0x94d9f8][_0x2d061b(0x188)]&&_0x2a0cb4[_0x2d061b(0x1b1)](_0x1ff748),_0x5c35f0[_0x94d9f8][_0x2d061b(0x1df)]&&_0x2a0cb4[_0x2d061b(0x15f)](_0x1ff748,_0x5c35f0[_0x94d9f8][_0x2d061b(0x1df)]===_0x2d061b(0x1b5)?![]:!![]),_0x2a0cb4[_0x2d061b(0x17e)](_0x1ff748,_0x5c35f0[_0x94d9f8][_0x2d061b(0x1a1)]||_0x1ff748);}if(_0x1a0b1b[_0x2d061b(0x1e0)]){_0x1a0b1b['joins']=JSON['parse'](_0x1a0b1b['joins']);for(let _0x3d9dac=0x0;_0x3d9dac<_0x1a0b1b[_0x2d061b(0x1e0)]['length'];_0x3d9dac+=0x1){_0x1a0b1b[_0x2d061b(0x1e0)][_0x3d9dac]['type']&&_[_0x2d061b(0x164)](_0x3d0519,_0x1a0b1b[_0x2d061b(0x1e0)][_0x3d9dac][_0x2d061b(0x195)])&&_0x1a0b1b['joins'][_0x3d9dac]['parentKey']&&_0x1a0b1b[_0x2d061b(0x1e0)][_0x3d9dac][_0x2d061b(0x15e)]&&_0x1a0b1b[_0x2d061b(0x1e0)][_0x3d9dac][_0x2d061b(0x1db)]&&_0x2a0cb4[_0x1a0b1b['joins'][_0x3d9dac][_0x2d061b(0x195)]](_0x1a0b1b[_0x2d061b(0x1e0)][_0x3d9dac][_0x2d061b(0x15e)],null,util[_0x2d061b(0x1c2)](_0x2d061b(0x1c9),_0x1a0b1b[_0x2d061b(0x19f)],_0x1a0b1b[_0x2d061b(0x1e0)][_0x3d9dac][_0x2d061b(0x16c)],_0x1a0b1b['joins'][_0x3d9dac][_0x2d061b(0x15e)],_0x1a0b1b[_0x2d061b(0x1e0)][_0x3d9dac][_0x2d061b(0x1db)]));}}return _0x1a0b1b['conditions']&&(_0x1a0b1b['conditions']=JSON['parse'](_0x1a0b1b[_0x2d061b(0x1d1)]),_0x2a0cb4[_0x2d061b(0x194)](_0xe40250(_0x1a0b1b[_0x2d061b(0x1d1)][_0x2d061b(0x1b1)]))),_0x2a0cb4[_0x2d061b(0x1ab)](_0x17579a),_0x2a0cb4[_0x2d061b(0x167)](0x0),logger['debug'](_0x2d061b(0x1ad),_0x2a0cb4[_0x2d061b(0x1be)]()),dbH[_0x2d061b(0x1ac)][_0x2d061b(0x1ce)](_0x2a0cb4[_0x2d061b(0x1be)](),{'type':QueryTypes[_0x2d061b(0x1b4)]});}})['then'](respondWithResult(_0x5d98b5,null))[_0x23ffba(0x196)](handleError(_0x5d98b5,null));};function runReport(_0x570f24,_0x59c9f9,_0x49c0e4){const _0x41f91c=a6_0x2a5e75,_0x5d9c70=_0x59c9f9[_0x41f91c(0x1b2)],_0x19893f=0xa,_0x2ca07a=[_0x41f91c(0x1eb),_0x41f91c(0x1c0),'right_join','cross_join'],_0x363c3c={'SUM':'SUM(%s)','COUNT':_0x41f91c(0x1ed),'COUNT\x20DISTINCT':_0x41f91c(0x18b),'MAX':'MAX(%s)','MIN':_0x41f91c(0x15a),'AVG':_0x41f91c(0x1a8),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT\x20ASC':_0x41f91c(0x1bf),'GROUP_CONCAT\x20DESC':_0x41f91c(0x172)},_0x5ea523={'SEC_TO_TIME':_0x41f91c(0x18d),'DATE':'DATE(%s)','HOUR':'HOUR(%s)','ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x41f91c(0x156)},_0x537a07=function(_0x39abfd){const _0x1be673=_0x41f91c;return!_[_0x1be673(0x164)]([_0x1be673(0x186),_0x1be673(0x1d5),_0x1be673(0x180),_0x1be673(0x1c8)],_0x39abfd);},_0x25a480=function(_0x46292b){const _0x3bf479=_0x41f91c;if(!_0x46292b||!_0x46292b[_0x3bf479(0x15b)][_0x3bf479(0x1e3)])return'';let _0x35d0fe='(';for(let _0x384b57=0x0;_0x384b57<_0x46292b[_0x3bf479(0x15b)][_0x3bf479(0x1e3)];_0x384b57+=0x1){_0x384b57>0x0&&(_0x35d0fe+='\x20'+_0x46292b[_0x3bf479(0x1b8)]+'\x20'),_0x35d0fe+=_0x46292b['rules'][_0x384b57][_0x3bf479(0x1b1)]?_0x25a480(_0x46292b['rules'][_0x384b57][_0x3bf479(0x1b1)]):_0x46292b['rules'][_0x384b57][_0x3bf479(0x17e)]+'\x20'+_0x46292b['rules'][_0x384b57][_0x3bf479(0x16b)]+(_0x537a07(_0x46292b['rules'][_0x384b57]['condition'])?'\x20'+_0x46292b[_0x3bf479(0x15b)][_0x384b57][_0x3bf479(0x191)]:'');}return _0x35d0fe+')';};let _0x230efe={'where':{'id':_0x570f24['id']}},_0x78a0a0,_0x555d2d,_0x2a6b10,_0x436b92,_0x4155ae;return _0x230efe=_[_0x41f91c(0x1aa)]({},_0x230efe,_0x49c0e4),db[_0x41f91c(0x18e)]['findOne'](_0x230efe)[_0x41f91c(0x19a)](function(_0x47cf14){if(_0x47cf14)return _0x78a0a0=_0x47cf14,_0x47cf14['getFields']();return null;})[_0x41f91c(0x19a)](function(_0x49279f){const _0x1f0d1e=_0x41f91c;if(_0x49279f){if(!_0x49279f[_0x1f0d1e(0x1e3)])throw new ValidationErrorItem(_0x1f0d1e(0x165),0x193);return _0x555d2d=_0x49279f,db[_0x1f0d1e(0x1a7)][_0x1f0d1e(0x163)]({'raw':!![]});}return null;})[_0x41f91c(0x19a)](function(_0x7e3ab){const _0x51b6d8=_0x41f91c;if(_0x7e3ab){_0x2a6b10=_[_0x51b6d8(0x171)](_0x7e3ab,'id');let _0x3b0b87;const _0xd594a2=squel[_0x51b6d8(0x19c)]();_0xd594a2['from'](_0x78a0a0[_0x51b6d8(0x19f)]);for(let _0x5b9b98=0x0;_0x5b9b98<_0x555d2d[_0x51b6d8(0x1e3)];_0x5b9b98+=0x1){_0x3b0b87=_0x555d2d[_0x5b9b98][_0x51b6d8(0x174)]?_0x2a6b10[_0x555d2d[_0x5b9b98]['MetricId']][_0x51b6d8(0x18f)]:_0x555d2d[_0x5b9b98]['field'],_0x3b0b87=_0x555d2d[_0x5b9b98][_0x51b6d8(0x190)]?_[_0x51b6d8(0x1e1)](_0x363c3c[_0x555d2d[_0x5b9b98][_0x51b6d8(0x190)]],'%s',_0x3b0b87):_0x3b0b87,_0x3b0b87=_0x555d2d[_0x5b9b98][_0x51b6d8(0x1c2)]?_['replace'](_0x5ea523[_0x555d2d[_0x5b9b98][_0x51b6d8(0x1c2)]],'%s',_0x3b0b87):_0x3b0b87,_0x555d2d[_0x5b9b98][_0x51b6d8(0x188)]&&_0xd594a2[_0x51b6d8(0x1b1)](_0x3b0b87),_0x555d2d[_0x5b9b98][_0x51b6d8(0x1df)]&&_0xd594a2[_0x51b6d8(0x15f)](_0x3b0b87,_0x555d2d[_0x5b9b98][_0x51b6d8(0x1df)]==='DESC'?![]:!![]),_0xd594a2[_0x51b6d8(0x17e)](_0x3b0b87,_0x555d2d[_0x5b9b98]['alias']||_0x3b0b87);}if(_0x78a0a0['joins']){_0x78a0a0['joins']=JSON[_0x51b6d8(0x1ea)](_0x78a0a0[_0x51b6d8(0x1e0)]);for(let _0x4f0612=0x0;_0x4f0612<_0x78a0a0[_0x51b6d8(0x1e0)][_0x51b6d8(0x1e3)];_0x4f0612+=0x1){_0x78a0a0['joins'][_0x4f0612][_0x51b6d8(0x195)]&&_['includes'](_0x2ca07a,_0x78a0a0[_0x51b6d8(0x1e0)][_0x4f0612][_0x51b6d8(0x195)])&&_0x78a0a0[_0x51b6d8(0x1e0)][_0x4f0612][_0x51b6d8(0x16c)]&&_0x78a0a0[_0x51b6d8(0x1e0)][_0x4f0612][_0x51b6d8(0x15e)]&&_0x78a0a0[_0x51b6d8(0x1e0)][_0x4f0612][_0x51b6d8(0x1db)]&&_0xd594a2[_0x78a0a0[_0x51b6d8(0x1e0)][_0x4f0612]['type']](_0x78a0a0[_0x51b6d8(0x1e0)][_0x4f0612]['foreignTable'],null,util[_0x51b6d8(0x1c2)](_0x51b6d8(0x1c9),_0x78a0a0[_0x51b6d8(0x19f)],_0x78a0a0[_0x51b6d8(0x1e0)][_0x4f0612][_0x51b6d8(0x16c)],_0x78a0a0['joins'][_0x4f0612][_0x51b6d8(0x15e)],_0x78a0a0[_0x51b6d8(0x1e0)][_0x4f0612][_0x51b6d8(0x1db)]));}}_0x78a0a0[_0x51b6d8(0x1d1)]&&(_0x78a0a0[_0x51b6d8(0x1d1)]=JSON[_0x51b6d8(0x1ea)](_0x78a0a0[_0x51b6d8(0x1d1)]),_0xd594a2[_0x51b6d8(0x194)](_0x25a480(_0x78a0a0[_0x51b6d8(0x1d1)][_0x51b6d8(0x1b1)])));_0x4155ae=_0xd594a2['clone'](),_0xd594a2[_0x51b6d8(0x1ab)](_0x19893f),_0xd594a2[_0x51b6d8(0x167)](0x0);return;}})['then'](function(){const _0x555275=_0x41f91c;if(_0x59c9f9[_0x555275(0x1a2)]==='web')return null;const _0x35ab70=_[_0x555275(0x1aa)](_0x59c9f9,{'name':_0x59c9f9[_0x555275(0x1b7)]||_0x59c9f9[_0x555275(0x1b2)]||_0x78a0a0['name'],'basename':_0x5d9c70,'savename':util[_0x555275(0x1c2)]('%s-%s.%s',_0x59c9f9['name']||_0x78a0a0['name'],require(_0x555275(0x1af))[_0x555275(0x1bc)](0x4),_0x59c9f9[_0x555275(0x1a2)]||_0x555275(0x176)),'reportId':_0x78a0a0['id'],'reportType':_0x555275(0x161)});return db[_0x555275(0x1ca)][_0x555275(0x16e)](_0x35ab70,{'raw':!![]});})[_0x41f91c(0x19a)](function(_0xb0de10){const _0x540f5a=_0x41f91c;_0x78a0a0[_0x540f5a(0x19f)]===_0x540f5a(0x17a)?_0x4155ae[_0x540f5a(0x194)](_0x78a0a0['table']+_0x540f5a(0x1c5),_0x59c9f9[_0x540f5a(0x16a)],_0x59c9f9[_0x540f5a(0x17f)]):_0x4155ae[_0x540f5a(0x194)](_0x78a0a0[_0x540f5a(0x19f)]+'.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x59c9f9[_0x540f5a(0x16a)],_0x59c9f9['endDate']);if(_0xb0de10){const _0x1c14da=_0x4155ae[_0x540f5a(0x1be)](),_0x8b47f9=path[_0x540f5a(0x1eb)](global['appRoot'],_0x540f5a(0x158),_0xb0de10[_0x540f5a(0x1cc)]),_0x7d1b60=path[_0x540f5a(0x1ec)](_0xb0de10[_0x540f5a(0x1cc)])[_0x540f5a(0x1e1)](/^./,'');return logger[_0x540f5a(0x173)](_0x540f5a(0x157),_0x1c14da),forkExportProcess(_0x7d1b60,_0xb0de10['id'],_0x1c14da,_0x8b47f9,_0x5d9c70),_0xb0de10;}else{const _0x171838=squel[_0x540f5a(0x19c)]();return _0x171838[_0x540f5a(0x1a4)]('('+_0x4155ae[_0x540f5a(0x1be)]()+')','countTable'),_0x171838[_0x540f5a(0x17e)](_0x540f5a(0x17b),_0x540f5a(0x1e7)),_0x4155ae[_0x540f5a(0x1ab)](_0x59c9f9[_0x540f5a(0x1ab)]||_0x19893f),_0x4155ae[_0x540f5a(0x167)](_0x59c9f9[_0x540f5a(0x167)]||0x0),dbH['sequelize'][_0x540f5a(0x1ce)](_0x171838[_0x540f5a(0x1be)](),{'type':dbH['sequelize'][_0x540f5a(0x168)]['SELECT']})[_0x540f5a(0x19a)](function(_0x4c1a45){const _0x3f39d8=_0x540f5a;return!_0x4c1a45[_0x3f39d8(0x1e3)]?_0x436b92=0x0:_0x436b92=_0x4c1a45[0x0][_0x3f39d8(0x1e7)]||0x0,dbH[_0x3f39d8(0x1ac)]['query'](_0x4155ae['toString'](),{'type':dbH['sequelize'][_0x3f39d8(0x168)]['SELECT']});})[_0x540f5a(0x19a)](function(_0x317138){return{'rows':_0x317138||[],'count':_0x436b92};});}});}exports['run']=function(_0x314c9d,_0x227d47){const _0x2623de=a6_0x2a5e75;return runReport(_0x314c9d[_0x2623de(0x1d7)],_0x314c9d[_0x2623de(0x1ce)],_0x314c9d[_0x2623de(0x1e8)])['then'](respondWithResult(_0x227d47,null))[_0x2623de(0x196)](handleError(_0x227d47,null));},exports[a6_0x2a5e75(0x1c7)]=runReport,exports[a6_0x2a5e75(0x1ce)]=function(_0x3ae0f2,_0x22d0ee){const _0x40d8a0=a6_0x2a5e75,_0x4323de=0xa,_0x4e87fb=['join',_0x40d8a0(0x1c0),_0x40d8a0(0x1b0),'cross_join'],_0x5df92={'SUM':_0x40d8a0(0x183),'COUNT':_0x40d8a0(0x1ed),'COUNT\x20DISTINCT':_0x40d8a0(0x18b),'MAX':_0x40d8a0(0x1e5),'MIN':'MIN(%s)','AVG':_0x40d8a0(0x1a8),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT\x20ASC':_0x40d8a0(0x1bf),'GROUP_CONCAT\x20DESC':_0x40d8a0(0x172)},_0x252674={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x40d8a0(0x179),'HOUR':_0x40d8a0(0x1ba),'ROUND':_0x40d8a0(0x15d),'UNIX_TIMESTAMP':_0x40d8a0(0x156)},_0x49cafe=function(_0x16cc87){const _0x4118e1=_0x40d8a0;return!_['includes']([_0x4118e1(0x186),_0x4118e1(0x1d5),_0x4118e1(0x180),_0x4118e1(0x1c8)],_0x16cc87);},_0x24abd6=function(_0x11126){const _0x538b77=_0x40d8a0;if(!_0x11126||!_0x11126['rules']['length'])return'';let _0x3cf94e='(';for(let _0x5bbf43=0x0;_0x5bbf43<_0x11126[_0x538b77(0x15b)][_0x538b77(0x1e3)];_0x5bbf43+=0x1){_0x5bbf43>0x0&&(_0x3cf94e+='\x20'+_0x11126[_0x538b77(0x1b8)]+'\x20'),_0x3cf94e+=_0x11126[_0x538b77(0x15b)][_0x5bbf43][_0x538b77(0x1b1)]?_0x24abd6(_0x11126[_0x538b77(0x15b)][_0x5bbf43][_0x538b77(0x1b1)]):_0x11126[_0x538b77(0x15b)][_0x5bbf43][_0x538b77(0x17e)]+'\x20'+_0x11126['rules'][_0x5bbf43][_0x538b77(0x16b)]+(_0x49cafe(_0x11126['rules'][_0x5bbf43][_0x538b77(0x16b)])?'\x20'+_0x11126['rules'][_0x5bbf43][_0x538b77(0x191)]:'');}return _0x3cf94e+')';};let _0x212a22={'where':{'id':_0x3ae0f2[_0x40d8a0(0x1d7)]['id']}},_0x5ab6d7,_0x4d2c64,_0x435a1e,_0x3377;return _0x212a22=_['merge']({},_0x212a22,_0x3ae0f2[_0x40d8a0(0x1e8)]),db[_0x40d8a0(0x18e)]['findOne'](_0x212a22)[_0x40d8a0(0x19a)](function(_0x54e7e9){const _0x5c8304=_0x40d8a0;if(_0x54e7e9)return _0x5ab6d7=_0x54e7e9,_0x54e7e9[_0x5c8304(0x1ae)]();return null;})[_0x40d8a0(0x19a)](function(_0x159e74){const _0x11f6ac=_0x40d8a0;if(_0x159e74){if(!_0x159e74[_0x11f6ac(0x1e3)])throw new ValidationErrorItem('Please\x20insert\x20at\x20least\x20one\x20field',0x193);return _0x4d2c64=_0x159e74,db[_0x11f6ac(0x1a7)][_0x11f6ac(0x163)]({'raw':!![]});}return null;})['then'](function(_0x364d3b){const _0xa7ed1a=_0x40d8a0;if(_0x364d3b){_0x435a1e=_['keyBy'](_0x364d3b,'id');let _0x4b73ab;const _0x518389=squel[_0xa7ed1a(0x19c)]();_0x518389[_0xa7ed1a(0x1a4)](_0x5ab6d7[_0xa7ed1a(0x19f)]);for(let _0x52ad91=0x0;_0x52ad91<_0x4d2c64[_0xa7ed1a(0x1e3)];_0x52ad91+=0x1){_0x4b73ab=_0x4d2c64[_0x52ad91]['MetricId']?_0x435a1e[_0x4d2c64[_0x52ad91][_0xa7ed1a(0x174)]][_0xa7ed1a(0x18f)]:_0x4d2c64[_0x52ad91][_0xa7ed1a(0x17e)],_0x4b73ab=_0x4d2c64[_0x52ad91][_0xa7ed1a(0x190)]?_[_0xa7ed1a(0x1e1)](_0x5df92[_0x4d2c64[_0x52ad91][_0xa7ed1a(0x190)]],'%s',_0x4b73ab):_0x4b73ab,_0x4b73ab=_0x4d2c64[_0x52ad91][_0xa7ed1a(0x1c2)]?_[_0xa7ed1a(0x1e1)](_0x252674[_0x4d2c64[_0x52ad91][_0xa7ed1a(0x1c2)]],'%s',_0x4b73ab):_0x4b73ab,_0x4d2c64[_0x52ad91][_0xa7ed1a(0x188)]&&_0x518389[_0xa7ed1a(0x1b1)](_0x4b73ab),_0x4d2c64[_0x52ad91][_0xa7ed1a(0x1df)]&&_0x518389[_0xa7ed1a(0x15f)](_0x4b73ab,_0x4d2c64[_0x52ad91]['orderBy']===_0xa7ed1a(0x1b5)?![]:!![]),_0x518389[_0xa7ed1a(0x17e)](_0x4b73ab,_0x4d2c64[_0x52ad91][_0xa7ed1a(0x1a1)]||_0x4b73ab);}if(_0x5ab6d7[_0xa7ed1a(0x1e0)]){_0x5ab6d7[_0xa7ed1a(0x1e0)]=JSON[_0xa7ed1a(0x1ea)](_0x5ab6d7['joins']);for(let _0x37eb6f=0x0;_0x37eb6f<_0x5ab6d7[_0xa7ed1a(0x1e0)]['length'];_0x37eb6f+=0x1){_0x5ab6d7[_0xa7ed1a(0x1e0)][_0x37eb6f][_0xa7ed1a(0x195)]&&_[_0xa7ed1a(0x164)](_0x4e87fb,_0x5ab6d7[_0xa7ed1a(0x1e0)][_0x37eb6f][_0xa7ed1a(0x195)])&&_0x5ab6d7[_0xa7ed1a(0x1e0)][_0x37eb6f][_0xa7ed1a(0x16c)]&&_0x5ab6d7['joins'][_0x37eb6f][_0xa7ed1a(0x15e)]&&_0x5ab6d7[_0xa7ed1a(0x1e0)][_0x37eb6f][_0xa7ed1a(0x1db)]&&_0x518389[_0x5ab6d7['joins'][_0x37eb6f][_0xa7ed1a(0x195)]](_0x5ab6d7[_0xa7ed1a(0x1e0)][_0x37eb6f][_0xa7ed1a(0x15e)],null,util[_0xa7ed1a(0x1c2)](_0xa7ed1a(0x1c9),_0x5ab6d7['table'],_0x5ab6d7[_0xa7ed1a(0x1e0)][_0x37eb6f][_0xa7ed1a(0x16c)],_0x5ab6d7['joins'][_0x37eb6f][_0xa7ed1a(0x15e)],_0x5ab6d7[_0xa7ed1a(0x1e0)][_0x37eb6f]['foreignKey']));}}return _0x5ab6d7[_0xa7ed1a(0x1d1)]&&(_0x5ab6d7['conditions']=JSON[_0xa7ed1a(0x1ea)](_0x5ab6d7[_0xa7ed1a(0x1d1)]),_0x518389['where'](_0x24abd6(_0x5ab6d7[_0xa7ed1a(0x1d1)][_0xa7ed1a(0x1b1)]))),_0x3377=_0x518389[_0xa7ed1a(0x16f)](),_0x518389[_0xa7ed1a(0x1ab)](_0x4323de),_0x518389[_0xa7ed1a(0x167)](0x0),logger[_0xa7ed1a(0x192)](_0xa7ed1a(0x1ad),_0x518389[_0xa7ed1a(0x1be)]()),dbH[_0xa7ed1a(0x1ac)][_0xa7ed1a(0x1ce)](_0x518389['toString'](),{'type':QueryTypes[_0xa7ed1a(0x1b4)]});}})[_0x40d8a0(0x19a)](function(){const _0xdab0b7=_0x40d8a0;return{'sql':_0x3377[_0xdab0b7(0x1be)]()};})[_0x40d8a0(0x19a)](respondWithResult(_0x22d0ee,null))[_0x40d8a0(0x196)](handleError(_0x22d0ee,null));};