18 var _0x2a39=['sox','ejs','fs-extra','lodash','squel','crypto','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','status','end','json','offset','limit','undefined','count','set','apply','reject','save','then','destroy','error','name','send','index','map','fieldName','type','key','model','query','keys','filters','intersection','attributes','hasOwnProperty','nolimit','sort','where','filter','VIRTUAL','options','includeAll','include','AnalyticFieldReport','rows','catch','show','params','rawAttributes','fields','find','create','body','update','bulkDestroy','ids','addFields','AnalyticCustomReport','findOne','sequelize','transaction','CustomReportId','eml-format','rimraf','zip-dir','fast-json-patch','moment','util'];(function(_0xe1a3a5,_0xd3e341){var _0x362646=function(_0xdcef03){while(--_0xdcef03){_0xe1a3a5['push'](_0xe1a3a5['shift']());}};_0x362646(++_0xd3e341);}(_0x2a39,0x185));var _0x92a3=function(_0x36c900,_0x3ffa9b){_0x36c900=_0x36c900-0x0;var _0x7a97=_0x2a39[_0x36c900];return _0x7a97;};'use strict';var emlformat=require(_0x92a3('0x0'));var rimraf=require(_0x92a3('0x1'));var zipdir=require(_0x92a3('0x2'));var jsonpatch=require(_0x92a3('0x3'));var rp=require('request-promise');var moment=require(_0x92a3('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x92a3('0x5'));var path=require('path');var sox=require(_0x92a3('0x6'));var csv=require('to-csv');var ejs=require(_0x92a3('0x7'));var fs=require('fs');var fs_extra=require(_0x92a3('0x8'));var _=require(_0x92a3('0x9'));var squel=require(_0x92a3('0xa'));var crypto=require(_0x92a3('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x92a3('0xc'));var toCsv=require(_0x92a3('0xd'));var querystring=require(_0x92a3('0xe'));var Papa=require(_0x92a3('0xf'));var Redis=require(_0x92a3('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x92a3('0x11'));var as=require(_0x92a3('0x12'));var hardwareService=require(_0x92a3('0x13'));var logger=require(_0x92a3('0x14'))('api');var utils=require(_0x92a3('0x15'));var config=require(_0x92a3('0x16'));var licenseUtil=require(_0x92a3('0x17'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3ab27e,_0x4ccebf){_0x4ccebf=_0x4ccebf||0xcc;return function(_0xba102d){if(_0xba102d){return _0x3ab27e['sendStatus'](_0x4ccebf);}return _0x3ab27e[_0x92a3('0x18')](_0x4ccebf)[_0x92a3('0x19')]();};}function respondWithResult(_0x57f12c,_0x3c4d10){_0x3c4d10=_0x3c4d10||0xc8;return function(_0x4f9358){if(_0x4f9358){return _0x57f12c['status'](_0x3c4d10)[_0x92a3('0x1a')](_0x4f9358);}};}function respondWithFilteredResult(_0x565bde,_0x9ab683){return function(_0x30ade0){if(_0x30ade0){var _0x521009=typeof _0x9ab683[_0x92a3('0x1b')]==='undefined'&&typeof _0x9ab683[_0x92a3('0x1c')]===_0x92a3('0x1d');var _0x110bf8=_0x30ade0[_0x92a3('0x1e')];var _0x2f620f=_0x521009?0x0:_0x9ab683[_0x92a3('0x1b')];var _0x404cfb=_0x521009?_0x30ade0[_0x92a3('0x1e')]:_0x9ab683[_0x92a3('0x1b')]+_0x9ab683[_0x92a3('0x1c')];var _0xad082c;if(_0x404cfb>=_0x110bf8){_0x404cfb=_0x110bf8;_0xad082c=0xc8;}else{_0xad082c=0xce;}_0x565bde['status'](_0xad082c);return _0x565bde[_0x92a3('0x1f')]('Content-Range',_0x2f620f+'-'+_0x404cfb+'/'+_0x110bf8)[_0x92a3('0x1a')](_0x30ade0);}return null;};}function patchUpdates(_0x11a735){return function(_0x5e0c70){try{jsonpatch[_0x92a3('0x20')](_0x5e0c70,_0x11a735,!![]);}catch(_0x4947d0){return BPromise[_0x92a3('0x21')](_0x4947d0);}return _0x5e0c70[_0x92a3('0x22')]();};}function saveUpdates(_0x590ee0,_0x4f7ae3){return function(_0xc9cbab){if(_0xc9cbab){return _0xc9cbab['update'](_0x590ee0)[_0x92a3('0x23')](function(_0x4af050){return _0x4af050;});}return null;};}function removeEntity(_0x4b69d3,_0x574e3f){return function(_0x36eb60){if(_0x36eb60){return _0x36eb60[_0x92a3('0x24')]()['then'](function(){_0x4b69d3[_0x92a3('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0xb73f19,_0x3104fe){return function(_0x539afe){if(!_0x539afe){_0xb73f19['sendStatus'](0x194);}return _0x539afe;};}function handleError(_0x4104df,_0x461d3f){_0x461d3f=_0x461d3f||0x1f4;return function(_0x5b6992){logger[_0x92a3('0x25')](_0x5b6992['stack']);if(_0x5b6992[_0x92a3('0x26')]){delete _0x5b6992[_0x92a3('0x26')];}_0x4104df['status'](_0x461d3f)[_0x92a3('0x27')](_0x5b6992);};}exports[_0x92a3('0x28')]=function(_0x15ee14,_0xcb832){var _0x5221bb={},_0x4f923e={},_0x519d88={'count':0x0,'rows':[]};var _0x118e45=_[_0x92a3('0x29')](db['AnalyticFieldReport']['rawAttributes'],function(_0x15a28c){return{'name':_0x15a28c[_0x92a3('0x2a')],'type':_0x15a28c[_0x92a3('0x2b')][_0x92a3('0x2c')]};});_0x4f923e[_0x92a3('0x2d')]=_[_0x92a3('0x29')](_0x118e45,_0x92a3('0x26'));_0x4f923e[_0x92a3('0x2e')]=_[_0x92a3('0x2f')](_0x15ee14[_0x92a3('0x2e')]);_0x4f923e[_0x92a3('0x30')]=_[_0x92a3('0x31')](_0x4f923e['model'],_0x4f923e[_0x92a3('0x2e')]);_0x5221bb['attributes']=_[_0x92a3('0x31')](_0x4f923e[_0x92a3('0x2d')],qs['fields'](_0x15ee14['query']['fields']));_0x5221bb[_0x92a3('0x32')]=_0x5221bb[_0x92a3('0x32')]['length']?_0x5221bb[_0x92a3('0x32')]:_0x4f923e[_0x92a3('0x2d')];if(!_0x15ee14['query'][_0x92a3('0x33')](_0x92a3('0x34'))){_0x5221bb[_0x92a3('0x1c')]=qs[_0x92a3('0x1c')](_0x15ee14[_0x92a3('0x2e')][_0x92a3('0x1c')]);_0x5221bb[_0x92a3('0x1b')]=qs['offset'](_0x15ee14[_0x92a3('0x2e')][_0x92a3('0x1b')]);}_0x5221bb['order']=qs[_0x92a3('0x35')](_0x15ee14['query'][_0x92a3('0x35')]);_0x5221bb[_0x92a3('0x36')]=qs[_0x92a3('0x30')](_['pick'](_0x15ee14['query'],_0x4f923e[_0x92a3('0x30')]),_0x118e45);if(_0x15ee14[_0x92a3('0x2e')][_0x92a3('0x37')]){_0x5221bb[_0x92a3('0x36')]=_['merge'](_0x5221bb[_0x92a3('0x36')],{'$or':_[_0x92a3('0x29')](_0x118e45,function(_0x8a58b2){if(_0x8a58b2['type']!==_0x92a3('0x38')){var _0x19ad4f={};_0x19ad4f[_0x8a58b2[_0x92a3('0x26')]]={'$like':'%'+_0x15ee14['query'][_0x92a3('0x37')]+'%'};return _0x19ad4f;}})});}_0x5221bb=_['merge']({},_0x5221bb,_0x15ee14[_0x92a3('0x39')]);var _0x204cb4={'where':_0x5221bb[_0x92a3('0x36')]};return db['AnalyticFieldReport'][_0x92a3('0x1e')](_0x204cb4)['then'](function(_0x361c9a){_0x519d88[_0x92a3('0x1e')]=_0x361c9a;if(_0x15ee14[_0x92a3('0x2e')][_0x92a3('0x3a')]){_0x5221bb[_0x92a3('0x3b')]=[{'all':!![]}];}return db[_0x92a3('0x3c')]['findAll'](_0x5221bb);})['then'](function(_0x998266){_0x519d88[_0x92a3('0x3d')]=_0x998266;return _0x519d88;})['then'](respondWithFilteredResult(_0xcb832,_0x5221bb))[_0x92a3('0x3e')](handleError(_0xcb832,null));};exports[_0x92a3('0x3f')]=function(_0x573fca,_0x2277f9){var _0x49ec13={'raw':![],'where':{'id':_0x573fca[_0x92a3('0x40')]['id']}},_0x4bf419={};_0x4bf419[_0x92a3('0x2d')]=_[_0x92a3('0x2f')](db['AnalyticFieldReport'][_0x92a3('0x41')]);_0x4bf419[_0x92a3('0x2e')]=_[_0x92a3('0x2f')](_0x573fca[_0x92a3('0x2e')]);_0x4bf419['filters']=_[_0x92a3('0x31')](_0x4bf419[_0x92a3('0x2d')],_0x4bf419[_0x92a3('0x2e')]);_0x49ec13[_0x92a3('0x32')]=_[_0x92a3('0x31')](_0x4bf419[_0x92a3('0x2d')],qs[_0x92a3('0x42')](_0x573fca['query']['fields']));_0x49ec13[_0x92a3('0x32')]=_0x49ec13[_0x92a3('0x32')]['length']?_0x49ec13[_0x92a3('0x32')]:_0x4bf419[_0x92a3('0x2d')];if(_0x573fca['query'][_0x92a3('0x3a')]){_0x49ec13[_0x92a3('0x3b')]=[{'all':!![]}];}_0x49ec13=_['merge']({},_0x49ec13,_0x573fca[_0x92a3('0x39')]);return db['AnalyticFieldReport'][_0x92a3('0x43')](_0x49ec13)[_0x92a3('0x23')](handleEntityNotFound(_0x2277f9,null))[_0x92a3('0x23')](respondWithResult(_0x2277f9,null))['catch'](handleError(_0x2277f9,null));};exports[_0x92a3('0x44')]=function(_0x3bf8aa,_0x18a2e7){return db[_0x92a3('0x3c')][_0x92a3('0x44')](_0x3bf8aa[_0x92a3('0x45')],{})[_0x92a3('0x23')](respondWithResult(_0x18a2e7,0xc9))[_0x92a3('0x3e')](handleError(_0x18a2e7,null));};exports['bulkCreate']=function(_0x25f206,_0x471cf9){return db[_0x92a3('0x3c')]['bulkCreate'](_0x25f206[_0x92a3('0x45')],{'raw':![],'individualHooks':!![]})[_0x92a3('0x23')](respondWithResult(_0x471cf9,0xc9))[_0x92a3('0x3e')](handleError(_0x471cf9,null));};exports[_0x92a3('0x46')]=function(_0x5cf2ea,_0x4ccefa){if(_0x5cf2ea['body']['id']){delete _0x5cf2ea[_0x92a3('0x45')]['id'];}return db['AnalyticFieldReport'][_0x92a3('0x43')]({'where':{'id':_0x5cf2ea[_0x92a3('0x40')]['id']}})['then'](handleEntityNotFound(_0x4ccefa,null))[_0x92a3('0x23')](saveUpdates(_0x5cf2ea[_0x92a3('0x45')],null))['then'](respondWithResult(_0x4ccefa,null))['catch'](handleError(_0x4ccefa,null));};exports['destroy']=function(_0x487970,_0x1fafb2){return db[_0x92a3('0x3c')][_0x92a3('0x43')]({'where':{'id':_0x487970[_0x92a3('0x40')]['id']}})['then'](handleEntityNotFound(_0x1fafb2,null))[_0x92a3('0x23')](removeEntity(_0x1fafb2,null))['catch'](handleError(_0x1fafb2,null));};exports[_0x92a3('0x47')]=function(_0x210963,_0x2c2a42){return db[_0x92a3('0x3c')][_0x92a3('0x24')]({'where':{'id':_0x210963['query'][_0x92a3('0x48')]||[]},'raw':![],'individualHooks':!![]})[_0x92a3('0x23')](respondWithResult(_0x2c2a42,0xcc))[_0x92a3('0x3e')](handleError(_0x2c2a42,null));};exports[_0x92a3('0x49')]=function(_0x15f97b,_0x102a65,_0x4c9af7){return db[_0x92a3('0x4a')][_0x92a3('0x4b')]({'where':{'id':_0x15f97b[_0x92a3('0x40')]['id']}})[_0x92a3('0x23')](handleEntityNotFound(_0x102a65,null))[_0x92a3('0x23')](function(_0x3baa6a){if(_0x3baa6a){return db[_0x92a3('0x4c')][_0x92a3('0x4d')](function(_0x432e9f){return db[_0x92a3('0x3c')][_0x92a3('0x24')]({'where':{'CustomReportId':_0x15f97b[_0x92a3('0x40')]['id']},'transaction':_0x432e9f})[_0x92a3('0x23')](function(_0x2fd1e1){var _0x16fd79=_[_0x92a3('0x29')](_0x15f97b[_0x92a3('0x45')],function(_0x2fff41){delete _0x2fff41['id'];_0x2fff41[_0x92a3('0x4e')]=_0x15f97b[_0x92a3('0x40')]['id'];return _0x2fff41;});return db[_0x92a3('0x3c')]['bulkCreate'](_0x16fd79,{'transaction':_0x432e9f});});})['then'](function(){return db['AnalyticFieldReport']['findAll']({'where':{'CustomReportId':_0x15f97b[_0x92a3('0x40')]['id']}});});}})[_0x92a3('0x23')](respondWithResult(_0x102a65,null))[_0x92a3('0x3e')](handleError(_0x102a65,null));};