Built motion from commit 87cd5f02.|2.5.48
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xd388=['length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','count','rows','catch','params','include','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','preview','join','left_join','right_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','SEC_TO_TIME(%s)','DATE(%s)','includes','IS\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','group','field','condition','getFields','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','findAll','select','from','table','MetricId','metric','replace','function','format','groupBy','orderBy','alias','joins','parse','parentKey','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','conditions','clone','toString','sequelize','SELECT','cross_join','AVG(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','ROUND(%s)','UNIX_TIMESTAMP(%s)','IS\x20NULL','operator','value','keyBy','DESC','web','%s-%s.%s','randomstring','generate','output','csv','custom','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','Run\x20Query:','child_process','fork','../../components/export/','../../files/reports','savename','countTable','COUNT(*)','QueryTypes','run','debug','Limited\x20Query:','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','fs-extra','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','dbH','end','status','json','offset','undefined','limit','set','Content-Range','apply','reject','save','then','get','UserProfileResource','destroy','sendStatus','error','name','index','map','AnalyticCustomReport','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields'];(function(_0x5b5a1a,_0x534424){var _0x20af86=function(_0x2f56d8){while(--_0x2f56d8){_0x5b5a1a['push'](_0x5b5a1a['shift']());}};_0x20af86(++_0x534424);}(_0xd388,0x6c));var _0x8d38=function(_0xef6554,_0x1bf141){_0xef6554=_0xef6554-0x0;var _0x5d17d3=_0xd388[_0xef6554];return _0x5d17d3;};'use strict';var emlformat=require(_0x8d38('0x0'));var rimraf=require(_0x8d38('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x8d38('0x2'));var rp=require(_0x8d38('0x3'));var moment=require(_0x8d38('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x8d38('0x5'));var util=require(_0x8d38('0x6'));var path=require('path');var sox=require(_0x8d38('0x7'));var csv=require(_0x8d38('0x8'));var ejs=require(_0x8d38('0x9'));var fs=require('fs');var fs_extra=require(_0x8d38('0xa'));var _=require('lodash');var squel=require(_0x8d38('0xb'));var crypto=require(_0x8d38('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x8d38('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x8d38('0xe'));var Redis=require(_0x8d38('0xf'));var authService=require(_0x8d38('0x10'));var qs=require(_0x8d38('0x11'));var as=require(_0x8d38('0x12'));var hardwareService=require(_0x8d38('0x13'));var logger=require(_0x8d38('0x14'))(_0x8d38('0x15'));var utils=require(_0x8d38('0x16'));var config=require(_0x8d38('0x17'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var dbH=require(_0x8d38('0x18'))[_0x8d38('0x19')];function respondWithStatusCode(_0x528eee,_0x4ddbf8){_0x4ddbf8=_0x4ddbf8||0xcc;return function(_0x110b84){if(_0x110b84){return _0x528eee['sendStatus'](_0x4ddbf8);}return _0x528eee['status'](_0x4ddbf8)[_0x8d38('0x1a')]();};}function respondWithResult(_0x4cb3ad,_0x5b37dd){_0x5b37dd=_0x5b37dd||0xc8;return function(_0x444e95){if(_0x444e95){return _0x4cb3ad[_0x8d38('0x1b')](_0x5b37dd)[_0x8d38('0x1c')](_0x444e95);}};}function respondWithFilteredResult(_0x24ef09,_0x2b9651){return function(_0x2ae369){if(_0x2ae369){var _0x5c99fe=typeof _0x2b9651[_0x8d38('0x1d')]===_0x8d38('0x1e')&&typeof _0x2b9651[_0x8d38('0x1f')]==='undefined';var _0xce606b=_0x2ae369['count'];var _0x3c3db7=_0x5c99fe?0x0:_0x2b9651['offset'];var _0x3bd55e=_0x5c99fe?_0x2ae369['count']:_0x2b9651[_0x8d38('0x1d')]+_0x2b9651['limit'];var _0x2f5359;if(_0x3bd55e>=_0xce606b){_0x3bd55e=_0xce606b;_0x2f5359=0xc8;}else{_0x2f5359=0xce;}_0x24ef09[_0x8d38('0x1b')](_0x2f5359);return _0x24ef09[_0x8d38('0x20')](_0x8d38('0x21'),_0x3c3db7+'-'+_0x3bd55e+'/'+_0xce606b)[_0x8d38('0x1c')](_0x2ae369);}return null;};}function patchUpdates(_0xbfaade){return function(_0x4149f6){try{jsonpatch[_0x8d38('0x22')](_0x4149f6,_0xbfaade,!![]);}catch(_0x19e3ce){return BPromise[_0x8d38('0x23')](_0x19e3ce);}return _0x4149f6[_0x8d38('0x24')]();};}function saveUpdates(_0x295b4e,_0x259abb){return function(_0xb26881){if(_0xb26881){return _0xb26881['update'](_0x295b4e)[_0x8d38('0x25')](function(_0x457736){return _0x457736;});}return null;};}function removeEntity(_0x5818ac,_0x30c6ca){return function(_0x18cfaf){if(_0x18cfaf){return _0x18cfaf['destroy']()[_0x8d38('0x25')](function(){var _0xd77b2c=_0x18cfaf[_0x8d38('0x26')]({'plain':!![]});var _0xa43cc2='CustomReports';return db[_0x8d38('0x27')][_0x8d38('0x28')]({'where':{'type':_0xa43cc2,'resourceId':_0xd77b2c['id']}})[_0x8d38('0x25')](function(){return _0x18cfaf;});})['then'](function(){_0x5818ac['status'](0xcc)[_0x8d38('0x1a')]();});}};}function handleEntityNotFound(_0x5950f7,_0x41bdb4){return function(_0x254f1b){if(!_0x254f1b){_0x5950f7[_0x8d38('0x29')](0x194);}return _0x254f1b;};}function handleError(_0x4c767b,_0x1e4086){_0x1e4086=_0x1e4086||0x1f4;return function(_0x40ab18){logger[_0x8d38('0x2a')](_0x40ab18['stack']);if(_0x40ab18[_0x8d38('0x2b')]){delete _0x40ab18[_0x8d38('0x2b')];}_0x4c767b['status'](_0x1e4086)['send'](_0x40ab18);};}exports[_0x8d38('0x2c')]=function(_0xa1b71f,_0x2647a7){var _0x3274dd={},_0x42ab4c={},_0x5f1afd={'count':0x0,'rows':[]};var _0x1bc446=_[_0x8d38('0x2d')](db[_0x8d38('0x2e')][_0x8d38('0x2f')],function(_0x273226){return{'name':_0x273226[_0x8d38('0x30')],'type':_0x273226[_0x8d38('0x31')][_0x8d38('0x32')]};});_0x42ab4c[_0x8d38('0x33')]=_[_0x8d38('0x2d')](_0x1bc446,'name');_0x42ab4c[_0x8d38('0x34')]=_[_0x8d38('0x35')](_0xa1b71f[_0x8d38('0x34')]);_0x42ab4c[_0x8d38('0x36')]=_['intersection'](_0x42ab4c[_0x8d38('0x33')],_0x42ab4c[_0x8d38('0x34')]);_0x3274dd[_0x8d38('0x37')]=_[_0x8d38('0x38')](_0x42ab4c[_0x8d38('0x33')],qs[_0x8d38('0x39')](_0xa1b71f[_0x8d38('0x34')][_0x8d38('0x39')]));_0x3274dd[_0x8d38('0x37')]=_0x3274dd[_0x8d38('0x37')][_0x8d38('0x3a')]?_0x3274dd[_0x8d38('0x37')]:_0x42ab4c['model'];if(!_0xa1b71f['query'][_0x8d38('0x3b')](_0x8d38('0x3c'))){_0x3274dd[_0x8d38('0x1f')]=qs[_0x8d38('0x1f')](_0xa1b71f[_0x8d38('0x34')]['limit']);_0x3274dd[_0x8d38('0x1d')]=qs[_0x8d38('0x1d')](_0xa1b71f['query'][_0x8d38('0x1d')]);}_0x3274dd[_0x8d38('0x3d')]=qs[_0x8d38('0x3e')](_0xa1b71f[_0x8d38('0x34')]['sort']);_0x3274dd[_0x8d38('0x3f')]=qs[_0x8d38('0x36')](_[_0x8d38('0x40')](_0xa1b71f[_0x8d38('0x34')],_0x42ab4c[_0x8d38('0x36')]),_0x1bc446);if(_0xa1b71f[_0x8d38('0x34')][_0x8d38('0x41')]){_0x3274dd[_0x8d38('0x3f')]=_['merge'](_0x3274dd[_0x8d38('0x3f')],{'$or':_[_0x8d38('0x2d')](_0x1bc446,function(_0x3d651c){if(_0x3d651c['type']!==_0x8d38('0x42')){var _0x2d4c18={};_0x2d4c18[_0x3d651c[_0x8d38('0x2b')]]={'$like':'%'+_0xa1b71f['query'][_0x8d38('0x41')]+'%'};return _0x2d4c18;}})});}_0x3274dd=_[_0x8d38('0x43')]({},_0x3274dd,_0xa1b71f['options']);var _0x2ade12={'where':_0x3274dd[_0x8d38('0x3f')]};return db[_0x8d38('0x2e')]['count'](_0x2ade12)['then'](function(_0x1f60b1){_0x5f1afd[_0x8d38('0x44')]=_0x1f60b1;if(_0xa1b71f[_0x8d38('0x34')]['includeAll']){_0x3274dd['include']=[{'all':!![]}];}return db[_0x8d38('0x2e')]['findAll'](_0x3274dd);})[_0x8d38('0x25')](function(_0x319ce1){_0x5f1afd[_0x8d38('0x45')]=_0x319ce1;return _0x5f1afd;})['then'](respondWithFilteredResult(_0x2647a7,_0x3274dd))[_0x8d38('0x46')](handleError(_0x2647a7,null));};exports['show']=function(_0xe12a71,_0xc07e0){var _0xa1003a={'raw':![],'where':{'id':_0xe12a71[_0x8d38('0x47')]['id']}},_0x2ac4f8={};_0x2ac4f8[_0x8d38('0x33')]=_[_0x8d38('0x35')](db[_0x8d38('0x2e')][_0x8d38('0x2f')]);_0x2ac4f8['query']=_[_0x8d38('0x35')](_0xe12a71['query']);_0x2ac4f8[_0x8d38('0x36')]=_['intersection'](_0x2ac4f8['model'],_0x2ac4f8[_0x8d38('0x34')]);_0xa1003a[_0x8d38('0x37')]=_['intersection'](_0x2ac4f8['model'],qs[_0x8d38('0x39')](_0xe12a71[_0x8d38('0x34')][_0x8d38('0x39')]));_0xa1003a[_0x8d38('0x37')]=_0xa1003a[_0x8d38('0x37')][_0x8d38('0x3a')]?_0xa1003a['attributes']:_0x2ac4f8[_0x8d38('0x33')];if(_0xe12a71[_0x8d38('0x34')]['includeAll']){_0xa1003a[_0x8d38('0x48')]=[{'all':!![]}];}_0xa1003a=_[_0x8d38('0x43')]({},_0xa1003a,_0xe12a71[_0x8d38('0x49')]);return db[_0x8d38('0x2e')][_0x8d38('0x4a')](_0xa1003a)['then'](handleEntityNotFound(_0xc07e0,null))[_0x8d38('0x25')](respondWithResult(_0xc07e0,null))['catch'](handleError(_0xc07e0,null));};exports['create']=function(_0xb07b0d,_0x427279){return db['AnalyticCustomReport'][_0x8d38('0x4b')](_0xb07b0d[_0x8d38('0x4c')],{})[_0x8d38('0x25')](function(_0x183816){var _0x41fd13=_0xb07b0d[_0x8d38('0x4d')][_0x8d38('0x26')]({'plain':!![]});if(!_0x41fd13)throw new Error(_0x8d38('0x4e'));if(_0x41fd13[_0x8d38('0x4f')]==='user'){var _0xc3675c=_0x183816['get']({'plain':!![]});var _0x3d36de='Reports';return db[_0x8d38('0x50')][_0x8d38('0x4a')]({'where':{'name':_0x3d36de,'userProfileId':_0x41fd13[_0x8d38('0x51')]},'raw':!![]})[_0x8d38('0x25')](function(_0x481433){if(_0x481433&&_0x481433[_0x8d38('0x52')]===0x0){return db[_0x8d38('0x27')][_0x8d38('0x4b')]({'name':_0xc3675c['name'],'resourceId':_0xc3675c['id'],'type':'CustomReports','sectionId':_0x481433['id']},{})[_0x8d38('0x25')](function(){return _0x183816;});}else{return _0x183816;}})[_0x8d38('0x46')](function(_0x29aef7){logger[_0x8d38('0x2a')](_0x8d38('0x53'),_0x29aef7);throw _0x29aef7;});}return _0x183816;})['then'](respondWithResult(_0x427279,0xc9))[_0x8d38('0x46')](handleError(_0x427279,null));};exports[_0x8d38('0x54')]=function(_0x3cf15b,_0x3e4615){if(_0x3cf15b[_0x8d38('0x4c')]['id']){delete _0x3cf15b[_0x8d38('0x4c')]['id'];}return db[_0x8d38('0x2e')][_0x8d38('0x4a')]({'where':{'id':_0x3cf15b[_0x8d38('0x47')]['id']}})['then'](handleEntityNotFound(_0x3e4615,null))['then'](saveUpdates(_0x3cf15b[_0x8d38('0x4c')],null))[_0x8d38('0x25')](respondWithResult(_0x3e4615,null))[_0x8d38('0x46')](handleError(_0x3e4615,null));};exports[_0x8d38('0x28')]=function(_0x83010,_0x4fb6e9){return db['AnalyticCustomReport']['find']({'where':{'id':_0x83010['params']['id']}})[_0x8d38('0x25')](handleEntityNotFound(_0x4fb6e9,null))[_0x8d38('0x25')](removeEntity(_0x4fb6e9,null))[_0x8d38('0x46')](handleError(_0x4fb6e9,null));};exports[_0x8d38('0x55')]=function(_0x1cc440,_0x29aee4){var _0x8a6fdd=0xa;var _0x329cd2=[_0x8d38('0x56'),_0x8d38('0x57'),_0x8d38('0x58'),'cross_join'];var _0x47a6b2={'SUM':_0x8d38('0x59'),'COUNT':_0x8d38('0x5a'),'COUNT DISTINCT':_0x8d38('0x5b'),'MAX':_0x8d38('0x5c'),'MIN':_0x8d38('0x5d'),'AVG':'AVG(%s)','GROUP_CONCAT':_0x8d38('0x5e'),'GROUP_CONCAT ASC':_0x8d38('0x5f'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x434198={'SEC_TO_TIME':_0x8d38('0x60'),'DATE':_0x8d38('0x61'),'HOUR':'HOUR(%s)','ROUND':'ROUND(%s)','UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x5e64aa=function(_0x441508){return!_[_0x8d38('0x62')](['IS\x20NULL',_0x8d38('0x63'),_0x8d38('0x64'),_0x8d38('0x65')],_0x441508);};var _0x4e1863=function(_0x43ab96){if(!_0x43ab96||!_0x43ab96['rules']['length']){return'';}for(var _0x3fba3c='(',_0x576aaf=0x0;_0x576aaf<_0x43ab96[_0x8d38('0x66')]['length'];_0x576aaf+=0x1){_0x576aaf>0x0&&(_0x3fba3c+='\x20'+_0x43ab96['operator']+'\x20');_0x3fba3c+=_0x43ab96[_0x8d38('0x66')][_0x576aaf][_0x8d38('0x67')]?_0x4e1863(_0x43ab96['rules'][_0x576aaf][_0x8d38('0x67')]):_0x43ab96['rules'][_0x576aaf][_0x8d38('0x68')]+'\x20'+_0x43ab96[_0x8d38('0x66')][_0x576aaf]['condition']+(_0x5e64aa(_0x43ab96[_0x8d38('0x66')][_0x576aaf][_0x8d38('0x69')])?'\x20'+_0x43ab96['rules'][_0x576aaf]['value']:'');}return _0x3fba3c+')';};var _0x4646e1={'where':{'id':_0x1cc440['params']['id']}},_0x488b63,_0x8952b0,_0x5b6f11,_0x19d985,_0x579050;_0x4646e1=_[_0x8d38('0x43')]({},_0x4646e1,_0x1cc440[_0x8d38('0x49')]);return db['AnalyticCustomReport'][_0x8d38('0x4a')](_0x4646e1)[_0x8d38('0x25')](function(_0x1746e9){if(_0x1746e9){_0x488b63=_0x1746e9;return _0x1746e9[_0x8d38('0x6a')]();}return null;})[_0x8d38('0x25')](function(_0x149e93){if(_0x149e93){if(!_0x149e93[_0x8d38('0x3a')]){throw new db['Sequelize'][(_0x8d38('0x6b'))](_0x8d38('0x6c'),0x193);}_0x8952b0=_0x149e93;return db[_0x8d38('0x6d')][_0x8d38('0x6e')]({'raw':!![]});}return null;})[_0x8d38('0x25')](function(_0x33d942){if(_0x33d942){_0x5b6f11=_['keyBy'](_0x33d942,'id');var _0x546d5d;var _0x29c1ae=squel[_0x8d38('0x6f')]();_0x29c1ae[_0x8d38('0x70')](_0x488b63[_0x8d38('0x71')]);for(var _0x3a3c02=0x0;_0x3a3c02<_0x8952b0['length'];_0x3a3c02+=0x1){_0x546d5d=_0x8952b0[_0x3a3c02][_0x8d38('0x72')]?_0x5b6f11[_0x8952b0[_0x3a3c02]['MetricId']][_0x8d38('0x73')]:_0x8952b0[_0x3a3c02][_0x8d38('0x68')];_0x546d5d=_0x8952b0[_0x3a3c02]['function']?_[_0x8d38('0x74')](_0x47a6b2[_0x8952b0[_0x3a3c02][_0x8d38('0x75')]],'%s',_0x546d5d):_0x546d5d;_0x546d5d=_0x8952b0[_0x3a3c02][_0x8d38('0x76')]?_[_0x8d38('0x74')](_0x434198[_0x8952b0[_0x3a3c02][_0x8d38('0x76')]],'%s',_0x546d5d):_0x546d5d;if(_0x8952b0[_0x3a3c02][_0x8d38('0x77')]){_0x29c1ae[_0x8d38('0x67')](_0x546d5d);}_0x8952b0[_0x3a3c02][_0x8d38('0x78')]&&_0x29c1ae[_0x8d38('0x3d')](_0x546d5d,_0x8952b0[_0x3a3c02][_0x8d38('0x78')]==='DESC'?![]:!![]);_0x29c1ae['field'](_0x546d5d,_0x8952b0[_0x3a3c02][_0x8d38('0x79')]||_0x546d5d);}if(_0x488b63[_0x8d38('0x7a')]){_0x488b63['joins']=JSON[_0x8d38('0x7b')](_0x488b63[_0x8d38('0x7a')]);for(var _0x37c1a6=0x0;_0x37c1a6<_0x488b63[_0x8d38('0x7a')][_0x8d38('0x3a')];_0x37c1a6+=0x1){if(_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x31')]&&_['includes'](_0x329cd2,_0x488b63[_0x8d38('0x7a')][_0x37c1a6]['type'])&&_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7c')]&&_0x488b63['joins'][_0x37c1a6][_0x8d38('0x7d')]&&_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7e')]){_0x29c1ae[_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x31')]](_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7d')],null,util[_0x8d38('0x76')](_0x8d38('0x7f'),_0x488b63[_0x8d38('0x71')],_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7c')],_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7d')],_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7e')]));}}}if(_0x488b63['conditions']){_0x488b63[_0x8d38('0x80')]=JSON[_0x8d38('0x7b')](_0x488b63[_0x8d38('0x80')]);_0x29c1ae[_0x8d38('0x3f')](_0x4e1863(_0x488b63[_0x8d38('0x80')]['group']));}_0x579050=_0x29c1ae[_0x8d38('0x81')]();_0x29c1ae[_0x8d38('0x1f')](_0x8a6fdd);_0x29c1ae[_0x8d38('0x1d')](0x0);logger['debug']('Limited\x20Query:',_0x29c1ae[_0x8d38('0x82')]());return dbH[_0x8d38('0x83')][_0x8d38('0x34')](_0x29c1ae[_0x8d38('0x82')](),{'type':dbH['sequelize']['QueryTypes'][_0x8d38('0x84')]});}})[_0x8d38('0x25')](respondWithResult(_0x29aee4,null))[_0x8d38('0x46')](handleError(_0x29aee4,null));};function runReport(_0x5eae48,_0x5d9654,_0x17f15d){var _0x429711=_0x5d9654[_0x8d38('0x2b')];var _0x24efbe=0xa;var _0x438b4f=[_0x8d38('0x56'),_0x8d38('0x57'),_0x8d38('0x58'),_0x8d38('0x85')];var _0x4419bb={'SUM':'SUM(%s)','COUNT':_0x8d38('0x5a'),'COUNT DISTINCT':_0x8d38('0x5b'),'MAX':_0x8d38('0x5c'),'MIN':'MIN(%s)','AVG':_0x8d38('0x86'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0x8d38('0x5f'),'GROUP_CONCAT DESC':_0x8d38('0x87')};var _0x25b323={'SEC_TO_TIME':_0x8d38('0x60'),'DATE':_0x8d38('0x61'),'HOUR':'HOUR(%s)','ROUND':_0x8d38('0x88'),'UNIX_TIMESTAMP':_0x8d38('0x89')};var _0x3d924e=function(_0x42ed60){return!_[_0x8d38('0x62')]([_0x8d38('0x8a'),'IS\x20NOT\x20NULL',_0x8d38('0x64'),_0x8d38('0x65')],_0x42ed60);};var _0x3a50bd=function(_0x5a12b5){if(!_0x5a12b5||!_0x5a12b5[_0x8d38('0x66')]['length']){return'';}for(var _0x5f1c36='(',_0x14307a=0x0;_0x14307a<_0x5a12b5[_0x8d38('0x66')][_0x8d38('0x3a')];_0x14307a+=0x1){_0x14307a>0x0&&(_0x5f1c36+='\x20'+_0x5a12b5[_0x8d38('0x8b')]+'\x20');_0x5f1c36+=_0x5a12b5[_0x8d38('0x66')][_0x14307a][_0x8d38('0x67')]?_0x3a50bd(_0x5a12b5['rules'][_0x14307a][_0x8d38('0x67')]):_0x5a12b5[_0x8d38('0x66')][_0x14307a]['field']+'\x20'+_0x5a12b5[_0x8d38('0x66')][_0x14307a]['condition']+(_0x3d924e(_0x5a12b5['rules'][_0x14307a][_0x8d38('0x69')])?'\x20'+_0x5a12b5[_0x8d38('0x66')][_0x14307a][_0x8d38('0x8c')]:'');}return _0x5f1c36+')';};var _0x51aa93={'where':{'id':_0x5eae48['id']}},_0xd2018d,_0x4f7a00,_0xc423e0,_0xc5f183,_0x356efa;_0x51aa93=_[_0x8d38('0x43')]({},_0x51aa93,_0x17f15d);return db[_0x8d38('0x2e')]['find'](_0x51aa93)[_0x8d38('0x25')](function(_0x571ef7){if(_0x571ef7){_0xd2018d=_0x571ef7;return _0x571ef7[_0x8d38('0x6a')]();}return null;})['then'](function(_0x15ec44){if(_0x15ec44){if(!_0x15ec44[_0x8d38('0x3a')]){throw new db['Sequelize'][(_0x8d38('0x6b'))](_0x8d38('0x6c'),0x193);}_0x4f7a00=_0x15ec44;return db[_0x8d38('0x6d')][_0x8d38('0x6e')]({'raw':!![]});}return null;})['then'](function(_0x3d653c){if(_0x3d653c){_0xc423e0=_[_0x8d38('0x8d')](_0x3d653c,'id');var _0x30c291;var _0x5e7b07=squel[_0x8d38('0x6f')]();_0x5e7b07[_0x8d38('0x70')](_0xd2018d[_0x8d38('0x71')]);for(var _0x36a7be=0x0;_0x36a7be<_0x4f7a00[_0x8d38('0x3a')];_0x36a7be+=0x1){_0x30c291=_0x4f7a00[_0x36a7be]['MetricId']?_0xc423e0[_0x4f7a00[_0x36a7be][_0x8d38('0x72')]]['metric']:_0x4f7a00[_0x36a7be][_0x8d38('0x68')];_0x30c291=_0x4f7a00[_0x36a7be]['function']?_[_0x8d38('0x74')](_0x4419bb[_0x4f7a00[_0x36a7be][_0x8d38('0x75')]],'%s',_0x30c291):_0x30c291;_0x30c291=_0x4f7a00[_0x36a7be]['format']?_[_0x8d38('0x74')](_0x25b323[_0x4f7a00[_0x36a7be][_0x8d38('0x76')]],'%s',_0x30c291):_0x30c291;if(_0x4f7a00[_0x36a7be][_0x8d38('0x77')]){_0x5e7b07[_0x8d38('0x67')](_0x30c291);}_0x4f7a00[_0x36a7be][_0x8d38('0x78')]&&_0x5e7b07['order'](_0x30c291,_0x4f7a00[_0x36a7be]['orderBy']===_0x8d38('0x8e')?![]:!![]);_0x5e7b07[_0x8d38('0x68')](_0x30c291,_0x4f7a00[_0x36a7be][_0x8d38('0x79')]||_0x30c291);}if(_0xd2018d['joins']){_0xd2018d[_0x8d38('0x7a')]=JSON[_0x8d38('0x7b')](_0xd2018d[_0x8d38('0x7a')]);for(var _0x43765e=0x0;_0x43765e<_0xd2018d[_0x8d38('0x7a')]['length'];_0x43765e+=0x1){if(_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x31')]&&_[_0x8d38('0x62')](_0x438b4f,_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x31')])&&_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x7c')]&&_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x7d')]&&_0xd2018d[_0x8d38('0x7a')][_0x43765e]['foreignKey']){_0x5e7b07[_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x31')]](_0xd2018d[_0x8d38('0x7a')][_0x43765e]['foreignTable'],null,util[_0x8d38('0x76')]('%s.%s\x20=\x20%s.%s',_0xd2018d[_0x8d38('0x71')],_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x7c')],_0xd2018d[_0x8d38('0x7a')][_0x43765e]['foreignTable'],_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x7e')]));}}}if(_0xd2018d[_0x8d38('0x80')]){_0xd2018d[_0x8d38('0x80')]=JSON[_0x8d38('0x7b')](_0xd2018d[_0x8d38('0x80')]);_0x5e7b07[_0x8d38('0x3f')](_0x3a50bd(_0xd2018d['conditions'][_0x8d38('0x67')]));}_0x356efa=_0x5e7b07[_0x8d38('0x81')]();_0x5e7b07['limit'](_0x24efbe);_0x5e7b07[_0x8d38('0x1d')](0x0);return;}})[_0x8d38('0x25')](function(){if(_0x5d9654['output']===_0x8d38('0x8f')){return null;}var _0xd59734=_[_0x8d38('0x43')](_0x5d9654,{'name':_0x5d9654['fullPath']||_0x5d9654[_0x8d38('0x2b')]||_0xd2018d[_0x8d38('0x2b')],'basename':_0x429711,'savename':util[_0x8d38('0x76')](_0x8d38('0x90'),_0x5d9654['name']||_0xd2018d[_0x8d38('0x2b')],require(_0x8d38('0x91'))[_0x8d38('0x92')](0x4),_0x5d9654[_0x8d38('0x93')]||_0x8d38('0x94')),'reportId':_0xd2018d['id'],'reportType':_0x8d38('0x95')});return db['AnalyticExtractedReport'][_0x8d38('0x4b')](_0xd59734,{'raw':!![]});})['then'](function(_0x178f52){if(_0xd2018d[_0x8d38('0x71')]===_0x8d38('0x96')){_0x356efa[_0x8d38('0x3f')](_0xd2018d[_0x8d38('0x71')]+_0x8d38('0x97'),_0x5d9654[_0x8d38('0x98')],_0x5d9654[_0x8d38('0x99')]);}else{_0x356efa['where'](_0xd2018d['table']+'.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x5d9654[_0x8d38('0x98')],_0x5d9654[_0x8d38('0x99')]);}if(_0x178f52){logger['info'](_0x8d38('0x9a'),_0x356efa[_0x8d38('0x82')]());require(_0x8d38('0x9b'))[_0x8d38('0x9c')](path[_0x8d38('0x56')](__dirname,_0x8d38('0x9d'),_0x178f52[_0x8d38('0x93')]),[_0x178f52['id'],_0x356efa[_0x8d38('0x82')](),path[_0x8d38('0x56')](__dirname,_0x8d38('0x9e'),_0x178f52[_0x8d38('0x9f')]),_0x429711]);return _0x178f52;}else{var _0x1429de=squel[_0x8d38('0x6f')]();_0x1429de[_0x8d38('0x70')]('('+_0x356efa['toString']()+')',_0x8d38('0xa0'));_0x1429de[_0x8d38('0x68')](_0x8d38('0xa1'),'count');_0x356efa['limit'](_0x5d9654[_0x8d38('0x1f')]||_0x24efbe);_0x356efa[_0x8d38('0x1d')](_0x5d9654[_0x8d38('0x1d')]||0x0);return dbH['sequelize'][_0x8d38('0x34')](_0x1429de[_0x8d38('0x82')](),{'type':dbH[_0x8d38('0x83')][_0x8d38('0xa2')][_0x8d38('0x84')]})[_0x8d38('0x25')](function(_0x27cca0){if(!_0x27cca0[_0x8d38('0x3a')]){_0xc5f183=0x0;}else{_0xc5f183=_0x27cca0[0x0][_0x8d38('0x44')]||0x0;}return dbH['sequelize'][_0x8d38('0x34')](_0x356efa[_0x8d38('0x82')](),{'type':dbH[_0x8d38('0x83')]['QueryTypes'][_0x8d38('0x84')]});})[_0x8d38('0x25')](function(_0x3c02b1){return{'rows':_0x3c02b1||[],'count':_0xc5f183};});}});}exports[_0x8d38('0xa3')]=function(_0x514fec,_0x2ef97c){return runReport(_0x514fec['params'],_0x514fec['query'],_0x514fec[_0x8d38('0x49')])['then'](respondWithResult(_0x2ef97c,null))[_0x8d38('0x46')](handleError(_0x2ef97c,null));};exports['runReport']=runReport;exports['query']=function(_0x52a82d,_0x2d54ea){var _0x1cbd07=0xa;var _0x128b4a=[_0x8d38('0x56'),_0x8d38('0x57'),_0x8d38('0x58'),'cross_join'];var _0x3547b8={'SUM':_0x8d38('0x59'),'COUNT':_0x8d38('0x5a'),'COUNT DISTINCT':_0x8d38('0x5b'),'MAX':_0x8d38('0x5c'),'MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0x8d38('0x5e'),'GROUP_CONCAT ASC':_0x8d38('0x5f'),'GROUP_CONCAT DESC':_0x8d38('0x87')};var _0x6d91b0={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x8d38('0x61'),'HOUR':'HOUR(%s)','ROUND':_0x8d38('0x88'),'UNIX_TIMESTAMP':_0x8d38('0x89')};var _0x5a9bc5=function(_0x40beab){return!_[_0x8d38('0x62')](['IS\x20NULL',_0x8d38('0x63'),_0x8d38('0x64'),'IS\x20NOT\x20EMPTY'],_0x40beab);};var _0x1b734c=function(_0x33b04e){if(!_0x33b04e||!_0x33b04e[_0x8d38('0x66')][_0x8d38('0x3a')]){return'';}for(var _0x3bfd5e='(',_0x45ce56=0x0;_0x45ce56<_0x33b04e[_0x8d38('0x66')]['length'];_0x45ce56+=0x1){_0x45ce56>0x0&&(_0x3bfd5e+='\x20'+_0x33b04e[_0x8d38('0x8b')]+'\x20');_0x3bfd5e+=_0x33b04e[_0x8d38('0x66')][_0x45ce56]['group']?_0x1b734c(_0x33b04e['rules'][_0x45ce56][_0x8d38('0x67')]):_0x33b04e['rules'][_0x45ce56][_0x8d38('0x68')]+'\x20'+_0x33b04e[_0x8d38('0x66')][_0x45ce56][_0x8d38('0x69')]+(_0x5a9bc5(_0x33b04e[_0x8d38('0x66')][_0x45ce56][_0x8d38('0x69')])?'\x20'+_0x33b04e[_0x8d38('0x66')][_0x45ce56][_0x8d38('0x8c')]:'');}return _0x3bfd5e+')';};var _0x186bfd={'where':{'id':_0x52a82d['params']['id']}},_0x35d334,_0x134290,_0x517d40,_0x3adeee,_0x51f5ec;_0x186bfd=_[_0x8d38('0x43')]({},_0x186bfd,_0x52a82d['options']);return db[_0x8d38('0x2e')][_0x8d38('0x4a')](_0x186bfd)[_0x8d38('0x25')](function(_0x3b904e){if(_0x3b904e){_0x35d334=_0x3b904e;return _0x3b904e[_0x8d38('0x6a')]();}return null;})[_0x8d38('0x25')](function(_0x3a0aa6){if(_0x3a0aa6){if(!_0x3a0aa6[_0x8d38('0x3a')]){throw new db['Sequelize'][(_0x8d38('0x6b'))](_0x8d38('0x6c'),0x193);}_0x134290=_0x3a0aa6;return db[_0x8d38('0x6d')]['findAll']({'raw':!![]});}return null;})[_0x8d38('0x25')](function(_0x4fbe3f){if(_0x4fbe3f){_0x517d40=_[_0x8d38('0x8d')](_0x4fbe3f,'id');var _0x8c51cd;var _0x1b4268=squel['select']();_0x1b4268['from'](_0x35d334[_0x8d38('0x71')]);for(var _0x5e5977=0x0;_0x5e5977<_0x134290[_0x8d38('0x3a')];_0x5e5977+=0x1){_0x8c51cd=_0x134290[_0x5e5977][_0x8d38('0x72')]?_0x517d40[_0x134290[_0x5e5977][_0x8d38('0x72')]][_0x8d38('0x73')]:_0x134290[_0x5e5977][_0x8d38('0x68')];_0x8c51cd=_0x134290[_0x5e5977][_0x8d38('0x75')]?_[_0x8d38('0x74')](_0x3547b8[_0x134290[_0x5e5977][_0x8d38('0x75')]],'%s',_0x8c51cd):_0x8c51cd;_0x8c51cd=_0x134290[_0x5e5977][_0x8d38('0x76')]?_['replace'](_0x6d91b0[_0x134290[_0x5e5977][_0x8d38('0x76')]],'%s',_0x8c51cd):_0x8c51cd;if(_0x134290[_0x5e5977][_0x8d38('0x77')]){_0x1b4268[_0x8d38('0x67')](_0x8c51cd);}_0x134290[_0x5e5977][_0x8d38('0x78')]&&_0x1b4268['order'](_0x8c51cd,_0x134290[_0x5e5977][_0x8d38('0x78')]===_0x8d38('0x8e')?![]:!![]);_0x1b4268[_0x8d38('0x68')](_0x8c51cd,_0x134290[_0x5e5977][_0x8d38('0x79')]||_0x8c51cd);}if(_0x35d334[_0x8d38('0x7a')]){_0x35d334['joins']=JSON[_0x8d38('0x7b')](_0x35d334[_0x8d38('0x7a')]);for(var _0x76491b=0x0;_0x76491b<_0x35d334[_0x8d38('0x7a')][_0x8d38('0x3a')];_0x76491b+=0x1){if(_0x35d334['joins'][_0x76491b][_0x8d38('0x31')]&&_['includes'](_0x128b4a,_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x31')])&&_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7c')]&&_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7d')]&&_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7e')]){_0x1b4268[_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x31')]](_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7d')],null,util[_0x8d38('0x76')](_0x8d38('0x7f'),_0x35d334[_0x8d38('0x71')],_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7c')],_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7d')],_0x35d334['joins'][_0x76491b][_0x8d38('0x7e')]));}}}if(_0x35d334[_0x8d38('0x80')]){_0x35d334['conditions']=JSON[_0x8d38('0x7b')](_0x35d334['conditions']);_0x1b4268['where'](_0x1b734c(_0x35d334['conditions'][_0x8d38('0x67')]));}_0x51f5ec=_0x1b4268[_0x8d38('0x81')]();_0x1b4268[_0x8d38('0x1f')](_0x1cbd07);_0x1b4268['offset'](0x0);logger[_0x8d38('0xa4')](_0x8d38('0xa5'),_0x1b4268[_0x8d38('0x82')]());return dbH[_0x8d38('0x83')]['query'](_0x1b4268['toString'](),{'type':dbH[_0x8d38('0x83')]['QueryTypes'][_0x8d38('0x84')]});}})[_0x8d38('0x25')](function(){return{'sql':_0x51f5ec[_0x8d38('0x82')]()};})[_0x8d38('0x25')](respondWithResult(_0x2d54ea,null))[_0x8d38('0x46')](handleError(_0x2d54ea,null));};