Built motion from commit 5fcd269f5146f10cf3129722d518881dfac64576. Version 3.0.0...
[motion-next.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
1 const a5_0x4d7c=['../../config/logger','../../components/parsers/qs','%s-%s.%s','fields','params','findOne','UNIX_TIMESTAMP(%s)','child_process','count','value','%s.%s\x20=\x20%s.%s','DESC','stack','offset','update','startDate','squel','foreignTable','web','debug','groupBy','IS\x20NOT\x20EMPTY','group','foreignKey','../../mysqldb','SELECT','No\x20available\x20data','sort','SUM(%s)','parse','send','lodash','SEC_TO_TIME(%s)','from','path','replace','cross_join','autoAssociation','length','rows','CustomReports','IS\x20NULL','create','condition','Please\x20insert\x20at\x20least\x20one\x20field','run','like','Limited\x20Query:','role','function','type','left_join','util','MetricId','sequelize','joins','catch','cdr','../../components/export/','table','nolimit','select','options','AnalyticCustomReport','generate','Unable\x20to\x20retrieve\x20the\x20current\x20user','merge','where','toString','includes','join','VIRTUAL','fieldName','GROUP_CONCAT(%s)','../../files/reports','UserProfileResource','field','rules','get','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','includeAll','name','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','endDate','HOUR(%s)','AVG(%s)','right_join','MIN(%s)','body','MAX(%s)','savename','filter','DATE(%s)','operator','error','destroy','ROUND(%s)','json','clone','QueryTypes','Content-Range','index','output','then','intersection','include','alias','randomstring','status','sendStatus','findAll','orderBy','COUNT(DISTINCT\x20%s)','attributes','getFields','keys','IS\x20EMPTY','COUNT(*)','map','model','runReport','Reports','rawAttributes','keyBy','info','fork','set','key','format','metric','UserProfileSection','Run\x20Query:','filters','user','order','parentKey','COUNT(%s)','IS\x20NOT\x20NULL','.createdAt\x20BETWEEN\x20?\x20AND\x20?','conditions','AnalyticMetric','countTable','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','limit','query'];(function(_0x537ff9,_0x4d7cf5){const _0x3e3159=function(_0x44d574){while(--_0x44d574){_0x537ff9['push'](_0x537ff9['shift']());}};_0x3e3159(++_0x4d7cf5);}(a5_0x4d7c,0x14c));const a5_0x3e31=function(_0x537ff9,_0x4d7cf5){_0x537ff9=_0x537ff9-0x0;let _0x3e3159=a5_0x4d7c[_0x537ff9];return _0x3e3159;};const _0x3c51b8=a5_0x3e31;'use strict';const util=require(_0x3c51b8('0xa')),path=require(_0x3c51b8('0x89')),_=require(_0x3c51b8('0x86')),squel=require(_0x3c51b8('0x77')),qs=require(_0x3c51b8('0x68')),logger=require(_0x3c51b8('0x67'))('api'),db=require(_0x3c51b8('0x7f'))['db'],dbH=require(_0x3c51b8('0x7f'))['dbH'],{Op,ValidationErrorItem,QueryTypes}=require(_0x3c51b8('0xc'));function respondWithResult(_0x44d574,_0x4af35f){return _0x4af35f=_0x4af35f||0xc8,function(_0x28181b){const _0x3394f9=a5_0x3e31;if(_0x28181b)return _0x44d574[_0x3394f9('0x42')](_0x4af35f)[_0x3394f9('0x37')](_0x28181b);};}function respondWithFilteredResult(_0x36dcce,_0x2ecad0){return function(_0x5265b9){const _0x19b02e=a5_0x3e31;if(_0x5265b9){const _0x30b1cc=_0x5265b9[_0x19b02e('0x6f')],_0x524ffc=_0x2ecad0[_0x19b02e('0x74')];let _0x23f616=_0x2ecad0[_0x19b02e('0x74')]+_0x2ecad0[_0x19b02e('0x65')],_0x54ee3e;return _0x23f616>=_0x30b1cc?(_0x23f616=_0x30b1cc,_0x54ee3e=0xc8):_0x54ee3e=0xce,_0x36dcce[_0x19b02e('0x42')](_0x54ee3e),_0x36dcce[_0x19b02e('0x54')](_0x19b02e('0x3a'),_0x524ffc+'-'+_0x23f616+'/'+_0x30b1cc)[_0x19b02e('0x37')](_0x5265b9);}return null;};}function saveUpdates(_0x59ffd2){return function(_0x3214b1){if(_0x3214b1)return _0x3214b1['update'](_0x59ffd2)['then'](function(_0x3a7ade){return _0x3a7ade;});return null;};}function removeEntity(_0x2bbe35){return function(_0x3609ab){const _0x4352ef=a5_0x3e31;if(_0x3609ab)return _0x3609ab[_0x4352ef('0x35')]()[_0x4352ef('0x3d')](function(){const _0x1790cc=_0x4352ef,_0x5bd3cd=_0x3609ab[_0x1790cc('0x24')]({'plain':!![]}),_0x264e42='CustomReports';return db[_0x1790cc('0x21')]['destroy']({'where':{'type':_0x264e42,'resourceId':_0x5bd3cd['id']}})['then'](function(){return _0x3609ab;});})['then'](function(){const _0x391a80=_0x4352ef;_0x2bbe35[_0x391a80('0x42')](0xcc)['end']();});};}function handleEntityNotFound(_0x38eb56){return function(_0xafa8dd){const _0x17f2ae=a5_0x3e31;return!_0xafa8dd&&_0x38eb56[_0x17f2ae('0x43')](0x194),_0xafa8dd;};}function handleError(_0xff79be,_0x3f231b){return _0x3f231b=_0x3f231b||0x1f4,function(_0x2c5bc7){const _0x593b09=a5_0x3e31;logger[_0x593b09('0x34')](_0x2c5bc7[_0x593b09('0x73')]),_0x2c5bc7[_0x593b09('0x27')]&&delete _0x2c5bc7['name'],_0xff79be['status'](_0x3f231b)[_0x593b09('0x85')](_0x2c5bc7);};}exports[_0x3c51b8('0x3b')]=function(_0xd71a40,_0x45d940){const _0x426140=_0x3c51b8;let _0x2c9585={};const _0x5e480e={},_0x5e00e1={'count':0x0,'rows':[]},_0x4d6995=_[_0x426140('0x4c')](db[_0x426140('0x15')][_0x426140('0x50')],function(_0x4575e1){const _0x41fa67=_0x426140;return{'name':_0x4575e1[_0x41fa67('0x1e')],'type':_0x4575e1['type'][_0x41fa67('0x55')]};});_0x5e480e[_0x426140('0x4d')]=_[_0x426140('0x4c')](_0x4d6995,_0x426140('0x27')),_0x5e480e[_0x426140('0x66')]=_['keys'](_0xd71a40[_0x426140('0x66')]),_0x5e480e[_0x426140('0x5a')]=_['intersection'](_0x5e480e[_0x426140('0x4d')],_0x5e480e['query']),_0x2c9585[_0x426140('0x47')]=_[_0x426140('0x3e')](_0x5e480e['model'],qs[_0x426140('0x6a')](_0xd71a40[_0x426140('0x66')]['fields'])),_0x2c9585[_0x426140('0x47')]=_0x2c9585[_0x426140('0x47')][_0x426140('0x8d')]?_0x2c9585[_0x426140('0x47')]:_0x5e480e[_0x426140('0x4d')];typeof _0xd71a40[_0x426140('0x66')][_0x426140('0x12')]==='undefined'&&(_0x2c9585[_0x426140('0x65')]=qs[_0x426140('0x65')](_0xd71a40[_0x426140('0x66')][_0x426140('0x65')]),_0x2c9585[_0x426140('0x74')]=qs[_0x426140('0x74')](_0xd71a40['query'][_0x426140('0x74')]));_0x2c9585[_0x426140('0x5c')]=qs[_0x426140('0x82')](_0xd71a40[_0x426140('0x66')]['sort']),_0x2c9585[_0x426140('0x19')]=qs[_0x426140('0x5a')](_['pick'](_0xd71a40[_0x426140('0x66')],_0x5e480e[_0x426140('0x5a')]),_0x4d6995);_0xd71a40[_0x426140('0x66')][_0x426140('0x31')]&&(_0x2c9585[_0x426140('0x19')]=_[_0x426140('0x18')](_0x2c9585['where'],{[Op['or']]:_[_0x426140('0x4c')](_0x4d6995,function(_0x1874ea){const _0x318242=_0x426140;if(_0x1874ea[_0x318242('0x8')]!==_0x318242('0x1d')){const _0x2a7508={};return _0x2a7508[_0x1874ea[_0x318242('0x27')]]={[Op[_0x318242('0x4')]]:'%'+_0xd71a40[_0x318242('0x66')][_0x318242('0x31')]+'%'},_0x2a7508;}})}));_0x2c9585=_[_0x426140('0x18')]({},_0x2c9585,_0xd71a40[_0x426140('0x14')]);const _0x30eeda={'where':_0x2c9585['where']};return db[_0x426140('0x15')][_0x426140('0x6f')](_0x30eeda)[_0x426140('0x3d')](function(_0x3ae71e){const _0x3ab419=_0x426140;return _0x5e00e1[_0x3ab419('0x6f')]=_0x3ae71e,_0xd71a40[_0x3ab419('0x66')][_0x3ab419('0x26')]&&(_0x2c9585['include']=[{'all':!![]}]),db[_0x3ab419('0x15')]['findAll'](_0x2c9585);})[_0x426140('0x3d')](function(_0x35dd26){const _0x470bcd=_0x426140;return _0x5e00e1[_0x470bcd('0x8e')]=_0x35dd26,_0x5e00e1;})[_0x426140('0x3d')](respondWithFilteredResult(_0x45d940,_0x2c9585))[_0x426140('0xe')](handleError(_0x45d940,null));},exports['show']=function(_0x4519b6,_0x4a8989){const _0x330266=_0x3c51b8;let _0xfb89c5={'raw':![],'where':{'id':_0x4519b6['params']['id']}};const _0x3a4d8f={};return _0x3a4d8f[_0x330266('0x4d')]=_['keys'](db['AnalyticCustomReport'][_0x330266('0x50')]),_0x3a4d8f[_0x330266('0x66')]=_[_0x330266('0x49')](_0x4519b6[_0x330266('0x66')]),_0x3a4d8f[_0x330266('0x5a')]=_['intersection'](_0x3a4d8f['model'],_0x3a4d8f[_0x330266('0x66')]),_0xfb89c5['attributes']=_[_0x330266('0x3e')](_0x3a4d8f[_0x330266('0x4d')],qs[_0x330266('0x6a')](_0x4519b6[_0x330266('0x66')]['fields'])),_0xfb89c5['attributes']=_0xfb89c5[_0x330266('0x47')]['length']?_0xfb89c5['attributes']:_0x3a4d8f['model'],_0x4519b6['query']['includeAll']&&(_0xfb89c5[_0x330266('0x3f')]=[{'all':!![]}]),_0xfb89c5=_[_0x330266('0x18')]({},_0xfb89c5,_0x4519b6[_0x330266('0x14')]),db['AnalyticCustomReport'][_0x330266('0x6c')](_0xfb89c5)[_0x330266('0x3d')](handleEntityNotFound(_0x4a8989,null))[_0x330266('0x3d')](respondWithResult(_0x4a8989,null))[_0x330266('0xe')](handleError(_0x4a8989,null));},exports['create']=function(_0x15e022,_0x252864){const _0x6079a2=_0x3c51b8;return db[_0x6079a2('0x15')][_0x6079a2('0x0')](_0x15e022[_0x6079a2('0x2e')],{})[_0x6079a2('0x3d')](function(_0x545f48){const _0x52e33d=_0x6079a2,_0x4741e1=_0x15e022[_0x52e33d('0x5b')]['get']({'plain':!![]});if(!_0x4741e1)throw new Error(_0x52e33d('0x17'));if(_0x4741e1[_0x52e33d('0x6')]===_0x52e33d('0x5b')){const _0xc7206b=_0x545f48[_0x52e33d('0x24')]({'plain':!![]}),_0x21736b=_0x52e33d('0x4f');return db[_0x52e33d('0x58')][_0x52e33d('0x6c')]({'where':{'name':_0x21736b,'userProfileId':_0x4741e1['userProfileId']},'raw':!![]})[_0x52e33d('0x3d')](function(_0x238a48){const _0x3b28bd=_0x52e33d;return _0x238a48&&_0x238a48[_0x3b28bd('0x8c')]===0x0?db[_0x3b28bd('0x21')][_0x3b28bd('0x0')]({'name':_0xc7206b[_0x3b28bd('0x27')],'resourceId':_0xc7206b['id'],'type':_0x3b28bd('0x8f'),'sectionId':_0x238a48['id']},{})[_0x3b28bd('0x3d')](function(){return _0x545f48;}):_0x545f48;})[_0x52e33d('0xe')](function(_0x7359cc){const _0x36ee23=_0x52e33d;logger[_0x36ee23('0x34')](_0x36ee23('0x25'),_0x7359cc);throw _0x7359cc;});}return _0x545f48;})[_0x6079a2('0x3d')](respondWithResult(_0x252864,0xc9))['catch'](handleError(_0x252864,null));},exports[_0x3c51b8('0x75')]=function(_0x443202,_0x6bfafb){const _0x166c9b=_0x3c51b8;return _0x443202['body']['id']&&delete _0x443202[_0x166c9b('0x2e')]['id'],db[_0x166c9b('0x15')][_0x166c9b('0x6c')]({'where':{'id':_0x443202['params']['id']}})[_0x166c9b('0x3d')](handleEntityNotFound(_0x6bfafb,null))[_0x166c9b('0x3d')](saveUpdates(_0x443202[_0x166c9b('0x2e')],null))['then'](respondWithResult(_0x6bfafb,null))[_0x166c9b('0xe')](handleError(_0x6bfafb,null));},exports[_0x3c51b8('0x35')]=function(_0x1b58cf,_0x22c96c){const _0x34e55a=_0x3c51b8;return db[_0x34e55a('0x15')][_0x34e55a('0x6c')]({'where':{'id':_0x1b58cf['params']['id']}})[_0x34e55a('0x3d')](handleEntityNotFound(_0x22c96c,null))[_0x34e55a('0x3d')](removeEntity(_0x22c96c,null))[_0x34e55a('0xe')](handleError(_0x22c96c,null));},exports['preview']=function(_0x537c32,_0x2a98ac){const _0x5adfb4=_0x3c51b8,_0x378556=0xa,_0x3abf0f=['join',_0x5adfb4('0x9'),_0x5adfb4('0x2c'),'cross_join'],_0x2978a5={'SUM':_0x5adfb4('0x83'),'COUNT':'COUNT(%s)','COUNT\x20DISTINCT':_0x5adfb4('0x46'),'MAX':'MAX(%s)','MIN':_0x5adfb4('0x2d'),'AVG':_0x5adfb4('0x2b'),'GROUP_CONCAT':_0x5adfb4('0x1f'),'GROUP_CONCAT\x20ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT\x20DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'},_0x36bc6d={'SEC_TO_TIME':_0x5adfb4('0x87'),'DATE':_0x5adfb4('0x32'),'HOUR':'HOUR(%s)','ROUND':_0x5adfb4('0x36'),'UNIX_TIMESTAMP':_0x5adfb4('0x6d')},_0x178b8b=function(_0x3e7083){const _0x2bb294=_0x5adfb4;return!_[_0x2bb294('0x1b')]([_0x2bb294('0x90'),_0x2bb294('0x5f'),_0x2bb294('0x4a'),'IS\x20NOT\x20EMPTY'],_0x3e7083);},_0x3ff2aa=function(_0x4f3816){const _0x35f9f4=_0x5adfb4;if(!_0x4f3816||!_0x4f3816[_0x35f9f4('0x23')][_0x35f9f4('0x8d')])return'';let _0xf9678a='(';for(let _0x209233=0x0;_0x209233<_0x4f3816[_0x35f9f4('0x23')][_0x35f9f4('0x8d')];_0x209233+=0x1){_0x209233>0x0&&(_0xf9678a+='\x20'+_0x4f3816[_0x35f9f4('0x33')]+'\x20'),_0xf9678a+=_0x4f3816[_0x35f9f4('0x23')][_0x209233][_0x35f9f4('0x7d')]?_0x3ff2aa(_0x4f3816[_0x35f9f4('0x23')][_0x209233][_0x35f9f4('0x7d')]):_0x4f3816[_0x35f9f4('0x23')][_0x209233][_0x35f9f4('0x22')]+'\x20'+_0x4f3816[_0x35f9f4('0x23')][_0x209233]['condition']+(_0x178b8b(_0x4f3816[_0x35f9f4('0x23')][_0x209233][_0x35f9f4('0x1')])?'\x20'+_0x4f3816[_0x35f9f4('0x23')][_0x209233][_0x35f9f4('0x70')]:'');}return _0xf9678a+')';};let _0x178aba={'where':{'id':_0x537c32[_0x5adfb4('0x6b')]['id']}},_0x164115,_0x36a231,_0x4f5c4c;return _0x178aba=_[_0x5adfb4('0x18')]({},_0x178aba,_0x537c32[_0x5adfb4('0x14')]),db[_0x5adfb4('0x15')][_0x5adfb4('0x6c')](_0x178aba)['then'](function(_0xf75563){const _0x5cdb36=_0x5adfb4;if(_0xf75563)return _0x164115=_0xf75563,_0xf75563[_0x5cdb36('0x48')]();return null;})[_0x5adfb4('0x3d')](function(_0x1d09dc){const _0x14ed23=_0x5adfb4;if(_0x1d09dc){if(!_0x1d09dc[_0x14ed23('0x8d')])throw new ValidationErrorItem('Please\x20insert\x20at\x20least\x20one\x20field',0x193);return _0x36a231=_0x1d09dc,db[_0x14ed23('0x62')][_0x14ed23('0x44')]({'raw':!![]});}return null;})[_0x5adfb4('0x3d')](function(_0x12cd09){const _0x49ad35=_0x5adfb4;if(_0x12cd09){_0x4f5c4c=_[_0x49ad35('0x51')](_0x12cd09,'id');let _0x10ea64;const _0x461fc6=squel['select']();_0x461fc6[_0x49ad35('0x88')](_0x164115[_0x49ad35('0x11')]);for(let _0xae73ae=0x0;_0xae73ae<_0x36a231[_0x49ad35('0x8d')];_0xae73ae+=0x1){_0x10ea64=_0x36a231[_0xae73ae][_0x49ad35('0xb')]?_0x4f5c4c[_0x36a231[_0xae73ae][_0x49ad35('0xb')]][_0x49ad35('0x57')]:_0x36a231[_0xae73ae][_0x49ad35('0x22')],_0x10ea64=_0x36a231[_0xae73ae][_0x49ad35('0x7')]?_[_0x49ad35('0x8a')](_0x2978a5[_0x36a231[_0xae73ae][_0x49ad35('0x7')]],'%s',_0x10ea64):_0x10ea64,_0x10ea64=_0x36a231[_0xae73ae][_0x49ad35('0x56')]?_[_0x49ad35('0x8a')](_0x36bc6d[_0x36a231[_0xae73ae]['format']],'%s',_0x10ea64):_0x10ea64,_0x36a231[_0xae73ae][_0x49ad35('0x7b')]&&_0x461fc6[_0x49ad35('0x7d')](_0x10ea64),_0x36a231[_0xae73ae][_0x49ad35('0x45')]&&_0x461fc6[_0x49ad35('0x5c')](_0x10ea64,_0x36a231[_0xae73ae][_0x49ad35('0x45')]===_0x49ad35('0x72')?![]:!![]),_0x461fc6[_0x49ad35('0x22')](_0x10ea64,_0x36a231[_0xae73ae][_0x49ad35('0x40')]||_0x10ea64);}if(_0x164115['joins']){_0x164115[_0x49ad35('0xd')]=JSON['parse'](_0x164115[_0x49ad35('0xd')]);for(let _0x3fcd38=0x0;_0x3fcd38<_0x164115['joins'][_0x49ad35('0x8d')];_0x3fcd38+=0x1){_0x164115[_0x49ad35('0xd')][_0x3fcd38][_0x49ad35('0x8')]&&_[_0x49ad35('0x1b')](_0x3abf0f,_0x164115[_0x49ad35('0xd')][_0x3fcd38]['type'])&&_0x164115[_0x49ad35('0xd')][_0x3fcd38][_0x49ad35('0x5d')]&&_0x164115['joins'][_0x3fcd38][_0x49ad35('0x78')]&&_0x164115[_0x49ad35('0xd')][_0x3fcd38][_0x49ad35('0x7e')]&&_0x461fc6[_0x164115['joins'][_0x3fcd38]['type']](_0x164115['joins'][_0x3fcd38][_0x49ad35('0x78')],null,util['format'](_0x49ad35('0x71'),_0x164115['table'],_0x164115[_0x49ad35('0xd')][_0x3fcd38][_0x49ad35('0x5d')],_0x164115['joins'][_0x3fcd38]['foreignTable'],_0x164115[_0x49ad35('0xd')][_0x3fcd38]['foreignKey']));}}return _0x164115[_0x49ad35('0x61')]&&(_0x164115[_0x49ad35('0x61')]=JSON[_0x49ad35('0x84')](_0x164115[_0x49ad35('0x61')]),_0x461fc6[_0x49ad35('0x19')](_0x3ff2aa(_0x164115[_0x49ad35('0x61')][_0x49ad35('0x7d')]))),_0x461fc6[_0x49ad35('0x65')](_0x378556),_0x461fc6['offset'](0x0),logger[_0x49ad35('0x7a')](_0x49ad35('0x5'),_0x461fc6[_0x49ad35('0x1a')]()),db[_0x49ad35('0xc')][_0x49ad35('0x66')](_0x461fc6[_0x49ad35('0x1a')](),{'type':QueryTypes[_0x49ad35('0x80')]});}})[_0x5adfb4('0x3d')](respondWithResult(_0x2a98ac,null))[_0x5adfb4('0xe')](handleError(_0x2a98ac,null));};function runReport(_0x2b51ff,_0x1e8d57,_0x14867d){const _0x3d27e9=_0x3c51b8,_0x11b3a6=_0x1e8d57[_0x3d27e9('0x27')],_0x309c71=0xa,_0x7b56e9=[_0x3d27e9('0x1c'),_0x3d27e9('0x9'),'right_join','cross_join'],_0x24db5c={'SUM':_0x3d27e9('0x83'),'COUNT':_0x3d27e9('0x5e'),'COUNT\x20DISTINCT':_0x3d27e9('0x46'),'MAX':'MAX(%s)','MIN':_0x3d27e9('0x2d'),'AVG':_0x3d27e9('0x2b'),'GROUP_CONCAT':_0x3d27e9('0x1f'),'GROUP_CONCAT\x20ASC':_0x3d27e9('0x64'),'GROUP_CONCAT\x20DESC':_0x3d27e9('0x28')},_0x417cfd={'SEC_TO_TIME':_0x3d27e9('0x87'),'DATE':_0x3d27e9('0x32'),'HOUR':_0x3d27e9('0x2a'),'ROUND':_0x3d27e9('0x36'),'UNIX_TIMESTAMP':_0x3d27e9('0x6d')},_0x2ceaf6=function(_0x43c992){const _0x34ec3f=_0x3d27e9;return!_['includes'](['IS\x20NULL','IS\x20NOT\x20NULL',_0x34ec3f('0x4a'),_0x34ec3f('0x7c')],_0x43c992);},_0x28a990=function(_0x21fe57){const _0x5b25e8=_0x3d27e9;if(!_0x21fe57||!_0x21fe57[_0x5b25e8('0x23')][_0x5b25e8('0x8d')])return'';let _0x30030='(';for(let _0x3ff3f8=0x0;_0x3ff3f8<_0x21fe57[_0x5b25e8('0x23')]['length'];_0x3ff3f8+=0x1){_0x3ff3f8>0x0&&(_0x30030+='\x20'+_0x21fe57['operator']+'\x20'),_0x30030+=_0x21fe57[_0x5b25e8('0x23')][_0x3ff3f8][_0x5b25e8('0x7d')]?_0x28a990(_0x21fe57[_0x5b25e8('0x23')][_0x3ff3f8][_0x5b25e8('0x7d')]):_0x21fe57[_0x5b25e8('0x23')][_0x3ff3f8][_0x5b25e8('0x22')]+'\x20'+_0x21fe57['rules'][_0x3ff3f8][_0x5b25e8('0x1')]+(_0x2ceaf6(_0x21fe57[_0x5b25e8('0x23')][_0x3ff3f8][_0x5b25e8('0x1')])?'\x20'+_0x21fe57[_0x5b25e8('0x23')][_0x3ff3f8][_0x5b25e8('0x70')]:'');}return _0x30030+')';};let _0x197733={'where':{'id':_0x2b51ff['id']}},_0x3ce650,_0x39cb30,_0x8e501a,_0xd7c51c,_0x3e77be;return _0x197733=_[_0x3d27e9('0x18')]({},_0x197733,_0x14867d),db[_0x3d27e9('0x15')][_0x3d27e9('0x6c')](_0x197733)[_0x3d27e9('0x3d')](function(_0x436092){const _0x11a39b=_0x3d27e9;if(_0x436092)return _0x3ce650=_0x436092,_0x436092[_0x11a39b('0x48')]();return null;})[_0x3d27e9('0x3d')](function(_0x2d8977){const _0xd70ed1=_0x3d27e9;if(_0x2d8977){if(!_0x2d8977['length'])throw new ValidationErrorItem(_0xd70ed1('0x2'),0x193);return _0x39cb30=_0x2d8977,db['AnalyticMetric'][_0xd70ed1('0x44')]({'raw':!![]});}return null;})['then'](function(_0x2c66a9){const _0x16bd26=_0x3d27e9;if(_0x2c66a9){_0x8e501a=_['keyBy'](_0x2c66a9,'id');let _0x2448cc;const _0x5af7d1=squel[_0x16bd26('0x13')]();_0x5af7d1[_0x16bd26('0x88')](_0x3ce650['table']);for(let _0x5c0bc0=0x0;_0x5c0bc0<_0x39cb30[_0x16bd26('0x8d')];_0x5c0bc0+=0x1){_0x2448cc=_0x39cb30[_0x5c0bc0][_0x16bd26('0xb')]?_0x8e501a[_0x39cb30[_0x5c0bc0]['MetricId']][_0x16bd26('0x57')]:_0x39cb30[_0x5c0bc0][_0x16bd26('0x22')],_0x2448cc=_0x39cb30[_0x5c0bc0]['function']?_[_0x16bd26('0x8a')](_0x24db5c[_0x39cb30[_0x5c0bc0][_0x16bd26('0x7')]],'%s',_0x2448cc):_0x2448cc,_0x2448cc=_0x39cb30[_0x5c0bc0][_0x16bd26('0x56')]?_[_0x16bd26('0x8a')](_0x417cfd[_0x39cb30[_0x5c0bc0][_0x16bd26('0x56')]],'%s',_0x2448cc):_0x2448cc,_0x39cb30[_0x5c0bc0][_0x16bd26('0x7b')]&&_0x5af7d1['group'](_0x2448cc),_0x39cb30[_0x5c0bc0][_0x16bd26('0x45')]&&_0x5af7d1[_0x16bd26('0x5c')](_0x2448cc,_0x39cb30[_0x5c0bc0]['orderBy']===_0x16bd26('0x72')?![]:!![]),_0x5af7d1[_0x16bd26('0x22')](_0x2448cc,_0x39cb30[_0x5c0bc0][_0x16bd26('0x40')]||_0x2448cc);}if(_0x3ce650['joins']){_0x3ce650[_0x16bd26('0xd')]=JSON[_0x16bd26('0x84')](_0x3ce650[_0x16bd26('0xd')]);for(let _0x5a0d1f=0x0;_0x5a0d1f<_0x3ce650['joins'][_0x16bd26('0x8d')];_0x5a0d1f+=0x1){_0x3ce650[_0x16bd26('0xd')][_0x5a0d1f][_0x16bd26('0x8')]&&_[_0x16bd26('0x1b')](_0x7b56e9,_0x3ce650[_0x16bd26('0xd')][_0x5a0d1f][_0x16bd26('0x8')])&&_0x3ce650['joins'][_0x5a0d1f]['parentKey']&&_0x3ce650['joins'][_0x5a0d1f][_0x16bd26('0x78')]&&_0x3ce650[_0x16bd26('0xd')][_0x5a0d1f]['foreignKey']&&_0x5af7d1[_0x3ce650[_0x16bd26('0xd')][_0x5a0d1f][_0x16bd26('0x8')]](_0x3ce650[_0x16bd26('0xd')][_0x5a0d1f]['foreignTable'],null,util[_0x16bd26('0x56')](_0x16bd26('0x71'),_0x3ce650['table'],_0x3ce650[_0x16bd26('0xd')][_0x5a0d1f][_0x16bd26('0x5d')],_0x3ce650[_0x16bd26('0xd')][_0x5a0d1f][_0x16bd26('0x78')],_0x3ce650[_0x16bd26('0xd')][_0x5a0d1f][_0x16bd26('0x7e')]));}}return _0x3ce650[_0x16bd26('0x61')]&&(_0x3ce650['conditions']=JSON[_0x16bd26('0x84')](_0x3ce650[_0x16bd26('0x61')]),_0x5af7d1['where'](_0x28a990(_0x3ce650[_0x16bd26('0x61')][_0x16bd26('0x7d')]))),_0x3e77be=_0x5af7d1['clone'](),_0x5af7d1[_0x16bd26('0x65')](_0x309c71),_0x5af7d1[_0x16bd26('0x74')](0x0),logger[_0x16bd26('0x7a')](_0x16bd26('0x5'),_0x5af7d1[_0x16bd26('0x1a')]()),db[_0x16bd26('0xc')]['query'](_0x5af7d1[_0x16bd26('0x1a')](),{'type':QueryTypes[_0x16bd26('0x80')]});}})[_0x3d27e9('0x3d')](function(_0x33c49d){const _0x3a775a=_0x3d27e9;if(!_0x33c49d[_0x3a775a('0x8d')])throw new ValidationErrorItem(_0x3a775a('0x81'),0xcc);if(_0x1e8d57[_0x3a775a('0x3c')]===_0x3a775a('0x79'))return null;const _0x17987b=_[_0x3a775a('0x18')](_0x1e8d57,{'name':_0x1e8d57['fullPath']||_0x1e8d57[_0x3a775a('0x27')]||_0x3ce650[_0x3a775a('0x27')],'basename':_0x11b3a6,'savename':util['format'](_0x3a775a('0x69'),_0x1e8d57[_0x3a775a('0x27')]||_0x3ce650[_0x3a775a('0x27')],require(_0x3a775a('0x41'))[_0x3a775a('0x16')](0x4),_0x1e8d57[_0x3a775a('0x3c')]||'csv'),'reportId':_0x3ce650['id'],'reportType':'custom'});return db['AnalyticExtractedReport'][_0x3a775a('0x0')](_0x17987b,{'raw':!![]});})['then'](function(_0x4f364b){const _0x26fe85=_0x3d27e9;_0x3ce650[_0x26fe85('0x11')]===_0x26fe85('0xf')?_0x3e77be[_0x26fe85('0x19')](_0x3ce650[_0x26fe85('0x11')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x1e8d57[_0x26fe85('0x76')],_0x1e8d57['endDate']):_0x3e77be[_0x26fe85('0x19')](_0x3ce650['table']+_0x26fe85('0x60'),_0x1e8d57[_0x26fe85('0x76')],_0x1e8d57[_0x26fe85('0x29')]);if(_0x4f364b)return logger[_0x26fe85('0x52')](_0x26fe85('0x59'),_0x3e77be['toString']()),require(_0x26fe85('0x6e'))[_0x26fe85('0x53')](path[_0x26fe85('0x1c')](__dirname,_0x26fe85('0x10'),_0x4f364b[_0x26fe85('0x3c')]),[_0x4f364b['id'],_0x3e77be['toString'](),path[_0x26fe85('0x1c')](__dirname,_0x26fe85('0x20'),_0x4f364b[_0x26fe85('0x30')]),_0x11b3a6]),_0x4f364b;else{const _0x28995f=squel['select']();return _0x28995f[_0x26fe85('0x88')]('('+_0x3e77be[_0x26fe85('0x1a')]()+')',_0x26fe85('0x63')),_0x28995f[_0x26fe85('0x22')](_0x26fe85('0x4b'),_0x26fe85('0x6f')),_0x3e77be[_0x26fe85('0x65')](_0x1e8d57[_0x26fe85('0x65')]||_0x309c71),_0x3e77be[_0x26fe85('0x74')](_0x1e8d57[_0x26fe85('0x74')]||0x0),dbH[_0x26fe85('0xc')][_0x26fe85('0x66')](_0x28995f['toString'](),{'type':dbH['sequelize'][_0x26fe85('0x39')][_0x26fe85('0x80')]})[_0x26fe85('0x3d')](function(_0x5897c9){const _0x2b43ff=_0x26fe85;return!_0x5897c9['length']?_0xd7c51c=0x0:_0xd7c51c=_0x5897c9[0x0][_0x2b43ff('0x6f')]||0x0,dbH[_0x2b43ff('0xc')][_0x2b43ff('0x66')](_0x3e77be[_0x2b43ff('0x1a')](),{'type':dbH[_0x2b43ff('0xc')][_0x2b43ff('0x39')][_0x2b43ff('0x80')]});})[_0x26fe85('0x3d')](function(_0x37c76d){return{'rows':_0x37c76d||[],'count':_0xd7c51c};});}});}exports[_0x3c51b8('0x3')]=function(_0x1825bc,_0x46cc10){const _0x2620d3=_0x3c51b8;return runReport(_0x1825bc[_0x2620d3('0x6b')],_0x1825bc[_0x2620d3('0x66')],_0x1825bc[_0x2620d3('0x14')])[_0x2620d3('0x3d')](respondWithResult(_0x46cc10,null))[_0x2620d3('0xe')](handleError(_0x46cc10,null));},exports[_0x3c51b8('0x4e')]=runReport,exports[_0x3c51b8('0x66')]=function(_0x5bd6da,_0x883007){const _0x3ec8db=_0x3c51b8,_0x17bf0a=0xa,_0x557f2a=[_0x3ec8db('0x1c'),_0x3ec8db('0x9'),_0x3ec8db('0x2c'),_0x3ec8db('0x8b')],_0x3c134a={'SUM':_0x3ec8db('0x83'),'COUNT':_0x3ec8db('0x5e'),'COUNT\x20DISTINCT':_0x3ec8db('0x46'),'MAX':_0x3ec8db('0x2f'),'MIN':_0x3ec8db('0x2d'),'AVG':_0x3ec8db('0x2b'),'GROUP_CONCAT':_0x3ec8db('0x1f'),'GROUP_CONCAT\x20ASC':_0x3ec8db('0x64'),'GROUP_CONCAT\x20DESC':_0x3ec8db('0x28')},_0x1abe07={'SEC_TO_TIME':_0x3ec8db('0x87'),'DATE':'DATE(%s)','HOUR':_0x3ec8db('0x2a'),'ROUND':_0x3ec8db('0x36'),'UNIX_TIMESTAMP':_0x3ec8db('0x6d')},_0x398ccc=function(_0x3495ee){const _0xfb2ea0=_0x3ec8db;return!_[_0xfb2ea0('0x1b')]([_0xfb2ea0('0x90'),'IS\x20NOT\x20NULL',_0xfb2ea0('0x4a'),'IS\x20NOT\x20EMPTY'],_0x3495ee);},_0x557715=function(_0x188d39){const _0x621586=_0x3ec8db;if(!_0x188d39||!_0x188d39[_0x621586('0x23')][_0x621586('0x8d')])return'';let _0x3439e7='(';for(let _0x3ea7bf=0x0;_0x3ea7bf<_0x188d39[_0x621586('0x23')][_0x621586('0x8d')];_0x3ea7bf+=0x1){_0x3ea7bf>0x0&&(_0x3439e7+='\x20'+_0x188d39[_0x621586('0x33')]+'\x20'),_0x3439e7+=_0x188d39[_0x621586('0x23')][_0x3ea7bf][_0x621586('0x7d')]?_0x557715(_0x188d39['rules'][_0x3ea7bf][_0x621586('0x7d')]):_0x188d39['rules'][_0x3ea7bf][_0x621586('0x22')]+'\x20'+_0x188d39[_0x621586('0x23')][_0x3ea7bf][_0x621586('0x1')]+(_0x398ccc(_0x188d39[_0x621586('0x23')][_0x3ea7bf][_0x621586('0x1')])?'\x20'+_0x188d39[_0x621586('0x23')][_0x3ea7bf][_0x621586('0x70')]:'');}return _0x3439e7+')';};let _0x964a8e={'where':{'id':_0x5bd6da['params']['id']}},_0x41b01f,_0x4c8b95,_0x574358,_0x4678f5;return _0x964a8e=_[_0x3ec8db('0x18')]({},_0x964a8e,_0x5bd6da[_0x3ec8db('0x14')]),db[_0x3ec8db('0x15')]['findOne'](_0x964a8e)[_0x3ec8db('0x3d')](function(_0x1b1e1f){const _0x38ac5a=_0x3ec8db;if(_0x1b1e1f)return _0x41b01f=_0x1b1e1f,_0x1b1e1f[_0x38ac5a('0x48')]();return null;})[_0x3ec8db('0x3d')](function(_0x4ced81){const _0x1ca612=_0x3ec8db;if(_0x4ced81){if(!_0x4ced81[_0x1ca612('0x8d')])throw new ValidationErrorItem(_0x1ca612('0x2'),0x193);return _0x4c8b95=_0x4ced81,db[_0x1ca612('0x62')][_0x1ca612('0x44')]({'raw':!![]});}return null;})['then'](function(_0x57b8ec){const _0x3ffa58=_0x3ec8db;if(_0x57b8ec){_0x574358=_['keyBy'](_0x57b8ec,'id');let _0x3d3c1c;const _0x1da2ce=squel[_0x3ffa58('0x13')]();_0x1da2ce[_0x3ffa58('0x88')](_0x41b01f[_0x3ffa58('0x11')]);for(let _0x9b1d9e=0x0;_0x9b1d9e<_0x4c8b95['length'];_0x9b1d9e+=0x1){_0x3d3c1c=_0x4c8b95[_0x9b1d9e]['MetricId']?_0x574358[_0x4c8b95[_0x9b1d9e][_0x3ffa58('0xb')]][_0x3ffa58('0x57')]:_0x4c8b95[_0x9b1d9e][_0x3ffa58('0x22')],_0x3d3c1c=_0x4c8b95[_0x9b1d9e][_0x3ffa58('0x7')]?_[_0x3ffa58('0x8a')](_0x3c134a[_0x4c8b95[_0x9b1d9e][_0x3ffa58('0x7')]],'%s',_0x3d3c1c):_0x3d3c1c,_0x3d3c1c=_0x4c8b95[_0x9b1d9e][_0x3ffa58('0x56')]?_[_0x3ffa58('0x8a')](_0x1abe07[_0x4c8b95[_0x9b1d9e]['format']],'%s',_0x3d3c1c):_0x3d3c1c,_0x4c8b95[_0x9b1d9e][_0x3ffa58('0x7b')]&&_0x1da2ce[_0x3ffa58('0x7d')](_0x3d3c1c),_0x4c8b95[_0x9b1d9e]['orderBy']&&_0x1da2ce[_0x3ffa58('0x5c')](_0x3d3c1c,_0x4c8b95[_0x9b1d9e][_0x3ffa58('0x45')]==='DESC'?![]:!![]),_0x1da2ce[_0x3ffa58('0x22')](_0x3d3c1c,_0x4c8b95[_0x9b1d9e][_0x3ffa58('0x40')]||_0x3d3c1c);}if(_0x41b01f[_0x3ffa58('0xd')]){_0x41b01f[_0x3ffa58('0xd')]=JSON['parse'](_0x41b01f[_0x3ffa58('0xd')]);for(let _0x3ed084=0x0;_0x3ed084<_0x41b01f[_0x3ffa58('0xd')][_0x3ffa58('0x8d')];_0x3ed084+=0x1){_0x41b01f[_0x3ffa58('0xd')][_0x3ed084][_0x3ffa58('0x8')]&&_[_0x3ffa58('0x1b')](_0x557f2a,_0x41b01f[_0x3ffa58('0xd')][_0x3ed084][_0x3ffa58('0x8')])&&_0x41b01f[_0x3ffa58('0xd')][_0x3ed084]['parentKey']&&_0x41b01f[_0x3ffa58('0xd')][_0x3ed084]['foreignTable']&&_0x41b01f['joins'][_0x3ed084]['foreignKey']&&_0x1da2ce[_0x41b01f[_0x3ffa58('0xd')][_0x3ed084]['type']](_0x41b01f[_0x3ffa58('0xd')][_0x3ed084]['foreignTable'],null,util[_0x3ffa58('0x56')](_0x3ffa58('0x71'),_0x41b01f[_0x3ffa58('0x11')],_0x41b01f[_0x3ffa58('0xd')][_0x3ed084][_0x3ffa58('0x5d')],_0x41b01f[_0x3ffa58('0xd')][_0x3ed084][_0x3ffa58('0x78')],_0x41b01f[_0x3ffa58('0xd')][_0x3ed084][_0x3ffa58('0x7e')]));}}return _0x41b01f['conditions']&&(_0x41b01f['conditions']=JSON[_0x3ffa58('0x84')](_0x41b01f[_0x3ffa58('0x61')]),_0x1da2ce[_0x3ffa58('0x19')](_0x557715(_0x41b01f[_0x3ffa58('0x61')][_0x3ffa58('0x7d')]))),_0x4678f5=_0x1da2ce[_0x3ffa58('0x38')](),_0x1da2ce[_0x3ffa58('0x65')](_0x17bf0a),_0x1da2ce[_0x3ffa58('0x74')](0x0),logger['debug'](_0x3ffa58('0x5'),_0x1da2ce[_0x3ffa58('0x1a')]()),db['sequelize'][_0x3ffa58('0x66')](_0x1da2ce[_0x3ffa58('0x1a')](),{'type':QueryTypes[_0x3ffa58('0x80')]});}})[_0x3ec8db('0x3d')](function(){const _0x52f0e2=_0x3ec8db;return{'sql':_0x4678f5[_0x52f0e2('0x1a')]()};})[_0x3ec8db('0x3d')](respondWithResult(_0x883007,null))[_0x3ec8db('0xe')](handleError(_0x883007,null));};