792a0c8420b7b18b824792dfa0f5262e1fd0ff68
[motion-next.git] / server / api / intZohoAccount / intZohoAccount.controller.js
1 const a346_0x4c66=['request-promise-native','attributes','ZohoConfiguration','Call_Start_Time','getConfigurations','GET','stringify','Call_Type','substring','getFields','params','system_mandatory','Unable\x20to\x20retrieve\x20the\x20access\x20token','../../config/logger','where','undefined','statusCode','refresh_token','util','fieldName','type','https://accounts.zoho.eu','refreshToken','intersection','Content-Range','picklist','catch','../../components/parsers/qs','Call_Duration','sort','update','Wrong\x20credentials','length','https://accounts.zoho.com.au','create','include','model','nolimit','custom_field','https://accounts.zoho.com.cn','/oauth/v2/token','https://www.zohoapis.%s/crm/v2/settings/fields','../../mysqldb','ZohoField','rawAttributes','Subjects','zone','display_label','message','error','pick','pick_list_values','query','Descriptions','order','status','clientSecret','getFields,\x20%s,\x20%s,\x20%s','Zoho-oauthtoken\x20','index','sendStatus','json','options','host','findOne','destroy','lastIndexOf','WhoId','fields','ZohoAccount','includeAll','Call_Result','filters','api_name','then','body','Refresh\x20Token\x20not\x20available\x20for\x20the\x20account','like','slice','test','../../components/integrations/configuration','filter','Owner','getDescriptions','limit','https://accounts.zoho.in','sequelize','name','clientId','stack','offset','code','Description','access_token','POST','keys','response','includes','merge','serverUrl','com','map','findAll'];(function(_0x436cc3,_0x4c669a){const _0xacafa8=function(_0x1fc175){while(--_0x1fc175){_0x436cc3['push'](_0x436cc3['shift']());}};_0xacafa8(++_0x4c669a);}(a346_0x4c66,0x108));const a346_0xacaf=function(_0x436cc3,_0x4c669a){_0x436cc3=_0x436cc3-0x0;let _0xacafa8=a346_0x4c66[_0x436cc3];return _0xacafa8;};const _0x17231b=a346_0xacaf;'use strict';const rp=require(_0x17231b('0x2d')),util=require(_0x17231b('0x3f')),_=require('lodash'),qs=require(_0x17231b('0x48')),logger=require(_0x17231b('0x3a'))('api'),db=require(_0x17231b('0x57'))['db'],{Op}=require(_0x17231b('0x1c')),integrations=require(_0x17231b('0x16'));function respondWithResult(_0x1fc175,_0x2cbea2){return _0x2cbea2=_0x2cbea2||0xc8,function(_0x5e64ed){const _0x478f32=a346_0xacaf;if(_0x5e64ed)return _0x1fc175[_0x478f32('0x64')](_0x2cbea2)[_0x478f32('0x3')](_0x5e64ed);};}function respondWithFilteredResult(_0x44fbc7,_0x9f74d3){return function(_0x1ac680){const _0x48fc8e=a346_0xacaf;if(_0x1ac680){const _0x305eab=_0x1ac680['count'],_0x139869=_0x9f74d3[_0x48fc8e('0x20')];let _0x1fd13a=_0x9f74d3['offset']+_0x9f74d3[_0x48fc8e('0x1a')],_0x369b23;return _0x1fd13a>=_0x305eab?(_0x1fd13a=_0x305eab,_0x369b23=0xc8):_0x369b23=0xce,_0x44fbc7[_0x48fc8e('0x64')](_0x369b23),_0x44fbc7['set'](_0x48fc8e('0x45'),_0x139869+'-'+_0x1fd13a+'/'+_0x305eab)['json'](_0x1ac680);}return null;};}function saveUpdates(_0x4b0eba){return function(_0x51f3e2){const _0x5c9315=a346_0xacaf;if(_0x51f3e2)return _0x51f3e2['update'](_0x4b0eba)[_0x5c9315('0x10')](function(_0x34b9ab){return _0x34b9ab;});return null;};}function removeEntity(_0x59e504){return function(_0x470e42){const _0x3afb74=a346_0xacaf;if(_0x470e42)return _0x470e42[_0x3afb74('0x7')]()['then'](function(){const _0x4516b2=_0x3afb74;_0x59e504[_0x4516b2('0x64')](0xcc)['end']();});};}function handleEntityNotFound(_0x3714c8){return function(_0x154b46){const _0x4352f7=a346_0xacaf;return!_0x154b46&&_0x3714c8[_0x4352f7('0x2')](0x194),_0x154b46;};}function handleError(_0x219db9,_0x686993){return _0x686993=_0x686993||0x1f4,function(_0x42d09e){const _0x1775c5=a346_0xacaf;logger[_0x1775c5('0x5e')](_0x42d09e[_0x1775c5('0x1f')]),_0x42d09e[_0x1775c5('0x1d')]&&delete _0x42d09e[_0x1775c5('0x1d')],_0x219db9[_0x1775c5('0x64')](_0x686993)['send'](_0x42d09e);};}exports[_0x17231b('0x1')]=function(_0x35da06,_0x38b122){const _0x1b4c4e=_0x17231b;let _0x3d854d={};const _0x556c20={},_0x2062dc={'count':0x0,'rows':[]},_0x404333=_[_0x1b4c4e('0x2b')](db[_0x1b4c4e('0xb')][_0x1b4c4e('0x59')],function(_0x388b19){const _0x54e009=_0x1b4c4e;return{'name':_0x388b19[_0x54e009('0x40')],'type':_0x388b19['type']['key']};});_0x556c20[_0x1b4c4e('0x51')]=_[_0x1b4c4e('0x2b')](_0x404333,'name'),_0x556c20[_0x1b4c4e('0x61')]=_['keys'](_0x35da06[_0x1b4c4e('0x61')]),_0x556c20['filters']=_[_0x1b4c4e('0x44')](_0x556c20[_0x1b4c4e('0x51')],_0x556c20[_0x1b4c4e('0x61')]),_0x3d854d[_0x1b4c4e('0x2e')]=_[_0x1b4c4e('0x44')](_0x556c20['model'],qs[_0x1b4c4e('0xa')](_0x35da06[_0x1b4c4e('0x61')]['fields'])),_0x3d854d[_0x1b4c4e('0x2e')]=_0x3d854d[_0x1b4c4e('0x2e')]['length']?_0x3d854d[_0x1b4c4e('0x2e')]:_0x556c20[_0x1b4c4e('0x51')];typeof _0x35da06[_0x1b4c4e('0x61')][_0x1b4c4e('0x52')]===_0x1b4c4e('0x3c')&&(_0x3d854d['limit']=qs['limit'](_0x35da06['query'][_0x1b4c4e('0x1a')]),_0x3d854d[_0x1b4c4e('0x20')]=qs['offset'](_0x35da06[_0x1b4c4e('0x61')][_0x1b4c4e('0x20')]));_0x3d854d[_0x1b4c4e('0x63')]=qs['sort'](_0x35da06[_0x1b4c4e('0x61')][_0x1b4c4e('0x4a')]),_0x3d854d[_0x1b4c4e('0x3b')]=qs[_0x1b4c4e('0xe')](_[_0x1b4c4e('0x5f')](_0x35da06[_0x1b4c4e('0x61')],_0x556c20[_0x1b4c4e('0xe')]),_0x404333);_0x35da06[_0x1b4c4e('0x61')]['filter']&&(_0x3d854d[_0x1b4c4e('0x3b')]=_['merge'](_0x3d854d[_0x1b4c4e('0x3b')],{[Op['or']]:_[_0x1b4c4e('0x2b')](_0x404333,function(_0x21bdf6){const _0x526d6a=_0x1b4c4e;if(_0x21bdf6[_0x526d6a('0x41')]!=='VIRTUAL'){const _0x567753={};return _0x567753[_0x21bdf6[_0x526d6a('0x1d')]]={[Op[_0x526d6a('0x13')]]:'%'+_0x35da06['query'][_0x526d6a('0x17')]+'%'},_0x567753;}})}));_0x3d854d=_[_0x1b4c4e('0x28')]({},_0x3d854d,_0x35da06[_0x1b4c4e('0x4')]);const _0x851059={'where':_0x3d854d[_0x1b4c4e('0x3b')]};return db[_0x1b4c4e('0xb')]['count'](_0x851059)[_0x1b4c4e('0x10')](function(_0x2ce83f){const _0x48ad59=_0x1b4c4e;return _0x2062dc['count']=_0x2ce83f,_0x35da06[_0x48ad59('0x61')][_0x48ad59('0xc')]&&(_0x3d854d['include']=[{'all':!![]}]),db[_0x48ad59('0xb')][_0x48ad59('0x2c')](_0x3d854d);})[_0x1b4c4e('0x10')](function(_0x4541c0){return _0x2062dc['rows']=_0x4541c0,_0x2062dc;})[_0x1b4c4e('0x10')](respondWithFilteredResult(_0x38b122,_0x3d854d))[_0x1b4c4e('0x47')](handleError(_0x38b122,null));},exports['show']=function(_0x11f0a9,_0x3cc756){const _0x2b8b19=_0x17231b;let _0x59edf9={'raw':![],'where':{'id':_0x11f0a9['params']['id']}};const _0x39423a={};return _0x39423a[_0x2b8b19('0x51')]=_['keys'](db[_0x2b8b19('0xb')]['rawAttributes']),_0x39423a[_0x2b8b19('0x61')]=_['keys'](_0x11f0a9[_0x2b8b19('0x61')]),_0x39423a[_0x2b8b19('0xe')]=_[_0x2b8b19('0x44')](_0x39423a[_0x2b8b19('0x51')],_0x39423a['query']),_0x59edf9[_0x2b8b19('0x2e')]=_[_0x2b8b19('0x44')](_0x39423a[_0x2b8b19('0x51')],qs[_0x2b8b19('0xa')](_0x11f0a9[_0x2b8b19('0x61')][_0x2b8b19('0xa')])),_0x59edf9['attributes']=_0x59edf9[_0x2b8b19('0x2e')][_0x2b8b19('0x4d')]?_0x59edf9['attributes']:_0x39423a[_0x2b8b19('0x51')],_0x11f0a9[_0x2b8b19('0x61')]['includeAll']&&(_0x59edf9[_0x2b8b19('0x50')]=[{'all':!![]}]),_0x59edf9=_[_0x2b8b19('0x28')]({},_0x59edf9,_0x11f0a9['options']),db['ZohoAccount']['findOne'](_0x59edf9)[_0x2b8b19('0x10')](handleEntityNotFound(_0x3cc756,null))[_0x2b8b19('0x10')](respondWithResult(_0x3cc756,null))[_0x2b8b19('0x47')](handleError(_0x3cc756,null));},exports[_0x17231b('0x4f')]=function(_0x18f318,_0x8781dd){const _0x1a0d39=_0x17231b;return db['ZohoAccount']['create'](_0x18f318[_0x1a0d39('0x11')],{})[_0x1a0d39('0x10')](respondWithResult(_0x8781dd,0xc9))['catch'](handleError(_0x8781dd,null));},exports[_0x17231b('0x4b')]=function(_0x541e97,_0x405825){const _0x4bd2ab=_0x17231b;return _0x541e97['body']['id']&&delete _0x541e97['body']['id'],db['ZohoAccount'][_0x4bd2ab('0x6')]({'where':{'id':_0x541e97[_0x4bd2ab('0x37')]['id']}})[_0x4bd2ab('0x10')](handleEntityNotFound(_0x405825,null))[_0x4bd2ab('0x10')](saveUpdates(_0x541e97[_0x4bd2ab('0x11')],null))[_0x4bd2ab('0x10')](respondWithResult(_0x405825,null))['catch'](handleError(_0x405825,null));},exports[_0x17231b('0x7')]=function(_0x438d0c,_0x197cfb){const _0x297ae6=_0x17231b;return db['ZohoAccount']['findOne']({'where':{'id':_0x438d0c['params']['id']}})['then'](handleEntityNotFound(_0x197cfb,null))[_0x297ae6('0x10')](removeEntity(_0x197cfb,null))['catch'](handleError(_0x197cfb,null));},exports[_0x17231b('0x31')]=function(_0x3f2258,_0x5b64a2){const _0x40f700=_0x17231b;let _0x391a9e={};const _0x15bfb3={};let _0x205011,_0x19583b;return db[_0x40f700('0xb')][_0x40f700('0x6')]({'where':{'id':_0x3f2258[_0x40f700('0x37')]['id']}})['then'](handleEntityNotFound(_0x5b64a2,null))[_0x40f700('0x10')](function(_0x4bdc5d){const _0xafa281=_0x40f700;if(_0x4bdc5d)return _0x205011=_0x4bdc5d,_0x15bfb3[_0xafa281('0x51')]=_[_0xafa281('0x25')](db[_0xafa281('0x2f')]['rawAttributes']),_0x15bfb3[_0xafa281('0x61')]=_[_0xafa281('0x25')](_0x3f2258[_0xafa281('0x61')]),_0x15bfb3['filters']=_[_0xafa281('0x44')](_0x15bfb3[_0xafa281('0x51')],_0x15bfb3[_0xafa281('0x61')]),_0x391a9e[_0xafa281('0x2e')]=_['intersection'](_0x15bfb3[_0xafa281('0x51')],qs[_0xafa281('0xa')](_0x3f2258[_0xafa281('0x61')][_0xafa281('0xa')])),_0x391a9e[_0xafa281('0x2e')]=_0x391a9e[_0xafa281('0x2e')][_0xafa281('0x4d')]?_0x391a9e[_0xafa281('0x2e')]:_0x15bfb3[_0xafa281('0x51')],_0x391a9e['order']=qs['sort'](_0x3f2258[_0xafa281('0x61')]['sort']),_0x391a9e[_0xafa281('0x3b')]=qs[_0xafa281('0xe')](_[_0xafa281('0x5f')](_0x3f2258[_0xafa281('0x61')],_0x15bfb3[_0xafa281('0xe')])),_0x3f2258[_0xafa281('0x61')][_0xafa281('0x17')]&&(_0x391a9e[_0xafa281('0x3b')]=_[_0xafa281('0x28')](_0x391a9e[_0xafa281('0x3b')],{[Op['or']]:_[_0xafa281('0x2b')](_0x391a9e[_0xafa281('0x2e')],function(_0x125994){const _0x1c9e9b=_0xafa281,_0x13a916={};return _0x13a916[_0x125994]={[Op['like']]:'%'+_0x3f2258[_0x1c9e9b('0x61')][_0x1c9e9b('0x17')]+'%'},_0x13a916;})})),_0x391a9e=_[_0xafa281('0x28')]({},_0x391a9e,_0x3f2258[_0xafa281('0x4')]),_0x205011['getConfigurations'](_0x391a9e);})[_0x40f700('0x10')](function(_0x2ca6da){const _0x3c5a08=_0x40f700;if(_0x2ca6da)return _0x19583b=_0x2ca6da[_0x3c5a08('0x4d')],typeof _0x3f2258[_0x3c5a08('0x61')][_0x3c5a08('0x52')]===_0x3c5a08('0x3c')&&(_0x391a9e[_0x3c5a08('0x1a')]=qs['limit'](_0x3f2258[_0x3c5a08('0x61')][_0x3c5a08('0x1a')]),_0x391a9e['offset']=qs[_0x3c5a08('0x20')](_0x3f2258[_0x3c5a08('0x61')][_0x3c5a08('0x20')])),_0x205011[_0x3c5a08('0x31')](_0x391a9e);})['then'](function(_0x510a72){if(_0x510a72)return _0x510a72?{'count':_0x19583b,'rows':_0x510a72}:null;})[_0x40f700('0x10')](respondWithResult(_0x5b64a2,null))[_0x40f700('0x47')](handleError(_0x5b64a2,null));},exports['addConfiguration']=function(_0x373517,_0x39258c){const _0x36350a=_0x17231b;return _0x373517[_0x36350a('0x11')]['id']&&delete _0x373517[_0x36350a('0x11')]['id'],db[_0x36350a('0xb')][_0x36350a('0x6')]({'where':{'id':_0x373517[_0x36350a('0x37')]['id']}})[_0x36350a('0x10')](handleEntityNotFound(_0x39258c,null))[_0x36350a('0x10')](function(_0x5e667f){const _0x4ac2be=_0x36350a;if(_0x5e667f)return _0x373517['body']['AccountId']=_0x5e667f['id'],_0x373517[_0x4ac2be('0x11')][_0x4ac2be('0x5a')]=integrations['getSubjects'](_0x373517[_0x4ac2be('0x11')]['channel'],_0x373517[_0x4ac2be('0x11')]['type']),_0x373517['body'][_0x4ac2be('0x62')]=integrations[_0x4ac2be('0x19')](_0x373517[_0x4ac2be('0x11')]['channel'],_0x373517['body'][_0x4ac2be('0x41')]),db[_0x4ac2be('0x2f')][_0x4ac2be('0x4f')](_0x373517[_0x4ac2be('0x11')],{'include':[{'model':db[_0x4ac2be('0x58')],'as':'Subjects'},{'model':db['ZohoField'],'as':'Descriptions'}]});return null;})[_0x36350a('0x10')](respondWithResult(_0x39258c,null))['catch'](handleError(_0x39258c,null));};function getAccessToken(_0x241a1c){return new Promise(function(_0x19c596,_0x24ebbd){const _0x2a9424=a346_0xacaf;let _0x4fc6ff;switch(_0x241a1c[_0x2a9424('0x5b')]){case'US':_0x4fc6ff='https://accounts.zoho.com';break;case'AU':_0x4fc6ff=_0x2a9424('0x4e');break;case'EU':_0x4fc6ff=_0x2a9424('0x42');break;case'IN':_0x4fc6ff=_0x2a9424('0x1b');break;case'CN':_0x4fc6ff=_0x2a9424('0x54');break;default:_0x4fc6ff=_0x2a9424('0x42');break;}const _0x108a13={'method':_0x2a9424('0x24'),'uri':_0x4fc6ff+_0x2a9424('0x55'),'qs':{'refresh_token':_0x241a1c[_0x2a9424('0x43')],'client_id':_0x241a1c[_0x2a9424('0x1e')],'client_secret':_0x241a1c[_0x2a9424('0x65')],'grant_type':_0x2a9424('0x3e')},'json':!![]};return rp(_0x108a13)['then'](function(_0x55620a){const _0x523284=_0x2a9424;_0x55620a[_0x523284('0x23')]?_0x19c596(_0x55620a[_0x523284('0x23')]):_0x24ebbd(_0x523284('0x39'));})[_0x2a9424('0x47')](function(_0x5132f6){_0x24ebbd(_0x5132f6);});});}exports[_0x17231b('0x36')]=function(_0x1fc843,_0x7db004){const _0x1bd4e9=_0x17231b;let _0x3daaf5,_0x541877,_0x256a5d,_0x3e2c71;return db[_0x1bd4e9('0xb')][_0x1bd4e9('0x6')]({'where':{'id':_0x1fc843['params']['id']},'attributes':['id',_0x1bd4e9('0x5'),_0x1bd4e9('0x5b'),_0x1bd4e9('0x1e'),'clientSecret',_0x1bd4e9('0x29'),_0x1bd4e9('0x21'),'refreshToken']})['then'](handleEntityNotFound(_0x7db004,null))['then'](function(_0x3fec5c){const _0x3f4c92=_0x1bd4e9;_0x3e2c71=_0x3fec5c,_0x3daaf5=_0x3e2c71[_0x3f4c92('0x5')],_0x541877=_0x3daaf5==='zoho.eu'?'eu':_0x3f4c92('0x2a'),_0x256a5d=_0x3e2c71[_0x3f4c92('0x29')];const _0x2e5ce0=_0x256a5d[_0x3f4c92('0x14')](-0x1);(_0x2e5ce0==='/'||_0x2e5ce0==='\x5c'||_0x2e5ce0===':')&&(_0x256a5d=_0x256a5d[_0x3f4c92('0x35')](0x0,_0x256a5d[_0x3f4c92('0x8')](_0x2e5ce0)));if(!_0x3e2c71[_0x3f4c92('0x43')])throw new Error(_0x3f4c92('0x12'));return getAccessToken(_0x3e2c71);})[_0x1bd4e9('0x10')](function(_0x1d661b){const _0x301e60=_0x1bd4e9;if(_0x1d661b)return rp({'method':_0x301e60('0x32'),'uri':util['format'](_0x301e60('0x56'),_0x541877),'qs':{'module':'Calls'},'headers':{'Authorization':_0x301e60('0x0')+_0x1d661b},'json':!![]});})['then'](function(_0x2eaa5e){const _0x2201df=_0x1bd4e9;if(_0x2eaa5e){if(_0x2eaa5e[_0x2201df('0x26')]&&_0x2eaa5e[_0x2201df('0x26')]['error'])throw new Error(_0x2eaa5e['response'][_0x2201df('0x5e')][_0x2201df('0x5d')]);const _0x3dde59=[];let _0x10cd3e=[];const _0x110dce=[_0x2201df('0x18'),'Subject',_0x2201df('0x22'),_0x2201df('0x9'),_0x2201df('0x49'),_0x2201df('0xd'),_0x2201df('0x30'),_0x2201df('0x34')];_0x10cd3e=_['remove'](_0x2eaa5e['fields'],function(_0xfb5e87){const _0x39fa6c=_0x2201df;return _0x110dce[_0x39fa6c('0x27')](_0xfb5e87[_0x39fa6c('0xf')]);});for(let _0x55a152=0x0;_0x55a152<_0x10cd3e[_0x2201df('0x4d')];_0x55a152++){_0x10cd3e[_0x55a152][_0x2201df('0x38')]===![]&&_0x3dde59['push']({'id':_0x10cd3e[_0x55a152]['id'],'name':_0x10cd3e[_0x55a152][_0x2201df('0x5c')],'custom':_0x10cd3e[_0x55a152][_0x2201df('0x53')],'options':_0x10cd3e[_0x55a152]['data_type']===_0x2201df('0x46')&&_0x10cd3e[_0x55a152][_0x2201df('0x60')][_0x2201df('0x4d')]>-0x1?_[_0x2201df('0x2b')](_0x10cd3e[_0x55a152]['pick_list_values'],function(_0x253038){return{'name':_0x253038,'value':_0x253038};}):[]});}return{'count':_0x3dde59[_0x2201df('0x4d')],'rows':_0x3dde59};}else return{'count':0x0,'rows':[]};})[_0x1bd4e9('0x10')](respondWithResult(_0x7db004,null))['catch'](function(_0x46c2f0){const _0x29f41b=_0x1bd4e9;let _0x23e200=_0x1fc843[_0x29f41b('0x61')][_0x29f41b('0x15')]?0x1f4:_0x46c2f0[_0x29f41b('0x3d')]||0x1f4;logger[_0x29f41b('0x5e')](_0x29f41b('0x66'),_0x29f41b('0x36'),_0x23e200,JSON[_0x29f41b('0x33')](_0x46c2f0)),delete _0x46c2f0[_0x29f41b('0x1d')],_0x23e200===0x191&&(_0x23e200=0x190),_0x7db004['status'](_0x23e200)['send'](_0x1fc843[_0x29f41b('0x61')][_0x29f41b('0x15')]?{'message':_0x29f41b('0x4c'),'statusCode':_0x46c2f0[_0x29f41b('0x3d')]}:_0x46c2f0);});};