Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / intSugarcrmAccount / intSugarcrmAccount.controller.js
index 4af2414..533553e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3ff8=['nolimit','order','where','pick','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','length','find','create','body','params','getConfigurations','findOne','sort','addConfiguration','Subjects','channel','Descriptions','getDescriptions','SugarcrmConfiguration','SugarcrmField','assigned_user_id','description','duration_hours','duration_minutes','parent_id','parent_type','parent_name','direction','remoteUri','substring','lastIndexOf','POST','format','%s%s','login','JSON','stringify','password','Invalid\x20Login','Password\x20Expired','/service/v4_1/rest.php','get_module_fields','Calls','values','module_fields','remove','includes','label','endsWith','value','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','Wrong\x20credentials','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/utils','../../components/integrations/configuration','sendStatus','end','status','json','offset','undefined','count','limit','Content-Range','save','update','then','destroy','error','name','send','index','map','SugarcrmAccount','rawAttributes','type','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty'];(function(_0x1651e4,_0x49c4af){var _0x349e62=function(_0x1fddef){while(--_0x1fddef){_0x1651e4['push'](_0x1651e4['shift']());}};_0x349e62(++_0x49c4af);}(_0x3ff8,0x194));var _0x83ff=function(_0x4bf4a2,_0x15f64c){_0x4bf4a2=_0x4bf4a2-0x0;var _0x1eca49=_0x3ff8[_0x4bf4a2];return _0x1eca49;};'use strict';var emlformat=require(_0x83ff('0x0'));var rimraf=require(_0x83ff('0x1'));var zipdir=require(_0x83ff('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x83ff('0x3'));var moment=require('moment');var BPromise=require(_0x83ff('0x4'));var Mustache=require(_0x83ff('0x5'));var util=require(_0x83ff('0x6'));var path=require(_0x83ff('0x7'));var sox=require(_0x83ff('0x8'));var csv=require('to-csv');var ejs=require(_0x83ff('0x9'));var fs=require('fs');var fs_extra=require(_0x83ff('0xa'));var _=require('lodash');var squel=require(_0x83ff('0xb'));var crypto=require(_0x83ff('0xc'));var jsforce=require(_0x83ff('0xd'));var deskjs=require(_0x83ff('0xe'));var toCsv=require('to-csv');var querystring=require(_0x83ff('0xf'));var Papa=require(_0x83ff('0x10'));var Redis=require(_0x83ff('0x11'));var authService=require(_0x83ff('0x12'));var qs=require(_0x83ff('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x83ff('0x14'));var logger=require('../../config/logger')('api');var utils=require(_0x83ff('0x15'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var integrations=require(_0x83ff('0x16'));function respondWithStatusCode(_0x2ca8f1,_0x428833){_0x428833=_0x428833||0xcc;return function(_0x1ac763){if(_0x1ac763){return _0x2ca8f1[_0x83ff('0x17')](_0x428833);}return _0x2ca8f1['status'](_0x428833)[_0x83ff('0x18')]();};}function respondWithResult(_0x5a4c22,_0x2e8fc9){_0x2e8fc9=_0x2e8fc9||0xc8;return function(_0x10b147){if(_0x10b147){return _0x5a4c22[_0x83ff('0x19')](_0x2e8fc9)[_0x83ff('0x1a')](_0x10b147);}};}function respondWithFilteredResult(_0x5b44e6,_0x4df331){return function(_0x1f8205){if(_0x1f8205){var _0x19f576=typeof _0x4df331[_0x83ff('0x1b')]===_0x83ff('0x1c')&&typeof _0x4df331['limit']===_0x83ff('0x1c');var _0x4fbf85=_0x1f8205[_0x83ff('0x1d')];var _0x149a11=_0x19f576?0x0:_0x4df331[_0x83ff('0x1b')];var _0x5f2188=_0x19f576?_0x1f8205[_0x83ff('0x1d')]:_0x4df331[_0x83ff('0x1b')]+_0x4df331[_0x83ff('0x1e')];var _0x50598e;if(_0x5f2188>=_0x4fbf85){_0x5f2188=_0x4fbf85;_0x50598e=0xc8;}else{_0x50598e=0xce;}_0x5b44e6[_0x83ff('0x19')](_0x50598e);return _0x5b44e6['set'](_0x83ff('0x1f'),_0x149a11+'-'+_0x5f2188+'/'+_0x4fbf85)[_0x83ff('0x1a')](_0x1f8205);}return null;};}function patchUpdates(_0x1e567d){return function(_0xcbd32e){try{jsonpatch['apply'](_0xcbd32e,_0x1e567d,!![]);}catch(_0x2b0279){return BPromise['reject'](_0x2b0279);}return _0xcbd32e[_0x83ff('0x20')]();};}function saveUpdates(_0x48dba2,_0x15d180){return function(_0x29b884){if(_0x29b884){return _0x29b884[_0x83ff('0x21')](_0x48dba2)[_0x83ff('0x22')](function(_0x121db7){return _0x121db7;});}return null;};}function removeEntity(_0x5ae45f,_0x51882c){return function(_0x200180){if(_0x200180){return _0x200180[_0x83ff('0x23')]()['then'](function(){_0x5ae45f[_0x83ff('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x30426d,_0x193f56){return function(_0x19086e){if(!_0x19086e){_0x30426d['sendStatus'](0x194);}return _0x19086e;};}function handleError(_0x546d87,_0x4bcb4a){_0x4bcb4a=_0x4bcb4a||0x1f4;return function(_0x526e93){logger[_0x83ff('0x24')](_0x526e93['stack']);if(_0x526e93[_0x83ff('0x25')]){delete _0x526e93[_0x83ff('0x25')];}_0x546d87[_0x83ff('0x19')](_0x4bcb4a)[_0x83ff('0x26')](_0x526e93);};}exports[_0x83ff('0x27')]=function(_0x2c7b56,_0x3911ec){var _0x1dc58b={},_0x500e16={},_0x3a9cda={'count':0x0,'rows':[]};var _0xbc19b2=_[_0x83ff('0x28')](db[_0x83ff('0x29')][_0x83ff('0x2a')],function(_0x311d6e){return{'name':_0x311d6e['fieldName'],'type':_0x311d6e[_0x83ff('0x2b')]['key']};});_0x500e16[_0x83ff('0x2c')]=_[_0x83ff('0x28')](_0xbc19b2,_0x83ff('0x25'));_0x500e16['query']=_[_0x83ff('0x2d')](_0x2c7b56[_0x83ff('0x2e')]);_0x500e16[_0x83ff('0x2f')]=_[_0x83ff('0x30')](_0x500e16[_0x83ff('0x2c')],_0x500e16[_0x83ff('0x2e')]);_0x1dc58b[_0x83ff('0x31')]=_[_0x83ff('0x30')](_0x500e16[_0x83ff('0x2c')],qs['fields'](_0x2c7b56['query'][_0x83ff('0x32')]));_0x1dc58b[_0x83ff('0x31')]=_0x1dc58b[_0x83ff('0x31')]['length']?_0x1dc58b['attributes']:_0x500e16['model'];if(!_0x2c7b56[_0x83ff('0x2e')][_0x83ff('0x33')](_0x83ff('0x34'))){_0x1dc58b['limit']=qs['limit'](_0x2c7b56[_0x83ff('0x2e')][_0x83ff('0x1e')]);_0x1dc58b[_0x83ff('0x1b')]=qs[_0x83ff('0x1b')](_0x2c7b56[_0x83ff('0x2e')][_0x83ff('0x1b')]);}_0x1dc58b[_0x83ff('0x35')]=qs['sort'](_0x2c7b56['query']['sort']);_0x1dc58b[_0x83ff('0x36')]=qs[_0x83ff('0x2f')](_[_0x83ff('0x37')](_0x2c7b56['query'],_0x500e16[_0x83ff('0x2f')]),_0xbc19b2);if(_0x2c7b56[_0x83ff('0x2e')][_0x83ff('0x38')]){_0x1dc58b[_0x83ff('0x36')]=_[_0x83ff('0x39')](_0x1dc58b[_0x83ff('0x36')],{'$or':_['map'](_0xbc19b2,function(_0x49fc68){if(_0x49fc68[_0x83ff('0x2b')]!==_0x83ff('0x3a')){var _0x432d88={};_0x432d88[_0x49fc68[_0x83ff('0x25')]]={'$like':'%'+_0x2c7b56[_0x83ff('0x2e')][_0x83ff('0x38')]+'%'};return _0x432d88;}})});}_0x1dc58b=_['merge']({},_0x1dc58b,_0x2c7b56[_0x83ff('0x3b')]);var _0x4cf5e7={'where':_0x1dc58b[_0x83ff('0x36')]};return db[_0x83ff('0x29')]['count'](_0x4cf5e7)['then'](function(_0x45eb4f){_0x3a9cda[_0x83ff('0x1d')]=_0x45eb4f;if(_0x2c7b56[_0x83ff('0x2e')][_0x83ff('0x3c')]){_0x1dc58b[_0x83ff('0x3d')]=[{'all':!![]}];}return db['SugarcrmAccount']['findAll'](_0x1dc58b);})[_0x83ff('0x22')](function(_0x1c2782){_0x3a9cda[_0x83ff('0x3e')]=_0x1c2782;return _0x3a9cda;})[_0x83ff('0x22')](respondWithFilteredResult(_0x3911ec,_0x1dc58b))[_0x83ff('0x3f')](handleError(_0x3911ec,null));};exports['show']=function(_0x481c40,_0x4400ec){var _0x5523a6={'raw':![],'where':{'id':_0x481c40['params']['id']}},_0x82478a={};_0x82478a[_0x83ff('0x2c')]=_[_0x83ff('0x2d')](db[_0x83ff('0x29')][_0x83ff('0x2a')]);_0x82478a[_0x83ff('0x2e')]=_[_0x83ff('0x2d')](_0x481c40[_0x83ff('0x2e')]);_0x82478a[_0x83ff('0x2f')]=_[_0x83ff('0x30')](_0x82478a[_0x83ff('0x2c')],_0x82478a[_0x83ff('0x2e')]);_0x5523a6['attributes']=_[_0x83ff('0x30')](_0x82478a['model'],qs['fields'](_0x481c40[_0x83ff('0x2e')][_0x83ff('0x32')]));_0x5523a6['attributes']=_0x5523a6[_0x83ff('0x31')][_0x83ff('0x40')]?_0x5523a6[_0x83ff('0x31')]:_0x82478a['model'];if(_0x481c40[_0x83ff('0x2e')]['includeAll']){_0x5523a6['include']=[{'all':!![]}];}_0x5523a6=_[_0x83ff('0x39')]({},_0x5523a6,_0x481c40[_0x83ff('0x3b')]);return db['SugarcrmAccount'][_0x83ff('0x41')](_0x5523a6)[_0x83ff('0x22')](handleEntityNotFound(_0x4400ec,null))[_0x83ff('0x22')](respondWithResult(_0x4400ec,null))['catch'](handleError(_0x4400ec,null));};exports[_0x83ff('0x42')]=function(_0x2bc4aa,_0x9e91ce){return db[_0x83ff('0x29')]['create'](_0x2bc4aa[_0x83ff('0x43')],{})[_0x83ff('0x22')](respondWithResult(_0x9e91ce,0xc9))[_0x83ff('0x3f')](handleError(_0x9e91ce,null));};exports[_0x83ff('0x21')]=function(_0xb2de24,_0x474987){if(_0xb2de24[_0x83ff('0x43')]['id']){delete _0xb2de24[_0x83ff('0x43')]['id'];}return db[_0x83ff('0x29')][_0x83ff('0x41')]({'where':{'id':_0xb2de24[_0x83ff('0x44')]['id']}})[_0x83ff('0x22')](handleEntityNotFound(_0x474987,null))[_0x83ff('0x22')](saveUpdates(_0xb2de24[_0x83ff('0x43')],null))[_0x83ff('0x22')](respondWithResult(_0x474987,null))[_0x83ff('0x3f')](handleError(_0x474987,null));};exports[_0x83ff('0x23')]=function(_0x1827b3,_0x326f41){return db['SugarcrmAccount']['find']({'where':{'id':_0x1827b3[_0x83ff('0x44')]['id']}})[_0x83ff('0x22')](handleEntityNotFound(_0x326f41,null))['then'](removeEntity(_0x326f41,null))[_0x83ff('0x3f')](handleError(_0x326f41,null));};exports[_0x83ff('0x45')]=function(_0x5738e7,_0x1e87a7,_0x9644d){var _0x42c771={};var _0x5dca5e={};var _0xd89752;var _0x25cc73;return db[_0x83ff('0x29')][_0x83ff('0x46')]({'where':{'id':_0x5738e7[_0x83ff('0x44')]['id']}})[_0x83ff('0x22')](handleEntityNotFound(_0x1e87a7,null))[_0x83ff('0x22')](function(_0x4c0281){if(_0x4c0281){_0xd89752=_0x4c0281;_0x5dca5e[_0x83ff('0x2c')]=_['keys'](db['SugarcrmConfiguration'][_0x83ff('0x2a')]);_0x5dca5e[_0x83ff('0x2e')]=_[_0x83ff('0x2d')](_0x5738e7[_0x83ff('0x2e')]);_0x5dca5e[_0x83ff('0x2f')]=_[_0x83ff('0x30')](_0x5dca5e[_0x83ff('0x2c')],_0x5dca5e['query']);_0x42c771[_0x83ff('0x31')]=_[_0x83ff('0x30')](_0x5dca5e['model'],qs['fields'](_0x5738e7[_0x83ff('0x2e')]['fields']));_0x42c771[_0x83ff('0x31')]=_0x42c771[_0x83ff('0x31')]['length']?_0x42c771['attributes']:_0x5dca5e['model'];_0x42c771[_0x83ff('0x35')]=qs[_0x83ff('0x47')](_0x5738e7[_0x83ff('0x2e')][_0x83ff('0x47')]);_0x42c771[_0x83ff('0x36')]=qs['filters'](_['pick'](_0x5738e7[_0x83ff('0x2e')],_0x5dca5e['filters']));if(_0x5738e7['query'][_0x83ff('0x38')]){_0x42c771['where']=_[_0x83ff('0x39')](_0x42c771[_0x83ff('0x36')],{'$or':_['map'](_0x42c771[_0x83ff('0x31')],function(_0x12095c){var _0x4cd922={};_0x4cd922[_0x12095c]={'$like':'%'+_0x5738e7[_0x83ff('0x2e')][_0x83ff('0x38')]+'%'};return _0x4cd922;})});}_0x42c771=_[_0x83ff('0x39')]({},_0x42c771,_0x5738e7[_0x83ff('0x3b')]);return _0xd89752[_0x83ff('0x45')](_0x42c771);}})[_0x83ff('0x22')](function(_0x2fdc50){if(_0x2fdc50){_0x25cc73=_0x2fdc50[_0x83ff('0x40')];if(!_0x5738e7['query']['hasOwnProperty'](_0x83ff('0x34'))){_0x42c771[_0x83ff('0x1e')]=qs[_0x83ff('0x1e')](_0x5738e7[_0x83ff('0x2e')][_0x83ff('0x1e')]);_0x42c771[_0x83ff('0x1b')]=qs[_0x83ff('0x1b')](_0x5738e7[_0x83ff('0x2e')][_0x83ff('0x1b')]);}return _0xd89752['getConfigurations'](_0x42c771);}})['then'](function(_0x331e54){if(_0x331e54){return _0x331e54?{'count':_0x25cc73,'rows':_0x331e54}:null;}})[_0x83ff('0x22')](respondWithResult(_0x1e87a7,null))[_0x83ff('0x3f')](handleError(_0x1e87a7,null));};exports[_0x83ff('0x48')]=function(_0x19b108,_0x471e8b,_0x436afd){if(_0x19b108[_0x83ff('0x43')]['id']){delete _0x19b108[_0x83ff('0x43')]['id'];}return db[_0x83ff('0x29')][_0x83ff('0x46')]({'where':{'id':_0x19b108['params']['id']}})[_0x83ff('0x22')](handleEntityNotFound(_0x471e8b,null))[_0x83ff('0x22')](function(_0x4da1ff){if(_0x4da1ff){_0x19b108['body']['AccountId']=_0x4da1ff['id'];_0x19b108[_0x83ff('0x43')][_0x83ff('0x49')]=integrations['getSubjects'](_0x19b108['body'][_0x83ff('0x4a')],_0x19b108[_0x83ff('0x43')][_0x83ff('0x2b')]);_0x19b108['body'][_0x83ff('0x4b')]=integrations[_0x83ff('0x4c')](_0x19b108[_0x83ff('0x43')][_0x83ff('0x4a')],_0x19b108[_0x83ff('0x43')][_0x83ff('0x2b')]);return db[_0x83ff('0x4d')][_0x83ff('0x42')](_0x19b108[_0x83ff('0x43')],{'include':[{'model':db['SugarcrmField'],'as':'Subjects'},{'model':db[_0x83ff('0x4e')],'as':_0x83ff('0x4b')}]});}return null;})['then'](respondWithResult(_0x471e8b,null))[_0x83ff('0x3f')](handleError(_0x471e8b,null));};exports['getFields']=function(_0x20fffb,_0x38b562,_0x18ef89){var _0x400b5c='';var _0x5e4add=['id',_0x83ff('0x25'),_0x83ff('0x4f'),'created_by',_0x83ff('0x50'),'date_start',_0x83ff('0x51'),_0x83ff('0x52'),_0x83ff('0x53'),_0x83ff('0x54'),_0x83ff('0x55'),_0x83ff('0x56')];return db[_0x83ff('0x29')]['findOne']({'where':{'id':_0x20fffb['params']['id']},'attributes':['id','username','password',_0x83ff('0x57')]})[_0x83ff('0x22')](handleEntityNotFound(_0x38b562,null))['then'](function(_0x300f08){if(_0x300f08){_0x400b5c=_0x300f08[_0x83ff('0x57')];var _0x256552=_0x400b5c['slice'](-0x1);if(_0x256552==='/'){_0x400b5c=_0x400b5c[_0x83ff('0x58')](0x0,_0x400b5c[_0x83ff('0x59')](_0x256552));}return rp({'method':_0x83ff('0x5a'),'uri':util[_0x83ff('0x5b')](_0x83ff('0x5c'),_0x400b5c,'/service/v4_1/rest.php'),'json':!![],'form':{'method':_0x83ff('0x5d'),'input_type':'JSON','response_type':_0x83ff('0x5e'),'rest_data':JSON[_0x83ff('0x5f')]({'user_auth':{'user_name':_0x300f08['username'],'password':_0x300f08[_0x83ff('0x60')],'encryption':'PLAIN'},'application':'xCALLY\x20Motion\x20Integration'})}});}})[_0x83ff('0x22')](function(_0xe54d1d){if(_0xe54d1d&&_0xe54d1d[_0x83ff('0x25')]!==_0x83ff('0x61')&&_0xe54d1d[_0x83ff('0x25')]!==_0x83ff('0x62')){return rp({'method':'POST','uri':util['format'](_0x83ff('0x5c'),_0x400b5c,_0x83ff('0x63')),'json':!![],'form':{'method':_0x83ff('0x64'),'input_type':_0x83ff('0x5e'),'response_type':_0x83ff('0x5e'),'rest_data':JSON[_0x83ff('0x5f')]({'session':_0xe54d1d['id'],'module_name':_0x83ff('0x65')})}})[_0x83ff('0x22')](function(_0x5905a7){if(_0x5905a7){var _0x26d7d4=_[_0x83ff('0x66')](_0x5905a7[_0x83ff('0x67')]);_[_0x83ff('0x68')](_0x26d7d4,function(_0x5d3dba){return _0x5e4add[_0x83ff('0x69')](_0x5d3dba[_0x83ff('0x25')]);});return{'count':_0x26d7d4[_0x83ff('0x40')],'rows':_[_0x83ff('0x28')](_0x26d7d4,function(_0x26efe6){return{'id':_0x26efe6['name'],'name':_0x26efe6[_0x83ff('0x6a')],'custom':_[_0x83ff('0x6b')](_0x26efe6[_0x83ff('0x25')],'_c')?!![]:![],'options':_0x26efe6['options']?_[_0x83ff('0x28')](_[_0x83ff('0x66')](_0x26efe6[_0x83ff('0x3b')]),function(_0x590101){return{'name':_0x590101[_0x83ff('0x6c')],'value':_0x590101[_0x83ff('0x25')]};}):[]};})};}})[_0x83ff('0x22')](respondWithResult(_0x38b562,null))[_0x83ff('0x3f')](function(_0x4bb662){var _0x18bbcc=_0x20fffb[_0x83ff('0x2e')][_0x83ff('0x6d')]?0x1f4:_0x4bb662[_0x83ff('0x6e')]||0x1f4;logger['error'](_0x83ff('0x6f'),_0x83ff('0x70'),_0x18bbcc,JSON['stringify'](_0x4bb662));delete _0x4bb662[_0x83ff('0x25')];if(_0x18bbcc===0x191){_0x18bbcc=0x190;}_0x38b562['status'](_0x18bbcc)[_0x83ff('0x26')](_0x20fffb[_0x83ff('0x2e')]['test']?{'message':'Wrong\x20credentials','statusCode':_0x4bb662[_0x83ff('0x6e')]}:_0x4bb662);});}else{var _0x47577c=0x1f4;_0x38b562['status'](_0x47577c)[_0x83ff('0x26')]({'message':_0x83ff('0x71'),'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