Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index c0dc3a0..a7c572b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0a7f=['xCALLY\x20Motion\x20Integration','get_module_fields','module_fields','remove','values','test','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','getFields','send','Wrong\x20credentials','zip-dir','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../components/integrations/configuration','sendStatus','status','end','json','offset','undefined','count','limit','Content-Range','apply','reject','update','then','name','map','SugarcrmAccount','model','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','type','VIRTUAL','options','includeAll','rows','catch','show','params','keys','rawAttributes','include','find','create','body','getConfigurations','findOne','SugarcrmConfiguration','addConfiguration','AccountId','Subjects','getSubjects','channel','Descriptions','SugarcrmField','assigned_user_id','created_by','date_start','duration_minutes','parent_type','parent_name','password','remoteUri','slice','substring','lastIndexOf','POST','format','%s%s','/service/v4_1/rest.php','login','JSON','stringify','PLAIN'];(function(_0x376c38,_0x48bc5a){var _0x249054=function(_0x2147ee){while(--_0x2147ee){_0x376c38['push'](_0x376c38['shift']());}};_0x249054(++_0x48bc5a);}(_0x0a7f,0xe6));var _0xf0a7=function(_0x5ed045,_0x5a7320){_0x5ed045=_0x5ed045-0x0;var _0x4a6362=_0x0a7f[_0x5ed045];return _0x4a6362;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf0a7('0x0'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf0a7('0x1'));var moment=require(_0xf0a7('0x2'));var BPromise=require(_0xf0a7('0x3'));var Mustache=require(_0xf0a7('0x4'));var util=require(_0xf0a7('0x5'));var path=require(_0xf0a7('0x6'));var sox=require('sox');var csv=require(_0xf0a7('0x7'));var ejs=require(_0xf0a7('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0xf0a7('0x9'));var crypto=require(_0xf0a7('0xa'));var jsforce=require(_0xf0a7('0xb'));var deskjs=require('desk.js');var toCsv=require(_0xf0a7('0x7'));var querystring=require(_0xf0a7('0xc'));var Papa=require(_0xf0a7('0xd'));var Redis=require(_0xf0a7('0xe'));var authService=require(_0xf0a7('0xf'));var qs=require(_0xf0a7('0x10'));var as=require(_0xf0a7('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf0a7('0x12'))('api');var utils=require(_0xf0a7('0x13'));var config=require(_0xf0a7('0x14'));var licenseUtil=require(_0xf0a7('0x15'));var db=require('../../mysqldb')['db'];var integrations=require(_0xf0a7('0x16'));function respondWithStatusCode(_0x11c036,_0x23d5fe){_0x23d5fe=_0x23d5fe||0xcc;return function(_0x2804a8){if(_0x2804a8){return _0x11c036[_0xf0a7('0x17')](_0x23d5fe);}return _0x11c036[_0xf0a7('0x18')](_0x23d5fe)[_0xf0a7('0x19')]();};}function respondWithResult(_0x27e3b6,_0x5d5f7e){_0x5d5f7e=_0x5d5f7e||0xc8;return function(_0x2b3bae){if(_0x2b3bae){return _0x27e3b6[_0xf0a7('0x18')](_0x5d5f7e)[_0xf0a7('0x1a')](_0x2b3bae);}};}function respondWithFilteredResult(_0xaafb82,_0x3f457a){return function(_0x22a1fc){if(_0x22a1fc){var _0x163520=typeof _0x3f457a[_0xf0a7('0x1b')]===_0xf0a7('0x1c')&&typeof _0x3f457a['limit']==='undefined';var _0x196424=_0x22a1fc[_0xf0a7('0x1d')];var _0x271583=_0x163520?0x0:_0x3f457a[_0xf0a7('0x1b')];var _0x78ced8=_0x163520?_0x22a1fc[_0xf0a7('0x1d')]:_0x3f457a['offset']+_0x3f457a[_0xf0a7('0x1e')];var _0x16b98c;if(_0x78ced8>=_0x196424){_0x78ced8=_0x196424;_0x16b98c=0xc8;}else{_0x16b98c=0xce;}_0xaafb82[_0xf0a7('0x18')](_0x16b98c);return _0xaafb82['set'](_0xf0a7('0x1f'),_0x271583+'-'+_0x78ced8+'/'+_0x196424)[_0xf0a7('0x1a')](_0x22a1fc);}return null;};}function patchUpdates(_0x5ab854){return function(_0x3c7f0c){try{jsonpatch[_0xf0a7('0x20')](_0x3c7f0c,_0x5ab854,!![]);}catch(_0x1b534d){return BPromise[_0xf0a7('0x21')](_0x1b534d);}return _0x3c7f0c['save']();};}function saveUpdates(_0x49c5fc,_0x4f30d1){return function(_0x58bed1){if(_0x58bed1){return _0x58bed1[_0xf0a7('0x22')](_0x49c5fc)[_0xf0a7('0x23')](function(_0x411bc6){return _0x411bc6;});}return null;};}function removeEntity(_0xb0e2a,_0x29d9c9){return function(_0x4c56c1){if(_0x4c56c1){return _0x4c56c1['destroy']()['then'](function(){_0xb0e2a[_0xf0a7('0x18')](0xcc)[_0xf0a7('0x19')]();});}};}function handleEntityNotFound(_0x2cf972,_0x57010a){return function(_0x5798e1){if(!_0x5798e1){_0x2cf972[_0xf0a7('0x17')](0x194);}return _0x5798e1;};}function handleError(_0xa684a,_0x236b4c){_0x236b4c=_0x236b4c||0x1f4;return function(_0x1dbf6a){logger['error'](_0x1dbf6a['stack']);if(_0x1dbf6a['name']){delete _0x1dbf6a[_0xf0a7('0x24')];}_0xa684a['status'](_0x236b4c)['send'](_0x1dbf6a);};}exports['index']=function(_0x2405b0,_0x1380d6){var _0x387019={},_0x2e6b25={},_0x38d5f0={'count':0x0,'rows':[]};var _0x3be558=_[_0xf0a7('0x25')](db[_0xf0a7('0x26')]['rawAttributes'],function(_0x14a762){return{'name':_0x14a762['fieldName'],'type':_0x14a762['type']['key']};});_0x2e6b25[_0xf0a7('0x27')]=_['map'](_0x3be558,_0xf0a7('0x24'));_0x2e6b25[_0xf0a7('0x28')]=_['keys'](_0x2405b0[_0xf0a7('0x28')]);_0x2e6b25[_0xf0a7('0x29')]=_[_0xf0a7('0x2a')](_0x2e6b25['model'],_0x2e6b25['query']);_0x387019['attributes']=_[_0xf0a7('0x2a')](_0x2e6b25[_0xf0a7('0x27')],qs[_0xf0a7('0x2b')](_0x2405b0[_0xf0a7('0x28')][_0xf0a7('0x2b')]));_0x387019[_0xf0a7('0x2c')]=_0x387019[_0xf0a7('0x2c')][_0xf0a7('0x2d')]?_0x387019[_0xf0a7('0x2c')]:_0x2e6b25['model'];if(!_0x2405b0[_0xf0a7('0x28')][_0xf0a7('0x2e')](_0xf0a7('0x2f'))){_0x387019[_0xf0a7('0x1e')]=qs[_0xf0a7('0x1e')](_0x2405b0['query'][_0xf0a7('0x1e')]);_0x387019['offset']=qs[_0xf0a7('0x1b')](_0x2405b0[_0xf0a7('0x28')][_0xf0a7('0x1b')]);}_0x387019[_0xf0a7('0x30')]=qs[_0xf0a7('0x31')](_0x2405b0[_0xf0a7('0x28')][_0xf0a7('0x31')]);_0x387019['where']=qs[_0xf0a7('0x29')](_[_0xf0a7('0x32')](_0x2405b0[_0xf0a7('0x28')],_0x2e6b25[_0xf0a7('0x29')]),_0x3be558);if(_0x2405b0[_0xf0a7('0x28')][_0xf0a7('0x33')]){_0x387019[_0xf0a7('0x34')]=_[_0xf0a7('0x35')](_0x387019[_0xf0a7('0x34')],{'$or':_[_0xf0a7('0x25')](_0x3be558,function(_0x1359bb){if(_0x1359bb[_0xf0a7('0x36')]!==_0xf0a7('0x37')){var _0x52ca8e={};_0x52ca8e[_0x1359bb[_0xf0a7('0x24')]]={'$like':'%'+_0x2405b0[_0xf0a7('0x28')][_0xf0a7('0x33')]+'%'};return _0x52ca8e;}})});}_0x387019=_[_0xf0a7('0x35')]({},_0x387019,_0x2405b0[_0xf0a7('0x38')]);var _0x36098c={'where':_0x387019[_0xf0a7('0x34')]};return db[_0xf0a7('0x26')][_0xf0a7('0x1d')](_0x36098c)[_0xf0a7('0x23')](function(_0x5e1e95){_0x38d5f0[_0xf0a7('0x1d')]=_0x5e1e95;if(_0x2405b0[_0xf0a7('0x28')][_0xf0a7('0x39')]){_0x387019['include']=[{'all':!![]}];}return db['SugarcrmAccount']['findAll'](_0x387019);})[_0xf0a7('0x23')](function(_0x1c4cfc){_0x38d5f0[_0xf0a7('0x3a')]=_0x1c4cfc;return _0x38d5f0;})[_0xf0a7('0x23')](respondWithFilteredResult(_0x1380d6,_0x387019))[_0xf0a7('0x3b')](handleError(_0x1380d6,null));};exports[_0xf0a7('0x3c')]=function(_0x42cc54,_0x44cf8b){var _0x3278eb={'raw':![],'where':{'id':_0x42cc54[_0xf0a7('0x3d')]['id']}},_0x3c1144={};_0x3c1144['model']=_[_0xf0a7('0x3e')](db[_0xf0a7('0x26')][_0xf0a7('0x3f')]);_0x3c1144[_0xf0a7('0x28')]=_[_0xf0a7('0x3e')](_0x42cc54[_0xf0a7('0x28')]);_0x3c1144[_0xf0a7('0x29')]=_[_0xf0a7('0x2a')](_0x3c1144[_0xf0a7('0x27')],_0x3c1144[_0xf0a7('0x28')]);_0x3278eb[_0xf0a7('0x2c')]=_[_0xf0a7('0x2a')](_0x3c1144['model'],qs[_0xf0a7('0x2b')](_0x42cc54[_0xf0a7('0x28')][_0xf0a7('0x2b')]));_0x3278eb['attributes']=_0x3278eb[_0xf0a7('0x2c')][_0xf0a7('0x2d')]?_0x3278eb[_0xf0a7('0x2c')]:_0x3c1144[_0xf0a7('0x27')];if(_0x42cc54[_0xf0a7('0x28')][_0xf0a7('0x39')]){_0x3278eb[_0xf0a7('0x40')]=[{'all':!![]}];}_0x3278eb=_[_0xf0a7('0x35')]({},_0x3278eb,_0x42cc54[_0xf0a7('0x38')]);return db['SugarcrmAccount'][_0xf0a7('0x41')](_0x3278eb)[_0xf0a7('0x23')](handleEntityNotFound(_0x44cf8b,null))['then'](respondWithResult(_0x44cf8b,null))[_0xf0a7('0x3b')](handleError(_0x44cf8b,null));};exports[_0xf0a7('0x42')]=function(_0x2784f8,_0x48a2b0){return db['SugarcrmAccount'][_0xf0a7('0x42')](_0x2784f8[_0xf0a7('0x43')],{})['then'](respondWithResult(_0x48a2b0,0xc9))[_0xf0a7('0x3b')](handleError(_0x48a2b0,null));};exports['update']=function(_0x1fe20b,_0x45ce7c){if(_0x1fe20b[_0xf0a7('0x43')]['id']){delete _0x1fe20b[_0xf0a7('0x43')]['id'];}return db['SugarcrmAccount'][_0xf0a7('0x41')]({'where':{'id':_0x1fe20b[_0xf0a7('0x3d')]['id']}})[_0xf0a7('0x23')](handleEntityNotFound(_0x45ce7c,null))[_0xf0a7('0x23')](saveUpdates(_0x1fe20b[_0xf0a7('0x43')],null))[_0xf0a7('0x23')](respondWithResult(_0x45ce7c,null))[_0xf0a7('0x3b')](handleError(_0x45ce7c,null));};exports['destroy']=function(_0x579fd8,_0x325f0d){return db[_0xf0a7('0x26')][_0xf0a7('0x41')]({'where':{'id':_0x579fd8[_0xf0a7('0x3d')]['id']}})['then'](handleEntityNotFound(_0x325f0d,null))['then'](removeEntity(_0x325f0d,null))[_0xf0a7('0x3b')](handleError(_0x325f0d,null));};exports[_0xf0a7('0x44')]=function(_0x24a18f,_0x11d90e,_0x424e98){var _0x5ea63a={};var _0x525aa4={};var _0x3a356d;var _0x42d281;return db[_0xf0a7('0x26')][_0xf0a7('0x45')]({'where':{'id':_0x24a18f[_0xf0a7('0x3d')]['id']}})['then'](handleEntityNotFound(_0x11d90e,null))[_0xf0a7('0x23')](function(_0x222a9c){if(_0x222a9c){_0x3a356d=_0x222a9c;_0x525aa4['model']=_[_0xf0a7('0x3e')](db[_0xf0a7('0x46')][_0xf0a7('0x3f')]);_0x525aa4[_0xf0a7('0x28')]=_[_0xf0a7('0x3e')](_0x24a18f[_0xf0a7('0x28')]);_0x525aa4[_0xf0a7('0x29')]=_[_0xf0a7('0x2a')](_0x525aa4[_0xf0a7('0x27')],_0x525aa4[_0xf0a7('0x28')]);_0x5ea63a[_0xf0a7('0x2c')]=_['intersection'](_0x525aa4[_0xf0a7('0x27')],qs[_0xf0a7('0x2b')](_0x24a18f[_0xf0a7('0x28')]['fields']));_0x5ea63a[_0xf0a7('0x2c')]=_0x5ea63a[_0xf0a7('0x2c')]['length']?_0x5ea63a[_0xf0a7('0x2c')]:_0x525aa4[_0xf0a7('0x27')];_0x5ea63a['order']=qs[_0xf0a7('0x31')](_0x24a18f[_0xf0a7('0x28')][_0xf0a7('0x31')]);_0x5ea63a[_0xf0a7('0x34')]=qs[_0xf0a7('0x29')](_[_0xf0a7('0x32')](_0x24a18f[_0xf0a7('0x28')],_0x525aa4[_0xf0a7('0x29')]));if(_0x24a18f['query'][_0xf0a7('0x33')]){_0x5ea63a['where']=_[_0xf0a7('0x35')](_0x5ea63a['where'],{'$or':_[_0xf0a7('0x25')](_0x5ea63a[_0xf0a7('0x2c')],function(_0x1537d2){var _0x2535ce={};_0x2535ce[_0x1537d2]={'$like':'%'+_0x24a18f[_0xf0a7('0x28')][_0xf0a7('0x33')]+'%'};return _0x2535ce;})});}_0x5ea63a=_[_0xf0a7('0x35')]({},_0x5ea63a,_0x24a18f['options']);return _0x3a356d[_0xf0a7('0x44')](_0x5ea63a);}})[_0xf0a7('0x23')](function(_0x48d294){if(_0x48d294){_0x42d281=_0x48d294['length'];if(!_0x24a18f['query'][_0xf0a7('0x2e')]('nolimit')){_0x5ea63a[_0xf0a7('0x1e')]=qs[_0xf0a7('0x1e')](_0x24a18f[_0xf0a7('0x28')]['limit']);_0x5ea63a[_0xf0a7('0x1b')]=qs['offset'](_0x24a18f[_0xf0a7('0x28')][_0xf0a7('0x1b')]);}return _0x3a356d[_0xf0a7('0x44')](_0x5ea63a);}})[_0xf0a7('0x23')](function(_0x244eda){if(_0x244eda){return _0x244eda?{'count':_0x42d281,'rows':_0x244eda}:null;}})[_0xf0a7('0x23')](respondWithResult(_0x11d90e,null))[_0xf0a7('0x3b')](handleError(_0x11d90e,null));};exports[_0xf0a7('0x47')]=function(_0x48de9a,_0x307835,_0x1a01f3){if(_0x48de9a[_0xf0a7('0x43')]['id']){delete _0x48de9a[_0xf0a7('0x43')]['id'];}return db[_0xf0a7('0x26')]['findOne']({'where':{'id':_0x48de9a[_0xf0a7('0x3d')]['id']}})['then'](handleEntityNotFound(_0x307835,null))[_0xf0a7('0x23')](function(_0x164f35){if(_0x164f35){_0x48de9a['body'][_0xf0a7('0x48')]=_0x164f35['id'];_0x48de9a[_0xf0a7('0x43')][_0xf0a7('0x49')]=integrations[_0xf0a7('0x4a')](_0x48de9a[_0xf0a7('0x43')][_0xf0a7('0x4b')],_0x48de9a['body'][_0xf0a7('0x36')]);_0x48de9a[_0xf0a7('0x43')][_0xf0a7('0x4c')]=integrations['getDescriptions'](_0x48de9a[_0xf0a7('0x43')][_0xf0a7('0x4b')],_0x48de9a[_0xf0a7('0x43')][_0xf0a7('0x36')]);return db[_0xf0a7('0x46')][_0xf0a7('0x42')](_0x48de9a[_0xf0a7('0x43')],{'include':[{'model':db[_0xf0a7('0x4d')],'as':_0xf0a7('0x49')},{'model':db[_0xf0a7('0x4d')],'as':_0xf0a7('0x4c')}]});}return null;})['then'](respondWithResult(_0x307835,null))[_0xf0a7('0x3b')](handleError(_0x307835,null));};exports['getFields']=function(_0x1e869a,_0x39ae71,_0x49bfa2){var _0x3733ff='';var _0x429af1=['id',_0xf0a7('0x24'),_0xf0a7('0x4e'),_0xf0a7('0x4f'),'description',_0xf0a7('0x50'),'duration_hours',_0xf0a7('0x51'),'parent_id',_0xf0a7('0x52'),_0xf0a7('0x53'),'direction'];return db[_0xf0a7('0x26')][_0xf0a7('0x45')]({'where':{'id':_0x1e869a[_0xf0a7('0x3d')]['id']},'attributes':['id','username',_0xf0a7('0x54'),_0xf0a7('0x55')]})[_0xf0a7('0x23')](handleEntityNotFound(_0x39ae71,null))[_0xf0a7('0x23')](function(_0x4c9440){if(_0x4c9440){_0x3733ff=_0x4c9440[_0xf0a7('0x55')];var _0x3c7584=_0x3733ff[_0xf0a7('0x56')](-0x1);if(_0x3c7584==='/'){_0x3733ff=_0x3733ff[_0xf0a7('0x57')](0x0,_0x3733ff[_0xf0a7('0x58')](_0x3c7584));}return rp({'method':_0xf0a7('0x59'),'uri':util[_0xf0a7('0x5a')](_0xf0a7('0x5b'),_0x3733ff,_0xf0a7('0x5c')),'json':!![],'form':{'method':_0xf0a7('0x5d'),'input_type':_0xf0a7('0x5e'),'response_type':_0xf0a7('0x5e'),'rest_data':JSON[_0xf0a7('0x5f')]({'user_auth':{'user_name':_0x4c9440['username'],'password':_0x4c9440['password'],'encryption':_0xf0a7('0x60')},'application':_0xf0a7('0x61')})}});}})[_0xf0a7('0x23')](function(_0x21fa21){if(_0x21fa21&&_0x21fa21['name']!=='Invalid\x20Login'&&_0x21fa21[_0xf0a7('0x24')]!=='Password\x20Expired'){return rp({'method':_0xf0a7('0x59'),'uri':util['format'](_0xf0a7('0x5b'),_0x3733ff,_0xf0a7('0x5c')),'json':!![],'form':{'method':_0xf0a7('0x62'),'input_type':_0xf0a7('0x5e'),'response_type':'JSON','rest_data':JSON['stringify']({'session':_0x21fa21['id'],'module_name':'Calls'})}})[_0xf0a7('0x23')](function(_0x17a8f1){if(_0x17a8f1){var _0x54e68c=_['values'](_0x17a8f1[_0xf0a7('0x63')]);_[_0xf0a7('0x64')](_0x54e68c,function(_0x2eb43f){return _0x429af1['includes'](_0x2eb43f['name']);});return{'count':_0x54e68c[_0xf0a7('0x2d')],'rows':_[_0xf0a7('0x25')](_0x54e68c,function(_0x5208bc){return{'id':_0x5208bc[_0xf0a7('0x24')],'name':_0x5208bc['label'],'custom':_['endsWith'](_0x5208bc[_0xf0a7('0x24')],'_c')?!![]:![],'options':_0x5208bc[_0xf0a7('0x38')]?_[_0xf0a7('0x25')](_[_0xf0a7('0x65')](_0x5208bc[_0xf0a7('0x38')]),function(_0x5bd6ce){return{'name':_0x5bd6ce['value'],'value':_0x5bd6ce[_0xf0a7('0x24')]};}):[]};})};}})[_0xf0a7('0x23')](respondWithResult(_0x39ae71,null))[_0xf0a7('0x3b')](function(_0x12db8e){var _0x31f058=_0x1e869a[_0xf0a7('0x28')][_0xf0a7('0x66')]?0x1f4:_0x12db8e[_0xf0a7('0x67')]||0x1f4;logger[_0xf0a7('0x68')](_0xf0a7('0x69'),_0xf0a7('0x6a'),_0x31f058,JSON[_0xf0a7('0x5f')](_0x12db8e));delete _0x12db8e[_0xf0a7('0x24')];if(_0x31f058===0x191){_0x31f058=0x190;}_0x39ae71[_0xf0a7('0x18')](_0x31f058)[_0xf0a7('0x6b')](_0x1e869a[_0xf0a7('0x28')][_0xf0a7('0x66')]?{'message':_0xf0a7('0x6c'),'statusCode':_0x12db8e['statusCode']}:_0x12db8e);});}else{var _0xaf7af9=0x1f4;_0x39ae71[_0xf0a7('0x18')](_0xaf7af9)[_0xf0a7('0x6b')]({'message':_0xf0a7('0x6c'),'statusCode':0x190});}});};
\ No newline at end of file
+var _0x2f63=['body','update','destroy','getConfigurations','SugarcrmConfiguration','filter','addConfiguration','findOne','Subjects','getSubjects','channel','Descriptions','getDescriptions','SugarcrmField','getFields','assigned_user_id','description','duration_minutes','parent_id','parent_name','direction','username','remoteUri','slice','substring','/service/v4_1/rest.php','JSON','stringify','PLAIN','xCALLY\x20Motion\x20Integration','Invalid\x20Login','Password\x20Expired','format','get_module_fields','Calls','values','module_fields','remove','label','endsWith','value','test','statusCode','error','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','../../components/integrations/configuration','end','status','offset','undefined','limit','count','set','apply','save','then','sendStatus','stack','name','send','index','map','SugarcrmAccount','rawAttributes','fieldName','type','model','keys','intersection','query','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','find','create'];(function(_0x4a9fb1,_0x273043){var _0x348672=function(_0x142b69){while(--_0x142b69){_0x4a9fb1['push'](_0x4a9fb1['shift']());}};_0x348672(++_0x273043);}(_0x2f63,0x116));var _0x32f6=function(_0x37ef22,_0x348c92){_0x37ef22=_0x37ef22-0x0;var _0x49eeb3=_0x2f63[_0x37ef22];return _0x49eeb3;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x32f6('0x0'));var zipdir=require(_0x32f6('0x1'));var jsonpatch=require(_0x32f6('0x2'));var rp=require('request-promise');var moment=require(_0x32f6('0x3'));var BPromise=require(_0x32f6('0x4'));var Mustache=require(_0x32f6('0x5'));var util=require('util');var path=require(_0x32f6('0x6'));var sox=require(_0x32f6('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x32f6('0x8'));var _=require(_0x32f6('0x9'));var squel=require(_0x32f6('0xa'));var crypto=require('crypto');var jsforce=require(_0x32f6('0xb'));var deskjs=require(_0x32f6('0xc'));var toCsv=require(_0x32f6('0xd'));var querystring=require(_0x32f6('0xe'));var Papa=require(_0x32f6('0xf'));var Redis=require('ioredis');var authService=require(_0x32f6('0x10'));var qs=require(_0x32f6('0x11'));var as=require(_0x32f6('0x12'));var hardwareService=require(_0x32f6('0x13'));var logger=require(_0x32f6('0x14'))(_0x32f6('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x32f6('0x16'));var db=require(_0x32f6('0x17'))['db'];var integrations=require(_0x32f6('0x18'));function respondWithStatusCode(_0x3e4ba8,_0x353002){_0x353002=_0x353002||0xcc;return function(_0x21489d){if(_0x21489d){return _0x3e4ba8['sendStatus'](_0x353002);}return _0x3e4ba8['status'](_0x353002)[_0x32f6('0x19')]();};}function respondWithResult(_0x162916,_0x34d9b3){_0x34d9b3=_0x34d9b3||0xc8;return function(_0x56860c){if(_0x56860c){return _0x162916[_0x32f6('0x1a')](_0x34d9b3)['json'](_0x56860c);}};}function respondWithFilteredResult(_0x2aedd5,_0x4bf682){return function(_0x3c5493){if(_0x3c5493){var _0x9bfcba=typeof _0x4bf682[_0x32f6('0x1b')]===_0x32f6('0x1c')&&typeof _0x4bf682[_0x32f6('0x1d')]===_0x32f6('0x1c');var _0x20cad0=_0x3c5493['count'];var _0x59611d=_0x9bfcba?0x0:_0x4bf682['offset'];var _0x53edc2=_0x9bfcba?_0x3c5493[_0x32f6('0x1e')]:_0x4bf682['offset']+_0x4bf682[_0x32f6('0x1d')];var _0x38e756;if(_0x53edc2>=_0x20cad0){_0x53edc2=_0x20cad0;_0x38e756=0xc8;}else{_0x38e756=0xce;}_0x2aedd5[_0x32f6('0x1a')](_0x38e756);return _0x2aedd5[_0x32f6('0x1f')]('Content-Range',_0x59611d+'-'+_0x53edc2+'/'+_0x20cad0)['json'](_0x3c5493);}return null;};}function patchUpdates(_0x274f12){return function(_0x51dfcf){try{jsonpatch[_0x32f6('0x20')](_0x51dfcf,_0x274f12,!![]);}catch(_0x2b1642){return BPromise['reject'](_0x2b1642);}return _0x51dfcf[_0x32f6('0x21')]();};}function saveUpdates(_0xb6b636,_0x17d4bb){return function(_0x230bd5){if(_0x230bd5){return _0x230bd5['update'](_0xb6b636)[_0x32f6('0x22')](function(_0x49bb56){return _0x49bb56;});}return null;};}function removeEntity(_0x2d09ba,_0x110617){return function(_0x273bd2){if(_0x273bd2){return _0x273bd2['destroy']()[_0x32f6('0x22')](function(){_0x2d09ba[_0x32f6('0x1a')](0xcc)[_0x32f6('0x19')]();});}};}function handleEntityNotFound(_0x2975f2,_0x295f5b){return function(_0x53ea0b){if(!_0x53ea0b){_0x2975f2[_0x32f6('0x23')](0x194);}return _0x53ea0b;};}function handleError(_0x4b898d,_0x59288b){_0x59288b=_0x59288b||0x1f4;return function(_0x43978f){logger['error'](_0x43978f[_0x32f6('0x24')]);if(_0x43978f[_0x32f6('0x25')]){delete _0x43978f[_0x32f6('0x25')];}_0x4b898d[_0x32f6('0x1a')](_0x59288b)[_0x32f6('0x26')](_0x43978f);};}exports[_0x32f6('0x27')]=function(_0x3726dd,_0x26ed5b){var _0x46d083={},_0x3c7288={},_0x25e9aa={'count':0x0,'rows':[]};var _0x8a72cb=_[_0x32f6('0x28')](db[_0x32f6('0x29')][_0x32f6('0x2a')],function(_0x2afe28){return{'name':_0x2afe28[_0x32f6('0x2b')],'type':_0x2afe28[_0x32f6('0x2c')]['key']};});_0x3c7288[_0x32f6('0x2d')]=_[_0x32f6('0x28')](_0x8a72cb,_0x32f6('0x25'));_0x3c7288['query']=_[_0x32f6('0x2e')](_0x3726dd['query']);_0x3c7288['filters']=_[_0x32f6('0x2f')](_0x3c7288[_0x32f6('0x2d')],_0x3c7288[_0x32f6('0x30')]);_0x46d083[_0x32f6('0x31')]=_[_0x32f6('0x2f')](_0x3c7288[_0x32f6('0x2d')],qs[_0x32f6('0x32')](_0x3726dd[_0x32f6('0x30')][_0x32f6('0x32')]));_0x46d083[_0x32f6('0x31')]=_0x46d083[_0x32f6('0x31')][_0x32f6('0x33')]?_0x46d083['attributes']:_0x3c7288['model'];if(!_0x3726dd[_0x32f6('0x30')][_0x32f6('0x34')](_0x32f6('0x35'))){_0x46d083[_0x32f6('0x1d')]=qs[_0x32f6('0x1d')](_0x3726dd[_0x32f6('0x30')][_0x32f6('0x1d')]);_0x46d083[_0x32f6('0x1b')]=qs[_0x32f6('0x1b')](_0x3726dd[_0x32f6('0x30')]['offset']);}_0x46d083[_0x32f6('0x36')]=qs[_0x32f6('0x37')](_0x3726dd[_0x32f6('0x30')][_0x32f6('0x37')]);_0x46d083[_0x32f6('0x38')]=qs[_0x32f6('0x39')](_[_0x32f6('0x3a')](_0x3726dd['query'],_0x3c7288[_0x32f6('0x39')]),_0x8a72cb);if(_0x3726dd[_0x32f6('0x30')]['filter']){_0x46d083['where']=_[_0x32f6('0x3b')](_0x46d083['where'],{'$or':_[_0x32f6('0x28')](_0x8a72cb,function(_0x2425a7){if(_0x2425a7[_0x32f6('0x2c')]!==_0x32f6('0x3c')){var _0x211b52={};_0x211b52[_0x2425a7[_0x32f6('0x25')]]={'$like':'%'+_0x3726dd[_0x32f6('0x30')]['filter']+'%'};return _0x211b52;}})});}_0x46d083=_['merge']({},_0x46d083,_0x3726dd[_0x32f6('0x3d')]);var _0x1be7a8={'where':_0x46d083[_0x32f6('0x38')]};return db['SugarcrmAccount'][_0x32f6('0x1e')](_0x1be7a8)[_0x32f6('0x22')](function(_0x331a75){_0x25e9aa[_0x32f6('0x1e')]=_0x331a75;if(_0x3726dd[_0x32f6('0x30')][_0x32f6('0x3e')]){_0x46d083[_0x32f6('0x3f')]=[{'all':!![]}];}return db[_0x32f6('0x29')][_0x32f6('0x40')](_0x46d083);})[_0x32f6('0x22')](function(_0x7e9f3d){_0x25e9aa['rows']=_0x7e9f3d;return _0x25e9aa;})[_0x32f6('0x22')](respondWithFilteredResult(_0x26ed5b,_0x46d083))[_0x32f6('0x41')](handleError(_0x26ed5b,null));};exports[_0x32f6('0x42')]=function(_0x70daf7,_0x48317a){var _0x1f04ae={'raw':![],'where':{'id':_0x70daf7[_0x32f6('0x43')]['id']}},_0x509f87={};_0x509f87[_0x32f6('0x2d')]=_[_0x32f6('0x2e')](db[_0x32f6('0x29')]['rawAttributes']);_0x509f87[_0x32f6('0x30')]=_[_0x32f6('0x2e')](_0x70daf7[_0x32f6('0x30')]);_0x509f87[_0x32f6('0x39')]=_['intersection'](_0x509f87['model'],_0x509f87[_0x32f6('0x30')]);_0x1f04ae[_0x32f6('0x31')]=_[_0x32f6('0x2f')](_0x509f87[_0x32f6('0x2d')],qs['fields'](_0x70daf7[_0x32f6('0x30')][_0x32f6('0x32')]));_0x1f04ae[_0x32f6('0x31')]=_0x1f04ae[_0x32f6('0x31')]['length']?_0x1f04ae['attributes']:_0x509f87['model'];if(_0x70daf7[_0x32f6('0x30')]['includeAll']){_0x1f04ae[_0x32f6('0x3f')]=[{'all':!![]}];}_0x1f04ae=_[_0x32f6('0x3b')]({},_0x1f04ae,_0x70daf7[_0x32f6('0x3d')]);return db['SugarcrmAccount'][_0x32f6('0x44')](_0x1f04ae)[_0x32f6('0x22')](handleEntityNotFound(_0x48317a,null))[_0x32f6('0x22')](respondWithResult(_0x48317a,null))[_0x32f6('0x41')](handleError(_0x48317a,null));};exports[_0x32f6('0x45')]=function(_0x252f03,_0x337532){return db[_0x32f6('0x29')][_0x32f6('0x45')](_0x252f03[_0x32f6('0x46')],{})[_0x32f6('0x22')](respondWithResult(_0x337532,0xc9))[_0x32f6('0x41')](handleError(_0x337532,null));};exports[_0x32f6('0x47')]=function(_0x313f10,_0x4b9ab8){if(_0x313f10[_0x32f6('0x46')]['id']){delete _0x313f10[_0x32f6('0x46')]['id'];}return db['SugarcrmAccount'][_0x32f6('0x44')]({'where':{'id':_0x313f10['params']['id']}})['then'](handleEntityNotFound(_0x4b9ab8,null))['then'](saveUpdates(_0x313f10[_0x32f6('0x46')],null))[_0x32f6('0x22')](respondWithResult(_0x4b9ab8,null))['catch'](handleError(_0x4b9ab8,null));};exports[_0x32f6('0x48')]=function(_0x875f43,_0xaa409b){return db['SugarcrmAccount'][_0x32f6('0x44')]({'where':{'id':_0x875f43[_0x32f6('0x43')]['id']}})[_0x32f6('0x22')](handleEntityNotFound(_0xaa409b,null))[_0x32f6('0x22')](removeEntity(_0xaa409b,null))[_0x32f6('0x41')](handleError(_0xaa409b,null));};exports[_0x32f6('0x49')]=function(_0xaacf4f,_0x4c3755,_0x5b4c83){var _0x8b4fb5={};var _0x318523={};var _0x37db5e;var _0x3141e1;return db[_0x32f6('0x29')]['findOne']({'where':{'id':_0xaacf4f[_0x32f6('0x43')]['id']}})['then'](handleEntityNotFound(_0x4c3755,null))[_0x32f6('0x22')](function(_0x18e660){if(_0x18e660){_0x37db5e=_0x18e660;_0x318523[_0x32f6('0x2d')]=_[_0x32f6('0x2e')](db[_0x32f6('0x4a')][_0x32f6('0x2a')]);_0x318523[_0x32f6('0x30')]=_[_0x32f6('0x2e')](_0xaacf4f['query']);_0x318523['filters']=_[_0x32f6('0x2f')](_0x318523[_0x32f6('0x2d')],_0x318523['query']);_0x8b4fb5[_0x32f6('0x31')]=_[_0x32f6('0x2f')](_0x318523[_0x32f6('0x2d')],qs[_0x32f6('0x32')](_0xaacf4f[_0x32f6('0x30')][_0x32f6('0x32')]));_0x8b4fb5[_0x32f6('0x31')]=_0x8b4fb5['attributes'][_0x32f6('0x33')]?_0x8b4fb5[_0x32f6('0x31')]:_0x318523[_0x32f6('0x2d')];_0x8b4fb5[_0x32f6('0x36')]=qs[_0x32f6('0x37')](_0xaacf4f[_0x32f6('0x30')][_0x32f6('0x37')]);_0x8b4fb5[_0x32f6('0x38')]=qs['filters'](_[_0x32f6('0x3a')](_0xaacf4f[_0x32f6('0x30')],_0x318523[_0x32f6('0x39')]));if(_0xaacf4f[_0x32f6('0x30')]['filter']){_0x8b4fb5[_0x32f6('0x38')]=_[_0x32f6('0x3b')](_0x8b4fb5[_0x32f6('0x38')],{'$or':_[_0x32f6('0x28')](_0x8b4fb5[_0x32f6('0x31')],function(_0x4cbcbe){var _0x209f7d={};_0x209f7d[_0x4cbcbe]={'$like':'%'+_0xaacf4f['query'][_0x32f6('0x4b')]+'%'};return _0x209f7d;})});}_0x8b4fb5=_[_0x32f6('0x3b')]({},_0x8b4fb5,_0xaacf4f['options']);return _0x37db5e[_0x32f6('0x49')](_0x8b4fb5);}})[_0x32f6('0x22')](function(_0x5f42d1){if(_0x5f42d1){_0x3141e1=_0x5f42d1[_0x32f6('0x33')];if(!_0xaacf4f[_0x32f6('0x30')][_0x32f6('0x34')](_0x32f6('0x35'))){_0x8b4fb5['limit']=qs[_0x32f6('0x1d')](_0xaacf4f[_0x32f6('0x30')][_0x32f6('0x1d')]);_0x8b4fb5['offset']=qs['offset'](_0xaacf4f['query'][_0x32f6('0x1b')]);}return _0x37db5e[_0x32f6('0x49')](_0x8b4fb5);}})[_0x32f6('0x22')](function(_0x5454a8){if(_0x5454a8){return _0x5454a8?{'count':_0x3141e1,'rows':_0x5454a8}:null;}})[_0x32f6('0x22')](respondWithResult(_0x4c3755,null))['catch'](handleError(_0x4c3755,null));};exports[_0x32f6('0x4c')]=function(_0x34ff2d,_0x3ee6fa,_0x40f159){if(_0x34ff2d[_0x32f6('0x46')]['id']){delete _0x34ff2d[_0x32f6('0x46')]['id'];}return db[_0x32f6('0x29')][_0x32f6('0x4d')]({'where':{'id':_0x34ff2d['params']['id']}})['then'](handleEntityNotFound(_0x3ee6fa,null))[_0x32f6('0x22')](function(_0x55e306){if(_0x55e306){_0x34ff2d[_0x32f6('0x46')]['AccountId']=_0x55e306['id'];_0x34ff2d['body'][_0x32f6('0x4e')]=integrations[_0x32f6('0x4f')](_0x34ff2d[_0x32f6('0x46')][_0x32f6('0x50')],_0x34ff2d[_0x32f6('0x46')][_0x32f6('0x2c')]);_0x34ff2d[_0x32f6('0x46')][_0x32f6('0x51')]=integrations[_0x32f6('0x52')](_0x34ff2d[_0x32f6('0x46')][_0x32f6('0x50')],_0x34ff2d['body']['type']);return db['SugarcrmConfiguration'][_0x32f6('0x45')](_0x34ff2d[_0x32f6('0x46')],{'include':[{'model':db[_0x32f6('0x53')],'as':_0x32f6('0x4e')},{'model':db[_0x32f6('0x53')],'as':_0x32f6('0x51')}]});}return null;})['then'](respondWithResult(_0x3ee6fa,null))[_0x32f6('0x41')](handleError(_0x3ee6fa,null));};exports[_0x32f6('0x54')]=function(_0x111b4b,_0x29542b,_0x46f916){var _0x4debf2='';var _0xea97da=['id',_0x32f6('0x25'),_0x32f6('0x55'),'created_by',_0x32f6('0x56'),'date_start','duration_hours',_0x32f6('0x57'),_0x32f6('0x58'),'parent_type',_0x32f6('0x59'),_0x32f6('0x5a')];return db[_0x32f6('0x29')][_0x32f6('0x4d')]({'where':{'id':_0x111b4b['params']['id']},'attributes':['id',_0x32f6('0x5b'),'password',_0x32f6('0x5c')]})['then'](handleEntityNotFound(_0x29542b,null))[_0x32f6('0x22')](function(_0x5c6ed1){if(_0x5c6ed1){_0x4debf2=_0x5c6ed1[_0x32f6('0x5c')];var _0x5848b7=_0x4debf2[_0x32f6('0x5d')](-0x1);if(_0x5848b7==='/'){_0x4debf2=_0x4debf2[_0x32f6('0x5e')](0x0,_0x4debf2['lastIndexOf'](_0x5848b7));}return rp({'method':'POST','uri':util['format']('%s%s',_0x4debf2,_0x32f6('0x5f')),'json':!![],'form':{'method':'login','input_type':_0x32f6('0x60'),'response_type':_0x32f6('0x60'),'rest_data':JSON[_0x32f6('0x61')]({'user_auth':{'user_name':_0x5c6ed1[_0x32f6('0x5b')],'password':_0x5c6ed1['password'],'encryption':_0x32f6('0x62')},'application':_0x32f6('0x63')})}});}})[_0x32f6('0x22')](function(_0x73dab3){if(_0x73dab3&&_0x73dab3[_0x32f6('0x25')]!==_0x32f6('0x64')&&_0x73dab3[_0x32f6('0x25')]!==_0x32f6('0x65')){return rp({'method':'POST','uri':util[_0x32f6('0x66')]('%s%s',_0x4debf2,_0x32f6('0x5f')),'json':!![],'form':{'method':_0x32f6('0x67'),'input_type':_0x32f6('0x60'),'response_type':_0x32f6('0x60'),'rest_data':JSON[_0x32f6('0x61')]({'session':_0x73dab3['id'],'module_name':_0x32f6('0x68')})}})['then'](function(_0x39d04c){if(_0x39d04c){var _0x29fbe5=_[_0x32f6('0x69')](_0x39d04c[_0x32f6('0x6a')]);_[_0x32f6('0x6b')](_0x29fbe5,function(_0x3ece94){return _0xea97da['includes'](_0x3ece94[_0x32f6('0x25')]);});return{'count':_0x29fbe5[_0x32f6('0x33')],'rows':_[_0x32f6('0x28')](_0x29fbe5,function(_0x3725bc){return{'id':_0x3725bc[_0x32f6('0x25')],'name':_0x3725bc[_0x32f6('0x6c')],'custom':_[_0x32f6('0x6d')](_0x3725bc[_0x32f6('0x25')],'_c')?!![]:![],'options':_0x3725bc[_0x32f6('0x3d')]?_[_0x32f6('0x28')](_[_0x32f6('0x69')](_0x3725bc['options']),function(_0xfd91e3){return{'name':_0xfd91e3[_0x32f6('0x6e')],'value':_0xfd91e3[_0x32f6('0x25')]};}):[]};})};}})['then'](respondWithResult(_0x29542b,null))['catch'](function(_0x1b35e3){var _0x484a29=_0x111b4b[_0x32f6('0x30')][_0x32f6('0x6f')]?0x1f4:_0x1b35e3[_0x32f6('0x70')]||0x1f4;logger[_0x32f6('0x71')](_0x32f6('0x72'),_0x32f6('0x54'),_0x484a29,JSON[_0x32f6('0x61')](_0x1b35e3));delete _0x1b35e3[_0x32f6('0x25')];if(_0x484a29===0x191){_0x484a29=0x190;}_0x29542b[_0x32f6('0x1a')](_0x484a29)[_0x32f6('0x26')](_0x111b4b[_0x32f6('0x30')][_0x32f6('0x6f')]?{'message':_0x32f6('0x73'),'statusCode':_0x1b35e3['statusCode']}:_0x1b35e3);});}else{var _0x450ccb=0x1f4;_0x29542b[_0x32f6('0x1a')](_0x450ccb)[_0x32f6('0x26')]({'message':_0x32f6('0x73'),'statusCode':0x190});}});};
\ No newline at end of file