Built motion from commit aab208717af8d15f4fa224cdb6a202877019af9b. Version 3.0.0...
[motion-next.git] / server / api / intSalesforceAccount / intSalesforceAccount.controller.js
1 const a281_0x5181=['create','getFields','getFields,\x20%s,\x20%s,\x20%s','send','order','count','findOne','CallType','SuppliedCompany','value','Status','sequelize','intersection','picklistValues','../../components/parsers/qs','key','test','ticketType','catch','label','Descriptions','slice','options','where','SalesforceAccount','rawAttributes','nolimit','channel','Priority','custom','attributes','query','login','then','CallObject','clientId','keys','include','type','fieldName','Case','findAll','isNil','addConfiguration','update','params','limit','SalesforceConfiguration','../../components/integrations/configuration','sobject','Subjects','sort','like','show','includeAll','Content-Range','filter','remoteUri','password','offset','false','body','map','merge','end','CallDurationInSeconds','statusCode','username','pick','name','clientSecret','Task','AccountId','json','Reason','undefined','securityToken','fields','IsArchived','describe','remove','rows','status','boolean','stack','true','destroy','getDescriptions','concat','getConfigurations','length','model','True','stringify','filters','sendStatus','error','../../config/logger','SalesforceField','index','../../mysqldb'];(function(_0x35a13f,_0x5181d1){const _0x33f250=function(_0x49577d){while(--_0x49577d){_0x35a13f['push'](_0x35a13f['shift']());}};_0x33f250(++_0x5181d1);}(a281_0x5181,0xbe));const a281_0x33f2=function(_0x35a13f,_0x5181d1){_0x35a13f=_0x35a13f-0x0;let _0x33f250=a281_0x5181[_0x35a13f];return _0x33f250;};const _0x1d3724=a281_0x33f2;'use strict';const _=require('lodash'),jsforce=require('jsforce'),qs=require(_0x1d3724('0x1a')),logger=require(_0x1d3724('0x8'))('api'),db=require(_0x1d3724('0xb'))['db'],{Op}=require(_0x1d3724('0x17')),integrations=require(_0x1d3724('0x3c'));function respondWithResult(_0x49577d,_0x5c36c9){return _0x5c36c9=_0x5c36c9||0xc8,function(_0x2ffbb8){const _0x348d34=a281_0x33f2;if(_0x2ffbb8)return _0x49577d[_0x348d34('0x5e')](_0x5c36c9)[_0x348d34('0x55')](_0x2ffbb8);};}function respondWithFilteredResult(_0x2e43a8,_0xf4d8b0){return function(_0x1d651a){const _0x2be5c0=a281_0x33f2;if(_0x1d651a){const _0x18b605=_0x1d651a[_0x2be5c0('0x11')],_0x152da1=_0xf4d8b0[_0x2be5c0('0x47')];let _0xe5e090=_0xf4d8b0['offset']+_0xf4d8b0[_0x2be5c0('0x3a')],_0x4cf235;return _0xe5e090>=_0x18b605?(_0xe5e090=_0x18b605,_0x4cf235=0xc8):_0x4cf235=0xce,_0x2e43a8[_0x2be5c0('0x5e')](_0x4cf235),_0x2e43a8['set'](_0x2be5c0('0x43'),_0x152da1+'-'+_0xe5e090+'/'+_0x18b605)[_0x2be5c0('0x55')](_0x1d651a);}return null;};}function saveUpdates(_0x2cf365){return function(_0x9ab5f9){const _0x2ecafb=a281_0x33f2;if(_0x9ab5f9)return _0x9ab5f9[_0x2ecafb('0x38')](_0x2cf365)['then'](function(_0x3e5569){return _0x3e5569;});return null;};}function removeEntity(_0x3f96c6){return function(_0x31aa89){const _0x1b9036=a281_0x33f2;if(_0x31aa89)return _0x31aa89[_0x1b9036('0x62')]()[_0x1b9036('0x2d')](function(){const _0x49ed8b=_0x1b9036;_0x3f96c6[_0x49ed8b('0x5e')](0xcc)[_0x49ed8b('0x4c')]();});};}function handleEntityNotFound(_0x37c1e6){return function(_0x47abc0){const _0x408426=a281_0x33f2;return!_0x47abc0&&_0x37c1e6[_0x408426('0x6')](0x194),_0x47abc0;};}function handleError(_0x16df54,_0x6e2f1b){return _0x6e2f1b=_0x6e2f1b||0x1f4,function(_0x5e3647){const _0x3ae6ac=a281_0x33f2;logger[_0x3ae6ac('0x7')](_0x5e3647[_0x3ae6ac('0x60')]),_0x5e3647[_0x3ae6ac('0x51')]&&delete _0x5e3647[_0x3ae6ac('0x51')],_0x16df54[_0x3ae6ac('0x5e')](_0x6e2f1b)[_0x3ae6ac('0xf')](_0x5e3647);};}exports[_0x1d3724('0xa')]=function(_0x182125,_0x1f4f9f){const _0x5a3457=_0x1d3724;let _0x5cdcc9={};const _0x2bd10d={},_0x5ab2ed={'count':0x0,'rows':[]},_0x1eeb67=_[_0x5a3457('0x4a')](db['SalesforceAccount'][_0x5a3457('0x25')],function(_0x469eff){const _0x29f407=_0x5a3457;return{'name':_0x469eff[_0x29f407('0x33')],'type':_0x469eff[_0x29f407('0x32')][_0x29f407('0x1b')]};});_0x2bd10d[_0x5a3457('0x2')]=_[_0x5a3457('0x4a')](_0x1eeb67,_0x5a3457('0x51')),_0x2bd10d[_0x5a3457('0x2b')]=_[_0x5a3457('0x30')](_0x182125[_0x5a3457('0x2b')]),_0x2bd10d[_0x5a3457('0x5')]=_[_0x5a3457('0x18')](_0x2bd10d[_0x5a3457('0x2')],_0x2bd10d[_0x5a3457('0x2b')]),_0x5cdcc9[_0x5a3457('0x2a')]=_[_0x5a3457('0x18')](_0x2bd10d['model'],qs[_0x5a3457('0x59')](_0x182125[_0x5a3457('0x2b')]['fields'])),_0x5cdcc9[_0x5a3457('0x2a')]=_0x5cdcc9[_0x5a3457('0x2a')]['length']?_0x5cdcc9[_0x5a3457('0x2a')]:_0x2bd10d[_0x5a3457('0x2')];typeof _0x182125['query'][_0x5a3457('0x26')]===_0x5a3457('0x57')&&(_0x5cdcc9[_0x5a3457('0x3a')]=qs[_0x5a3457('0x3a')](_0x182125[_0x5a3457('0x2b')][_0x5a3457('0x3a')]),_0x5cdcc9[_0x5a3457('0x47')]=qs[_0x5a3457('0x47')](_0x182125[_0x5a3457('0x2b')][_0x5a3457('0x47')]));_0x5cdcc9[_0x5a3457('0x10')]=qs[_0x5a3457('0x3f')](_0x182125[_0x5a3457('0x2b')][_0x5a3457('0x3f')]),_0x5cdcc9[_0x5a3457('0x23')]=qs['filters'](_[_0x5a3457('0x50')](_0x182125['query'],_0x2bd10d[_0x5a3457('0x5')]),_0x1eeb67);_0x182125['query'][_0x5a3457('0x44')]&&(_0x5cdcc9['where']=_[_0x5a3457('0x4b')](_0x5cdcc9[_0x5a3457('0x23')],{[Op['or']]:_['map'](_0x1eeb67,function(_0x5b9f7d){const _0x2e5d57=_0x5a3457;if(_0x5b9f7d[_0x2e5d57('0x32')]!=='VIRTUAL'){const _0x308484={};return _0x308484[_0x5b9f7d[_0x2e5d57('0x51')]]={[Op['like']]:'%'+_0x182125['query'][_0x2e5d57('0x44')]+'%'},_0x308484;}})}));_0x5cdcc9=_['merge']({},_0x5cdcc9,_0x182125[_0x5a3457('0x22')]);const _0x24fe3c={'where':_0x5cdcc9['where']};return db[_0x5a3457('0x24')][_0x5a3457('0x11')](_0x24fe3c)[_0x5a3457('0x2d')](function(_0xf47d22){const _0x2fb65f=_0x5a3457;return _0x5ab2ed[_0x2fb65f('0x11')]=_0xf47d22,_0x182125[_0x2fb65f('0x2b')]['includeAll']&&(_0x5cdcc9[_0x2fb65f('0x31')]=[{'all':!![]}]),db[_0x2fb65f('0x24')][_0x2fb65f('0x35')](_0x5cdcc9);})[_0x5a3457('0x2d')](function(_0x469001){const _0x3327a3=_0x5a3457;return _0x5ab2ed[_0x3327a3('0x5d')]=_0x469001,_0x5ab2ed;})[_0x5a3457('0x2d')](respondWithFilteredResult(_0x1f4f9f,_0x5cdcc9))[_0x5a3457('0x1e')](handleError(_0x1f4f9f,null));},exports[_0x1d3724('0x41')]=function(_0x31b991,_0x1afc05){const _0x256593=_0x1d3724;let _0xc08ab8={'raw':![],'where':{'id':_0x31b991[_0x256593('0x39')]['id']}};const _0x3fd7b8={};return _0x3fd7b8[_0x256593('0x2')]=_[_0x256593('0x30')](db[_0x256593('0x24')][_0x256593('0x25')]),_0x3fd7b8[_0x256593('0x2b')]=_[_0x256593('0x30')](_0x31b991[_0x256593('0x2b')]),_0x3fd7b8[_0x256593('0x5')]=_[_0x256593('0x18')](_0x3fd7b8['model'],_0x3fd7b8[_0x256593('0x2b')]),_0xc08ab8['attributes']=_['intersection'](_0x3fd7b8[_0x256593('0x2')],qs[_0x256593('0x59')](_0x31b991[_0x256593('0x2b')][_0x256593('0x59')])),_0xc08ab8['attributes']=_0xc08ab8[_0x256593('0x2a')]['length']?_0xc08ab8[_0x256593('0x2a')]:_0x3fd7b8['model'],_0x31b991[_0x256593('0x2b')][_0x256593('0x42')]&&(_0xc08ab8['include']=[{'all':!![]}]),_0xc08ab8=_[_0x256593('0x4b')]({},_0xc08ab8,_0x31b991[_0x256593('0x22')]),db[_0x256593('0x24')][_0x256593('0x12')](_0xc08ab8)[_0x256593('0x2d')](handleEntityNotFound(_0x1afc05,null))['then'](respondWithResult(_0x1afc05,null))[_0x256593('0x1e')](handleError(_0x1afc05,null));},exports[_0x1d3724('0xc')]=function(_0x3479a5,_0x3e3bcf){const _0x5f55c8=_0x1d3724;return db[_0x5f55c8('0x24')][_0x5f55c8('0xc')](_0x3479a5[_0x5f55c8('0x49')],{})[_0x5f55c8('0x2d')](respondWithResult(_0x3e3bcf,0xc9))[_0x5f55c8('0x1e')](handleError(_0x3e3bcf,null));},exports[_0x1d3724('0x38')]=function(_0x13058e,_0xb8f393){const _0x58a4db=_0x1d3724;return _0x13058e[_0x58a4db('0x49')]['id']&&delete _0x13058e['body']['id'],db[_0x58a4db('0x24')]['findOne']({'where':{'id':_0x13058e['params']['id']}})['then'](handleEntityNotFound(_0xb8f393,null))[_0x58a4db('0x2d')](saveUpdates(_0x13058e[_0x58a4db('0x49')],null))[_0x58a4db('0x2d')](respondWithResult(_0xb8f393,null))['catch'](handleError(_0xb8f393,null));},exports[_0x1d3724('0x62')]=function(_0x54ba3c,_0x42feca){const _0x738f47=_0x1d3724;return db[_0x738f47('0x24')]['findOne']({'where':{'id':_0x54ba3c[_0x738f47('0x39')]['id']}})[_0x738f47('0x2d')](handleEntityNotFound(_0x42feca,null))[_0x738f47('0x2d')](removeEntity(_0x42feca,null))['catch'](handleError(_0x42feca,null));},exports[_0x1d3724('0x0')]=function(_0x42ff64,_0x3546e0){const _0x389ab4=_0x1d3724;let _0x309687={};const _0x278a21={};let _0x1f1882,_0x3b9c3a;return db[_0x389ab4('0x24')][_0x389ab4('0x12')]({'where':{'id':_0x42ff64['params']['id']}})[_0x389ab4('0x2d')](handleEntityNotFound(_0x3546e0,null))['then'](function(_0x25e498){const _0x5a1013=_0x389ab4;if(_0x25e498)return _0x1f1882=_0x25e498,_0x278a21['model']=_[_0x5a1013('0x30')](db[_0x5a1013('0x3b')]['rawAttributes']),_0x278a21[_0x5a1013('0x2b')]=_[_0x5a1013('0x30')](_0x42ff64['query']),_0x278a21[_0x5a1013('0x5')]=_[_0x5a1013('0x18')](_0x278a21[_0x5a1013('0x2')],_0x278a21[_0x5a1013('0x2b')]),_0x309687[_0x5a1013('0x2a')]=_[_0x5a1013('0x18')](_0x278a21['model'],qs[_0x5a1013('0x59')](_0x42ff64[_0x5a1013('0x2b')][_0x5a1013('0x59')])),_0x309687[_0x5a1013('0x2a')]=_0x309687['attributes']['length']?_0x309687[_0x5a1013('0x2a')]:_0x278a21['model'],_0x309687['order']=qs[_0x5a1013('0x3f')](_0x42ff64['query']['sort']),_0x309687[_0x5a1013('0x23')]=qs[_0x5a1013('0x5')](_[_0x5a1013('0x50')](_0x42ff64['query'],_0x278a21[_0x5a1013('0x5')])),_0x42ff64['query'][_0x5a1013('0x44')]&&(_0x309687[_0x5a1013('0x23')]=_[_0x5a1013('0x4b')](_0x309687[_0x5a1013('0x23')],{[Op['or']]:_[_0x5a1013('0x4a')](_0x309687[_0x5a1013('0x2a')],function(_0x501044){const _0x2e2072=_0x5a1013,_0x437a27={};return _0x437a27[_0x501044]={[Op[_0x2e2072('0x40')]]:'%'+_0x42ff64['query'][_0x2e2072('0x44')]+'%'},_0x437a27;})})),_0x309687=_[_0x5a1013('0x4b')]({},_0x309687,_0x42ff64[_0x5a1013('0x22')]),_0x1f1882['getConfigurations'](_0x309687);})['then'](function(_0x202379){const _0x333e59=_0x389ab4;if(_0x202379)return _0x3b9c3a=_0x202379[_0x333e59('0x1')],typeof _0x42ff64[_0x333e59('0x2b')][_0x333e59('0x26')]==='undefined'&&(_0x309687['limit']=qs[_0x333e59('0x3a')](_0x42ff64['query'][_0x333e59('0x3a')]),_0x309687[_0x333e59('0x47')]=qs[_0x333e59('0x47')](_0x42ff64[_0x333e59('0x2b')][_0x333e59('0x47')])),_0x1f1882[_0x333e59('0x0')](_0x309687);})[_0x389ab4('0x2d')](function(_0x4417ab){if(_0x4417ab)return _0x4417ab?{'count':_0x3b9c3a,'rows':_0x4417ab}:null;})['then'](respondWithResult(_0x3546e0,null))[_0x389ab4('0x1e')](handleError(_0x3546e0,null));},exports[_0x1d3724('0x37')]=function(_0x12a58a,_0x5da687){const _0x237667=_0x1d3724;return _0x12a58a[_0x237667('0x49')]['id']&&delete _0x12a58a[_0x237667('0x49')]['id'],db[_0x237667('0x24')][_0x237667('0x12')]({'where':{'id':_0x12a58a[_0x237667('0x39')]['id']}})[_0x237667('0x2d')](handleEntityNotFound(_0x5da687,null))[_0x237667('0x2d')](function(_0x1c396a){const _0x3585f5=_0x237667;if(_0x1c396a)return _0x12a58a[_0x3585f5('0x49')][_0x3585f5('0x54')]=_0x1c396a['id'],_0x12a58a[_0x3585f5('0x49')][_0x3585f5('0x3e')]=integrations['getSubjects'](_0x12a58a[_0x3585f5('0x49')][_0x3585f5('0x27')],_0x12a58a[_0x3585f5('0x49')]['type']),_0x12a58a[_0x3585f5('0x49')][_0x3585f5('0x20')]=integrations[_0x3585f5('0x63')](_0x12a58a[_0x3585f5('0x49')]['channel'],_0x12a58a[_0x3585f5('0x49')][_0x3585f5('0x32')]),db[_0x3585f5('0x3b')][_0x3585f5('0xc')](_0x12a58a[_0x3585f5('0x49')],{'include':[{'model':db['SalesforceField'],'as':'Subjects'},{'model':db[_0x3585f5('0x9')],'as':_0x3585f5('0x20')}]});return null;})[_0x237667('0x2d')](respondWithResult(_0x5da687,null))['catch'](handleError(_0x5da687,null));},exports[_0x1d3724('0xd')]=function(_0x1746b,_0x76c86b){const _0x2259b0=_0x1d3724;let _0x5703c9,_0x5b4404='',_0x341fc6=_0x2259b0('0x53');return db['SalesforceAccount'][_0x2259b0('0x12')]({'where':{'id':_0x1746b[_0x2259b0('0x39')]['id']},'attributes':['id','remoteUri',_0x2259b0('0x2f'),_0x2259b0('0x52'),'username',_0x2259b0('0x46'),'securityToken']})[_0x2259b0('0x2d')](handleEntityNotFound(_0x76c86b,null))[_0x2259b0('0x2d')](function(_0x290342){const _0x2309ab=_0x2259b0;if(_0x290342){_0x5b4404=_0x290342[_0x2309ab('0x45')];const _0x3c22b0=_0x5b4404[_0x2309ab('0x21')](-0x1);return _0x3c22b0==='/'&&(_0x5b4404=_0x5b4404['substring'](0x0,_0x5b4404['lastIndexOf'](_0x3c22b0))),_0x5703c9=new jsforce['Connection']({'oauth2':{'loginUrl':_0x5b4404,'clientId':_0x290342['clientId'],'clientSecret':_0x290342[_0x2309ab('0x52')]}}),_0x5703c9[_0x2309ab('0x2c')](_0x290342[_0x2309ab('0x4f')],_0x290342[_0x2309ab('0x46')][_0x2309ab('0x64')](_0x290342[_0x2309ab('0x58')]));}})[_0x2259b0('0x2d')](function(_0x3453a8){const _0x431bfa=_0x2259b0;if(_0x3453a8)return!_[_0x431bfa('0x36')](_0x1746b[_0x431bfa('0x2b')][_0x431bfa('0x1d')])&&(_0x341fc6=_0x1746b[_0x431bfa('0x2b')][_0x431bfa('0x1d')]),_0x5703c9[_0x431bfa('0x3d')](_0x341fc6)[_0x431bfa('0x5b')]();})[_0x2259b0('0x2d')](function(_0x3131aa){const _0x279a61=_0x2259b0;let _0x232a4b=['CallDisposition',_0x279a61('0x4d'),_0x279a61('0x2e'),_0x279a61('0x13'),_0x279a61('0x5a'),_0x279a61('0x28'),_0x279a61('0x16'),'Type'];!_[_0x279a61('0x36')](_0x1746b[_0x279a61('0x2b')][_0x279a61('0x1d')])&&_0x1746b[_0x279a61('0x2b')][_0x279a61('0x1d')]===_0x279a61('0x34')&&(_0x232a4b=['Type','Origin',_0x279a61('0x56'),_0x279a61('0x16'),_0x279a61('0x28'),'IsEscalated','SuppliedName',_0x279a61('0x14')]);if(_0x3131aa)return _[_0x279a61('0x5c')](_0x3131aa[_0x279a61('0x59')],function(_0x1d4c83){const _0x20a896=_0x279a61;return _0x1d4c83[_0x20a896('0x29')]===![]&&!_0x232a4b['includes'](_0x1d4c83[_0x20a896('0x51')]);}),{'count':_0x3131aa['fields'][_0x279a61('0x1')],'rows':_[_0x279a61('0x4a')](_0x3131aa[_0x279a61('0x59')],function(_0x277907){const _0x313f27=_0x279a61;return{'id':_0x277907['name'],'name':_0x277907[_0x313f27('0x1f')],'custom':_0x277907['custom'],'options':_0x277907[_0x313f27('0x19')]['length']>0x0?_['map'](_0x277907[_0x313f27('0x19')],function(_0x1447ec){const _0x5e42cc=_0x313f27;return{'name':_0x1447ec[_0x5e42cc('0x1f')],'value':_0x1447ec[_0x5e42cc('0x15')]};}):_0x277907['type']==_0x313f27('0x5f')?[{'name':_0x313f27('0x3'),'value':_0x313f27('0x61')},{'name':'False','value':_0x313f27('0x48')}]:[]};})};})['then'](respondWithResult(_0x76c86b,null))[_0x2259b0('0x1e')](function(_0x27c912){const _0xf88c97=_0x2259b0;let _0x43a65c=_0x1746b[_0xf88c97('0x2b')][_0xf88c97('0x1c')]?0x1f4:_0x27c912[_0xf88c97('0x4e')]||0x1f4;logger['error'](_0xf88c97('0xe'),'getFields',_0x43a65c,JSON[_0xf88c97('0x4')](_0x27c912)),delete _0x27c912[_0xf88c97('0x51')],_0x43a65c===0x191&&(_0x43a65c=0x190),_0x76c86b[_0xf88c97('0x5e')](_0x43a65c)[_0xf88c97('0xf')](_0x1746b[_0xf88c97('0x2b')][_0xf88c97('0x1c')]?{'message':'Wrong\x20credentials','statusCode':_0x27c912['statusCode']}:_0x27c912);});};