Built motion from commit 82a371561bcdbc7605c801e5e414f4032ba9e7ad. Version 3.0.0...
[motion-next.git] / server / api / intZendeskAccount / intZendeskAccount.controller.js
1 const a333_0x3a90=['catch','from','token','sendStatus','model','where','status','util','subject','ZendeskAccount','description','custom_field_options','toString','Descriptions','options','VIRTUAL','stack','send','lastIndexOf','filters','remoteUri','update','base64','rawAttributes','channel','intersection','Content-Range','stringify','like','sort','../../components/integrations/configuration','username','nolimit','undefined','length','rows','findOne','system_field_options','AccountId','getConfigurations','request-promise-native','position','json','test','fields','attributes','merge','map','count','type','body','title','name','then','findAll','params','getFields,\x20%s,\x20%s,\x20%s','addConfiguration','ZendeskField','format','group','end','lodash','remove','ticket_fields','order','headers','../../config/logger','keys','index','destroy','statusCode','error','Wrong\x20credentials','%s:%s','assignee','%s/%s','Basic\x20%s','ZendeskConfiguration','authType','pick','key','include','Unknown\x20authentication\x20type','offset','Subjects','query','filter','limit','password','../../components/parsers/qs','create'];(function(_0x22b53a,_0x3a906c){const _0x202358=function(_0x3da21b){while(--_0x3da21b){_0x22b53a['push'](_0x22b53a['shift']());}};_0x202358(++_0x3a906c);}(a333_0x3a90,0x11e));const a333_0x2023=function(_0x22b53a,_0x3a906c){_0x22b53a=_0x22b53a-0x0;let _0x202358=a333_0x3a90[_0x22b53a];return _0x202358;};const _0xea796f=a333_0x2023;'use strict';const rp=require(_0xea796f('0x1e')),util=require(_0xea796f('0x59')),_=require(_0xea796f('0x34')),qs=require(_0xea796f('0x50')),logger=require(_0xea796f('0x39'))('api'),db=require('../../mysqldb')['db'],{Op,ValidationError}=require('sequelize'),integrations=require(_0xea796f('0x14'));function respondWithResult(_0x3da21b,_0x5a0fb5){return _0x5a0fb5=_0x5a0fb5||0xc8,function(_0x5cbf85){if(_0x5cbf85)return _0x3da21b['status'](_0x5a0fb5)['json'](_0x5cbf85);};}function respondWithFilteredResult(_0x3b9fd3,_0x49135e){return function(_0x471442){const _0x26629f=a333_0x2023;if(_0x471442){const _0x2b8b21=_0x471442[_0x26629f('0x26')],_0x405b20=_0x49135e[_0x26629f('0x4a')];let _0x1d76f2=_0x49135e[_0x26629f('0x4a')]+_0x49135e[_0x26629f('0x4e')],_0x52ef7b;return _0x1d76f2>=_0x2b8b21?(_0x1d76f2=_0x2b8b21,_0x52ef7b=0xc8):_0x52ef7b=0xce,_0x3b9fd3['status'](_0x52ef7b),_0x3b9fd3['set'](_0x26629f('0x10'),_0x405b20+'-'+_0x1d76f2+'/'+_0x2b8b21)[_0x26629f('0x20')](_0x471442);}return null;};}function saveUpdates(_0x1b5287){return function(_0x2ac111){const _0xaf21ed=a333_0x2023;if(_0x2ac111)return _0x2ac111[_0xaf21ed('0xb')](_0x1b5287)[_0xaf21ed('0x2b')](function(_0x5d2e6c){return _0x5d2e6c;});return null;};}function removeEntity(_0x422642){return function(_0x47afb6){const _0x49c708=a333_0x2023;if(_0x47afb6)return _0x47afb6[_0x49c708('0x3c')]()[_0x49c708('0x2b')](function(){const _0x54164a=_0x49c708;_0x422642[_0x54164a('0x58')](0xcc)[_0x54164a('0x33')]();});};}function handleEntityNotFound(_0x59a7ec){return function(_0x26f4e6){const _0x53d17d=a333_0x2023;return!_0x26f4e6&&_0x59a7ec[_0x53d17d('0x55')](0x194),_0x26f4e6;};}function handleError(_0x3d08cc,_0x4aa667){return _0x4aa667=_0x4aa667||0x1f4,function(_0x43b0ed){const _0x2facf1=a333_0x2023;logger[_0x2facf1('0x3e')](_0x43b0ed[_0x2facf1('0x6')]),_0x43b0ed[_0x2facf1('0x2a')]&&delete _0x43b0ed[_0x2facf1('0x2a')],_0x3d08cc['status'](_0x4aa667)[_0x2facf1('0x7')](_0x43b0ed);};}exports[_0xea796f('0x3b')]=function(_0x5b0520,_0x5a9d84){const _0x2c79a2=_0xea796f;let _0x3f6e90={};const _0x392437={},_0xc79428={'count':0x0,'rows':[]},_0x369525=_[_0x2c79a2('0x25')](db['ZendeskAccount'][_0x2c79a2('0xd')],function(_0x4c898e){const _0x313c2f=_0x2c79a2;return{'name':_0x4c898e['fieldName'],'type':_0x4c898e[_0x313c2f('0x27')][_0x313c2f('0x47')]};});_0x392437['model']=_[_0x2c79a2('0x25')](_0x369525,_0x2c79a2('0x2a')),_0x392437['query']=_['keys'](_0x5b0520[_0x2c79a2('0x4c')]),_0x392437[_0x2c79a2('0x9')]=_[_0x2c79a2('0xf')](_0x392437[_0x2c79a2('0x56')],_0x392437[_0x2c79a2('0x4c')]),_0x3f6e90[_0x2c79a2('0x23')]=_[_0x2c79a2('0xf')](_0x392437[_0x2c79a2('0x56')],qs['fields'](_0x5b0520['query'][_0x2c79a2('0x22')])),_0x3f6e90[_0x2c79a2('0x23')]=_0x3f6e90[_0x2c79a2('0x23')]['length']?_0x3f6e90[_0x2c79a2('0x23')]:_0x392437[_0x2c79a2('0x56')];typeof _0x5b0520[_0x2c79a2('0x4c')][_0x2c79a2('0x16')]===_0x2c79a2('0x17')&&(_0x3f6e90['limit']=qs[_0x2c79a2('0x4e')](_0x5b0520[_0x2c79a2('0x4c')]['limit']),_0x3f6e90[_0x2c79a2('0x4a')]=qs[_0x2c79a2('0x4a')](_0x5b0520[_0x2c79a2('0x4c')][_0x2c79a2('0x4a')]));_0x3f6e90['order']=qs[_0x2c79a2('0x13')](_0x5b0520[_0x2c79a2('0x4c')]['sort']),_0x3f6e90[_0x2c79a2('0x57')]=qs['filters'](_[_0x2c79a2('0x46')](_0x5b0520[_0x2c79a2('0x4c')],_0x392437[_0x2c79a2('0x9')]),_0x369525);_0x5b0520[_0x2c79a2('0x4c')][_0x2c79a2('0x4d')]&&(_0x3f6e90[_0x2c79a2('0x57')]=_[_0x2c79a2('0x24')](_0x3f6e90['where'],{[Op['or']]:_[_0x2c79a2('0x25')](_0x369525,function(_0x43a578){const _0x46b789=_0x2c79a2;if(_0x43a578['type']!==_0x46b789('0x5')){const _0x2fa63a={};return _0x2fa63a[_0x43a578[_0x46b789('0x2a')]]={[Op['like']]:'%'+_0x5b0520[_0x46b789('0x4c')][_0x46b789('0x4d')]+'%'},_0x2fa63a;}})}));_0x3f6e90=_['merge']({},_0x3f6e90,_0x5b0520[_0x2c79a2('0x4')]);const _0x46db8f={'where':_0x3f6e90[_0x2c79a2('0x57')]};return db[_0x2c79a2('0x5b')][_0x2c79a2('0x26')](_0x46db8f)['then'](function(_0xaed6dc){const _0x49bf49=_0x2c79a2;return _0xc79428[_0x49bf49('0x26')]=_0xaed6dc,_0x5b0520[_0x49bf49('0x4c')]['includeAll']&&(_0x3f6e90[_0x49bf49('0x48')]=[{'all':!![]}]),db[_0x49bf49('0x5b')][_0x49bf49('0x2c')](_0x3f6e90);})['then'](function(_0x3a3ec9){const _0x3b8e3a=_0x2c79a2;return _0xc79428[_0x3b8e3a('0x19')]=_0x3a3ec9,_0xc79428;})[_0x2c79a2('0x2b')](respondWithFilteredResult(_0x5a9d84,_0x3f6e90))[_0x2c79a2('0x52')](handleError(_0x5a9d84,null));},exports['show']=function(_0x52aa02,_0x2616c3){const _0x327d7c=_0xea796f;let _0x5ddbcc={'raw':![],'where':{'id':_0x52aa02[_0x327d7c('0x2d')]['id']}};const _0x2258c5={};return _0x2258c5[_0x327d7c('0x56')]=_[_0x327d7c('0x3a')](db['ZendeskAccount'][_0x327d7c('0xd')]),_0x2258c5['query']=_[_0x327d7c('0x3a')](_0x52aa02['query']),_0x2258c5[_0x327d7c('0x9')]=_['intersection'](_0x2258c5[_0x327d7c('0x56')],_0x2258c5[_0x327d7c('0x4c')]),_0x5ddbcc[_0x327d7c('0x23')]=_[_0x327d7c('0xf')](_0x2258c5[_0x327d7c('0x56')],qs[_0x327d7c('0x22')](_0x52aa02[_0x327d7c('0x4c')][_0x327d7c('0x22')])),_0x5ddbcc[_0x327d7c('0x23')]=_0x5ddbcc[_0x327d7c('0x23')][_0x327d7c('0x18')]?_0x5ddbcc[_0x327d7c('0x23')]:_0x2258c5['model'],_0x52aa02[_0x327d7c('0x4c')]['includeAll']&&(_0x5ddbcc[_0x327d7c('0x48')]=[{'all':!![]}]),_0x5ddbcc=_[_0x327d7c('0x24')]({},_0x5ddbcc,_0x52aa02[_0x327d7c('0x4')]),db[_0x327d7c('0x5b')][_0x327d7c('0x1a')](_0x5ddbcc)['then'](handleEntityNotFound(_0x2616c3,null))[_0x327d7c('0x2b')](respondWithResult(_0x2616c3,null))[_0x327d7c('0x52')](handleError(_0x2616c3,null));},exports[_0xea796f('0x51')]=function(_0x476704,_0x1f39bc){const _0x3cb065=_0xea796f;return db['ZendeskAccount'][_0x3cb065('0x51')](_0x476704['body'],{})[_0x3cb065('0x2b')](respondWithResult(_0x1f39bc,0xc9))['catch'](handleError(_0x1f39bc,null));},exports['update']=function(_0x44eb05,_0x5ab44d){const _0x1e6340=_0xea796f;return _0x44eb05[_0x1e6340('0x28')]['id']&&delete _0x44eb05[_0x1e6340('0x28')]['id'],db[_0x1e6340('0x5b')][_0x1e6340('0x1a')]({'where':{'id':_0x44eb05[_0x1e6340('0x2d')]['id']}})[_0x1e6340('0x2b')](handleEntityNotFound(_0x5ab44d,null))[_0x1e6340('0x2b')](saveUpdates(_0x44eb05[_0x1e6340('0x28')],null))[_0x1e6340('0x2b')](respondWithResult(_0x5ab44d,null))[_0x1e6340('0x52')](handleError(_0x5ab44d,null));},exports[_0xea796f('0x3c')]=function(_0x524347,_0x2cd7bd){const _0x5f02c1=_0xea796f;return db[_0x5f02c1('0x5b')]['findOne']({'where':{'id':_0x524347[_0x5f02c1('0x2d')]['id']}})['then'](handleEntityNotFound(_0x2cd7bd,null))['then'](removeEntity(_0x2cd7bd,null))[_0x5f02c1('0x52')](handleError(_0x2cd7bd,null));},exports[_0xea796f('0x1d')]=function(_0x12c294,_0x5f005a){const _0x1532ca=_0xea796f;let _0x43089b={};const _0x2d29f5={};let _0x568971,_0x214f4f;return db[_0x1532ca('0x5b')][_0x1532ca('0x1a')]({'where':{'id':_0x12c294[_0x1532ca('0x2d')]['id']}})['then'](handleEntityNotFound(_0x5f005a,null))[_0x1532ca('0x2b')](function(_0x405f59){const _0x43165b=_0x1532ca;if(_0x405f59)return _0x568971=_0x405f59,_0x2d29f5['model']=_[_0x43165b('0x3a')](db[_0x43165b('0x44')][_0x43165b('0xd')]),_0x2d29f5['query']=_[_0x43165b('0x3a')](_0x12c294[_0x43165b('0x4c')]),_0x2d29f5['filters']=_[_0x43165b('0xf')](_0x2d29f5[_0x43165b('0x56')],_0x2d29f5[_0x43165b('0x4c')]),_0x43089b[_0x43165b('0x23')]=_['intersection'](_0x2d29f5[_0x43165b('0x56')],qs[_0x43165b('0x22')](_0x12c294['query']['fields'])),_0x43089b['attributes']=_0x43089b[_0x43165b('0x23')][_0x43165b('0x18')]?_0x43089b[_0x43165b('0x23')]:_0x2d29f5[_0x43165b('0x56')],_0x43089b[_0x43165b('0x37')]=qs['sort'](_0x12c294['query'][_0x43165b('0x13')]),_0x43089b[_0x43165b('0x57')]=qs[_0x43165b('0x9')](_[_0x43165b('0x46')](_0x12c294[_0x43165b('0x4c')],_0x2d29f5[_0x43165b('0x9')])),_0x12c294[_0x43165b('0x4c')][_0x43165b('0x4d')]&&(_0x43089b['where']=_[_0x43165b('0x24')](_0x43089b[_0x43165b('0x57')],{[Op['or']]:_[_0x43165b('0x25')](_0x43089b[_0x43165b('0x23')],function(_0x2c64af){const _0xbc6e6b=_0x43165b,_0x4997a7={};return _0x4997a7[_0x2c64af]={[Op[_0xbc6e6b('0x12')]]:'%'+_0x12c294['query'][_0xbc6e6b('0x4d')]+'%'},_0x4997a7;})})),_0x43089b=_['merge']({},_0x43089b,_0x12c294[_0x43165b('0x4')]),_0x568971['getConfigurations'](_0x43089b);})[_0x1532ca('0x2b')](function(_0x4824de){const _0x284065=_0x1532ca;if(_0x4824de)return _0x214f4f=_0x4824de[_0x284065('0x18')],typeof _0x12c294[_0x284065('0x4c')][_0x284065('0x16')]===_0x284065('0x17')&&(_0x43089b[_0x284065('0x4e')]=qs[_0x284065('0x4e')](_0x12c294[_0x284065('0x4c')][_0x284065('0x4e')]),_0x43089b[_0x284065('0x4a')]=qs['offset'](_0x12c294['query'][_0x284065('0x4a')])),_0x568971['getConfigurations'](_0x43089b);})[_0x1532ca('0x2b')](function(_0x510f8b){if(_0x510f8b)return _0x510f8b?{'count':_0x214f4f,'rows':_0x510f8b}:null;})['then'](respondWithResult(_0x5f005a,null))[_0x1532ca('0x52')](handleError(_0x5f005a,null));},exports[_0xea796f('0x2f')]=function(_0x30fb29,_0xc4e26e){const _0x5a06a1=_0xea796f;return _0x30fb29[_0x5a06a1('0x28')]['id']&&delete _0x30fb29[_0x5a06a1('0x28')]['id'],db[_0x5a06a1('0x5b')][_0x5a06a1('0x1a')]({'where':{'id':_0x30fb29[_0x5a06a1('0x2d')]['id']}})[_0x5a06a1('0x2b')](handleEntityNotFound(_0xc4e26e,null))[_0x5a06a1('0x2b')](function(_0x5244ca){const _0x436519=_0x5a06a1;if(_0x5244ca)return _0x30fb29['body'][_0x436519('0x1c')]=_0x5244ca['id'],_0x30fb29[_0x436519('0x28')]['Subjects']=integrations['getSubjects'](_0x30fb29[_0x436519('0x28')]['channel'],_0x30fb29['body'][_0x436519('0x27')]),_0x30fb29[_0x436519('0x28')][_0x436519('0x3')]=integrations['getDescriptions'](_0x30fb29[_0x436519('0x28')][_0x436519('0xe')],_0x30fb29['body'][_0x436519('0x27')]),db[_0x436519('0x44')]['create'](_0x30fb29[_0x436519('0x28')],{'include':[{'model':db[_0x436519('0x30')],'as':_0x436519('0x4b')},{'model':db[_0x436519('0x30')],'as':'Descriptions'}]});return null;})[_0x5a06a1('0x2b')](respondWithResult(_0xc4e26e,null))[_0x5a06a1('0x52')](handleError(_0xc4e26e,null));},exports['getFields']=function(_0x2f3dbf,_0x418673){const _0x18454f=_0xea796f;let _0x3e9d38='';return db[_0x18454f('0x5b')][_0x18454f('0x1a')]({'where':{'id':_0x2f3dbf['params']['id']},'attributes':['id',_0x18454f('0x15'),_0x18454f('0x4f'),_0x18454f('0x54'),'authType',_0x18454f('0xa')]})[_0x18454f('0x2b')](handleEntityNotFound(_0x418673,null))[_0x18454f('0x2b')](function(_0x243e1c){const _0x44e5bb=_0x18454f;if(_0x243e1c){_0x3e9d38=_0x243e1c[_0x44e5bb('0xa')];const _0x489a3d=_0x3e9d38['slice'](-0x1);_0x489a3d==='/'&&(_0x3e9d38=_0x3e9d38['substring'](0x0,_0x3e9d38[_0x44e5bb('0x8')](_0x489a3d)));const _0x11abfc={'method':'GET','uri':util[_0x44e5bb('0x31')](_0x44e5bb('0x42'),_0x3e9d38,_0x44e5bb('0x36')),'json':!![]};switch(_0x243e1c[_0x44e5bb('0x45')]){case'password':_0x11abfc[_0x44e5bb('0x38')]={'Authorization':util[_0x44e5bb('0x31')](_0x44e5bb('0x43'),Buffer[_0x44e5bb('0x53')](util['format'](_0x44e5bb('0x40'),_0x243e1c[_0x44e5bb('0x15')],_0x243e1c[_0x44e5bb('0x4f')]))[_0x44e5bb('0x2')](_0x44e5bb('0xc')))};break;case _0x44e5bb('0x54'):_0x11abfc[_0x44e5bb('0x38')]={'Authorization':util[_0x44e5bb('0x31')]('Basic\x20%s',Buffer['from'](util[_0x44e5bb('0x31')]('%s/token:%s',_0x243e1c[_0x44e5bb('0x15')],_0x243e1c[_0x44e5bb('0x54')]))[_0x44e5bb('0x2')](_0x44e5bb('0xc')))};break;default:throw new ValidationError(_0x44e5bb('0x49'));}return rp(_0x11abfc);}})[_0x18454f('0x2b')](function(_0x2d3033){const _0x472278=_0x18454f;if(_0x2d3033){const _0x1685da=[_0x472278('0x5a'),_0x472278('0x0'),_0x472278('0x32'),_0x472278('0x41')];return _[_0x472278('0x35')](_0x2d3033[_0x472278('0x36')],function(_0xc8ec8e){const _0x1aedcb=_0x472278;return _0x1685da['includes'](_0xc8ec8e[_0x1aedcb('0x27')]);}),{'count':_0x2d3033['ticket_fields'][_0x472278('0x18')],'rows':_[_0x472278('0x25')](_0x2d3033[_0x472278('0x36')],function(_0x2e8b0c){const _0x5a773f=_0x472278;return{'id':_0x2e8b0c['id'],'name':_0x2e8b0c[_0x5a773f('0x1f')]>0x7?_0x2e8b0c[_0x5a773f('0x29')]:_0x2e8b0c[_0x5a773f('0x27')],'custom':_0x2e8b0c['position']>0x7?!![]:![],'options':_0x2e8b0c[_0x5a773f('0x1b')]?_0x2e8b0c[_0x5a773f('0x1b')]:_0x2e8b0c[_0x5a773f('0x1')]?_0x2e8b0c[_0x5a773f('0x1')]:[]};})};}})['then'](respondWithResult(_0x418673,null))['catch'](function(_0x138919){const _0x1eedd8=_0x18454f;let _0x60b0a5=_0x2f3dbf[_0x1eedd8('0x4c')]['test']?0x1f4:_0x138919[_0x1eedd8('0x3d')]||0x1f4;logger[_0x1eedd8('0x3e')](_0x1eedd8('0x2e'),'getFields',_0x60b0a5,JSON[_0x1eedd8('0x11')](_0x138919)),delete _0x138919[_0x1eedd8('0x2a')],_0x60b0a5===0x191&&(_0x60b0a5=0x190),_0x418673[_0x1eedd8('0x58')](_0x60b0a5)[_0x1eedd8('0x7')](_0x2f3dbf[_0x1eedd8('0x4c')][_0x1eedd8('0x21')]?{'message':_0x1eedd8('0x3f'),'statusCode':_0x138919[_0x1eedd8('0x3d')]}:_0x138919);});};