ce1df59f37bce6919168924ad05610fe6154817d
[motion-next.git] / server / api / intZendeskAccount / intZendeskAccount.controller.js
1 const a333_0x4152=['rows','destroy','then','keys','fields','system_field_options','update','like','params','GET','Descriptions','ZendeskAccount','type','format','channel','key','intersection','error','../../components/integrations/configuration','getSubjects','length','Wrong\x20credentials','set','filter','toString','index','includeAll','position','getFields','limit','subject','map','Content-Range','show','undefined','../../components/parsers/qs','options','findOne','end','findAll','ZendeskConfiguration','catch','filters','statusCode','headers','%s/token:%s','addConfiguration','name','test','token','substring','username','create','count','lodash','Unknown\x20authentication\x20type','getConfigurations','remoteUri','sendStatus','../../mysqldb','../../config/logger','Basic\x20%s','body','assignee','attributes','merge','includes','%s:%s','rawAttributes','stringify','authType','where','fieldName','VIRTUAL','sort','password','slice','remove','order','offset','Subjects','model','json','api','status','include','sequelize','query','lastIndexOf','custom_field_options','ticket_fields','pick','AccountId','util','nolimit'];(function(_0xf74993,_0x41520e){const _0x435726=function(_0x37ad3a){while(--_0x37ad3a){_0xf74993['push'](_0xf74993['shift']());}};_0x435726(++_0x41520e);}(a333_0x4152,0xe4));const a333_0x4357=function(_0xf74993,_0x41520e){_0xf74993=_0xf74993-0x0;let _0x435726=a333_0x4152[_0xf74993];return _0x435726;};const _0x4d292d=a333_0x4357;'use strict';const rp=require('request-promise-native'),util=require(_0x4d292d('0x37')),_=require(_0x4d292d('0x10')),qs=require(_0x4d292d('0x5c')),logger=require(_0x4d292d('0x16'))(_0x4d292d('0x2d')),db=require(_0x4d292d('0x15'))['db'],{Op,ValidationError}=require(_0x4d292d('0x30')),integrations=require(_0x4d292d('0x4b'));function respondWithResult(_0x37ad3a,_0x4f09e3){return _0x4f09e3=_0x4f09e3||0xc8,function(_0x17adc1){const _0x52080d=a333_0x4357;if(_0x17adc1)return _0x37ad3a[_0x52080d('0x2e')](_0x4f09e3)[_0x52080d('0x2c')](_0x17adc1);};}function respondWithFilteredResult(_0x38a695,_0x517e71){return function(_0x2153b0){const _0x518754=a333_0x4357;if(_0x2153b0){const _0xbd4d9e=_0x2153b0[_0x518754('0xf')],_0x39ff3f=_0x517e71[_0x518754('0x29')];let _0x1dd3e9=_0x517e71['offset']+_0x517e71['limit'],_0x4eab7f;return _0x1dd3e9>=_0xbd4d9e?(_0x1dd3e9=_0xbd4d9e,_0x4eab7f=0xc8):_0x4eab7f=0xce,_0x38a695[_0x518754('0x2e')](_0x4eab7f),_0x38a695[_0x518754('0x4f')](_0x518754('0x59'),_0x39ff3f+'-'+_0x1dd3e9+'/'+_0xbd4d9e)[_0x518754('0x2c')](_0x2153b0);}return null;};}function saveUpdates(_0x821cb2){return function(_0x3c3d7c){const _0x52947d=a333_0x4357;if(_0x3c3d7c)return _0x3c3d7c['update'](_0x821cb2)[_0x52947d('0x3b')](function(_0x2714c4){return _0x2714c4;});return null;};}function removeEntity(_0x485531){return function(_0x2b3944){const _0x4ba2d7=a333_0x4357;if(_0x2b3944)return _0x2b3944[_0x4ba2d7('0x3a')]()[_0x4ba2d7('0x3b')](function(){const _0x47c7e7=_0x4ba2d7;_0x485531[_0x47c7e7('0x2e')](0xcc)[_0x47c7e7('0x0')]();});};}function handleEntityNotFound(_0x579ca6){return function(_0x27d3ab){const _0x147abe=a333_0x4357;return!_0x27d3ab&&_0x579ca6[_0x147abe('0x14')](0x194),_0x27d3ab;};}function handleError(_0x4a8751,_0x444865){return _0x444865=_0x444865||0x1f4,function(_0x6a42fc){const _0x200654=a333_0x4357;logger[_0x200654('0x4a')](_0x6a42fc['stack']),_0x6a42fc[_0x200654('0x9')]&&delete _0x6a42fc['name'],_0x4a8751[_0x200654('0x2e')](_0x444865)['send'](_0x6a42fc);};}exports[_0x4d292d('0x52')]=function(_0x427350,_0x15eaff){const _0x14e02b=_0x4d292d;let _0x68259e={};const _0xc91309={},_0x1daf9a={'count':0x0,'rows':[]},_0x3051d6=_[_0x14e02b('0x58')](db[_0x14e02b('0x44')][_0x14e02b('0x1e')],function(_0x52a7ed){const _0x1430db=_0x14e02b;return{'name':_0x52a7ed[_0x1430db('0x22')],'type':_0x52a7ed[_0x1430db('0x45')][_0x1430db('0x48')]};});_0xc91309[_0x14e02b('0x2b')]=_[_0x14e02b('0x58')](_0x3051d6,_0x14e02b('0x9')),_0xc91309['query']=_['keys'](_0x427350[_0x14e02b('0x31')]),_0xc91309[_0x14e02b('0x4')]=_[_0x14e02b('0x49')](_0xc91309[_0x14e02b('0x2b')],_0xc91309['query']),_0x68259e[_0x14e02b('0x1a')]=_[_0x14e02b('0x49')](_0xc91309[_0x14e02b('0x2b')],qs[_0x14e02b('0x3d')](_0x427350[_0x14e02b('0x31')][_0x14e02b('0x3d')])),_0x68259e[_0x14e02b('0x1a')]=_0x68259e[_0x14e02b('0x1a')][_0x14e02b('0x4d')]?_0x68259e[_0x14e02b('0x1a')]:_0xc91309[_0x14e02b('0x2b')];typeof _0x427350['query'][_0x14e02b('0x38')]==='undefined'&&(_0x68259e[_0x14e02b('0x56')]=qs['limit'](_0x427350['query'][_0x14e02b('0x56')]),_0x68259e[_0x14e02b('0x29')]=qs[_0x14e02b('0x29')](_0x427350[_0x14e02b('0x31')][_0x14e02b('0x29')]));_0x68259e[_0x14e02b('0x28')]=qs[_0x14e02b('0x24')](_0x427350[_0x14e02b('0x31')][_0x14e02b('0x24')]),_0x68259e[_0x14e02b('0x21')]=qs[_0x14e02b('0x4')](_[_0x14e02b('0x35')](_0x427350['query'],_0xc91309[_0x14e02b('0x4')]),_0x3051d6);_0x427350[_0x14e02b('0x31')]['filter']&&(_0x68259e[_0x14e02b('0x21')]=_[_0x14e02b('0x1b')](_0x68259e[_0x14e02b('0x21')],{[Op['or']]:_['map'](_0x3051d6,function(_0x34adce){const _0x5cdc3b=_0x14e02b;if(_0x34adce['type']!==_0x5cdc3b('0x23')){const _0x2a1a49={};return _0x2a1a49[_0x34adce['name']]={[Op[_0x5cdc3b('0x40')]]:'%'+_0x427350[_0x5cdc3b('0x31')]['filter']+'%'},_0x2a1a49;}})}));_0x68259e=_[_0x14e02b('0x1b')]({},_0x68259e,_0x427350[_0x14e02b('0x5d')]);const _0x337fa6={'where':_0x68259e[_0x14e02b('0x21')]};return db[_0x14e02b('0x44')][_0x14e02b('0xf')](_0x337fa6)[_0x14e02b('0x3b')](function(_0x34c37f){const _0x4c8490=_0x14e02b;return _0x1daf9a['count']=_0x34c37f,_0x427350[_0x4c8490('0x31')][_0x4c8490('0x53')]&&(_0x68259e['include']=[{'all':!![]}]),db[_0x4c8490('0x44')][_0x4c8490('0x1')](_0x68259e);})[_0x14e02b('0x3b')](function(_0x40e108){const _0x331c85=_0x14e02b;return _0x1daf9a[_0x331c85('0x39')]=_0x40e108,_0x1daf9a;})[_0x14e02b('0x3b')](respondWithFilteredResult(_0x15eaff,_0x68259e))[_0x14e02b('0x3')](handleError(_0x15eaff,null));},exports[_0x4d292d('0x5a')]=function(_0x165c5b,_0x2f3e6d){const _0x293d04=_0x4d292d;let _0x3aa14c={'raw':![],'where':{'id':_0x165c5b[_0x293d04('0x41')]['id']}};const _0x3a9880={};return _0x3a9880[_0x293d04('0x2b')]=_[_0x293d04('0x3c')](db[_0x293d04('0x44')]['rawAttributes']),_0x3a9880[_0x293d04('0x31')]=_['keys'](_0x165c5b[_0x293d04('0x31')]),_0x3a9880[_0x293d04('0x4')]=_['intersection'](_0x3a9880[_0x293d04('0x2b')],_0x3a9880[_0x293d04('0x31')]),_0x3aa14c[_0x293d04('0x1a')]=_[_0x293d04('0x49')](_0x3a9880[_0x293d04('0x2b')],qs[_0x293d04('0x3d')](_0x165c5b['query'][_0x293d04('0x3d')])),_0x3aa14c['attributes']=_0x3aa14c['attributes'][_0x293d04('0x4d')]?_0x3aa14c['attributes']:_0x3a9880[_0x293d04('0x2b')],_0x165c5b[_0x293d04('0x31')][_0x293d04('0x53')]&&(_0x3aa14c[_0x293d04('0x2f')]=[{'all':!![]}]),_0x3aa14c=_[_0x293d04('0x1b')]({},_0x3aa14c,_0x165c5b[_0x293d04('0x5d')]),db[_0x293d04('0x44')]['findOne'](_0x3aa14c)['then'](handleEntityNotFound(_0x2f3e6d,null))[_0x293d04('0x3b')](respondWithResult(_0x2f3e6d,null))[_0x293d04('0x3')](handleError(_0x2f3e6d,null));},exports['create']=function(_0xb79c0f,_0x35beff){const _0x4abe51=_0x4d292d;return db[_0x4abe51('0x44')]['create'](_0xb79c0f['body'],{})[_0x4abe51('0x3b')](respondWithResult(_0x35beff,0xc9))[_0x4abe51('0x3')](handleError(_0x35beff,null));},exports[_0x4d292d('0x3f')]=function(_0x32a13e,_0x469e47){const _0x7daca7=_0x4d292d;return _0x32a13e['body']['id']&&delete _0x32a13e['body']['id'],db[_0x7daca7('0x44')][_0x7daca7('0x5e')]({'where':{'id':_0x32a13e[_0x7daca7('0x41')]['id']}})[_0x7daca7('0x3b')](handleEntityNotFound(_0x469e47,null))[_0x7daca7('0x3b')](saveUpdates(_0x32a13e[_0x7daca7('0x18')],null))['then'](respondWithResult(_0x469e47,null))[_0x7daca7('0x3')](handleError(_0x469e47,null));},exports['destroy']=function(_0x4bae6e,_0x24f7f1){const _0x40dd1e=_0x4d292d;return db[_0x40dd1e('0x44')][_0x40dd1e('0x5e')]({'where':{'id':_0x4bae6e[_0x40dd1e('0x41')]['id']}})[_0x40dd1e('0x3b')](handleEntityNotFound(_0x24f7f1,null))[_0x40dd1e('0x3b')](removeEntity(_0x24f7f1,null))[_0x40dd1e('0x3')](handleError(_0x24f7f1,null));},exports[_0x4d292d('0x12')]=function(_0x520629,_0x539c3c){const _0x5d052f=_0x4d292d;let _0x150c97={};const _0x2cafde={};let _0xa448d2,_0x1faac5;return db['ZendeskAccount'][_0x5d052f('0x5e')]({'where':{'id':_0x520629['params']['id']}})[_0x5d052f('0x3b')](handleEntityNotFound(_0x539c3c,null))[_0x5d052f('0x3b')](function(_0x5c09b0){const _0x485c96=_0x5d052f;if(_0x5c09b0)return _0xa448d2=_0x5c09b0,_0x2cafde[_0x485c96('0x2b')]=_[_0x485c96('0x3c')](db[_0x485c96('0x2')][_0x485c96('0x1e')]),_0x2cafde[_0x485c96('0x31')]=_[_0x485c96('0x3c')](_0x520629[_0x485c96('0x31')]),_0x2cafde[_0x485c96('0x4')]=_[_0x485c96('0x49')](_0x2cafde['model'],_0x2cafde[_0x485c96('0x31')]),_0x150c97[_0x485c96('0x1a')]=_[_0x485c96('0x49')](_0x2cafde['model'],qs[_0x485c96('0x3d')](_0x520629[_0x485c96('0x31')]['fields'])),_0x150c97['attributes']=_0x150c97['attributes'][_0x485c96('0x4d')]?_0x150c97[_0x485c96('0x1a')]:_0x2cafde[_0x485c96('0x2b')],_0x150c97[_0x485c96('0x28')]=qs[_0x485c96('0x24')](_0x520629['query'][_0x485c96('0x24')]),_0x150c97['where']=qs[_0x485c96('0x4')](_[_0x485c96('0x35')](_0x520629['query'],_0x2cafde['filters'])),_0x520629[_0x485c96('0x31')][_0x485c96('0x50')]&&(_0x150c97[_0x485c96('0x21')]=_['merge'](_0x150c97[_0x485c96('0x21')],{[Op['or']]:_[_0x485c96('0x58')](_0x150c97['attributes'],function(_0x1e928c){const _0x5e8a4f=_0x485c96,_0xde7440={};return _0xde7440[_0x1e928c]={[Op['like']]:'%'+_0x520629[_0x5e8a4f('0x31')]['filter']+'%'},_0xde7440;})})),_0x150c97=_[_0x485c96('0x1b')]({},_0x150c97,_0x520629[_0x485c96('0x5d')]),_0xa448d2['getConfigurations'](_0x150c97);})['then'](function(_0x1fedb3){const _0x160fc4=_0x5d052f;if(_0x1fedb3)return _0x1faac5=_0x1fedb3[_0x160fc4('0x4d')],typeof _0x520629['query'][_0x160fc4('0x38')]===_0x160fc4('0x5b')&&(_0x150c97['limit']=qs[_0x160fc4('0x56')](_0x520629[_0x160fc4('0x31')][_0x160fc4('0x56')]),_0x150c97[_0x160fc4('0x29')]=qs[_0x160fc4('0x29')](_0x520629[_0x160fc4('0x31')][_0x160fc4('0x29')])),_0xa448d2[_0x160fc4('0x12')](_0x150c97);})['then'](function(_0x9d682b){if(_0x9d682b)return _0x9d682b?{'count':_0x1faac5,'rows':_0x9d682b}:null;})['then'](respondWithResult(_0x539c3c,null))['catch'](handleError(_0x539c3c,null));},exports[_0x4d292d('0x8')]=function(_0x3a7dd2,_0x54e3c2){const _0x196806=_0x4d292d;return _0x3a7dd2['body']['id']&&delete _0x3a7dd2['body']['id'],db[_0x196806('0x44')][_0x196806('0x5e')]({'where':{'id':_0x3a7dd2[_0x196806('0x41')]['id']}})[_0x196806('0x3b')](handleEntityNotFound(_0x54e3c2,null))['then'](function(_0x96b647){const _0x3c955b=_0x196806;if(_0x96b647)return _0x3a7dd2[_0x3c955b('0x18')][_0x3c955b('0x36')]=_0x96b647['id'],_0x3a7dd2[_0x3c955b('0x18')]['Subjects']=integrations[_0x3c955b('0x4c')](_0x3a7dd2[_0x3c955b('0x18')][_0x3c955b('0x47')],_0x3a7dd2['body'][_0x3c955b('0x45')]),_0x3a7dd2[_0x3c955b('0x18')]['Descriptions']=integrations['getDescriptions'](_0x3a7dd2['body'][_0x3c955b('0x47')],_0x3a7dd2[_0x3c955b('0x18')][_0x3c955b('0x45')]),db[_0x3c955b('0x2')][_0x3c955b('0xe')](_0x3a7dd2[_0x3c955b('0x18')],{'include':[{'model':db['ZendeskField'],'as':_0x3c955b('0x2a')},{'model':db['ZendeskField'],'as':_0x3c955b('0x43')}]});return null;})[_0x196806('0x3b')](respondWithResult(_0x54e3c2,null))[_0x196806('0x3')](handleError(_0x54e3c2,null));},exports[_0x4d292d('0x55')]=function(_0xa38e35,_0x4b19ab){const _0x41359f=_0x4d292d;let _0x479075='';return db['ZendeskAccount'][_0x41359f('0x5e')]({'where':{'id':_0xa38e35[_0x41359f('0x41')]['id']},'attributes':['id',_0x41359f('0xd'),_0x41359f('0x25'),'token',_0x41359f('0x20'),_0x41359f('0x13')]})[_0x41359f('0x3b')](handleEntityNotFound(_0x4b19ab,null))[_0x41359f('0x3b')](function(_0x1aef59){const _0x4a68a8=_0x41359f;if(_0x1aef59){_0x479075=_0x1aef59['remoteUri'];const _0x3d02c6=_0x479075[_0x4a68a8('0x26')](-0x1);_0x3d02c6==='/'&&(_0x479075=_0x479075[_0x4a68a8('0xc')](0x0,_0x479075[_0x4a68a8('0x32')](_0x3d02c6)));const _0x4be84a={'method':_0x4a68a8('0x42'),'uri':util[_0x4a68a8('0x46')]('%s/%s',_0x479075,_0x4a68a8('0x34')),'json':!![]};switch(_0x1aef59[_0x4a68a8('0x20')]){case'password':_0x4be84a['headers']={'Authorization':util[_0x4a68a8('0x46')](_0x4a68a8('0x17'),Buffer['from'](util[_0x4a68a8('0x46')](_0x4a68a8('0x1d'),_0x1aef59[_0x4a68a8('0xd')],_0x1aef59[_0x4a68a8('0x25')]))[_0x4a68a8('0x51')]('base64'))};break;case _0x4a68a8('0xb'):_0x4be84a[_0x4a68a8('0x6')]={'Authorization':util['format']('Basic\x20%s',Buffer['from'](util[_0x4a68a8('0x46')](_0x4a68a8('0x7'),_0x1aef59[_0x4a68a8('0xd')],_0x1aef59[_0x4a68a8('0xb')]))['toString']('base64'))};break;default:throw new ValidationError(_0x4a68a8('0x11'));}return rp(_0x4be84a);}})['then'](function(_0xd91d0e){const _0x1fb2d9=_0x41359f;if(_0xd91d0e){const _0xc179c0=[_0x1fb2d9('0x57'),'description','group',_0x1fb2d9('0x19')];return _[_0x1fb2d9('0x27')](_0xd91d0e[_0x1fb2d9('0x34')],function(_0x4be3bb){const _0x65976f=_0x1fb2d9;return _0xc179c0[_0x65976f('0x1c')](_0x4be3bb[_0x65976f('0x45')]);}),{'count':_0xd91d0e['ticket_fields'][_0x1fb2d9('0x4d')],'rows':_[_0x1fb2d9('0x58')](_0xd91d0e[_0x1fb2d9('0x34')],function(_0x3ddb91){const _0x368031=_0x1fb2d9;return{'id':_0x3ddb91['id'],'name':_0x3ddb91[_0x368031('0x54')]>0x7?_0x3ddb91['title']:_0x3ddb91['type'],'custom':_0x3ddb91['position']>0x7?!![]:![],'options':_0x3ddb91[_0x368031('0x3e')]?_0x3ddb91[_0x368031('0x3e')]:_0x3ddb91['custom_field_options']?_0x3ddb91[_0x368031('0x33')]:[]};})};}})[_0x41359f('0x3b')](respondWithResult(_0x4b19ab,null))['catch'](function(_0x4c7d60){const _0x49b1da=_0x41359f;let _0x23b2aa=_0xa38e35[_0x49b1da('0x31')][_0x49b1da('0xa')]?0x1f4:_0x4c7d60[_0x49b1da('0x5')]||0x1f4;logger[_0x49b1da('0x4a')]('getFields,\x20%s,\x20%s,\x20%s','getFields',_0x23b2aa,JSON[_0x49b1da('0x1f')](_0x4c7d60)),delete _0x4c7d60[_0x49b1da('0x9')],_0x23b2aa===0x191&&(_0x23b2aa=0x190),_0x4b19ab[_0x49b1da('0x2e')](_0x23b2aa)['send'](_0xa38e35['query'][_0x49b1da('0xa')]?{'message':_0x49b1da('0x4e'),'statusCode':_0x4c7d60[_0x49b1da('0x5')]}:_0x4c7d60);});};