Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index 80cc694..0e1f082 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7fbb=['to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','error','name','send','index','SugarcrmAccount','rawAttributes','type','key','keys','query','filters','intersection','attributes','model','fields','length','nolimit','order','sort','where','pick','filter','merge','map','VIRTUAL','include','findAll','catch','show','params','includeAll','find','create','body','destroy','getConfigurations','findOne','options','hasOwnProperty','addConfiguration','AccountId','getSubjects','channel','SugarcrmConfiguration','SugarcrmField','Subjects','Descriptions','assigned_user_id','created_by','description','date_start','parent_id','parent_type','parent_name','direction','username','password','remoteUri','slice','substring','POST','format','%s%s','/service/v4_1/rest.php','login','JSON','stringify','PLAIN','xCALLY\x20Motion\x20Integration','get_module_fields','module_fields','remove','label','endsWith','values','value','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util'];(function(_0x21a9d9,_0x4d5ac8){var _0x46adce=function(_0xfdd336){while(--_0xfdd336){_0x21a9d9['push'](_0x21a9d9['shift']());}};_0x46adce(++_0x4d5ac8);}(_0x7fbb,0x71));var _0xb7fb=function(_0x5542e4,_0x51f559){_0x5542e4=_0x5542e4-0x0;var _0x58d6aa=_0x7fbb[_0x5542e4];return _0x58d6aa;};'use strict';var emlformat=require(_0xb7fb('0x0'));var rimraf=require(_0xb7fb('0x1'));var zipdir=require(_0xb7fb('0x2'));var jsonpatch=require(_0xb7fb('0x3'));var rp=require(_0xb7fb('0x4'));var moment=require(_0xb7fb('0x5'));var BPromise=require(_0xb7fb('0x6'));var Mustache=require(_0xb7fb('0x7'));var util=require(_0xb7fb('0x8'));var path=require('path');var sox=require('sox');var csv=require(_0xb7fb('0x9'));var ejs=require(_0xb7fb('0xa'));var fs=require('fs');var fs_extra=require(_0xb7fb('0xb'));var _=require(_0xb7fb('0xc'));var squel=require(_0xb7fb('0xd'));var crypto=require(_0xb7fb('0xe'));var jsforce=require(_0xb7fb('0xf'));var deskjs=require(_0xb7fb('0x10'));var toCsv=require(_0xb7fb('0x9'));var querystring=require('querystring');var Papa=require(_0xb7fb('0x11'));var Redis=require('ioredis');var authService=require(_0xb7fb('0x12'));var qs=require(_0xb7fb('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb7fb('0x14'));var logger=require(_0xb7fb('0x15'))('api');var utils=require(_0xb7fb('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xb7fb('0x17'));var db=require(_0xb7fb('0x18'))['db'];var integrations=require(_0xb7fb('0x19'));function respondWithStatusCode(_0x26d55d,_0x43dc33){_0x43dc33=_0x43dc33||0xcc;return function(_0x420d0e){if(_0x420d0e){return _0x26d55d[_0xb7fb('0x1a')](_0x43dc33);}return _0x26d55d[_0xb7fb('0x1b')](_0x43dc33)[_0xb7fb('0x1c')]();};}function respondWithResult(_0xa48844,_0x66cfb1){_0x66cfb1=_0x66cfb1||0xc8;return function(_0x50eb15){if(_0x50eb15){return _0xa48844[_0xb7fb('0x1b')](_0x66cfb1)[_0xb7fb('0x1d')](_0x50eb15);}};}function respondWithFilteredResult(_0x42d05c,_0x5c8bbe){return function(_0x341f69){if(_0x341f69){var _0x7210=typeof _0x5c8bbe[_0xb7fb('0x1e')]===_0xb7fb('0x1f')&&typeof _0x5c8bbe[_0xb7fb('0x20')]==='undefined';var _0x345c40=_0x341f69[_0xb7fb('0x21')];var _0x5e12e3=_0x7210?0x0:_0x5c8bbe[_0xb7fb('0x1e')];var _0x319d93=_0x7210?_0x341f69[_0xb7fb('0x21')]:_0x5c8bbe['offset']+_0x5c8bbe['limit'];var _0x31590a;if(_0x319d93>=_0x345c40){_0x319d93=_0x345c40;_0x31590a=0xc8;}else{_0x31590a=0xce;}_0x42d05c[_0xb7fb('0x1b')](_0x31590a);return _0x42d05c[_0xb7fb('0x22')](_0xb7fb('0x23'),_0x5e12e3+'-'+_0x319d93+'/'+_0x345c40)[_0xb7fb('0x1d')](_0x341f69);}return null;};}function patchUpdates(_0x12870b){return function(_0xa8eb17){try{jsonpatch[_0xb7fb('0x24')](_0xa8eb17,_0x12870b,!![]);}catch(_0x16fb90){return BPromise[_0xb7fb('0x25')](_0x16fb90);}return _0xa8eb17[_0xb7fb('0x26')]();};}function saveUpdates(_0x2c145a,_0x2188aa){return function(_0x464f34){if(_0x464f34){return _0x464f34[_0xb7fb('0x27')](_0x2c145a)[_0xb7fb('0x28')](function(_0x49cf90){return _0x49cf90;});}return null;};}function removeEntity(_0x4bc0ef,_0x3e2b14){return function(_0x6317b5){if(_0x6317b5){return _0x6317b5['destroy']()['then'](function(){_0x4bc0ef[_0xb7fb('0x1b')](0xcc)[_0xb7fb('0x1c')]();});}};}function handleEntityNotFound(_0x2e290f,_0x55c1a9){return function(_0x37e49a){if(!_0x37e49a){_0x2e290f[_0xb7fb('0x1a')](0x194);}return _0x37e49a;};}function handleError(_0x3c3bf0,_0x30708a){_0x30708a=_0x30708a||0x1f4;return function(_0x6bf47e){logger[_0xb7fb('0x29')](_0x6bf47e['stack']);if(_0x6bf47e[_0xb7fb('0x2a')]){delete _0x6bf47e['name'];}_0x3c3bf0['status'](_0x30708a)[_0xb7fb('0x2b')](_0x6bf47e);};}exports[_0xb7fb('0x2c')]=function(_0x2fe917,_0x470f70){var _0x43a4df={},_0x258b4f={},_0x3fdc66={'count':0x0,'rows':[]};var _0x1146ce=_['map'](db[_0xb7fb('0x2d')][_0xb7fb('0x2e')],function(_0x51908b){return{'name':_0x51908b['fieldName'],'type':_0x51908b[_0xb7fb('0x2f')][_0xb7fb('0x30')]};});_0x258b4f['model']=_['map'](_0x1146ce,_0xb7fb('0x2a'));_0x258b4f['query']=_[_0xb7fb('0x31')](_0x2fe917[_0xb7fb('0x32')]);_0x258b4f[_0xb7fb('0x33')]=_[_0xb7fb('0x34')](_0x258b4f['model'],_0x258b4f[_0xb7fb('0x32')]);_0x43a4df[_0xb7fb('0x35')]=_['intersection'](_0x258b4f[_0xb7fb('0x36')],qs['fields'](_0x2fe917[_0xb7fb('0x32')][_0xb7fb('0x37')]));_0x43a4df['attributes']=_0x43a4df['attributes'][_0xb7fb('0x38')]?_0x43a4df[_0xb7fb('0x35')]:_0x258b4f[_0xb7fb('0x36')];if(!_0x2fe917['query']['hasOwnProperty'](_0xb7fb('0x39'))){_0x43a4df['limit']=qs[_0xb7fb('0x20')](_0x2fe917['query'][_0xb7fb('0x20')]);_0x43a4df[_0xb7fb('0x1e')]=qs['offset'](_0x2fe917[_0xb7fb('0x32')]['offset']);}_0x43a4df[_0xb7fb('0x3a')]=qs['sort'](_0x2fe917['query'][_0xb7fb('0x3b')]);_0x43a4df[_0xb7fb('0x3c')]=qs[_0xb7fb('0x33')](_[_0xb7fb('0x3d')](_0x2fe917[_0xb7fb('0x32')],_0x258b4f['filters']),_0x1146ce);if(_0x2fe917[_0xb7fb('0x32')][_0xb7fb('0x3e')]){_0x43a4df[_0xb7fb('0x3c')]=_[_0xb7fb('0x3f')](_0x43a4df['where'],{'$or':_[_0xb7fb('0x40')](_0x1146ce,function(_0x338e26){if(_0x338e26[_0xb7fb('0x2f')]!==_0xb7fb('0x41')){var _0x3f2109={};_0x3f2109[_0x338e26['name']]={'$like':'%'+_0x2fe917['query']['filter']+'%'};return _0x3f2109;}})});}_0x43a4df=_['merge']({},_0x43a4df,_0x2fe917['options']);var _0x5bdef9={'where':_0x43a4df[_0xb7fb('0x3c')]};return db['SugarcrmAccount'][_0xb7fb('0x21')](_0x5bdef9)[_0xb7fb('0x28')](function(_0x537f0d){_0x3fdc66[_0xb7fb('0x21')]=_0x537f0d;if(_0x2fe917[_0xb7fb('0x32')]['includeAll']){_0x43a4df[_0xb7fb('0x42')]=[{'all':!![]}];}return db[_0xb7fb('0x2d')][_0xb7fb('0x43')](_0x43a4df);})[_0xb7fb('0x28')](function(_0x2e16c6){_0x3fdc66['rows']=_0x2e16c6;return _0x3fdc66;})[_0xb7fb('0x28')](respondWithFilteredResult(_0x470f70,_0x43a4df))[_0xb7fb('0x44')](handleError(_0x470f70,null));};exports[_0xb7fb('0x45')]=function(_0x8e1bbe,_0x53d27b){var _0x835cb0={'raw':![],'where':{'id':_0x8e1bbe[_0xb7fb('0x46')]['id']}},_0x584390={};_0x584390[_0xb7fb('0x36')]=_[_0xb7fb('0x31')](db[_0xb7fb('0x2d')][_0xb7fb('0x2e')]);_0x584390['query']=_['keys'](_0x8e1bbe[_0xb7fb('0x32')]);_0x584390[_0xb7fb('0x33')]=_[_0xb7fb('0x34')](_0x584390['model'],_0x584390[_0xb7fb('0x32')]);_0x835cb0[_0xb7fb('0x35')]=_[_0xb7fb('0x34')](_0x584390['model'],qs[_0xb7fb('0x37')](_0x8e1bbe[_0xb7fb('0x32')]['fields']));_0x835cb0['attributes']=_0x835cb0[_0xb7fb('0x35')][_0xb7fb('0x38')]?_0x835cb0[_0xb7fb('0x35')]:_0x584390['model'];if(_0x8e1bbe[_0xb7fb('0x32')][_0xb7fb('0x47')]){_0x835cb0[_0xb7fb('0x42')]=[{'all':!![]}];}_0x835cb0=_[_0xb7fb('0x3f')]({},_0x835cb0,_0x8e1bbe['options']);return db[_0xb7fb('0x2d')][_0xb7fb('0x48')](_0x835cb0)['then'](handleEntityNotFound(_0x53d27b,null))[_0xb7fb('0x28')](respondWithResult(_0x53d27b,null))[_0xb7fb('0x44')](handleError(_0x53d27b,null));};exports[_0xb7fb('0x49')]=function(_0x91e59e,_0x4690da){return db['SugarcrmAccount']['create'](_0x91e59e[_0xb7fb('0x4a')],{})['then'](respondWithResult(_0x4690da,0xc9))['catch'](handleError(_0x4690da,null));};exports[_0xb7fb('0x27')]=function(_0x301554,_0x1ed459){if(_0x301554['body']['id']){delete _0x301554[_0xb7fb('0x4a')]['id'];}return db[_0xb7fb('0x2d')][_0xb7fb('0x48')]({'where':{'id':_0x301554[_0xb7fb('0x46')]['id']}})[_0xb7fb('0x28')](handleEntityNotFound(_0x1ed459,null))[_0xb7fb('0x28')](saveUpdates(_0x301554[_0xb7fb('0x4a')],null))[_0xb7fb('0x28')](respondWithResult(_0x1ed459,null))[_0xb7fb('0x44')](handleError(_0x1ed459,null));};exports[_0xb7fb('0x4b')]=function(_0xc27d6b,_0x10db92){return db[_0xb7fb('0x2d')][_0xb7fb('0x48')]({'where':{'id':_0xc27d6b[_0xb7fb('0x46')]['id']}})[_0xb7fb('0x28')](handleEntityNotFound(_0x10db92,null))['then'](removeEntity(_0x10db92,null))[_0xb7fb('0x44')](handleError(_0x10db92,null));};exports[_0xb7fb('0x4c')]=function(_0x4c9b77,_0x3e7074,_0x3d0e19){var _0x587f94={};var _0x61627={};var _0x47a880;var _0x5ba9e0;return db[_0xb7fb('0x2d')][_0xb7fb('0x4d')]({'where':{'id':_0x4c9b77['params']['id']}})[_0xb7fb('0x28')](handleEntityNotFound(_0x3e7074,null))[_0xb7fb('0x28')](function(_0x886c4c){if(_0x886c4c){_0x47a880=_0x886c4c;_0x61627[_0xb7fb('0x36')]=_[_0xb7fb('0x31')](db['SugarcrmConfiguration']['rawAttributes']);_0x61627[_0xb7fb('0x32')]=_['keys'](_0x4c9b77[_0xb7fb('0x32')]);_0x61627['filters']=_[_0xb7fb('0x34')](_0x61627['model'],_0x61627[_0xb7fb('0x32')]);_0x587f94[_0xb7fb('0x35')]=_[_0xb7fb('0x34')](_0x61627[_0xb7fb('0x36')],qs[_0xb7fb('0x37')](_0x4c9b77['query'][_0xb7fb('0x37')]));_0x587f94[_0xb7fb('0x35')]=_0x587f94[_0xb7fb('0x35')][_0xb7fb('0x38')]?_0x587f94[_0xb7fb('0x35')]:_0x61627[_0xb7fb('0x36')];_0x587f94[_0xb7fb('0x3a')]=qs[_0xb7fb('0x3b')](_0x4c9b77[_0xb7fb('0x32')][_0xb7fb('0x3b')]);_0x587f94['where']=qs['filters'](_['pick'](_0x4c9b77[_0xb7fb('0x32')],_0x61627[_0xb7fb('0x33')]));if(_0x4c9b77[_0xb7fb('0x32')][_0xb7fb('0x3e')]){_0x587f94['where']=_['merge'](_0x587f94['where'],{'$or':_[_0xb7fb('0x40')](_0x587f94['attributes'],function(_0x1bdd38){var _0x5131ca={};_0x5131ca[_0x1bdd38]={'$like':'%'+_0x4c9b77['query'][_0xb7fb('0x3e')]+'%'};return _0x5131ca;})});}_0x587f94=_[_0xb7fb('0x3f')]({},_0x587f94,_0x4c9b77[_0xb7fb('0x4e')]);return _0x47a880[_0xb7fb('0x4c')](_0x587f94);}})[_0xb7fb('0x28')](function(_0x17a404){if(_0x17a404){_0x5ba9e0=_0x17a404[_0xb7fb('0x38')];if(!_0x4c9b77['query'][_0xb7fb('0x4f')](_0xb7fb('0x39'))){_0x587f94['limit']=qs['limit'](_0x4c9b77[_0xb7fb('0x32')]['limit']);_0x587f94[_0xb7fb('0x1e')]=qs[_0xb7fb('0x1e')](_0x4c9b77[_0xb7fb('0x32')]['offset']);}return _0x47a880[_0xb7fb('0x4c')](_0x587f94);}})[_0xb7fb('0x28')](function(_0x18b374){if(_0x18b374){return _0x18b374?{'count':_0x5ba9e0,'rows':_0x18b374}:null;}})[_0xb7fb('0x28')](respondWithResult(_0x3e7074,null))[_0xb7fb('0x44')](handleError(_0x3e7074,null));};exports[_0xb7fb('0x50')]=function(_0x5a5d1c,_0x48af91,_0x48d747){if(_0x5a5d1c[_0xb7fb('0x4a')]['id']){delete _0x5a5d1c[_0xb7fb('0x4a')]['id'];}return db[_0xb7fb('0x2d')]['findOne']({'where':{'id':_0x5a5d1c['params']['id']}})[_0xb7fb('0x28')](handleEntityNotFound(_0x48af91,null))[_0xb7fb('0x28')](function(_0x206d7c){if(_0x206d7c){_0x5a5d1c['body'][_0xb7fb('0x51')]=_0x206d7c['id'];_0x5a5d1c[_0xb7fb('0x4a')]['Subjects']=integrations[_0xb7fb('0x52')](_0x5a5d1c[_0xb7fb('0x4a')]['channel'],_0x5a5d1c['body']['type']);_0x5a5d1c[_0xb7fb('0x4a')]['Descriptions']=integrations['getDescriptions'](_0x5a5d1c['body'][_0xb7fb('0x53')],_0x5a5d1c[_0xb7fb('0x4a')]['type']);return db[_0xb7fb('0x54')]['create'](_0x5a5d1c[_0xb7fb('0x4a')],{'include':[{'model':db[_0xb7fb('0x55')],'as':_0xb7fb('0x56')},{'model':db[_0xb7fb('0x55')],'as':_0xb7fb('0x57')}]});}return null;})[_0xb7fb('0x28')](respondWithResult(_0x48af91,null))[_0xb7fb('0x44')](handleError(_0x48af91,null));};exports['getFields']=function(_0x1c38a0,_0x4a2ba3,_0x5b5435){var _0x3d4d5f='';var _0x4e21d3=['id','name',_0xb7fb('0x58'),_0xb7fb('0x59'),_0xb7fb('0x5a'),_0xb7fb('0x5b'),'duration_hours','duration_minutes',_0xb7fb('0x5c'),_0xb7fb('0x5d'),_0xb7fb('0x5e'),_0xb7fb('0x5f')];return db[_0xb7fb('0x2d')]['findOne']({'where':{'id':_0x1c38a0['params']['id']},'attributes':['id',_0xb7fb('0x60'),_0xb7fb('0x61'),'remoteUri']})[_0xb7fb('0x28')](handleEntityNotFound(_0x4a2ba3,null))[_0xb7fb('0x28')](function(_0x585f1f){if(_0x585f1f){_0x3d4d5f=_0x585f1f[_0xb7fb('0x62')];var _0x456474=_0x3d4d5f[_0xb7fb('0x63')](-0x1);if(_0x456474==='/'){_0x3d4d5f=_0x3d4d5f[_0xb7fb('0x64')](0x0,_0x3d4d5f['lastIndexOf'](_0x456474));}return rp({'method':_0xb7fb('0x65'),'uri':util[_0xb7fb('0x66')](_0xb7fb('0x67'),_0x3d4d5f,_0xb7fb('0x68')),'json':!![],'form':{'method':_0xb7fb('0x69'),'input_type':_0xb7fb('0x6a'),'response_type':'JSON','rest_data':JSON[_0xb7fb('0x6b')]({'user_auth':{'user_name':_0x585f1f[_0xb7fb('0x60')],'password':_0x585f1f['password'],'encryption':_0xb7fb('0x6c')},'application':_0xb7fb('0x6d')})}});}})[_0xb7fb('0x28')](function(_0x453e31){if(_0x453e31&&_0x453e31[_0xb7fb('0x2a')]!=='Invalid\x20Login'&&_0x453e31['name']!=='Password\x20Expired'){return rp({'method':'POST','uri':util[_0xb7fb('0x66')](_0xb7fb('0x67'),_0x3d4d5f,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0xb7fb('0x6e'),'input_type':_0xb7fb('0x6a'),'response_type':_0xb7fb('0x6a'),'rest_data':JSON[_0xb7fb('0x6b')]({'session':_0x453e31['id'],'module_name':'Calls'})}})[_0xb7fb('0x28')](function(_0x509466){if(_0x509466){var _0x12b029=_['values'](_0x509466[_0xb7fb('0x6f')]);_[_0xb7fb('0x70')](_0x12b029,function(_0x1e62e2){return _0x4e21d3['includes'](_0x1e62e2[_0xb7fb('0x2a')]);});return{'count':_0x12b029[_0xb7fb('0x38')],'rows':_[_0xb7fb('0x40')](_0x12b029,function(_0x516f52){return{'id':_0x516f52['name'],'name':_0x516f52[_0xb7fb('0x71')],'custom':_[_0xb7fb('0x72')](_0x516f52[_0xb7fb('0x2a')],'_c')?!![]:![],'options':_0x516f52[_0xb7fb('0x4e')]?_[_0xb7fb('0x40')](_[_0xb7fb('0x73')](_0x516f52[_0xb7fb('0x4e')]),function(_0x444a04){return{'name':_0x444a04[_0xb7fb('0x74')],'value':_0x444a04[_0xb7fb('0x2a')]};}):[]};})};}})['then'](respondWithResult(_0x4a2ba3,null))[_0xb7fb('0x44')](function(_0x4ec31a){var _0x477a7c=_0x1c38a0[_0xb7fb('0x32')][_0xb7fb('0x75')]?0x1f4:_0x4ec31a[_0xb7fb('0x76')]||0x1f4;logger[_0xb7fb('0x29')](_0xb7fb('0x77'),_0xb7fb('0x78'),_0x477a7c,JSON[_0xb7fb('0x6b')](_0x4ec31a));delete _0x4ec31a['name'];if(_0x477a7c===0x191){_0x477a7c=0x190;}_0x4a2ba3[_0xb7fb('0x1b')](_0x477a7c)['send'](_0x1c38a0[_0xb7fb('0x32')][_0xb7fb('0x75')]?{'message':_0xb7fb('0x79'),'statusCode':_0x4ec31a[_0xb7fb('0x76')]}:_0x4ec31a);});}else{var _0x539b51=0x1f4;_0x4a2ba3['status'](_0x539b51)[_0xb7fb('0x2b')]({'message':_0xb7fb('0x79'),'statusCode':0x190});}});};
\ No newline at end of file
+var _0x58a4=['show','params','length','find','create','body','destroy','getConfigurations','findOne','SugarcrmConfiguration','addConfiguration','AccountId','Subjects','channel','getDescriptions','SugarcrmField','Descriptions','getFields','created_by','description','parent_id','parent_name','direction','username','password','remoteUri','substring','lastIndexOf','POST','%s%s','login','JSON','stringify','PLAIN','xCALLY\x20Motion\x20Integration','Invalid\x20Login','Password\x20Expired','/service/v4_1/rest.php','get_module_fields','Calls','values','includes','label','endsWith','value','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','error','stack','name','send','index','map','SugarcrmAccount','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','then','catch'];(function(_0x4186fa,_0x26a01c){var _0x136990=function(_0x13324f){while(--_0x13324f){_0x4186fa['push'](_0x4186fa['shift']());}};_0x136990(++_0x26a01c);}(_0x58a4,0x196));var _0x458a=function(_0xbe6d5d,_0x308a41){_0xbe6d5d=_0xbe6d5d-0x0;var _0x2cb584=_0x58a4[_0xbe6d5d];return _0x2cb584;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x458a('0x0'));var zipdir=require(_0x458a('0x1'));var jsonpatch=require(_0x458a('0x2'));var rp=require('request-promise');var moment=require(_0x458a('0x3'));var BPromise=require(_0x458a('0x4'));var Mustache=require(_0x458a('0x5'));var util=require(_0x458a('0x6'));var path=require('path');var sox=require(_0x458a('0x7'));var csv=require(_0x458a('0x8'));var ejs=require(_0x458a('0x9'));var fs=require('fs');var fs_extra=require(_0x458a('0xa'));var _=require('lodash');var squel=require(_0x458a('0xb'));var crypto=require(_0x458a('0xc'));var jsforce=require(_0x458a('0xd'));var deskjs=require(_0x458a('0xe'));var toCsv=require(_0x458a('0x8'));var querystring=require(_0x458a('0xf'));var Papa=require(_0x458a('0x10'));var Redis=require(_0x458a('0x11'));var authService=require(_0x458a('0x12'));var qs=require(_0x458a('0x13'));var as=require(_0x458a('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x458a('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x458a('0x16'));var db=require(_0x458a('0x17'))['db'];var integrations=require('../../components/integrations/configuration');function respondWithStatusCode(_0x357dfd,_0x33fbe7){_0x33fbe7=_0x33fbe7||0xcc;return function(_0x4ea160){if(_0x4ea160){return _0x357dfd[_0x458a('0x18')](_0x33fbe7);}return _0x357dfd[_0x458a('0x19')](_0x33fbe7)[_0x458a('0x1a')]();};}function respondWithResult(_0x3f97eb,_0x3909dd){_0x3909dd=_0x3909dd||0xc8;return function(_0x432e9f){if(_0x432e9f){return _0x3f97eb['status'](_0x3909dd)[_0x458a('0x1b')](_0x432e9f);}};}function respondWithFilteredResult(_0x48eb95,_0x312085){return function(_0x172a84){if(_0x172a84){var _0x4edb57=typeof _0x312085[_0x458a('0x1c')]===_0x458a('0x1d')&&typeof _0x312085[_0x458a('0x1e')]==='undefined';var _0x40524b=_0x172a84[_0x458a('0x1f')];var _0x40d804=_0x4edb57?0x0:_0x312085[_0x458a('0x1c')];var _0x354e31=_0x4edb57?_0x172a84[_0x458a('0x1f')]:_0x312085['offset']+_0x312085[_0x458a('0x1e')];var _0x41a894;if(_0x354e31>=_0x40524b){_0x354e31=_0x40524b;_0x41a894=0xc8;}else{_0x41a894=0xce;}_0x48eb95['status'](_0x41a894);return _0x48eb95[_0x458a('0x20')](_0x458a('0x21'),_0x40d804+'-'+_0x354e31+'/'+_0x40524b)[_0x458a('0x1b')](_0x172a84);}return null;};}function patchUpdates(_0x15155e){return function(_0x2aecb1){try{jsonpatch['apply'](_0x2aecb1,_0x15155e,!![]);}catch(_0x350072){return BPromise[_0x458a('0x22')](_0x350072);}return _0x2aecb1[_0x458a('0x23')]();};}function saveUpdates(_0x46c6ff,_0x4a0a7b){return function(_0x252c9a){if(_0x252c9a){return _0x252c9a[_0x458a('0x24')](_0x46c6ff)['then'](function(_0x421c5e){return _0x421c5e;});}return null;};}function removeEntity(_0x1f943b,_0xf3dbb){return function(_0x3ea4cd){if(_0x3ea4cd){return _0x3ea4cd['destroy']()['then'](function(){_0x1f943b['status'](0xcc)[_0x458a('0x1a')]();});}};}function handleEntityNotFound(_0x239821,_0x37a8fc){return function(_0xb18de7){if(!_0xb18de7){_0x239821[_0x458a('0x18')](0x194);}return _0xb18de7;};}function handleError(_0x5274cb,_0x22019a){_0x22019a=_0x22019a||0x1f4;return function(_0x27b02e){logger[_0x458a('0x25')](_0x27b02e[_0x458a('0x26')]);if(_0x27b02e['name']){delete _0x27b02e[_0x458a('0x27')];}_0x5274cb[_0x458a('0x19')](_0x22019a)[_0x458a('0x28')](_0x27b02e);};}exports[_0x458a('0x29')]=function(_0x156b66,_0x5429d9){var _0xd21328={},_0xab831d={},_0x415c8e={'count':0x0,'rows':[]};var _0x334bb3=_[_0x458a('0x2a')](db[_0x458a('0x2b')][_0x458a('0x2c')],function(_0x2b591e){return{'name':_0x2b591e[_0x458a('0x2d')],'type':_0x2b591e[_0x458a('0x2e')][_0x458a('0x2f')]};});_0xab831d[_0x458a('0x30')]=_[_0x458a('0x2a')](_0x334bb3,_0x458a('0x27'));_0xab831d[_0x458a('0x31')]=_[_0x458a('0x32')](_0x156b66[_0x458a('0x31')]);_0xab831d[_0x458a('0x33')]=_[_0x458a('0x34')](_0xab831d[_0x458a('0x30')],_0xab831d[_0x458a('0x31')]);_0xd21328[_0x458a('0x35')]=_[_0x458a('0x34')](_0xab831d[_0x458a('0x30')],qs[_0x458a('0x36')](_0x156b66[_0x458a('0x31')][_0x458a('0x36')]));_0xd21328[_0x458a('0x35')]=_0xd21328[_0x458a('0x35')]['length']?_0xd21328['attributes']:_0xab831d[_0x458a('0x30')];if(!_0x156b66['query'][_0x458a('0x37')](_0x458a('0x38'))){_0xd21328['limit']=qs[_0x458a('0x1e')](_0x156b66['query'][_0x458a('0x1e')]);_0xd21328['offset']=qs[_0x458a('0x1c')](_0x156b66[_0x458a('0x31')][_0x458a('0x1c')]);}_0xd21328[_0x458a('0x39')]=qs[_0x458a('0x3a')](_0x156b66[_0x458a('0x31')][_0x458a('0x3a')]);_0xd21328['where']=qs[_0x458a('0x33')](_[_0x458a('0x3b')](_0x156b66[_0x458a('0x31')],_0xab831d['filters']),_0x334bb3);if(_0x156b66[_0x458a('0x31')][_0x458a('0x3c')]){_0xd21328[_0x458a('0x3d')]=_[_0x458a('0x3e')](_0xd21328[_0x458a('0x3d')],{'$or':_[_0x458a('0x2a')](_0x334bb3,function(_0x46c2f6){if(_0x46c2f6[_0x458a('0x2e')]!==_0x458a('0x3f')){var _0x60dfc0={};_0x60dfc0[_0x46c2f6[_0x458a('0x27')]]={'$like':'%'+_0x156b66[_0x458a('0x31')]['filter']+'%'};return _0x60dfc0;}})});}_0xd21328=_['merge']({},_0xd21328,_0x156b66[_0x458a('0x40')]);var _0x4c2aba={'where':_0xd21328[_0x458a('0x3d')]};return db[_0x458a('0x2b')][_0x458a('0x1f')](_0x4c2aba)['then'](function(_0xb4d73d){_0x415c8e[_0x458a('0x1f')]=_0xb4d73d;if(_0x156b66[_0x458a('0x31')][_0x458a('0x41')]){_0xd21328[_0x458a('0x42')]=[{'all':!![]}];}return db[_0x458a('0x2b')][_0x458a('0x43')](_0xd21328);})['then'](function(_0x480ccf){_0x415c8e['rows']=_0x480ccf;return _0x415c8e;})[_0x458a('0x44')](respondWithFilteredResult(_0x5429d9,_0xd21328))[_0x458a('0x45')](handleError(_0x5429d9,null));};exports[_0x458a('0x46')]=function(_0x525776,_0x293923){var _0x16dc79={'raw':![],'where':{'id':_0x525776[_0x458a('0x47')]['id']}},_0x3d7033={};_0x3d7033['model']=_[_0x458a('0x32')](db['SugarcrmAccount'][_0x458a('0x2c')]);_0x3d7033[_0x458a('0x31')]=_['keys'](_0x525776['query']);_0x3d7033['filters']=_[_0x458a('0x34')](_0x3d7033[_0x458a('0x30')],_0x3d7033[_0x458a('0x31')]);_0x16dc79[_0x458a('0x35')]=_[_0x458a('0x34')](_0x3d7033[_0x458a('0x30')],qs[_0x458a('0x36')](_0x525776[_0x458a('0x31')][_0x458a('0x36')]));_0x16dc79[_0x458a('0x35')]=_0x16dc79[_0x458a('0x35')][_0x458a('0x48')]?_0x16dc79[_0x458a('0x35')]:_0x3d7033[_0x458a('0x30')];if(_0x525776[_0x458a('0x31')][_0x458a('0x41')]){_0x16dc79[_0x458a('0x42')]=[{'all':!![]}];}_0x16dc79=_[_0x458a('0x3e')]({},_0x16dc79,_0x525776[_0x458a('0x40')]);return db[_0x458a('0x2b')][_0x458a('0x49')](_0x16dc79)[_0x458a('0x44')](handleEntityNotFound(_0x293923,null))['then'](respondWithResult(_0x293923,null))[_0x458a('0x45')](handleError(_0x293923,null));};exports[_0x458a('0x4a')]=function(_0x51ffbc,_0x469724){return db[_0x458a('0x2b')][_0x458a('0x4a')](_0x51ffbc[_0x458a('0x4b')],{})[_0x458a('0x44')](respondWithResult(_0x469724,0xc9))[_0x458a('0x45')](handleError(_0x469724,null));};exports[_0x458a('0x24')]=function(_0x58e229,_0x1b7d63){if(_0x58e229[_0x458a('0x4b')]['id']){delete _0x58e229[_0x458a('0x4b')]['id'];}return db['SugarcrmAccount'][_0x458a('0x49')]({'where':{'id':_0x58e229[_0x458a('0x47')]['id']}})['then'](handleEntityNotFound(_0x1b7d63,null))[_0x458a('0x44')](saveUpdates(_0x58e229['body'],null))['then'](respondWithResult(_0x1b7d63,null))[_0x458a('0x45')](handleError(_0x1b7d63,null));};exports[_0x458a('0x4c')]=function(_0xc97b5f,_0x41f9c6){return db[_0x458a('0x2b')]['find']({'where':{'id':_0xc97b5f[_0x458a('0x47')]['id']}})[_0x458a('0x44')](handleEntityNotFound(_0x41f9c6,null))[_0x458a('0x44')](removeEntity(_0x41f9c6,null))[_0x458a('0x45')](handleError(_0x41f9c6,null));};exports[_0x458a('0x4d')]=function(_0x4df6c2,_0x61c134,_0x34e6d8){var _0x52c750={};var _0x38be91={};var _0x1e0ca3;var _0x1d2ce4;return db[_0x458a('0x2b')][_0x458a('0x4e')]({'where':{'id':_0x4df6c2[_0x458a('0x47')]['id']}})['then'](handleEntityNotFound(_0x61c134,null))[_0x458a('0x44')](function(_0x465243){if(_0x465243){_0x1e0ca3=_0x465243;_0x38be91['model']=_['keys'](db[_0x458a('0x4f')][_0x458a('0x2c')]);_0x38be91[_0x458a('0x31')]=_[_0x458a('0x32')](_0x4df6c2[_0x458a('0x31')]);_0x38be91[_0x458a('0x33')]=_['intersection'](_0x38be91[_0x458a('0x30')],_0x38be91[_0x458a('0x31')]);_0x52c750['attributes']=_[_0x458a('0x34')](_0x38be91[_0x458a('0x30')],qs[_0x458a('0x36')](_0x4df6c2[_0x458a('0x31')]['fields']));_0x52c750['attributes']=_0x52c750['attributes'][_0x458a('0x48')]?_0x52c750[_0x458a('0x35')]:_0x38be91['model'];_0x52c750[_0x458a('0x39')]=qs[_0x458a('0x3a')](_0x4df6c2[_0x458a('0x31')]['sort']);_0x52c750[_0x458a('0x3d')]=qs[_0x458a('0x33')](_[_0x458a('0x3b')](_0x4df6c2[_0x458a('0x31')],_0x38be91[_0x458a('0x33')]));if(_0x4df6c2[_0x458a('0x31')][_0x458a('0x3c')]){_0x52c750[_0x458a('0x3d')]=_[_0x458a('0x3e')](_0x52c750[_0x458a('0x3d')],{'$or':_['map'](_0x52c750[_0x458a('0x35')],function(_0x2a43f5){var _0x48d9ae={};_0x48d9ae[_0x2a43f5]={'$like':'%'+_0x4df6c2['query'][_0x458a('0x3c')]+'%'};return _0x48d9ae;})});}_0x52c750=_[_0x458a('0x3e')]({},_0x52c750,_0x4df6c2[_0x458a('0x40')]);return _0x1e0ca3[_0x458a('0x4d')](_0x52c750);}})[_0x458a('0x44')](function(_0x3890be){if(_0x3890be){_0x1d2ce4=_0x3890be[_0x458a('0x48')];if(!_0x4df6c2[_0x458a('0x31')][_0x458a('0x37')](_0x458a('0x38'))){_0x52c750[_0x458a('0x1e')]=qs[_0x458a('0x1e')](_0x4df6c2[_0x458a('0x31')][_0x458a('0x1e')]);_0x52c750['offset']=qs[_0x458a('0x1c')](_0x4df6c2['query'][_0x458a('0x1c')]);}return _0x1e0ca3['getConfigurations'](_0x52c750);}})['then'](function(_0x4584f9){if(_0x4584f9){return _0x4584f9?{'count':_0x1d2ce4,'rows':_0x4584f9}:null;}})[_0x458a('0x44')](respondWithResult(_0x61c134,null))[_0x458a('0x45')](handleError(_0x61c134,null));};exports[_0x458a('0x50')]=function(_0x1e08f2,_0x55557b,_0x47724a){if(_0x1e08f2[_0x458a('0x4b')]['id']){delete _0x1e08f2[_0x458a('0x4b')]['id'];}return db[_0x458a('0x2b')]['findOne']({'where':{'id':_0x1e08f2['params']['id']}})['then'](handleEntityNotFound(_0x55557b,null))[_0x458a('0x44')](function(_0x530928){if(_0x530928){_0x1e08f2[_0x458a('0x4b')][_0x458a('0x51')]=_0x530928['id'];_0x1e08f2[_0x458a('0x4b')][_0x458a('0x52')]=integrations['getSubjects'](_0x1e08f2['body'][_0x458a('0x53')],_0x1e08f2[_0x458a('0x4b')][_0x458a('0x2e')]);_0x1e08f2[_0x458a('0x4b')]['Descriptions']=integrations[_0x458a('0x54')](_0x1e08f2[_0x458a('0x4b')][_0x458a('0x53')],_0x1e08f2[_0x458a('0x4b')]['type']);return db[_0x458a('0x4f')]['create'](_0x1e08f2[_0x458a('0x4b')],{'include':[{'model':db[_0x458a('0x55')],'as':_0x458a('0x52')},{'model':db[_0x458a('0x55')],'as':_0x458a('0x56')}]});}return null;})[_0x458a('0x44')](respondWithResult(_0x55557b,null))[_0x458a('0x45')](handleError(_0x55557b,null));};exports[_0x458a('0x57')]=function(_0x4ea096,_0x11dedb,_0x414e39){var _0x377c7d='';var _0x3ea53d=['id',_0x458a('0x27'),'assigned_user_id',_0x458a('0x58'),_0x458a('0x59'),'date_start','duration_hours','duration_minutes',_0x458a('0x5a'),'parent_type',_0x458a('0x5b'),_0x458a('0x5c')];return db[_0x458a('0x2b')][_0x458a('0x4e')]({'where':{'id':_0x4ea096[_0x458a('0x47')]['id']},'attributes':['id',_0x458a('0x5d'),_0x458a('0x5e'),_0x458a('0x5f')]})[_0x458a('0x44')](handleEntityNotFound(_0x11dedb,null))[_0x458a('0x44')](function(_0x3a9ffc){if(_0x3a9ffc){_0x377c7d=_0x3a9ffc[_0x458a('0x5f')];var _0x5cf49f=_0x377c7d['slice'](-0x1);if(_0x5cf49f==='/'){_0x377c7d=_0x377c7d[_0x458a('0x60')](0x0,_0x377c7d[_0x458a('0x61')](_0x5cf49f));}return rp({'method':_0x458a('0x62'),'uri':util['format'](_0x458a('0x63'),_0x377c7d,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x458a('0x64'),'input_type':_0x458a('0x65'),'response_type':_0x458a('0x65'),'rest_data':JSON[_0x458a('0x66')]({'user_auth':{'user_name':_0x3a9ffc[_0x458a('0x5d')],'password':_0x3a9ffc['password'],'encryption':_0x458a('0x67')},'application':_0x458a('0x68')})}});}})[_0x458a('0x44')](function(_0x59a6f8){if(_0x59a6f8&&_0x59a6f8[_0x458a('0x27')]!==_0x458a('0x69')&&_0x59a6f8[_0x458a('0x27')]!==_0x458a('0x6a')){return rp({'method':_0x458a('0x62'),'uri':util['format'](_0x458a('0x63'),_0x377c7d,_0x458a('0x6b')),'json':!![],'form':{'method':_0x458a('0x6c'),'input_type':'JSON','response_type':_0x458a('0x65'),'rest_data':JSON[_0x458a('0x66')]({'session':_0x59a6f8['id'],'module_name':_0x458a('0x6d')})}})[_0x458a('0x44')](function(_0x2f1adb){if(_0x2f1adb){var _0x3f88ff=_[_0x458a('0x6e')](_0x2f1adb['module_fields']);_['remove'](_0x3f88ff,function(_0x7ed3a){return _0x3ea53d[_0x458a('0x6f')](_0x7ed3a[_0x458a('0x27')]);});return{'count':_0x3f88ff[_0x458a('0x48')],'rows':_['map'](_0x3f88ff,function(_0x38e40d){return{'id':_0x38e40d[_0x458a('0x27')],'name':_0x38e40d[_0x458a('0x70')],'custom':_[_0x458a('0x71')](_0x38e40d[_0x458a('0x27')],'_c')?!![]:![],'options':_0x38e40d['options']?_[_0x458a('0x2a')](_['values'](_0x38e40d[_0x458a('0x40')]),function(_0xc85e79){return{'name':_0xc85e79[_0x458a('0x72')],'value':_0xc85e79['name']};}):[]};})};}})[_0x458a('0x44')](respondWithResult(_0x11dedb,null))['catch'](function(_0x8fc92b){var _0x2d9518=_0x4ea096['query'][_0x458a('0x73')]?0x1f4:_0x8fc92b[_0x458a('0x74')]||0x1f4;logger[_0x458a('0x25')](_0x458a('0x75'),_0x458a('0x57'),_0x2d9518,JSON['stringify'](_0x8fc92b));delete _0x8fc92b[_0x458a('0x27')];if(_0x2d9518===0x191){_0x2d9518=0x190;}_0x11dedb[_0x458a('0x19')](_0x2d9518)['send'](_0x4ea096[_0x458a('0x31')][_0x458a('0x73')]?{'message':_0x458a('0x76'),'statusCode':_0x8fc92b[_0x458a('0x74')]}:_0x8fc92b);});}else{var _0x43305a=0x1f4;_0x11dedb[_0x458a('0x19')](_0x43305a)[_0x458a('0x28')]({'message':_0x458a('0x76'),'statusCode':0x190});}});};
\ No newline at end of file