Built motion from commit 82a371561bcdbc7605c801e5e414f4032ba9e7ad. Version 3.0.0...
[motion-next.git] / server / api / intSalesforceAccount / intSalesforceAccount.controller.js
1 const a281_0xda6a=['getDescriptions','keys','error','params','lodash','SalesforceAccount','true','SalesforceConfiguration','../../components/integrations/configuration','ticketType','picklistValues','Status','Subjects','CallDurationInSeconds','create','Wrong\x20credentials','lastIndexOf','api','name','sequelize','CallObject','order','CallDisposition','type','clientSecret','count','describe','includeAll','key','sort','catch','false','limit','False','SuppliedCompany','Origin','sobject','getFields,\x20%s,\x20%s,\x20%s','IsEscalated','Task','rawAttributes','attributes','Content-Range','findOne','intersection','addConfiguration','model','destroy','pick','like','value','clientId','Descriptions','body','CallType','getSubjects','update','filters','login','json','slice','length','substring','options','VIRTUAL','offset','remove','end','statusCode','getConfigurations','where','nolimit','IsArchived','status','SuppliedName','Type','stringify','undefined','Case','map','test','sendStatus','password','boolean','username','filter','Connection','stack','fields','concat','merge','custom','then','query','Reason','channel','isNil','getFields','Priority','include','securityToken','remoteUri','jsforce','AccountId','fieldName'];(function(_0x58d87c,_0xda6a91){const _0x290ab0=function(_0x4fdfba){while(--_0x4fdfba){_0x58d87c['push'](_0x58d87c['shift']());}};_0x290ab0(++_0xda6a91);}(a281_0xda6a,0x16d));const a281_0x290a=function(_0x58d87c,_0xda6a91){_0x58d87c=_0x58d87c-0x0;let _0x290ab0=a281_0xda6a[_0x58d87c];return _0x290ab0;};const _0x218e38=a281_0x290a;'use strict';const _=require(_0x218e38('0x3b')),jsforce=require(_0x218e38('0x34')),qs=require('../../components/parsers/qs'),logger=require('../../config/logger')(_0x218e38('0x48')),db=require('../../mysqldb')['db'],{Op}=require(_0x218e38('0x4a')),integrations=require(_0x218e38('0x3f'));function respondWithResult(_0x4fdfba,_0x379b3c){return _0x379b3c=_0x379b3c||0xc8,function(_0x45d29a){const _0x2fa56c=a281_0x290a;if(_0x45d29a)return _0x4fdfba['status'](_0x379b3c)[_0x2fa56c('0x9')](_0x45d29a);};}function respondWithFilteredResult(_0x22b93a,_0x35dc20){return function(_0x43b6bd){const _0xa03132=a281_0x290a;if(_0x43b6bd){const _0x320f00=_0x43b6bd['count'],_0x2be8b0=_0x35dc20[_0xa03132('0xf')];let _0x163d20=_0x35dc20[_0xa03132('0xf')]+_0x35dc20[_0xa03132('0x57')],_0x477104;return _0x163d20>=_0x320f00?(_0x163d20=_0x320f00,_0x477104=0xc8):_0x477104=0xce,_0x22b93a[_0xa03132('0x17')](_0x477104),_0x22b93a['set'](_0xa03132('0x61'),_0x2be8b0+'-'+_0x163d20+'/'+_0x320f00)[_0xa03132('0x9')](_0x43b6bd);}return null;};}function saveUpdates(_0x56602c){return function(_0x49f8e8){const _0x407bff=a281_0x290a;if(_0x49f8e8)return _0x49f8e8[_0x407bff('0x6')](_0x56602c)['then'](function(_0x312878){return _0x312878;});return null;};}function removeEntity(_0x3da6ac){return function(_0x2c815c){const _0x59621f=a281_0x290a;if(_0x2c815c)return _0x2c815c[_0x59621f('0x66')]()[_0x59621f('0x2a')](function(){const _0x2cae22=_0x59621f;_0x3da6ac[_0x2cae22('0x17')](0xcc)[_0x2cae22('0x11')]();});};}function handleEntityNotFound(_0x1227f7){return function(_0x51427d){const _0x2535af=a281_0x290a;return!_0x51427d&&_0x1227f7[_0x2535af('0x1f')](0x194),_0x51427d;};}function handleError(_0x3290cc,_0x3f925c){return _0x3f925c=_0x3f925c||0x1f4,function(_0x240354){const _0x19a45=a281_0x290a;logger[_0x19a45('0x39')](_0x240354[_0x19a45('0x25')]),_0x240354[_0x19a45('0x49')]&&delete _0x240354[_0x19a45('0x49')],_0x3290cc['status'](_0x3f925c)['send'](_0x240354);};}exports['index']=function(_0x5942aa,_0xcd4967){const _0x31b78f=_0x218e38;let _0x4a0524={};const _0x123653={},_0x22e3bc={'count':0x0,'rows':[]},_0x4b79f2=_[_0x31b78f('0x1d')](db[_0x31b78f('0x3c')][_0x31b78f('0x5f')],function(_0x4d5099){const _0x141a30=_0x31b78f;return{'name':_0x4d5099[_0x141a30('0x36')],'type':_0x4d5099[_0x141a30('0x4e')][_0x141a30('0x53')]};});_0x123653[_0x31b78f('0x65')]=_['map'](_0x4b79f2,_0x31b78f('0x49')),_0x123653[_0x31b78f('0x2b')]=_['keys'](_0x5942aa['query']),_0x123653['filters']=_[_0x31b78f('0x63')](_0x123653[_0x31b78f('0x65')],_0x123653[_0x31b78f('0x2b')]),_0x4a0524[_0x31b78f('0x60')]=_['intersection'](_0x123653[_0x31b78f('0x65')],qs['fields'](_0x5942aa['query'][_0x31b78f('0x26')])),_0x4a0524['attributes']=_0x4a0524[_0x31b78f('0x60')]['length']?_0x4a0524[_0x31b78f('0x60')]:_0x123653[_0x31b78f('0x65')];typeof _0x5942aa['query'][_0x31b78f('0x15')]===_0x31b78f('0x1b')&&(_0x4a0524[_0x31b78f('0x57')]=qs[_0x31b78f('0x57')](_0x5942aa['query'][_0x31b78f('0x57')]),_0x4a0524[_0x31b78f('0xf')]=qs[_0x31b78f('0xf')](_0x5942aa[_0x31b78f('0x2b')]['offset']));_0x4a0524[_0x31b78f('0x4c')]=qs[_0x31b78f('0x54')](_0x5942aa[_0x31b78f('0x2b')][_0x31b78f('0x54')]),_0x4a0524[_0x31b78f('0x14')]=qs['filters'](_['pick'](_0x5942aa['query'],_0x123653[_0x31b78f('0x7')]),_0x4b79f2);_0x5942aa['query'][_0x31b78f('0x23')]&&(_0x4a0524[_0x31b78f('0x14')]=_[_0x31b78f('0x28')](_0x4a0524[_0x31b78f('0x14')],{[Op['or']]:_['map'](_0x4b79f2,function(_0x3c6986){const _0x369788=_0x31b78f;if(_0x3c6986[_0x369788('0x4e')]!==_0x369788('0xe')){const _0x4536c4={};return _0x4536c4[_0x3c6986[_0x369788('0x49')]]={[Op[_0x369788('0x68')]]:'%'+_0x5942aa[_0x369788('0x2b')][_0x369788('0x23')]+'%'},_0x4536c4;}})}));_0x4a0524=_['merge']({},_0x4a0524,_0x5942aa[_0x31b78f('0xd')]);const _0x2dae00={'where':_0x4a0524['where']};return db[_0x31b78f('0x3c')][_0x31b78f('0x50')](_0x2dae00)[_0x31b78f('0x2a')](function(_0x23727c){const _0x27d88c=_0x31b78f;return _0x22e3bc['count']=_0x23727c,_0x5942aa[_0x27d88c('0x2b')][_0x27d88c('0x52')]&&(_0x4a0524[_0x27d88c('0x31')]=[{'all':!![]}]),db[_0x27d88c('0x3c')]['findAll'](_0x4a0524);})['then'](function(_0x3b3a08){return _0x22e3bc['rows']=_0x3b3a08,_0x22e3bc;})['then'](respondWithFilteredResult(_0xcd4967,_0x4a0524))[_0x31b78f('0x55')](handleError(_0xcd4967,null));},exports['show']=function(_0x4f0875,_0x98ef8e){const _0xc74a8a=_0x218e38;let _0x5d5150={'raw':![],'where':{'id':_0x4f0875[_0xc74a8a('0x3a')]['id']}};const _0x285a7b={};return _0x285a7b[_0xc74a8a('0x65')]=_[_0xc74a8a('0x38')](db['SalesforceAccount']['rawAttributes']),_0x285a7b[_0xc74a8a('0x2b')]=_[_0xc74a8a('0x38')](_0x4f0875[_0xc74a8a('0x2b')]),_0x285a7b['filters']=_[_0xc74a8a('0x63')](_0x285a7b[_0xc74a8a('0x65')],_0x285a7b[_0xc74a8a('0x2b')]),_0x5d5150[_0xc74a8a('0x60')]=_[_0xc74a8a('0x63')](_0x285a7b['model'],qs['fields'](_0x4f0875[_0xc74a8a('0x2b')][_0xc74a8a('0x26')])),_0x5d5150[_0xc74a8a('0x60')]=_0x5d5150[_0xc74a8a('0x60')][_0xc74a8a('0xb')]?_0x5d5150[_0xc74a8a('0x60')]:_0x285a7b[_0xc74a8a('0x65')],_0x4f0875[_0xc74a8a('0x2b')][_0xc74a8a('0x52')]&&(_0x5d5150[_0xc74a8a('0x31')]=[{'all':!![]}]),_0x5d5150=_[_0xc74a8a('0x28')]({},_0x5d5150,_0x4f0875[_0xc74a8a('0xd')]),db['SalesforceAccount'][_0xc74a8a('0x62')](_0x5d5150)[_0xc74a8a('0x2a')](handleEntityNotFound(_0x98ef8e,null))[_0xc74a8a('0x2a')](respondWithResult(_0x98ef8e,null))[_0xc74a8a('0x55')](handleError(_0x98ef8e,null));},exports[_0x218e38('0x45')]=function(_0x5b04e5,_0x13e2e6){const _0x51b0ed=_0x218e38;return db['SalesforceAccount'][_0x51b0ed('0x45')](_0x5b04e5['body'],{})['then'](respondWithResult(_0x13e2e6,0xc9))[_0x51b0ed('0x55')](handleError(_0x13e2e6,null));},exports[_0x218e38('0x6')]=function(_0x561c51,_0x49fcaf){const _0xb6145d=_0x218e38;return _0x561c51[_0xb6145d('0x3')]['id']&&delete _0x561c51[_0xb6145d('0x3')]['id'],db[_0xb6145d('0x3c')][_0xb6145d('0x62')]({'where':{'id':_0x561c51[_0xb6145d('0x3a')]['id']}})[_0xb6145d('0x2a')](handleEntityNotFound(_0x49fcaf,null))[_0xb6145d('0x2a')](saveUpdates(_0x561c51['body'],null))[_0xb6145d('0x2a')](respondWithResult(_0x49fcaf,null))[_0xb6145d('0x55')](handleError(_0x49fcaf,null));},exports[_0x218e38('0x66')]=function(_0x39c297,_0x182784){const _0x2c55cf=_0x218e38;return db[_0x2c55cf('0x3c')][_0x2c55cf('0x62')]({'where':{'id':_0x39c297[_0x2c55cf('0x3a')]['id']}})[_0x2c55cf('0x2a')](handleEntityNotFound(_0x182784,null))[_0x2c55cf('0x2a')](removeEntity(_0x182784,null))[_0x2c55cf('0x55')](handleError(_0x182784,null));},exports[_0x218e38('0x13')]=function(_0x3924ac,_0x3d6650){const _0x37d67b=_0x218e38;let _0x4e7722={};const _0x5c558b={};let _0x477580,_0x1c8c56;return db[_0x37d67b('0x3c')][_0x37d67b('0x62')]({'where':{'id':_0x3924ac['params']['id']}})[_0x37d67b('0x2a')](handleEntityNotFound(_0x3d6650,null))['then'](function(_0x3c6a7a){const _0x1634e4=_0x37d67b;if(_0x3c6a7a)return _0x477580=_0x3c6a7a,_0x5c558b['model']=_[_0x1634e4('0x38')](db[_0x1634e4('0x3e')][_0x1634e4('0x5f')]),_0x5c558b[_0x1634e4('0x2b')]=_[_0x1634e4('0x38')](_0x3924ac['query']),_0x5c558b[_0x1634e4('0x7')]=_['intersection'](_0x5c558b[_0x1634e4('0x65')],_0x5c558b['query']),_0x4e7722['attributes']=_[_0x1634e4('0x63')](_0x5c558b['model'],qs[_0x1634e4('0x26')](_0x3924ac[_0x1634e4('0x2b')][_0x1634e4('0x26')])),_0x4e7722[_0x1634e4('0x60')]=_0x4e7722[_0x1634e4('0x60')][_0x1634e4('0xb')]?_0x4e7722[_0x1634e4('0x60')]:_0x5c558b[_0x1634e4('0x65')],_0x4e7722[_0x1634e4('0x4c')]=qs[_0x1634e4('0x54')](_0x3924ac['query']['sort']),_0x4e7722[_0x1634e4('0x14')]=qs[_0x1634e4('0x7')](_[_0x1634e4('0x67')](_0x3924ac[_0x1634e4('0x2b')],_0x5c558b['filters'])),_0x3924ac['query'][_0x1634e4('0x23')]&&(_0x4e7722[_0x1634e4('0x14')]=_[_0x1634e4('0x28')](_0x4e7722[_0x1634e4('0x14')],{[Op['or']]:_[_0x1634e4('0x1d')](_0x4e7722[_0x1634e4('0x60')],function(_0x26c076){const _0x42a7f1=_0x1634e4,_0x5069bb={};return _0x5069bb[_0x26c076]={[Op[_0x42a7f1('0x68')]]:'%'+_0x3924ac[_0x42a7f1('0x2b')]['filter']+'%'},_0x5069bb;})})),_0x4e7722=_[_0x1634e4('0x28')]({},_0x4e7722,_0x3924ac[_0x1634e4('0xd')]),_0x477580[_0x1634e4('0x13')](_0x4e7722);})[_0x37d67b('0x2a')](function(_0x1fa49d){const _0x55cb93=_0x37d67b;if(_0x1fa49d)return _0x1c8c56=_0x1fa49d[_0x55cb93('0xb')],typeof _0x3924ac[_0x55cb93('0x2b')][_0x55cb93('0x15')]==='undefined'&&(_0x4e7722[_0x55cb93('0x57')]=qs[_0x55cb93('0x57')](_0x3924ac[_0x55cb93('0x2b')][_0x55cb93('0x57')]),_0x4e7722[_0x55cb93('0xf')]=qs[_0x55cb93('0xf')](_0x3924ac[_0x55cb93('0x2b')][_0x55cb93('0xf')])),_0x477580[_0x55cb93('0x13')](_0x4e7722);})[_0x37d67b('0x2a')](function(_0x429c4f){if(_0x429c4f)return _0x429c4f?{'count':_0x1c8c56,'rows':_0x429c4f}:null;})['then'](respondWithResult(_0x3d6650,null))[_0x37d67b('0x55')](handleError(_0x3d6650,null));},exports[_0x218e38('0x64')]=function(_0x368879,_0x208638){const _0x5d1709=_0x218e38;return _0x368879[_0x5d1709('0x3')]['id']&&delete _0x368879[_0x5d1709('0x3')]['id'],db[_0x5d1709('0x3c')][_0x5d1709('0x62')]({'where':{'id':_0x368879[_0x5d1709('0x3a')]['id']}})[_0x5d1709('0x2a')](handleEntityNotFound(_0x208638,null))[_0x5d1709('0x2a')](function(_0x932781){const _0x5ab9cf=_0x5d1709;if(_0x932781)return _0x368879[_0x5ab9cf('0x3')][_0x5ab9cf('0x35')]=_0x932781['id'],_0x368879[_0x5ab9cf('0x3')][_0x5ab9cf('0x43')]=integrations[_0x5ab9cf('0x5')](_0x368879['body'][_0x5ab9cf('0x2d')],_0x368879[_0x5ab9cf('0x3')][_0x5ab9cf('0x4e')]),_0x368879['body'][_0x5ab9cf('0x2')]=integrations[_0x5ab9cf('0x37')](_0x368879[_0x5ab9cf('0x3')][_0x5ab9cf('0x2d')],_0x368879['body'][_0x5ab9cf('0x4e')]),db[_0x5ab9cf('0x3e')][_0x5ab9cf('0x45')](_0x368879[_0x5ab9cf('0x3')],{'include':[{'model':db['SalesforceField'],'as':'Subjects'},{'model':db['SalesforceField'],'as':'Descriptions'}]});return null;})['then'](respondWithResult(_0x208638,null))[_0x5d1709('0x55')](handleError(_0x208638,null));},exports[_0x218e38('0x2f')]=function(_0xfc4f15,_0x3f55d8){const _0x1f3e4c=_0x218e38;let _0x190b04,_0x386211='',_0x4ec669=_0x1f3e4c('0x5e');return db[_0x1f3e4c('0x3c')][_0x1f3e4c('0x62')]({'where':{'id':_0xfc4f15['params']['id']},'attributes':['id',_0x1f3e4c('0x33'),_0x1f3e4c('0x1'),'clientSecret',_0x1f3e4c('0x22'),_0x1f3e4c('0x20'),_0x1f3e4c('0x32')]})[_0x1f3e4c('0x2a')](handleEntityNotFound(_0x3f55d8,null))[_0x1f3e4c('0x2a')](function(_0x579fb7){const _0x12513b=_0x1f3e4c;if(_0x579fb7){_0x386211=_0x579fb7['remoteUri'];const _0x26133b=_0x386211[_0x12513b('0xa')](-0x1);return _0x26133b==='/'&&(_0x386211=_0x386211[_0x12513b('0xc')](0x0,_0x386211[_0x12513b('0x47')](_0x26133b))),_0x190b04=new jsforce[(_0x12513b('0x24'))]({'oauth2':{'loginUrl':_0x386211,'clientId':_0x579fb7['clientId'],'clientSecret':_0x579fb7[_0x12513b('0x4f')]}}),_0x190b04[_0x12513b('0x8')](_0x579fb7['username'],_0x579fb7[_0x12513b('0x20')][_0x12513b('0x27')](_0x579fb7[_0x12513b('0x32')]));}})[_0x1f3e4c('0x2a')](function(_0x2f946a){const _0x157450=_0x1f3e4c;if(_0x2f946a)return!_['isNil'](_0xfc4f15[_0x157450('0x2b')][_0x157450('0x40')])&&(_0x4ec669=_0xfc4f15['query'][_0x157450('0x40')]),_0x190b04[_0x157450('0x5b')](_0x4ec669)[_0x157450('0x51')]();})[_0x1f3e4c('0x2a')](function(_0x343d70){const _0x120437=_0x1f3e4c;let _0x3a5e50=[_0x120437('0x4d'),_0x120437('0x44'),_0x120437('0x4b'),_0x120437('0x4'),_0x120437('0x16'),_0x120437('0x30'),'Status',_0x120437('0x19')];!_[_0x120437('0x2e')](_0xfc4f15[_0x120437('0x2b')]['ticketType'])&&_0xfc4f15[_0x120437('0x2b')][_0x120437('0x40')]===_0x120437('0x1c')&&(_0x3a5e50=[_0x120437('0x19'),_0x120437('0x5a'),_0x120437('0x2c'),_0x120437('0x42'),_0x120437('0x30'),_0x120437('0x5d'),_0x120437('0x18'),_0x120437('0x59')]);if(_0x343d70)return _[_0x120437('0x10')](_0x343d70[_0x120437('0x26')],function(_0x535bf0){const _0x379602=_0x120437;return _0x535bf0[_0x379602('0x29')]===![]&&!_0x3a5e50['includes'](_0x535bf0[_0x379602('0x49')]);}),{'count':_0x343d70['fields']['length'],'rows':_[_0x120437('0x1d')](_0x343d70['fields'],function(_0x26080d){const _0x4dd8e2=_0x120437;return{'id':_0x26080d[_0x4dd8e2('0x49')],'name':_0x26080d['label'],'custom':_0x26080d[_0x4dd8e2('0x29')],'options':_0x26080d['picklistValues'][_0x4dd8e2('0xb')]>0x0?_[_0x4dd8e2('0x1d')](_0x26080d[_0x4dd8e2('0x41')],function(_0x48c4f1){const _0x479ab0=_0x4dd8e2;return{'name':_0x48c4f1['label'],'value':_0x48c4f1[_0x479ab0('0x0')]};}):_0x26080d[_0x4dd8e2('0x4e')]==_0x4dd8e2('0x21')?[{'name':'True','value':_0x4dd8e2('0x3d')},{'name':_0x4dd8e2('0x58'),'value':_0x4dd8e2('0x56')}]:[]};})};})[_0x1f3e4c('0x2a')](respondWithResult(_0x3f55d8,null))[_0x1f3e4c('0x55')](function(_0x30026e){const _0x10ccb1=_0x1f3e4c;let _0x2a3fd5=_0xfc4f15['query'][_0x10ccb1('0x1e')]?0x1f4:_0x30026e[_0x10ccb1('0x12')]||0x1f4;logger['error'](_0x10ccb1('0x5c'),_0x10ccb1('0x2f'),_0x2a3fd5,JSON[_0x10ccb1('0x1a')](_0x30026e)),delete _0x30026e[_0x10ccb1('0x49')],_0x2a3fd5===0x191&&(_0x2a3fd5=0x190),_0x3f55d8[_0x10ccb1('0x17')](_0x2a3fd5)['send'](_0xfc4f15[_0x10ccb1('0x2b')]['test']?{'message':_0x10ccb1('0x46'),'statusCode':_0x30026e['statusCode']}:_0x30026e);});};