Built motion from commit a9fb64cc6defd8fb3a5cc199221f878e91c0e969. Version 3.0.0...
[motion-next.git] / server / api / analyticDefaultReport / analyticDefaultReport.controller.js
1 const a9_0x1633=['model','include','left_join','function','query','SEC_TO_TIME(%s)','Content-Range','dbH','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','filter','json','pick','ROUND(%s)','AVG(%s)','api','Please\x20insert\x20at\x20least\x20one\x20field','fieldName','status','alias','nolimit','util','create','where','../../config/logger','show','../../files/reports','orderBy','sendStatus','parse','MetricId','child_process','DefaultReports','limit','SELECT','findAll','map','COUNT(*)','run','field','type','UserProfileSection','join','COUNT(DISTINCT\x20%s)','toString','table','Limited\x20Query:','lodash','options','right_join','body','sort','count','path','catch','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','attributes','findOne','Unable\x20to\x20retrieve\x20the\x20current\x20user','format','VIRTUAL','includeAll','default','runReport','keys','.createdAt\x20BETWEEN\x20?\x20AND\x20?','order','group','sequelize','joins','HOUR(%s)','IS\x20NOT\x20NULL','rows','conditions','role','end','destroy','length','error','autoAssociation','MIN(%s)','rules','select','clone','condition','then','DESC','operator','QueryTypes','stack','parentKey','send','rawAttributes','cdr','UNIX_TIMESTAMP(%s)','like','debug','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','getFields','randomstring','metric','merge','startDate','GROUP_CONCAT(%s)','cross_join','COUNT(%s)','get','name','countTable','set','foreignTable','%s.%s\x20=\x20%s.%s','info','web','SUM(%s)','generate','offset','IS\x20EMPTY','UserProfileResource','foreignKey','key','MAX(%s)','output','includes','AnalyticMetric','IS\x20NOT\x20EMPTY','filters','DATE(%s)','AnalyticDefaultReport','params','intersection','Reports','../../mysqldb','savename','replace','groupBy','IS\x20NULL','fields','from'];(function(_0x3ae1ca,_0x1633b4){const _0x22383b=function(_0x8fa80d){while(--_0x8fa80d){_0x3ae1ca['push'](_0x3ae1ca['shift']());}};_0x22383b(++_0x1633b4);}(a9_0x1633,0x87));const a9_0x2238=function(_0x3ae1ca,_0x1633b4){_0x3ae1ca=_0x3ae1ca-0x0;let _0x22383b=a9_0x1633[_0x3ae1ca];return _0x22383b;};const _0x10fc55=a9_0x2238;'use strict';const util=require(_0x10fc55('0x17')),path=require(_0x10fc55('0x37')),_=require(_0x10fc55('0x31')),squel=require('squel'),qs=require('../../components/parsers/qs'),logger=require(_0x10fc55('0x1a'))(_0x10fc55('0x11')),db=require(_0x10fc55('0x86'))['db'],dbH=require(_0x10fc55('0x86'))[_0x10fc55('0xa')],{Op,ValidationErrorItem,QueryTypes}=require(_0x10fc55('0x46'));function respondWithResult(_0x8fa80d,_0x2a8aaf){return _0x2a8aaf=_0x2a8aaf||0xc8,function(_0x7b2979){const _0x6cc53=a9_0x2238;if(_0x7b2979)return _0x8fa80d[_0x6cc53('0x14')](_0x2a8aaf)[_0x6cc53('0xd')](_0x7b2979);};}function respondWithFilteredResult(_0x14092b,_0x361d21){return function(_0x2272af){const _0x54bcb5=a9_0x2238;if(_0x2272af){const _0x2f14ae=_0x2272af['count'],_0x14bb6c=_0x361d21[_0x54bcb5('0x76')];let _0x28251c=_0x361d21[_0x54bcb5('0x76')]+_0x361d21[_0x54bcb5('0x23')],_0x87550d;return _0x28251c>=_0x2f14ae?(_0x28251c=_0x2f14ae,_0x87550d=0xc8):_0x87550d=0xce,_0x14092b[_0x54bcb5('0x14')](_0x87550d),_0x14092b[_0x54bcb5('0x6f')](_0x54bcb5('0x9'),_0x14bb6c+'-'+_0x28251c+'/'+_0x2f14ae)[_0x54bcb5('0xd')](_0x2272af);}return null;};}function saveUpdates(_0x491ab5){return function(_0x291f7d){const _0x5c37c0=a9_0x2238;if(_0x291f7d)return _0x291f7d['update'](_0x491ab5)[_0x5c37c0('0x57')](function(_0x1af2c7){return _0x1af2c7;});return null;};}function removeEntity(_0x35c435){return function(_0x46ff8f){const _0x31ea59=a9_0x2238;if(_0x46ff8f)return _0x46ff8f[_0x31ea59('0x4e')]()['then'](function(){const _0xb36f5c=_0x31ea59,_0x54e27e=_0x46ff8f['get']({'plain':!![]}),_0xc86b3f=_0xb36f5c('0x22');return db[_0xb36f5c('0x78')][_0xb36f5c('0x4e')]({'where':{'type':_0xc86b3f,'resourceId':_0x54e27e['id']}})[_0xb36f5c('0x57')](function(){return _0x46ff8f;});})[_0x31ea59('0x57')](function(){const _0x4d6e13=_0x31ea59;_0x35c435['status'](0xcc)[_0x4d6e13('0x4d')]();});};}function handleEntityNotFound(_0x273214){return function(_0x248337){const _0x2a0236=a9_0x2238;return!_0x248337&&_0x273214[_0x2a0236('0x1e')](0x194),_0x248337;};}function handleError(_0x23a358,_0x35fa69){return _0x35fa69=_0x35fa69||0x1f4,function(_0x5eb9dd){const _0x227a8d=a9_0x2238;logger[_0x227a8d('0x50')](_0x5eb9dd[_0x227a8d('0x5b')]),_0x5eb9dd['name']&&delete _0x5eb9dd[_0x227a8d('0x6d')],_0x23a358[_0x227a8d('0x14')](_0x35fa69)[_0x227a8d('0x5d')](_0x5eb9dd);};}exports['index']=function(_0x50d57f,_0x1b719c){const _0xd2165b=_0x10fc55;let _0x1295cb={};const _0x107511={},_0x20cbf9={'count':0x0,'rows':[]},_0x36bc12=_['map'](db['AnalyticDefaultReport']['rawAttributes'],function(_0x149743){const _0xc1f32=a9_0x2238;return{'name':_0x149743[_0xc1f32('0x13')],'type':_0x149743['type'][_0xc1f32('0x7a')]};});_0x107511['model']=_[_0xd2165b('0x26')](_0x36bc12,'name'),_0x107511[_0xd2165b('0x7')]=_['keys'](_0x50d57f[_0xd2165b('0x7')]),_0x107511['filters']=_['intersection'](_0x107511[_0xd2165b('0x3')],_0x107511['query']),_0x1295cb[_0xd2165b('0x3a')]=_[_0xd2165b('0x84')](_0x107511['model'],qs['fields'](_0x50d57f[_0xd2165b('0x7')][_0xd2165b('0x1')])),_0x1295cb[_0xd2165b('0x3a')]=_0x1295cb['attributes'][_0xd2165b('0x4f')]?_0x1295cb[_0xd2165b('0x3a')]:_0x107511[_0xd2165b('0x3')];typeof _0x50d57f[_0xd2165b('0x7')][_0xd2165b('0x16')]==='undefined'&&(_0x1295cb[_0xd2165b('0x23')]=qs['limit'](_0x50d57f[_0xd2165b('0x7')][_0xd2165b('0x23')]),_0x1295cb['offset']=qs['offset'](_0x50d57f[_0xd2165b('0x7')]['offset']));_0x1295cb[_0xd2165b('0x44')]=qs['sort'](_0x50d57f[_0xd2165b('0x7')][_0xd2165b('0x35')]),_0x1295cb[_0xd2165b('0x19')]=qs[_0xd2165b('0x80')](_[_0xd2165b('0xe')](_0x50d57f[_0xd2165b('0x7')],_0x107511['filters']),_0x36bc12);_0x50d57f[_0xd2165b('0x7')]['filter']&&(_0x1295cb['where']=_[_0xd2165b('0x67')](_0x1295cb[_0xd2165b('0x19')],{[Op['or']]:_[_0xd2165b('0x26')](_0x36bc12,function(_0xe70b60){const _0x40dfee=_0xd2165b;if(_0xe70b60[_0x40dfee('0x2a')]!==_0x40dfee('0x3e')){const _0x24556e={};return _0x24556e[_0xe70b60['name']]={[Op[_0x40dfee('0x61')]]:'%'+_0x50d57f['query'][_0x40dfee('0xc')]+'%'},_0x24556e;}})}));_0x1295cb=_[_0xd2165b('0x67')]({},_0x1295cb,_0x50d57f[_0xd2165b('0x32')]);const _0x3a2aae={'where':_0x1295cb[_0xd2165b('0x19')]};return db[_0xd2165b('0x82')][_0xd2165b('0x36')](_0x3a2aae)['then'](function(_0x1f07df){const _0x162919=_0xd2165b;return _0x20cbf9['count']=_0x1f07df,_0x50d57f[_0x162919('0x7')][_0x162919('0x3f')]&&(_0x1295cb[_0x162919('0x4')]=[{'all':!![]}]),db[_0x162919('0x82')][_0x162919('0x25')](_0x1295cb);})[_0xd2165b('0x57')](function(_0x512b23){const _0x4d5f27=_0xd2165b;return _0x20cbf9[_0x4d5f27('0x4a')]=_0x512b23,_0x20cbf9;})['then'](respondWithFilteredResult(_0x1b719c,_0x1295cb))[_0xd2165b('0x38')](handleError(_0x1b719c,null));},exports[_0x10fc55('0x1b')]=function(_0x49d7e4,_0x4fef97){const _0x4ba7fc=_0x10fc55;let _0x4b79cf={'raw':!![],'where':{'id':_0x49d7e4['params']['id']}};const _0x5a9ba5={};return _0x5a9ba5['model']=_[_0x4ba7fc('0x42')](db[_0x4ba7fc('0x82')][_0x4ba7fc('0x5e')]),_0x5a9ba5[_0x4ba7fc('0x7')]=_['keys'](_0x49d7e4['query']),_0x5a9ba5[_0x4ba7fc('0x80')]=_[_0x4ba7fc('0x84')](_0x5a9ba5[_0x4ba7fc('0x3')],_0x5a9ba5[_0x4ba7fc('0x7')]),_0x4b79cf['attributes']=_['intersection'](_0x5a9ba5[_0x4ba7fc('0x3')],qs['fields'](_0x49d7e4[_0x4ba7fc('0x7')][_0x4ba7fc('0x1')])),_0x4b79cf['attributes']=_0x4b79cf['attributes'][_0x4ba7fc('0x4f')]?_0x4b79cf['attributes']:_0x5a9ba5[_0x4ba7fc('0x3')],_0x49d7e4['query'][_0x4ba7fc('0x3f')]&&(_0x4b79cf[_0x4ba7fc('0x4')]=[{'all':!![]}]),_0x4b79cf=_[_0x4ba7fc('0x67')]({},_0x4b79cf,_0x49d7e4[_0x4ba7fc('0x32')]),db[_0x4ba7fc('0x82')][_0x4ba7fc('0x3b')](_0x4b79cf)[_0x4ba7fc('0x57')](handleEntityNotFound(_0x4fef97,null))[_0x4ba7fc('0x57')](respondWithResult(_0x4fef97,null))['catch'](handleError(_0x4fef97,null));},exports[_0x10fc55('0x18')]=function(_0x10b6ee,_0x4662ae){const _0x390cf7=_0x10fc55;return db[_0x390cf7('0x82')][_0x390cf7('0x18')](_0x10b6ee['body'],{})[_0x390cf7('0x57')](function(_0x5d0f85){const _0x323f2a=_0x390cf7,_0x4d008d=_0x10b6ee['user'][_0x323f2a('0x6c')]({'plain':!![]});if(!_0x4d008d)throw new Error(_0x323f2a('0x3c'));if(_0x4d008d[_0x323f2a('0x4c')]==='user'){const _0x3a7260=_0x5d0f85[_0x323f2a('0x6c')]({'plain':!![]}),_0xf549ad=_0x323f2a('0x85');return db[_0x323f2a('0x2b')][_0x323f2a('0x3b')]({'where':{'name':_0xf549ad,'userProfileId':_0x4d008d['userProfileId']},'raw':!![]})[_0x323f2a('0x57')](function(_0x4e21a3){const _0x1d6fa3=_0x323f2a;return _0x4e21a3&&_0x4e21a3[_0x1d6fa3('0x51')]===0x0?db[_0x1d6fa3('0x78')][_0x1d6fa3('0x18')]({'name':_0x3a7260[_0x1d6fa3('0x6d')],'resourceId':_0x3a7260['id'],'type':_0x1d6fa3('0x22'),'sectionId':_0x4e21a3['id']},{})[_0x1d6fa3('0x57')](function(){return _0x5d0f85;}):_0x5d0f85;})[_0x323f2a('0x38')](function(_0x3b44b0){const _0x402c07=_0x323f2a;logger[_0x402c07('0x50')](_0x402c07('0x39'),_0x3b44b0);throw _0x3b44b0;});}return _0x5d0f85;})['then'](respondWithResult(_0x4662ae,0xc9))[_0x390cf7('0x38')](handleError(_0x4662ae,null));},exports['update']=function(_0x1acaf3,_0x107678){const _0x274efd=_0x10fc55;return _0x1acaf3[_0x274efd('0x34')]['id']&&delete _0x1acaf3[_0x274efd('0x34')]['id'],db[_0x274efd('0x82')]['findOne']({'where':{'id':_0x1acaf3[_0x274efd('0x83')]['id']}})['then'](handleEntityNotFound(_0x107678,null))['then'](saveUpdates(_0x1acaf3[_0x274efd('0x34')],null))[_0x274efd('0x57')](respondWithResult(_0x107678,null))[_0x274efd('0x38')](handleError(_0x107678,null));},exports['destroy']=function(_0x464815,_0x1cd98c){const _0x1a4dc1=_0x10fc55;return db[_0x1a4dc1('0x82')][_0x1a4dc1('0x3b')]({'where':{'id':_0x464815[_0x1a4dc1('0x83')]['id']}})['then'](handleEntityNotFound(_0x1cd98c,null))[_0x1a4dc1('0x57')](removeEntity(_0x1cd98c,null))[_0x1a4dc1('0x38')](handleError(_0x1cd98c,null));},exports['preview']=function(_0x547db4,_0x3f3415){const _0x2eb175=_0x10fc55,_0x595c94=0xa,_0x2d0530=[_0x2eb175('0x2c'),'left_join','right_join','cross_join'],_0x77adcc={'SUM':_0x2eb175('0x74'),'COUNT':_0x2eb175('0x6b'),'COUNT\x20DISTINCT':_0x2eb175('0x2d'),'MAX':_0x2eb175('0x7b'),'MIN':_0x2eb175('0x52'),'AVG':_0x2eb175('0x10'),'GROUP_CONCAT':_0x2eb175('0x69'),'GROUP_CONCAT\x20ASC':_0x2eb175('0x63'),'GROUP_CONCAT\x20DESC':_0x2eb175('0xb')},_0x2905a8={'SEC_TO_TIME':_0x2eb175('0x8'),'DATE':'DATE(%s)','HOUR':_0x2eb175('0x48'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x2eb175('0x60')},_0x2bfb08=function(_0x568579){const _0x1e6a67=_0x2eb175;return!_[_0x1e6a67('0x7d')](['IS\x20NULL',_0x1e6a67('0x49'),_0x1e6a67('0x77'),_0x1e6a67('0x7f')],_0x568579);},_0x92e971=function(_0x5754e3){const _0x4d5589=_0x2eb175;if(!_0x5754e3||!_0x5754e3['rules'][_0x4d5589('0x4f')])return'';let _0x95efd0='(';for(let _0xf60f6c=0x0;_0xf60f6c<_0x5754e3[_0x4d5589('0x53')][_0x4d5589('0x4f')];_0xf60f6c+=0x1){_0xf60f6c>0x0&&(_0x95efd0+='\x20'+_0x5754e3['operator']+'\x20'),_0x95efd0+=_0x5754e3['rules'][_0xf60f6c][_0x4d5589('0x45')]?_0x92e971(_0x5754e3[_0x4d5589('0x53')][_0xf60f6c][_0x4d5589('0x45')]):_0x5754e3[_0x4d5589('0x53')][_0xf60f6c]['field']+'\x20'+_0x5754e3[_0x4d5589('0x53')][_0xf60f6c]['condition']+(_0x2bfb08(_0x5754e3[_0x4d5589('0x53')][_0xf60f6c][_0x4d5589('0x56')])?'\x20'+_0x5754e3[_0x4d5589('0x53')][_0xf60f6c]['value']:'');}return _0x95efd0+')';};let _0x4da5f4={'where':{'id':_0x547db4[_0x2eb175('0x83')]['id']}},_0x14d6e7,_0x3b0c7e,_0x5b430b;return _0x4da5f4=_[_0x2eb175('0x67')]({},_0x4da5f4,_0x547db4[_0x2eb175('0x32')]),db[_0x2eb175('0x82')][_0x2eb175('0x3b')](_0x4da5f4)[_0x2eb175('0x57')](function(_0x23e4bc){if(_0x23e4bc)return _0x14d6e7=_0x23e4bc,_0x23e4bc['getFields']();return null;})[_0x2eb175('0x57')](function(_0x2d3eac){const _0x3244f8=_0x2eb175;if(_0x2d3eac){if(!_0x2d3eac[_0x3244f8('0x4f')])throw new ValidationErrorItem(_0x3244f8('0x12'),0x193);return _0x3b0c7e=_0x2d3eac,db[_0x3244f8('0x7e')][_0x3244f8('0x25')]({'raw':!![]});}return null;})[_0x2eb175('0x57')](function(_0x45b3fe){const _0x8cd560=_0x2eb175;if(_0x45b3fe){_0x5b430b=_['keyBy'](_0x45b3fe,'id');let _0x4623b6;const _0x36e95a=squel['select']();_0x36e95a['from'](_0x14d6e7['table']);for(let _0x594cb1=0x0;_0x594cb1<_0x3b0c7e['length'];_0x594cb1+=0x1){_0x4623b6=_0x3b0c7e[_0x594cb1][_0x8cd560('0x20')]?_0x5b430b[_0x3b0c7e[_0x594cb1][_0x8cd560('0x20')]][_0x8cd560('0x66')]:_0x3b0c7e[_0x594cb1][_0x8cd560('0x29')],_0x4623b6=_0x3b0c7e[_0x594cb1][_0x8cd560('0x6')]?_['replace'](_0x77adcc[_0x3b0c7e[_0x594cb1]['function']],'%s',_0x4623b6):_0x4623b6,_0x4623b6=_0x3b0c7e[_0x594cb1][_0x8cd560('0x3d')]?_[_0x8cd560('0x88')](_0x2905a8[_0x3b0c7e[_0x594cb1][_0x8cd560('0x3d')]],'%s',_0x4623b6):_0x4623b6,_0x3b0c7e[_0x594cb1][_0x8cd560('0x89')]&&_0x36e95a[_0x8cd560('0x45')](_0x4623b6),_0x3b0c7e[_0x594cb1][_0x8cd560('0x1d')]&&_0x36e95a[_0x8cd560('0x44')](_0x4623b6,_0x3b0c7e[_0x594cb1][_0x8cd560('0x1d')]===_0x8cd560('0x58')?![]:!![]),_0x36e95a[_0x8cd560('0x29')](_0x4623b6,_0x3b0c7e[_0x594cb1]['alias']||_0x4623b6);}if(_0x14d6e7[_0x8cd560('0x47')]){_0x14d6e7[_0x8cd560('0x47')]=JSON['parse'](_0x14d6e7[_0x8cd560('0x47')]);for(let _0x4430be=0x0;_0x4430be<_0x14d6e7[_0x8cd560('0x47')][_0x8cd560('0x4f')];_0x4430be+=0x1){_0x14d6e7[_0x8cd560('0x47')][_0x4430be][_0x8cd560('0x2a')]&&_[_0x8cd560('0x7d')](_0x2d0530,_0x14d6e7['joins'][_0x4430be][_0x8cd560('0x2a')])&&_0x14d6e7[_0x8cd560('0x47')][_0x4430be][_0x8cd560('0x5c')]&&_0x14d6e7[_0x8cd560('0x47')][_0x4430be][_0x8cd560('0x70')]&&_0x14d6e7[_0x8cd560('0x47')][_0x4430be]['foreignKey']&&_0x36e95a[_0x14d6e7[_0x8cd560('0x47')][_0x4430be]['type']](_0x14d6e7[_0x8cd560('0x47')][_0x4430be][_0x8cd560('0x70')],null,util[_0x8cd560('0x3d')]('%s.%s\x20=\x20%s.%s',_0x14d6e7[_0x8cd560('0x2f')],_0x14d6e7[_0x8cd560('0x47')][_0x4430be][_0x8cd560('0x5c')],_0x14d6e7[_0x8cd560('0x47')][_0x4430be]['foreignTable'],_0x14d6e7[_0x8cd560('0x47')][_0x4430be]['foreignKey']));}}return _0x14d6e7[_0x8cd560('0x4b')]&&(_0x14d6e7['conditions']=JSON[_0x8cd560('0x1f')](_0x14d6e7['conditions']),_0x36e95a[_0x8cd560('0x19')](_0x92e971(_0x14d6e7[_0x8cd560('0x4b')][_0x8cd560('0x45')]))),_0x36e95a[_0x8cd560('0x23')](_0x595c94),_0x36e95a[_0x8cd560('0x76')](0x0),logger[_0x8cd560('0x62')]('Limited\x20Query:',_0x36e95a['toString']()),db[_0x8cd560('0x46')][_0x8cd560('0x7')](_0x36e95a[_0x8cd560('0x2e')](),{'type':QueryTypes['SELECT']});}})['then'](respondWithResult(_0x3f3415,null))[_0x2eb175('0x38')](handleError(_0x3f3415,null));};function runReport(_0x47beb7,_0x256cec,_0x381849){const _0xca04e3=_0x10fc55,_0x3f654d=_0x256cec[_0xca04e3('0x6d')],_0x1c528d=0xa,_0x31ec29=['join',_0xca04e3('0x5'),_0xca04e3('0x33'),'cross_join'],_0x1bfad2={'SUM':_0xca04e3('0x74'),'COUNT':_0xca04e3('0x6b'),'COUNT\x20DISTINCT':_0xca04e3('0x2d'),'MAX':_0xca04e3('0x7b'),'MIN':'MIN(%s)','AVG':_0xca04e3('0x10'),'GROUP_CONCAT':_0xca04e3('0x69'),'GROUP_CONCAT\x20ASC':_0xca04e3('0x63'),'GROUP_CONCAT\x20DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'},_0x39d3aa={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':'DATE(%s)','HOUR':_0xca04e3('0x48'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xca04e3('0x60')},_0x9d141a=function(_0x22b3d5){const _0x4958ac=_0xca04e3;return!_[_0x4958ac('0x7d')](['IS\x20NULL',_0x4958ac('0x49'),_0x4958ac('0x77'),'IS\x20NOT\x20EMPTY'],_0x22b3d5);},_0xdbc6ec=function(_0x376eb0){const _0x300cdc=_0xca04e3;if(!_0x376eb0||!_0x376eb0['rules']['length'])return'';let _0x416046='(';for(let _0x57a137=0x0;_0x57a137<_0x376eb0[_0x300cdc('0x53')][_0x300cdc('0x4f')];_0x57a137+=0x1){_0x57a137>0x0&&(_0x416046+='\x20'+_0x376eb0[_0x300cdc('0x59')]+'\x20'),_0x416046+=_0x376eb0[_0x300cdc('0x53')][_0x57a137][_0x300cdc('0x45')]?_0xdbc6ec(_0x376eb0[_0x300cdc('0x53')][_0x57a137][_0x300cdc('0x45')]):_0x376eb0[_0x300cdc('0x53')][_0x57a137][_0x300cdc('0x29')]+'\x20'+_0x376eb0[_0x300cdc('0x53')][_0x57a137][_0x300cdc('0x56')]+(_0x9d141a(_0x376eb0[_0x300cdc('0x53')][_0x57a137][_0x300cdc('0x56')])?'\x20'+_0x376eb0[_0x300cdc('0x53')][_0x57a137]['value']:'');}return _0x416046+')';};let _0x7ccb1d={'where':{'id':_0x47beb7['id']}},_0x22f40c,_0x4339e4,_0xcf40f3,_0x31f179,_0x54dc66;return _0x7ccb1d=_[_0xca04e3('0x67')]({},_0x7ccb1d,_0x381849),db[_0xca04e3('0x82')][_0xca04e3('0x3b')](_0x7ccb1d)[_0xca04e3('0x57')](function(_0x1b124d){if(_0x1b124d)return _0x22f40c=_0x1b124d,_0x1b124d['getFields']();return null;})[_0xca04e3('0x57')](function(_0x13950f){const _0x334705=_0xca04e3;if(_0x13950f){if(!_0x13950f[_0x334705('0x4f')])throw new ValidationErrorItem('Please\x20insert\x20at\x20least\x20one\x20field',0x193);return _0x4339e4=_0x13950f,db[_0x334705('0x7e')][_0x334705('0x25')]({'raw':!![]});}return null;})[_0xca04e3('0x57')](function(_0x2b8ccf){const _0x2196b5=_0xca04e3;if(_0x2b8ccf){_0xcf40f3=_['keyBy'](_0x2b8ccf,'id');let _0x38b10b;const _0x245632=squel[_0x2196b5('0x54')]();_0x245632[_0x2196b5('0x2')](_0x22f40c['table']);for(let _0xa7c581=0x0;_0xa7c581<_0x4339e4['length'];_0xa7c581+=0x1){_0x38b10b=_0x4339e4[_0xa7c581][_0x2196b5('0x20')]?_0xcf40f3[_0x4339e4[_0xa7c581][_0x2196b5('0x20')]][_0x2196b5('0x66')]:_0x4339e4[_0xa7c581]['field'],_0x38b10b=_0x4339e4[_0xa7c581][_0x2196b5('0x6')]?_[_0x2196b5('0x88')](_0x1bfad2[_0x4339e4[_0xa7c581][_0x2196b5('0x6')]],'%s',_0x38b10b):_0x38b10b,_0x38b10b=_0x4339e4[_0xa7c581][_0x2196b5('0x3d')]?_[_0x2196b5('0x88')](_0x39d3aa[_0x4339e4[_0xa7c581]['format']],'%s',_0x38b10b):_0x38b10b,_0x4339e4[_0xa7c581]['groupBy']&&_0x245632[_0x2196b5('0x45')](_0x38b10b),_0x4339e4[_0xa7c581][_0x2196b5('0x1d')]&&_0x245632['order'](_0x38b10b,_0x4339e4[_0xa7c581][_0x2196b5('0x1d')]===_0x2196b5('0x58')?![]:!![]),_0x245632[_0x2196b5('0x29')](_0x38b10b,_0x4339e4[_0xa7c581][_0x2196b5('0x15')]||_0x38b10b);}if(_0x22f40c[_0x2196b5('0x47')]){_0x22f40c[_0x2196b5('0x47')]=JSON[_0x2196b5('0x1f')](_0x22f40c[_0x2196b5('0x47')]);for(let _0x243b7a=0x0;_0x243b7a<_0x22f40c[_0x2196b5('0x47')]['length'];_0x243b7a+=0x1){_0x22f40c[_0x2196b5('0x47')][_0x243b7a][_0x2196b5('0x2a')]&&_[_0x2196b5('0x7d')](_0x31ec29,_0x22f40c[_0x2196b5('0x47')][_0x243b7a][_0x2196b5('0x2a')])&&_0x22f40c[_0x2196b5('0x47')][_0x243b7a][_0x2196b5('0x5c')]&&_0x22f40c[_0x2196b5('0x47')][_0x243b7a][_0x2196b5('0x70')]&&_0x22f40c[_0x2196b5('0x47')][_0x243b7a][_0x2196b5('0x79')]&&_0x245632[_0x22f40c[_0x2196b5('0x47')][_0x243b7a][_0x2196b5('0x2a')]](_0x22f40c['joins'][_0x243b7a][_0x2196b5('0x70')],null,util[_0x2196b5('0x3d')]('%s.%s\x20=\x20%s.%s',_0x22f40c[_0x2196b5('0x2f')],_0x22f40c[_0x2196b5('0x47')][_0x243b7a][_0x2196b5('0x5c')],_0x22f40c[_0x2196b5('0x47')][_0x243b7a][_0x2196b5('0x70')],_0x22f40c[_0x2196b5('0x47')][_0x243b7a][_0x2196b5('0x79')]));}}return _0x22f40c[_0x2196b5('0x4b')]&&(_0x22f40c['conditions']=JSON[_0x2196b5('0x1f')](_0x22f40c[_0x2196b5('0x4b')]),_0x245632[_0x2196b5('0x19')](_0xdbc6ec(_0x22f40c['conditions']['group']))),_0x54dc66=_0x245632[_0x2196b5('0x55')](),_0x245632[_0x2196b5('0x23')](_0x1c528d),_0x245632['offset'](0x0),logger[_0x2196b5('0x62')]('Limited\x20Query:',_0x245632[_0x2196b5('0x2e')]()),db[_0x2196b5('0x46')]['query'](_0x245632[_0x2196b5('0x2e')](),{'type':QueryTypes[_0x2196b5('0x24')]});}})['then'](function(_0x32bce4){const _0x2fab47=_0xca04e3;if(!_0x32bce4[_0x2fab47('0x4f')])throw new ValidationErrorItem('No\x20available\x20data',0xcc);if(_0x256cec[_0x2fab47('0x7c')]===_0x2fab47('0x73'))return null;const _0x3cd23b=_[_0x2fab47('0x67')](_0x256cec,{'name':_0x256cec['fullPath']||_0x256cec[_0x2fab47('0x6d')]||_0x22f40c[_0x2fab47('0x6d')],'basename':_0x3f654d,'savename':util[_0x2fab47('0x3d')]('%s-%s.%s',_0x256cec[_0x2fab47('0x6d')]||_0x22f40c[_0x2fab47('0x6d')],require(_0x2fab47('0x65'))[_0x2fab47('0x75')](0x4),_0x256cec[_0x2fab47('0x7c')]||'csv'),'reportId':_0x22f40c['id'],'reportType':_0x2fab47('0x40')});return db['AnalyticExtractedReport'][_0x2fab47('0x18')](_0x3cd23b,{'raw':!![]});})[_0xca04e3('0x57')](function(_0x3ca2bd){const _0x725b92=_0xca04e3;_0x22f40c[_0x725b92('0x2f')]===_0x725b92('0x5f')?_0x54dc66[_0x725b92('0x19')](_0x22f40c[_0x725b92('0x2f')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x256cec[_0x725b92('0x68')],_0x256cec['endDate']):_0x54dc66[_0x725b92('0x19')](_0x22f40c['table']+_0x725b92('0x43'),_0x256cec['startDate'],_0x256cec['endDate']);if(_0x3ca2bd)return logger[_0x725b92('0x72')]('Run\x20Query:',_0x54dc66[_0x725b92('0x2e')]()),require(_0x725b92('0x21'))['fork'](path[_0x725b92('0x2c')](__dirname,'../../components/export/',_0x3ca2bd['output']),[_0x3ca2bd['id'],_0x54dc66['toString'](),path[_0x725b92('0x2c')](__dirname,_0x725b92('0x1c'),_0x3ca2bd[_0x725b92('0x87')]),_0x3f654d]),_0x3ca2bd;else{const _0x85578a=squel[_0x725b92('0x54')]();return _0x85578a['from']('('+_0x54dc66[_0x725b92('0x2e')]()+')',_0x725b92('0x6e')),_0x85578a[_0x725b92('0x29')](_0x725b92('0x27'),_0x725b92('0x36')),_0x54dc66[_0x725b92('0x23')](_0x256cec[_0x725b92('0x23')]||_0x1c528d),_0x54dc66[_0x725b92('0x76')](_0x256cec[_0x725b92('0x76')]||0x0),dbH[_0x725b92('0x46')][_0x725b92('0x7')](_0x85578a['toString'](),{'type':dbH[_0x725b92('0x46')][_0x725b92('0x5a')][_0x725b92('0x24')]})['then'](function(_0x41e273){const _0x2e27d0=_0x725b92;return!_0x41e273[_0x2e27d0('0x4f')]?_0x31f179=0x0:_0x31f179=_0x41e273[0x0][_0x2e27d0('0x36')]||0x0,dbH['sequelize'][_0x2e27d0('0x7')](_0x54dc66[_0x2e27d0('0x2e')](),{'type':dbH[_0x2e27d0('0x46')]['QueryTypes'][_0x2e27d0('0x24')]});})[_0x725b92('0x57')](function(_0x5a9b64){return{'rows':_0x5a9b64||[],'count':_0x31f179};});}});}exports[_0x10fc55('0x28')]=function(_0x3d1e82,_0x52386a){const _0x3f843c=_0x10fc55;return runReport(_0x3d1e82[_0x3f843c('0x83')],_0x3d1e82[_0x3f843c('0x7')],_0x3d1e82[_0x3f843c('0x32')])[_0x3f843c('0x57')](respondWithResult(_0x52386a,null))[_0x3f843c('0x38')](handleError(_0x52386a,null));},exports[_0x10fc55('0x41')]=runReport,exports['query']=function(_0x557e6a,_0x3eece7){const _0x194b32=_0x10fc55,_0x18ad19=0xa,_0x8d0dfa=[_0x194b32('0x2c'),_0x194b32('0x5'),_0x194b32('0x33'),_0x194b32('0x6a')],_0x528939={'SUM':_0x194b32('0x74'),'COUNT':_0x194b32('0x6b'),'COUNT\x20DISTINCT':_0x194b32('0x2d'),'MAX':_0x194b32('0x7b'),'MIN':_0x194b32('0x52'),'AVG':_0x194b32('0x10'),'GROUP_CONCAT':_0x194b32('0x69'),'GROUP_CONCAT\x20ASC':_0x194b32('0x63'),'GROUP_CONCAT\x20DESC':_0x194b32('0xb')},_0x37564e={'SEC_TO_TIME':_0x194b32('0x8'),'DATE':_0x194b32('0x81'),'HOUR':_0x194b32('0x48'),'ROUND':_0x194b32('0xf'),'UNIX_TIMESTAMP':_0x194b32('0x60')},_0x97963e=function(_0x4685f3){const _0x4a87b3=_0x194b32;return!_['includes']([_0x4a87b3('0x0'),'IS\x20NOT\x20NULL',_0x4a87b3('0x77'),'IS\x20NOT\x20EMPTY'],_0x4685f3);},_0x137bad=function(_0x305236){const _0x7e4705=_0x194b32;if(!_0x305236||!_0x305236['rules'][_0x7e4705('0x4f')])return'';let _0x32aabd='(';for(let _0x41ca27=0x0;_0x41ca27<_0x305236[_0x7e4705('0x53')][_0x7e4705('0x4f')];_0x41ca27+=0x1){_0x41ca27>0x0&&(_0x32aabd+='\x20'+_0x305236[_0x7e4705('0x59')]+'\x20'),_0x32aabd+=_0x305236['rules'][_0x41ca27][_0x7e4705('0x45')]?_0x137bad(_0x305236['rules'][_0x41ca27][_0x7e4705('0x45')]):_0x305236['rules'][_0x41ca27]['field']+'\x20'+_0x305236['rules'][_0x41ca27][_0x7e4705('0x56')]+(_0x97963e(_0x305236[_0x7e4705('0x53')][_0x41ca27][_0x7e4705('0x56')])?'\x20'+_0x305236['rules'][_0x41ca27]['value']:'');}return _0x32aabd+')';};let _0x3eca3f={'where':{'id':_0x557e6a[_0x194b32('0x83')]['id']}},_0x403110,_0x43d6c8,_0x3ace40,_0xd14a8c;return _0x3eca3f=_[_0x194b32('0x67')]({},_0x3eca3f,_0x557e6a[_0x194b32('0x32')]),db['AnalyticDefaultReport'][_0x194b32('0x3b')](_0x3eca3f)[_0x194b32('0x57')](function(_0x41c06c){const _0x225771=_0x194b32;if(_0x41c06c)return _0x403110=_0x41c06c,_0x41c06c[_0x225771('0x64')]();return null;})[_0x194b32('0x57')](function(_0x497913){const _0x4e679b=_0x194b32;if(_0x497913){if(!_0x497913['length'])throw new ValidationErrorItem(_0x4e679b('0x12'),0x193);return _0x43d6c8=_0x497913,db[_0x4e679b('0x7e')][_0x4e679b('0x25')]({'raw':!![]});}return null;})[_0x194b32('0x57')](function(_0xe41cec){const _0x10563d=_0x194b32;if(_0xe41cec){_0x3ace40=_['keyBy'](_0xe41cec,'id');let _0x5c9f97;const _0x2ce9f4=squel[_0x10563d('0x54')]();_0x2ce9f4[_0x10563d('0x2')](_0x403110['table']);for(let _0x467c15=0x0;_0x467c15<_0x43d6c8['length'];_0x467c15+=0x1){_0x5c9f97=_0x43d6c8[_0x467c15][_0x10563d('0x20')]?_0x3ace40[_0x43d6c8[_0x467c15][_0x10563d('0x20')]]['metric']:_0x43d6c8[_0x467c15]['field'],_0x5c9f97=_0x43d6c8[_0x467c15][_0x10563d('0x6')]?_[_0x10563d('0x88')](_0x528939[_0x43d6c8[_0x467c15][_0x10563d('0x6')]],'%s',_0x5c9f97):_0x5c9f97,_0x5c9f97=_0x43d6c8[_0x467c15][_0x10563d('0x3d')]?_[_0x10563d('0x88')](_0x37564e[_0x43d6c8[_0x467c15]['format']],'%s',_0x5c9f97):_0x5c9f97,_0x43d6c8[_0x467c15][_0x10563d('0x89')]&&_0x2ce9f4[_0x10563d('0x45')](_0x5c9f97),_0x43d6c8[_0x467c15][_0x10563d('0x1d')]&&_0x2ce9f4[_0x10563d('0x44')](_0x5c9f97,_0x43d6c8[_0x467c15][_0x10563d('0x1d')]===_0x10563d('0x58')?![]:!![]),_0x2ce9f4[_0x10563d('0x29')](_0x5c9f97,_0x43d6c8[_0x467c15][_0x10563d('0x15')]||_0x5c9f97);}if(_0x403110[_0x10563d('0x47')]){_0x403110[_0x10563d('0x47')]=JSON['parse'](_0x403110['joins']);for(let _0x26702f=0x0;_0x26702f<_0x403110[_0x10563d('0x47')][_0x10563d('0x4f')];_0x26702f+=0x1){_0x403110[_0x10563d('0x47')][_0x26702f][_0x10563d('0x2a')]&&_['includes'](_0x8d0dfa,_0x403110[_0x10563d('0x47')][_0x26702f]['type'])&&_0x403110[_0x10563d('0x47')][_0x26702f][_0x10563d('0x5c')]&&_0x403110[_0x10563d('0x47')][_0x26702f][_0x10563d('0x70')]&&_0x403110[_0x10563d('0x47')][_0x26702f]['foreignKey']&&_0x2ce9f4[_0x403110[_0x10563d('0x47')][_0x26702f][_0x10563d('0x2a')]](_0x403110[_0x10563d('0x47')][_0x26702f][_0x10563d('0x70')],null,util[_0x10563d('0x3d')](_0x10563d('0x71'),_0x403110[_0x10563d('0x2f')],_0x403110[_0x10563d('0x47')][_0x26702f][_0x10563d('0x5c')],_0x403110[_0x10563d('0x47')][_0x26702f][_0x10563d('0x70')],_0x403110[_0x10563d('0x47')][_0x26702f][_0x10563d('0x79')]));}}return _0x403110[_0x10563d('0x4b')]&&(_0x403110[_0x10563d('0x4b')]=JSON['parse'](_0x403110['conditions']),_0x2ce9f4[_0x10563d('0x19')](_0x137bad(_0x403110[_0x10563d('0x4b')][_0x10563d('0x45')]))),_0xd14a8c=_0x2ce9f4['clone'](),_0x2ce9f4[_0x10563d('0x23')](_0x18ad19),_0x2ce9f4[_0x10563d('0x76')](0x0),logger['debug'](_0x10563d('0x30'),_0x2ce9f4[_0x10563d('0x2e')]()),db[_0x10563d('0x46')][_0x10563d('0x7')](_0x2ce9f4['toString'](),{'type':QueryTypes['SELECT']});}})['then'](function(){const _0x3939f7=_0x194b32;return{'sql':_0xd14a8c[_0x3939f7('0x2e')]()};})[_0x194b32('0x57')](respondWithResult(_0x3eece7,null))[_0x194b32('0x38')](handleError(_0x3eece7,null));};