Built motion from commit 709aa6fb5ed03aa61bc373fcdbf622215d37d30b. Version 3.0.0...
[motion-next.git] / server / api / intDeskAccount / intDeskAccount.controller.js
1 const a229_0x4815=['lastIndexOf','toString','key','DeskField','fields','test','util','lodash','length','findOne','query','Subjects','../../mysqldb','end','consumerKey','AccountId','includeAll','options','GET','slice','catch','%s:%s','nolimit','request-promise-native','show','../../components/parsers/qs','application/json','like','type','getFields,\x20%s,\x20%s,\x20%s','create','../../components/integrations/configuration','sendStatus','offset','../../config/logger','then','rawAttributes','DeskAccount','pick','send','undefined','where','%s/custom_fields','remoteUri','index','intersection','sort','entries','destroy','channel','password','set','attributes','Wrong\x20credentials','getConfigurations','api','tokenSecret','filter','map','sequelize','statusCode','stringify','substring','Authorization','headers','merge','getFields','rows','authType','count','token','from','getSubjects','DeskConfiguration','error','filters','VIRTUAL','json','Descriptions','include','getDescriptions','name','order','Content-Range','model','format','priority','keys','limit','status','active','params','body','username'];(function(_0x2bb272,_0x481564){const _0x20714d=function(_0x4138f1){while(--_0x4138f1){_0x2bb272['push'](_0x2bb272['shift']());}};_0x20714d(++_0x481564);}(a229_0x4815,0x1e7));const a229_0x2071=function(_0x2bb272,_0x481564){_0x2bb272=_0x2bb272-0x0;let _0x20714d=a229_0x4815[_0x2bb272];return _0x20714d;};const _0x131994=a229_0x2071;'use strict';const rp=require(_0x131994('0x6')),util=require(_0x131994('0x53')),_=require(_0x131994('0x54')),qs=require(_0x131994('0x8')),logger=require(_0x131994('0x11'))(_0x131994('0x26')),db=require(_0x131994('0x59'))['db'],{Op}=require(_0x131994('0x2a')),integrations=require(_0x131994('0xe'));function respondWithResult(_0x4138f1,_0x4cb526){return _0x4cb526=_0x4cb526||0xc8,function(_0x4c9030){const _0x21bbc7=a229_0x2071;if(_0x4c9030)return _0x4138f1[_0x21bbc7('0x48')](_0x4cb526)[_0x21bbc7('0x3c')](_0x4c9030);};}function respondWithFilteredResult(_0x58e07e,_0x2aacb9){return function(_0x38f2ab){const _0x52e9c5=a229_0x2071;if(_0x38f2ab){const _0xc6641c=_0x38f2ab['count'],_0x443206=_0x2aacb9[_0x52e9c5('0x10')];let _0x320e3b=_0x2aacb9[_0x52e9c5('0x10')]+_0x2aacb9[_0x52e9c5('0x47')],_0x5142bd;return _0x320e3b>=_0xc6641c?(_0x320e3b=_0xc6641c,_0x5142bd=0xc8):_0x5142bd=0xce,_0x58e07e[_0x52e9c5('0x48')](_0x5142bd),_0x58e07e[_0x52e9c5('0x22')](_0x52e9c5('0x42'),_0x443206+'-'+_0x320e3b+'/'+_0xc6641c)[_0x52e9c5('0x3c')](_0x38f2ab);}return null;};}function saveUpdates(_0x1bcbc5){return function(_0x141115){const _0x4ba059=a229_0x2071;if(_0x141115)return _0x141115['update'](_0x1bcbc5)[_0x4ba059('0x12')](function(_0x75a168){return _0x75a168;});return null;};}function removeEntity(_0x3f6b85){return function(_0x21e321){const _0x51e56d=a229_0x2071;if(_0x21e321)return _0x21e321[_0x51e56d('0x1f')]()['then'](function(){const _0x7fefbd=_0x51e56d;_0x3f6b85[_0x7fefbd('0x48')](0xcc)[_0x7fefbd('0x5a')]();});};}function handleEntityNotFound(_0x494625){return function(_0x443b5c){const _0x36ab0a=a229_0x2071;return!_0x443b5c&&_0x494625[_0x36ab0a('0xf')](0x194),_0x443b5c;};}function handleError(_0x33d098,_0x3b2b7a){return _0x3b2b7a=_0x3b2b7a||0x1f4,function(_0x2beab0){const _0x484cb9=a229_0x2071;logger[_0x484cb9('0x39')](_0x2beab0['stack']),_0x2beab0[_0x484cb9('0x40')]&&delete _0x2beab0[_0x484cb9('0x40')],_0x33d098[_0x484cb9('0x48')](_0x3b2b7a)['send'](_0x2beab0);};}exports[_0x131994('0x1b')]=function(_0x15d76b,_0xbbf731){const _0x2fcf5a=_0x131994;let _0x352ac1={};const _0x1f6df4={},_0x1b756d={'count':0x0,'rows':[]},_0x46ec8c=_['map'](db[_0x2fcf5a('0x14')][_0x2fcf5a('0x13')],function(_0x46094d){const _0x1cb4b7=_0x2fcf5a;return{'name':_0x46094d['fieldName'],'type':_0x46094d[_0x1cb4b7('0xb')][_0x1cb4b7('0x4f')]};});_0x1f6df4['model']=_['map'](_0x46ec8c,'name'),_0x1f6df4[_0x2fcf5a('0x57')]=_[_0x2fcf5a('0x46')](_0x15d76b[_0x2fcf5a('0x57')]),_0x1f6df4['filters']=_['intersection'](_0x1f6df4[_0x2fcf5a('0x43')],_0x1f6df4['query']),_0x352ac1[_0x2fcf5a('0x23')]=_[_0x2fcf5a('0x1c')](_0x1f6df4[_0x2fcf5a('0x43')],qs[_0x2fcf5a('0x51')](_0x15d76b[_0x2fcf5a('0x57')][_0x2fcf5a('0x51')])),_0x352ac1[_0x2fcf5a('0x23')]=_0x352ac1['attributes'][_0x2fcf5a('0x55')]?_0x352ac1[_0x2fcf5a('0x23')]:_0x1f6df4[_0x2fcf5a('0x43')];typeof _0x15d76b['query']['nolimit']===_0x2fcf5a('0x17')&&(_0x352ac1[_0x2fcf5a('0x47')]=qs[_0x2fcf5a('0x47')](_0x15d76b[_0x2fcf5a('0x57')][_0x2fcf5a('0x47')]),_0x352ac1[_0x2fcf5a('0x10')]=qs['offset'](_0x15d76b[_0x2fcf5a('0x57')][_0x2fcf5a('0x10')]));_0x352ac1[_0x2fcf5a('0x41')]=qs[_0x2fcf5a('0x1d')](_0x15d76b[_0x2fcf5a('0x57')][_0x2fcf5a('0x1d')]),_0x352ac1[_0x2fcf5a('0x18')]=qs[_0x2fcf5a('0x3a')](_['pick'](_0x15d76b[_0x2fcf5a('0x57')],_0x1f6df4[_0x2fcf5a('0x3a')]),_0x46ec8c);_0x15d76b[_0x2fcf5a('0x57')][_0x2fcf5a('0x28')]&&(_0x352ac1[_0x2fcf5a('0x18')]=_[_0x2fcf5a('0x30')](_0x352ac1[_0x2fcf5a('0x18')],{[Op['or']]:_[_0x2fcf5a('0x29')](_0x46ec8c,function(_0x94a099){const _0x5290ea=_0x2fcf5a;if(_0x94a099[_0x5290ea('0xb')]!==_0x5290ea('0x3b')){const _0x204336={};return _0x204336[_0x94a099[_0x5290ea('0x40')]]={[Op[_0x5290ea('0xa')]]:'%'+_0x15d76b[_0x5290ea('0x57')][_0x5290ea('0x28')]+'%'},_0x204336;}})}));_0x352ac1=_['merge']({},_0x352ac1,_0x15d76b['options']);const _0x21bff4={'where':_0x352ac1[_0x2fcf5a('0x18')]};return db[_0x2fcf5a('0x14')][_0x2fcf5a('0x34')](_0x21bff4)[_0x2fcf5a('0x12')](function(_0x579375){const _0x45609f=_0x2fcf5a;return _0x1b756d['count']=_0x579375,_0x15d76b['query'][_0x45609f('0x5d')]&&(_0x352ac1[_0x45609f('0x3e')]=[{'all':!![]}]),db[_0x45609f('0x14')]['findAll'](_0x352ac1);})[_0x2fcf5a('0x12')](function(_0x1d3cad){const _0x3e711e=_0x2fcf5a;return _0x1b756d[_0x3e711e('0x32')]=_0x1d3cad,_0x1b756d;})['then'](respondWithFilteredResult(_0xbbf731,_0x352ac1))[_0x2fcf5a('0x3')](handleError(_0xbbf731,null));},exports[_0x131994('0x7')]=function(_0x4311dd,_0x469bc2){const _0x2f2944=_0x131994;let _0x178483={'raw':![],'where':{'id':_0x4311dd[_0x2f2944('0x4a')]['id']}};const _0x4ab0c0={};return _0x4ab0c0[_0x2f2944('0x43')]=_['keys'](db[_0x2f2944('0x14')][_0x2f2944('0x13')]),_0x4ab0c0[_0x2f2944('0x57')]=_[_0x2f2944('0x46')](_0x4311dd[_0x2f2944('0x57')]),_0x4ab0c0[_0x2f2944('0x3a')]=_['intersection'](_0x4ab0c0['model'],_0x4ab0c0[_0x2f2944('0x57')]),_0x178483['attributes']=_[_0x2f2944('0x1c')](_0x4ab0c0['model'],qs[_0x2f2944('0x51')](_0x4311dd[_0x2f2944('0x57')][_0x2f2944('0x51')])),_0x178483[_0x2f2944('0x23')]=_0x178483[_0x2f2944('0x23')]['length']?_0x178483[_0x2f2944('0x23')]:_0x4ab0c0['model'],_0x4311dd['query']['includeAll']&&(_0x178483[_0x2f2944('0x3e')]=[{'all':!![]}]),_0x178483=_['merge']({},_0x178483,_0x4311dd[_0x2f2944('0x0')]),db[_0x2f2944('0x14')][_0x2f2944('0x56')](_0x178483)[_0x2f2944('0x12')](handleEntityNotFound(_0x469bc2,null))[_0x2f2944('0x12')](respondWithResult(_0x469bc2,null))['catch'](handleError(_0x469bc2,null));},exports[_0x131994('0xd')]=function(_0x40b1e2,_0x1d24e6){const _0x2a4135=_0x131994;return db[_0x2a4135('0x14')][_0x2a4135('0xd')](_0x40b1e2[_0x2a4135('0x4b')],{})[_0x2a4135('0x12')](respondWithResult(_0x1d24e6,0xc9))['catch'](handleError(_0x1d24e6,null));},exports['update']=function(_0x481ae4,_0x106410){const _0x282334=_0x131994;return _0x481ae4[_0x282334('0x4b')]['id']&&delete _0x481ae4[_0x282334('0x4b')]['id'],db[_0x282334('0x14')][_0x282334('0x56')]({'where':{'id':_0x481ae4[_0x282334('0x4a')]['id']}})['then'](handleEntityNotFound(_0x106410,null))['then'](saveUpdates(_0x481ae4[_0x282334('0x4b')],null))['then'](respondWithResult(_0x106410,null))[_0x282334('0x3')](handleError(_0x106410,null));},exports['destroy']=function(_0x3dce55,_0x5b1acd){const _0x1d34d4=_0x131994;return db[_0x1d34d4('0x14')][_0x1d34d4('0x56')]({'where':{'id':_0x3dce55['params']['id']}})[_0x1d34d4('0x12')](handleEntityNotFound(_0x5b1acd,null))[_0x1d34d4('0x12')](removeEntity(_0x5b1acd,null))[_0x1d34d4('0x3')](handleError(_0x5b1acd,null));},exports[_0x131994('0x25')]=function(_0x3e35b7,_0x30d5b){const _0x18a6c0=_0x131994;let _0x4be42f={};const _0x339986={};let _0x228b1c,_0x222544;return db['DeskAccount'][_0x18a6c0('0x56')]({'where':{'id':_0x3e35b7[_0x18a6c0('0x4a')]['id']}})['then'](handleEntityNotFound(_0x30d5b,null))[_0x18a6c0('0x12')](function(_0x241f5a){const _0x2956f9=_0x18a6c0;if(_0x241f5a)return _0x228b1c=_0x241f5a,_0x339986[_0x2956f9('0x43')]=_[_0x2956f9('0x46')](db[_0x2956f9('0x38')][_0x2956f9('0x13')]),_0x339986[_0x2956f9('0x57')]=_['keys'](_0x3e35b7['query']),_0x339986[_0x2956f9('0x3a')]=_[_0x2956f9('0x1c')](_0x339986[_0x2956f9('0x43')],_0x339986[_0x2956f9('0x57')]),_0x4be42f[_0x2956f9('0x23')]=_[_0x2956f9('0x1c')](_0x339986['model'],qs[_0x2956f9('0x51')](_0x3e35b7['query'][_0x2956f9('0x51')])),_0x4be42f['attributes']=_0x4be42f[_0x2956f9('0x23')][_0x2956f9('0x55')]?_0x4be42f[_0x2956f9('0x23')]:_0x339986[_0x2956f9('0x43')],_0x4be42f['order']=qs['sort'](_0x3e35b7[_0x2956f9('0x57')][_0x2956f9('0x1d')]),_0x4be42f[_0x2956f9('0x18')]=qs['filters'](_[_0x2956f9('0x15')](_0x3e35b7['query'],_0x339986[_0x2956f9('0x3a')])),_0x3e35b7['query'][_0x2956f9('0x28')]&&(_0x4be42f[_0x2956f9('0x18')]=_['merge'](_0x4be42f[_0x2956f9('0x18')],{[Op['or']]:_[_0x2956f9('0x29')](_0x4be42f[_0x2956f9('0x23')],function(_0x1e521a){const _0x486798=_0x2956f9,_0x3cabce={};return _0x3cabce[_0x1e521a]={[Op[_0x486798('0xa')]]:'%'+_0x3e35b7[_0x486798('0x57')][_0x486798('0x28')]+'%'},_0x3cabce;})})),_0x4be42f=_[_0x2956f9('0x30')]({},_0x4be42f,_0x3e35b7['options']),_0x228b1c[_0x2956f9('0x25')](_0x4be42f);})[_0x18a6c0('0x12')](function(_0x471315){const _0x3016fc=_0x18a6c0;if(_0x471315)return _0x222544=_0x471315[_0x3016fc('0x55')],typeof _0x3e35b7[_0x3016fc('0x57')][_0x3016fc('0x5')]===_0x3016fc('0x17')&&(_0x4be42f[_0x3016fc('0x47')]=qs['limit'](_0x3e35b7['query'][_0x3016fc('0x47')]),_0x4be42f['offset']=qs[_0x3016fc('0x10')](_0x3e35b7['query'][_0x3016fc('0x10')])),_0x228b1c[_0x3016fc('0x25')](_0x4be42f);})['then'](function(_0x1fc7f9){if(_0x1fc7f9)return _0x1fc7f9?{'count':_0x222544,'rows':_0x1fc7f9}:null;})[_0x18a6c0('0x12')](respondWithResult(_0x30d5b,null))[_0x18a6c0('0x3')](handleError(_0x30d5b,null));},exports['addConfiguration']=function(_0x50a920,_0x287ce6){const _0x101612=_0x131994;return _0x50a920[_0x101612('0x4b')]['id']&&delete _0x50a920[_0x101612('0x4b')]['id'],db['DeskAccount'][_0x101612('0x56')]({'where':{'id':_0x50a920['params']['id']}})[_0x101612('0x12')](handleEntityNotFound(_0x287ce6,null))[_0x101612('0x12')](function(_0x3299b8){const _0x585e70=_0x101612;if(_0x3299b8)return _0x50a920[_0x585e70('0x4b')][_0x585e70('0x5c')]=_0x3299b8['id'],_0x50a920[_0x585e70('0x4b')][_0x585e70('0x58')]=integrations[_0x585e70('0x37')](_0x50a920['body'][_0x585e70('0x20')],_0x50a920['body'][_0x585e70('0xb')]),_0x50a920[_0x585e70('0x4b')][_0x585e70('0x3d')]=integrations[_0x585e70('0x3f')](_0x50a920['body'][_0x585e70('0x20')],_0x50a920[_0x585e70('0x4b')]['type']),db[_0x585e70('0x38')][_0x585e70('0xd')](_0x50a920[_0x585e70('0x4b')],{'include':[{'model':db[_0x585e70('0x50')],'as':_0x585e70('0x58')},{'model':db[_0x585e70('0x50')],'as':_0x585e70('0x3d')}]});return null;})[_0x101612('0x12')](respondWithResult(_0x287ce6,null))[_0x101612('0x3')](handleError(_0x287ce6,null));},exports['getFields']=function(_0x1b33bc,_0x15dd73){const _0x149747=_0x131994,_0x3860ff=[{'name':_0x149747('0x45'),'label':'priority','custom':![],'options':[{'name':0x1,'value':0x1},{'name':0x2,'value':0x2},{'name':0x3,'value':0x3},{'name':0x4,'value':0x4},{'name':0x5,'value':0x5},{'name':0x6,'value':0x6},{'name':0x7,'value':0x7},{'name':0x8,'value':0x8},{'name':0x9,'value':0x9},{'name':0xa,'value':0xa}]}];let _0x22632b='';return db[_0x149747('0x14')][_0x149747('0x56')]({'where':{'id':_0x1b33bc[_0x149747('0x4a')]['id']},'attributes':['id','remoteUri',_0x149747('0x33'),_0x149747('0x4c'),_0x149747('0x21'),_0x149747('0x5b'),'consumerSecret',_0x149747('0x35'),_0x149747('0x27')]})[_0x149747('0x12')](handleEntityNotFound(_0x15dd73,null))[_0x149747('0x12')](function(_0x32e727){const _0x4eaaa6=_0x149747;if(_0x32e727){_0x22632b=_0x32e727[_0x4eaaa6('0x1a')];const _0x2d855b=_0x22632b[_0x4eaaa6('0x2')](-0x1);_0x2d855b==='/'&&(_0x22632b=_0x22632b[_0x4eaaa6('0x2d')](0x0,_0x22632b[_0x4eaaa6('0x4d')](_0x2d855b)));const _0x596e35={'method':_0x4eaaa6('0x1'),'uri':util[_0x4eaaa6('0x44')](_0x4eaaa6('0x19'),_0x22632b),'headers':{'Content-Type':_0x4eaaa6('0x9'),'Accept':_0x4eaaa6('0x9')},'json':!![]};return _0x32e727[_0x4eaaa6('0x33')]==='basic'&&(_0x596e35[_0x4eaaa6('0x2f')][_0x4eaaa6('0x2e')]=util[_0x4eaaa6('0x44')]('Basic\x20%s',Buffer[_0x4eaaa6('0x36')](util[_0x4eaaa6('0x44')](_0x4eaaa6('0x4'),_0x32e727[_0x4eaaa6('0x4c')],_0x32e727[_0x4eaaa6('0x21')]))[_0x4eaaa6('0x4e')]('base64'))),rp(_0x596e35)[_0x4eaaa6('0x12')](function(_0xdfb9e6){const _0x1eab0c=_0x4eaaa6;return _0x3860ff['concat'](_[_0x1eab0c('0x29')](_0xdfb9e6['_embedded'][_0x1eab0c('0x1e')],function(_0x197cd3){const _0x4d23b6=_0x1eab0c;return{'id':_0x197cd3['name'],'name':_0x197cd3['name'],'type':_0x197cd3['type'],'active':_0x197cd3[_0x4d23b6('0x49')],'label':_0x197cd3['label'],'custom':!![]};}));});}})['then'](function(_0x29e047){const _0x766833=_0x149747;return{'count':_0x29e047[_0x766833('0x55')],'rows':_0x29e047};})['then'](respondWithResult(_0x15dd73,null))[_0x149747('0x3')](function(_0x256fe9){const _0x3c68e6=_0x149747;let _0x4649ef=_0x1b33bc['query'][_0x3c68e6('0x52')]?0x1f4:_0x256fe9[_0x3c68e6('0x2b')]||0x1f4;logger[_0x3c68e6('0x39')](_0x3c68e6('0xc'),_0x3c68e6('0x31'),_0x4649ef,JSON[_0x3c68e6('0x2c')](_0x256fe9)),delete _0x256fe9[_0x3c68e6('0x40')],_0x4649ef===0x191&&(_0x4649ef=0x190),_0x15dd73[_0x3c68e6('0x48')](_0x4649ef)[_0x3c68e6('0x16')](_0x1b33bc[_0x3c68e6('0x57')][_0x3c68e6('0x52')]?{'message':_0x3c68e6('0x24'),'statusCode':_0x256fe9[_0x3c68e6('0x2b')]}:_0x256fe9);});};