Built motion from commit 82a371561bcdbc7605c801e5e414f4032ba9e7ad. Version 3.0.0...
[motion-next.git] / server / api / voiceExtension / voiceExtension.controller.js
1 const a727_0x26a0=['VIRTUAL','findAndCountAll','filters','index','outbound','userProfileId','query','UserProfileSection','then','description','addApplications','model','destroy','name','count','json','UserProfileResource','user','update','get','where','include','catch','fields','Unable\x20to\x20retrieve\x20the\x20current\x20user','Content-Range','offset','OutboundRoutes','rows','VoiceExtension','type','bulkCreate','create','options','set','limit','value','send','api','autoAssociation','mandatoryDisposition','status','attributes','findAll','context','error','map','show','exten','startsWith','merge','cutdigits','body','order','key','sort','internal','intersection','params','find','includeAll','sendStatus','InternalRoutes','ignore','includes','sequelize','keys','inbound','../../components/parsers/qs','role','InboundRoutes','length','../../mysqldb','VoiceExtensionId','cast(priority\x20as\x20unsigned)','findOne','transaction','concat','end','rawAttributes','filter','register','../../config/logger'];(function(_0x2f77e3,_0x26a0cc){const _0x1aaddb=function(_0x38ac20){while(--_0x38ac20){_0x2f77e3['push'](_0x2f77e3['shift']());}};_0x1aaddb(++_0x26a0cc);}(a727_0x26a0,0x165));const a727_0x1aad=function(_0x2f77e3,_0x26a0cc){_0x2f77e3=_0x2f77e3-0x0;let _0x1aaddb=a727_0x26a0[_0x2f77e3];return _0x1aaddb;};const _0x5150f4=a727_0x1aad;'use strict';const _=require('lodash'),qs=require(_0x5150f4('0x2b')),logger=require(_0x5150f4('0x39'))(_0x5150f4('0xd')),{getSocket}=require('../../rediscache'),socket=getSocket(),db=require(_0x5150f4('0x2f'))['db'],{Op}=require(_0x5150f4('0x28'));require('./voiceExtension.socket')[_0x5150f4('0x38')](socket);function respondWithStatusCode(_0x38ac20,_0x31fa93){return _0x31fa93=_0x31fa93||0xcc,function(_0x345ef7){const _0x5356c6=a727_0x1aad;if(_0x345ef7)return _0x38ac20[_0x5356c6('0x24')](_0x31fa93);return _0x38ac20[_0x5356c6('0x10')](_0x31fa93)[_0x5356c6('0x35')]();};}function respondWithResult(_0x321c0f,_0x44eb01){return _0x44eb01=_0x44eb01||0xc8,function(_0x2fe51c){if(_0x2fe51c)return _0x321c0f['status'](_0x44eb01)['json'](_0x2fe51c);};}function respondWithFilteredResult(_0x2c6c1a,_0x5204aa){return function(_0x5c8902){const _0x364589=a727_0x1aad;if(_0x5c8902){const _0x1be608=_0x5c8902[_0x364589('0x48')],_0x52be0c=_0x5204aa[_0x364589('0x1')];let _0x3c645b=_0x5204aa[_0x364589('0x1')]+_0x5204aa[_0x364589('0xa')],_0x2507de;return _0x3c645b>=_0x1be608?(_0x3c645b=_0x1be608,_0x2507de=0xc8):_0x2507de=0xce,_0x2c6c1a[_0x364589('0x10')](_0x2507de),_0x2c6c1a[_0x364589('0x9')](_0x364589('0x0'),_0x52be0c+'-'+_0x3c645b+'/'+_0x1be608)[_0x364589('0x49')](_0x5c8902);}return null;};}function removeEntity(_0x5925ed){return function(_0x5fb5d3){const _0x13746e=a727_0x1aad;if(_0x5fb5d3)return _0x5fb5d3['destroy']()[_0x13746e('0x42')](function(){const _0x5e1cf1=_0x13746e,_0x4bca6a=_0x5fb5d3[_0x5e1cf1('0x4d')]({'plain':!![]}),_0x4cec41=[{'name':_0x5e1cf1('0x2d'),'value':'inbound','ignore':![]},{'name':_0x5e1cf1('0x2'),'value':_0x5e1cf1('0x3e'),'ignore':![]},{'name':_0x5e1cf1('0x25'),'value':_0x5e1cf1('0x1f'),'ignore':![]}],_0x80cac7=_(_0x4cec41)[_0x5e1cf1('0x37')](_0x5e1cf1('0x26'))['map'](_0x5e1cf1('0xb'))['value']();if(_[_0x5e1cf1('0x27')](_0x80cac7,_0x4bca6a[_0x5e1cf1('0x5')]))return;const _0xad7dd2=_[_0x5e1cf1('0x22')](_0x4cec41,['value',_0x4bca6a['type']])[_0x5e1cf1('0x47')];return db[_0x5e1cf1('0x4a')]['destroy']({'where':{'type':_0xad7dd2,'resourceId':_0x4bca6a['id']}})[_0x5e1cf1('0x42')](function(){return _0x5fb5d3;});})[_0x13746e('0x42')](function(){const _0x3dbf62=_0x13746e;_0x5925ed['status'](0xcc)[_0x3dbf62('0x35')]();});};}function handleEntityNotFound(_0x1f6ddf){return function(_0x2049ed){const _0x273fd8=a727_0x1aad;return!_0x2049ed&&_0x1f6ddf[_0x273fd8('0x24')](0x194),_0x2049ed;};}function handleError(_0x8f1cb0,_0x1f8527){return _0x1f8527=_0x1f8527||0x1f4,function(_0x29323c){const _0xd8b8a2=a727_0x1aad;logger[_0xd8b8a2('0x14')](_0x29323c['stack']),_0x29323c[_0xd8b8a2('0x47')]&&delete _0x29323c[_0xd8b8a2('0x47')],_0x8f1cb0[_0xd8b8a2('0x10')](_0x1f8527)[_0xd8b8a2('0xc')](_0x29323c);};}exports[_0x5150f4('0x3d')]=function(_0x4a0153,_0x3eb78f){const _0x1bbf92=_0x5150f4;let _0x587863={};const _0x4e3d9a={},_0x41b2c1={'count':0x0,'rows':[]},_0x5dc1fc=_[_0x1bbf92('0x15')](db[_0x1bbf92('0x4')][_0x1bbf92('0x36')],function(_0x3298e3){const _0x455a78=_0x1bbf92;return{'name':_0x3298e3['fieldName'],'type':_0x3298e3[_0x455a78('0x5')][_0x455a78('0x1d')]};});_0x4e3d9a[_0x1bbf92('0x45')]=_['map'](_0x5dc1fc,'name'),_0x4e3d9a[_0x1bbf92('0x40')]=_[_0x1bbf92('0x29')](_0x4a0153[_0x1bbf92('0x40')]),_0x4e3d9a['filters']=_['intersection'](_0x4e3d9a['model'],_0x4e3d9a[_0x1bbf92('0x40')]),_0x587863[_0x1bbf92('0x11')]=_['intersection'](_0x4e3d9a[_0x1bbf92('0x45')],qs[_0x1bbf92('0x51')](_0x4a0153[_0x1bbf92('0x40')][_0x1bbf92('0x51')])),_0x587863[_0x1bbf92('0x11')]=_0x587863[_0x1bbf92('0x11')][_0x1bbf92('0x2e')]?_0x587863['attributes']:_0x4e3d9a[_0x1bbf92('0x45')];typeof _0x4a0153[_0x1bbf92('0x40')]['nolimit']==='undefined'&&(_0x587863[_0x1bbf92('0xa')]=qs[_0x1bbf92('0xa')](_0x4a0153[_0x1bbf92('0x40')][_0x1bbf92('0xa')]),_0x587863[_0x1bbf92('0x1')]=qs[_0x1bbf92('0x1')](_0x4a0153['query'][_0x1bbf92('0x1')]));_0x587863[_0x1bbf92('0x1c')]=qs[_0x1bbf92('0x1e')](_0x4a0153[_0x1bbf92('0x40')][_0x1bbf92('0x1e')]),_0x587863['where']=qs['filters'](_['pick'](_0x4a0153[_0x1bbf92('0x40')],_0x4e3d9a[_0x1bbf92('0x3c')]),_0x5dc1fc);_0x4a0153['query'][_0x1bbf92('0x37')]&&(_0x587863[_0x1bbf92('0x4e')]=_[_0x1bbf92('0x19')](_0x587863['where'],{[Op['or']]:_['map'](_0x5dc1fc,function(_0x33835d){const _0x14ce5e=_0x1bbf92;if(_0x33835d[_0x14ce5e('0x5')]!==_0x14ce5e('0x3a')){const _0x7b5722={};return _0x7b5722[_0x33835d[_0x14ce5e('0x47')]]={[Op['like']]:'%'+_0x4a0153[_0x14ce5e('0x40')][_0x14ce5e('0x37')]+'%'},_0x7b5722;}})}));_0x587863=_[_0x1bbf92('0x19')]({},_0x587863,_0x4a0153[_0x1bbf92('0x8')]);const _0x4dd084={'where':_0x587863[_0x1bbf92('0x4e')]};return db[_0x1bbf92('0x4')]['count'](_0x4dd084)[_0x1bbf92('0x42')](function(_0x498d82){const _0x256132=_0x1bbf92;return _0x41b2c1[_0x256132('0x48')]=_0x498d82,_0x4a0153[_0x256132('0x40')][_0x256132('0x23')]&&(_0x587863[_0x256132('0x4f')]=[{'all':!![]}]),db['VoiceExtension'][_0x256132('0x12')](_0x587863);})[_0x1bbf92('0x42')](function(_0x380f2e){const _0x2e4004=_0x1bbf92;return _0x41b2c1[_0x2e4004('0x3')]=_0x380f2e,_0x41b2c1;})[_0x1bbf92('0x42')](respondWithFilteredResult(_0x3eb78f,_0x587863))[_0x1bbf92('0x50')](handleError(_0x3eb78f,null));},exports[_0x5150f4('0x16')]=function(_0x5845c2,_0x471764){const _0x1c2fbd=_0x5150f4;let _0x2c50d7={'raw':![],'where':{'id':_0x5845c2['params']['id']}};const _0x1efc74={};return _0x1efc74['model']=_[_0x1c2fbd('0x29')](db[_0x1c2fbd('0x4')]['rawAttributes']),_0x1efc74['query']=_[_0x1c2fbd('0x29')](_0x5845c2[_0x1c2fbd('0x40')]),_0x1efc74['filters']=_[_0x1c2fbd('0x20')](_0x1efc74[_0x1c2fbd('0x45')],_0x1efc74['query']),_0x2c50d7['attributes']=_[_0x1c2fbd('0x20')](_0x1efc74[_0x1c2fbd('0x45')],qs['fields'](_0x5845c2[_0x1c2fbd('0x40')][_0x1c2fbd('0x51')])),_0x2c50d7[_0x1c2fbd('0x11')]=_0x2c50d7['attributes']['length']?_0x2c50d7['attributes']:_0x1efc74[_0x1c2fbd('0x45')],_0x5845c2[_0x1c2fbd('0x40')][_0x1c2fbd('0x23')]&&(_0x2c50d7[_0x1c2fbd('0x4f')]=[{'all':!![]}]),_0x2c50d7=_[_0x1c2fbd('0x19')]({},_0x2c50d7,_0x5845c2[_0x1c2fbd('0x8')]),db[_0x1c2fbd('0x4')]['findOne'](_0x2c50d7)[_0x1c2fbd('0x42')](handleEntityNotFound(_0x471764,null))[_0x1c2fbd('0x42')](respondWithResult(_0x471764,null))[_0x1c2fbd('0x50')](handleError(_0x471764,null));},exports['destroy']=function(_0x22467e,_0x2f2584){const _0x674832=_0x5150f4;return db[_0x674832('0x4')][_0x674832('0x32')]({'where':{'id':_0x22467e['params']['id']}})['then'](handleEntityNotFound(_0x2f2584,null))['then'](removeEntity(_0x2f2584,null))[_0x674832('0x50')](handleError(_0x2f2584,null));},exports[_0x5150f4('0x7')]=function(_0x3c8932,_0x52a37e){const _0x292e28=_0x5150f4;return _0x3c8932[_0x292e28('0x1b')][_0x292e28('0x5')]===_0x292e28('0x3e')&&!_[_0x292e28('0x18')](_0x3c8932[_0x292e28('0x1b')]['exten'],'_')&&(_0x3c8932['body'][_0x292e28('0x17')]='_'[_0x292e28('0x34')](_0x3c8932[_0x292e28('0x1b')][_0x292e28('0x17')])),db[_0x292e28('0x4')]['create'](_0x3c8932[_0x292e28('0x1b')],{'raw':![]})[_0x292e28('0x42')](function(_0x345058){const _0x5902cd=_0x292e28,_0x1fe8f8=_0x3c8932[_0x5902cd('0x4b')]['get']({'plain':!![]});if(!_0x1fe8f8)throw new Error(_0x5902cd('0x52'));if(_0x1fe8f8[_0x5902cd('0x2c')]===_0x5902cd('0x4b')){const _0x543ec0=_0x345058[_0x5902cd('0x4d')]({'plain':!![]}),_0x16c593=[{'name':_0x5902cd('0x2d'),'value':_0x5902cd('0x2a')},{'name':_0x5902cd('0x2'),'value':_0x5902cd('0x3e')},{'name':'InternalRoutes','value':_0x5902cd('0x1f')}],_0x4aec36=_[_0x5902cd('0x22')](_0x16c593,[_0x5902cd('0xb'),_0x543ec0[_0x5902cd('0x5')]])[_0x5902cd('0x47')];return db[_0x5902cd('0x41')]['findOne']({'where':{'name':_0x4aec36,'userProfileId':_0x1fe8f8[_0x5902cd('0x3f')]},'raw':!![]})[_0x5902cd('0x42')](function(_0x189b46){const _0xbca3cd=_0x5902cd;return _0x189b46&&_0x189b46[_0xbca3cd('0xe')]===0x0?db['UserProfileResource']['create']({'name':_0x543ec0[_0xbca3cd('0x47')],'resourceId':_0x543ec0['id'],'type':_0x189b46[_0xbca3cd('0x47')],'sectionId':_0x189b46['id']},{})['then'](function(){return _0x345058;}):_0x345058;})[_0x5902cd('0x50')](function(_0x35f0a4){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x35f0a4);throw _0x35f0a4;});}return _0x345058;})[_0x292e28('0x42')](respondWithResult(_0x52a37e,0xc9))['catch'](handleError(_0x52a37e,null));},exports[_0x5150f4('0x4c')]=function(_0x211af7,_0x24249f){const _0x54ef26=_0x5150f4;return _0x211af7[_0x54ef26('0x1b')]['id']&&delete _0x211af7['body']['id'],db['VoiceExtension'][_0x54ef26('0x32')]({'where':{'id':_0x211af7['params']['id']}})[_0x54ef26('0x42')](handleEntityNotFound(_0x24249f,null))[_0x54ef26('0x42')](function(_0x19fbec){const _0x42673b=_0x54ef26;if(_0x19fbec)return db[_0x42673b('0x4')][_0x42673b('0x4c')](_['pick'](_0x211af7[_0x42673b('0x1b')],[_0x42673b('0x17'),_0x42673b('0x13'),_0x42673b('0x43'),'recordingFormat',_0x42673b('0x1a'),_0x42673b('0xf')]),{'where':{'context':_0x19fbec[_0x42673b('0x13')],'exten':_0x19fbec[_0x42673b('0x17')]},'individualHooks':!![]})[_0x42673b('0x42')](function(_0x13127f){return _0x13127f;});return null;})[_0x54ef26('0x42')](respondWithStatusCode(_0x24249f,null))[_0x54ef26('0x50')](handleError(_0x24249f,null));},exports[_0x5150f4('0x44')]=function(_0x580648,_0x12924b){const _0x302790=_0x5150f4;return db[_0x302790('0x4')]['findOne']({'where':{'id':_0x580648[_0x302790('0x21')]['id']}})[_0x302790('0x42')](handleEntityNotFound(_0x12924b,null))[_0x302790('0x42')](function(_0x15802a){const _0x3116c9=_0x302790;if(_0x15802a)return db[_0x3116c9('0x28')][_0x3116c9('0x33')](function(_0x5bea9c){const _0x3d78b7=_0x3116c9;return db['VoiceExtension'][_0x3d78b7('0x46')]({'where':{'VoiceExtensionId':_0x580648[_0x3d78b7('0x21')]['id']},'transaction':_0x5bea9c})[_0x3d78b7('0x42')](function(){const _0x2ca2ae=_0x3d78b7,_0x2a6605=_['map'](_0x580648[_0x2ca2ae('0x1b')],function(_0x2b5067){const _0x3c4aa4=_0x2ca2ae;return _0x2b5067[_0x3c4aa4('0x30')]=_0x580648['params']['id'],_0x2b5067;});return db['VoiceExtension'][_0x2ca2ae('0x6')](_0x2a6605,{'transaction':_0x5bea9c});});})[_0x3116c9('0x42')](function(){const _0x532a8a=_0x3116c9;return db[_0x532a8a('0x4')][_0x532a8a('0x3b')]({'where':{'isApp':!![],'VoiceExtensionId':_0x580648[_0x532a8a('0x21')]['id']},'order':_0x532a8a('0x31')});});})[_0x302790('0x42')](respondWithResult(_0x12924b,null))['catch'](handleError(_0x12924b,null));};