Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index e5aa32a..6113ee1 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x415c=['IS\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','operator','group','condition','params','getFields','Sequelize','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','select','from','table','MetricId','field','function','replace','format','groupBy','orderBy','order','joins','parse','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','parentKey','conditions','sequelize','toString','SELECT','right_join','COUNT(DISTINCT\x20%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','UNIX_TIMESTAMP(%s)','IS\x20NOT\x20NULL','value','metric','DESC','alias','clone','output','%s-%s.%s','randomstring','generate','custom','AnalyticExtractedReport','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','Run\x20Query:','child_process','fork','../../components/export/','../../files/reports','savename','COUNT(*)','QueryTypes','run','debug','Limited\x20Query:','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','ejs','fs-extra','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','then','destroy','get','CustomReports','UserProfileResource','error','stack','name','index','AnalyticCustomReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','sort','pick','filter','where','merge','map','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Reports','UserProfileSection','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','preview','join','left_join','cross_join','SUM(%s)','COUNT(%s)','MAX(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','HOUR(%s)','ROUND(%s)','includes'];(function(_0x4771d9,_0x16e00b){var _0x42e8eb=function(_0x579242){while(--_0x579242){_0x4771d9['push'](_0x4771d9['shift']());}};_0x42e8eb(++_0x16e00b);}(_0x415c,0x197));var _0xc415=function(_0x2e7daa,_0x5a764b){_0x2e7daa=_0x2e7daa-0x0;var _0x3b1036=_0x415c[_0x2e7daa];return _0x3b1036;};'use strict';var emlformat=require(_0xc415('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xc415('0x1'));var jsonpatch=require(_0xc415('0x2'));var rp=require(_0xc415('0x3'));var moment=require(_0xc415('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xc415('0x5'));var util=require(_0xc415('0x6'));var path=require(_0xc415('0x7'));var sox=require(_0xc415('0x8'));var csv=require('to-csv');var ejs=require(_0xc415('0x9'));var fs=require('fs');var fs_extra=require(_0xc415('0xa'));var _=require(_0xc415('0xb'));var squel=require(_0xc415('0xc'));var crypto=require('crypto');var jsforce=require(_0xc415('0xd'));var deskjs=require(_0xc415('0xe'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xc415('0xf'));var Redis=require(_0xc415('0x10'));var authService=require(_0xc415('0x11'));var qs=require(_0xc415('0x12'));var as=require(_0xc415('0x13'));var hardwareService=require(_0xc415('0x14'));var logger=require(_0xc415('0x15'))(_0xc415('0x16'));var utils=require('../../config/utils');var config=require(_0xc415('0x17'));var licenseUtil=require(_0xc415('0x18'));var db=require(_0xc415('0x19'))['db'];var dbH=require('../../mysqldb')[_0xc415('0x1a')];function respondWithStatusCode(_0x35b1f5,_0x5a865e){_0x5a865e=_0x5a865e||0xcc;return function(_0x53efb0){if(_0x53efb0){return _0x35b1f5[_0xc415('0x1b')](_0x5a865e);}return _0x35b1f5[_0xc415('0x1c')](_0x5a865e)[_0xc415('0x1d')]();};}function respondWithResult(_0x2bac1,_0x3fbac5){_0x3fbac5=_0x3fbac5||0xc8;return function(_0x212ef1){if(_0x212ef1){return _0x2bac1['status'](_0x3fbac5)[_0xc415('0x1e')](_0x212ef1);}};}function respondWithFilteredResult(_0x343c0d,_0x3ed8c9){return function(_0x46f942){if(_0x46f942){var _0x1cc047=typeof _0x3ed8c9[_0xc415('0x1f')]===_0xc415('0x20')&&typeof _0x3ed8c9[_0xc415('0x21')]===_0xc415('0x20');var _0x298895=_0x46f942[_0xc415('0x22')];var _0x491c86=_0x1cc047?0x0:_0x3ed8c9[_0xc415('0x1f')];var _0x356e9e=_0x1cc047?_0x46f942['count']:_0x3ed8c9[_0xc415('0x1f')]+_0x3ed8c9['limit'];var _0x4e1119;if(_0x356e9e>=_0x298895){_0x356e9e=_0x298895;_0x4e1119=0xc8;}else{_0x4e1119=0xce;}_0x343c0d[_0xc415('0x1c')](_0x4e1119);return _0x343c0d[_0xc415('0x23')](_0xc415('0x24'),_0x491c86+'-'+_0x356e9e+'/'+_0x298895)[_0xc415('0x1e')](_0x46f942);}return null;};}function patchUpdates(_0x9eeb08){return function(_0x3b5881){try{jsonpatch['apply'](_0x3b5881,_0x9eeb08,!![]);}catch(_0x3f3797){return BPromise[_0xc415('0x25')](_0x3f3797);}return _0x3b5881[_0xc415('0x26')]();};}function saveUpdates(_0x11a99e,_0x41783e){return function(_0x2ddb4b){if(_0x2ddb4b){return _0x2ddb4b[_0xc415('0x27')](_0x11a99e)[_0xc415('0x28')](function(_0x4fcb10){return _0x4fcb10;});}return null;};}function removeEntity(_0x1b87b1,_0x5b2986){return function(_0x48a46d){if(_0x48a46d){return _0x48a46d[_0xc415('0x29')]()[_0xc415('0x28')](function(){var _0x281dd0=_0x48a46d[_0xc415('0x2a')]({'plain':!![]});var _0x4b5841=_0xc415('0x2b');return db[_0xc415('0x2c')][_0xc415('0x29')]({'where':{'type':_0x4b5841,'resourceId':_0x281dd0['id']}})[_0xc415('0x28')](function(){return _0x48a46d;});})['then'](function(){_0x1b87b1[_0xc415('0x1c')](0xcc)[_0xc415('0x1d')]();});}};}function handleEntityNotFound(_0x4e6718,_0x508730){return function(_0x54229f){if(!_0x54229f){_0x4e6718[_0xc415('0x1b')](0x194);}return _0x54229f;};}function handleError(_0x21462b,_0x5d5e5d){_0x5d5e5d=_0x5d5e5d||0x1f4;return function(_0x2d8ef7){logger[_0xc415('0x2d')](_0x2d8ef7[_0xc415('0x2e')]);if(_0x2d8ef7['name']){delete _0x2d8ef7[_0xc415('0x2f')];}_0x21462b['status'](_0x5d5e5d)['send'](_0x2d8ef7);};}exports[_0xc415('0x30')]=function(_0x15bcc3,_0x4d08c6){var _0x38ed36={},_0x1c036c={},_0x594739={'count':0x0,'rows':[]};var _0x10c39e=_['map'](db[_0xc415('0x31')][_0xc415('0x32')],function(_0x4c92c1){return{'name':_0x4c92c1[_0xc415('0x33')],'type':_0x4c92c1[_0xc415('0x34')][_0xc415('0x35')]};});_0x1c036c[_0xc415('0x36')]=_['map'](_0x10c39e,'name');_0x1c036c[_0xc415('0x37')]=_[_0xc415('0x38')](_0x15bcc3[_0xc415('0x37')]);_0x1c036c[_0xc415('0x39')]=_[_0xc415('0x3a')](_0x1c036c['model'],_0x1c036c[_0xc415('0x37')]);_0x38ed36[_0xc415('0x3b')]=_[_0xc415('0x3a')](_0x1c036c[_0xc415('0x36')],qs[_0xc415('0x3c')](_0x15bcc3['query']['fields']));_0x38ed36[_0xc415('0x3b')]=_0x38ed36[_0xc415('0x3b')][_0xc415('0x3d')]?_0x38ed36[_0xc415('0x3b')]:_0x1c036c[_0xc415('0x36')];if(!_0x15bcc3[_0xc415('0x37')][_0xc415('0x3e')]('nolimit')){_0x38ed36[_0xc415('0x21')]=qs[_0xc415('0x21')](_0x15bcc3[_0xc415('0x37')][_0xc415('0x21')]);_0x38ed36['offset']=qs[_0xc415('0x1f')](_0x15bcc3[_0xc415('0x37')][_0xc415('0x1f')]);}_0x38ed36['order']=qs['sort'](_0x15bcc3[_0xc415('0x37')][_0xc415('0x3f')]);_0x38ed36['where']=qs[_0xc415('0x39')](_[_0xc415('0x40')](_0x15bcc3['query'],_0x1c036c['filters']),_0x10c39e);if(_0x15bcc3[_0xc415('0x37')][_0xc415('0x41')]){_0x38ed36[_0xc415('0x42')]=_[_0xc415('0x43')](_0x38ed36[_0xc415('0x42')],{'$or':_[_0xc415('0x44')](_0x10c39e,function(_0x2d3596){if(_0x2d3596[_0xc415('0x34')]!==_0xc415('0x45')){var _0x4c4ceb={};_0x4c4ceb[_0x2d3596[_0xc415('0x2f')]]={'$like':'%'+_0x15bcc3[_0xc415('0x37')][_0xc415('0x41')]+'%'};return _0x4c4ceb;}})});}_0x38ed36=_[_0xc415('0x43')]({},_0x38ed36,_0x15bcc3[_0xc415('0x46')]);var _0x31a103={'where':_0x38ed36[_0xc415('0x42')]};return db[_0xc415('0x31')]['count'](_0x31a103)[_0xc415('0x28')](function(_0x3f89c1){_0x594739['count']=_0x3f89c1;if(_0x15bcc3[_0xc415('0x37')][_0xc415('0x47')]){_0x38ed36[_0xc415('0x48')]=[{'all':!![]}];}return db[_0xc415('0x31')][_0xc415('0x49')](_0x38ed36);})[_0xc415('0x28')](function(_0x5495c6){_0x594739[_0xc415('0x4a')]=_0x5495c6;return _0x594739;})[_0xc415('0x28')](respondWithFilteredResult(_0x4d08c6,_0x38ed36))[_0xc415('0x4b')](handleError(_0x4d08c6,null));};exports[_0xc415('0x4c')]=function(_0x5a22eb,_0x10eea0){var _0x31026b={'raw':![],'where':{'id':_0x5a22eb['params']['id']}},_0x2399a5={};_0x2399a5['model']=_[_0xc415('0x38')](db[_0xc415('0x31')][_0xc415('0x32')]);_0x2399a5['query']=_[_0xc415('0x38')](_0x5a22eb[_0xc415('0x37')]);_0x2399a5[_0xc415('0x39')]=_[_0xc415('0x3a')](_0x2399a5[_0xc415('0x36')],_0x2399a5['query']);_0x31026b[_0xc415('0x3b')]=_[_0xc415('0x3a')](_0x2399a5[_0xc415('0x36')],qs['fields'](_0x5a22eb[_0xc415('0x37')]['fields']));_0x31026b[_0xc415('0x3b')]=_0x31026b[_0xc415('0x3b')][_0xc415('0x3d')]?_0x31026b['attributes']:_0x2399a5['model'];if(_0x5a22eb[_0xc415('0x37')][_0xc415('0x47')]){_0x31026b[_0xc415('0x48')]=[{'all':!![]}];}_0x31026b=_[_0xc415('0x43')]({},_0x31026b,_0x5a22eb[_0xc415('0x46')]);return db['AnalyticCustomReport'][_0xc415('0x4d')](_0x31026b)['then'](handleEntityNotFound(_0x10eea0,null))[_0xc415('0x28')](respondWithResult(_0x10eea0,null))[_0xc415('0x4b')](handleError(_0x10eea0,null));};exports[_0xc415('0x4e')]=function(_0x46eb14,_0xb12861){return db[_0xc415('0x31')][_0xc415('0x4e')](_0x46eb14[_0xc415('0x4f')],{})[_0xc415('0x28')](function(_0xd2b1d5){var _0x31ee2a=_0x46eb14[_0xc415('0x50')]['get']({'plain':!![]});if(!_0x31ee2a)throw new Error(_0xc415('0x51'));if(_0x31ee2a[_0xc415('0x52')]===_0xc415('0x50')){var _0x4381ac=_0xd2b1d5[_0xc415('0x2a')]({'plain':!![]});var _0x355293=_0xc415('0x53');return db[_0xc415('0x54')][_0xc415('0x4d')]({'where':{'name':_0x355293,'userProfileId':_0x31ee2a['userProfileId']},'raw':!![]})[_0xc415('0x28')](function(_0x3f89d5){if(_0x3f89d5&&_0x3f89d5['autoAssociation']===0x0){return db['UserProfileResource'][_0xc415('0x4e')]({'name':_0x4381ac[_0xc415('0x2f')],'resourceId':_0x4381ac['id'],'type':'CustomReports','sectionId':_0x3f89d5['id']},{})[_0xc415('0x28')](function(){return _0xd2b1d5;});}else{return _0xd2b1d5;}})[_0xc415('0x4b')](function(_0x58a21f){logger['error'](_0xc415('0x55'),_0x58a21f);throw _0x58a21f;});}return _0xd2b1d5;})[_0xc415('0x28')](respondWithResult(_0xb12861,0xc9))[_0xc415('0x4b')](handleError(_0xb12861,null));};exports[_0xc415('0x27')]=function(_0x35d54d,_0x33adca){if(_0x35d54d[_0xc415('0x4f')]['id']){delete _0x35d54d[_0xc415('0x4f')]['id'];}return db[_0xc415('0x31')][_0xc415('0x4d')]({'where':{'id':_0x35d54d['params']['id']}})[_0xc415('0x28')](handleEntityNotFound(_0x33adca,null))[_0xc415('0x28')](saveUpdates(_0x35d54d[_0xc415('0x4f')],null))['then'](respondWithResult(_0x33adca,null))[_0xc415('0x4b')](handleError(_0x33adca,null));};exports[_0xc415('0x29')]=function(_0xeee817,_0xa2e50){return db[_0xc415('0x31')][_0xc415('0x4d')]({'where':{'id':_0xeee817['params']['id']}})[_0xc415('0x28')](handleEntityNotFound(_0xa2e50,null))[_0xc415('0x28')](removeEntity(_0xa2e50,null))[_0xc415('0x4b')](handleError(_0xa2e50,null));};exports[_0xc415('0x56')]=function(_0x2c1de3,_0x1da3d6){var _0x2ca646=0xa;var _0x75fe0e=[_0xc415('0x57'),_0xc415('0x58'),'right_join',_0xc415('0x59')];var _0x4bb740={'SUM':_0xc415('0x5a'),'COUNT':_0xc415('0x5b'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0xc415('0x5c'),'MIN':_0xc415('0x5d'),'AVG':_0xc415('0x5e'),'GROUP_CONCAT':_0xc415('0x5f'),'GROUP_CONCAT ASC':_0xc415('0x60'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x8c70ac={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':'DATE(%s)','HOUR':_0xc415('0x61'),'ROUND':_0xc415('0x62'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x3bb4b2=function(_0x1dcd63){return!_[_0xc415('0x63')]([_0xc415('0x64'),'IS\x20NOT\x20NULL',_0xc415('0x65'),_0xc415('0x66')],_0x1dcd63);};var _0x274b63=function(_0xfdb3bb){if(!_0xfdb3bb||!_0xfdb3bb[_0xc415('0x67')][_0xc415('0x3d')]){return'';}for(var _0x1b17b0='(',_0x1e7117=0x0;_0x1e7117<_0xfdb3bb[_0xc415('0x67')][_0xc415('0x3d')];_0x1e7117+=0x1){_0x1e7117>0x0&&(_0x1b17b0+='\x20'+_0xfdb3bb[_0xc415('0x68')]+'\x20');_0x1b17b0+=_0xfdb3bb['rules'][_0x1e7117][_0xc415('0x69')]?_0x274b63(_0xfdb3bb[_0xc415('0x67')][_0x1e7117][_0xc415('0x69')]):_0xfdb3bb[_0xc415('0x67')][_0x1e7117]['field']+'\x20'+_0xfdb3bb[_0xc415('0x67')][_0x1e7117][_0xc415('0x6a')]+(_0x3bb4b2(_0xfdb3bb[_0xc415('0x67')][_0x1e7117]['condition'])?'\x20'+_0xfdb3bb[_0xc415('0x67')][_0x1e7117]['value']:'');}return _0x1b17b0+')';};var _0x4b7f0b={'where':{'id':_0x2c1de3[_0xc415('0x6b')]['id']}},_0x400d07,_0x2e9914,_0xcb8288,_0x118580,_0x4e879e;_0x4b7f0b=_[_0xc415('0x43')]({},_0x4b7f0b,_0x2c1de3[_0xc415('0x46')]);return db[_0xc415('0x31')]['find'](_0x4b7f0b)[_0xc415('0x28')](function(_0xc184a6){if(_0xc184a6){_0x400d07=_0xc184a6;return _0xc184a6[_0xc415('0x6c')]();}return null;})[_0xc415('0x28')](function(_0x505108){if(_0x505108){if(!_0x505108[_0xc415('0x3d')]){throw new db[(_0xc415('0x6d'))][(_0xc415('0x6e'))](_0xc415('0x6f'),0x193);}_0x2e9914=_0x505108;return db[_0xc415('0x70')][_0xc415('0x49')]({'raw':!![]});}return null;})[_0xc415('0x28')](function(_0x298e12){if(_0x298e12){_0xcb8288=_[_0xc415('0x71')](_0x298e12,'id');var _0x14171c;var _0x593ab2=squel[_0xc415('0x72')]();_0x593ab2[_0xc415('0x73')](_0x400d07[_0xc415('0x74')]);for(var _0x4fb9b0=0x0;_0x4fb9b0<_0x2e9914['length'];_0x4fb9b0+=0x1){_0x14171c=_0x2e9914[_0x4fb9b0][_0xc415('0x75')]?_0xcb8288[_0x2e9914[_0x4fb9b0][_0xc415('0x75')]]['metric']:_0x2e9914[_0x4fb9b0][_0xc415('0x76')];_0x14171c=_0x2e9914[_0x4fb9b0][_0xc415('0x77')]?_[_0xc415('0x78')](_0x4bb740[_0x2e9914[_0x4fb9b0][_0xc415('0x77')]],'%s',_0x14171c):_0x14171c;_0x14171c=_0x2e9914[_0x4fb9b0][_0xc415('0x79')]?_[_0xc415('0x78')](_0x8c70ac[_0x2e9914[_0x4fb9b0][_0xc415('0x79')]],'%s',_0x14171c):_0x14171c;if(_0x2e9914[_0x4fb9b0][_0xc415('0x7a')]){_0x593ab2[_0xc415('0x69')](_0x14171c);}_0x2e9914[_0x4fb9b0][_0xc415('0x7b')]&&_0x593ab2[_0xc415('0x7c')](_0x14171c,_0x2e9914[_0x4fb9b0]['orderBy']==='DESC'?![]:!![]);_0x593ab2[_0xc415('0x76')](_0x14171c,_0x2e9914[_0x4fb9b0]['alias']||_0x14171c);}if(_0x400d07['joins']){_0x400d07[_0xc415('0x7d')]=JSON[_0xc415('0x7e')](_0x400d07[_0xc415('0x7d')]);for(var _0x585fbc=0x0;_0x585fbc<_0x400d07[_0xc415('0x7d')][_0xc415('0x3d')];_0x585fbc+=0x1){if(_0x400d07['joins'][_0x585fbc]['type']&&_[_0xc415('0x63')](_0x75fe0e,_0x400d07['joins'][_0x585fbc][_0xc415('0x34')])&&_0x400d07[_0xc415('0x7d')][_0x585fbc]['parentKey']&&_0x400d07[_0xc415('0x7d')][_0x585fbc][_0xc415('0x7f')]&&_0x400d07[_0xc415('0x7d')][_0x585fbc][_0xc415('0x80')]){_0x593ab2[_0x400d07[_0xc415('0x7d')][_0x585fbc][_0xc415('0x34')]](_0x400d07[_0xc415('0x7d')][_0x585fbc][_0xc415('0x7f')],null,util[_0xc415('0x79')](_0xc415('0x81'),_0x400d07[_0xc415('0x74')],_0x400d07[_0xc415('0x7d')][_0x585fbc][_0xc415('0x82')],_0x400d07['joins'][_0x585fbc]['foreignTable'],_0x400d07[_0xc415('0x7d')][_0x585fbc]['foreignKey']));}}}if(_0x400d07[_0xc415('0x83')]){_0x400d07['conditions']=JSON['parse'](_0x400d07[_0xc415('0x83')]);_0x593ab2[_0xc415('0x42')](_0x274b63(_0x400d07[_0xc415('0x83')][_0xc415('0x69')]));}_0x4e879e=_0x593ab2['clone']();_0x593ab2[_0xc415('0x21')](_0x2ca646);_0x593ab2[_0xc415('0x1f')](0x0);logger['debug']('Limited\x20Query:',_0x593ab2['toString']());return dbH[_0xc415('0x84')][_0xc415('0x37')](_0x593ab2[_0xc415('0x85')](),{'type':dbH['sequelize']['QueryTypes'][_0xc415('0x86')]});}})['then'](respondWithResult(_0x1da3d6,null))[_0xc415('0x4b')](handleError(_0x1da3d6,null));};function runReport(_0x32f39c,_0x4bdf5e,_0x2679c4){var _0x230459=_0x4bdf5e[_0xc415('0x2f')];var _0x519452=0xa;var _0x1ec2b3=[_0xc415('0x57'),_0xc415('0x58'),_0xc415('0x87'),'cross_join'];var _0x23d998={'SUM':_0xc415('0x5a'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0xc415('0x88'),'MAX':_0xc415('0x5c'),'MIN':_0xc415('0x5d'),'AVG':_0xc415('0x5e'),'GROUP_CONCAT':_0xc415('0x5f'),'GROUP_CONCAT ASC':_0xc415('0x60'),'GROUP_CONCAT DESC':_0xc415('0x89')};var _0x400e0f={'SEC_TO_TIME':_0xc415('0x8a'),'DATE':_0xc415('0x8b'),'HOUR':'HOUR(%s)','ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xc415('0x8c')};var _0x3a3827=function(_0x49fb39){return!_[_0xc415('0x63')]([_0xc415('0x64'),_0xc415('0x8d'),'IS\x20EMPTY',_0xc415('0x66')],_0x49fb39);};var _0x1736db=function(_0xd23fbf){if(!_0xd23fbf||!_0xd23fbf[_0xc415('0x67')][_0xc415('0x3d')]){return'';}for(var _0x56076b='(',_0x3643c1=0x0;_0x3643c1<_0xd23fbf[_0xc415('0x67')][_0xc415('0x3d')];_0x3643c1+=0x1){_0x3643c1>0x0&&(_0x56076b+='\x20'+_0xd23fbf[_0xc415('0x68')]+'\x20');_0x56076b+=_0xd23fbf[_0xc415('0x67')][_0x3643c1]['group']?_0x1736db(_0xd23fbf[_0xc415('0x67')][_0x3643c1][_0xc415('0x69')]):_0xd23fbf[_0xc415('0x67')][_0x3643c1]['field']+'\x20'+_0xd23fbf['rules'][_0x3643c1][_0xc415('0x6a')]+(_0x3a3827(_0xd23fbf[_0xc415('0x67')][_0x3643c1][_0xc415('0x6a')])?'\x20'+_0xd23fbf[_0xc415('0x67')][_0x3643c1][_0xc415('0x8e')]:'');}return _0x56076b+')';};var _0x205abd={'where':{'id':_0x32f39c['id']}},_0x3b3fca,_0x20aa71,_0x41498e,_0x460c73,_0x3a0fc2;_0x205abd=_[_0xc415('0x43')]({},_0x205abd,_0x2679c4);return db[_0xc415('0x31')][_0xc415('0x4d')](_0x205abd)['then'](function(_0x37a23e){if(_0x37a23e){_0x3b3fca=_0x37a23e;return _0x37a23e[_0xc415('0x6c')]();}return null;})[_0xc415('0x28')](function(_0x15f097){if(_0x15f097){if(!_0x15f097['length']){throw new db[(_0xc415('0x6d'))][(_0xc415('0x6e'))](_0xc415('0x6f'),0x193);}_0x20aa71=_0x15f097;return db['AnalyticMetric']['findAll']({'raw':!![]});}return null;})[_0xc415('0x28')](function(_0x58e2c7){if(_0x58e2c7){_0x41498e=_[_0xc415('0x71')](_0x58e2c7,'id');var _0x1485ed;var _0x67710e=squel[_0xc415('0x72')]();_0x67710e['from'](_0x3b3fca[_0xc415('0x74')]);for(var _0x542a3f=0x0;_0x542a3f<_0x20aa71[_0xc415('0x3d')];_0x542a3f+=0x1){_0x1485ed=_0x20aa71[_0x542a3f][_0xc415('0x75')]?_0x41498e[_0x20aa71[_0x542a3f][_0xc415('0x75')]][_0xc415('0x8f')]:_0x20aa71[_0x542a3f][_0xc415('0x76')];_0x1485ed=_0x20aa71[_0x542a3f]['function']?_[_0xc415('0x78')](_0x23d998[_0x20aa71[_0x542a3f][_0xc415('0x77')]],'%s',_0x1485ed):_0x1485ed;_0x1485ed=_0x20aa71[_0x542a3f][_0xc415('0x79')]?_[_0xc415('0x78')](_0x400e0f[_0x20aa71[_0x542a3f][_0xc415('0x79')]],'%s',_0x1485ed):_0x1485ed;if(_0x20aa71[_0x542a3f][_0xc415('0x7a')]){_0x67710e[_0xc415('0x69')](_0x1485ed);}_0x20aa71[_0x542a3f][_0xc415('0x7b')]&&_0x67710e[_0xc415('0x7c')](_0x1485ed,_0x20aa71[_0x542a3f]['orderBy']===_0xc415('0x90')?![]:!![]);_0x67710e[_0xc415('0x76')](_0x1485ed,_0x20aa71[_0x542a3f][_0xc415('0x91')]||_0x1485ed);}if(_0x3b3fca[_0xc415('0x7d')]){_0x3b3fca['joins']=JSON[_0xc415('0x7e')](_0x3b3fca['joins']);for(var _0x65b61c=0x0;_0x65b61c<_0x3b3fca[_0xc415('0x7d')][_0xc415('0x3d')];_0x65b61c+=0x1){if(_0x3b3fca['joins'][_0x65b61c][_0xc415('0x34')]&&_[_0xc415('0x63')](_0x1ec2b3,_0x3b3fca['joins'][_0x65b61c][_0xc415('0x34')])&&_0x3b3fca['joins'][_0x65b61c][_0xc415('0x82')]&&_0x3b3fca['joins'][_0x65b61c][_0xc415('0x7f')]&&_0x3b3fca[_0xc415('0x7d')][_0x65b61c]['foreignKey']){_0x67710e[_0x3b3fca[_0xc415('0x7d')][_0x65b61c][_0xc415('0x34')]](_0x3b3fca['joins'][_0x65b61c]['foreignTable'],null,util[_0xc415('0x79')](_0xc415('0x81'),_0x3b3fca[_0xc415('0x74')],_0x3b3fca[_0xc415('0x7d')][_0x65b61c][_0xc415('0x82')],_0x3b3fca[_0xc415('0x7d')][_0x65b61c][_0xc415('0x7f')],_0x3b3fca[_0xc415('0x7d')][_0x65b61c][_0xc415('0x80')]));}}}if(_0x3b3fca['conditions']){_0x3b3fca[_0xc415('0x83')]=JSON[_0xc415('0x7e')](_0x3b3fca['conditions']);_0x67710e[_0xc415('0x42')](_0x1736db(_0x3b3fca[_0xc415('0x83')][_0xc415('0x69')]));}_0x3a0fc2=_0x67710e[_0xc415('0x92')]();_0x67710e[_0xc415('0x21')](_0x519452);_0x67710e[_0xc415('0x1f')](0x0);return;}})[_0xc415('0x28')](function(){if(_0x4bdf5e[_0xc415('0x93')]==='web'){return null;}var _0x155616=_['merge'](_0x4bdf5e,{'name':_0x4bdf5e['fullPath']||_0x4bdf5e[_0xc415('0x2f')]||_0x3b3fca[_0xc415('0x2f')],'basename':_0x230459,'savename':util[_0xc415('0x79')](_0xc415('0x94'),_0x4bdf5e[_0xc415('0x2f')]||_0x3b3fca[_0xc415('0x2f')],require(_0xc415('0x95'))[_0xc415('0x96')](0x4),_0x4bdf5e[_0xc415('0x93')]||'csv'),'reportId':_0x3b3fca['id'],'reportType':_0xc415('0x97')});return db[_0xc415('0x98')][_0xc415('0x4e')](_0x155616,{'raw':!![]});})[_0xc415('0x28')](function(_0x3d912b){if(_0x3b3fca['table']===_0xc415('0x99')){_0x3a0fc2[_0xc415('0x42')](_0x3b3fca['table']+_0xc415('0x9a'),_0x4bdf5e[_0xc415('0x9b')],_0x4bdf5e['endDate']);}else{_0x3a0fc2[_0xc415('0x42')](_0x3b3fca[_0xc415('0x74')]+_0xc415('0x9c'),_0x4bdf5e['startDate'],_0x4bdf5e['endDate']);}if(_0x3d912b){logger[_0xc415('0x9d')](_0xc415('0x9e'),_0x3a0fc2[_0xc415('0x85')]());require(_0xc415('0x9f'))[_0xc415('0xa0')](path['join'](__dirname,_0xc415('0xa1'),_0x3d912b['output']),[_0x3d912b['id'],_0x3a0fc2['toString'](),path[_0xc415('0x57')](__dirname,_0xc415('0xa2'),_0x3d912b[_0xc415('0xa3')]),_0x230459]);return _0x3d912b;}else{var _0x4e02a0=squel[_0xc415('0x72')]();_0x4e02a0[_0xc415('0x73')]('('+_0x3a0fc2['toString']()+')','countTable');_0x4e02a0[_0xc415('0x76')](_0xc415('0xa4'),_0xc415('0x22'));_0x3a0fc2[_0xc415('0x21')](_0x4bdf5e[_0xc415('0x21')]||_0x519452);_0x3a0fc2[_0xc415('0x1f')](_0x4bdf5e['offset']||0x0);return dbH[_0xc415('0x84')]['query'](_0x4e02a0[_0xc415('0x85')](),{'type':dbH[_0xc415('0x84')][_0xc415('0xa5')]['SELECT']})[_0xc415('0x28')](function(_0x251692){if(!_0x251692[_0xc415('0x3d')]){_0x460c73=0x0;}else{_0x460c73=_0x251692[0x0][_0xc415('0x22')]||0x0;}return dbH[_0xc415('0x84')]['query'](_0x3a0fc2['toString'](),{'type':dbH[_0xc415('0x84')]['QueryTypes'][_0xc415('0x86')]});})[_0xc415('0x28')](function(_0x31e5ce){return{'rows':_0x31e5ce||[],'count':_0x460c73};});}});}exports[_0xc415('0xa6')]=function(_0x24b94c,_0x1b1a85){return runReport(_0x24b94c[_0xc415('0x6b')],_0x24b94c[_0xc415('0x37')],_0x24b94c[_0xc415('0x46')])[_0xc415('0x28')](respondWithResult(_0x1b1a85,null))[_0xc415('0x4b')](handleError(_0x1b1a85,null));};exports['runReport']=runReport;exports[_0xc415('0x37')]=function(_0x1241dc,_0x9d3a24){var _0x477ba8=0xa;var _0x31ecd4=['join',_0xc415('0x58'),'right_join',_0xc415('0x59')];var _0x67c171={'SUM':'SUM(%s)','COUNT':_0xc415('0x5b'),'COUNT DISTINCT':_0xc415('0x88'),'MAX':_0xc415('0x5c'),'MIN':_0xc415('0x5d'),'AVG':_0xc415('0x5e'),'GROUP_CONCAT':_0xc415('0x5f'),'GROUP_CONCAT ASC':_0xc415('0x60'),'GROUP_CONCAT DESC':_0xc415('0x89')};var _0x27e582={'SEC_TO_TIME':_0xc415('0x8a'),'DATE':'DATE(%s)','HOUR':_0xc415('0x61'),'ROUND':_0xc415('0x62'),'UNIX_TIMESTAMP':_0xc415('0x8c')};var _0x3966e5=function(_0x197d7f){return!_[_0xc415('0x63')]([_0xc415('0x64'),_0xc415('0x8d'),_0xc415('0x65'),_0xc415('0x66')],_0x197d7f);};var _0x55db7c=function(_0x22a1ab){if(!_0x22a1ab||!_0x22a1ab[_0xc415('0x67')][_0xc415('0x3d')]){return'';}for(var _0x4da32c='(',_0x427319=0x0;_0x427319<_0x22a1ab[_0xc415('0x67')]['length'];_0x427319+=0x1){_0x427319>0x0&&(_0x4da32c+='\x20'+_0x22a1ab[_0xc415('0x68')]+'\x20');_0x4da32c+=_0x22a1ab[_0xc415('0x67')][_0x427319][_0xc415('0x69')]?_0x55db7c(_0x22a1ab[_0xc415('0x67')][_0x427319][_0xc415('0x69')]):_0x22a1ab[_0xc415('0x67')][_0x427319][_0xc415('0x76')]+'\x20'+_0x22a1ab[_0xc415('0x67')][_0x427319][_0xc415('0x6a')]+(_0x3966e5(_0x22a1ab[_0xc415('0x67')][_0x427319]['condition'])?'\x20'+_0x22a1ab[_0xc415('0x67')][_0x427319][_0xc415('0x8e')]:'');}return _0x4da32c+')';};var _0x4cfc66={'where':{'id':_0x1241dc['params']['id']}},_0x486734,_0x4d3af7,_0x3198eb,_0x27322d,_0x265d20;_0x4cfc66=_[_0xc415('0x43')]({},_0x4cfc66,_0x1241dc[_0xc415('0x46')]);return db[_0xc415('0x31')][_0xc415('0x4d')](_0x4cfc66)['then'](function(_0x186dca){if(_0x186dca){_0x486734=_0x186dca;return _0x186dca[_0xc415('0x6c')]();}return null;})[_0xc415('0x28')](function(_0x1e091f){if(_0x1e091f){if(!_0x1e091f['length']){throw new db[(_0xc415('0x6d'))][(_0xc415('0x6e'))](_0xc415('0x6f'),0x193);}_0x4d3af7=_0x1e091f;return db['AnalyticMetric'][_0xc415('0x49')]({'raw':!![]});}return null;})[_0xc415('0x28')](function(_0x4e5430){if(_0x4e5430){_0x3198eb=_['keyBy'](_0x4e5430,'id');var _0x2cea62;var _0x12f11c=squel['select']();_0x12f11c[_0xc415('0x73')](_0x486734[_0xc415('0x74')]);for(var _0x4b262f=0x0;_0x4b262f<_0x4d3af7['length'];_0x4b262f+=0x1){_0x2cea62=_0x4d3af7[_0x4b262f][_0xc415('0x75')]?_0x3198eb[_0x4d3af7[_0x4b262f][_0xc415('0x75')]][_0xc415('0x8f')]:_0x4d3af7[_0x4b262f][_0xc415('0x76')];_0x2cea62=_0x4d3af7[_0x4b262f][_0xc415('0x77')]?_[_0xc415('0x78')](_0x67c171[_0x4d3af7[_0x4b262f]['function']],'%s',_0x2cea62):_0x2cea62;_0x2cea62=_0x4d3af7[_0x4b262f]['format']?_[_0xc415('0x78')](_0x27e582[_0x4d3af7[_0x4b262f][_0xc415('0x79')]],'%s',_0x2cea62):_0x2cea62;if(_0x4d3af7[_0x4b262f][_0xc415('0x7a')]){_0x12f11c[_0xc415('0x69')](_0x2cea62);}_0x4d3af7[_0x4b262f][_0xc415('0x7b')]&&_0x12f11c[_0xc415('0x7c')](_0x2cea62,_0x4d3af7[_0x4b262f][_0xc415('0x7b')]===_0xc415('0x90')?![]:!![]);_0x12f11c[_0xc415('0x76')](_0x2cea62,_0x4d3af7[_0x4b262f][_0xc415('0x91')]||_0x2cea62);}if(_0x486734[_0xc415('0x7d')]){_0x486734[_0xc415('0x7d')]=JSON[_0xc415('0x7e')](_0x486734[_0xc415('0x7d')]);for(var _0x26f212=0x0;_0x26f212<_0x486734[_0xc415('0x7d')]['length'];_0x26f212+=0x1){if(_0x486734[_0xc415('0x7d')][_0x26f212][_0xc415('0x34')]&&_[_0xc415('0x63')](_0x31ecd4,_0x486734[_0xc415('0x7d')][_0x26f212]['type'])&&_0x486734[_0xc415('0x7d')][_0x26f212][_0xc415('0x82')]&&_0x486734['joins'][_0x26f212][_0xc415('0x7f')]&&_0x486734[_0xc415('0x7d')][_0x26f212][_0xc415('0x80')]){_0x12f11c[_0x486734[_0xc415('0x7d')][_0x26f212]['type']](_0x486734[_0xc415('0x7d')][_0x26f212]['foreignTable'],null,util['format'](_0xc415('0x81'),_0x486734['table'],_0x486734[_0xc415('0x7d')][_0x26f212][_0xc415('0x82')],_0x486734[_0xc415('0x7d')][_0x26f212][_0xc415('0x7f')],_0x486734[_0xc415('0x7d')][_0x26f212]['foreignKey']));}}}if(_0x486734[_0xc415('0x83')]){_0x486734[_0xc415('0x83')]=JSON[_0xc415('0x7e')](_0x486734['conditions']);_0x12f11c[_0xc415('0x42')](_0x55db7c(_0x486734['conditions']['group']));}_0x265d20=_0x12f11c[_0xc415('0x92')]();_0x12f11c[_0xc415('0x21')](_0x477ba8);_0x12f11c['offset'](0x0);logger[_0xc415('0xa7')](_0xc415('0xa8'),_0x12f11c[_0xc415('0x85')]());return dbH['sequelize'][_0xc415('0x37')](_0x12f11c[_0xc415('0x85')](),{'type':dbH[_0xc415('0x84')]['QueryTypes'][_0xc415('0x86')]});}})[_0xc415('0x28')](function(){return{'sql':_0x265d20[_0xc415('0x85')]()};})[_0xc415('0x28')](respondWithResult(_0x9d3a24,null))['catch'](handleError(_0x9d3a24,null));};
\ No newline at end of file
+var _0x37a5=['body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','Reports','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','find','join','left_join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','DATE(%s)','HOUR(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','rules','group','field','condition','value','getFields','Sequelize','ValidationErrorItem','findAll','select','MetricId','replace','function','format','groupBy','orderBy','DESC','alias','joins','parse','parentKey','foreignKey','foreignTable','table','conditions','debug','toString','sequelize','QueryTypes','SELECT','ROUND(%s)','IS\x20EMPTY','IS\x20NOT\x20EMPTY','operator','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','from','metric','%s.%s\x20=\x20%s.%s','clone','output','%s-%s.%s','randomstring','generate','csv','custom','AnalyticExtractedReport','cdr','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','Run\x20Query:','child_process','../../components/export/','../../files/reports','savename','COUNT(*)','run','runReport','Limited\x20Query:','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','end','offset','limit','undefined','count','status','set','json','reject','save','then','destroy','get','CustomReports','UserProfileResource','error','stack','name','rawAttributes','fieldName','key','model','query','keys','intersection','attributes','fields','length','nolimit','order','sort','where','filters','pick','filter','merge','map','type','VIRTUAL','options','includeAll','AnalyticCustomReport','rows','catch','show','params','include','create'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x37a5,0x100));var _0x537a=function(_0x279d37,_0x14de3f){_0x279d37=_0x279d37-0x0;var _0x530173=_0x37a5[_0x279d37];return _0x530173;};'use strict';var emlformat=require(_0x537a('0x0'));var rimraf=require(_0x537a('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x537a('0x2'));var moment=require(_0x537a('0x3'));var BPromise=require(_0x537a('0x4'));var Mustache=require(_0x537a('0x5'));var util=require(_0x537a('0x6'));var path=require(_0x537a('0x7'));var sox=require(_0x537a('0x8'));var csv=require(_0x537a('0x9'));var ejs=require(_0x537a('0xa'));var fs=require('fs');var fs_extra=require(_0x537a('0xb'));var _=require(_0x537a('0xc'));var squel=require(_0x537a('0xd'));var crypto=require(_0x537a('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x537a('0xf'));var toCsv=require('to-csv');var querystring=require(_0x537a('0x10'));var Papa=require(_0x537a('0x11'));var Redis=require(_0x537a('0x12'));var authService=require(_0x537a('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x537a('0x14'));var hardwareService=require(_0x537a('0x15'));var logger=require('../../config/logger')(_0x537a('0x16'));var utils=require('../../config/utils');var config=require(_0x537a('0x17'));var licenseUtil=require(_0x537a('0x18'));var db=require(_0x537a('0x19'))['db'];var dbH=require(_0x537a('0x19'))[_0x537a('0x1a')];function respondWithStatusCode(_0x3aac38,_0x2af99d){_0x2af99d=_0x2af99d||0xcc;return function(_0x1d217d){if(_0x1d217d){return _0x3aac38[_0x537a('0x1b')](_0x2af99d);}return _0x3aac38['status'](_0x2af99d)[_0x537a('0x1c')]();};}function respondWithResult(_0x24251f,_0x5408ec){_0x5408ec=_0x5408ec||0xc8;return function(_0x43f947){if(_0x43f947){return _0x24251f['status'](_0x5408ec)['json'](_0x43f947);}};}function respondWithFilteredResult(_0x22ca6d,_0x3dbaad){return function(_0x1de481){if(_0x1de481){var _0x126282=typeof _0x3dbaad[_0x537a('0x1d')]==='undefined'&&typeof _0x3dbaad[_0x537a('0x1e')]===_0x537a('0x1f');var _0x13878d=_0x1de481['count'];var _0x45ac62=_0x126282?0x0:_0x3dbaad[_0x537a('0x1d')];var _0x55b05e=_0x126282?_0x1de481[_0x537a('0x20')]:_0x3dbaad[_0x537a('0x1d')]+_0x3dbaad[_0x537a('0x1e')];var _0x81d861;if(_0x55b05e>=_0x13878d){_0x55b05e=_0x13878d;_0x81d861=0xc8;}else{_0x81d861=0xce;}_0x22ca6d[_0x537a('0x21')](_0x81d861);return _0x22ca6d[_0x537a('0x22')]('Content-Range',_0x45ac62+'-'+_0x55b05e+'/'+_0x13878d)[_0x537a('0x23')](_0x1de481);}return null;};}function patchUpdates(_0x58693f){return function(_0x261149){try{jsonpatch['apply'](_0x261149,_0x58693f,!![]);}catch(_0x308018){return BPromise[_0x537a('0x24')](_0x308018);}return _0x261149[_0x537a('0x25')]();};}function saveUpdates(_0x5ac447,_0x47c84d){return function(_0xec03c){if(_0xec03c){return _0xec03c['update'](_0x5ac447)[_0x537a('0x26')](function(_0x1fd6ee){return _0x1fd6ee;});}return null;};}function removeEntity(_0xff35ae,_0x343f7f){return function(_0x33f05f){if(_0x33f05f){return _0x33f05f[_0x537a('0x27')]()[_0x537a('0x26')](function(){var _0x4f9759=_0x33f05f[_0x537a('0x28')]({'plain':!![]});var _0x1f7835=_0x537a('0x29');return db[_0x537a('0x2a')][_0x537a('0x27')]({'where':{'type':_0x1f7835,'resourceId':_0x4f9759['id']}})['then'](function(){return _0x33f05f;});})[_0x537a('0x26')](function(){_0xff35ae['status'](0xcc)[_0x537a('0x1c')]();});}};}function handleEntityNotFound(_0x3720f6,_0x55d7d7){return function(_0x55eda1){if(!_0x55eda1){_0x3720f6[_0x537a('0x1b')](0x194);}return _0x55eda1;};}function handleError(_0x23b9ab,_0xf9ee53){_0xf9ee53=_0xf9ee53||0x1f4;return function(_0x196ee8){logger[_0x537a('0x2b')](_0x196ee8[_0x537a('0x2c')]);if(_0x196ee8[_0x537a('0x2d')]){delete _0x196ee8[_0x537a('0x2d')];}_0x23b9ab[_0x537a('0x21')](_0xf9ee53)['send'](_0x196ee8);};}exports['index']=function(_0x324cc8,_0x24e703){var _0x991c8={},_0xa47381={},_0x445f99={'count':0x0,'rows':[]};var _0x2284ef=_['map'](db['AnalyticCustomReport'][_0x537a('0x2e')],function(_0x29e813){return{'name':_0x29e813[_0x537a('0x2f')],'type':_0x29e813['type'][_0x537a('0x30')]};});_0xa47381[_0x537a('0x31')]=_['map'](_0x2284ef,'name');_0xa47381[_0x537a('0x32')]=_[_0x537a('0x33')](_0x324cc8['query']);_0xa47381['filters']=_[_0x537a('0x34')](_0xa47381[_0x537a('0x31')],_0xa47381[_0x537a('0x32')]);_0x991c8[_0x537a('0x35')]=_[_0x537a('0x34')](_0xa47381[_0x537a('0x31')],qs[_0x537a('0x36')](_0x324cc8['query'][_0x537a('0x36')]));_0x991c8[_0x537a('0x35')]=_0x991c8[_0x537a('0x35')][_0x537a('0x37')]?_0x991c8[_0x537a('0x35')]:_0xa47381[_0x537a('0x31')];if(!_0x324cc8[_0x537a('0x32')]['hasOwnProperty'](_0x537a('0x38'))){_0x991c8[_0x537a('0x1e')]=qs[_0x537a('0x1e')](_0x324cc8[_0x537a('0x32')][_0x537a('0x1e')]);_0x991c8[_0x537a('0x1d')]=qs['offset'](_0x324cc8[_0x537a('0x32')][_0x537a('0x1d')]);}_0x991c8[_0x537a('0x39')]=qs[_0x537a('0x3a')](_0x324cc8[_0x537a('0x32')][_0x537a('0x3a')]);_0x991c8[_0x537a('0x3b')]=qs[_0x537a('0x3c')](_[_0x537a('0x3d')](_0x324cc8[_0x537a('0x32')],_0xa47381['filters']),_0x2284ef);if(_0x324cc8[_0x537a('0x32')][_0x537a('0x3e')]){_0x991c8[_0x537a('0x3b')]=_[_0x537a('0x3f')](_0x991c8[_0x537a('0x3b')],{'$or':_[_0x537a('0x40')](_0x2284ef,function(_0x2cca08){if(_0x2cca08[_0x537a('0x41')]!==_0x537a('0x42')){var _0x52c40d={};_0x52c40d[_0x2cca08[_0x537a('0x2d')]]={'$like':'%'+_0x324cc8[_0x537a('0x32')]['filter']+'%'};return _0x52c40d;}})});}_0x991c8=_['merge']({},_0x991c8,_0x324cc8[_0x537a('0x43')]);var _0x2fa5cd={'where':_0x991c8[_0x537a('0x3b')]};return db['AnalyticCustomReport'][_0x537a('0x20')](_0x2fa5cd)[_0x537a('0x26')](function(_0xa07f0a){_0x445f99[_0x537a('0x20')]=_0xa07f0a;if(_0x324cc8['query'][_0x537a('0x44')]){_0x991c8['include']=[{'all':!![]}];}return db[_0x537a('0x45')]['findAll'](_0x991c8);})[_0x537a('0x26')](function(_0x43cca7){_0x445f99[_0x537a('0x46')]=_0x43cca7;return _0x445f99;})[_0x537a('0x26')](respondWithFilteredResult(_0x24e703,_0x991c8))[_0x537a('0x47')](handleError(_0x24e703,null));};exports[_0x537a('0x48')]=function(_0x3e20f0,_0x12deb2){var _0x2d2e67={'raw':![],'where':{'id':_0x3e20f0[_0x537a('0x49')]['id']}},_0x295d8c={};_0x295d8c['model']=_['keys'](db[_0x537a('0x45')][_0x537a('0x2e')]);_0x295d8c[_0x537a('0x32')]=_[_0x537a('0x33')](_0x3e20f0[_0x537a('0x32')]);_0x295d8c['filters']=_[_0x537a('0x34')](_0x295d8c['model'],_0x295d8c[_0x537a('0x32')]);_0x2d2e67[_0x537a('0x35')]=_['intersection'](_0x295d8c[_0x537a('0x31')],qs[_0x537a('0x36')](_0x3e20f0['query'][_0x537a('0x36')]));_0x2d2e67['attributes']=_0x2d2e67['attributes'][_0x537a('0x37')]?_0x2d2e67['attributes']:_0x295d8c[_0x537a('0x31')];if(_0x3e20f0['query'][_0x537a('0x44')]){_0x2d2e67[_0x537a('0x4a')]=[{'all':!![]}];}_0x2d2e67=_[_0x537a('0x3f')]({},_0x2d2e67,_0x3e20f0[_0x537a('0x43')]);return db[_0x537a('0x45')]['find'](_0x2d2e67)[_0x537a('0x26')](handleEntityNotFound(_0x12deb2,null))['then'](respondWithResult(_0x12deb2,null))[_0x537a('0x47')](handleError(_0x12deb2,null));};exports[_0x537a('0x4b')]=function(_0x5243a9,_0x7cf7c3){return db[_0x537a('0x45')][_0x537a('0x4b')](_0x5243a9[_0x537a('0x4c')],{})[_0x537a('0x26')](function(_0x178659){var _0x3272ed=_0x5243a9['user']['get']({'plain':!![]});if(!_0x3272ed)throw new Error(_0x537a('0x4d'));if(_0x3272ed['role']===_0x537a('0x4e')){var _0x1101a2=_0x178659[_0x537a('0x28')]({'plain':!![]});var _0x4aad1e=_0x537a('0x4f');return db[_0x537a('0x50')]['find']({'where':{'name':_0x4aad1e,'userProfileId':_0x3272ed['userProfileId']},'raw':!![]})[_0x537a('0x26')](function(_0xd37962){if(_0xd37962&&_0xd37962[_0x537a('0x51')]===0x0){return db[_0x537a('0x2a')]['create']({'name':_0x1101a2[_0x537a('0x2d')],'resourceId':_0x1101a2['id'],'type':_0x537a('0x29'),'sectionId':_0xd37962['id']},{})[_0x537a('0x26')](function(){return _0x178659;});}else{return _0x178659;}})['catch'](function(_0xb0eb4d){logger[_0x537a('0x2b')](_0x537a('0x52'),_0xb0eb4d);throw _0xb0eb4d;});}return _0x178659;})[_0x537a('0x26')](respondWithResult(_0x7cf7c3,0xc9))[_0x537a('0x47')](handleError(_0x7cf7c3,null));};exports[_0x537a('0x53')]=function(_0xe2d43b,_0x2d258a){if(_0xe2d43b[_0x537a('0x4c')]['id']){delete _0xe2d43b[_0x537a('0x4c')]['id'];}return db[_0x537a('0x45')]['find']({'where':{'id':_0xe2d43b[_0x537a('0x49')]['id']}})[_0x537a('0x26')](handleEntityNotFound(_0x2d258a,null))[_0x537a('0x26')](saveUpdates(_0xe2d43b[_0x537a('0x4c')],null))[_0x537a('0x26')](respondWithResult(_0x2d258a,null))[_0x537a('0x47')](handleError(_0x2d258a,null));};exports[_0x537a('0x27')]=function(_0x40587e,_0x60388a){return db[_0x537a('0x45')][_0x537a('0x54')]({'where':{'id':_0x40587e[_0x537a('0x49')]['id']}})[_0x537a('0x26')](handleEntityNotFound(_0x60388a,null))[_0x537a('0x26')](removeEntity(_0x60388a,null))[_0x537a('0x47')](handleError(_0x60388a,null));};exports['preview']=function(_0x2ac3c2,_0x51e712){var _0x549e10=0xa;var _0x104c5c=[_0x537a('0x55'),_0x537a('0x56'),_0x537a('0x57'),_0x537a('0x58')];var _0x5eb546={'SUM':_0x537a('0x59'),'COUNT':_0x537a('0x5a'),'COUNT DISTINCT':_0x537a('0x5b'),'MAX':_0x537a('0x5c'),'MIN':_0x537a('0x5d'),'AVG':_0x537a('0x5e'),'GROUP_CONCAT':_0x537a('0x5f'),'GROUP_CONCAT ASC':_0x537a('0x60'),'GROUP_CONCAT DESC':_0x537a('0x61')};var _0x3df5f3={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x537a('0x62'),'HOUR':_0x537a('0x63'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x537a('0x64')};var _0x61aa87=function(_0x19affc){return!_[_0x537a('0x65')]([_0x537a('0x66'),_0x537a('0x67'),'IS\x20EMPTY','IS\x20NOT\x20EMPTY'],_0x19affc);};var _0x3de487=function(_0x432eed){if(!_0x432eed||!_0x432eed[_0x537a('0x68')][_0x537a('0x37')]){return'';}for(var _0x59c8c6='(',_0x24c8cd=0x0;_0x24c8cd<_0x432eed[_0x537a('0x68')][_0x537a('0x37')];_0x24c8cd+=0x1){_0x24c8cd>0x0&&(_0x59c8c6+='\x20'+_0x432eed['operator']+'\x20');_0x59c8c6+=_0x432eed['rules'][_0x24c8cd][_0x537a('0x69')]?_0x3de487(_0x432eed[_0x537a('0x68')][_0x24c8cd][_0x537a('0x69')]):_0x432eed[_0x537a('0x68')][_0x24c8cd][_0x537a('0x6a')]+'\x20'+_0x432eed[_0x537a('0x68')][_0x24c8cd][_0x537a('0x6b')]+(_0x61aa87(_0x432eed['rules'][_0x24c8cd]['condition'])?'\x20'+_0x432eed[_0x537a('0x68')][_0x24c8cd][_0x537a('0x6c')]:'');}return _0x59c8c6+')';};var _0x1db9c5={'where':{'id':_0x2ac3c2[_0x537a('0x49')]['id']}},_0x4b9766,_0x2ccff5,_0x1a044f,_0x1655cb,_0x14e0a2;_0x1db9c5=_['merge']({},_0x1db9c5,_0x2ac3c2[_0x537a('0x43')]);return db[_0x537a('0x45')]['find'](_0x1db9c5)[_0x537a('0x26')](function(_0x268e01){if(_0x268e01){_0x4b9766=_0x268e01;return _0x268e01[_0x537a('0x6d')]();}return null;})[_0x537a('0x26')](function(_0x29178c){if(_0x29178c){if(!_0x29178c['length']){throw new db[(_0x537a('0x6e'))][(_0x537a('0x6f'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x2ccff5=_0x29178c;return db['AnalyticMetric'][_0x537a('0x70')]({'raw':!![]});}return null;})[_0x537a('0x26')](function(_0x4a5e3d){if(_0x4a5e3d){_0x1a044f=_['keyBy'](_0x4a5e3d,'id');var _0x3b23b9;var _0x14c7bd=squel[_0x537a('0x71')]();_0x14c7bd['from'](_0x4b9766['table']);for(var _0x5b3601=0x0;_0x5b3601<_0x2ccff5['length'];_0x5b3601+=0x1){_0x3b23b9=_0x2ccff5[_0x5b3601][_0x537a('0x72')]?_0x1a044f[_0x2ccff5[_0x5b3601]['MetricId']]['metric']:_0x2ccff5[_0x5b3601][_0x537a('0x6a')];_0x3b23b9=_0x2ccff5[_0x5b3601]['function']?_[_0x537a('0x73')](_0x5eb546[_0x2ccff5[_0x5b3601][_0x537a('0x74')]],'%s',_0x3b23b9):_0x3b23b9;_0x3b23b9=_0x2ccff5[_0x5b3601]['format']?_[_0x537a('0x73')](_0x3df5f3[_0x2ccff5[_0x5b3601][_0x537a('0x75')]],'%s',_0x3b23b9):_0x3b23b9;if(_0x2ccff5[_0x5b3601][_0x537a('0x76')]){_0x14c7bd['group'](_0x3b23b9);}_0x2ccff5[_0x5b3601][_0x537a('0x77')]&&_0x14c7bd[_0x537a('0x39')](_0x3b23b9,_0x2ccff5[_0x5b3601]['orderBy']===_0x537a('0x78')?![]:!![]);_0x14c7bd['field'](_0x3b23b9,_0x2ccff5[_0x5b3601][_0x537a('0x79')]||_0x3b23b9);}if(_0x4b9766['joins']){_0x4b9766[_0x537a('0x7a')]=JSON[_0x537a('0x7b')](_0x4b9766[_0x537a('0x7a')]);for(var _0x2f88cc=0x0;_0x2f88cc<_0x4b9766[_0x537a('0x7a')][_0x537a('0x37')];_0x2f88cc+=0x1){if(_0x4b9766[_0x537a('0x7a')][_0x2f88cc][_0x537a('0x41')]&&_[_0x537a('0x65')](_0x104c5c,_0x4b9766[_0x537a('0x7a')][_0x2f88cc][_0x537a('0x41')])&&_0x4b9766[_0x537a('0x7a')][_0x2f88cc][_0x537a('0x7c')]&&_0x4b9766[_0x537a('0x7a')][_0x2f88cc]['foreignTable']&&_0x4b9766[_0x537a('0x7a')][_0x2f88cc][_0x537a('0x7d')]){_0x14c7bd[_0x4b9766[_0x537a('0x7a')][_0x2f88cc][_0x537a('0x41')]](_0x4b9766[_0x537a('0x7a')][_0x2f88cc][_0x537a('0x7e')],null,util['format']('%s.%s\x20=\x20%s.%s',_0x4b9766[_0x537a('0x7f')],_0x4b9766[_0x537a('0x7a')][_0x2f88cc]['parentKey'],_0x4b9766[_0x537a('0x7a')][_0x2f88cc][_0x537a('0x7e')],_0x4b9766[_0x537a('0x7a')][_0x2f88cc][_0x537a('0x7d')]));}}}if(_0x4b9766[_0x537a('0x80')]){_0x4b9766[_0x537a('0x80')]=JSON[_0x537a('0x7b')](_0x4b9766['conditions']);_0x14c7bd[_0x537a('0x3b')](_0x3de487(_0x4b9766[_0x537a('0x80')][_0x537a('0x69')]));}_0x14e0a2=_0x14c7bd['clone']();_0x14c7bd[_0x537a('0x1e')](_0x549e10);_0x14c7bd[_0x537a('0x1d')](0x0);logger[_0x537a('0x81')]('Limited\x20Query:',_0x14c7bd[_0x537a('0x82')]());return dbH[_0x537a('0x83')][_0x537a('0x32')](_0x14c7bd[_0x537a('0x82')](),{'type':dbH[_0x537a('0x83')][_0x537a('0x84')][_0x537a('0x85')]});}})[_0x537a('0x26')](respondWithResult(_0x51e712,null))[_0x537a('0x47')](handleError(_0x51e712,null));};function runReport(_0x6b309e,_0x954afe,_0xf9eaa9){var _0x106f85=_0x954afe['name'];var _0x2ff464=0xa;var _0x413b85=[_0x537a('0x55'),'left_join',_0x537a('0x57'),_0x537a('0x58')];var _0x3aa14b={'SUM':'SUM(%s)','COUNT':_0x537a('0x5a'),'COUNT DISTINCT':_0x537a('0x5b'),'MAX':_0x537a('0x5c'),'MIN':'MIN(%s)','AVG':_0x537a('0x5e'),'GROUP_CONCAT':_0x537a('0x5f'),'GROUP_CONCAT ASC':_0x537a('0x60'),'GROUP_CONCAT DESC':_0x537a('0x61')};var _0x32875a={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x537a('0x62'),'HOUR':_0x537a('0x63'),'ROUND':_0x537a('0x86'),'UNIX_TIMESTAMP':_0x537a('0x64')};var _0x5e9a5c=function(_0xa8ae4c){return!_[_0x537a('0x65')]([_0x537a('0x66'),'IS\x20NOT\x20NULL',_0x537a('0x87'),_0x537a('0x88')],_0xa8ae4c);};var _0x10f1af=function(_0x481254){if(!_0x481254||!_0x481254[_0x537a('0x68')][_0x537a('0x37')]){return'';}for(var _0x309f9b='(',_0xd1e8ef=0x0;_0xd1e8ef<_0x481254['rules']['length'];_0xd1e8ef+=0x1){_0xd1e8ef>0x0&&(_0x309f9b+='\x20'+_0x481254[_0x537a('0x89')]+'\x20');_0x309f9b+=_0x481254[_0x537a('0x68')][_0xd1e8ef][_0x537a('0x69')]?_0x10f1af(_0x481254[_0x537a('0x68')][_0xd1e8ef][_0x537a('0x69')]):_0x481254[_0x537a('0x68')][_0xd1e8ef][_0x537a('0x6a')]+'\x20'+_0x481254[_0x537a('0x68')][_0xd1e8ef][_0x537a('0x6b')]+(_0x5e9a5c(_0x481254['rules'][_0xd1e8ef][_0x537a('0x6b')])?'\x20'+_0x481254[_0x537a('0x68')][_0xd1e8ef][_0x537a('0x6c')]:'');}return _0x309f9b+')';};var _0xa805e={'where':{'id':_0x6b309e['id']}},_0xabac0f,_0x1c95e0,_0x35a164,_0xc05e6e,_0x7d1805;_0xa805e=_[_0x537a('0x3f')]({},_0xa805e,_0xf9eaa9);return db['AnalyticCustomReport'][_0x537a('0x54')](_0xa805e)['then'](function(_0x14f623){if(_0x14f623){_0xabac0f=_0x14f623;return _0x14f623['getFields']();}return null;})['then'](function(_0x53efa9){if(_0x53efa9){if(!_0x53efa9[_0x537a('0x37')]){throw new db[(_0x537a('0x6e'))]['ValidationErrorItem'](_0x537a('0x8a'),0x193);}_0x1c95e0=_0x53efa9;return db[_0x537a('0x8b')][_0x537a('0x70')]({'raw':!![]});}return null;})[_0x537a('0x26')](function(_0x1ad8d7){if(_0x1ad8d7){_0x35a164=_[_0x537a('0x8c')](_0x1ad8d7,'id');var _0x2c3e3e;var _0x3c1c43=squel[_0x537a('0x71')]();_0x3c1c43[_0x537a('0x8d')](_0xabac0f[_0x537a('0x7f')]);for(var _0x1d343c=0x0;_0x1d343c<_0x1c95e0[_0x537a('0x37')];_0x1d343c+=0x1){_0x2c3e3e=_0x1c95e0[_0x1d343c][_0x537a('0x72')]?_0x35a164[_0x1c95e0[_0x1d343c]['MetricId']][_0x537a('0x8e')]:_0x1c95e0[_0x1d343c][_0x537a('0x6a')];_0x2c3e3e=_0x1c95e0[_0x1d343c]['function']?_[_0x537a('0x73')](_0x3aa14b[_0x1c95e0[_0x1d343c][_0x537a('0x74')]],'%s',_0x2c3e3e):_0x2c3e3e;_0x2c3e3e=_0x1c95e0[_0x1d343c][_0x537a('0x75')]?_[_0x537a('0x73')](_0x32875a[_0x1c95e0[_0x1d343c][_0x537a('0x75')]],'%s',_0x2c3e3e):_0x2c3e3e;if(_0x1c95e0[_0x1d343c][_0x537a('0x76')]){_0x3c1c43[_0x537a('0x69')](_0x2c3e3e);}_0x1c95e0[_0x1d343c][_0x537a('0x77')]&&_0x3c1c43['order'](_0x2c3e3e,_0x1c95e0[_0x1d343c][_0x537a('0x77')]==='DESC'?![]:!![]);_0x3c1c43[_0x537a('0x6a')](_0x2c3e3e,_0x1c95e0[_0x1d343c]['alias']||_0x2c3e3e);}if(_0xabac0f[_0x537a('0x7a')]){_0xabac0f[_0x537a('0x7a')]=JSON['parse'](_0xabac0f['joins']);for(var _0x468d21=0x0;_0x468d21<_0xabac0f[_0x537a('0x7a')]['length'];_0x468d21+=0x1){if(_0xabac0f[_0x537a('0x7a')][_0x468d21][_0x537a('0x41')]&&_[_0x537a('0x65')](_0x413b85,_0xabac0f[_0x537a('0x7a')][_0x468d21][_0x537a('0x41')])&&_0xabac0f[_0x537a('0x7a')][_0x468d21][_0x537a('0x7c')]&&_0xabac0f[_0x537a('0x7a')][_0x468d21][_0x537a('0x7e')]&&_0xabac0f['joins'][_0x468d21][_0x537a('0x7d')]){_0x3c1c43[_0xabac0f[_0x537a('0x7a')][_0x468d21][_0x537a('0x41')]](_0xabac0f[_0x537a('0x7a')][_0x468d21][_0x537a('0x7e')],null,util[_0x537a('0x75')](_0x537a('0x8f'),_0xabac0f[_0x537a('0x7f')],_0xabac0f[_0x537a('0x7a')][_0x468d21][_0x537a('0x7c')],_0xabac0f[_0x537a('0x7a')][_0x468d21][_0x537a('0x7e')],_0xabac0f[_0x537a('0x7a')][_0x468d21][_0x537a('0x7d')]));}}}if(_0xabac0f[_0x537a('0x80')]){_0xabac0f[_0x537a('0x80')]=JSON[_0x537a('0x7b')](_0xabac0f[_0x537a('0x80')]);_0x3c1c43['where'](_0x10f1af(_0xabac0f[_0x537a('0x80')][_0x537a('0x69')]));}_0x7d1805=_0x3c1c43[_0x537a('0x90')]();_0x3c1c43[_0x537a('0x1e')](_0x2ff464);_0x3c1c43['offset'](0x0);return;}})['then'](function(){if(_0x954afe[_0x537a('0x91')]==='web'){return null;}var _0xf8c42=_['merge'](_0x954afe,{'name':_0x954afe['fullPath']||_0x954afe[_0x537a('0x2d')]||_0xabac0f['name'],'basename':_0x106f85,'savename':util[_0x537a('0x75')](_0x537a('0x92'),_0x954afe['name']||_0xabac0f['name'],require(_0x537a('0x93'))[_0x537a('0x94')](0x4),_0x954afe['output']||_0x537a('0x95')),'reportId':_0xabac0f['id'],'reportType':_0x537a('0x96')});return db[_0x537a('0x97')]['create'](_0xf8c42,{'raw':!![]});})[_0x537a('0x26')](function(_0x4cdf8d){if(_0xabac0f[_0x537a('0x7f')]===_0x537a('0x98')){_0x7d1805[_0x537a('0x3b')](_0xabac0f[_0x537a('0x7f')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x954afe[_0x537a('0x99')],_0x954afe[_0x537a('0x9a')]);}else{_0x7d1805[_0x537a('0x3b')](_0xabac0f[_0x537a('0x7f')]+_0x537a('0x9b'),_0x954afe[_0x537a('0x99')],_0x954afe[_0x537a('0x9a')]);}if(_0x4cdf8d){logger[_0x537a('0x9c')](_0x537a('0x9d'),_0x7d1805[_0x537a('0x82')]());require(_0x537a('0x9e'))['fork'](path[_0x537a('0x55')](__dirname,_0x537a('0x9f'),_0x4cdf8d[_0x537a('0x91')]),[_0x4cdf8d['id'],_0x7d1805[_0x537a('0x82')](),path[_0x537a('0x55')](__dirname,_0x537a('0xa0'),_0x4cdf8d[_0x537a('0xa1')]),_0x106f85]);return _0x4cdf8d;}else{var _0x429c76=squel[_0x537a('0x71')]();_0x429c76[_0x537a('0x8d')]('('+_0x7d1805['toString']()+')','countTable');_0x429c76[_0x537a('0x6a')](_0x537a('0xa2'),_0x537a('0x20'));_0x7d1805[_0x537a('0x1e')](_0x954afe['limit']||_0x2ff464);_0x7d1805[_0x537a('0x1d')](_0x954afe[_0x537a('0x1d')]||0x0);return dbH[_0x537a('0x83')][_0x537a('0x32')](_0x429c76[_0x537a('0x82')](),{'type':dbH[_0x537a('0x83')][_0x537a('0x84')][_0x537a('0x85')]})[_0x537a('0x26')](function(_0x3aa15b){if(!_0x3aa15b['length']){_0xc05e6e=0x0;}else{_0xc05e6e=_0x3aa15b[0x0][_0x537a('0x20')]||0x0;}return dbH[_0x537a('0x83')][_0x537a('0x32')](_0x7d1805[_0x537a('0x82')](),{'type':dbH[_0x537a('0x83')][_0x537a('0x84')][_0x537a('0x85')]});})['then'](function(_0x38649d){return{'rows':_0x38649d||[],'count':_0xc05e6e};});}});}exports[_0x537a('0xa3')]=function(_0x3a4cdf,_0x388d08){return runReport(_0x3a4cdf[_0x537a('0x49')],_0x3a4cdf[_0x537a('0x32')],_0x3a4cdf[_0x537a('0x43')])[_0x537a('0x26')](respondWithResult(_0x388d08,null))['catch'](handleError(_0x388d08,null));};exports[_0x537a('0xa4')]=runReport;exports[_0x537a('0x32')]=function(_0x24a318,_0x124ed8){var _0xfca19=0xa;var _0x5b31c0=[_0x537a('0x55'),_0x537a('0x56'),_0x537a('0x57'),_0x537a('0x58')];var _0x51f7bc={'SUM':_0x537a('0x59'),'COUNT':_0x537a('0x5a'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':'MAX(%s)','MIN':_0x537a('0x5d'),'AVG':_0x537a('0x5e'),'GROUP_CONCAT':_0x537a('0x5f'),'GROUP_CONCAT ASC':_0x537a('0x60'),'GROUP_CONCAT DESC':_0x537a('0x61')};var _0xbab6bf={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x537a('0x62'),'HOUR':_0x537a('0x63'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x537a('0x64')};var _0x272158=function(_0x2ba6a5){return!_[_0x537a('0x65')]([_0x537a('0x66'),_0x537a('0x67'),'IS\x20EMPTY',_0x537a('0x88')],_0x2ba6a5);};var _0x1956b3=function(_0x154dd9){if(!_0x154dd9||!_0x154dd9['rules'][_0x537a('0x37')]){return'';}for(var _0x2a2134='(',_0x314f89=0x0;_0x314f89<_0x154dd9[_0x537a('0x68')][_0x537a('0x37')];_0x314f89+=0x1){_0x314f89>0x0&&(_0x2a2134+='\x20'+_0x154dd9['operator']+'\x20');_0x2a2134+=_0x154dd9[_0x537a('0x68')][_0x314f89][_0x537a('0x69')]?_0x1956b3(_0x154dd9[_0x537a('0x68')][_0x314f89][_0x537a('0x69')]):_0x154dd9[_0x537a('0x68')][_0x314f89]['field']+'\x20'+_0x154dd9['rules'][_0x314f89][_0x537a('0x6b')]+(_0x272158(_0x154dd9[_0x537a('0x68')][_0x314f89]['condition'])?'\x20'+_0x154dd9[_0x537a('0x68')][_0x314f89][_0x537a('0x6c')]:'');}return _0x2a2134+')';};var _0x57e4b9={'where':{'id':_0x24a318[_0x537a('0x49')]['id']}},_0x4428d2,_0x36b628,_0x5a665,_0x1d1969,_0x255281;_0x57e4b9=_['merge']({},_0x57e4b9,_0x24a318[_0x537a('0x43')]);return db[_0x537a('0x45')][_0x537a('0x54')](_0x57e4b9)[_0x537a('0x26')](function(_0x2ba332){if(_0x2ba332){_0x4428d2=_0x2ba332;return _0x2ba332['getFields']();}return null;})[_0x537a('0x26')](function(_0x4bd79b){if(_0x4bd79b){if(!_0x4bd79b[_0x537a('0x37')]){throw new db[(_0x537a('0x6e'))]['ValidationErrorItem'](_0x537a('0x8a'),0x193);}_0x36b628=_0x4bd79b;return db[_0x537a('0x8b')][_0x537a('0x70')]({'raw':!![]});}return null;})[_0x537a('0x26')](function(_0x4498df){if(_0x4498df){_0x5a665=_[_0x537a('0x8c')](_0x4498df,'id');var _0x104224;var _0x3f76fd=squel['select']();_0x3f76fd[_0x537a('0x8d')](_0x4428d2['table']);for(var _0x316781=0x0;_0x316781<_0x36b628[_0x537a('0x37')];_0x316781+=0x1){_0x104224=_0x36b628[_0x316781][_0x537a('0x72')]?_0x5a665[_0x36b628[_0x316781][_0x537a('0x72')]][_0x537a('0x8e')]:_0x36b628[_0x316781][_0x537a('0x6a')];_0x104224=_0x36b628[_0x316781][_0x537a('0x74')]?_['replace'](_0x51f7bc[_0x36b628[_0x316781][_0x537a('0x74')]],'%s',_0x104224):_0x104224;_0x104224=_0x36b628[_0x316781]['format']?_[_0x537a('0x73')](_0xbab6bf[_0x36b628[_0x316781][_0x537a('0x75')]],'%s',_0x104224):_0x104224;if(_0x36b628[_0x316781][_0x537a('0x76')]){_0x3f76fd[_0x537a('0x69')](_0x104224);}_0x36b628[_0x316781][_0x537a('0x77')]&&_0x3f76fd['order'](_0x104224,_0x36b628[_0x316781]['orderBy']===_0x537a('0x78')?![]:!![]);_0x3f76fd['field'](_0x104224,_0x36b628[_0x316781]['alias']||_0x104224);}if(_0x4428d2['joins']){_0x4428d2[_0x537a('0x7a')]=JSON[_0x537a('0x7b')](_0x4428d2[_0x537a('0x7a')]);for(var _0x4e89e0=0x0;_0x4e89e0<_0x4428d2[_0x537a('0x7a')][_0x537a('0x37')];_0x4e89e0+=0x1){if(_0x4428d2[_0x537a('0x7a')][_0x4e89e0][_0x537a('0x41')]&&_['includes'](_0x5b31c0,_0x4428d2[_0x537a('0x7a')][_0x4e89e0][_0x537a('0x41')])&&_0x4428d2['joins'][_0x4e89e0]['parentKey']&&_0x4428d2['joins'][_0x4e89e0]['foreignTable']&&_0x4428d2['joins'][_0x4e89e0][_0x537a('0x7d')]){_0x3f76fd[_0x4428d2[_0x537a('0x7a')][_0x4e89e0]['type']](_0x4428d2[_0x537a('0x7a')][_0x4e89e0][_0x537a('0x7e')],null,util[_0x537a('0x75')]('%s.%s\x20=\x20%s.%s',_0x4428d2['table'],_0x4428d2['joins'][_0x4e89e0][_0x537a('0x7c')],_0x4428d2[_0x537a('0x7a')][_0x4e89e0]['foreignTable'],_0x4428d2['joins'][_0x4e89e0][_0x537a('0x7d')]));}}}if(_0x4428d2[_0x537a('0x80')]){_0x4428d2[_0x537a('0x80')]=JSON[_0x537a('0x7b')](_0x4428d2[_0x537a('0x80')]);_0x3f76fd[_0x537a('0x3b')](_0x1956b3(_0x4428d2['conditions']['group']));}_0x255281=_0x3f76fd[_0x537a('0x90')]();_0x3f76fd[_0x537a('0x1e')](_0xfca19);_0x3f76fd['offset'](0x0);logger[_0x537a('0x81')](_0x537a('0xa5'),_0x3f76fd[_0x537a('0x82')]());return dbH[_0x537a('0x83')][_0x537a('0x32')](_0x3f76fd[_0x537a('0x82')](),{'type':dbH[_0x537a('0x83')][_0x537a('0x84')][_0x537a('0x85')]});}})[_0x537a('0x26')](function(){return{'sql':_0x255281[_0x537a('0x82')]()};})[_0x537a('0x26')](respondWithResult(_0x124ed8,null))['catch'](handleError(_0x124ed8,null));};
\ No newline at end of file