18 var _0xcefd=['mustache','util','path','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','../../config/license/util','../../mysqldb','sendStatus','status','end','limit','undefined','count','offset','set','Content-Range','apply','reject','update','error','stack','send','index','map','AnalyticTreeReport','type','key','model','name','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','VIRTUAL','merge','include','findAll','then','catch','show','params','rawAttributes','includeAll','options','create','body','destroy','find','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird'];(function(_0x267ce8,_0x4dd75c){var _0x5877a1=function(_0x1add15){while(--_0x1add15){_0x267ce8['push'](_0x267ce8['shift']());}};_0x5877a1(++_0x4dd75c);}(_0xcefd,0x12a));var _0xdcef=function(_0x19ebef,_0x451d2c){_0x19ebef=_0x19ebef-0x0;var _0x4aac24=_0xcefd[_0x19ebef];return _0x4aac24;};'use strict';var emlformat=require(_0xdcef('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xdcef('0x1'));var jsonpatch=require(_0xdcef('0x2'));var rp=require(_0xdcef('0x3'));var moment=require(_0xdcef('0x4'));var BPromise=require(_0xdcef('0x5'));var Mustache=require(_0xdcef('0x6'));var util=require(_0xdcef('0x7'));var path=require(_0xdcef('0x8'));var sox=require(_0xdcef('0x9'));var csv=require(_0xdcef('0xa'));var ejs=require(_0xdcef('0xb'));var fs=require('fs');var fs_extra=require(_0xdcef('0xc'));var _=require('lodash');var squel=require(_0xdcef('0xd'));var crypto=require(_0xdcef('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xdcef('0xf'));var toCsv=require(_0xdcef('0xa'));var querystring=require('querystring');var Papa=require(_0xdcef('0x10'));var Redis=require(_0xdcef('0x11'));var authService=require(_0xdcef('0x12'));var qs=require(_0xdcef('0x13'));var as=require(_0xdcef('0x14'));var hardwareService=require(_0xdcef('0x15'));var logger=require(_0xdcef('0x16'))(_0xdcef('0x17'));var utils=require(_0xdcef('0x18'));var config=require(_0xdcef('0x19'));var licenseUtil=require(_0xdcef('0x1a'));var db=require(_0xdcef('0x1b'))['db'];function respondWithStatusCode(_0x928c5,_0x202695){_0x202695=_0x202695||0xcc;return function(_0x1ef92e){if(_0x1ef92e){return _0x928c5[_0xdcef('0x1c')](_0x202695);}return _0x928c5[_0xdcef('0x1d')](_0x202695)[_0xdcef('0x1e')]();};}function respondWithResult(_0x3a5c92,_0x70db35){_0x70db35=_0x70db35||0xc8;return function(_0x223c07){if(_0x223c07){return _0x3a5c92[_0xdcef('0x1d')](_0x70db35)['json'](_0x223c07);}};}function respondWithFilteredResult(_0x4e61d7,_0x2de880){return function(_0x56c421){if(_0x56c421){var _0x1b7864=typeof _0x2de880['offset']==='undefined'&&typeof _0x2de880[_0xdcef('0x1f')]===_0xdcef('0x20');var _0xdae725=_0x56c421[_0xdcef('0x21')];var _0x142c67=_0x1b7864?0x0:_0x2de880['offset'];var _0x16814d=_0x1b7864?_0x56c421[_0xdcef('0x21')]:_0x2de880[_0xdcef('0x22')]+_0x2de880[_0xdcef('0x1f')];var _0x2986fb;if(_0x16814d>=_0xdae725){_0x16814d=_0xdae725;_0x2986fb=0xc8;}else{_0x2986fb=0xce;}_0x4e61d7[_0xdcef('0x1d')](_0x2986fb);return _0x4e61d7[_0xdcef('0x23')](_0xdcef('0x24'),_0x142c67+'-'+_0x16814d+'/'+_0xdae725)['json'](_0x56c421);}return null;};}function patchUpdates(_0x2d7021){return function(_0x17a6cc){try{jsonpatch[_0xdcef('0x25')](_0x17a6cc,_0x2d7021,!![]);}catch(_0x704da8){return BPromise[_0xdcef('0x26')](_0x704da8);}return _0x17a6cc['save']();};}function saveUpdates(_0x4eee15,_0x35dcca){return function(_0x48e2d3){if(_0x48e2d3){return _0x48e2d3[_0xdcef('0x27')](_0x4eee15)['then'](function(_0x514b5c){return _0x514b5c;});}return null;};}function removeEntity(_0x575d0d,_0x1fb00d){return function(_0x24b36d){if(_0x24b36d){return _0x24b36d['destroy']()['then'](function(){_0x575d0d['status'](0xcc)[_0xdcef('0x1e')]();});}};}function handleEntityNotFound(_0x363a90,_0x497f32){return function(_0x44497e){if(!_0x44497e){_0x363a90[_0xdcef('0x1c')](0x194);}return _0x44497e;};}function handleError(_0x1badec,_0x49a8df){_0x49a8df=_0x49a8df||0x1f4;return function(_0x1edc0e){logger[_0xdcef('0x28')](_0x1edc0e[_0xdcef('0x29')]);if(_0x1edc0e['name']){delete _0x1edc0e['name'];}_0x1badec[_0xdcef('0x1d')](_0x49a8df)[_0xdcef('0x2a')](_0x1edc0e);};}exports[_0xdcef('0x2b')]=function(_0x1c0681,_0x251ca3){var _0x1e5b3f={},_0x107f1b={},_0x183d81={'count':0x0,'rows':[]};var _0x233040=_[_0xdcef('0x2c')](db[_0xdcef('0x2d')]['rawAttributes'],function(_0x4295b7){return{'name':_0x4295b7['fieldName'],'type':_0x4295b7[_0xdcef('0x2e')][_0xdcef('0x2f')]};});_0x107f1b[_0xdcef('0x30')]=_['map'](_0x233040,_0xdcef('0x31'));_0x107f1b[_0xdcef('0x32')]=_[_0xdcef('0x33')](_0x1c0681[_0xdcef('0x32')]);_0x107f1b[_0xdcef('0x34')]=_[_0xdcef('0x35')](_0x107f1b[_0xdcef('0x30')],_0x107f1b[_0xdcef('0x32')]);_0x1e5b3f[_0xdcef('0x36')]=_[_0xdcef('0x35')](_0x107f1b['model'],qs[_0xdcef('0x37')](_0x1c0681[_0xdcef('0x32')]['fields']));_0x1e5b3f['attributes']=_0x1e5b3f[_0xdcef('0x36')][_0xdcef('0x38')]?_0x1e5b3f[_0xdcef('0x36')]:_0x107f1b[_0xdcef('0x30')];if(!_0x1c0681[_0xdcef('0x32')][_0xdcef('0x39')]('nolimit')){_0x1e5b3f[_0xdcef('0x1f')]=qs[_0xdcef('0x1f')](_0x1c0681[_0xdcef('0x32')][_0xdcef('0x1f')]);_0x1e5b3f[_0xdcef('0x22')]=qs[_0xdcef('0x22')](_0x1c0681[_0xdcef('0x32')][_0xdcef('0x22')]);}_0x1e5b3f[_0xdcef('0x3a')]=qs['sort'](_0x1c0681[_0xdcef('0x32')][_0xdcef('0x3b')]);_0x1e5b3f[_0xdcef('0x3c')]=qs[_0xdcef('0x34')](_['pick'](_0x1c0681[_0xdcef('0x32')],_0x107f1b['filters']),_0x233040);if(_0x1c0681[_0xdcef('0x32')]['filter']){_0x1e5b3f[_0xdcef('0x3c')]=_['merge'](_0x1e5b3f[_0xdcef('0x3c')],{'$or':_['map'](_0x233040,function(_0x368e48){if(_0x368e48[_0xdcef('0x2e')]!==_0xdcef('0x3d')){var _0x1f25db={};_0x1f25db[_0x368e48['name']]={'$like':'%'+_0x1c0681[_0xdcef('0x32')]['filter']+'%'};return _0x1f25db;}})});}_0x1e5b3f=_[_0xdcef('0x3e')]({},_0x1e5b3f,_0x1c0681['options']);var _0x3ce371={'where':_0x1e5b3f[_0xdcef('0x3c')]};return db[_0xdcef('0x2d')]['count'](_0x3ce371)['then'](function(_0x275d92){_0x183d81[_0xdcef('0x21')]=_0x275d92;if(_0x1c0681[_0xdcef('0x32')]['includeAll']){_0x1e5b3f[_0xdcef('0x3f')]=[{'all':!![]}];}return db[_0xdcef('0x2d')][_0xdcef('0x40')](_0x1e5b3f);})[_0xdcef('0x41')](function(_0x150753){_0x183d81['rows']=_0x150753;return _0x183d81;})[_0xdcef('0x41')](respondWithFilteredResult(_0x251ca3,_0x1e5b3f))[_0xdcef('0x42')](handleError(_0x251ca3,null));};exports[_0xdcef('0x43')]=function(_0xe83aff,_0x3e6eef){var _0x1c3416={'raw':!![],'where':{'id':_0xe83aff[_0xdcef('0x44')]['id']}},_0x3a0f7d={};_0x3a0f7d[_0xdcef('0x30')]=_[_0xdcef('0x33')](db[_0xdcef('0x2d')][_0xdcef('0x45')]);_0x3a0f7d[_0xdcef('0x32')]=_[_0xdcef('0x33')](_0xe83aff[_0xdcef('0x32')]);_0x3a0f7d[_0xdcef('0x34')]=_[_0xdcef('0x35')](_0x3a0f7d[_0xdcef('0x30')],_0x3a0f7d[_0xdcef('0x32')]);_0x1c3416[_0xdcef('0x36')]=_[_0xdcef('0x35')](_0x3a0f7d['model'],qs[_0xdcef('0x37')](_0xe83aff['query']['fields']));_0x1c3416[_0xdcef('0x36')]=_0x1c3416[_0xdcef('0x36')][_0xdcef('0x38')]?_0x1c3416[_0xdcef('0x36')]:_0x3a0f7d[_0xdcef('0x30')];if(_0xe83aff['query'][_0xdcef('0x46')]){_0x1c3416[_0xdcef('0x3f')]=[{'all':!![]}];}_0x1c3416=_[_0xdcef('0x3e')]({},_0x1c3416,_0xe83aff[_0xdcef('0x47')]);return db[_0xdcef('0x2d')]['find'](_0x1c3416)[_0xdcef('0x41')](handleEntityNotFound(_0x3e6eef,null))[_0xdcef('0x41')](respondWithResult(_0x3e6eef,null))[_0xdcef('0x42')](handleError(_0x3e6eef,null));};exports[_0xdcef('0x48')]=function(_0x3e7cb8,_0x2fbf3f){return db[_0xdcef('0x2d')][_0xdcef('0x48')](_0x3e7cb8[_0xdcef('0x49')],{})[_0xdcef('0x41')](respondWithResult(_0x2fbf3f,0xc9))[_0xdcef('0x42')](handleError(_0x2fbf3f,null));};exports[_0xdcef('0x27')]=function(_0x17b732,_0x35bfaf){if(_0x17b732['body']['id']){delete _0x17b732['body']['id'];}return db['AnalyticTreeReport']['find']({'where':{'id':_0x17b732['params']['id']}})[_0xdcef('0x41')](handleEntityNotFound(_0x35bfaf,null))[_0xdcef('0x41')](saveUpdates(_0x17b732[_0xdcef('0x49')],null))['then'](respondWithResult(_0x35bfaf,null))[_0xdcef('0x42')](handleError(_0x35bfaf,null));};exports[_0xdcef('0x4a')]=function(_0x1f8f54,_0x3f894f){return db[_0xdcef('0x2d')][_0xdcef('0x4b')]({'where':{'id':_0x1f8f54[_0xdcef('0x44')]['id']}})['then'](handleEntityNotFound(_0x3f894f,null))[_0xdcef('0x41')](removeEntity(_0x3f894f,null))[_0xdcef('0x42')](handleError(_0x3f894f,null));};