Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / voicePrefix / voicePrefix.controller.js
index 6284776..8b178e0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x056b=['forEach','removeTeams','select','field','tq.TeamId','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','VoicePrefixId\x20=\x20?','clone','ut.UserId\x20=\x20?','toString','QueryTypes','SELECT','every','TeamId','includes','all','union','value','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','./voicePrefix.socket','register','sendStatus','end','json','offset','limit','undefined','count','set','apply','reject','update','destroy','then','get','VoicePrefixes','UserProfileResource','status','error','stack','name','send','index','map','VoicePrefix','rawAttributes','fieldName','key','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','type','options','includeAll','include','findAll','rows','catch','params','find','describe','create','sequelize','transaction','body','VoiceExtension','VoiceExtensionId','user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','context','from-sip','app','system','description','Voice\x20Prefix\x20Extension','priority','appdata','prefix','Voice\x20Prefix','VoicePrefixId','bulkCreate','Extensions\x20creation\x20failed','Set','CDR(prefix)=','callerIdAll','push','NoOp','goto','${EXTEN:','charAt','system-','findById','addAgents','ids','spread','emit','userVoicePrefix:save','removeAgents','isArray','userVoicePrefix:remove','getAgents','findOne','order','Team','getTeams','addTeams','User','Agents','online','voicePause','flatMap','each','TeamVoicePrefix','upsert','UserVoicePrefix','findOrCreate'];(function(_0x46698a,_0x8de1e4){var _0x356db0=function(_0x19e83c){while(--_0x19e83c){_0x46698a['push'](_0x46698a['shift']());}};_0x356db0(++_0x8de1e4);}(_0x056b,0xb6));var _0xb056=function(_0x2d9f8f,_0x40bc79){_0x2d9f8f=_0x2d9f8f-0x0;var _0x240df4=_0x056b[_0x2d9f8f];return _0x240df4;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb056('0x0'));var zipdir=require(_0xb056('0x1'));var jsonpatch=require(_0xb056('0x2'));var rp=require(_0xb056('0x3'));var moment=require(_0xb056('0x4'));var BPromise=require(_0xb056('0x5'));var Mustache=require(_0xb056('0x6'));var util=require(_0xb056('0x7'));var path=require(_0xb056('0x8'));var sox=require(_0xb056('0x9'));var csv=require(_0xb056('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb056('0xb'));var _=require(_0xb056('0xc'));var squel=require(_0xb056('0xd'));var crypto=require(_0xb056('0xe'));var jsforce=require(_0xb056('0xf'));var deskjs=require(_0xb056('0x10'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xb056('0x11'));var Redis=require(_0xb056('0x12'));var authService=require(_0xb056('0x13'));var qs=require(_0xb056('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb056('0x15'));var logger=require('../../config/logger')(_0xb056('0x16'));var utils=require(_0xb056('0x17'));var config=require(_0xb056('0x18'));var licenseUtil=require(_0xb056('0x19'));var db=require(_0xb056('0x1a'))['db'];config['redis']=_['defaults'](config[_0xb056('0x1b')],{'host':_0xb056('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb056('0x1b')]));require(_0xb056('0x1d'))[_0xb056('0x1e')](socket);function respondWithStatusCode(_0x1197e5,_0x10dd19){_0x10dd19=_0x10dd19||0xcc;return function(_0x3776a1){if(_0x3776a1){return _0x1197e5[_0xb056('0x1f')](_0x10dd19);}return _0x1197e5['status'](_0x10dd19)[_0xb056('0x20')]();};}function respondWithResult(_0x43565e,_0x9e2eed){_0x9e2eed=_0x9e2eed||0xc8;return function(_0x65d7ca){if(_0x65d7ca){return _0x43565e['status'](_0x9e2eed)[_0xb056('0x21')](_0x65d7ca);}};}function respondWithFilteredResult(_0x4e501a,_0x2daffc){return function(_0x311eb9){if(_0x311eb9){var _0x48e140=typeof _0x2daffc[_0xb056('0x22')]==='undefined'&&typeof _0x2daffc[_0xb056('0x23')]===_0xb056('0x24');var _0x5e4bd9=_0x311eb9[_0xb056('0x25')];var _0x48cdaf=_0x48e140?0x0:_0x2daffc[_0xb056('0x22')];var _0x225081=_0x48e140?_0x311eb9[_0xb056('0x25')]:_0x2daffc[_0xb056('0x22')]+_0x2daffc['limit'];var _0x1db585;if(_0x225081>=_0x5e4bd9){_0x225081=_0x5e4bd9;_0x1db585=0xc8;}else{_0x1db585=0xce;}_0x4e501a['status'](_0x1db585);return _0x4e501a[_0xb056('0x26')]('Content-Range',_0x48cdaf+'-'+_0x225081+'/'+_0x5e4bd9)[_0xb056('0x21')](_0x311eb9);}return null;};}function patchUpdates(_0x40ac2d){return function(_0x1de11b){try{jsonpatch[_0xb056('0x27')](_0x1de11b,_0x40ac2d,!![]);}catch(_0x36e539){return BPromise[_0xb056('0x28')](_0x36e539);}return _0x1de11b['save']();};}function saveUpdates(_0x1016da,_0x18a3f2){return function(_0x341544){if(_0x341544){return _0x341544[_0xb056('0x29')](_0x1016da)['then'](function(_0x44a14f){return _0x44a14f;});}return null;};}function removeEntity(_0x10b9b3,_0x5c39db){return function(_0x6d0483){if(_0x6d0483){return _0x6d0483[_0xb056('0x2a')]()[_0xb056('0x2b')](function(){var _0x1d2c66=_0x6d0483[_0xb056('0x2c')]({'plain':!![]});var _0x4024d7=_0xb056('0x2d');return db[_0xb056('0x2e')]['destroy']({'where':{'type':_0x4024d7,'resourceId':_0x1d2c66['id']}})[_0xb056('0x2b')](function(){return _0x6d0483;});})['then'](function(){_0x10b9b3[_0xb056('0x2f')](0xcc)[_0xb056('0x20')]();});}};}function handleEntityNotFound(_0x294874,_0x488185){return function(_0xd53267){if(!_0xd53267){_0x294874[_0xb056('0x1f')](0x194);}return _0xd53267;};}function handleError(_0x4ba5f8,_0x3a9e7d){_0x3a9e7d=_0x3a9e7d||0x1f4;return function(_0x43aa63){logger[_0xb056('0x30')](_0x43aa63[_0xb056('0x31')]);if(_0x43aa63[_0xb056('0x32')]){delete _0x43aa63['name'];}_0x4ba5f8[_0xb056('0x2f')](_0x3a9e7d)[_0xb056('0x33')](_0x43aa63);};}exports[_0xb056('0x34')]=function(_0x248473,_0x103482){var _0x559c34={},_0x16bbd2={},_0x290807={'count':0x0,'rows':[]};var _0x16c1d6=_[_0xb056('0x35')](db[_0xb056('0x36')][_0xb056('0x37')],function(_0x19f277){return{'name':_0x19f277[_0xb056('0x38')],'type':_0x19f277['type'][_0xb056('0x39')]};});_0x16bbd2['model']=_[_0xb056('0x35')](_0x16c1d6,'name');_0x16bbd2['query']=_[_0xb056('0x3a')](_0x248473[_0xb056('0x3b')]);_0x16bbd2[_0xb056('0x3c')]=_[_0xb056('0x3d')](_0x16bbd2[_0xb056('0x3e')],_0x16bbd2[_0xb056('0x3b')]);_0x559c34[_0xb056('0x3f')]=_['intersection'](_0x16bbd2[_0xb056('0x3e')],qs[_0xb056('0x40')](_0x248473['query']['fields']));_0x559c34[_0xb056('0x3f')]=_0x559c34[_0xb056('0x3f')][_0xb056('0x41')]?_0x559c34['attributes']:_0x16bbd2[_0xb056('0x3e')];if(!_0x248473[_0xb056('0x3b')][_0xb056('0x42')](_0xb056('0x43'))){_0x559c34[_0xb056('0x23')]=qs[_0xb056('0x23')](_0x248473[_0xb056('0x3b')][_0xb056('0x23')]);_0x559c34[_0xb056('0x22')]=qs[_0xb056('0x22')](_0x248473[_0xb056('0x3b')][_0xb056('0x22')]);}_0x559c34['order']=qs[_0xb056('0x44')](_0x248473['query'][_0xb056('0x44')]);_0x559c34[_0xb056('0x45')]=qs[_0xb056('0x3c')](_[_0xb056('0x46')](_0x248473[_0xb056('0x3b')],_0x16bbd2[_0xb056('0x3c')]),_0x16c1d6);if(_0x248473[_0xb056('0x3b')][_0xb056('0x47')]){_0x559c34['where']=_[_0xb056('0x48')](_0x559c34[_0xb056('0x45')],{'$or':_[_0xb056('0x35')](_0x16c1d6,function(_0x4c2b1e){if(_0x4c2b1e[_0xb056('0x49')]!=='VIRTUAL'){var _0x39b861={};_0x39b861[_0x4c2b1e[_0xb056('0x32')]]={'$like':'%'+_0x248473[_0xb056('0x3b')][_0xb056('0x47')]+'%'};return _0x39b861;}})});}_0x559c34=_[_0xb056('0x48')]({},_0x559c34,_0x248473[_0xb056('0x4a')]);var _0x57da48={'where':_0x559c34[_0xb056('0x45')]};return db['VoicePrefix'][_0xb056('0x25')](_0x57da48)[_0xb056('0x2b')](function(_0x21d98e){_0x290807[_0xb056('0x25')]=_0x21d98e;if(_0x248473[_0xb056('0x3b')][_0xb056('0x4b')]){_0x559c34[_0xb056('0x4c')]=[{'all':!![]}];}return db[_0xb056('0x36')][_0xb056('0x4d')](_0x559c34);})[_0xb056('0x2b')](function(_0x4fa3c5){_0x290807[_0xb056('0x4e')]=_0x4fa3c5;return _0x290807;})[_0xb056('0x2b')](respondWithFilteredResult(_0x103482,_0x559c34))[_0xb056('0x4f')](handleError(_0x103482,null));};exports['show']=function(_0x2bf4dd,_0x505cad){var _0x49597d={'raw':![],'where':{'id':_0x2bf4dd[_0xb056('0x50')]['id']}},_0x5821e1={};_0x5821e1[_0xb056('0x3e')]=_[_0xb056('0x3a')](db[_0xb056('0x36')]['rawAttributes']);_0x5821e1['query']=_['keys'](_0x2bf4dd['query']);_0x5821e1['filters']=_['intersection'](_0x5821e1[_0xb056('0x3e')],_0x5821e1['query']);_0x49597d[_0xb056('0x3f')]=_[_0xb056('0x3d')](_0x5821e1[_0xb056('0x3e')],qs[_0xb056('0x40')](_0x2bf4dd[_0xb056('0x3b')][_0xb056('0x40')]));_0x49597d[_0xb056('0x3f')]=_0x49597d[_0xb056('0x3f')]['length']?_0x49597d[_0xb056('0x3f')]:_0x5821e1[_0xb056('0x3e')];if(_0x2bf4dd['query'][_0xb056('0x4b')]){_0x49597d[_0xb056('0x4c')]=[{'all':!![]}];}_0x49597d=_[_0xb056('0x48')]({},_0x49597d,_0x2bf4dd[_0xb056('0x4a')]);return db[_0xb056('0x36')][_0xb056('0x51')](_0x49597d)['then'](handleEntityNotFound(_0x505cad,null))[_0xb056('0x2b')](respondWithResult(_0x505cad,null))['catch'](handleError(_0x505cad,null));};exports[_0xb056('0x2a')]=function(_0x3e4a14,_0xde5564){return db[_0xb056('0x36')][_0xb056('0x51')]({'where':{'id':_0x3e4a14[_0xb056('0x50')]['id']}})[_0xb056('0x2b')](handleEntityNotFound(_0xde5564,null))[_0xb056('0x2b')](removeEntity(_0xde5564,null))['catch'](handleError(_0xde5564,null));};exports[_0xb056('0x52')]=function(_0x472a91,_0x5927c7){return db[_0xb056('0x36')][_0xb056('0x52')]()[_0xb056('0x2b')](respondWithResult(_0x5927c7,null))[_0xb056('0x4f')](handleError(_0x5927c7,null));};exports[_0xb056('0x53')]=function(_0x4a9968,_0x122ed7){var _0xc0be0d;return db[_0xb056('0x54')][_0xb056('0x55')](function(_0x1a5170){return db[_0xb056('0x36')]['create'](_0x4a9968[_0xb056('0x56')],{'transaction':_0x1a5170})[_0xb056('0x2b')](function(_0x30ba6e){_0xc0be0d=_0x30ba6e['get']({'plain':!![]});return db[_0xb056('0x57')]['find']({'where':{'id':_0xc0be0d[_0xb056('0x58')]},'raw':!![]})[_0xb056('0x2b')](function(_0x2a064f){return createVoicePrefixExtensions(_0xc0be0d,_0x2a064f,_0x1a5170);});});})[_0xb056('0x2b')](function(){var _0x58c533=_0x4a9968[_0xb056('0x59')][_0xb056('0x2c')]({'plain':!![]});if(!_0x58c533)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x58c533[_0xb056('0x5a')]===_0xb056('0x59')){var _0x1d3cdd=_0xc0be0d;return db[_0xb056('0x5b')][_0xb056('0x51')]({'where':{'name':'VoicePrefixes','userProfileId':_0x58c533[_0xb056('0x5c')]},'raw':!![]})[_0xb056('0x2b')](function(_0x10681b){if(_0x10681b&&_0x10681b[_0xb056('0x5d')]===0x0){return db[_0xb056('0x2e')][_0xb056('0x53')]({'name':_0x1d3cdd[_0xb056('0x32')],'resourceId':_0x1d3cdd['id'],'type':_0x10681b[_0xb056('0x32')],'sectionId':_0x10681b['id']},{})[_0xb056('0x2b')](function(){return _0xc0be0d;});}else{return _0xc0be0d;}})[_0xb056('0x4f')](function(_0x1b4a0d){logger[_0xb056('0x30')](_0xb056('0x5e'),_0x1b4a0d);throw _0x1b4a0d;});}return _0xc0be0d;})[_0xb056('0x2b')](respondWithResult(_0x122ed7,null))[_0xb056('0x4f')](handleError(_0x122ed7,null));};function Extension(_0x282c31,_0x28fc90,_0x435fe9,_0x39765e){this[_0xb056('0x5f')]=_0xb056('0x60');this['exten']=_0x282c31;this[_0xb056('0x61')]=_0x435fe9;this[_0xb056('0x49')]=_0xb056('0x62');this[_0xb056('0x63')]=_0xb056('0x64');this[_0xb056('0x65')]=_0x28fc90;this[_0xb056('0x66')]=_0x39765e;}function createVoicePrefixExtensions(_0x55808b,_0x5b03df,_0x30441e){return new BPromise(function(_0x388817,_0x1205cc){var _0x7b81c7=new Extension(formatPrefixName(_0x55808b[_0xb056('0x67')]),0x1,'NoOp',_0xb056('0x68'));_0x7b81c7[_0xb056('0x69')]=_0x55808b['id'];return db[_0xb056('0x57')][_0xb056('0x53')](_0x7b81c7,{'transaction':_0x30441e})['then'](function(_0x405108){var _0x24b037=_0x405108[_0xb056('0x2c')]({'plain':!![]});var _0x5e419e=_[_0xb056('0x35')](addVoicePrefixExtensions(_0x55808b,_0x5b03df),function(_0x2e02d5){_0x2e02d5[_0xb056('0x58')]=_0x24b037['id'];_0x2e02d5['VoicePrefixId']=_0x55808b['id'];return _0x2e02d5;});return db[_0xb056('0x57')][_0xb056('0x6a')](_0x5e419e,{'transaction':_0x30441e})[_0xb056('0x2b')](function(_0x5bf8ce){if(!_0x5bf8ce){return _0x1205cc(_0xb056('0x6b'));}else{return _0x388817(_0x5bf8ce);}})['catch'](function(_0x2d555d){return _0x1205cc(_0x2d555d);});});;});};function addVoicePrefixExtensions(_0x3e18c1,_0x103ff2){var _0x556a93=[];var _0x45d347=formatPrefixName(_0x3e18c1[_0xb056('0x67')]);_0x556a93['push'](new Extension(_0x45d347,0x2,_0xb056('0x6c'),_0xb056('0x6d')+_0x3e18c1[_0xb056('0x32')]));if(_0x3e18c1[_0xb056('0x6e')]){_0x556a93[_0xb056('0x6f')](new Extension(_0x45d347,0x3,'Set','PREFIX-CALLERIDALL='+_0x3e18c1[_0xb056('0x6e')]));}else{_0x556a93['push'](new Extension(_0x45d347,0x3,_0xb056('0x70'),'No\x20callerid\x20available'));}_0x556a93[_0xb056('0x6f')](new Extension(_0x45d347,0x4,_0xb056('0x71'),_0x103ff2[_0xb056('0x5f')]+','+_0xb056('0x72')+(0x8+_0x3e18c1['name']['length'])+'}'+','+0x1));return _0x556a93;}function formatPrefixName(_0xe6caf7){var _0x1e14e1='_';for(var _0x3b3bbf=0x0;_0x3b3bbf<_0xe6caf7[_0xb056('0x41')];_0x3b3bbf++){if(_0xe6caf7['charAt'](_0x3b3bbf)=='-'){_0x1e14e1+=_0xe6caf7[_0xb056('0x73')](_0x3b3bbf);}else{_0x1e14e1+='['+_0xe6caf7['charAt'](_0x3b3bbf)+']';}}_0x1e14e1+='.';return _0x1e14e1;}exports[_0xb056('0x29')]=function(_0x5f0278,_0x2129c5,_0x56bab7){var _0x432501=_0x5f0278[_0xb056('0x56')];_0x432501[_0xb056('0x67')]=_0xb056('0x74')+_0x432501['name']+'-';return db[_0xb056('0x54')]['transaction'](function(_0x227ab0){return db[_0xb056('0x36')][_0xb056('0x29')](_0x432501,{'where':{'id':_0x432501['id']},'transaction':_0x227ab0})[_0xb056('0x2b')](function(){return db[_0xb056('0x57')][_0xb056('0x2a')]({'where':{'VoicePrefixId':_0x432501['id']},'transaction':_0x227ab0})[_0xb056('0x2b')](function(){return db[_0xb056('0x57')][_0xb056('0x51')]({'where':{'id':_0x432501[_0xb056('0x58')]},'raw':!![]})[_0xb056('0x2b')](function(_0x3f6e2f){return createVoicePrefixExtensions(_0x432501,_0x3f6e2f,_0x227ab0);});});});})['then'](function(){return db['VoicePrefix'][_0xb056('0x75')](_0x432501['id']);})['then'](respondWithResult(_0x2129c5,null))[_0xb056('0x4f')](handleError(_0x2129c5,null));};exports['addAgents']=function(_0x208696,_0x5df962,_0x5f4b72){return db['VoicePrefix'][_0xb056('0x51')]({'where':{'id':_0x208696['params']['id']}})['then'](handleEntityNotFound(_0x5df962,null))[_0xb056('0x2b')](function(_0xb6fd9b){if(_0xb6fd9b){return _0xb6fd9b[_0xb056('0x76')](_0x208696['body']['ids'],_['omit'](_0x208696[_0xb056('0x56')],[_0xb056('0x77'),'id'])||{})[_0xb056('0x78')](function(_0x13bd5f){for(var _0x9185c=0x0;_0x9185c<_0x208696[_0xb056('0x56')][_0xb056('0x77')][_0xb056('0x41')];_0x9185c+=0x1){socket[_0xb056('0x79')](_0xb056('0x7a'),{'UserId':Number(_0x208696[_0xb056('0x56')][_0xb056('0x77')][_0x9185c]),'VoicePrefixId':Number(_0x208696[_0xb056('0x50')]['id'])});}return _0x13bd5f;});}})[_0xb056('0x2b')](respondWithResult(_0x5df962,null))['catch'](handleError(_0x5df962,null));};exports['removeAgents']=function(_0x18feb4,_0x5ef886,_0x11ef5f){return db[_0xb056('0x36')][_0xb056('0x51')]({'where':{'id':_0x18feb4[_0xb056('0x50')]['id']}})['then'](handleEntityNotFound(_0x5ef886,null))['then'](function(_0x2e027a){if(_0x2e027a){return _0x2e027a[_0xb056('0x7b')](_0x18feb4[_0xb056('0x3b')]['ids'])['then'](function(){if(_[_0xb056('0x7c')](_0x18feb4[_0xb056('0x3b')]['ids'])){for(var _0x345cf9=0x0;_0x345cf9<_0x18feb4[_0xb056('0x3b')][_0xb056('0x77')][_0xb056('0x41')];_0x345cf9+=0x1){socket[_0xb056('0x79')](_0xb056('0x7d'),{'UserId':Number(_0x18feb4[_0xb056('0x3b')][_0xb056('0x77')][_0x345cf9]),'VoicePrefixId':Number(_0x18feb4[_0xb056('0x50')]['id'])});}}else{socket[_0xb056('0x79')](_0xb056('0x7d'),{'UserId':Number(_0x18feb4['query'][_0xb056('0x77')]),'VoicePrefixId':Number(_0x18feb4[_0xb056('0x50')]['id'])});}});}})[_0xb056('0x2b')](respondWithStatusCode(_0x5ef886,null))['catch'](handleError(_0x5ef886,null));};exports[_0xb056('0x7e')]=function(_0x4dc495,_0x489233,_0x1b0bbb){var _0x3a2f2f={};var _0x2d7c96={};var _0x56578e;var _0x493d0d;return db[_0xb056('0x36')][_0xb056('0x7f')]({'where':{'id':_0x4dc495['params']['id']}})[_0xb056('0x2b')](handleEntityNotFound(_0x489233,null))['then'](function(_0x3b0f93){if(_0x3b0f93){_0x56578e=_0x3b0f93;_0x2d7c96[_0xb056('0x3e')]=_['keys'](db['User'][_0xb056('0x37')]);_0x2d7c96[_0xb056('0x3b')]=_['keys'](_0x4dc495[_0xb056('0x3b')]);_0x2d7c96['filters']=_['intersection'](_0x2d7c96[_0xb056('0x3e')],_0x2d7c96[_0xb056('0x3b')]);_0x3a2f2f[_0xb056('0x3f')]=_[_0xb056('0x3d')](_0x2d7c96[_0xb056('0x3e')],qs[_0xb056('0x40')](_0x4dc495['query'][_0xb056('0x40')]));_0x3a2f2f['attributes']=_0x3a2f2f[_0xb056('0x3f')][_0xb056('0x41')]?_0x3a2f2f['attributes']:_0x2d7c96[_0xb056('0x3e')];_0x3a2f2f[_0xb056('0x80')]=qs['sort'](_0x4dc495[_0xb056('0x3b')]['sort']);_0x3a2f2f[_0xb056('0x45')]=qs['filters'](_[_0xb056('0x46')](_0x4dc495[_0xb056('0x3b')],_0x2d7c96['filters']));if(_0x4dc495[_0xb056('0x3b')]['filter']){_0x3a2f2f[_0xb056('0x45')]=_[_0xb056('0x48')](_0x3a2f2f[_0xb056('0x45')],{'$or':_[_0xb056('0x35')](_0x3a2f2f[_0xb056('0x3f')],function(_0x100a52){var _0x1bac84={};_0x1bac84[_0x100a52]={'$like':'%'+_0x4dc495[_0xb056('0x3b')]['filter']+'%'};return _0x1bac84;})});}_0x3a2f2f=_[_0xb056('0x48')]({},_0x3a2f2f,_0x4dc495['options']);return _0x56578e['getAgents'](_0x3a2f2f);}})['then'](function(_0x2ea984){if(_0x2ea984){_0x493d0d=_0x2ea984[_0xb056('0x41')];if(!_0x4dc495[_0xb056('0x3b')][_0xb056('0x42')]('nolimit')){_0x3a2f2f[_0xb056('0x23')]=qs[_0xb056('0x23')](_0x4dc495[_0xb056('0x3b')][_0xb056('0x23')]);_0x3a2f2f[_0xb056('0x22')]=qs['offset'](_0x4dc495[_0xb056('0x3b')][_0xb056('0x22')]);}return _0x56578e[_0xb056('0x7e')](_0x3a2f2f);}})['then'](function(_0x526035){if(_0x526035){return _0x526035?{'count':_0x493d0d,'rows':_0x526035}:null;}})['then'](respondWithResult(_0x489233,null))['catch'](handleError(_0x489233,null));};exports['getTeams']=function(_0x5021d2,_0x41532c,_0x1f5c6d){var _0xd82e9={};var _0x2b62f1={};var _0x38b119;var _0xcdd8d6;return db['VoicePrefix'][_0xb056('0x7f')]({'where':{'id':_0x5021d2[_0xb056('0x50')]['id']}})[_0xb056('0x2b')](handleEntityNotFound(_0x41532c,null))[_0xb056('0x2b')](function(_0x1ff1e7){if(_0x1ff1e7){_0x38b119=_0x1ff1e7;_0x2b62f1[_0xb056('0x3e')]=_[_0xb056('0x3a')](db[_0xb056('0x81')][_0xb056('0x37')]);_0x2b62f1[_0xb056('0x3b')]=_['keys'](_0x5021d2['query']);_0x2b62f1['filters']=_[_0xb056('0x3d')](_0x2b62f1['model'],_0x2b62f1[_0xb056('0x3b')]);_0xd82e9[_0xb056('0x3f')]=_[_0xb056('0x3d')](_0x2b62f1[_0xb056('0x3e')],qs[_0xb056('0x40')](_0x5021d2[_0xb056('0x3b')][_0xb056('0x40')]));_0xd82e9[_0xb056('0x3f')]=_0xd82e9[_0xb056('0x3f')]['length']?_0xd82e9[_0xb056('0x3f')]:_0x2b62f1[_0xb056('0x3e')];_0xd82e9[_0xb056('0x80')]=qs[_0xb056('0x44')](_0x5021d2['query']['sort']);_0xd82e9[_0xb056('0x45')]=qs[_0xb056('0x3c')](_[_0xb056('0x46')](_0x5021d2[_0xb056('0x3b')],_0x2b62f1[_0xb056('0x3c')]));if(_0x5021d2[_0xb056('0x3b')][_0xb056('0x47')]){_0xd82e9['where']=_[_0xb056('0x48')](_0xd82e9['where'],{'$or':_[_0xb056('0x35')](_0xd82e9[_0xb056('0x3f')],function(_0x5ba4b4){var _0x13ea6a={};_0x13ea6a[_0x5ba4b4]={'$like':'%'+_0x5021d2['query'][_0xb056('0x47')]+'%'};return _0x13ea6a;})});}_0xd82e9=_[_0xb056('0x48')]({},_0xd82e9,_0x5021d2[_0xb056('0x4a')]);return _0x38b119[_0xb056('0x82')](_0xd82e9);}})[_0xb056('0x2b')](function(_0x48dbfb){if(_0x48dbfb){_0xcdd8d6=_0x48dbfb[_0xb056('0x41')];if(!_0x5021d2[_0xb056('0x3b')][_0xb056('0x42')](_0xb056('0x43'))){_0xd82e9[_0xb056('0x23')]=qs[_0xb056('0x23')](_0x5021d2[_0xb056('0x3b')][_0xb056('0x23')]);_0xd82e9[_0xb056('0x22')]=qs[_0xb056('0x22')](_0x5021d2[_0xb056('0x3b')][_0xb056('0x22')]);}return _0x38b119[_0xb056('0x82')](_0xd82e9);}})[_0xb056('0x2b')](function(_0x3837af){if(_0x3837af){return _0x3837af?{'count':_0xcdd8d6,'rows':_0x3837af}:null;}})[_0xb056('0x2b')](respondWithResult(_0x41532c,null))[_0xb056('0x4f')](handleError(_0x41532c,null));};exports[_0xb056('0x83')]=function(_0x1a8d5b,_0x341a86,_0x506e61){var _0x263bbe=_0x1a8d5b[_0xb056('0x56')][_0xb056('0x77')];var _0x3de775;return db[_0xb056('0x81')][_0xb056('0x4d')]({'where':{'id':_0x263bbe},'attributes':['id'],'include':[{'model':db[_0xb056('0x84')],'as':_0xb056('0x85'),'attributes':['id',_0xb056('0x32'),_0xb056('0x86'),_0xb056('0x87'),'interface'],'raw':!![]}]})['then'](function(_0x330dd3){if(_0x330dd3){_0x3de775=_0x330dd3;var _0x5e5b65=_[_0xb056('0x88')](_0x330dd3,function(_0x88e59f){var _0x2b36b0=_0x88e59f['get']({'plain':!![]});return _0x2b36b0[_0xb056('0x85')];});return db[_0xb056('0x36')]['find']({'where':{'id':_0x1a8d5b['params']['id']}})[_0xb056('0x2b')](function(_0x3f80ab){return db[_0xb056('0x54')][_0xb056('0x55')](function(_0x11276e){return _0x3f80ab['addTeams'](_0x263bbe,{'transaction':_0x11276e})['then'](function(){return BPromise[_0xb056('0x89')](_0x3de775,function(_0x587fcc){return db[_0xb056('0x8a')][_0xb056('0x8b')]({'TeamId':_0x587fcc['id'],'VoicePrefixId':_0x1a8d5b[_0xb056('0x50')]['id']},{'transaction':_0x11276e});});})[_0xb056('0x2b')](function(){return BPromise['each'](_0x5e5b65,function(_0x31fc76){return db[_0xb056('0x8c')][_0xb056('0x8d')]({'where':{'UserId':_0x31fc76['id'],'VoicePrefixId':_0x1a8d5b[_0xb056('0x50')]['id']},'transaction':_0x11276e});});})[_0xb056('0x2b')](function(){_0x5e5b65[_0xb056('0x8e')](function(_0x221269){socket['emit'](_0xb056('0x7a'),{'UserId':_0x221269['id'],'VoicePrefixId':_0x3f80ab['id']});});});});});}})[_0xb056('0x2b')](respondWithStatusCode(_0x341a86,null))[_0xb056('0x4f')](handleError(_0x341a86,null));};exports[_0xb056('0x8f')]=function(_0x38c9fd,_0x3d277a,_0x3803bc){return db['Team'][_0xb056('0x4d')]({'where':{'id':_0x38c9fd[_0xb056('0x3b')][_0xb056('0x77')]},'attributes':['id'],'include':[{'model':db['User'],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0xb056('0x2b')](handleEntityNotFound(_0x3d277a,null))['then'](function(_0x59020b){var _0x158f35=_[_0xb056('0x35')](_0x59020b,'id');var _0x18ee53=[];var _0xc4c8b4=[];var _0x1cca4d=squel[_0xb056('0x90')]();_0x1cca4d[_0xb056('0x91')](_0xb056('0x92'))['from']('team_has_voice_prefixes','tq')[_0xb056('0x93')](_0xb056('0x94'),'ut',_0xb056('0x95'))[_0xb056('0x45')](_0xb056('0x96'),_0x38c9fd[_0xb056('0x50')]['id']);for(var _0x5a7549=0x0;_0x5a7549<_0x59020b['length'];_0x5a7549+=0x1){let _0x4c9894=_0x59020b[_0x5a7549];for(var _0x2b75e4=0x0;_0x2b75e4<_0x4c9894['Agents'][_0xb056('0x41')];_0x2b75e4+=0x1){let _0x505f0d=_0x4c9894[_0xb056('0x85')][_0x2b75e4];var _0x462eb8=_0x1cca4d[_0xb056('0x97')]();_0x462eb8[_0xb056('0x45')](_0xb056('0x98'),_0x505f0d['id']);_0xc4c8b4[_0xb056('0x6f')](db[_0xb056('0x54')]['query'](_0x462eb8[_0xb056('0x99')](),{'type':db[_0xb056('0x54')][_0xb056('0x9a')][_0xb056('0x9b')]})[_0xb056('0x2b')](function(_0x499233){if(_0x499233[_0xb056('0x41')]===0x1){return _0x505f0d['id'];}else{var _0x391783=_[_0xb056('0x9c')](_[_0xb056('0x35')](_0x499233,_0xb056('0x9d')),function(_0x2f08e1){return _[_0xb056('0x9e')](_0x158f35,_0x2f08e1);});if(_0x391783){return _0x505f0d['id'];}}}));}}return BPromise[_0xb056('0x9f')](_0xc4c8b4)[_0xb056('0x2b')](function(_0x42b105){_0x18ee53=_(_0x18ee53)[_0xb056('0xa0')](_0x42b105)['compact']()[_0xb056('0xa1')]();return db[_0xb056('0x36')]['find']({'where':{'id':_0x38c9fd['params']['id']}})['then'](function(_0x512997){return db[_0xb056('0x54')][_0xb056('0x55')](function(_0x2f7ca9){return _0x512997[_0xb056('0x8f')](_0x38c9fd[_0xb056('0x3b')][_0xb056('0x77')],{'transaction':_0x2f7ca9})[_0xb056('0x2b')](function(){if(!_['isEmpty'](_0x18ee53)){return _0x512997[_0xb056('0x7b')](_0x18ee53,{'transaction':_0x2f7ca9});}})['then'](function(){_0x18ee53['forEach'](function(_0x33b1ad){socket[_0xb056('0x79')](_0xb056('0x7d'),{'UserId':_0x33b1ad,'VoicePrefixId':_0x512997['id']});});});});});});})[_0xb056('0x2b')](respondWithStatusCode(_0x3d277a,null))[_0xb056('0x4f')](handleError(_0x3d277a,null));};
\ No newline at end of file
+var _0x5f2f=['VoicePrefixes','UserProfileResource','error','stack','name','send','map','VoicePrefix','rawAttributes','type','key','model','query','keys','filters','intersection','fields','attributes','length','nolimit','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','show','params','find','describe','create','transaction','body','get','VoiceExtension','user','role','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','from-sip','app','system','description','Voice\x20Prefix\x20Extension','appdata','Voice\x20Prefix','VoiceExtensionId','VoicePrefixId','Extensions\x20creation\x20failed','push','Set','CDR(prefix)=','callerIdAll','PREFIX-CALLERIDALL=','NoOp','No\x20callerid\x20available','goto','context','charAt','prefix','system-','sequelize','findById','addAgents','ids','omit','spread','emit','removeAgents','isArray','userVoicePrefix:remove','getAgents','order','hasOwnProperty','getTeams','findOne','Team','addTeams','User','Agents','online','voicePause','flatMap','each','TeamVoicePrefix','UserVoicePrefix','findOrCreate','forEach','userVoicePrefix:save','select','tq.TeamId','from','team_has_voice_prefixes','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','VoicePrefixId\x20=\x20?','clone','ut.UserId\x20=\x20?','toString','QueryTypes','SELECT','every','TeamId','all','union','compact','value','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','./voicePrefix.socket','register','sendStatus','status','end','json','offset','undefined','limit','set','Content-Range','apply','reject','save','update','then','destroy'];(function(_0x1177d5,_0x22b649){var _0xc3ddc2=function(_0x43ff95){while(--_0x43ff95){_0x1177d5['push'](_0x1177d5['shift']());}};_0xc3ddc2(++_0x22b649);}(_0x5f2f,0x73));var _0xf5f2=function(_0x25cdd2,_0x1150f9){_0x25cdd2=_0x25cdd2-0x0;var _0x1c76ce=_0x5f2f[_0x25cdd2];return _0x1c76ce;};'use strict';var emlformat=require(_0xf5f2('0x0'));var rimraf=require(_0xf5f2('0x1'));var zipdir=require(_0xf5f2('0x2'));var jsonpatch=require(_0xf5f2('0x3'));var rp=require(_0xf5f2('0x4'));var moment=require(_0xf5f2('0x5'));var BPromise=require(_0xf5f2('0x6'));var Mustache=require(_0xf5f2('0x7'));var util=require('util');var path=require('path');var sox=require(_0xf5f2('0x8'));var csv=require(_0xf5f2('0x9'));var ejs=require(_0xf5f2('0xa'));var fs=require('fs');var fs_extra=require(_0xf5f2('0xb'));var _=require(_0xf5f2('0xc'));var squel=require(_0xf5f2('0xd'));var crypto=require('crypto');var jsforce=require(_0xf5f2('0xe'));var deskjs=require(_0xf5f2('0xf'));var toCsv=require(_0xf5f2('0x9'));var querystring=require('querystring');var Papa=require(_0xf5f2('0x10'));var Redis=require(_0xf5f2('0x11'));var authService=require(_0xf5f2('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xf5f2('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf5f2('0x14'));var utils=require(_0xf5f2('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xf5f2('0x16'));var db=require(_0xf5f2('0x17'))['db'];config[_0xf5f2('0x18')]=_[_0xf5f2('0x19')](config[_0xf5f2('0x18')],{'host':_0xf5f2('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf5f2('0x18')]));require(_0xf5f2('0x1b'))[_0xf5f2('0x1c')](socket);function respondWithStatusCode(_0x1c1a5c,_0x422b55){_0x422b55=_0x422b55||0xcc;return function(_0x4d97fc){if(_0x4d97fc){return _0x1c1a5c[_0xf5f2('0x1d')](_0x422b55);}return _0x1c1a5c[_0xf5f2('0x1e')](_0x422b55)[_0xf5f2('0x1f')]();};}function respondWithResult(_0x1b6dd2,_0x23e23a){_0x23e23a=_0x23e23a||0xc8;return function(_0x3a9dbb){if(_0x3a9dbb){return _0x1b6dd2[_0xf5f2('0x1e')](_0x23e23a)[_0xf5f2('0x20')](_0x3a9dbb);}};}function respondWithFilteredResult(_0x11f702,_0x228ace){return function(_0x20fccd){if(_0x20fccd){var _0x28e097=typeof _0x228ace[_0xf5f2('0x21')]===_0xf5f2('0x22')&&typeof _0x228ace[_0xf5f2('0x23')]===_0xf5f2('0x22');var _0x1bf655=_0x20fccd['count'];var _0x34706d=_0x28e097?0x0:_0x228ace[_0xf5f2('0x21')];var _0x49dac2=_0x28e097?_0x20fccd['count']:_0x228ace[_0xf5f2('0x21')]+_0x228ace[_0xf5f2('0x23')];var _0x4ae323;if(_0x49dac2>=_0x1bf655){_0x49dac2=_0x1bf655;_0x4ae323=0xc8;}else{_0x4ae323=0xce;}_0x11f702[_0xf5f2('0x1e')](_0x4ae323);return _0x11f702[_0xf5f2('0x24')](_0xf5f2('0x25'),_0x34706d+'-'+_0x49dac2+'/'+_0x1bf655)[_0xf5f2('0x20')](_0x20fccd);}return null;};}function patchUpdates(_0x36f1cb){return function(_0x4c691a){try{jsonpatch[_0xf5f2('0x26')](_0x4c691a,_0x36f1cb,!![]);}catch(_0x4669a6){return BPromise[_0xf5f2('0x27')](_0x4669a6);}return _0x4c691a[_0xf5f2('0x28')]();};}function saveUpdates(_0x287ad5,_0x5bdf4a){return function(_0x529f07){if(_0x529f07){return _0x529f07[_0xf5f2('0x29')](_0x287ad5)[_0xf5f2('0x2a')](function(_0x13da6f){return _0x13da6f;});}return null;};}function removeEntity(_0x1a5bb3,_0xf6c58d){return function(_0x788a8d){if(_0x788a8d){return _0x788a8d[_0xf5f2('0x2b')]()[_0xf5f2('0x2a')](function(){var _0x294414=_0x788a8d['get']({'plain':!![]});var _0xaa2602=_0xf5f2('0x2c');return db[_0xf5f2('0x2d')][_0xf5f2('0x2b')]({'where':{'type':_0xaa2602,'resourceId':_0x294414['id']}})[_0xf5f2('0x2a')](function(){return _0x788a8d;});})[_0xf5f2('0x2a')](function(){_0x1a5bb3['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x22c826,_0x14c829){return function(_0x11c771){if(!_0x11c771){_0x22c826['sendStatus'](0x194);}return _0x11c771;};}function handleError(_0x5a2c7e,_0x29571b){_0x29571b=_0x29571b||0x1f4;return function(_0x50b8a2){logger[_0xf5f2('0x2e')](_0x50b8a2[_0xf5f2('0x2f')]);if(_0x50b8a2[_0xf5f2('0x30')]){delete _0x50b8a2['name'];}_0x5a2c7e['status'](_0x29571b)[_0xf5f2('0x31')](_0x50b8a2);};}exports['index']=function(_0xb744b9,_0x58a4df){var _0x45b643={},_0x31087c={},_0x7b6817={'count':0x0,'rows':[]};var _0x428770=_[_0xf5f2('0x32')](db[_0xf5f2('0x33')][_0xf5f2('0x34')],function(_0x2c0e05){return{'name':_0x2c0e05['fieldName'],'type':_0x2c0e05[_0xf5f2('0x35')][_0xf5f2('0x36')]};});_0x31087c[_0xf5f2('0x37')]=_[_0xf5f2('0x32')](_0x428770,_0xf5f2('0x30'));_0x31087c[_0xf5f2('0x38')]=_[_0xf5f2('0x39')](_0xb744b9['query']);_0x31087c[_0xf5f2('0x3a')]=_[_0xf5f2('0x3b')](_0x31087c['model'],_0x31087c[_0xf5f2('0x38')]);_0x45b643['attributes']=_[_0xf5f2('0x3b')](_0x31087c[_0xf5f2('0x37')],qs[_0xf5f2('0x3c')](_0xb744b9[_0xf5f2('0x38')]['fields']));_0x45b643['attributes']=_0x45b643[_0xf5f2('0x3d')][_0xf5f2('0x3e')]?_0x45b643[_0xf5f2('0x3d')]:_0x31087c['model'];if(!_0xb744b9[_0xf5f2('0x38')]['hasOwnProperty'](_0xf5f2('0x3f'))){_0x45b643['limit']=qs[_0xf5f2('0x23')](_0xb744b9[_0xf5f2('0x38')]['limit']);_0x45b643[_0xf5f2('0x21')]=qs[_0xf5f2('0x21')](_0xb744b9[_0xf5f2('0x38')][_0xf5f2('0x21')]);}_0x45b643['order']=qs['sort'](_0xb744b9[_0xf5f2('0x38')][_0xf5f2('0x40')]);_0x45b643[_0xf5f2('0x41')]=qs[_0xf5f2('0x3a')](_[_0xf5f2('0x42')](_0xb744b9[_0xf5f2('0x38')],_0x31087c[_0xf5f2('0x3a')]),_0x428770);if(_0xb744b9['query'][_0xf5f2('0x43')]){_0x45b643[_0xf5f2('0x41')]=_['merge'](_0x45b643[_0xf5f2('0x41')],{'$or':_[_0xf5f2('0x32')](_0x428770,function(_0x71b0e7){if(_0x71b0e7[_0xf5f2('0x35')]!==_0xf5f2('0x44')){var _0x3b6372={};_0x3b6372[_0x71b0e7[_0xf5f2('0x30')]]={'$like':'%'+_0xb744b9[_0xf5f2('0x38')]['filter']+'%'};return _0x3b6372;}})});}_0x45b643=_[_0xf5f2('0x45')]({},_0x45b643,_0xb744b9[_0xf5f2('0x46')]);var _0x17a78e={'where':_0x45b643['where']};return db['VoicePrefix']['count'](_0x17a78e)[_0xf5f2('0x2a')](function(_0x2ad13c){_0x7b6817['count']=_0x2ad13c;if(_0xb744b9[_0xf5f2('0x38')][_0xf5f2('0x47')]){_0x45b643[_0xf5f2('0x48')]=[{'all':!![]}];}return db[_0xf5f2('0x33')][_0xf5f2('0x49')](_0x45b643);})[_0xf5f2('0x2a')](function(_0x1a6ec1){_0x7b6817[_0xf5f2('0x4a')]=_0x1a6ec1;return _0x7b6817;})[_0xf5f2('0x2a')](respondWithFilteredResult(_0x58a4df,_0x45b643))[_0xf5f2('0x4b')](handleError(_0x58a4df,null));};exports[_0xf5f2('0x4c')]=function(_0x4773cd,_0x4252a3){var _0x2fb67e={'raw':![],'where':{'id':_0x4773cd[_0xf5f2('0x4d')]['id']}},_0x4faeed={};_0x4faeed['model']=_[_0xf5f2('0x39')](db[_0xf5f2('0x33')][_0xf5f2('0x34')]);_0x4faeed[_0xf5f2('0x38')]=_[_0xf5f2('0x39')](_0x4773cd[_0xf5f2('0x38')]);_0x4faeed['filters']=_[_0xf5f2('0x3b')](_0x4faeed[_0xf5f2('0x37')],_0x4faeed[_0xf5f2('0x38')]);_0x2fb67e[_0xf5f2('0x3d')]=_[_0xf5f2('0x3b')](_0x4faeed[_0xf5f2('0x37')],qs[_0xf5f2('0x3c')](_0x4773cd[_0xf5f2('0x38')]['fields']));_0x2fb67e[_0xf5f2('0x3d')]=_0x2fb67e[_0xf5f2('0x3d')][_0xf5f2('0x3e')]?_0x2fb67e['attributes']:_0x4faeed[_0xf5f2('0x37')];if(_0x4773cd[_0xf5f2('0x38')][_0xf5f2('0x47')]){_0x2fb67e['include']=[{'all':!![]}];}_0x2fb67e=_['merge']({},_0x2fb67e,_0x4773cd[_0xf5f2('0x46')]);return db[_0xf5f2('0x33')]['find'](_0x2fb67e)[_0xf5f2('0x2a')](handleEntityNotFound(_0x4252a3,null))['then'](respondWithResult(_0x4252a3,null))[_0xf5f2('0x4b')](handleError(_0x4252a3,null));};exports['destroy']=function(_0x2cbd9d,_0x5d9120){return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x2cbd9d[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x5d9120,null))['then'](removeEntity(_0x5d9120,null))[_0xf5f2('0x4b')](handleError(_0x5d9120,null));};exports[_0xf5f2('0x4f')]=function(_0x4f6b01,_0x58213b){return db[_0xf5f2('0x33')][_0xf5f2('0x4f')]()['then'](respondWithResult(_0x58213b,null))[_0xf5f2('0x4b')](handleError(_0x58213b,null));};exports[_0xf5f2('0x50')]=function(_0x29c9b6,_0x41b1c7){var _0x5d0db0;return db['sequelize'][_0xf5f2('0x51')](function(_0xa3cc67){return db['VoicePrefix'][_0xf5f2('0x50')](_0x29c9b6[_0xf5f2('0x52')],{'transaction':_0xa3cc67})[_0xf5f2('0x2a')](function(_0x14029e){_0x5d0db0=_0x14029e[_0xf5f2('0x53')]({'plain':!![]});return db[_0xf5f2('0x54')][_0xf5f2('0x4e')]({'where':{'id':_0x5d0db0['VoiceExtensionId']},'raw':!![]})['then'](function(_0x330730){return createVoicePrefixExtensions(_0x5d0db0,_0x330730,_0xa3cc67);});});})[_0xf5f2('0x2a')](function(){var _0x3c349f=_0x29c9b6[_0xf5f2('0x55')][_0xf5f2('0x53')]({'plain':!![]});if(!_0x3c349f)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3c349f[_0xf5f2('0x56')]===_0xf5f2('0x55')){var _0x18b124=_0x5d0db0;return db['UserProfileSection'][_0xf5f2('0x4e')]({'where':{'name':'VoicePrefixes','userProfileId':_0x3c349f[_0xf5f2('0x57')]},'raw':!![]})[_0xf5f2('0x2a')](function(_0x28cce5){if(_0x28cce5&&_0x28cce5[_0xf5f2('0x58')]===0x0){return db['UserProfileResource']['create']({'name':_0x18b124[_0xf5f2('0x30')],'resourceId':_0x18b124['id'],'type':_0x28cce5['name'],'sectionId':_0x28cce5['id']},{})[_0xf5f2('0x2a')](function(){return _0x5d0db0;});}else{return _0x5d0db0;}})[_0xf5f2('0x4b')](function(_0x572ec1){logger[_0xf5f2('0x2e')](_0xf5f2('0x59'),_0x572ec1);throw _0x572ec1;});}return _0x5d0db0;})[_0xf5f2('0x2a')](respondWithResult(_0x41b1c7,null))['catch'](handleError(_0x41b1c7,null));};function Extension(_0x397b99,_0xcf7a50,_0x42cc27,_0x4579f4){this['context']=_0xf5f2('0x5a');this['exten']=_0x397b99;this[_0xf5f2('0x5b')]=_0x42cc27;this[_0xf5f2('0x35')]=_0xf5f2('0x5c');this[_0xf5f2('0x5d')]=_0xf5f2('0x5e');this['priority']=_0xcf7a50;this[_0xf5f2('0x5f')]=_0x4579f4;}function createVoicePrefixExtensions(_0xacd80,_0x3461e5,_0x212639){return new BPromise(function(_0x2c5733,_0x5359b5){var _0x31e16b=new Extension(formatPrefixName(_0xacd80['prefix']),0x1,'NoOp',_0xf5f2('0x60'));_0x31e16b['VoicePrefixId']=_0xacd80['id'];return db[_0xf5f2('0x54')][_0xf5f2('0x50')](_0x31e16b,{'transaction':_0x212639})[_0xf5f2('0x2a')](function(_0x123b93){var _0x5767fc=_0x123b93[_0xf5f2('0x53')]({'plain':!![]});var _0x3a53f2=_[_0xf5f2('0x32')](addVoicePrefixExtensions(_0xacd80,_0x3461e5),function(_0x18c41f){_0x18c41f[_0xf5f2('0x61')]=_0x5767fc['id'];_0x18c41f[_0xf5f2('0x62')]=_0xacd80['id'];return _0x18c41f;});return db[_0xf5f2('0x54')]['bulkCreate'](_0x3a53f2,{'transaction':_0x212639})[_0xf5f2('0x2a')](function(_0x2d171d){if(!_0x2d171d){return _0x5359b5(_0xf5f2('0x63'));}else{return _0x2c5733(_0x2d171d);}})[_0xf5f2('0x4b')](function(_0x5a5b2b){return _0x5359b5(_0x5a5b2b);});});;});};function addVoicePrefixExtensions(_0x1de396,_0x4cce08){var _0x410866=[];var _0x1c7f06=formatPrefixName(_0x1de396['prefix']);_0x410866[_0xf5f2('0x64')](new Extension(_0x1c7f06,0x2,_0xf5f2('0x65'),_0xf5f2('0x66')+_0x1de396[_0xf5f2('0x30')]));if(_0x1de396[_0xf5f2('0x67')]){_0x410866['push'](new Extension(_0x1c7f06,0x3,_0xf5f2('0x65'),_0xf5f2('0x68')+_0x1de396[_0xf5f2('0x67')]));}else{_0x410866[_0xf5f2('0x64')](new Extension(_0x1c7f06,0x3,_0xf5f2('0x69'),_0xf5f2('0x6a')));}_0x410866['push'](new Extension(_0x1c7f06,0x4,_0xf5f2('0x6b'),_0x4cce08[_0xf5f2('0x6c')]+','+'${EXTEN:'+(0x8+_0x1de396[_0xf5f2('0x30')][_0xf5f2('0x3e')])+'}'+','+0x1));return _0x410866;}function formatPrefixName(_0x377aad){var _0x51a3c7='_';for(var _0x551cc9=0x0;_0x551cc9<_0x377aad['length'];_0x551cc9++){if(_0x377aad[_0xf5f2('0x6d')](_0x551cc9)=='-'){_0x51a3c7+=_0x377aad[_0xf5f2('0x6d')](_0x551cc9);}else{_0x51a3c7+='['+_0x377aad[_0xf5f2('0x6d')](_0x551cc9)+']';}}_0x51a3c7+='.';return _0x51a3c7;}exports[_0xf5f2('0x29')]=function(_0x55da4d,_0x4d878e,_0x278b76){var _0x3a98b4=_0x55da4d[_0xf5f2('0x52')];_0x3a98b4[_0xf5f2('0x6e')]=_0xf5f2('0x6f')+_0x3a98b4[_0xf5f2('0x30')]+'-';return db[_0xf5f2('0x70')][_0xf5f2('0x51')](function(_0x155f45){return db[_0xf5f2('0x33')][_0xf5f2('0x29')](_0x3a98b4,{'where':{'id':_0x3a98b4['id']},'transaction':_0x155f45})['then'](function(){return db['VoiceExtension']['destroy']({'where':{'VoicePrefixId':_0x3a98b4['id']},'transaction':_0x155f45})[_0xf5f2('0x2a')](function(){return db[_0xf5f2('0x54')][_0xf5f2('0x4e')]({'where':{'id':_0x3a98b4[_0xf5f2('0x61')]},'raw':!![]})[_0xf5f2('0x2a')](function(_0x5c6959){return createVoicePrefixExtensions(_0x3a98b4,_0x5c6959,_0x155f45);});});});})[_0xf5f2('0x2a')](function(){return db[_0xf5f2('0x33')][_0xf5f2('0x71')](_0x3a98b4['id']);})[_0xf5f2('0x2a')](respondWithResult(_0x4d878e,null))[_0xf5f2('0x4b')](handleError(_0x4d878e,null));};exports['addAgents']=function(_0x2986ed,_0x1409b9,_0x517c15){return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x2986ed[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x1409b9,null))['then'](function(_0x40b36e){if(_0x40b36e){return _0x40b36e[_0xf5f2('0x72')](_0x2986ed[_0xf5f2('0x52')][_0xf5f2('0x73')],_[_0xf5f2('0x74')](_0x2986ed['body'],['ids','id'])||{})[_0xf5f2('0x75')](function(_0x30f362){for(var _0x17eb69=0x0;_0x17eb69<_0x2986ed[_0xf5f2('0x52')]['ids']['length'];_0x17eb69+=0x1){socket[_0xf5f2('0x76')]('userVoicePrefix:save',{'UserId':Number(_0x2986ed['body']['ids'][_0x17eb69]),'VoicePrefixId':Number(_0x2986ed['params']['id'])});}return _0x30f362;});}})[_0xf5f2('0x2a')](respondWithResult(_0x1409b9,null))[_0xf5f2('0x4b')](handleError(_0x1409b9,null));};exports[_0xf5f2('0x77')]=function(_0x168092,_0x3de508,_0x9f941e){return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x168092[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x3de508,null))[_0xf5f2('0x2a')](function(_0x2afeac){if(_0x2afeac){return _0x2afeac[_0xf5f2('0x77')](_0x168092[_0xf5f2('0x38')][_0xf5f2('0x73')])[_0xf5f2('0x2a')](function(){if(_[_0xf5f2('0x78')](_0x168092[_0xf5f2('0x38')]['ids'])){for(var _0xe7ac8=0x0;_0xe7ac8<_0x168092[_0xf5f2('0x38')][_0xf5f2('0x73')][_0xf5f2('0x3e')];_0xe7ac8+=0x1){socket[_0xf5f2('0x76')](_0xf5f2('0x79'),{'UserId':Number(_0x168092[_0xf5f2('0x38')][_0xf5f2('0x73')][_0xe7ac8]),'VoicePrefixId':Number(_0x168092['params']['id'])});}}else{socket[_0xf5f2('0x76')]('userVoicePrefix:remove',{'UserId':Number(_0x168092['query']['ids']),'VoicePrefixId':Number(_0x168092['params']['id'])});}});}})['then'](respondWithStatusCode(_0x3de508,null))['catch'](handleError(_0x3de508,null));};exports[_0xf5f2('0x7a')]=function(_0x18ce86,_0x26a57c,_0x375bc9){var _0x145d4d={};var _0x3cf857={};var _0x5dc63f;var _0x4a0005;return db[_0xf5f2('0x33')]['findOne']({'where':{'id':_0x18ce86[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x26a57c,null))['then'](function(_0x4f3ad4){if(_0x4f3ad4){_0x5dc63f=_0x4f3ad4;_0x3cf857[_0xf5f2('0x37')]=_[_0xf5f2('0x39')](db['User'][_0xf5f2('0x34')]);_0x3cf857[_0xf5f2('0x38')]=_['keys'](_0x18ce86[_0xf5f2('0x38')]);_0x3cf857[_0xf5f2('0x3a')]=_[_0xf5f2('0x3b')](_0x3cf857['model'],_0x3cf857[_0xf5f2('0x38')]);_0x145d4d[_0xf5f2('0x3d')]=_[_0xf5f2('0x3b')](_0x3cf857[_0xf5f2('0x37')],qs[_0xf5f2('0x3c')](_0x18ce86[_0xf5f2('0x38')][_0xf5f2('0x3c')]));_0x145d4d[_0xf5f2('0x3d')]=_0x145d4d[_0xf5f2('0x3d')][_0xf5f2('0x3e')]?_0x145d4d[_0xf5f2('0x3d')]:_0x3cf857[_0xf5f2('0x37')];_0x145d4d[_0xf5f2('0x7b')]=qs[_0xf5f2('0x40')](_0x18ce86[_0xf5f2('0x38')][_0xf5f2('0x40')]);_0x145d4d[_0xf5f2('0x41')]=qs[_0xf5f2('0x3a')](_[_0xf5f2('0x42')](_0x18ce86[_0xf5f2('0x38')],_0x3cf857[_0xf5f2('0x3a')]));if(_0x18ce86['query'][_0xf5f2('0x43')]){_0x145d4d[_0xf5f2('0x41')]=_['merge'](_0x145d4d[_0xf5f2('0x41')],{'$or':_[_0xf5f2('0x32')](_0x145d4d['attributes'],function(_0xb56304){var _0x2f54eb={};_0x2f54eb[_0xb56304]={'$like':'%'+_0x18ce86[_0xf5f2('0x38')]['filter']+'%'};return _0x2f54eb;})});}_0x145d4d=_['merge']({},_0x145d4d,_0x18ce86[_0xf5f2('0x46')]);return _0x5dc63f[_0xf5f2('0x7a')](_0x145d4d);}})[_0xf5f2('0x2a')](function(_0x5ba275){if(_0x5ba275){_0x4a0005=_0x5ba275['length'];if(!_0x18ce86[_0xf5f2('0x38')][_0xf5f2('0x7c')](_0xf5f2('0x3f'))){_0x145d4d['limit']=qs['limit'](_0x18ce86['query']['limit']);_0x145d4d['offset']=qs[_0xf5f2('0x21')](_0x18ce86['query'][_0xf5f2('0x21')]);}return _0x5dc63f[_0xf5f2('0x7a')](_0x145d4d);}})[_0xf5f2('0x2a')](function(_0x43a167){if(_0x43a167){return _0x43a167?{'count':_0x4a0005,'rows':_0x43a167}:null;}})[_0xf5f2('0x2a')](respondWithResult(_0x26a57c,null))[_0xf5f2('0x4b')](handleError(_0x26a57c,null));};exports[_0xf5f2('0x7d')]=function(_0x40e921,_0x3dc051,_0x27ca4a){var _0x1bb4ac={};var _0x36c3c8={};var _0x10c982;var _0x5e69a2;return db[_0xf5f2('0x33')][_0xf5f2('0x7e')]({'where':{'id':_0x40e921['params']['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x3dc051,null))[_0xf5f2('0x2a')](function(_0x537a7d){if(_0x537a7d){_0x10c982=_0x537a7d;_0x36c3c8[_0xf5f2('0x37')]=_[_0xf5f2('0x39')](db[_0xf5f2('0x7f')]['rawAttributes']);_0x36c3c8[_0xf5f2('0x38')]=_[_0xf5f2('0x39')](_0x40e921['query']);_0x36c3c8[_0xf5f2('0x3a')]=_[_0xf5f2('0x3b')](_0x36c3c8[_0xf5f2('0x37')],_0x36c3c8['query']);_0x1bb4ac[_0xf5f2('0x3d')]=_['intersection'](_0x36c3c8[_0xf5f2('0x37')],qs['fields'](_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x3c')]));_0x1bb4ac[_0xf5f2('0x3d')]=_0x1bb4ac[_0xf5f2('0x3d')]['length']?_0x1bb4ac[_0xf5f2('0x3d')]:_0x36c3c8['model'];_0x1bb4ac['order']=qs['sort'](_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x40')]);_0x1bb4ac['where']=qs[_0xf5f2('0x3a')](_[_0xf5f2('0x42')](_0x40e921[_0xf5f2('0x38')],_0x36c3c8[_0xf5f2('0x3a')]));if(_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x43')]){_0x1bb4ac['where']=_[_0xf5f2('0x45')](_0x1bb4ac[_0xf5f2('0x41')],{'$or':_['map'](_0x1bb4ac[_0xf5f2('0x3d')],function(_0x19cbff){var _0x58042c={};_0x58042c[_0x19cbff]={'$like':'%'+_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x43')]+'%'};return _0x58042c;})});}_0x1bb4ac=_[_0xf5f2('0x45')]({},_0x1bb4ac,_0x40e921[_0xf5f2('0x46')]);return _0x10c982[_0xf5f2('0x7d')](_0x1bb4ac);}})[_0xf5f2('0x2a')](function(_0x4df05c){if(_0x4df05c){_0x5e69a2=_0x4df05c[_0xf5f2('0x3e')];if(!_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x7c')](_0xf5f2('0x3f'))){_0x1bb4ac[_0xf5f2('0x23')]=qs[_0xf5f2('0x23')](_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x23')]);_0x1bb4ac[_0xf5f2('0x21')]=qs['offset'](_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x21')]);}return _0x10c982[_0xf5f2('0x7d')](_0x1bb4ac);}})[_0xf5f2('0x2a')](function(_0x35fe1a){if(_0x35fe1a){return _0x35fe1a?{'count':_0x5e69a2,'rows':_0x35fe1a}:null;}})[_0xf5f2('0x2a')](respondWithResult(_0x3dc051,null))[_0xf5f2('0x4b')](handleError(_0x3dc051,null));};exports[_0xf5f2('0x80')]=function(_0x33cfe7,_0x40d0eb,_0x4c138c){var _0x52e419=_0x33cfe7[_0xf5f2('0x52')][_0xf5f2('0x73')];var _0x28eda5;return db[_0xf5f2('0x7f')]['findAll']({'where':{'id':_0x52e419},'attributes':['id'],'include':[{'model':db[_0xf5f2('0x81')],'as':_0xf5f2('0x82'),'attributes':['id',_0xf5f2('0x30'),_0xf5f2('0x83'),_0xf5f2('0x84'),'interface'],'raw':!![]}]})[_0xf5f2('0x2a')](function(_0x18d727){if(_0x18d727){_0x28eda5=_0x18d727;var _0x4bdb72=_[_0xf5f2('0x85')](_0x18d727,function(_0x3ff714){var _0x2563fa=_0x3ff714[_0xf5f2('0x53')]({'plain':!![]});return _0x2563fa['Agents'];});return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x33cfe7[_0xf5f2('0x4d')]['id']}})['then'](function(_0x489d4a){return db[_0xf5f2('0x70')][_0xf5f2('0x51')](function(_0x1432ef){return _0x489d4a[_0xf5f2('0x80')](_0x52e419,{'transaction':_0x1432ef})[_0xf5f2('0x2a')](function(){return BPromise[_0xf5f2('0x86')](_0x28eda5,function(_0x58711d){return db[_0xf5f2('0x87')]['upsert']({'TeamId':_0x58711d['id'],'VoicePrefixId':_0x33cfe7[_0xf5f2('0x4d')]['id']},{'transaction':_0x1432ef});});})[_0xf5f2('0x2a')](function(){return BPromise[_0xf5f2('0x86')](_0x4bdb72,function(_0xa74467){return db[_0xf5f2('0x88')][_0xf5f2('0x89')]({'where':{'UserId':_0xa74467['id'],'VoicePrefixId':_0x33cfe7['params']['id']},'transaction':_0x1432ef});});})[_0xf5f2('0x2a')](function(){_0x4bdb72[_0xf5f2('0x8a')](function(_0x457b53){socket[_0xf5f2('0x76')](_0xf5f2('0x8b'),{'UserId':_0x457b53['id'],'VoicePrefixId':_0x489d4a['id']});});});});});}})[_0xf5f2('0x2a')](respondWithStatusCode(_0x40d0eb,null))[_0xf5f2('0x4b')](handleError(_0x40d0eb,null));};exports['removeTeams']=function(_0x1ee541,_0x4a6b83,_0x5857d1){return db['Team'][_0xf5f2('0x49')]({'where':{'id':_0x1ee541[_0xf5f2('0x38')]['ids']},'attributes':['id'],'include':[{'model':db[_0xf5f2('0x81')],'as':_0xf5f2('0x82'),'attributes':['id'],'raw':!![]}]})[_0xf5f2('0x2a')](handleEntityNotFound(_0x4a6b83,null))[_0xf5f2('0x2a')](function(_0x4f2704){var _0x3075b4=_[_0xf5f2('0x32')](_0x4f2704,'id');var _0x10ac11=[];var _0x5d3ca7=[];var _0x29f7bd=squel[_0xf5f2('0x8c')]();_0x29f7bd['field'](_0xf5f2('0x8d'))[_0xf5f2('0x8e')](_0xf5f2('0x8f'),'tq')[_0xf5f2('0x90')](_0xf5f2('0x91'),'ut',_0xf5f2('0x92'))[_0xf5f2('0x41')](_0xf5f2('0x93'),_0x1ee541[_0xf5f2('0x4d')]['id']);for(var _0x4782da=0x0;_0x4782da<_0x4f2704[_0xf5f2('0x3e')];_0x4782da+=0x1){let _0x4b6146=_0x4f2704[_0x4782da];for(var _0x299c53=0x0;_0x299c53<_0x4b6146[_0xf5f2('0x82')]['length'];_0x299c53+=0x1){let _0x2275ba=_0x4b6146['Agents'][_0x299c53];var _0x3b2620=_0x29f7bd[_0xf5f2('0x94')]();_0x3b2620[_0xf5f2('0x41')](_0xf5f2('0x95'),_0x2275ba['id']);_0x5d3ca7['push'](db[_0xf5f2('0x70')]['query'](_0x3b2620[_0xf5f2('0x96')](),{'type':db['sequelize'][_0xf5f2('0x97')][_0xf5f2('0x98')]})['then'](function(_0x2bfc53){if(_0x2bfc53[_0xf5f2('0x3e')]===0x1){return _0x2275ba['id'];}else{var _0x16619b=_[_0xf5f2('0x99')](_[_0xf5f2('0x32')](_0x2bfc53,_0xf5f2('0x9a')),function(_0x54c86e){return _['includes'](_0x3075b4,_0x54c86e);});if(_0x16619b){return _0x2275ba['id'];}}}));}}return BPromise[_0xf5f2('0x9b')](_0x5d3ca7)[_0xf5f2('0x2a')](function(_0x5dc5da){_0x10ac11=_(_0x10ac11)[_0xf5f2('0x9c')](_0x5dc5da)[_0xf5f2('0x9d')]()[_0xf5f2('0x9e')]();return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x1ee541[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](function(_0x4f9e2d){return db[_0xf5f2('0x70')]['transaction'](function(_0x3ea1aa){return _0x4f9e2d['removeTeams'](_0x1ee541[_0xf5f2('0x38')]['ids'],{'transaction':_0x3ea1aa})[_0xf5f2('0x2a')](function(){if(!_['isEmpty'](_0x10ac11)){return _0x4f9e2d['removeAgents'](_0x10ac11,{'transaction':_0x3ea1aa});}})[_0xf5f2('0x2a')](function(){_0x10ac11[_0xf5f2('0x8a')](function(_0x57708f){socket[_0xf5f2('0x76')](_0xf5f2('0x79'),{'UserId':_0x57708f,'VoicePrefixId':_0x4f9e2d['id']});});});});});});})[_0xf5f2('0x2a')](respondWithStatusCode(_0x4a6b83,null))[_0xf5f2('0x4b')](handleError(_0x4a6b83,null));};
\ No newline at end of file