c5721bd87d50531362b6efcc42b5918f17ae7035
[motion-next.git] / server / api / intZohoAccount / intZohoAccount.controller.js
1 const a416_0x29a4=['api_name','params','stringify','catch','keys','index','refresh_token','query','pick','https://accounts.zoho.com','refreshToken','update','end','../../config/logger','getFields','https://accounts.zoho.com.cn','api','message','display_label','includeAll','Subject','GET','create','data_type','../../components/parsers/qs','filters','show','include','lastIndexOf','sort','json','destroy','status','Call_Result','rawAttributes','channel','zone','body','AccountId','ZohoAccount','../../components/integrations/configuration','options','Unable\x20to\x20retrieve\x20the\x20access\x20token','pick_list_values','merge','picklist','rows','sendStatus','count','stack','format','where','findAll','ZohoConfiguration','filter','nolimit','clientId','VIRTUAL','order','getConfigurations','Wrong\x20credentials','name','POST','https://accounts.zoho.eu','key','intersection','Subjects','undefined','then','error','com','offset','/oauth/v2/token','Refresh\x20Token\x20not\x20available\x20for\x20the\x20account','getDescriptions','https://www.zohoapis.%s/crm/v2/settings/fields','lodash','slice','Descriptions','Zoho-oauthtoken\x20','type','sequelize','host','attributes','WhoId','Call_Type','ZohoField','findOne','send','test','custom_field','like','https://accounts.zoho.in','model','util','fields','limit','length','push','Call_Duration','fieldName','request-promise-native','Content-Range','includes','statusCode','serverUrl','map','https://accounts.zoho.com.au'];(function(_0x1a71b1,_0x2efd8e){const _0x29a4f8=function(_0x46ffa7){while(--_0x46ffa7){_0x1a71b1['push'](_0x1a71b1['shift']());}};_0x29a4f8(++_0x2efd8e);}(a416_0x29a4,0xd1));const a416_0x46ff=function(_0x1a71b1,_0x2efd8e){_0x1a71b1=_0x1a71b1-0xc5;let _0x29a4f8=a416_0x29a4[_0x1a71b1];return _0x29a4f8;};const a416_0x57451e=a416_0x46ff;'use strict';const rp=require(a416_0x57451e(0xc5)),util=require(a416_0x57451e(0x12a)),_=require(a416_0x57451e(0x118)),qs=require(a416_0x57451e(0xe4)),logger=require(a416_0x57451e(0xd9))(a416_0x57451e(0xdc)),{db}=require('../../mysqldb'),{Op}=require(a416_0x57451e(0x11d)),integrations=require(a416_0x57451e(0xf4));function respondWithResult(_0xa8c934,_0x395bef){return _0x395bef=_0x395bef||0xc8,function(_0x1cc2ac){const _0x1690fc=a416_0x46ff;if(_0x1cc2ac)return _0xa8c934['status'](_0x395bef)[_0x1690fc(0xea)](_0x1cc2ac);};}function respondWithFilteredResult(_0x3aec16,_0xb07bf5){return function(_0x460168){const _0x19ea58=a416_0x46ff;if(_0x460168){const _0x518f2b=_0x460168[_0x19ea58(0xfc)],_0x3b9375=_0xb07bf5['offset'];let _0x2f3176=_0xb07bf5[_0x19ea58(0x113)]+_0xb07bf5[_0x19ea58(0x12c)],_0x51948e;return _0x2f3176>=_0x518f2b?(_0x2f3176=_0x518f2b,_0x51948e=0xc8):_0x51948e=0xce,_0x3aec16['status'](_0x51948e),_0x3aec16['set'](_0x19ea58(0xc6),_0x3b9375+'-'+_0x2f3176+'/'+_0x518f2b)[_0x19ea58(0xea)](_0x460168);}return null;};}function saveUpdates(_0x507822){return function(_0x2b4bd6){const _0x4a818d=a416_0x46ff;if(_0x2b4bd6)return _0x2b4bd6['update'](_0x507822)[_0x4a818d(0x110)](function(_0x58d35b){return _0x58d35b;});return null;};}function removeEntity(_0x242e94){return function(_0x527d9b){const _0x54465e=a416_0x46ff;if(_0x527d9b)return _0x527d9b[_0x54465e(0xeb)]()[_0x54465e(0x110)](function(){const _0x462d51=_0x54465e;_0x242e94[_0x462d51(0xec)](0xcc)[_0x462d51(0xd8)]();});};}function handleEntityNotFound(_0x520317){return function(_0x5be21d){const _0x2b9247=a416_0x46ff;return!_0x5be21d&&_0x520317[_0x2b9247(0xfb)](0x194),_0x5be21d;};}function handleError(_0x4e22cb,_0x1a5654){return _0x1a5654=_0x1a5654||0x1f4,function(_0xcb0821){const _0x493aea=a416_0x46ff;logger[_0x493aea(0x111)](_0xcb0821[_0x493aea(0xfd)]),_0xcb0821[_0x493aea(0x109)]&&delete _0xcb0821[_0x493aea(0x109)],_0x4e22cb[_0x493aea(0xec)](_0x1a5654)['send'](_0xcb0821);};}exports[a416_0x57451e(0xd1)]=function(_0x5df985,_0x582601){const _0x5e52f8=a416_0x57451e;let _0x577867={};const _0x2c60ea={},_0xd36b6={'count':0x0,'rows':[]},_0x104a54=_['map'](db[_0x5e52f8(0xf3)][_0x5e52f8(0xee)],function(_0x14ff89){const _0x2742d3=_0x5e52f8;return{'name':_0x14ff89[_0x2742d3(0x130)],'type':_0x14ff89[_0x2742d3(0x11c)][_0x2742d3(0x10c)]};});_0x2c60ea[_0x5e52f8(0x129)]=_[_0x5e52f8(0xca)](_0x104a54,_0x5e52f8(0x109)),_0x2c60ea[_0x5e52f8(0xd3)]=_[_0x5e52f8(0xd0)](_0x5df985['query']),_0x2c60ea[_0x5e52f8(0xe5)]=_[_0x5e52f8(0x10d)](_0x2c60ea[_0x5e52f8(0x129)],_0x2c60ea[_0x5e52f8(0xd3)]),_0x577867[_0x5e52f8(0x11f)]=_[_0x5e52f8(0x10d)](_0x2c60ea[_0x5e52f8(0x129)],qs[_0x5e52f8(0x12b)](_0x5df985[_0x5e52f8(0xd3)][_0x5e52f8(0x12b)])),_0x577867[_0x5e52f8(0x11f)]=_0x577867['attributes'][_0x5e52f8(0x12d)]?_0x577867[_0x5e52f8(0x11f)]:_0x2c60ea[_0x5e52f8(0x129)];typeof _0x5df985['query'][_0x5e52f8(0x103)]===_0x5e52f8(0x10f)&&(_0x577867[_0x5e52f8(0x12c)]=qs[_0x5e52f8(0x12c)](_0x5df985[_0x5e52f8(0xd3)][_0x5e52f8(0x12c)]),_0x577867[_0x5e52f8(0x113)]=qs[_0x5e52f8(0x113)](_0x5df985[_0x5e52f8(0xd3)][_0x5e52f8(0x113)]));_0x577867[_0x5e52f8(0x106)]=qs[_0x5e52f8(0xe9)](_0x5df985[_0x5e52f8(0xd3)][_0x5e52f8(0xe9)]),_0x577867[_0x5e52f8(0xff)]=qs[_0x5e52f8(0xe5)](_['pick'](_0x5df985['query'],_0x2c60ea[_0x5e52f8(0xe5)]),_0x104a54);_0x5df985[_0x5e52f8(0xd3)][_0x5e52f8(0x102)]&&(_0x577867[_0x5e52f8(0xff)]=_[_0x5e52f8(0xf8)](_0x577867[_0x5e52f8(0xff)],{[Op['or']]:_[_0x5e52f8(0xca)](_0x104a54,function(_0x565a8f){const _0x2ca83f=_0x5e52f8;if(_0x565a8f[_0x2ca83f(0x11c)]!==_0x2ca83f(0x105)){const _0x3479d7={};return _0x3479d7[_0x565a8f[_0x2ca83f(0x109)]]={[Op[_0x2ca83f(0x127)]]:'%'+_0x5df985[_0x2ca83f(0xd3)]['filter']+'%'},_0x3479d7;}})}));_0x577867=_[_0x5e52f8(0xf8)]({},_0x577867,_0x5df985[_0x5e52f8(0xf5)]);const _0x2c980a={'where':_0x577867[_0x5e52f8(0xff)]};return db[_0x5e52f8(0xf3)][_0x5e52f8(0xfc)](_0x2c980a)[_0x5e52f8(0x110)](function(_0x361d76){const _0x5c2cf=_0x5e52f8;return _0xd36b6[_0x5c2cf(0xfc)]=_0x361d76,_0x5df985[_0x5c2cf(0xd3)][_0x5c2cf(0xdf)]&&(_0x577867[_0x5c2cf(0xe7)]=[{'all':!![]}]),db[_0x5c2cf(0xf3)][_0x5c2cf(0x100)](_0x577867);})[_0x5e52f8(0x110)](function(_0x23956b){const _0x15a34e=_0x5e52f8;return _0xd36b6[_0x15a34e(0xfa)]=_0x23956b,_0xd36b6;})['then'](respondWithFilteredResult(_0x582601,_0x577867))[_0x5e52f8(0xcf)](handleError(_0x582601,null));},exports[a416_0x57451e(0xe6)]=function(_0x259ab7,_0x28d84a){const _0x280a17=a416_0x57451e;let _0x13933={'raw':![],'where':{'id':_0x259ab7[_0x280a17(0xcd)]['id']}};const _0x2d7b9e={};return _0x2d7b9e[_0x280a17(0x129)]=_[_0x280a17(0xd0)](db[_0x280a17(0xf3)][_0x280a17(0xee)]),_0x2d7b9e['query']=_[_0x280a17(0xd0)](_0x259ab7[_0x280a17(0xd3)]),_0x2d7b9e[_0x280a17(0xe5)]=_[_0x280a17(0x10d)](_0x2d7b9e[_0x280a17(0x129)],_0x2d7b9e['query']),_0x13933['attributes']=_[_0x280a17(0x10d)](_0x2d7b9e[_0x280a17(0x129)],qs['fields'](_0x259ab7[_0x280a17(0xd3)][_0x280a17(0x12b)])),_0x13933['attributes']=_0x13933['attributes']['length']?_0x13933[_0x280a17(0x11f)]:_0x2d7b9e[_0x280a17(0x129)],_0x259ab7['query'][_0x280a17(0xdf)]&&(_0x13933[_0x280a17(0xe7)]=[{'all':!![]}]),_0x13933=_[_0x280a17(0xf8)]({},_0x13933,_0x259ab7['options']),db[_0x280a17(0xf3)][_0x280a17(0x123)](_0x13933)[_0x280a17(0x110)](handleEntityNotFound(_0x28d84a,null))[_0x280a17(0x110)](respondWithResult(_0x28d84a,null))[_0x280a17(0xcf)](handleError(_0x28d84a,null));},exports[a416_0x57451e(0xe2)]=function(_0x308bfa,_0x2305cb){const _0x5b2c40=a416_0x57451e;return db[_0x5b2c40(0xf3)][_0x5b2c40(0xe2)](_0x308bfa['body'],{})[_0x5b2c40(0x110)](respondWithResult(_0x2305cb,0xc9))[_0x5b2c40(0xcf)](handleError(_0x2305cb,null));},exports[a416_0x57451e(0xd7)]=function(_0x41a35d,_0x1e1cb9){const _0x5a0361=a416_0x57451e;return _0x41a35d[_0x5a0361(0xf1)]['id']&&delete _0x41a35d['body']['id'],db[_0x5a0361(0xf3)][_0x5a0361(0x123)]({'where':{'id':_0x41a35d[_0x5a0361(0xcd)]['id']}})[_0x5a0361(0x110)](handleEntityNotFound(_0x1e1cb9,null))[_0x5a0361(0x110)](saveUpdates(_0x41a35d[_0x5a0361(0xf1)],null))[_0x5a0361(0x110)](respondWithResult(_0x1e1cb9,null))[_0x5a0361(0xcf)](handleError(_0x1e1cb9,null));},exports['destroy']=function(_0x3aa5f7,_0x4d905a){const _0x4b6a2a=a416_0x57451e;return db['ZohoAccount'][_0x4b6a2a(0x123)]({'where':{'id':_0x3aa5f7[_0x4b6a2a(0xcd)]['id']}})[_0x4b6a2a(0x110)](handleEntityNotFound(_0x4d905a,null))[_0x4b6a2a(0x110)](removeEntity(_0x4d905a,null))[_0x4b6a2a(0xcf)](handleError(_0x4d905a,null));},exports[a416_0x57451e(0x107)]=function(_0x4d762c,_0x37b34b){const _0x118d75=a416_0x57451e;let _0x563f82={};const _0x233c48={};let _0x3bbc7d,_0x15edc3;return db[_0x118d75(0xf3)][_0x118d75(0x123)]({'where':{'id':_0x4d762c[_0x118d75(0xcd)]['id']}})[_0x118d75(0x110)](handleEntityNotFound(_0x37b34b,null))[_0x118d75(0x110)](function(_0x4066d3){const _0x18f42b=_0x118d75;if(_0x4066d3)return _0x3bbc7d=_0x4066d3,_0x233c48['model']=_[_0x18f42b(0xd0)](db['ZohoConfiguration'][_0x18f42b(0xee)]),_0x233c48[_0x18f42b(0xd3)]=_[_0x18f42b(0xd0)](_0x4d762c['query']),_0x233c48['filters']=_['intersection'](_0x233c48[_0x18f42b(0x129)],_0x233c48[_0x18f42b(0xd3)]),_0x563f82['attributes']=_[_0x18f42b(0x10d)](_0x233c48[_0x18f42b(0x129)],qs['fields'](_0x4d762c[_0x18f42b(0xd3)][_0x18f42b(0x12b)])),_0x563f82[_0x18f42b(0x11f)]=_0x563f82[_0x18f42b(0x11f)]['length']?_0x563f82['attributes']:_0x233c48[_0x18f42b(0x129)],_0x563f82[_0x18f42b(0x106)]=qs['sort'](_0x4d762c['query']['sort']),_0x563f82['where']=qs[_0x18f42b(0xe5)](_[_0x18f42b(0xd4)](_0x4d762c[_0x18f42b(0xd3)],_0x233c48['filters'])),_0x4d762c[_0x18f42b(0xd3)][_0x18f42b(0x102)]&&(_0x563f82['where']=_[_0x18f42b(0xf8)](_0x563f82['where'],{[Op['or']]:_['map'](_0x563f82[_0x18f42b(0x11f)],function(_0x38155b){const _0x3c2c4b=_0x18f42b,_0x479b9d={};return _0x479b9d[_0x38155b]={[Op['like']]:'%'+_0x4d762c[_0x3c2c4b(0xd3)]['filter']+'%'},_0x479b9d;})})),_0x563f82=_['merge']({},_0x563f82,_0x4d762c[_0x18f42b(0xf5)]),_0x3bbc7d[_0x18f42b(0x107)](_0x563f82);})['then'](function(_0x2f241a){const _0x5334a0=_0x118d75;if(_0x2f241a)return _0x15edc3=_0x2f241a[_0x5334a0(0x12d)],typeof _0x4d762c['query'][_0x5334a0(0x103)]===_0x5334a0(0x10f)&&(_0x563f82[_0x5334a0(0x12c)]=qs[_0x5334a0(0x12c)](_0x4d762c['query']['limit']),_0x563f82[_0x5334a0(0x113)]=qs['offset'](_0x4d762c[_0x5334a0(0xd3)][_0x5334a0(0x113)])),_0x3bbc7d[_0x5334a0(0x107)](_0x563f82);})[_0x118d75(0x110)](function(_0x2c90da){if(_0x2c90da)return _0x2c90da?{'count':_0x15edc3,'rows':_0x2c90da}:null;})['then'](respondWithResult(_0x37b34b,null))[_0x118d75(0xcf)](handleError(_0x37b34b,null));},exports['addConfiguration']=function(_0x565085,_0x3f9d83){const _0x2cf809=a416_0x57451e;return _0x565085[_0x2cf809(0xf1)]['id']&&delete _0x565085['body']['id'],db[_0x2cf809(0xf3)]['findOne']({'where':{'id':_0x565085[_0x2cf809(0xcd)]['id']}})[_0x2cf809(0x110)](handleEntityNotFound(_0x3f9d83,null))[_0x2cf809(0x110)](function(_0x130199){const _0x1b0fcf=_0x2cf809;if(_0x130199)return _0x565085[_0x1b0fcf(0xf1)][_0x1b0fcf(0xf2)]=_0x130199['id'],_0x565085[_0x1b0fcf(0xf1)][_0x1b0fcf(0x10e)]=integrations['getSubjects'](_0x565085[_0x1b0fcf(0xf1)][_0x1b0fcf(0xef)],_0x565085['body']['type']),_0x565085[_0x1b0fcf(0xf1)][_0x1b0fcf(0x11a)]=integrations[_0x1b0fcf(0x116)](_0x565085['body'][_0x1b0fcf(0xef)],_0x565085['body'][_0x1b0fcf(0x11c)]),db[_0x1b0fcf(0x101)][_0x1b0fcf(0xe2)](_0x565085[_0x1b0fcf(0xf1)],{'include':[{'model':db['ZohoField'],'as':'Subjects'},{'model':db[_0x1b0fcf(0x122)],'as':'Descriptions'}]});return null;})['then'](respondWithResult(_0x3f9d83,null))[_0x2cf809(0xcf)](handleError(_0x3f9d83,null));};function getAccessToken(_0x66cb5f){return new Promise(function(_0x2cf2d5,_0x1d1b4f){const _0x30819c=a416_0x46ff;let _0x59224f;switch(_0x66cb5f[_0x30819c(0xf0)]){case'US':_0x59224f=_0x30819c(0xd5);break;case'AU':_0x59224f=_0x30819c(0xcb);break;case'EU':_0x59224f=_0x30819c(0x10b);break;case'IN':_0x59224f=_0x30819c(0x128);break;case'CN':_0x59224f=_0x30819c(0xdb);break;default:_0x59224f=_0x30819c(0x10b);break;}const _0x5e3909={'method':_0x30819c(0x10a),'uri':_0x59224f+_0x30819c(0x114),'qs':{'refresh_token':_0x66cb5f[_0x30819c(0xd6)],'client_id':_0x66cb5f['clientId'],'client_secret':_0x66cb5f['clientSecret'],'grant_type':_0x30819c(0xd2)},'json':!![]};return rp(_0x5e3909)[_0x30819c(0x110)](function(_0x124458){const _0x1a4fe2=_0x30819c;_0x124458['access_token']?_0x2cf2d5(_0x124458['access_token']):_0x1d1b4f(_0x1a4fe2(0xf6));})[_0x30819c(0xcf)](function(_0x4ebc32){_0x1d1b4f(_0x4ebc32);});});}exports[a416_0x57451e(0xda)]=function(_0x1d9e5c,_0x3b9647){const _0xc26967=a416_0x57451e;let _0x3c213d,_0x38c0dd,_0x1a13af,_0x26f405;return db[_0xc26967(0xf3)]['findOne']({'where':{'id':_0x1d9e5c['params']['id']},'attributes':['id',_0xc26967(0x11e),_0xc26967(0xf0),_0xc26967(0x104),'clientSecret',_0xc26967(0xc9),'code',_0xc26967(0xd6)]})[_0xc26967(0x110)](handleEntityNotFound(_0x3b9647,null))[_0xc26967(0x110)](function(_0x3cd688){const _0x49ee99=_0xc26967;_0x26f405=_0x3cd688,_0x3c213d=_0x26f405[_0x49ee99(0x11e)],_0x38c0dd=_0x3c213d==='zoho.eu'?'eu':_0x49ee99(0x112),_0x1a13af=_0x26f405['serverUrl'];const _0x4ede60=_0x1a13af[_0x49ee99(0x119)](-0x1);(_0x4ede60==='/'||_0x4ede60==='\x5c'||_0x4ede60===':')&&(_0x1a13af=_0x1a13af['substring'](0x0,_0x1a13af[_0x49ee99(0xe8)](_0x4ede60)));if(!_0x26f405[_0x49ee99(0xd6)])throw new Error(_0x49ee99(0x115));return getAccessToken(_0x26f405);})[_0xc26967(0x110)](function(_0x35a47f){const _0x5c70a8=_0xc26967;if(_0x35a47f)return rp({'method':_0x5c70a8(0xe1),'uri':util[_0x5c70a8(0xfe)](_0x5c70a8(0x117),_0x38c0dd),'qs':{'module':'Calls'},'headers':{'Authorization':_0x5c70a8(0x11b)+_0x35a47f},'json':!![]});})[_0xc26967(0x110)](function(_0x3ed60c){const _0x121f26=_0xc26967;if(_0x3ed60c){if(_0x3ed60c['response']&&_0x3ed60c['response'][_0x121f26(0x111)])throw new Error(_0x3ed60c['response'][_0x121f26(0x111)][_0x121f26(0xdd)]);const _0x5dd662=[];let _0x2fe5de=[];const _0x210d1f=['Owner',_0x121f26(0xe0),'Description',_0x121f26(0x120),_0x121f26(0x12f),_0x121f26(0xed),'Call_Start_Time',_0x121f26(0x121)];_0x2fe5de=_['remove'](_0x3ed60c[_0x121f26(0x12b)],function(_0x32635c){const _0x58cc39=_0x121f26;return _0x210d1f[_0x58cc39(0xc7)](_0x32635c[_0x58cc39(0xcc)]);});for(let _0x46e21d=0x0;_0x46e21d<_0x2fe5de[_0x121f26(0x12d)];_0x46e21d++){_0x2fe5de[_0x46e21d]['system_mandatory']===![]&&_0x5dd662[_0x121f26(0x12e)]({'id':_0x2fe5de[_0x46e21d]['id'],'name':_0x2fe5de[_0x46e21d][_0x121f26(0xde)],'custom':_0x2fe5de[_0x46e21d][_0x121f26(0x126)],'options':_0x2fe5de[_0x46e21d][_0x121f26(0xe3)]===_0x121f26(0xf9)&&_0x2fe5de[_0x46e21d][_0x121f26(0xf7)][_0x121f26(0x12d)]>-0x1?_[_0x121f26(0xca)](_0x2fe5de[_0x46e21d][_0x121f26(0xf7)],function(_0x20e66f){return{'name':_0x20e66f,'value':_0x20e66f};}):[]});}return{'count':_0x5dd662[_0x121f26(0x12d)],'rows':_0x5dd662};}else return{'count':0x0,'rows':[]};})[_0xc26967(0x110)](respondWithResult(_0x3b9647,null))['catch'](function(_0x57c258){const _0x174e29=_0xc26967;let _0x5f4e3a=_0x1d9e5c['query'][_0x174e29(0x125)]?0x1f4:_0x57c258[_0x174e29(0xc8)]||0x1f4;logger[_0x174e29(0x111)]('getFields,\x20%s,\x20%s,\x20%s',_0x174e29(0xda),_0x5f4e3a,JSON[_0x174e29(0xce)](_0x57c258)),delete _0x57c258[_0x174e29(0x109)],_0x5f4e3a===0x191&&(_0x5f4e3a=0x190),_0x3b9647['status'](_0x5f4e3a)[_0x174e29(0x124)](_0x1d9e5c['query'][_0x174e29(0x125)]?{'message':_0x174e29(0x108),'statusCode':_0x57c258[_0x174e29(0xc8)]}:_0x57c258);});};