Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index 80cc694..533553e 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 _0x91a5=['remove','label','endsWith','test','Wrong\x20credentials','statusCode','eml-format','zip-dir','fast-json-patch','request-promise','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','limit','undefined','count','offset','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','index','SugarcrmAccount','rawAttributes','type','model','map','keys','query','filters','intersection','attributes','fields','length','nolimit','sort','where','pick','merge','VIRTUAL','options','include','findAll','show','params','includeAll','create','catch','body','find','getConfigurations','findOne','order','hasOwnProperty','AccountId','Subjects','getSubjects','channel','SugarcrmConfiguration','SugarcrmField','Descriptions','getFields','assigned_user_id','created_by','description','date_start','duration_hours','duration_minutes','parent_type','password','remoteUri','slice','substring','POST','format','/service/v4_1/rest.php','login','JSON','PLAIN','xCALLY\x20Motion\x20Integration','Invalid\x20Login','Password\x20Expired','get_module_fields','stringify','Calls','values','module_fields'];(function(_0x3fb5eb,_0x5947a6){var _0x481291=function(_0x74e4e){while(--_0x74e4e){_0x3fb5eb['push'](_0x3fb5eb['shift']());}};_0x481291(++_0x5947a6);}(_0x91a5,0x78));var _0x591a=function(_0x30033a,_0x5ce4a6){_0x30033a=_0x30033a-0x0;var _0x5e3518=_0x91a5[_0x30033a];return _0x5e3518;};'use strict';var emlformat=require(_0x591a('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x591a('0x1'));var jsonpatch=require(_0x591a('0x2'));var rp=require(_0x591a('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x591a('0x4'));var path=require(_0x591a('0x5'));var sox=require(_0x591a('0x6'));var csv=require(_0x591a('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x591a('0x8'));var _=require(_0x591a('0x9'));var squel=require(_0x591a('0xa'));var crypto=require(_0x591a('0xb'));var jsforce=require(_0x591a('0xc'));var deskjs=require(_0x591a('0xd'));var toCsv=require(_0x591a('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x591a('0xe'));var authService=require(_0x591a('0xf'));var qs=require(_0x591a('0x10'));var as=require(_0x591a('0x11'));var hardwareService=require(_0x591a('0x12'));var logger=require('../../config/logger')(_0x591a('0x13'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x591a('0x14'));var db=require(_0x591a('0x15'))['db'];var integrations=require(_0x591a('0x16'));function respondWithStatusCode(_0x217ad7,_0x24e89e){_0x24e89e=_0x24e89e||0xcc;return function(_0x5e1e75){if(_0x5e1e75){return _0x217ad7[_0x591a('0x17')](_0x24e89e);}return _0x217ad7[_0x591a('0x18')](_0x24e89e)[_0x591a('0x19')]();};}function respondWithResult(_0x27e7cc,_0x22906b){_0x22906b=_0x22906b||0xc8;return function(_0x33abbb){if(_0x33abbb){return _0x27e7cc[_0x591a('0x18')](_0x22906b)[_0x591a('0x1a')](_0x33abbb);}};}function respondWithFilteredResult(_0x7788fd,_0x15dce7){return function(_0x4596a7){if(_0x4596a7){var _0x4ff7cb=typeof _0x15dce7['offset']==='undefined'&&typeof _0x15dce7[_0x591a('0x1b')]===_0x591a('0x1c');var _0x2ac5ce=_0x4596a7[_0x591a('0x1d')];var _0x132309=_0x4ff7cb?0x0:_0x15dce7['offset'];var _0x382225=_0x4ff7cb?_0x4596a7[_0x591a('0x1d')]:_0x15dce7[_0x591a('0x1e')]+_0x15dce7[_0x591a('0x1b')];var _0x8da402;if(_0x382225>=_0x2ac5ce){_0x382225=_0x2ac5ce;_0x8da402=0xc8;}else{_0x8da402=0xce;}_0x7788fd['status'](_0x8da402);return _0x7788fd['set'](_0x591a('0x1f'),_0x132309+'-'+_0x382225+'/'+_0x2ac5ce)[_0x591a('0x1a')](_0x4596a7);}return null;};}function patchUpdates(_0x193485){return function(_0x420c80){try{jsonpatch[_0x591a('0x20')](_0x420c80,_0x193485,!![]);}catch(_0x4a9054){return BPromise[_0x591a('0x21')](_0x4a9054);}return _0x420c80[_0x591a('0x22')]();};}function saveUpdates(_0x5f4272,_0x2e4987){return function(_0x3303d5){if(_0x3303d5){return _0x3303d5[_0x591a('0x23')](_0x5f4272)[_0x591a('0x24')](function(_0x1c4307){return _0x1c4307;});}return null;};}function removeEntity(_0x25234d,_0x390679){return function(_0xfced56){if(_0xfced56){return _0xfced56[_0x591a('0x25')]()[_0x591a('0x24')](function(){_0x25234d[_0x591a('0x18')](0xcc)[_0x591a('0x19')]();});}};}function handleEntityNotFound(_0xba8f28,_0xc3a408){return function(_0xeaf5f2){if(!_0xeaf5f2){_0xba8f28['sendStatus'](0x194);}return _0xeaf5f2;};}function handleError(_0x433b90,_0x3f0b5f){_0x3f0b5f=_0x3f0b5f||0x1f4;return function(_0x19df07){logger[_0x591a('0x26')](_0x19df07[_0x591a('0x27')]);if(_0x19df07['name']){delete _0x19df07[_0x591a('0x28')];}_0x433b90[_0x591a('0x18')](_0x3f0b5f)[_0x591a('0x29')](_0x19df07);};}exports[_0x591a('0x2a')]=function(_0x361162,_0x3cd041){var _0x369320={},_0xb23a29={},_0x6f66ff={'count':0x0,'rows':[]};var _0x6537ad=_['map'](db[_0x591a('0x2b')][_0x591a('0x2c')],function(_0x10e763){return{'name':_0x10e763['fieldName'],'type':_0x10e763[_0x591a('0x2d')]['key']};});_0xb23a29[_0x591a('0x2e')]=_[_0x591a('0x2f')](_0x6537ad,_0x591a('0x28'));_0xb23a29['query']=_[_0x591a('0x30')](_0x361162[_0x591a('0x31')]);_0xb23a29[_0x591a('0x32')]=_[_0x591a('0x33')](_0xb23a29[_0x591a('0x2e')],_0xb23a29['query']);_0x369320[_0x591a('0x34')]=_['intersection'](_0xb23a29[_0x591a('0x2e')],qs[_0x591a('0x35')](_0x361162['query']['fields']));_0x369320[_0x591a('0x34')]=_0x369320['attributes'][_0x591a('0x36')]?_0x369320[_0x591a('0x34')]:_0xb23a29[_0x591a('0x2e')];if(!_0x361162[_0x591a('0x31')]['hasOwnProperty'](_0x591a('0x37'))){_0x369320['limit']=qs[_0x591a('0x1b')](_0x361162[_0x591a('0x31')]['limit']);_0x369320[_0x591a('0x1e')]=qs[_0x591a('0x1e')](_0x361162[_0x591a('0x31')][_0x591a('0x1e')]);}_0x369320['order']=qs[_0x591a('0x38')](_0x361162['query'][_0x591a('0x38')]);_0x369320[_0x591a('0x39')]=qs[_0x591a('0x32')](_[_0x591a('0x3a')](_0x361162[_0x591a('0x31')],_0xb23a29[_0x591a('0x32')]),_0x6537ad);if(_0x361162[_0x591a('0x31')]['filter']){_0x369320['where']=_[_0x591a('0x3b')](_0x369320[_0x591a('0x39')],{'$or':_[_0x591a('0x2f')](_0x6537ad,function(_0x3f0a4){if(_0x3f0a4['type']!==_0x591a('0x3c')){var _0x9a4422={};_0x9a4422[_0x3f0a4['name']]={'$like':'%'+_0x361162['query']['filter']+'%'};return _0x9a4422;}})});}_0x369320=_[_0x591a('0x3b')]({},_0x369320,_0x361162[_0x591a('0x3d')]);var _0x58d195={'where':_0x369320[_0x591a('0x39')]};return db[_0x591a('0x2b')]['count'](_0x58d195)[_0x591a('0x24')](function(_0x3c50aa){_0x6f66ff[_0x591a('0x1d')]=_0x3c50aa;if(_0x361162[_0x591a('0x31')]['includeAll']){_0x369320[_0x591a('0x3e')]=[{'all':!![]}];}return db[_0x591a('0x2b')][_0x591a('0x3f')](_0x369320);})[_0x591a('0x24')](function(_0x495a1a){_0x6f66ff['rows']=_0x495a1a;return _0x6f66ff;})[_0x591a('0x24')](respondWithFilteredResult(_0x3cd041,_0x369320))['catch'](handleError(_0x3cd041,null));};exports[_0x591a('0x40')]=function(_0x3202fc,_0x8f6041){var _0x4cf68e={'raw':![],'where':{'id':_0x3202fc[_0x591a('0x41')]['id']}},_0x57adf7={};_0x57adf7[_0x591a('0x2e')]=_['keys'](db[_0x591a('0x2b')][_0x591a('0x2c')]);_0x57adf7[_0x591a('0x31')]=_[_0x591a('0x30')](_0x3202fc[_0x591a('0x31')]);_0x57adf7['filters']=_[_0x591a('0x33')](_0x57adf7['model'],_0x57adf7[_0x591a('0x31')]);_0x4cf68e['attributes']=_[_0x591a('0x33')](_0x57adf7[_0x591a('0x2e')],qs['fields'](_0x3202fc[_0x591a('0x31')][_0x591a('0x35')]));_0x4cf68e[_0x591a('0x34')]=_0x4cf68e[_0x591a('0x34')][_0x591a('0x36')]?_0x4cf68e[_0x591a('0x34')]:_0x57adf7[_0x591a('0x2e')];if(_0x3202fc[_0x591a('0x31')][_0x591a('0x42')]){_0x4cf68e[_0x591a('0x3e')]=[{'all':!![]}];}_0x4cf68e=_['merge']({},_0x4cf68e,_0x3202fc[_0x591a('0x3d')]);return db['SugarcrmAccount']['find'](_0x4cf68e)[_0x591a('0x24')](handleEntityNotFound(_0x8f6041,null))['then'](respondWithResult(_0x8f6041,null))['catch'](handleError(_0x8f6041,null));};exports[_0x591a('0x43')]=function(_0x4658c1,_0x164608){return db[_0x591a('0x2b')][_0x591a('0x43')](_0x4658c1['body'],{})[_0x591a('0x24')](respondWithResult(_0x164608,0xc9))[_0x591a('0x44')](handleError(_0x164608,null));};exports['update']=function(_0x1987d5,_0x13a477){if(_0x1987d5['body']['id']){delete _0x1987d5[_0x591a('0x45')]['id'];}return db[_0x591a('0x2b')][_0x591a('0x46')]({'where':{'id':_0x1987d5[_0x591a('0x41')]['id']}})[_0x591a('0x24')](handleEntityNotFound(_0x13a477,null))[_0x591a('0x24')](saveUpdates(_0x1987d5[_0x591a('0x45')],null))[_0x591a('0x24')](respondWithResult(_0x13a477,null))[_0x591a('0x44')](handleError(_0x13a477,null));};exports[_0x591a('0x25')]=function(_0xfb3696,_0x179dbc){return db['SugarcrmAccount'][_0x591a('0x46')]({'where':{'id':_0xfb3696[_0x591a('0x41')]['id']}})[_0x591a('0x24')](handleEntityNotFound(_0x179dbc,null))[_0x591a('0x24')](removeEntity(_0x179dbc,null))[_0x591a('0x44')](handleError(_0x179dbc,null));};exports[_0x591a('0x47')]=function(_0x5942fd,_0x1e79d2,_0x190698){var _0x55e0c6={};var _0x1b67ca={};var _0x1e5590;var _0x82d343;return db[_0x591a('0x2b')][_0x591a('0x48')]({'where':{'id':_0x5942fd['params']['id']}})['then'](handleEntityNotFound(_0x1e79d2,null))[_0x591a('0x24')](function(_0x8422a4){if(_0x8422a4){_0x1e5590=_0x8422a4;_0x1b67ca['model']=_[_0x591a('0x30')](db['SugarcrmConfiguration'][_0x591a('0x2c')]);_0x1b67ca['query']=_[_0x591a('0x30')](_0x5942fd['query']);_0x1b67ca[_0x591a('0x32')]=_[_0x591a('0x33')](_0x1b67ca[_0x591a('0x2e')],_0x1b67ca[_0x591a('0x31')]);_0x55e0c6['attributes']=_['intersection'](_0x1b67ca[_0x591a('0x2e')],qs['fields'](_0x5942fd['query']['fields']));_0x55e0c6['attributes']=_0x55e0c6[_0x591a('0x34')]['length']?_0x55e0c6['attributes']:_0x1b67ca['model'];_0x55e0c6[_0x591a('0x49')]=qs[_0x591a('0x38')](_0x5942fd[_0x591a('0x31')][_0x591a('0x38')]);_0x55e0c6['where']=qs[_0x591a('0x32')](_[_0x591a('0x3a')](_0x5942fd[_0x591a('0x31')],_0x1b67ca[_0x591a('0x32')]));if(_0x5942fd[_0x591a('0x31')]['filter']){_0x55e0c6[_0x591a('0x39')]=_[_0x591a('0x3b')](_0x55e0c6[_0x591a('0x39')],{'$or':_[_0x591a('0x2f')](_0x55e0c6[_0x591a('0x34')],function(_0x2b2179){var _0xb83127={};_0xb83127[_0x2b2179]={'$like':'%'+_0x5942fd[_0x591a('0x31')]['filter']+'%'};return _0xb83127;})});}_0x55e0c6=_[_0x591a('0x3b')]({},_0x55e0c6,_0x5942fd['options']);return _0x1e5590[_0x591a('0x47')](_0x55e0c6);}})[_0x591a('0x24')](function(_0x3a42b7){if(_0x3a42b7){_0x82d343=_0x3a42b7[_0x591a('0x36')];if(!_0x5942fd[_0x591a('0x31')][_0x591a('0x4a')]('nolimit')){_0x55e0c6[_0x591a('0x1b')]=qs[_0x591a('0x1b')](_0x5942fd['query'][_0x591a('0x1b')]);_0x55e0c6[_0x591a('0x1e')]=qs['offset'](_0x5942fd[_0x591a('0x31')]['offset']);}return _0x1e5590['getConfigurations'](_0x55e0c6);}})[_0x591a('0x24')](function(_0x150e17){if(_0x150e17){return _0x150e17?{'count':_0x82d343,'rows':_0x150e17}:null;}})[_0x591a('0x24')](respondWithResult(_0x1e79d2,null))['catch'](handleError(_0x1e79d2,null));};exports['addConfiguration']=function(_0x23748b,_0x23c503,_0x837f91){if(_0x23748b[_0x591a('0x45')]['id']){delete _0x23748b[_0x591a('0x45')]['id'];}return db[_0x591a('0x2b')][_0x591a('0x48')]({'where':{'id':_0x23748b[_0x591a('0x41')]['id']}})[_0x591a('0x24')](handleEntityNotFound(_0x23c503,null))[_0x591a('0x24')](function(_0x1b4216){if(_0x1b4216){_0x23748b[_0x591a('0x45')][_0x591a('0x4b')]=_0x1b4216['id'];_0x23748b[_0x591a('0x45')][_0x591a('0x4c')]=integrations[_0x591a('0x4d')](_0x23748b[_0x591a('0x45')][_0x591a('0x4e')],_0x23748b['body'][_0x591a('0x2d')]);_0x23748b[_0x591a('0x45')]['Descriptions']=integrations['getDescriptions'](_0x23748b[_0x591a('0x45')][_0x591a('0x4e')],_0x23748b[_0x591a('0x45')]['type']);return db[_0x591a('0x4f')]['create'](_0x23748b['body'],{'include':[{'model':db[_0x591a('0x50')],'as':_0x591a('0x4c')},{'model':db[_0x591a('0x50')],'as':_0x591a('0x51')}]});}return null;})['then'](respondWithResult(_0x23c503,null))[_0x591a('0x44')](handleError(_0x23c503,null));};exports[_0x591a('0x52')]=function(_0x5759f9,_0x4da409,_0x4d6abe){var _0x2f9345='';var _0x3cd9ef=['id',_0x591a('0x28'),_0x591a('0x53'),_0x591a('0x54'),_0x591a('0x55'),_0x591a('0x56'),_0x591a('0x57'),_0x591a('0x58'),'parent_id',_0x591a('0x59'),'parent_name','direction'];return db[_0x591a('0x2b')][_0x591a('0x48')]({'where':{'id':_0x5759f9[_0x591a('0x41')]['id']},'attributes':['id','username',_0x591a('0x5a'),'remoteUri']})[_0x591a('0x24')](handleEntityNotFound(_0x4da409,null))['then'](function(_0x4c32e7){if(_0x4c32e7){_0x2f9345=_0x4c32e7[_0x591a('0x5b')];var _0x4a5ec5=_0x2f9345[_0x591a('0x5c')](-0x1);if(_0x4a5ec5==='/'){_0x2f9345=_0x2f9345[_0x591a('0x5d')](0x0,_0x2f9345['lastIndexOf'](_0x4a5ec5));}return rp({'method':_0x591a('0x5e'),'uri':util[_0x591a('0x5f')]('%s%s',_0x2f9345,_0x591a('0x60')),'json':!![],'form':{'method':_0x591a('0x61'),'input_type':_0x591a('0x62'),'response_type':_0x591a('0x62'),'rest_data':JSON['stringify']({'user_auth':{'user_name':_0x4c32e7['username'],'password':_0x4c32e7['password'],'encryption':_0x591a('0x63')},'application':_0x591a('0x64')})}});}})['then'](function(_0x301d89){if(_0x301d89&&_0x301d89[_0x591a('0x28')]!==_0x591a('0x65')&&_0x301d89[_0x591a('0x28')]!==_0x591a('0x66')){return rp({'method':_0x591a('0x5e'),'uri':util[_0x591a('0x5f')]('%s%s',_0x2f9345,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x591a('0x67'),'input_type':_0x591a('0x62'),'response_type':_0x591a('0x62'),'rest_data':JSON[_0x591a('0x68')]({'session':_0x301d89['id'],'module_name':_0x591a('0x69')})}})[_0x591a('0x24')](function(_0x23822a){if(_0x23822a){var _0x13f6b1=_[_0x591a('0x6a')](_0x23822a[_0x591a('0x6b')]);_[_0x591a('0x6c')](_0x13f6b1,function(_0x520d64){return _0x3cd9ef['includes'](_0x520d64[_0x591a('0x28')]);});return{'count':_0x13f6b1[_0x591a('0x36')],'rows':_[_0x591a('0x2f')](_0x13f6b1,function(_0xf2c451){return{'id':_0xf2c451['name'],'name':_0xf2c451[_0x591a('0x6d')],'custom':_[_0x591a('0x6e')](_0xf2c451[_0x591a('0x28')],'_c')?!![]:![],'options':_0xf2c451['options']?_[_0x591a('0x2f')](_[_0x591a('0x6a')](_0xf2c451[_0x591a('0x3d')]),function(_0x679770){return{'name':_0x679770['value'],'value':_0x679770[_0x591a('0x28')]};}):[]};})};}})[_0x591a('0x24')](respondWithResult(_0x4da409,null))[_0x591a('0x44')](function(_0x51d9b8){var _0x147543=_0x5759f9['query'][_0x591a('0x6f')]?0x1f4:_0x51d9b8['statusCode']||0x1f4;logger[_0x591a('0x26')]('getFields,\x20%s,\x20%s,\x20%s',_0x591a('0x52'),_0x147543,JSON[_0x591a('0x68')](_0x51d9b8));delete _0x51d9b8[_0x591a('0x28')];if(_0x147543===0x191){_0x147543=0x190;}_0x4da409[_0x591a('0x18')](_0x147543)[_0x591a('0x29')](_0x5759f9['query'][_0x591a('0x6f')]?{'message':_0x591a('0x70'),'statusCode':_0x51d9b8[_0x591a('0x71')]}:_0x51d9b8);});}else{var _0x14625c=0x1f4;_0x4da409[_0x591a('0x18')](_0x14625c)[_0x591a('0x29')]({'message':_0x591a('0x70'),'statusCode':0x190});}});};
\ No newline at end of file