Built motion from commit 5b761a7b.|2.5.36
[motion2.git] / server / api / voicePrefix / voicePrefix.controller.js
index 27a25cf..18d1c5b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf3fe=['save','update','then','UserProfileResource','error','stack','name','send','index','VoicePrefix','rawAttributes','fieldName','key','model','map','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','type','VIRTUAL','merge','options','include','findAll','rows','catch','params','includeAll','find','destroy','describe','body','get','VoiceExtensionId','role','user','UserProfileSection','VoicePrefixes','userProfileId','autoAssociation','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','context','from-sip','app','system','Voice\x20Prefix\x20Extension','priority','appdata','prefix','NoOp','VoicePrefixId','VoiceExtension','bulkCreate','Extensions\x20creation\x20failed','push','CDR(prefix)=','Set','PREFIX-CALLERIDALL=','callerIdAll','No\x20callerid\x20available','goto','${EXTEN:','charAt','transaction','addAgents','ids','emit','userVoicePrefix:save','isArray','userVoicePrefix:remove','getAgents','findOne','User','fields','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','localhost','redis','./voicePrefix.socket','register','sendStatus','status','end','json','count','offset','set','apply'];(function(_0x2cbdae,_0x50e7e3){var _0x2d5705=function(_0x26dc79){while(--_0x26dc79){_0x2cbdae['push'](_0x2cbdae['shift']());}};_0x2d5705(++_0x50e7e3);}(_0xf3fe,0x1cd));var _0xef3f=function(_0x2c3e93,_0x5e4a68){_0x2c3e93=_0x2c3e93-0x0;var _0x56d022=_0xf3fe[_0x2c3e93];return _0x56d022;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xef3f('0x0'));var rimraf=require(_0xef3f('0x1'));var zipdir=require(_0xef3f('0x2'));var jsonpatch=require(_0xef3f('0x3'));var rp=require(_0xef3f('0x4'));var moment=require('moment');var BPromise=require(_0xef3f('0x5'));var Mustache=require(_0xef3f('0x6'));var util=require(_0xef3f('0x7'));var path=require(_0xef3f('0x8'));var sox=require(_0xef3f('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xef3f('0xa'));var squel=require(_0xef3f('0xb'));var crypto=require(_0xef3f('0xc'));var jsforce=require(_0xef3f('0xd'));var deskjs=require(_0xef3f('0xe'));var toCsv=require(_0xef3f('0xf'));var querystring=require(_0xef3f('0x10'));var Papa=require(_0xef3f('0x11'));var Redis=require(_0xef3f('0x12'));var authService=require('../../components/auth/service');var qs=require(_0xef3f('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xef3f('0x14'));var logger=require(_0xef3f('0x15'))(_0xef3f('0x16'));var utils=require(_0xef3f('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xef3f('0x18'));var db=require(_0xef3f('0x19'))['db'];config['redis']=_[_0xef3f('0x1a')](config['redis'],{'host':_0xef3f('0x1b'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xef3f('0x1c')]));require(_0xef3f('0x1d'))[_0xef3f('0x1e')](socket);function respondWithStatusCode(_0x3d1914,_0x1577f3){_0x1577f3=_0x1577f3||0xcc;return function(_0xc26098){if(_0xc26098){return _0x3d1914[_0xef3f('0x1f')](_0x1577f3);}return _0x3d1914[_0xef3f('0x20')](_0x1577f3)[_0xef3f('0x21')]();};}function respondWithResult(_0x2032a5,_0x20569c){_0x20569c=_0x20569c||0xc8;return function(_0x51ac83){if(_0x51ac83){return _0x2032a5[_0xef3f('0x20')](_0x20569c)[_0xef3f('0x22')](_0x51ac83);}};}function respondWithFilteredResult(_0x53e80b,_0x91e52d){return function(_0x1d6e89){if(_0x1d6e89){var _0x5e47d5=_0x1d6e89[_0xef3f('0x23')],_0x4b97cf=_0x91e52d[_0xef3f('0x24')],_0x4b1aab=_0x91e52d['offset']+_0x91e52d['limit'],_0x4909b9;if(_0x4b1aab>=_0x5e47d5){_0x4b1aab=_0x5e47d5;_0x4909b9=0xc8;}else{_0x4909b9=0xce;}_0x53e80b['status'](_0x4909b9);return _0x53e80b[_0xef3f('0x25')]('Content-Range',_0x4b97cf+'-'+_0x4b1aab+'/'+_0x5e47d5)[_0xef3f('0x22')](_0x1d6e89);}return null;};}function patchUpdates(_0x4044ad){return function(_0x327209){try{jsonpatch[_0xef3f('0x26')](_0x327209,_0x4044ad,!![]);}catch(_0x54fb65){return BPromise['reject'](_0x54fb65);}return _0x327209[_0xef3f('0x27')]();};}function saveUpdates(_0x1b83ee,_0x33c9bb){return function(_0x3f9188){if(_0x3f9188){return _0x3f9188[_0xef3f('0x28')](_0x1b83ee)['then'](function(_0x157b36){return _0x157b36;});}return null;};}function removeEntity(_0x2e4432,_0x342e44){return function(_0x14baeb){if(_0x14baeb){return _0x14baeb['destroy']()[_0xef3f('0x29')](function(){var _0x274fc9=_0x14baeb['get']({'plain':!![]});var _0x289c3c='VoicePrefixes';return db[_0xef3f('0x2a')]['destroy']({'where':{'type':_0x289c3c,'resourceId':_0x274fc9['id']}})['then'](function(){return _0x14baeb;});})['then'](function(){_0x2e4432[_0xef3f('0x20')](0xcc)[_0xef3f('0x21')]();});}};}function handleEntityNotFound(_0x3f790d,_0x4150fd){return function(_0x37c1ef){if(!_0x37c1ef){_0x3f790d[_0xef3f('0x1f')](0x194);}return _0x37c1ef;};}function handleError(_0x5e46ee,_0x4e4e57){_0x4e4e57=_0x4e4e57||0x1f4;return function(_0x4b93af){logger[_0xef3f('0x2b')](_0x4b93af[_0xef3f('0x2c')]);if(_0x4b93af[_0xef3f('0x2d')]){delete _0x4b93af['name'];}_0x5e46ee[_0xef3f('0x20')](_0x4e4e57)[_0xef3f('0x2e')](_0x4b93af);};}exports[_0xef3f('0x2f')]=function(_0x4fd250,_0x545151){var _0x1fe5ce={},_0x19704f={},_0x2bb213={'count':0x0,'rows':[]};var _0x1ecb9f=_['map'](db[_0xef3f('0x30')][_0xef3f('0x31')],function(_0xd995bc){return{'name':_0xd995bc[_0xef3f('0x32')],'type':_0xd995bc['type'][_0xef3f('0x33')]};});_0x19704f[_0xef3f('0x34')]=_[_0xef3f('0x35')](_0x1ecb9f,'name');_0x19704f[_0xef3f('0x36')]=_[_0xef3f('0x37')](_0x4fd250[_0xef3f('0x36')]);_0x19704f[_0xef3f('0x38')]=_[_0xef3f('0x39')](_0x19704f[_0xef3f('0x34')],_0x19704f['query']);_0x1fe5ce[_0xef3f('0x3a')]=_['intersection'](_0x19704f[_0xef3f('0x34')],qs['fields'](_0x4fd250[_0xef3f('0x36')]['fields']));_0x1fe5ce['attributes']=_0x1fe5ce['attributes'][_0xef3f('0x3b')]?_0x1fe5ce[_0xef3f('0x3a')]:_0x19704f[_0xef3f('0x34')];if(!_0x4fd250[_0xef3f('0x36')][_0xef3f('0x3c')](_0xef3f('0x3d'))){_0x1fe5ce[_0xef3f('0x3e')]=qs[_0xef3f('0x3e')](_0x4fd250['query'][_0xef3f('0x3e')]);_0x1fe5ce[_0xef3f('0x24')]=qs[_0xef3f('0x24')](_0x4fd250[_0xef3f('0x36')][_0xef3f('0x24')]);}_0x1fe5ce[_0xef3f('0x3f')]=qs[_0xef3f('0x40')](_0x4fd250[_0xef3f('0x36')][_0xef3f('0x40')]);_0x1fe5ce[_0xef3f('0x41')]=qs[_0xef3f('0x38')](_[_0xef3f('0x42')](_0x4fd250[_0xef3f('0x36')],_0x19704f['filters']),_0x1ecb9f);if(_0x4fd250[_0xef3f('0x36')][_0xef3f('0x43')]){_0x1fe5ce['where']=_['merge'](_0x1fe5ce[_0xef3f('0x41')],{'$or':_['map'](_0x1ecb9f,function(_0x17c5ab){if(_0x17c5ab[_0xef3f('0x44')]!==_0xef3f('0x45')){var _0x10d51a={};_0x10d51a[_0x17c5ab[_0xef3f('0x2d')]]={'$like':'%'+_0x4fd250['query'][_0xef3f('0x43')]+'%'};return _0x10d51a;}})});}_0x1fe5ce=_[_0xef3f('0x46')]({},_0x1fe5ce,_0x4fd250[_0xef3f('0x47')]);var _0x286800={'where':_0x1fe5ce[_0xef3f('0x41')]};return db[_0xef3f('0x30')]['count'](_0x286800)[_0xef3f('0x29')](function(_0x4dfd20){_0x2bb213[_0xef3f('0x23')]=_0x4dfd20;if(_0x4fd250['query']['includeAll']){_0x1fe5ce[_0xef3f('0x48')]=[{'all':!![]}];}return db[_0xef3f('0x30')][_0xef3f('0x49')](_0x1fe5ce);})['then'](function(_0x2540e3){_0x2bb213[_0xef3f('0x4a')]=_0x2540e3;return _0x2bb213;})[_0xef3f('0x29')](respondWithFilteredResult(_0x545151,_0x1fe5ce))[_0xef3f('0x4b')](handleError(_0x545151,null));};exports['show']=function(_0x45114d,_0xc57ba6){var _0x1550d4={'raw':![],'where':{'id':_0x45114d[_0xef3f('0x4c')]['id']}},_0x539b40={};_0x539b40[_0xef3f('0x34')]=_[_0xef3f('0x37')](db[_0xef3f('0x30')]['rawAttributes']);_0x539b40[_0xef3f('0x36')]=_[_0xef3f('0x37')](_0x45114d[_0xef3f('0x36')]);_0x539b40['filters']=_[_0xef3f('0x39')](_0x539b40[_0xef3f('0x34')],_0x539b40['query']);_0x1550d4[_0xef3f('0x3a')]=_[_0xef3f('0x39')](_0x539b40[_0xef3f('0x34')],qs['fields'](_0x45114d[_0xef3f('0x36')]['fields']));_0x1550d4[_0xef3f('0x3a')]=_0x1550d4[_0xef3f('0x3a')]['length']?_0x1550d4[_0xef3f('0x3a')]:_0x539b40['model'];if(_0x45114d[_0xef3f('0x36')][_0xef3f('0x4d')]){_0x1550d4[_0xef3f('0x48')]=[{'all':!![]}];}_0x1550d4=_[_0xef3f('0x46')]({},_0x1550d4,_0x45114d['options']);return db['VoicePrefix'][_0xef3f('0x4e')](_0x1550d4)[_0xef3f('0x29')](handleEntityNotFound(_0xc57ba6,null))['then'](respondWithResult(_0xc57ba6,null))[_0xef3f('0x4b')](handleError(_0xc57ba6,null));};exports[_0xef3f('0x4f')]=function(_0x219bcb,_0x449864){return db[_0xef3f('0x30')][_0xef3f('0x4e')]({'where':{'id':_0x219bcb[_0xef3f('0x4c')]['id']}})[_0xef3f('0x29')](handleEntityNotFound(_0x449864,null))[_0xef3f('0x29')](removeEntity(_0x449864,null))[_0xef3f('0x4b')](handleError(_0x449864,null));};exports[_0xef3f('0x50')]=function(_0x567308,_0x56bf3c){return db[_0xef3f('0x30')]['describe']()[_0xef3f('0x29')](respondWithResult(_0x56bf3c,null))['catch'](handleError(_0x56bf3c,null));};exports['create']=function(_0x59194f,_0x36a707){var _0x4462e4;return db['sequelize']['transaction'](function(_0x2b5a01){return db['VoicePrefix']['create'](_0x59194f[_0xef3f('0x51')],{'transaction':_0x2b5a01})['then'](function(_0x1f3918){_0x4462e4=_0x1f3918[_0xef3f('0x52')]({'plain':!![]});return db['VoiceExtension'][_0xef3f('0x4e')]({'where':{'id':_0x4462e4[_0xef3f('0x53')]},'raw':!![]})[_0xef3f('0x29')](function(_0x46d11f){return createVoicePrefixExtensions(_0x4462e4,_0x46d11f,_0x2b5a01);});});})['then'](function(){var _0x148e45=_0x59194f['user']['get']({'plain':!![]});if(!_0x148e45)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x148e45[_0xef3f('0x54')]===_0xef3f('0x55')){var _0x1cc70d=_0x4462e4;return db[_0xef3f('0x56')][_0xef3f('0x4e')]({'where':{'name':_0xef3f('0x57'),'userProfileId':_0x148e45[_0xef3f('0x58')]},'raw':!![]})['then'](function(_0x43bb05){if(_0x43bb05&&_0x43bb05[_0xef3f('0x59')]===0x0){return db['UserProfileResource'][_0xef3f('0x5a')]({'name':_0x1cc70d[_0xef3f('0x2d')],'resourceId':_0x1cc70d['id'],'type':_0x43bb05[_0xef3f('0x2d')],'sectionId':_0x43bb05['id']},{})[_0xef3f('0x29')](function(){return _0x4462e4;});}else{return _0x4462e4;}})[_0xef3f('0x4b')](function(_0x2ba77f){logger[_0xef3f('0x2b')](_0xef3f('0x5b'),_0x2ba77f);throw _0x2ba77f;});}return _0x4462e4;})['then'](respondWithResult(_0x36a707,null))[_0xef3f('0x4b')](handleError(_0x36a707,null));};function Extension(_0x1ea4c7,_0x168853,_0x4e2736,_0x1162eb){this[_0xef3f('0x5c')]=_0xef3f('0x5d');this['exten']=_0x1ea4c7;this[_0xef3f('0x5e')]=_0x4e2736;this[_0xef3f('0x44')]=_0xef3f('0x5f');this['description']=_0xef3f('0x60');this[_0xef3f('0x61')]=_0x168853;this[_0xef3f('0x62')]=_0x1162eb;}function createVoicePrefixExtensions(_0x184d55,_0x2b3583,_0x24f17a){return new BPromise(function(_0x47bbd0,_0x13dd2b){var _0x14cc7c=new Extension(formatPrefixName(_0x184d55[_0xef3f('0x63')]),0x1,_0xef3f('0x64'),'Voice\x20Prefix');_0x14cc7c[_0xef3f('0x65')]=_0x184d55['id'];return db[_0xef3f('0x66')][_0xef3f('0x5a')](_0x14cc7c,{'transaction':_0x24f17a})[_0xef3f('0x29')](function(_0x3bffbf){var _0x5367cf=_0x3bffbf['get']({'plain':!![]});var _0x3e7a7a=_['map'](addVoicePrefixExtensions(_0x184d55,_0x2b3583),function(_0x12c7c2){_0x12c7c2[_0xef3f('0x53')]=_0x5367cf['id'];_0x12c7c2[_0xef3f('0x65')]=_0x184d55['id'];return _0x12c7c2;});return db[_0xef3f('0x66')][_0xef3f('0x67')](_0x3e7a7a,{'transaction':_0x24f17a})[_0xef3f('0x29')](function(_0x2c94f8){if(!_0x2c94f8){return _0x13dd2b(_0xef3f('0x68'));}else{return _0x47bbd0(_0x2c94f8);}})[_0xef3f('0x4b')](function(_0x4167bf){return _0x13dd2b(_0x4167bf);});});;});};function addVoicePrefixExtensions(_0x59e0b6,_0x4e8b76){var _0x4eab58=[];var _0x2a4908=formatPrefixName(_0x59e0b6[_0xef3f('0x63')]);_0x4eab58[_0xef3f('0x69')](new Extension(_0x2a4908,0x2,'Set',_0xef3f('0x6a')+_0x59e0b6['name']));if(_0x59e0b6['callerIdAll']){_0x4eab58['push'](new Extension(_0x2a4908,0x3,_0xef3f('0x6b'),_0xef3f('0x6c')+_0x59e0b6[_0xef3f('0x6d')]));}else{_0x4eab58[_0xef3f('0x69')](new Extension(_0x2a4908,0x3,_0xef3f('0x64'),_0xef3f('0x6e')));}_0x4eab58[_0xef3f('0x69')](new Extension(_0x2a4908,0x4,_0xef3f('0x6f'),_0x4e8b76['context']+','+_0xef3f('0x70')+(0x8+_0x59e0b6[_0xef3f('0x2d')]['length'])+'}'+','+0x1));return _0x4eab58;}function formatPrefixName(_0x53d6e0){var _0x2cf3c4='_';for(var _0x2c3afa=0x0;_0x2c3afa<_0x53d6e0[_0xef3f('0x3b')];_0x2c3afa++){if(_0x53d6e0[_0xef3f('0x71')](_0x2c3afa)=='-'){_0x2cf3c4+=_0x53d6e0['charAt'](_0x2c3afa);}else{_0x2cf3c4+='['+_0x53d6e0[_0xef3f('0x71')](_0x2c3afa)+']';}}_0x2cf3c4+='.';return _0x2cf3c4;}exports[_0xef3f('0x28')]=function(_0x4b0700,_0x4946c0,_0x15174c){var _0x3a6f97=_0x4b0700[_0xef3f('0x51')];_0x3a6f97['prefix']='system-'+_0x3a6f97['name']+'-';return db['sequelize'][_0xef3f('0x72')](function(_0x59d37d){return db[_0xef3f('0x30')][_0xef3f('0x28')](_0x3a6f97,{'where':{'id':_0x3a6f97['id']},'transaction':_0x59d37d})[_0xef3f('0x29')](function(){return db[_0xef3f('0x66')][_0xef3f('0x4f')]({'where':{'VoicePrefixId':_0x3a6f97['id']},'transaction':_0x59d37d})[_0xef3f('0x29')](function(){return db[_0xef3f('0x66')][_0xef3f('0x4e')]({'where':{'id':_0x3a6f97[_0xef3f('0x53')]},'raw':!![]})[_0xef3f('0x29')](function(_0x37391b){return createVoicePrefixExtensions(_0x3a6f97,_0x37391b,_0x59d37d);});});});})[_0xef3f('0x29')](function(){return db[_0xef3f('0x30')]['findById'](_0x3a6f97['id']);})[_0xef3f('0x29')](respondWithResult(_0x4946c0,null))[_0xef3f('0x4b')](handleError(_0x4946c0,null));};exports[_0xef3f('0x73')]=function(_0x2b1a2e,_0x3cacd3,_0x44b5e0){return db[_0xef3f('0x30')][_0xef3f('0x4e')]({'where':{'id':_0x2b1a2e['params']['id']}})[_0xef3f('0x29')](handleEntityNotFound(_0x3cacd3,null))['then'](function(_0x133b60){if(_0x133b60){return _0x133b60[_0xef3f('0x73')](_0x2b1a2e[_0xef3f('0x51')][_0xef3f('0x74')],_['omit'](_0x2b1a2e[_0xef3f('0x51')],['ids','id'])||{})['spread'](function(_0x4a8579){for(var _0x2f8f57=0x0;_0x2f8f57<_0x2b1a2e[_0xef3f('0x51')][_0xef3f('0x74')][_0xef3f('0x3b')];_0x2f8f57+=0x1){socket[_0xef3f('0x75')](_0xef3f('0x76'),{'UserId':_0x2b1a2e['body'][_0xef3f('0x74')][_0x2f8f57],'VoicePrefixId':_0x2b1a2e[_0xef3f('0x4c')]['id']});}return _0x4a8579;});}})['then'](respondWithResult(_0x3cacd3,null))['catch'](handleError(_0x3cacd3,null));};exports['removeAgents']=function(_0x4d262f,_0x2396d5,_0x3b7672){return db[_0xef3f('0x30')]['find']({'where':{'id':_0x4d262f[_0xef3f('0x4c')]['id']}})[_0xef3f('0x29')](handleEntityNotFound(_0x2396d5,null))[_0xef3f('0x29')](function(_0x2dec6e){if(_0x2dec6e){return _0x2dec6e['removeAgents'](_0x4d262f[_0xef3f('0x36')][_0xef3f('0x74')])[_0xef3f('0x29')](function(){if(_[_0xef3f('0x77')](_0x4d262f[_0xef3f('0x36')][_0xef3f('0x74')])){for(var _0x409954=0x0;_0x409954<_0x4d262f['query'][_0xef3f('0x74')][_0xef3f('0x3b')];_0x409954+=0x1){socket[_0xef3f('0x75')](_0xef3f('0x78'),{'UserId':Number(_0x4d262f[_0xef3f('0x36')][_0xef3f('0x74')][_0x409954]),'VoicePrefixId':Number(_0x4d262f['params']['id'])});}}else{socket[_0xef3f('0x75')](_0xef3f('0x78'),{'UserId':Number(_0x4d262f['query'][_0xef3f('0x74')]),'VoicePrefixId':Number(_0x4d262f[_0xef3f('0x4c')]['id'])});}});}})[_0xef3f('0x29')](respondWithStatusCode(_0x2396d5,null))[_0xef3f('0x4b')](handleError(_0x2396d5,null));};exports[_0xef3f('0x79')]=function(_0x3299cd,_0x3ef404,_0xb13ce4){var _0x213d67={};var _0x319fd2={};var _0x1a212f;var _0xc19fb3;return db[_0xef3f('0x30')][_0xef3f('0x7a')]({'where':{'id':_0x3299cd[_0xef3f('0x4c')]['id']}})[_0xef3f('0x29')](handleEntityNotFound(_0x3ef404,null))[_0xef3f('0x29')](function(_0x448027){if(_0x448027){_0x1a212f=_0x448027;_0x319fd2[_0xef3f('0x34')]=_[_0xef3f('0x37')](db[_0xef3f('0x7b')][_0xef3f('0x31')]);_0x319fd2[_0xef3f('0x36')]=_['keys'](_0x3299cd[_0xef3f('0x36')]);_0x319fd2[_0xef3f('0x38')]=_[_0xef3f('0x39')](_0x319fd2[_0xef3f('0x34')],_0x319fd2[_0xef3f('0x36')]);_0x213d67[_0xef3f('0x3a')]=_[_0xef3f('0x39')](_0x319fd2['model'],qs[_0xef3f('0x7c')](_0x3299cd[_0xef3f('0x36')]['fields']));_0x213d67[_0xef3f('0x3a')]=_0x213d67[_0xef3f('0x3a')][_0xef3f('0x3b')]?_0x213d67[_0xef3f('0x3a')]:_0x319fd2[_0xef3f('0x34')];_0x213d67['order']=qs['sort'](_0x3299cd[_0xef3f('0x36')][_0xef3f('0x40')]);_0x213d67[_0xef3f('0x41')]=qs[_0xef3f('0x38')](_[_0xef3f('0x42')](_0x3299cd['query'],_0x319fd2[_0xef3f('0x38')]));if(_0x3299cd['query'][_0xef3f('0x43')]){_0x213d67[_0xef3f('0x41')]=_[_0xef3f('0x46')](_0x213d67[_0xef3f('0x41')],{'$or':_[_0xef3f('0x35')](_0x213d67[_0xef3f('0x3a')],function(_0x1dbe7b){var _0xc21d83={};_0xc21d83[_0x1dbe7b]={'$like':'%'+_0x3299cd[_0xef3f('0x36')][_0xef3f('0x43')]+'%'};return _0xc21d83;})});}_0x213d67=_[_0xef3f('0x46')]({},_0x213d67,_0x3299cd[_0xef3f('0x47')]);return _0x1a212f[_0xef3f('0x79')](_0x213d67);}})[_0xef3f('0x29')](function(_0xd5e3d6){if(_0xd5e3d6){_0xc19fb3=_0xd5e3d6[_0xef3f('0x3b')];if(!_0x3299cd[_0xef3f('0x36')][_0xef3f('0x3c')]('nolimit')){_0x213d67[_0xef3f('0x3e')]=qs[_0xef3f('0x3e')](_0x3299cd['query']['limit']);_0x213d67['offset']=qs[_0xef3f('0x24')](_0x3299cd[_0xef3f('0x36')]['offset']);}return _0x1a212f[_0xef3f('0x79')](_0x213d67);}})[_0xef3f('0x29')](function(_0x393447){if(_0x393447){return _0x393447?{'count':_0xc19fb3,'rows':_0x393447}:null;}})['then'](respondWithResult(_0x3ef404,null))[_0xef3f('0x4b')](handleError(_0x3ef404,null));};
\ No newline at end of file
+var _0x3423=['VoiceExtension','role','user','UserProfileSection','VoicePrefixes','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','from-sip','exten','app','system','description','Voice\x20Prefix\x20Extension','priority','appdata','prefix','NoOp','Voice\x20Prefix','VoicePrefixId','VoiceExtensionId','bulkCreate','Extensions\x20creation\x20failed','push','callerIdAll','Set','PREFIX-CALLERIDALL=','No\x20callerid\x20available','context','charAt','transaction','findById','addAgents','ids','omit','spread','emit','userVoicePrefix:save','removeAgents','isArray','userVoicePrefix:remove','findOne','order','getAgents','nolimit','getTeams','Team','addTeams','online','Agents','each','TeamVoicePrefix','upsert','findOrCreate','forEach','removeTeams','User','select','field','tq.TeamId','from','team_has_voice_prefixes','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','toString','QueryTypes','SELECT','TeamId','includes','all','union','compact','value','isEmpty','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','api','../../config/utils','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./voicePrefix.socket','register','sendStatus','status','json','offset','undefined','limit','count','Content-Range','apply','reject','save','update','destroy','UserProfileResource','then','end','error','stack','name','index','VoicePrefix','rawAttributes','fieldName','type','key','model','map','query','keys','attributes','intersection','fields','length','hasOwnProperty','sort','where','filters','pick','filter','merge','options','include','findAll','rows','catch','show','includeAll','find','params','describe','create','sequelize','body','get'];(function(_0x4a6633,_0x32dfae){var _0x3443d7=function(_0x31ac56){while(--_0x31ac56){_0x4a6633['push'](_0x4a6633['shift']());}};_0x3443d7(++_0x32dfae);}(_0x3423,0x188));var _0x3342=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x3423[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x3342('0x0'));var jsonpatch=require(_0x3342('0x1'));var rp=require(_0x3342('0x2'));var moment=require(_0x3342('0x3'));var BPromise=require(_0x3342('0x4'));var Mustache=require(_0x3342('0x5'));var util=require(_0x3342('0x6'));var path=require(_0x3342('0x7'));var sox=require(_0x3342('0x8'));var csv=require(_0x3342('0x9'));var ejs=require(_0x3342('0xa'));var fs=require('fs');var fs_extra=require(_0x3342('0xb'));var _=require(_0x3342('0xc'));var squel=require(_0x3342('0xd'));var crypto=require(_0x3342('0xe'));var jsforce=require(_0x3342('0xf'));var deskjs=require(_0x3342('0x10'));var toCsv=require(_0x3342('0x9'));var querystring=require(_0x3342('0x11'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x3342('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x3342('0x13'));var utils=require(_0x3342('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x3342('0x15'));var db=require('../../mysqldb')['db'];config[_0x3342('0x16')]=_[_0x3342('0x17')](config['redis'],{'host':_0x3342('0x18'),'port':0x18eb});var socket=require(_0x3342('0x19'))(new Redis(config[_0x3342('0x16')]));require(_0x3342('0x1a'))[_0x3342('0x1b')](socket);function respondWithStatusCode(_0x104077,_0x34a306){_0x34a306=_0x34a306||0xcc;return function(_0x59be1d){if(_0x59be1d){return _0x104077[_0x3342('0x1c')](_0x34a306);}return _0x104077[_0x3342('0x1d')](_0x34a306)['end']();};}function respondWithResult(_0x40d609,_0x2c9df0){_0x2c9df0=_0x2c9df0||0xc8;return function(_0x51ef91){if(_0x51ef91){return _0x40d609['status'](_0x2c9df0)[_0x3342('0x1e')](_0x51ef91);}};}function respondWithFilteredResult(_0x143cf1,_0x6949fc){return function(_0x2075cb){if(_0x2075cb){var _0x12947a=typeof _0x6949fc[_0x3342('0x1f')]===_0x3342('0x20')&&typeof _0x6949fc[_0x3342('0x21')]===_0x3342('0x20');var _0x4f4c2a=_0x2075cb[_0x3342('0x22')];var _0xda235a=_0x12947a?0x0:_0x6949fc[_0x3342('0x1f')];var _0x5e05f5=_0x12947a?_0x2075cb[_0x3342('0x22')]:_0x6949fc[_0x3342('0x1f')]+_0x6949fc['limit'];var _0xe774b7;if(_0x5e05f5>=_0x4f4c2a){_0x5e05f5=_0x4f4c2a;_0xe774b7=0xc8;}else{_0xe774b7=0xce;}_0x143cf1[_0x3342('0x1d')](_0xe774b7);return _0x143cf1['set'](_0x3342('0x23'),_0xda235a+'-'+_0x5e05f5+'/'+_0x4f4c2a)['json'](_0x2075cb);}return null;};}function patchUpdates(_0x3f271c){return function(_0x38994e){try{jsonpatch[_0x3342('0x24')](_0x38994e,_0x3f271c,!![]);}catch(_0x2dbad1){return BPromise[_0x3342('0x25')](_0x2dbad1);}return _0x38994e[_0x3342('0x26')]();};}function saveUpdates(_0x26eb87,_0x2d8622){return function(_0x5d4f14){if(_0x5d4f14){return _0x5d4f14[_0x3342('0x27')](_0x26eb87)['then'](function(_0x51cf45){return _0x51cf45;});}return null;};}function removeEntity(_0x986ab0,_0x52ba65){return function(_0x5d2f0b){if(_0x5d2f0b){return _0x5d2f0b[_0x3342('0x28')]()['then'](function(){var _0x37df78=_0x5d2f0b['get']({'plain':!![]});var _0x524286='VoicePrefixes';return db[_0x3342('0x29')][_0x3342('0x28')]({'where':{'type':_0x524286,'resourceId':_0x37df78['id']}})[_0x3342('0x2a')](function(){return _0x5d2f0b;});})['then'](function(){_0x986ab0[_0x3342('0x1d')](0xcc)[_0x3342('0x2b')]();});}};}function handleEntityNotFound(_0x1cc542,_0x272a52){return function(_0x4fbfb7){if(!_0x4fbfb7){_0x1cc542[_0x3342('0x1c')](0x194);}return _0x4fbfb7;};}function handleError(_0x3d6810,_0x387ba2){_0x387ba2=_0x387ba2||0x1f4;return function(_0x301114){logger[_0x3342('0x2c')](_0x301114[_0x3342('0x2d')]);if(_0x301114[_0x3342('0x2e')]){delete _0x301114['name'];}_0x3d6810[_0x3342('0x1d')](_0x387ba2)['send'](_0x301114);};}exports[_0x3342('0x2f')]=function(_0x407f8c,_0x508f87){var _0x250396={},_0x1cc42d={},_0x347d52={'count':0x0,'rows':[]};var _0x4e7410=_['map'](db[_0x3342('0x30')][_0x3342('0x31')],function(_0x311cfe){return{'name':_0x311cfe[_0x3342('0x32')],'type':_0x311cfe[_0x3342('0x33')][_0x3342('0x34')]};});_0x1cc42d[_0x3342('0x35')]=_[_0x3342('0x36')](_0x4e7410,_0x3342('0x2e'));_0x1cc42d[_0x3342('0x37')]=_[_0x3342('0x38')](_0x407f8c[_0x3342('0x37')]);_0x1cc42d['filters']=_['intersection'](_0x1cc42d[_0x3342('0x35')],_0x1cc42d['query']);_0x250396[_0x3342('0x39')]=_[_0x3342('0x3a')](_0x1cc42d[_0x3342('0x35')],qs[_0x3342('0x3b')](_0x407f8c[_0x3342('0x37')][_0x3342('0x3b')]));_0x250396[_0x3342('0x39')]=_0x250396['attributes'][_0x3342('0x3c')]?_0x250396[_0x3342('0x39')]:_0x1cc42d[_0x3342('0x35')];if(!_0x407f8c[_0x3342('0x37')][_0x3342('0x3d')]('nolimit')){_0x250396[_0x3342('0x21')]=qs['limit'](_0x407f8c[_0x3342('0x37')][_0x3342('0x21')]);_0x250396[_0x3342('0x1f')]=qs[_0x3342('0x1f')](_0x407f8c['query'][_0x3342('0x1f')]);}_0x250396['order']=qs[_0x3342('0x3e')](_0x407f8c[_0x3342('0x37')][_0x3342('0x3e')]);_0x250396[_0x3342('0x3f')]=qs[_0x3342('0x40')](_[_0x3342('0x41')](_0x407f8c[_0x3342('0x37')],_0x1cc42d['filters']),_0x4e7410);if(_0x407f8c[_0x3342('0x37')][_0x3342('0x42')]){_0x250396['where']=_[_0x3342('0x43')](_0x250396[_0x3342('0x3f')],{'$or':_['map'](_0x4e7410,function(_0x45b956){if(_0x45b956[_0x3342('0x33')]!=='VIRTUAL'){var _0x4985db={};_0x4985db[_0x45b956['name']]={'$like':'%'+_0x407f8c[_0x3342('0x37')][_0x3342('0x42')]+'%'};return _0x4985db;}})});}_0x250396=_['merge']({},_0x250396,_0x407f8c[_0x3342('0x44')]);var _0x2a1f7e={'where':_0x250396[_0x3342('0x3f')]};return db[_0x3342('0x30')][_0x3342('0x22')](_0x2a1f7e)[_0x3342('0x2a')](function(_0x34de7b){_0x347d52[_0x3342('0x22')]=_0x34de7b;if(_0x407f8c['query']['includeAll']){_0x250396[_0x3342('0x45')]=[{'all':!![]}];}return db[_0x3342('0x30')][_0x3342('0x46')](_0x250396);})[_0x3342('0x2a')](function(_0x717946){_0x347d52[_0x3342('0x47')]=_0x717946;return _0x347d52;})['then'](respondWithFilteredResult(_0x508f87,_0x250396))[_0x3342('0x48')](handleError(_0x508f87,null));};exports[_0x3342('0x49')]=function(_0x283ce9,_0x309423){var _0x64e352={'raw':![],'where':{'id':_0x283ce9['params']['id']}},_0x365d6f={};_0x365d6f[_0x3342('0x35')]=_['keys'](db[_0x3342('0x30')][_0x3342('0x31')]);_0x365d6f[_0x3342('0x37')]=_[_0x3342('0x38')](_0x283ce9['query']);_0x365d6f[_0x3342('0x40')]=_[_0x3342('0x3a')](_0x365d6f['model'],_0x365d6f[_0x3342('0x37')]);_0x64e352[_0x3342('0x39')]=_[_0x3342('0x3a')](_0x365d6f[_0x3342('0x35')],qs['fields'](_0x283ce9[_0x3342('0x37')][_0x3342('0x3b')]));_0x64e352['attributes']=_0x64e352[_0x3342('0x39')]['length']?_0x64e352['attributes']:_0x365d6f[_0x3342('0x35')];if(_0x283ce9[_0x3342('0x37')][_0x3342('0x4a')]){_0x64e352[_0x3342('0x45')]=[{'all':!![]}];}_0x64e352=_[_0x3342('0x43')]({},_0x64e352,_0x283ce9[_0x3342('0x44')]);return db[_0x3342('0x30')]['find'](_0x64e352)['then'](handleEntityNotFound(_0x309423,null))[_0x3342('0x2a')](respondWithResult(_0x309423,null))['catch'](handleError(_0x309423,null));};exports[_0x3342('0x28')]=function(_0x5e1202,_0x4c9214){return db['VoicePrefix'][_0x3342('0x4b')]({'where':{'id':_0x5e1202[_0x3342('0x4c')]['id']}})[_0x3342('0x2a')](handleEntityNotFound(_0x4c9214,null))[_0x3342('0x2a')](removeEntity(_0x4c9214,null))['catch'](handleError(_0x4c9214,null));};exports[_0x3342('0x4d')]=function(_0x3a6597,_0x4ce271){return db[_0x3342('0x30')][_0x3342('0x4d')]()[_0x3342('0x2a')](respondWithResult(_0x4ce271,null))['catch'](handleError(_0x4ce271,null));};exports[_0x3342('0x4e')]=function(_0x1497d9,_0x45eb2c){var _0x3be76c;return db[_0x3342('0x4f')]['transaction'](function(_0x2699d2){return db[_0x3342('0x30')][_0x3342('0x4e')](_0x1497d9[_0x3342('0x50')],{'transaction':_0x2699d2})[_0x3342('0x2a')](function(_0x386a5d){_0x3be76c=_0x386a5d[_0x3342('0x51')]({'plain':!![]});return db[_0x3342('0x52')][_0x3342('0x4b')]({'where':{'id':_0x3be76c['VoiceExtensionId']},'raw':!![]})[_0x3342('0x2a')](function(_0x4eebaa){return createVoicePrefixExtensions(_0x3be76c,_0x4eebaa,_0x2699d2);});});})[_0x3342('0x2a')](function(){var _0x524fb6=_0x1497d9['user']['get']({'plain':!![]});if(!_0x524fb6)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x524fb6[_0x3342('0x53')]===_0x3342('0x54')){var _0x3cd098=_0x3be76c;return db[_0x3342('0x55')][_0x3342('0x4b')]({'where':{'name':_0x3342('0x56'),'userProfileId':_0x524fb6[_0x3342('0x57')]},'raw':!![]})[_0x3342('0x2a')](function(_0x2938e0){if(_0x2938e0&&_0x2938e0[_0x3342('0x58')]===0x0){return db[_0x3342('0x29')]['create']({'name':_0x3cd098['name'],'resourceId':_0x3cd098['id'],'type':_0x2938e0[_0x3342('0x2e')],'sectionId':_0x2938e0['id']},{})['then'](function(){return _0x3be76c;});}else{return _0x3be76c;}})[_0x3342('0x48')](function(_0x59964b){logger['error'](_0x3342('0x59'),_0x59964b);throw _0x59964b;});}return _0x3be76c;})[_0x3342('0x2a')](respondWithResult(_0x45eb2c,null))[_0x3342('0x48')](handleError(_0x45eb2c,null));};function Extension(_0x5d5e0f,_0x58d37a,_0x54b41d,_0x3cc92a){this['context']=_0x3342('0x5a');this[_0x3342('0x5b')]=_0x5d5e0f;this[_0x3342('0x5c')]=_0x54b41d;this['type']=_0x3342('0x5d');this[_0x3342('0x5e')]=_0x3342('0x5f');this[_0x3342('0x60')]=_0x58d37a;this[_0x3342('0x61')]=_0x3cc92a;}function createVoicePrefixExtensions(_0x19e27b,_0xa4452,_0x57942a){return new BPromise(function(_0x4bc9a9,_0x30e299){var _0x4ec1c4=new Extension(formatPrefixName(_0x19e27b[_0x3342('0x62')]),0x1,_0x3342('0x63'),_0x3342('0x64'));_0x4ec1c4[_0x3342('0x65')]=_0x19e27b['id'];return db[_0x3342('0x52')]['create'](_0x4ec1c4,{'transaction':_0x57942a})[_0x3342('0x2a')](function(_0x3f2fcb){var _0x4c1c6a=_0x3f2fcb[_0x3342('0x51')]({'plain':!![]});var _0x14cc64=_[_0x3342('0x36')](addVoicePrefixExtensions(_0x19e27b,_0xa4452),function(_0x2858a6){_0x2858a6[_0x3342('0x66')]=_0x4c1c6a['id'];_0x2858a6[_0x3342('0x65')]=_0x19e27b['id'];return _0x2858a6;});return db[_0x3342('0x52')][_0x3342('0x67')](_0x14cc64,{'transaction':_0x57942a})[_0x3342('0x2a')](function(_0x36eec8){if(!_0x36eec8){return _0x30e299(_0x3342('0x68'));}else{return _0x4bc9a9(_0x36eec8);}})[_0x3342('0x48')](function(_0x3b01a3){return _0x30e299(_0x3b01a3);});});;});};function addVoicePrefixExtensions(_0x58cbdd,_0x5c9399){var _0x146ffc=[];var _0x4672b5=formatPrefixName(_0x58cbdd[_0x3342('0x62')]);_0x146ffc[_0x3342('0x69')](new Extension(_0x4672b5,0x2,'Set','CDR(prefix)='+_0x58cbdd[_0x3342('0x2e')]));if(_0x58cbdd[_0x3342('0x6a')]){_0x146ffc[_0x3342('0x69')](new Extension(_0x4672b5,0x3,_0x3342('0x6b'),_0x3342('0x6c')+_0x58cbdd[_0x3342('0x6a')]));}else{_0x146ffc[_0x3342('0x69')](new Extension(_0x4672b5,0x3,_0x3342('0x63'),_0x3342('0x6d')));}_0x146ffc[_0x3342('0x69')](new Extension(_0x4672b5,0x4,'goto',_0x5c9399[_0x3342('0x6e')]+','+'${EXTEN:'+(0x8+_0x58cbdd[_0x3342('0x2e')][_0x3342('0x3c')])+'}'+','+0x1));return _0x146ffc;}function formatPrefixName(_0x536fbc){var _0x18cadb='_';for(var _0x3506d4=0x0;_0x3506d4<_0x536fbc['length'];_0x3506d4++){if(_0x536fbc[_0x3342('0x6f')](_0x3506d4)=='-'){_0x18cadb+=_0x536fbc[_0x3342('0x6f')](_0x3506d4);}else{_0x18cadb+='['+_0x536fbc[_0x3342('0x6f')](_0x3506d4)+']';}}_0x18cadb+='.';return _0x18cadb;}exports[_0x3342('0x27')]=function(_0x6b9502,_0x42bc3b,_0x28d937){var _0x57b8ac=_0x6b9502[_0x3342('0x50')];_0x57b8ac['prefix']='system-'+_0x57b8ac[_0x3342('0x2e')]+'-';return db[_0x3342('0x4f')][_0x3342('0x70')](function(_0x28e73f){return db[_0x3342('0x30')][_0x3342('0x27')](_0x57b8ac,{'where':{'id':_0x57b8ac['id']},'transaction':_0x28e73f})[_0x3342('0x2a')](function(){return db[_0x3342('0x52')]['destroy']({'where':{'VoicePrefixId':_0x57b8ac['id']},'transaction':_0x28e73f})[_0x3342('0x2a')](function(){return db[_0x3342('0x52')][_0x3342('0x4b')]({'where':{'id':_0x57b8ac[_0x3342('0x66')]},'raw':!![]})[_0x3342('0x2a')](function(_0x2f02ce){return createVoicePrefixExtensions(_0x57b8ac,_0x2f02ce,_0x28e73f);});});});})[_0x3342('0x2a')](function(){return db['VoicePrefix'][_0x3342('0x71')](_0x57b8ac['id']);})[_0x3342('0x2a')](respondWithResult(_0x42bc3b,null))[_0x3342('0x48')](handleError(_0x42bc3b,null));};exports[_0x3342('0x72')]=function(_0x38a83f,_0x30e493,_0x5a9027){return db['VoicePrefix']['find']({'where':{'id':_0x38a83f[_0x3342('0x4c')]['id']}})[_0x3342('0x2a')](handleEntityNotFound(_0x30e493,null))[_0x3342('0x2a')](function(_0x43cabb){if(_0x43cabb){return _0x43cabb[_0x3342('0x72')](_0x38a83f[_0x3342('0x50')][_0x3342('0x73')],_[_0x3342('0x74')](_0x38a83f['body'],[_0x3342('0x73'),'id'])||{})[_0x3342('0x75')](function(_0x2967d6){for(var _0x42782f=0x0;_0x42782f<_0x38a83f['body'][_0x3342('0x73')][_0x3342('0x3c')];_0x42782f+=0x1){socket[_0x3342('0x76')](_0x3342('0x77'),{'UserId':Number(_0x38a83f[_0x3342('0x50')][_0x3342('0x73')][_0x42782f]),'VoicePrefixId':Number(_0x38a83f[_0x3342('0x4c')]['id'])});}return _0x2967d6;});}})[_0x3342('0x2a')](respondWithResult(_0x30e493,null))[_0x3342('0x48')](handleError(_0x30e493,null));};exports['removeAgents']=function(_0xdc419a,_0x1862b8,_0x58c1b1){return db[_0x3342('0x30')]['find']({'where':{'id':_0xdc419a[_0x3342('0x4c')]['id']}})['then'](handleEntityNotFound(_0x1862b8,null))[_0x3342('0x2a')](function(_0x5b2f46){if(_0x5b2f46){return _0x5b2f46[_0x3342('0x78')](_0xdc419a[_0x3342('0x37')]['ids'])[_0x3342('0x2a')](function(){if(_[_0x3342('0x79')](_0xdc419a['query'][_0x3342('0x73')])){for(var _0x24c9ef=0x0;_0x24c9ef<_0xdc419a[_0x3342('0x37')][_0x3342('0x73')][_0x3342('0x3c')];_0x24c9ef+=0x1){socket[_0x3342('0x76')]('userVoicePrefix:remove',{'UserId':Number(_0xdc419a[_0x3342('0x37')][_0x3342('0x73')][_0x24c9ef]),'VoicePrefixId':Number(_0xdc419a[_0x3342('0x4c')]['id'])});}}else{socket[_0x3342('0x76')](_0x3342('0x7a'),{'UserId':Number(_0xdc419a[_0x3342('0x37')][_0x3342('0x73')]),'VoicePrefixId':Number(_0xdc419a[_0x3342('0x4c')]['id'])});}});}})[_0x3342('0x2a')](respondWithStatusCode(_0x1862b8,null))[_0x3342('0x48')](handleError(_0x1862b8,null));};exports['getAgents']=function(_0x677fc4,_0x7c5834,_0x2e050f){var _0x592122={};var _0x5ef689={};var _0x344a1d;var _0x52e891;return db['VoicePrefix'][_0x3342('0x7b')]({'where':{'id':_0x677fc4[_0x3342('0x4c')]['id']}})['then'](handleEntityNotFound(_0x7c5834,null))[_0x3342('0x2a')](function(_0x4d7132){if(_0x4d7132){_0x344a1d=_0x4d7132;_0x5ef689[_0x3342('0x35')]=_['keys'](db['User'][_0x3342('0x31')]);_0x5ef689[_0x3342('0x37')]=_[_0x3342('0x38')](_0x677fc4['query']);_0x5ef689['filters']=_[_0x3342('0x3a')](_0x5ef689['model'],_0x5ef689[_0x3342('0x37')]);_0x592122[_0x3342('0x39')]=_[_0x3342('0x3a')](_0x5ef689[_0x3342('0x35')],qs['fields'](_0x677fc4['query'][_0x3342('0x3b')]));_0x592122[_0x3342('0x39')]=_0x592122['attributes'][_0x3342('0x3c')]?_0x592122['attributes']:_0x5ef689[_0x3342('0x35')];_0x592122[_0x3342('0x7c')]=qs[_0x3342('0x3e')](_0x677fc4[_0x3342('0x37')][_0x3342('0x3e')]);_0x592122['where']=qs['filters'](_['pick'](_0x677fc4[_0x3342('0x37')],_0x5ef689[_0x3342('0x40')]));if(_0x677fc4[_0x3342('0x37')]['filter']){_0x592122[_0x3342('0x3f')]=_[_0x3342('0x43')](_0x592122[_0x3342('0x3f')],{'$or':_[_0x3342('0x36')](_0x592122[_0x3342('0x39')],function(_0x2355c0){var _0x5cfbf6={};_0x5cfbf6[_0x2355c0]={'$like':'%'+_0x677fc4[_0x3342('0x37')]['filter']+'%'};return _0x5cfbf6;})});}_0x592122=_['merge']({},_0x592122,_0x677fc4['options']);return _0x344a1d[_0x3342('0x7d')](_0x592122);}})[_0x3342('0x2a')](function(_0x50c080){if(_0x50c080){_0x52e891=_0x50c080[_0x3342('0x3c')];if(!_0x677fc4[_0x3342('0x37')]['hasOwnProperty'](_0x3342('0x7e'))){_0x592122[_0x3342('0x21')]=qs[_0x3342('0x21')](_0x677fc4[_0x3342('0x37')][_0x3342('0x21')]);_0x592122[_0x3342('0x1f')]=qs[_0x3342('0x1f')](_0x677fc4[_0x3342('0x37')]['offset']);}return _0x344a1d[_0x3342('0x7d')](_0x592122);}})[_0x3342('0x2a')](function(_0x13738c){if(_0x13738c){return _0x13738c?{'count':_0x52e891,'rows':_0x13738c}:null;}})[_0x3342('0x2a')](respondWithResult(_0x7c5834,null))[_0x3342('0x48')](handleError(_0x7c5834,null));};exports[_0x3342('0x7f')]=function(_0x2d2902,_0x49de28,_0x57a3f8){var _0x1fdaa3={};var _0x2fd436={};var _0x28b7ba;var _0x36ac0d;return db[_0x3342('0x30')][_0x3342('0x7b')]({'where':{'id':_0x2d2902[_0x3342('0x4c')]['id']}})['then'](handleEntityNotFound(_0x49de28,null))[_0x3342('0x2a')](function(_0x15652e){if(_0x15652e){_0x28b7ba=_0x15652e;_0x2fd436[_0x3342('0x35')]=_[_0x3342('0x38')](db[_0x3342('0x80')]['rawAttributes']);_0x2fd436[_0x3342('0x37')]=_[_0x3342('0x38')](_0x2d2902[_0x3342('0x37')]);_0x2fd436[_0x3342('0x40')]=_['intersection'](_0x2fd436[_0x3342('0x35')],_0x2fd436[_0x3342('0x37')]);_0x1fdaa3[_0x3342('0x39')]=_[_0x3342('0x3a')](_0x2fd436[_0x3342('0x35')],qs[_0x3342('0x3b')](_0x2d2902[_0x3342('0x37')]['fields']));_0x1fdaa3['attributes']=_0x1fdaa3[_0x3342('0x39')]['length']?_0x1fdaa3[_0x3342('0x39')]:_0x2fd436[_0x3342('0x35')];_0x1fdaa3[_0x3342('0x7c')]=qs[_0x3342('0x3e')](_0x2d2902[_0x3342('0x37')]['sort']);_0x1fdaa3[_0x3342('0x3f')]=qs[_0x3342('0x40')](_[_0x3342('0x41')](_0x2d2902['query'],_0x2fd436['filters']));if(_0x2d2902[_0x3342('0x37')][_0x3342('0x42')]){_0x1fdaa3[_0x3342('0x3f')]=_[_0x3342('0x43')](_0x1fdaa3[_0x3342('0x3f')],{'$or':_[_0x3342('0x36')](_0x1fdaa3[_0x3342('0x39')],function(_0x2c8c08){var _0x316b4c={};_0x316b4c[_0x2c8c08]={'$like':'%'+_0x2d2902[_0x3342('0x37')][_0x3342('0x42')]+'%'};return _0x316b4c;})});}_0x1fdaa3=_[_0x3342('0x43')]({},_0x1fdaa3,_0x2d2902['options']);return _0x28b7ba['getTeams'](_0x1fdaa3);}})['then'](function(_0x2539a0){if(_0x2539a0){_0x36ac0d=_0x2539a0[_0x3342('0x3c')];if(!_0x2d2902[_0x3342('0x37')][_0x3342('0x3d')](_0x3342('0x7e'))){_0x1fdaa3['limit']=qs[_0x3342('0x21')](_0x2d2902[_0x3342('0x37')][_0x3342('0x21')]);_0x1fdaa3['offset']=qs[_0x3342('0x1f')](_0x2d2902[_0x3342('0x37')]['offset']);}return _0x28b7ba['getTeams'](_0x1fdaa3);}})[_0x3342('0x2a')](function(_0x1cbc11){if(_0x1cbc11){return _0x1cbc11?{'count':_0x36ac0d,'rows':_0x1cbc11}:null;}})[_0x3342('0x2a')](respondWithResult(_0x49de28,null))[_0x3342('0x48')](handleError(_0x49de28,null));};exports[_0x3342('0x81')]=function(_0x51b0f9,_0x48cb53,_0x37fdc5){var _0x26063d=_0x51b0f9[_0x3342('0x50')][_0x3342('0x73')];var _0x43323e;return db[_0x3342('0x80')][_0x3342('0x46')]({'where':{'id':_0x26063d},'attributes':['id'],'include':[{'model':db['User'],'as':'Agents','attributes':['id','name',_0x3342('0x82'),'voicePause','interface'],'raw':!![]}]})['then'](function(_0x3c1c34){if(_0x3c1c34){_0x43323e=_0x3c1c34;var _0x319a6e=_['flatMap'](_0x3c1c34,function(_0x36739b){var _0x4dcbb1=_0x36739b['get']({'plain':!![]});return _0x4dcbb1[_0x3342('0x83')];});return db['VoicePrefix'][_0x3342('0x4b')]({'where':{'id':_0x51b0f9[_0x3342('0x4c')]['id']}})[_0x3342('0x2a')](function(_0x2b029d){return db[_0x3342('0x4f')][_0x3342('0x70')](function(_0x5aa6ce){return _0x2b029d[_0x3342('0x81')](_0x26063d,{'transaction':_0x5aa6ce})[_0x3342('0x2a')](function(){return BPromise[_0x3342('0x84')](_0x43323e,function(_0x5d9c1e){return db[_0x3342('0x85')][_0x3342('0x86')]({'TeamId':_0x5d9c1e['id'],'VoicePrefixId':_0x51b0f9[_0x3342('0x4c')]['id']},{'transaction':_0x5aa6ce});});})[_0x3342('0x2a')](function(){return BPromise[_0x3342('0x84')](_0x319a6e,function(_0x41de0c){return db['UserVoicePrefix'][_0x3342('0x87')]({'where':{'UserId':_0x41de0c['id'],'VoicePrefixId':_0x51b0f9[_0x3342('0x4c')]['id']},'transaction':_0x5aa6ce});});})[_0x3342('0x2a')](function(){_0x319a6e[_0x3342('0x88')](function(_0x441c2a){socket['emit'](_0x3342('0x77'),{'UserId':_0x441c2a['id'],'VoicePrefixId':_0x2b029d['id']});});});});});}})[_0x3342('0x2a')](respondWithStatusCode(_0x48cb53,null))[_0x3342('0x48')](handleError(_0x48cb53,null));};exports[_0x3342('0x89')]=function(_0x498de2,_0x100d41,_0x56251e){return db[_0x3342('0x80')][_0x3342('0x46')]({'where':{'id':_0x498de2[_0x3342('0x37')]['ids']},'attributes':['id'],'include':[{'model':db[_0x3342('0x8a')],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0x3342('0x2a')](handleEntityNotFound(_0x100d41,null))['then'](function(_0x340350){var _0xe6d040=_[_0x3342('0x36')](_0x340350,'id');var _0x58253f=[];var _0x25b867=[];var _0x3a6d87=squel[_0x3342('0x8b')]();_0x3a6d87[_0x3342('0x8c')](_0x3342('0x8d'))[_0x3342('0x8e')](_0x3342('0x8f'),'tq')['join'](_0x3342('0x90'),'ut',_0x3342('0x91'))[_0x3342('0x3f')]('VoicePrefixId\x20=\x20?',_0x498de2[_0x3342('0x4c')]['id']);for(var _0x3c0eb8=0x0;_0x3c0eb8<_0x340350[_0x3342('0x3c')];_0x3c0eb8+=0x1){let _0x2b5df1=_0x340350[_0x3c0eb8];for(var _0xe57bc1=0x0;_0xe57bc1<_0x2b5df1[_0x3342('0x83')][_0x3342('0x3c')];_0xe57bc1+=0x1){let _0x2ae81c=_0x2b5df1['Agents'][_0xe57bc1];var _0x448a3c=_0x3a6d87[_0x3342('0x92')]();_0x448a3c['where'](_0x3342('0x93'),_0x2ae81c['id']);_0x25b867[_0x3342('0x69')](db[_0x3342('0x4f')][_0x3342('0x37')](_0x448a3c[_0x3342('0x94')](),{'type':db[_0x3342('0x4f')][_0x3342('0x95')][_0x3342('0x96')]})[_0x3342('0x2a')](function(_0x31095f){if(_0x31095f[_0x3342('0x3c')]===0x1){return _0x2ae81c['id'];}else{var _0x4a301d=_['every'](_[_0x3342('0x36')](_0x31095f,_0x3342('0x97')),function(_0x107e1b){return _[_0x3342('0x98')](_0xe6d040,_0x107e1b);});if(_0x4a301d){return _0x2ae81c['id'];}}}));}}return BPromise[_0x3342('0x99')](_0x25b867)[_0x3342('0x2a')](function(_0x34f15a){_0x58253f=_(_0x58253f)[_0x3342('0x9a')](_0x34f15a)[_0x3342('0x9b')]()[_0x3342('0x9c')]();return db[_0x3342('0x30')][_0x3342('0x4b')]({'where':{'id':_0x498de2[_0x3342('0x4c')]['id']}})[_0x3342('0x2a')](function(_0x45d548){return db[_0x3342('0x4f')]['transaction'](function(_0x4e1359){return _0x45d548[_0x3342('0x89')](_0x498de2[_0x3342('0x37')]['ids'],{'transaction':_0x4e1359})[_0x3342('0x2a')](function(){if(!_[_0x3342('0x9d')](_0x58253f)){return _0x45d548['removeAgents'](_0x58253f,{'transaction':_0x4e1359});}})[_0x3342('0x2a')](function(){_0x58253f['forEach'](function(_0x24049f){socket[_0x3342('0x76')](_0x3342('0x7a'),{'UserId':_0x24049f,'VoicePrefixId':_0x45d548['id']});});});});});});})[_0x3342('0x2a')](respondWithStatusCode(_0x100d41,null))[_0x3342('0x48')](handleError(_0x100d41,null));};
\ No newline at end of file