51cd9a50852beb45efa3837a85340c22d8c0738c
[motion-next.git] / server / api / intSalesforceAccount / intSalesforceAccount.controller.js
1 const a281_0x3f61=['custom','then','statusCode','ticketType','SuppliedCompany','options','../../components/integrations/configuration','Content-Range','query','remove','fields','lastIndexOf','limit','status','channel','value','login','isNil','findOne','concat','Case','rawAttributes','findAll','merge','index','update','count','clientId','CallDurationInSeconds','label','error','clientSecret','VIRTUAL','nolimit','model','Type','map','create','SalesforceAccount','body','../../config/logger','getFields,\x20%s,\x20%s,\x20%s','show','getSubjects','keys','Origin','destroy','set','Connection','username','SuppliedName','catch','includes','like','attributes','getFields','sobject','AccountId','name','filters','boolean','where','rows','stringify','CallDisposition','password','end','Status','api','describe','pick','Descriptions','params','sort','type','key','jsforce','SalesforceField','intersection','undefined','Wrong\x20credentials','getConfigurations','filter','SalesforceConfiguration','sendStatus','fieldName','json','offset','False','Priority','test','order','Subjects','picklistValues','CallObject','length','remoteUri','CallType'];(function(_0x47a2fd,_0x3f617d){const _0x9dfb6f=function(_0x129d66){while(--_0x129d66){_0x47a2fd['push'](_0x47a2fd['shift']());}};_0x9dfb6f(++_0x3f617d);}(a281_0x3f61,0x15b));const a281_0x9dfb=function(_0x47a2fd,_0x3f617d){_0x47a2fd=_0x47a2fd-0x0;let _0x9dfb6f=a281_0x3f61[_0x47a2fd];return _0x9dfb6f;};const _0x446e5c=a281_0x9dfb;'use strict';const _=require('lodash'),jsforce=require(_0x446e5c('0x17')),qs=require('../../components/parsers/qs'),logger=require(_0x446e5c('0x55'))(_0x446e5c('0xf')),db=require('../../mysqldb')['db'],{Op}=require('sequelize'),integrations=require(_0x446e5c('0x33'));function respondWithResult(_0x129d66,_0x2eea5c){return _0x2eea5c=_0x2eea5c||0xc8,function(_0x341b64){const _0x1b462f=a281_0x9dfb;if(_0x341b64)return _0x129d66[_0x1b462f('0x3a')](_0x2eea5c)[_0x1b462f('0x21')](_0x341b64);};}function respondWithFilteredResult(_0x2375db,_0x45797a){return function(_0x5ac81c){const _0x33f824=a281_0x9dfb;if(_0x5ac81c){const _0x4a77bd=_0x5ac81c['count'],_0x394b8a=_0x45797a[_0x33f824('0x22')];let _0x4d76cd=_0x45797a[_0x33f824('0x22')]+_0x45797a[_0x33f824('0x39')],_0x54b317;return _0x4d76cd>=_0x4a77bd?(_0x4d76cd=_0x4a77bd,_0x54b317=0xc8):_0x54b317=0xce,_0x2375db[_0x33f824('0x3a')](_0x54b317),_0x2375db[_0x33f824('0x5c')](_0x33f824('0x34'),_0x394b8a+'-'+_0x4d76cd+'/'+_0x4a77bd)[_0x33f824('0x21')](_0x5ac81c);}return null;};}function saveUpdates(_0x449e7d){return function(_0x4d769d){const _0x3414b6=a281_0x9dfb;if(_0x4d769d)return _0x4d769d['update'](_0x449e7d)[_0x3414b6('0x2e')](function(_0x53ee19){return _0x53ee19;});return null;};}function removeEntity(_0x4f8f5c){return function(_0x1db51d){const _0x1e2378=a281_0x9dfb;if(_0x1db51d)return _0x1db51d['destroy']()[_0x1e2378('0x2e')](function(){const _0x5b1e11=_0x1e2378;_0x4f8f5c['status'](0xcc)[_0x5b1e11('0xd')]();});};}function handleEntityNotFound(_0x5aeb37){return function(_0x2944df){const _0x592c44=a281_0x9dfb;return!_0x2944df&&_0x5aeb37[_0x592c44('0x1f')](0x194),_0x2944df;};}function handleError(_0x13b260,_0x3711){return _0x3711=_0x3711||0x1f4,function(_0x3922c6){const _0xf7cbd1=a281_0x9dfb;logger['error'](_0x3922c6['stack']),_0x3922c6[_0xf7cbd1('0x5')]&&delete _0x3922c6['name'],_0x13b260['status'](_0x3711)['send'](_0x3922c6);};}exports[_0x446e5c('0x45')]=function(_0x2a7a7c,_0x252314){const _0x49fcf4=_0x446e5c;let _0x557553={};const _0x320a12={},_0x4fdefa={'count':0x0,'rows':[]},_0x1cbaa1=_[_0x49fcf4('0x51')](db[_0x49fcf4('0x53')][_0x49fcf4('0x42')],function(_0x4d049f){const _0x31b6ea=_0x49fcf4;return{'name':_0x4d049f[_0x31b6ea('0x20')],'type':_0x4d049f['type'][_0x31b6ea('0x16')]};});_0x320a12[_0x49fcf4('0x4f')]=_[_0x49fcf4('0x51')](_0x1cbaa1,_0x49fcf4('0x5')),_0x320a12[_0x49fcf4('0x35')]=_[_0x49fcf4('0x59')](_0x2a7a7c[_0x49fcf4('0x35')]),_0x320a12['filters']=_[_0x49fcf4('0x19')](_0x320a12[_0x49fcf4('0x4f')],_0x320a12[_0x49fcf4('0x35')]),_0x557553[_0x49fcf4('0x1')]=_[_0x49fcf4('0x19')](_0x320a12['model'],qs['fields'](_0x2a7a7c[_0x49fcf4('0x35')][_0x49fcf4('0x37')])),_0x557553['attributes']=_0x557553[_0x49fcf4('0x1')]['length']?_0x557553[_0x49fcf4('0x1')]:_0x320a12[_0x49fcf4('0x4f')];typeof _0x2a7a7c[_0x49fcf4('0x35')]['nolimit']==='undefined'&&(_0x557553[_0x49fcf4('0x39')]=qs[_0x49fcf4('0x39')](_0x2a7a7c[_0x49fcf4('0x35')][_0x49fcf4('0x39')]),_0x557553[_0x49fcf4('0x22')]=qs[_0x49fcf4('0x22')](_0x2a7a7c[_0x49fcf4('0x35')][_0x49fcf4('0x22')]));_0x557553[_0x49fcf4('0x26')]=qs[_0x49fcf4('0x14')](_0x2a7a7c[_0x49fcf4('0x35')][_0x49fcf4('0x14')]),_0x557553[_0x49fcf4('0x8')]=qs[_0x49fcf4('0x6')](_['pick'](_0x2a7a7c['query'],_0x320a12[_0x49fcf4('0x6')]),_0x1cbaa1);_0x2a7a7c[_0x49fcf4('0x35')]['filter']&&(_0x557553[_0x49fcf4('0x8')]=_['merge'](_0x557553[_0x49fcf4('0x8')],{[Op['or']]:_[_0x49fcf4('0x51')](_0x1cbaa1,function(_0xcbeba5){const _0x5aad4a=_0x49fcf4;if(_0xcbeba5[_0x5aad4a('0x15')]!==_0x5aad4a('0x4d')){const _0x109f87={};return _0x109f87[_0xcbeba5[_0x5aad4a('0x5')]]={[Op['like']]:'%'+_0x2a7a7c['query']['filter']+'%'},_0x109f87;}})}));_0x557553=_[_0x49fcf4('0x44')]({},_0x557553,_0x2a7a7c[_0x49fcf4('0x32')]);const _0x25d0d1={'where':_0x557553[_0x49fcf4('0x8')]};return db[_0x49fcf4('0x53')][_0x49fcf4('0x47')](_0x25d0d1)[_0x49fcf4('0x2e')](function(_0x5c8bb2){const _0x5b77ec=_0x49fcf4;return _0x4fdefa[_0x5b77ec('0x47')]=_0x5c8bb2,_0x2a7a7c[_0x5b77ec('0x35')]['includeAll']&&(_0x557553['include']=[{'all':!![]}]),db[_0x5b77ec('0x53')][_0x5b77ec('0x43')](_0x557553);})[_0x49fcf4('0x2e')](function(_0x305f52){const _0x58c593=_0x49fcf4;return _0x4fdefa[_0x58c593('0x9')]=_0x305f52,_0x4fdefa;})[_0x49fcf4('0x2e')](respondWithFilteredResult(_0x252314,_0x557553))[_0x49fcf4('0x60')](handleError(_0x252314,null));},exports[_0x446e5c('0x57')]=function(_0x3a79bb,_0x3184c6){const _0x1ca8b0=_0x446e5c;let _0x3ec581={'raw':![],'where':{'id':_0x3a79bb[_0x1ca8b0('0x13')]['id']}};const _0x541bda={};return _0x541bda[_0x1ca8b0('0x4f')]=_[_0x1ca8b0('0x59')](db[_0x1ca8b0('0x53')][_0x1ca8b0('0x42')]),_0x541bda[_0x1ca8b0('0x35')]=_[_0x1ca8b0('0x59')](_0x3a79bb[_0x1ca8b0('0x35')]),_0x541bda[_0x1ca8b0('0x6')]=_['intersection'](_0x541bda[_0x1ca8b0('0x4f')],_0x541bda[_0x1ca8b0('0x35')]),_0x3ec581[_0x1ca8b0('0x1')]=_[_0x1ca8b0('0x19')](_0x541bda['model'],qs[_0x1ca8b0('0x37')](_0x3a79bb['query'][_0x1ca8b0('0x37')])),_0x3ec581['attributes']=_0x3ec581[_0x1ca8b0('0x1')][_0x1ca8b0('0x2a')]?_0x3ec581[_0x1ca8b0('0x1')]:_0x541bda[_0x1ca8b0('0x4f')],_0x3a79bb[_0x1ca8b0('0x35')]['includeAll']&&(_0x3ec581['include']=[{'all':!![]}]),_0x3ec581=_[_0x1ca8b0('0x44')]({},_0x3ec581,_0x3a79bb[_0x1ca8b0('0x32')]),db[_0x1ca8b0('0x53')][_0x1ca8b0('0x3f')](_0x3ec581)['then'](handleEntityNotFound(_0x3184c6,null))[_0x1ca8b0('0x2e')](respondWithResult(_0x3184c6,null))[_0x1ca8b0('0x60')](handleError(_0x3184c6,null));},exports[_0x446e5c('0x52')]=function(_0x10d590,_0x3d38fd){const _0xa50b8c=_0x446e5c;return db[_0xa50b8c('0x53')][_0xa50b8c('0x52')](_0x10d590[_0xa50b8c('0x54')],{})[_0xa50b8c('0x2e')](respondWithResult(_0x3d38fd,0xc9))[_0xa50b8c('0x60')](handleError(_0x3d38fd,null));},exports[_0x446e5c('0x46')]=function(_0x455e7c,_0x4a1c61){const _0x2f7b83=_0x446e5c;return _0x455e7c[_0x2f7b83('0x54')]['id']&&delete _0x455e7c[_0x2f7b83('0x54')]['id'],db[_0x2f7b83('0x53')][_0x2f7b83('0x3f')]({'where':{'id':_0x455e7c[_0x2f7b83('0x13')]['id']}})[_0x2f7b83('0x2e')](handleEntityNotFound(_0x4a1c61,null))[_0x2f7b83('0x2e')](saveUpdates(_0x455e7c[_0x2f7b83('0x54')],null))['then'](respondWithResult(_0x4a1c61,null))[_0x2f7b83('0x60')](handleError(_0x4a1c61,null));},exports[_0x446e5c('0x5b')]=function(_0x7bc57,_0x5d1d20){const _0x2906cc=_0x446e5c;return db['SalesforceAccount'][_0x2906cc('0x3f')]({'where':{'id':_0x7bc57[_0x2906cc('0x13')]['id']}})[_0x2906cc('0x2e')](handleEntityNotFound(_0x5d1d20,null))['then'](removeEntity(_0x5d1d20,null))[_0x2906cc('0x60')](handleError(_0x5d1d20,null));},exports[_0x446e5c('0x1c')]=function(_0x4e3123,_0x520ef5){const _0x2314a0=_0x446e5c;let _0x2d1a1d={};const _0x3e35c9={};let _0x115770,_0x1fc2d8;return db[_0x2314a0('0x53')][_0x2314a0('0x3f')]({'where':{'id':_0x4e3123[_0x2314a0('0x13')]['id']}})[_0x2314a0('0x2e')](handleEntityNotFound(_0x520ef5,null))['then'](function(_0x2fd4bd){const _0x5f1385=_0x2314a0;if(_0x2fd4bd)return _0x115770=_0x2fd4bd,_0x3e35c9[_0x5f1385('0x4f')]=_[_0x5f1385('0x59')](db[_0x5f1385('0x1e')]['rawAttributes']),_0x3e35c9[_0x5f1385('0x35')]=_[_0x5f1385('0x59')](_0x4e3123[_0x5f1385('0x35')]),_0x3e35c9['filters']=_['intersection'](_0x3e35c9[_0x5f1385('0x4f')],_0x3e35c9[_0x5f1385('0x35')]),_0x2d1a1d[_0x5f1385('0x1')]=_[_0x5f1385('0x19')](_0x3e35c9['model'],qs[_0x5f1385('0x37')](_0x4e3123[_0x5f1385('0x35')]['fields'])),_0x2d1a1d['attributes']=_0x2d1a1d[_0x5f1385('0x1')]['length']?_0x2d1a1d[_0x5f1385('0x1')]:_0x3e35c9[_0x5f1385('0x4f')],_0x2d1a1d[_0x5f1385('0x26')]=qs[_0x5f1385('0x14')](_0x4e3123[_0x5f1385('0x35')][_0x5f1385('0x14')]),_0x2d1a1d[_0x5f1385('0x8')]=qs['filters'](_[_0x5f1385('0x11')](_0x4e3123[_0x5f1385('0x35')],_0x3e35c9[_0x5f1385('0x6')])),_0x4e3123[_0x5f1385('0x35')][_0x5f1385('0x1d')]&&(_0x2d1a1d['where']=_[_0x5f1385('0x44')](_0x2d1a1d[_0x5f1385('0x8')],{[Op['or']]:_[_0x5f1385('0x51')](_0x2d1a1d[_0x5f1385('0x1')],function(_0xbfa715){const _0x1cbe24=_0x5f1385,_0x911c7e={};return _0x911c7e[_0xbfa715]={[Op[_0x1cbe24('0x0')]]:'%'+_0x4e3123['query']['filter']+'%'},_0x911c7e;})})),_0x2d1a1d=_['merge']({},_0x2d1a1d,_0x4e3123[_0x5f1385('0x32')]),_0x115770[_0x5f1385('0x1c')](_0x2d1a1d);})['then'](function(_0x27f220){const _0x16912a=_0x2314a0;if(_0x27f220)return _0x1fc2d8=_0x27f220[_0x16912a('0x2a')],typeof _0x4e3123[_0x16912a('0x35')][_0x16912a('0x4e')]===_0x16912a('0x1a')&&(_0x2d1a1d[_0x16912a('0x39')]=qs[_0x16912a('0x39')](_0x4e3123[_0x16912a('0x35')][_0x16912a('0x39')]),_0x2d1a1d[_0x16912a('0x22')]=qs[_0x16912a('0x22')](_0x4e3123[_0x16912a('0x35')][_0x16912a('0x22')])),_0x115770['getConfigurations'](_0x2d1a1d);})['then'](function(_0x53ce7c){if(_0x53ce7c)return _0x53ce7c?{'count':_0x1fc2d8,'rows':_0x53ce7c}:null;})[_0x2314a0('0x2e')](respondWithResult(_0x520ef5,null))[_0x2314a0('0x60')](handleError(_0x520ef5,null));},exports['addConfiguration']=function(_0x8d66b5,_0x3ef94d){const _0x395b14=_0x446e5c;return _0x8d66b5[_0x395b14('0x54')]['id']&&delete _0x8d66b5[_0x395b14('0x54')]['id'],db[_0x395b14('0x53')][_0x395b14('0x3f')]({'where':{'id':_0x8d66b5['params']['id']}})['then'](handleEntityNotFound(_0x3ef94d,null))['then'](function(_0x792763){const _0x53dd2e=_0x395b14;if(_0x792763)return _0x8d66b5[_0x53dd2e('0x54')][_0x53dd2e('0x4')]=_0x792763['id'],_0x8d66b5[_0x53dd2e('0x54')]['Subjects']=integrations[_0x53dd2e('0x58')](_0x8d66b5[_0x53dd2e('0x54')][_0x53dd2e('0x3b')],_0x8d66b5[_0x53dd2e('0x54')][_0x53dd2e('0x15')]),_0x8d66b5[_0x53dd2e('0x54')][_0x53dd2e('0x12')]=integrations['getDescriptions'](_0x8d66b5[_0x53dd2e('0x54')][_0x53dd2e('0x3b')],_0x8d66b5[_0x53dd2e('0x54')][_0x53dd2e('0x15')]),db[_0x53dd2e('0x1e')]['create'](_0x8d66b5[_0x53dd2e('0x54')],{'include':[{'model':db[_0x53dd2e('0x18')],'as':_0x53dd2e('0x27')},{'model':db['SalesforceField'],'as':'Descriptions'}]});return null;})['then'](respondWithResult(_0x3ef94d,null))['catch'](handleError(_0x3ef94d,null));},exports['getFields']=function(_0x53348f,_0x28125e){const _0x566dea=_0x446e5c;let _0x41d8b9,_0x13f803='',_0x3d2213='Task';return db['SalesforceAccount'][_0x566dea('0x3f')]({'where':{'id':_0x53348f[_0x566dea('0x13')]['id']},'attributes':['id',_0x566dea('0x2b'),_0x566dea('0x48'),_0x566dea('0x4c'),_0x566dea('0x5e'),_0x566dea('0xc'),'securityToken']})[_0x566dea('0x2e')](handleEntityNotFound(_0x28125e,null))[_0x566dea('0x2e')](function(_0xc34df5){const _0x148007=_0x566dea;if(_0xc34df5){_0x13f803=_0xc34df5[_0x148007('0x2b')];const _0x1e6b6b=_0x13f803['slice'](-0x1);return _0x1e6b6b==='/'&&(_0x13f803=_0x13f803['substring'](0x0,_0x13f803[_0x148007('0x38')](_0x1e6b6b))),_0x41d8b9=new jsforce[(_0x148007('0x5d'))]({'oauth2':{'loginUrl':_0x13f803,'clientId':_0xc34df5[_0x148007('0x48')],'clientSecret':_0xc34df5[_0x148007('0x4c')]}}),_0x41d8b9[_0x148007('0x3d')](_0xc34df5[_0x148007('0x5e')],_0xc34df5[_0x148007('0xc')][_0x148007('0x40')](_0xc34df5['securityToken']));}})[_0x566dea('0x2e')](function(_0x5c4dc8){const _0x4ca802=_0x566dea;if(_0x5c4dc8)return!_[_0x4ca802('0x3e')](_0x53348f[_0x4ca802('0x35')]['ticketType'])&&(_0x3d2213=_0x53348f['query']['ticketType']),_0x41d8b9[_0x4ca802('0x3')](_0x3d2213)[_0x4ca802('0x10')]();})[_0x566dea('0x2e')](function(_0x56528f){const _0x1a760d=_0x566dea;let _0x447772=[_0x1a760d('0xb'),_0x1a760d('0x49'),_0x1a760d('0x29'),_0x1a760d('0x2c'),'IsArchived',_0x1a760d('0x24'),_0x1a760d('0xe'),_0x1a760d('0x50')];!_['isNil'](_0x53348f[_0x1a760d('0x35')][_0x1a760d('0x30')])&&_0x53348f['query'][_0x1a760d('0x30')]===_0x1a760d('0x41')&&(_0x447772=[_0x1a760d('0x50'),_0x1a760d('0x5a'),'Reason','Status','Priority','IsEscalated',_0x1a760d('0x5f'),_0x1a760d('0x31')]);if(_0x56528f)return _[_0x1a760d('0x36')](_0x56528f[_0x1a760d('0x37')],function(_0x571045){const _0x34e522=_0x1a760d;return _0x571045[_0x34e522('0x2d')]===![]&&!_0x447772[_0x34e522('0x61')](_0x571045[_0x34e522('0x5')]);}),{'count':_0x56528f[_0x1a760d('0x37')][_0x1a760d('0x2a')],'rows':_[_0x1a760d('0x51')](_0x56528f[_0x1a760d('0x37')],function(_0x43ad6d){const _0x5b9c40=_0x1a760d;return{'id':_0x43ad6d[_0x5b9c40('0x5')],'name':_0x43ad6d[_0x5b9c40('0x4a')],'custom':_0x43ad6d[_0x5b9c40('0x2d')],'options':_0x43ad6d[_0x5b9c40('0x28')]['length']>0x0?_[_0x5b9c40('0x51')](_0x43ad6d[_0x5b9c40('0x28')],function(_0x4d9495){const _0xa8ea65=_0x5b9c40;return{'name':_0x4d9495[_0xa8ea65('0x4a')],'value':_0x4d9495[_0xa8ea65('0x3c')]};}):_0x43ad6d[_0x5b9c40('0x15')]==_0x5b9c40('0x7')?[{'name':'True','value':'true'},{'name':_0x5b9c40('0x23'),'value':'false'}]:[]};})};})[_0x566dea('0x2e')](respondWithResult(_0x28125e,null))[_0x566dea('0x60')](function(_0x30e843){const _0x3ca9c2=_0x566dea;let _0x36aedb=_0x53348f[_0x3ca9c2('0x35')]['test']?0x1f4:_0x30e843[_0x3ca9c2('0x2f')]||0x1f4;logger[_0x3ca9c2('0x4b')](_0x3ca9c2('0x56'),_0x3ca9c2('0x2'),_0x36aedb,JSON[_0x3ca9c2('0xa')](_0x30e843)),delete _0x30e843[_0x3ca9c2('0x5')],_0x36aedb===0x191&&(_0x36aedb=0x190),_0x28125e[_0x3ca9c2('0x3a')](_0x36aedb)['send'](_0x53348f[_0x3ca9c2('0x35')][_0x3ca9c2('0x25')]?{'message':_0x3ca9c2('0x1b'),'statusCode':_0x30e843['statusCode']}:_0x30e843);});};