Built motion from commit efa66e19.|2.6.22
[motion2.git] / server / api / voicePrefix / voicePrefix.controller.js
index 8b9e88d..2d5c88f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf1c6=['transaction','findById','addAgents','ids','omit','userVoicePrefix:remove','getAgents','User','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','redis','localhost','./voicePrefix.socket','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','save','then','destroy','get','VoicePrefixes','UserProfileResource','stack','name','index','map','rawAttributes','fieldName','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','type','VIRTUAL','includeAll','include','VoicePrefix','findAll','catch','show','params','options','find','describe','create','sequelize','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','error','context','from-sip','exten','app','system','Voice\x20Prefix\x20Extension','appdata','prefix','Voice\x20Prefix','VoicePrefixId','VoiceExtension','VoiceExtensionId','bulkCreate','Extensions\x20creation\x20failed','CDR(prefix)=','callerIdAll','push','Set','NoOp','goto','charAt','update'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0xf1c6,0xf4));var _0x6f1c=function(_0xfe00bd,_0x4c9578){_0xfe00bd=_0xfe00bd-0x0;var _0x50e3ee=_0xf1c6[_0xfe00bd];return _0x50e3ee;};'use strict';var pdf=require(_0x6f1c('0x0'));var emlformat=require(_0x6f1c('0x1'));var rimraf=require(_0x6f1c('0x2'));var zipdir=require(_0x6f1c('0x3'));var jsonpatch=require(_0x6f1c('0x4'));var rp=require(_0x6f1c('0x5'));var moment=require(_0x6f1c('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x6f1c('0x7'));var util=require(_0x6f1c('0x8'));var path=require(_0x6f1c('0x9'));var sox=require(_0x6f1c('0xa'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x6f1c('0xb'));var squel=require(_0x6f1c('0xc'));var crypto=require(_0x6f1c('0xd'));var jsforce=require(_0x6f1c('0xe'));var deskjs=require(_0x6f1c('0xf'));var toCsv=require(_0x6f1c('0x10'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x6f1c('0x11'));var authService=require(_0x6f1c('0x12'));var qs=require(_0x6f1c('0x13'));var as=require(_0x6f1c('0x14'));var hardwareService=require(_0x6f1c('0x15'));var logger=require(_0x6f1c('0x16'))('api');var utils=require(_0x6f1c('0x17'));var config=require(_0x6f1c('0x18'));var licenseUtil=require('../../config/license/util');var db=require(_0x6f1c('0x19'))['db'];config['redis']=_['defaults'](config[_0x6f1c('0x1a')],{'host':_0x6f1c('0x1b'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x6f1c('0x1c'))['register'](socket);function respondWithStatusCode(_0x206ed5,_0xb36b41){_0xb36b41=_0xb36b41||0xcc;return function(_0x14c412){if(_0x14c412){return _0x206ed5[_0x6f1c('0x1d')](_0xb36b41);}return _0x206ed5[_0x6f1c('0x1e')](_0xb36b41)[_0x6f1c('0x1f')]();};}function respondWithResult(_0xbac2ee,_0x5e953f){_0x5e953f=_0x5e953f||0xc8;return function(_0x2ca612){if(_0x2ca612){return _0xbac2ee['status'](_0x5e953f)[_0x6f1c('0x20')](_0x2ca612);}};}function respondWithFilteredResult(_0x5a0a2d,_0x1d968f){return function(_0x66103a){if(_0x66103a){var _0x5b11ea=_0x66103a[_0x6f1c('0x21')],_0x5475d6=_0x1d968f['offset'],_0x317686=_0x1d968f[_0x6f1c('0x22')]+_0x1d968f[_0x6f1c('0x23')],_0x842773;if(_0x317686>=_0x5b11ea){_0x317686=_0x5b11ea;_0x842773=0xc8;}else{_0x842773=0xce;}_0x5a0a2d[_0x6f1c('0x1e')](_0x842773);return _0x5a0a2d['set'](_0x6f1c('0x24'),_0x5475d6+'-'+_0x317686+'/'+_0x5b11ea)[_0x6f1c('0x20')](_0x66103a);}return null;};}function patchUpdates(_0x27a351){return function(_0x539d59){try{jsonpatch[_0x6f1c('0x25')](_0x539d59,_0x27a351,!![]);}catch(_0xebf430){return BPromise['reject'](_0xebf430);}return _0x539d59[_0x6f1c('0x26')]();};}function saveUpdates(_0x1f7ac2,_0x3fe23a){return function(_0x25e460){if(_0x25e460){return _0x25e460['update'](_0x1f7ac2)[_0x6f1c('0x27')](function(_0xd19a62){return _0xd19a62;});}return null;};}function removeEntity(_0x235773,_0x241ee7){return function(_0xa9c80d){if(_0xa9c80d){return _0xa9c80d[_0x6f1c('0x28')]()['then'](function(){var _0x1ac41=_0xa9c80d[_0x6f1c('0x29')]({'plain':!![]});var _0x2d4236=_0x6f1c('0x2a');return db[_0x6f1c('0x2b')]['destroy']({'where':{'type':_0x2d4236,'resourceId':_0x1ac41['id']}})[_0x6f1c('0x27')](function(){return _0xa9c80d;});})[_0x6f1c('0x27')](function(){_0x235773[_0x6f1c('0x1e')](0xcc)[_0x6f1c('0x1f')]();});}};}function handleEntityNotFound(_0x31e829,_0x145ae9){return function(_0x4d120d){if(!_0x4d120d){_0x31e829['sendStatus'](0x194);}return _0x4d120d;};}function handleError(_0x30ba57,_0x2b3732){_0x2b3732=_0x2b3732||0x1f4;return function(_0x1b5c9a){logger['error'](_0x1b5c9a[_0x6f1c('0x2c')]);if(_0x1b5c9a[_0x6f1c('0x2d')]){delete _0x1b5c9a[_0x6f1c('0x2d')];}_0x30ba57[_0x6f1c('0x1e')](_0x2b3732)['send'](_0x1b5c9a);};}exports[_0x6f1c('0x2e')]=function(_0x11f1f6,_0x5c09ba){var _0x11ac4b={},_0x346c4a={},_0x182f99={'count':0x0,'rows':[]};var _0x5a25ec=_[_0x6f1c('0x2f')](db['VoicePrefix'][_0x6f1c('0x30')],function(_0x2ee3e7){return{'name':_0x2ee3e7[_0x6f1c('0x31')],'type':_0x2ee3e7['type']['key']};});_0x346c4a[_0x6f1c('0x32')]=_[_0x6f1c('0x2f')](_0x5a25ec,_0x6f1c('0x2d'));_0x346c4a[_0x6f1c('0x33')]=_[_0x6f1c('0x34')](_0x11f1f6[_0x6f1c('0x33')]);_0x346c4a[_0x6f1c('0x35')]=_[_0x6f1c('0x36')](_0x346c4a[_0x6f1c('0x32')],_0x346c4a[_0x6f1c('0x33')]);_0x11ac4b[_0x6f1c('0x37')]=_[_0x6f1c('0x36')](_0x346c4a[_0x6f1c('0x32')],qs[_0x6f1c('0x38')](_0x11f1f6[_0x6f1c('0x33')]['fields']));_0x11ac4b[_0x6f1c('0x37')]=_0x11ac4b[_0x6f1c('0x37')][_0x6f1c('0x39')]?_0x11ac4b[_0x6f1c('0x37')]:_0x346c4a['model'];if(!_0x11f1f6[_0x6f1c('0x33')][_0x6f1c('0x3a')](_0x6f1c('0x3b'))){_0x11ac4b[_0x6f1c('0x23')]=qs[_0x6f1c('0x23')](_0x11f1f6[_0x6f1c('0x33')][_0x6f1c('0x23')]);_0x11ac4b['offset']=qs[_0x6f1c('0x22')](_0x11f1f6[_0x6f1c('0x33')][_0x6f1c('0x22')]);}_0x11ac4b[_0x6f1c('0x3c')]=qs[_0x6f1c('0x3d')](_0x11f1f6[_0x6f1c('0x33')][_0x6f1c('0x3d')]);_0x11ac4b[_0x6f1c('0x3e')]=qs[_0x6f1c('0x35')](_[_0x6f1c('0x3f')](_0x11f1f6['query'],_0x346c4a[_0x6f1c('0x35')]),_0x5a25ec);if(_0x11f1f6[_0x6f1c('0x33')][_0x6f1c('0x40')]){_0x11ac4b[_0x6f1c('0x3e')]=_[_0x6f1c('0x41')](_0x11ac4b[_0x6f1c('0x3e')],{'$or':_[_0x6f1c('0x2f')](_0x5a25ec,function(_0x248fc4){if(_0x248fc4[_0x6f1c('0x42')]!==_0x6f1c('0x43')){var _0xcd112e={};_0xcd112e[_0x248fc4['name']]={'$like':'%'+_0x11f1f6[_0x6f1c('0x33')][_0x6f1c('0x40')]+'%'};return _0xcd112e;}})});}_0x11ac4b=_[_0x6f1c('0x41')]({},_0x11ac4b,_0x11f1f6['options']);var _0x4e2754={'where':_0x11ac4b[_0x6f1c('0x3e')]};return db['VoicePrefix']['count'](_0x4e2754)[_0x6f1c('0x27')](function(_0x4f58a7){_0x182f99[_0x6f1c('0x21')]=_0x4f58a7;if(_0x11f1f6['query'][_0x6f1c('0x44')]){_0x11ac4b[_0x6f1c('0x45')]=[{'all':!![]}];}return db[_0x6f1c('0x46')][_0x6f1c('0x47')](_0x11ac4b);})[_0x6f1c('0x27')](function(_0x35203e){_0x182f99['rows']=_0x35203e;return _0x182f99;})[_0x6f1c('0x27')](respondWithFilteredResult(_0x5c09ba,_0x11ac4b))[_0x6f1c('0x48')](handleError(_0x5c09ba,null));};exports[_0x6f1c('0x49')]=function(_0x234d79,_0x1a506b){var _0x307e7e={'raw':![],'where':{'id':_0x234d79[_0x6f1c('0x4a')]['id']}},_0xd61e73={};_0xd61e73[_0x6f1c('0x32')]=_[_0x6f1c('0x34')](db[_0x6f1c('0x46')][_0x6f1c('0x30')]);_0xd61e73['query']=_['keys'](_0x234d79[_0x6f1c('0x33')]);_0xd61e73['filters']=_[_0x6f1c('0x36')](_0xd61e73[_0x6f1c('0x32')],_0xd61e73['query']);_0x307e7e[_0x6f1c('0x37')]=_[_0x6f1c('0x36')](_0xd61e73[_0x6f1c('0x32')],qs['fields'](_0x234d79['query'][_0x6f1c('0x38')]));_0x307e7e[_0x6f1c('0x37')]=_0x307e7e[_0x6f1c('0x37')][_0x6f1c('0x39')]?_0x307e7e['attributes']:_0xd61e73[_0x6f1c('0x32')];if(_0x234d79[_0x6f1c('0x33')][_0x6f1c('0x44')]){_0x307e7e[_0x6f1c('0x45')]=[{'all':!![]}];}_0x307e7e=_[_0x6f1c('0x41')]({},_0x307e7e,_0x234d79[_0x6f1c('0x4b')]);return db['VoicePrefix'][_0x6f1c('0x4c')](_0x307e7e)['then'](handleEntityNotFound(_0x1a506b,null))['then'](respondWithResult(_0x1a506b,null))[_0x6f1c('0x48')](handleError(_0x1a506b,null));};exports['destroy']=function(_0x256ca1,_0x79498){return db[_0x6f1c('0x46')][_0x6f1c('0x4c')]({'where':{'id':_0x256ca1[_0x6f1c('0x4a')]['id']}})[_0x6f1c('0x27')](handleEntityNotFound(_0x79498,null))[_0x6f1c('0x27')](removeEntity(_0x79498,null))[_0x6f1c('0x48')](handleError(_0x79498,null));};exports[_0x6f1c('0x4d')]=function(_0x374bf6,_0x530b9f){return db['VoicePrefix'][_0x6f1c('0x4d')]()[_0x6f1c('0x27')](respondWithResult(_0x530b9f,null))[_0x6f1c('0x48')](handleError(_0x530b9f,null));};exports[_0x6f1c('0x4e')]=function(_0xe29b0c,_0x70c654){var _0x353b50;return db[_0x6f1c('0x4f')]['transaction'](function(_0x2878e7){return db['VoicePrefix']['create'](_0xe29b0c[_0x6f1c('0x50')],{'transaction':_0x2878e7})[_0x6f1c('0x27')](function(_0x4a7244){_0x353b50=_0x4a7244[_0x6f1c('0x29')]({'plain':!![]});return db['VoiceExtension'][_0x6f1c('0x4c')]({'where':{'id':_0x353b50['VoiceExtensionId']},'raw':!![]})[_0x6f1c('0x27')](function(_0x546f05){return createVoicePrefixExtensions(_0x353b50,_0x546f05,_0x2878e7);});});})[_0x6f1c('0x27')](function(){var _0x40c1a7=_0xe29b0c[_0x6f1c('0x51')][_0x6f1c('0x29')]({'plain':!![]});if(!_0x40c1a7)throw new Error(_0x6f1c('0x52'));if(_0x40c1a7[_0x6f1c('0x53')]===_0x6f1c('0x51')){var _0x2397c2=_0x353b50;return db[_0x6f1c('0x54')][_0x6f1c('0x4c')]({'where':{'name':_0x6f1c('0x2a'),'userProfileId':_0x40c1a7[_0x6f1c('0x55')]},'raw':!![]})[_0x6f1c('0x27')](function(_0x567d50){if(_0x567d50&&_0x567d50[_0x6f1c('0x56')]===0x0){return db[_0x6f1c('0x2b')][_0x6f1c('0x4e')]({'name':_0x2397c2[_0x6f1c('0x2d')],'resourceId':_0x2397c2['id'],'type':_0x567d50['name'],'sectionId':_0x567d50['id']},{})[_0x6f1c('0x27')](function(){return _0x353b50;});}else{return _0x353b50;}})['catch'](function(_0x199aad){logger[_0x6f1c('0x57')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x199aad);throw _0x199aad;});}return _0x353b50;})[_0x6f1c('0x27')](respondWithResult(_0x70c654,null))['catch'](handleError(_0x70c654,null));};function Extension(_0xd9e2a2,_0x43b6c1,_0x5ce94a,_0x12d3c9){this[_0x6f1c('0x58')]=_0x6f1c('0x59');this[_0x6f1c('0x5a')]=_0xd9e2a2;this[_0x6f1c('0x5b')]=_0x5ce94a;this['type']=_0x6f1c('0x5c');this['description']=_0x6f1c('0x5d');this['priority']=_0x43b6c1;this[_0x6f1c('0x5e')]=_0x12d3c9;}function createVoicePrefixExtensions(_0x8c47e0,_0x4556a6,_0x2ef7ce){return new BPromise(function(_0x471664,_0x712a6b){var _0x57ebea=new Extension(formatPrefixName(_0x8c47e0[_0x6f1c('0x5f')]),0x1,'NoOp',_0x6f1c('0x60'));_0x57ebea[_0x6f1c('0x61')]=_0x8c47e0['id'];return db[_0x6f1c('0x62')][_0x6f1c('0x4e')](_0x57ebea,{'transaction':_0x2ef7ce})[_0x6f1c('0x27')](function(_0x7baff3){var _0x4694f3=_0x7baff3[_0x6f1c('0x29')]({'plain':!![]});var _0x518bbc=_[_0x6f1c('0x2f')](addVoicePrefixExtensions(_0x8c47e0,_0x4556a6),function(_0x291a3f){_0x291a3f[_0x6f1c('0x63')]=_0x4694f3['id'];_0x291a3f[_0x6f1c('0x61')]=_0x8c47e0['id'];return _0x291a3f;});return db[_0x6f1c('0x62')][_0x6f1c('0x64')](_0x518bbc,{'transaction':_0x2ef7ce})[_0x6f1c('0x27')](function(_0x3f2cea){if(!_0x3f2cea){return _0x712a6b(_0x6f1c('0x65'));}else{return _0x471664(_0x3f2cea);}})[_0x6f1c('0x48')](function(_0x4ee324){return _0x712a6b(_0x4ee324);});});;});};function addVoicePrefixExtensions(_0x49c6ad,_0x23e0e5){var _0x3ed2f0=[];var _0xd36d97=formatPrefixName(_0x49c6ad[_0x6f1c('0x5f')]);_0x3ed2f0['push'](new Extension(_0xd36d97,0x2,'Set',_0x6f1c('0x66')+_0x49c6ad['name']));if(_0x49c6ad[_0x6f1c('0x67')]){_0x3ed2f0[_0x6f1c('0x68')](new Extension(_0xd36d97,0x3,_0x6f1c('0x69'),'PREFIX-CALLERIDALL='+_0x49c6ad[_0x6f1c('0x67')]));}else{_0x3ed2f0[_0x6f1c('0x68')](new Extension(_0xd36d97,0x3,_0x6f1c('0x6a'),'No\x20callerid\x20available'));}_0x3ed2f0['push'](new Extension(_0xd36d97,0x4,_0x6f1c('0x6b'),_0x23e0e5[_0x6f1c('0x58')]+','+'${EXTEN:'+(0x8+_0x49c6ad[_0x6f1c('0x2d')][_0x6f1c('0x39')])+'}'+','+0x1));return _0x3ed2f0;}function formatPrefixName(_0x515374){var _0x5f219a='_';for(var _0x24d863=0x0;_0x24d863<_0x515374[_0x6f1c('0x39')];_0x24d863++){if(_0x515374[_0x6f1c('0x6c')](_0x24d863)=='-'){_0x5f219a+=_0x515374[_0x6f1c('0x6c')](_0x24d863);}else{_0x5f219a+='['+_0x515374[_0x6f1c('0x6c')](_0x24d863)+']';}}_0x5f219a+='.';return _0x5f219a;}exports[_0x6f1c('0x6d')]=function(_0x27490c,_0x2c6752,_0x68c121){var _0x2e4743=_0x27490c[_0x6f1c('0x50')];_0x2e4743[_0x6f1c('0x5f')]='system-'+_0x2e4743[_0x6f1c('0x2d')]+'-';return db['sequelize'][_0x6f1c('0x6e')](function(_0x46bbc3){return db[_0x6f1c('0x46')][_0x6f1c('0x6d')](_0x2e4743,{'where':{'id':_0x2e4743['id']},'transaction':_0x46bbc3})[_0x6f1c('0x27')](function(){return db['VoiceExtension'][_0x6f1c('0x28')]({'where':{'VoicePrefixId':_0x2e4743['id']},'transaction':_0x46bbc3})[_0x6f1c('0x27')](function(){return db[_0x6f1c('0x62')][_0x6f1c('0x4c')]({'where':{'id':_0x2e4743[_0x6f1c('0x63')]},'raw':!![]})['then'](function(_0x5324e4){return createVoicePrefixExtensions(_0x2e4743,_0x5324e4,_0x46bbc3);});});});})[_0x6f1c('0x27')](function(){return db[_0x6f1c('0x46')][_0x6f1c('0x6f')](_0x2e4743['id']);})[_0x6f1c('0x27')](respondWithResult(_0x2c6752,null))[_0x6f1c('0x48')](handleError(_0x2c6752,null));};exports['addAgents']=function(_0x251baf,_0x32aa2f,_0x220d83){return db[_0x6f1c('0x46')]['find']({'where':{'id':_0x251baf[_0x6f1c('0x4a')]['id']}})[_0x6f1c('0x27')](handleEntityNotFound(_0x32aa2f,null))[_0x6f1c('0x27')](function(_0xe4ea3c){if(_0xe4ea3c){return _0xe4ea3c[_0x6f1c('0x70')](_0x251baf['body'][_0x6f1c('0x71')],_[_0x6f1c('0x72')](_0x251baf[_0x6f1c('0x50')],[_0x6f1c('0x71'),'id'])||{})['spread'](function(_0x565708){for(var _0xf82c2f=0x0;_0xf82c2f<_0x251baf['body'][_0x6f1c('0x71')][_0x6f1c('0x39')];_0xf82c2f+=0x1){socket['emit']('userVoicePrefix:save',{'UserId':_0x251baf[_0x6f1c('0x50')][_0x6f1c('0x71')][_0xf82c2f],'VoicePrefixId':_0x251baf[_0x6f1c('0x4a')]['id']});}return _0x565708;});}})[_0x6f1c('0x27')](respondWithResult(_0x32aa2f,null))[_0x6f1c('0x48')](handleError(_0x32aa2f,null));};exports['removeAgents']=function(_0x34927a,_0x4e666a,_0x2391d7){return db['VoicePrefix']['find']({'where':{'id':_0x34927a[_0x6f1c('0x4a')]['id']}})[_0x6f1c('0x27')](handleEntityNotFound(_0x4e666a,null))['then'](function(_0x4770f0){if(_0x4770f0){return _0x4770f0['removeAgents'](_0x34927a['query']['ids'])[_0x6f1c('0x27')](function(){if(_['isArray'](_0x34927a[_0x6f1c('0x33')][_0x6f1c('0x71')])){for(var _0x256bab=0x0;_0x256bab<_0x34927a[_0x6f1c('0x33')][_0x6f1c('0x71')][_0x6f1c('0x39')];_0x256bab+=0x1){socket['emit'](_0x6f1c('0x73'),{'UserId':Number(_0x34927a[_0x6f1c('0x33')]['ids'][_0x256bab]),'VoicePrefixId':Number(_0x34927a[_0x6f1c('0x4a')]['id'])});}}else{socket['emit'](_0x6f1c('0x73'),{'UserId':Number(_0x34927a[_0x6f1c('0x33')][_0x6f1c('0x71')]),'VoicePrefixId':Number(_0x34927a[_0x6f1c('0x4a')]['id'])});}});}})[_0x6f1c('0x27')](respondWithStatusCode(_0x4e666a,null))[_0x6f1c('0x48')](handleError(_0x4e666a,null));};exports[_0x6f1c('0x74')]=function(_0x281c4d,_0x2907cb,_0x2195ea){var _0x5d54ec={};var _0x4f4161={};var _0x12f48b;var _0x5d6858;return db['VoicePrefix']['findOne']({'where':{'id':_0x281c4d[_0x6f1c('0x4a')]['id']}})[_0x6f1c('0x27')](handleEntityNotFound(_0x2907cb,null))[_0x6f1c('0x27')](function(_0x37ccb3){if(_0x37ccb3){_0x12f48b=_0x37ccb3;_0x4f4161['model']=_[_0x6f1c('0x34')](db[_0x6f1c('0x75')]['rawAttributes']);_0x4f4161[_0x6f1c('0x33')]=_[_0x6f1c('0x34')](_0x281c4d[_0x6f1c('0x33')]);_0x4f4161[_0x6f1c('0x35')]=_[_0x6f1c('0x36')](_0x4f4161[_0x6f1c('0x32')],_0x4f4161[_0x6f1c('0x33')]);_0x5d54ec[_0x6f1c('0x37')]=_[_0x6f1c('0x36')](_0x4f4161['model'],qs[_0x6f1c('0x38')](_0x281c4d['query']['fields']));_0x5d54ec[_0x6f1c('0x37')]=_0x5d54ec[_0x6f1c('0x37')][_0x6f1c('0x39')]?_0x5d54ec[_0x6f1c('0x37')]:_0x4f4161[_0x6f1c('0x32')];_0x5d54ec[_0x6f1c('0x3c')]=qs[_0x6f1c('0x3d')](_0x281c4d['query']['sort']);_0x5d54ec[_0x6f1c('0x3e')]=qs[_0x6f1c('0x35')](_[_0x6f1c('0x3f')](_0x281c4d[_0x6f1c('0x33')],_0x4f4161['filters']));if(_0x281c4d[_0x6f1c('0x33')][_0x6f1c('0x40')]){_0x5d54ec[_0x6f1c('0x3e')]=_[_0x6f1c('0x41')](_0x5d54ec['where'],{'$or':_['map'](_0x5d54ec[_0x6f1c('0x37')],function(_0x282d6b){var _0x3695d9={};_0x3695d9[_0x282d6b]={'$like':'%'+_0x281c4d[_0x6f1c('0x33')]['filter']+'%'};return _0x3695d9;})});}_0x5d54ec=_[_0x6f1c('0x41')]({},_0x5d54ec,_0x281c4d[_0x6f1c('0x4b')]);return _0x12f48b['getAgents'](_0x5d54ec);}})['then'](function(_0x2deebb){if(_0x2deebb){_0x5d6858=_0x2deebb[_0x6f1c('0x39')];if(!_0x281c4d[_0x6f1c('0x33')][_0x6f1c('0x3a')](_0x6f1c('0x3b'))){_0x5d54ec['limit']=qs[_0x6f1c('0x23')](_0x281c4d['query']['limit']);_0x5d54ec[_0x6f1c('0x22')]=qs[_0x6f1c('0x22')](_0x281c4d[_0x6f1c('0x33')]['offset']);}return _0x12f48b[_0x6f1c('0x74')](_0x5d54ec);}})['then'](function(_0x39939b){if(_0x39939b){return _0x39939b?{'count':_0x5d6858,'rows':_0x39939b}:null;}})['then'](respondWithResult(_0x2907cb,null))[_0x6f1c('0x48')](handleError(_0x2907cb,null));};
\ No newline at end of file
+var _0x4213=['limit','count','set','Content-Range','json','apply','reject','update','then','destroy','get','VoicePrefixes','UserProfileResource','end','error','name','index','map','VoicePrefix','rawAttributes','fieldName','model','query','keys','filters','intersection','attributes','fields','length','sort','where','pick','filter','merge','options','includeAll','findAll','show','params','find','catch','describe','create','sequelize','transaction','body','VoiceExtensionId','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','context','from-sip','exten','app','type','description','Voice\x20Prefix\x20Extension','priority','appdata','NoOp','Voice\x20Prefix','VoicePrefixId','VoiceExtension','bulkCreate','Extensions\x20creation\x20failed','prefix','CDR(prefix)=','callerIdAll','Set','${EXTEN:','charAt','system-','addAgents','ids','spread','emit','userVoicePrefix:save','removeAgents','userVoicePrefix:remove','getAgents','User','nolimit','Team','order','getTeams','addTeams','Agents','online','voicePause','interface','flatMap','each','TeamVoicePrefix','UserVoicePrefix','findOrCreate','forEach','removeTeams','tq.TeamId','from','team_has_voice_prefixes','join','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','includes','all','union','compact','value','isEmpty','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./voicePrefix.socket','register','sendStatus','status','offset','undefined'];(function(_0x3dd3ee,_0x3dbf50){var _0x59b7a9=function(_0x16df3b){while(--_0x16df3b){_0x3dd3ee['push'](_0x3dd3ee['shift']());}};_0x59b7a9(++_0x3dbf50);}(_0x4213,0x77));var _0x3421=function(_0x3ffb65,_0xb02c87){_0x3ffb65=_0x3ffb65-0x0;var _0x1fce79=_0x4213[_0x3ffb65];return _0x1fce79;};'use strict';var emlformat=require(_0x3421('0x0'));var rimraf=require(_0x3421('0x1'));var zipdir=require(_0x3421('0x2'));var jsonpatch=require(_0x3421('0x3'));var rp=require(_0x3421('0x4'));var moment=require(_0x3421('0x5'));var BPromise=require(_0x3421('0x6'));var Mustache=require('mustache');var util=require(_0x3421('0x7'));var path=require('path');var sox=require(_0x3421('0x8'));var csv=require(_0x3421('0x9'));var ejs=require(_0x3421('0xa'));var fs=require('fs');var fs_extra=require(_0x3421('0xb'));var _=require('lodash');var squel=require(_0x3421('0xc'));var crypto=require(_0x3421('0xd'));var jsforce=require(_0x3421('0xe'));var deskjs=require(_0x3421('0xf'));var toCsv=require(_0x3421('0x9'));var querystring=require('querystring');var Papa=require(_0x3421('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x3421('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x3421('0x12'));var logger=require(_0x3421('0x13'))(_0x3421('0x14'));var utils=require(_0x3421('0x15'));var config=require(_0x3421('0x16'));var licenseUtil=require(_0x3421('0x17'));var db=require(_0x3421('0x18'))['db'];config['redis']=_[_0x3421('0x19')](config[_0x3421('0x1a')],{'host':_0x3421('0x1b'),'port':0x18eb});var socket=require(_0x3421('0x1c'))(new Redis(config[_0x3421('0x1a')]));require(_0x3421('0x1d'))[_0x3421('0x1e')](socket);function respondWithStatusCode(_0x59ea4a,_0xafd9e0){_0xafd9e0=_0xafd9e0||0xcc;return function(_0x4b5f43){if(_0x4b5f43){return _0x59ea4a[_0x3421('0x1f')](_0xafd9e0);}return _0x59ea4a[_0x3421('0x20')](_0xafd9e0)['end']();};}function respondWithResult(_0x1e33ab,_0x4c6f7b){_0x4c6f7b=_0x4c6f7b||0xc8;return function(_0x16bc8f){if(_0x16bc8f){return _0x1e33ab[_0x3421('0x20')](_0x4c6f7b)['json'](_0x16bc8f);}};}function respondWithFilteredResult(_0x3584d6,_0x3dec08){return function(_0x130d3c){if(_0x130d3c){var _0x104cc5=typeof _0x3dec08[_0x3421('0x21')]===_0x3421('0x22')&&typeof _0x3dec08[_0x3421('0x23')]===_0x3421('0x22');var _0x197b83=_0x130d3c[_0x3421('0x24')];var _0x538a8b=_0x104cc5?0x0:_0x3dec08['offset'];var _0x420114=_0x104cc5?_0x130d3c['count']:_0x3dec08['offset']+_0x3dec08['limit'];var _0x33155b;if(_0x420114>=_0x197b83){_0x420114=_0x197b83;_0x33155b=0xc8;}else{_0x33155b=0xce;}_0x3584d6[_0x3421('0x20')](_0x33155b);return _0x3584d6[_0x3421('0x25')](_0x3421('0x26'),_0x538a8b+'-'+_0x420114+'/'+_0x197b83)[_0x3421('0x27')](_0x130d3c);}return null;};}function patchUpdates(_0x39bed4){return function(_0x3df305){try{jsonpatch[_0x3421('0x28')](_0x3df305,_0x39bed4,!![]);}catch(_0xb9af5f){return BPromise[_0x3421('0x29')](_0xb9af5f);}return _0x3df305['save']();};}function saveUpdates(_0x57a4af,_0x494423){return function(_0x3fef90){if(_0x3fef90){return _0x3fef90[_0x3421('0x2a')](_0x57a4af)[_0x3421('0x2b')](function(_0x5bc28a){return _0x5bc28a;});}return null;};}function removeEntity(_0x506af4,_0x1b65d0){return function(_0x5b53b6){if(_0x5b53b6){return _0x5b53b6[_0x3421('0x2c')]()['then'](function(){var _0x15e73c=_0x5b53b6[_0x3421('0x2d')]({'plain':!![]});var _0x36d75f=_0x3421('0x2e');return db[_0x3421('0x2f')]['destroy']({'where':{'type':_0x36d75f,'resourceId':_0x15e73c['id']}})[_0x3421('0x2b')](function(){return _0x5b53b6;});})['then'](function(){_0x506af4['status'](0xcc)[_0x3421('0x30')]();});}};}function handleEntityNotFound(_0x5aa96b,_0x5074a2){return function(_0xb4eaf4){if(!_0xb4eaf4){_0x5aa96b['sendStatus'](0x194);}return _0xb4eaf4;};}function handleError(_0x20abc7,_0x5bcd19){_0x5bcd19=_0x5bcd19||0x1f4;return function(_0xc7f9fb){logger[_0x3421('0x31')](_0xc7f9fb['stack']);if(_0xc7f9fb[_0x3421('0x32')]){delete _0xc7f9fb[_0x3421('0x32')];}_0x20abc7[_0x3421('0x20')](_0x5bcd19)['send'](_0xc7f9fb);};}exports[_0x3421('0x33')]=function(_0x50d61b,_0x2b5af4){var _0xf0039={},_0x1045ab={},_0x841e08={'count':0x0,'rows':[]};var _0x3875c6=_[_0x3421('0x34')](db[_0x3421('0x35')][_0x3421('0x36')],function(_0x94559a){return{'name':_0x94559a[_0x3421('0x37')],'type':_0x94559a['type']['key']};});_0x1045ab[_0x3421('0x38')]=_[_0x3421('0x34')](_0x3875c6,'name');_0x1045ab[_0x3421('0x39')]=_[_0x3421('0x3a')](_0x50d61b[_0x3421('0x39')]);_0x1045ab[_0x3421('0x3b')]=_[_0x3421('0x3c')](_0x1045ab['model'],_0x1045ab[_0x3421('0x39')]);_0xf0039[_0x3421('0x3d')]=_[_0x3421('0x3c')](_0x1045ab['model'],qs[_0x3421('0x3e')](_0x50d61b['query'][_0x3421('0x3e')]));_0xf0039[_0x3421('0x3d')]=_0xf0039[_0x3421('0x3d')][_0x3421('0x3f')]?_0xf0039[_0x3421('0x3d')]:_0x1045ab[_0x3421('0x38')];if(!_0x50d61b[_0x3421('0x39')]['hasOwnProperty']('nolimit')){_0xf0039['limit']=qs[_0x3421('0x23')](_0x50d61b['query']['limit']);_0xf0039[_0x3421('0x21')]=qs['offset'](_0x50d61b[_0x3421('0x39')][_0x3421('0x21')]);}_0xf0039['order']=qs[_0x3421('0x40')](_0x50d61b[_0x3421('0x39')][_0x3421('0x40')]);_0xf0039[_0x3421('0x41')]=qs['filters'](_[_0x3421('0x42')](_0x50d61b[_0x3421('0x39')],_0x1045ab[_0x3421('0x3b')]),_0x3875c6);if(_0x50d61b[_0x3421('0x39')][_0x3421('0x43')]){_0xf0039['where']=_[_0x3421('0x44')](_0xf0039[_0x3421('0x41')],{'$or':_['map'](_0x3875c6,function(_0x15551c){if(_0x15551c['type']!=='VIRTUAL'){var _0x486ce8={};_0x486ce8[_0x15551c[_0x3421('0x32')]]={'$like':'%'+_0x50d61b[_0x3421('0x39')][_0x3421('0x43')]+'%'};return _0x486ce8;}})});}_0xf0039=_[_0x3421('0x44')]({},_0xf0039,_0x50d61b[_0x3421('0x45')]);var _0x417d6e={'where':_0xf0039[_0x3421('0x41')]};return db[_0x3421('0x35')][_0x3421('0x24')](_0x417d6e)[_0x3421('0x2b')](function(_0x3b9d15){_0x841e08[_0x3421('0x24')]=_0x3b9d15;if(_0x50d61b[_0x3421('0x39')][_0x3421('0x46')]){_0xf0039['include']=[{'all':!![]}];}return db[_0x3421('0x35')][_0x3421('0x47')](_0xf0039);})[_0x3421('0x2b')](function(_0x4466be){_0x841e08['rows']=_0x4466be;return _0x841e08;})[_0x3421('0x2b')](respondWithFilteredResult(_0x2b5af4,_0xf0039))['catch'](handleError(_0x2b5af4,null));};exports[_0x3421('0x48')]=function(_0x248f84,_0x669cfd){var _0x176aef={'raw':![],'where':{'id':_0x248f84[_0x3421('0x49')]['id']}},_0x2f9a84={};_0x2f9a84[_0x3421('0x38')]=_[_0x3421('0x3a')](db[_0x3421('0x35')][_0x3421('0x36')]);_0x2f9a84[_0x3421('0x39')]=_[_0x3421('0x3a')](_0x248f84[_0x3421('0x39')]);_0x2f9a84['filters']=_[_0x3421('0x3c')](_0x2f9a84['model'],_0x2f9a84[_0x3421('0x39')]);_0x176aef[_0x3421('0x3d')]=_[_0x3421('0x3c')](_0x2f9a84[_0x3421('0x38')],qs[_0x3421('0x3e')](_0x248f84[_0x3421('0x39')][_0x3421('0x3e')]));_0x176aef[_0x3421('0x3d')]=_0x176aef[_0x3421('0x3d')][_0x3421('0x3f')]?_0x176aef['attributes']:_0x2f9a84[_0x3421('0x38')];if(_0x248f84[_0x3421('0x39')][_0x3421('0x46')]){_0x176aef['include']=[{'all':!![]}];}_0x176aef=_['merge']({},_0x176aef,_0x248f84[_0x3421('0x45')]);return db[_0x3421('0x35')][_0x3421('0x4a')](_0x176aef)['then'](handleEntityNotFound(_0x669cfd,null))[_0x3421('0x2b')](respondWithResult(_0x669cfd,null))[_0x3421('0x4b')](handleError(_0x669cfd,null));};exports[_0x3421('0x2c')]=function(_0x356376,_0x57554a){return db[_0x3421('0x35')][_0x3421('0x4a')]({'where':{'id':_0x356376[_0x3421('0x49')]['id']}})['then'](handleEntityNotFound(_0x57554a,null))['then'](removeEntity(_0x57554a,null))['catch'](handleError(_0x57554a,null));};exports[_0x3421('0x4c')]=function(_0x1021f8,_0x5a9ccf){return db['VoicePrefix'][_0x3421('0x4c')]()[_0x3421('0x2b')](respondWithResult(_0x5a9ccf,null))[_0x3421('0x4b')](handleError(_0x5a9ccf,null));};exports[_0x3421('0x4d')]=function(_0x127835,_0x4987e3){var _0x27d284;return db[_0x3421('0x4e')][_0x3421('0x4f')](function(_0x2f9ce1){return db['VoicePrefix'][_0x3421('0x4d')](_0x127835[_0x3421('0x50')],{'transaction':_0x2f9ce1})[_0x3421('0x2b')](function(_0x48a967){_0x27d284=_0x48a967[_0x3421('0x2d')]({'plain':!![]});return db['VoiceExtension']['find']({'where':{'id':_0x27d284[_0x3421('0x51')]},'raw':!![]})['then'](function(_0x4e33a0){return createVoicePrefixExtensions(_0x27d284,_0x4e33a0,_0x2f9ce1);});});})[_0x3421('0x2b')](function(){var _0x12bd9a=_0x127835['user'][_0x3421('0x2d')]({'plain':!![]});if(!_0x12bd9a)throw new Error(_0x3421('0x52'));if(_0x12bd9a[_0x3421('0x53')]===_0x3421('0x54')){var _0x1c73b9=_0x27d284;return db[_0x3421('0x55')][_0x3421('0x4a')]({'where':{'name':_0x3421('0x2e'),'userProfileId':_0x12bd9a[_0x3421('0x56')]},'raw':!![]})['then'](function(_0x1e4add){if(_0x1e4add&&_0x1e4add[_0x3421('0x57')]===0x0){return db['UserProfileResource'][_0x3421('0x4d')]({'name':_0x1c73b9[_0x3421('0x32')],'resourceId':_0x1c73b9['id'],'type':_0x1e4add[_0x3421('0x32')],'sectionId':_0x1e4add['id']},{})['then'](function(){return _0x27d284;});}else{return _0x27d284;}})[_0x3421('0x4b')](function(_0x27085d){logger[_0x3421('0x31')](_0x3421('0x58'),_0x27085d);throw _0x27085d;});}return _0x27d284;})[_0x3421('0x2b')](respondWithResult(_0x4987e3,null))[_0x3421('0x4b')](handleError(_0x4987e3,null));};function Extension(_0x333b86,_0x3254aa,_0x31fd9b,_0x279b44){this[_0x3421('0x59')]=_0x3421('0x5a');this[_0x3421('0x5b')]=_0x333b86;this[_0x3421('0x5c')]=_0x31fd9b;this[_0x3421('0x5d')]='system';this[_0x3421('0x5e')]=_0x3421('0x5f');this[_0x3421('0x60')]=_0x3254aa;this[_0x3421('0x61')]=_0x279b44;}function createVoicePrefixExtensions(_0x1813c9,_0x25a641,_0x32c9a7){return new BPromise(function(_0x374a6a,_0x5d6488){var _0x379673=new Extension(formatPrefixName(_0x1813c9['prefix']),0x1,_0x3421('0x62'),_0x3421('0x63'));_0x379673[_0x3421('0x64')]=_0x1813c9['id'];return db[_0x3421('0x65')]['create'](_0x379673,{'transaction':_0x32c9a7})[_0x3421('0x2b')](function(_0x21e11b){var _0x9def45=_0x21e11b[_0x3421('0x2d')]({'plain':!![]});var _0x9e649=_[_0x3421('0x34')](addVoicePrefixExtensions(_0x1813c9,_0x25a641),function(_0x5e6c4d){_0x5e6c4d[_0x3421('0x51')]=_0x9def45['id'];_0x5e6c4d[_0x3421('0x64')]=_0x1813c9['id'];return _0x5e6c4d;});return db[_0x3421('0x65')][_0x3421('0x66')](_0x9e649,{'transaction':_0x32c9a7})[_0x3421('0x2b')](function(_0x1ba5e1){if(!_0x1ba5e1){return _0x5d6488(_0x3421('0x67'));}else{return _0x374a6a(_0x1ba5e1);}})[_0x3421('0x4b')](function(_0x4edb4e){return _0x5d6488(_0x4edb4e);});});;});};function addVoicePrefixExtensions(_0xfbdb57,_0x46717b){var _0x200958=[];var _0x40ae83=formatPrefixName(_0xfbdb57[_0x3421('0x68')]);_0x200958['push'](new Extension(_0x40ae83,0x2,'Set',_0x3421('0x69')+_0xfbdb57[_0x3421('0x32')]));if(_0xfbdb57[_0x3421('0x6a')]){_0x200958['push'](new Extension(_0x40ae83,0x3,_0x3421('0x6b'),'PREFIX-CALLERIDALL='+_0xfbdb57[_0x3421('0x6a')]));}else{_0x200958['push'](new Extension(_0x40ae83,0x3,'NoOp','No\x20callerid\x20available'));}_0x200958['push'](new Extension(_0x40ae83,0x4,'goto',_0x46717b[_0x3421('0x59')]+','+_0x3421('0x6c')+(0x8+_0xfbdb57[_0x3421('0x32')][_0x3421('0x3f')])+'}'+','+0x1));return _0x200958;}function formatPrefixName(_0xa05828){var _0x3ccb08='_';for(var _0x231067=0x0;_0x231067<_0xa05828[_0x3421('0x3f')];_0x231067++){if(_0xa05828[_0x3421('0x6d')](_0x231067)=='-'){_0x3ccb08+=_0xa05828[_0x3421('0x6d')](_0x231067);}else{_0x3ccb08+='['+_0xa05828['charAt'](_0x231067)+']';}}_0x3ccb08+='.';return _0x3ccb08;}exports[_0x3421('0x2a')]=function(_0x4dce60,_0x252b28,_0x41e5f8){var _0x40e0a6=_0x4dce60[_0x3421('0x50')];_0x40e0a6[_0x3421('0x68')]=_0x3421('0x6e')+_0x40e0a6[_0x3421('0x32')]+'-';return db[_0x3421('0x4e')][_0x3421('0x4f')](function(_0x5c74a8){return db[_0x3421('0x35')][_0x3421('0x2a')](_0x40e0a6,{'where':{'id':_0x40e0a6['id']},'transaction':_0x5c74a8})[_0x3421('0x2b')](function(){return db['VoiceExtension']['destroy']({'where':{'VoicePrefixId':_0x40e0a6['id']},'transaction':_0x5c74a8})['then'](function(){return db['VoiceExtension'][_0x3421('0x4a')]({'where':{'id':_0x40e0a6['VoiceExtensionId']},'raw':!![]})[_0x3421('0x2b')](function(_0x8aee05){return createVoicePrefixExtensions(_0x40e0a6,_0x8aee05,_0x5c74a8);});});});})[_0x3421('0x2b')](function(){return db[_0x3421('0x35')]['findById'](_0x40e0a6['id']);})[_0x3421('0x2b')](respondWithResult(_0x252b28,null))[_0x3421('0x4b')](handleError(_0x252b28,null));};exports[_0x3421('0x6f')]=function(_0xfb8c60,_0x151eaf,_0x4177cc){return db['VoicePrefix'][_0x3421('0x4a')]({'where':{'id':_0xfb8c60[_0x3421('0x49')]['id']}})[_0x3421('0x2b')](handleEntityNotFound(_0x151eaf,null))[_0x3421('0x2b')](function(_0x37e6d8){if(_0x37e6d8){return _0x37e6d8[_0x3421('0x6f')](_0xfb8c60[_0x3421('0x50')]['ids'],_['omit'](_0xfb8c60[_0x3421('0x50')],[_0x3421('0x70'),'id'])||{})[_0x3421('0x71')](function(_0x5d04c6){for(var _0x2dac40=0x0;_0x2dac40<_0xfb8c60['body'][_0x3421('0x70')]['length'];_0x2dac40+=0x1){socket[_0x3421('0x72')](_0x3421('0x73'),{'UserId':Number(_0xfb8c60[_0x3421('0x50')][_0x3421('0x70')][_0x2dac40]),'VoicePrefixId':Number(_0xfb8c60[_0x3421('0x49')]['id'])});}return _0x5d04c6;});}})[_0x3421('0x2b')](respondWithResult(_0x151eaf,null))[_0x3421('0x4b')](handleError(_0x151eaf,null));};exports[_0x3421('0x74')]=function(_0x3f1df5,_0x37ca80,_0x427013){return db[_0x3421('0x35')]['find']({'where':{'id':_0x3f1df5[_0x3421('0x49')]['id']}})[_0x3421('0x2b')](handleEntityNotFound(_0x37ca80,null))[_0x3421('0x2b')](function(_0x387d09){if(_0x387d09){return _0x387d09[_0x3421('0x74')](_0x3f1df5[_0x3421('0x39')][_0x3421('0x70')])[_0x3421('0x2b')](function(){if(_['isArray'](_0x3f1df5[_0x3421('0x39')]['ids'])){for(var _0x4d92ed=0x0;_0x4d92ed<_0x3f1df5['query'][_0x3421('0x70')][_0x3421('0x3f')];_0x4d92ed+=0x1){socket[_0x3421('0x72')](_0x3421('0x75'),{'UserId':Number(_0x3f1df5['query'][_0x3421('0x70')][_0x4d92ed]),'VoicePrefixId':Number(_0x3f1df5[_0x3421('0x49')]['id'])});}}else{socket[_0x3421('0x72')](_0x3421('0x75'),{'UserId':Number(_0x3f1df5[_0x3421('0x39')][_0x3421('0x70')]),'VoicePrefixId':Number(_0x3f1df5[_0x3421('0x49')]['id'])});}});}})[_0x3421('0x2b')](respondWithStatusCode(_0x37ca80,null))[_0x3421('0x4b')](handleError(_0x37ca80,null));};exports[_0x3421('0x76')]=function(_0x19e35d,_0x414218,_0x1d65ba){var _0x170340={};var _0x456644={};var _0x355f47;var _0x826d7c;return db['VoicePrefix']['findOne']({'where':{'id':_0x19e35d[_0x3421('0x49')]['id']}})['then'](handleEntityNotFound(_0x414218,null))[_0x3421('0x2b')](function(_0x2fd442){if(_0x2fd442){_0x355f47=_0x2fd442;_0x456644['model']=_[_0x3421('0x3a')](db[_0x3421('0x77')][_0x3421('0x36')]);_0x456644[_0x3421('0x39')]=_[_0x3421('0x3a')](_0x19e35d[_0x3421('0x39')]);_0x456644[_0x3421('0x3b')]=_[_0x3421('0x3c')](_0x456644[_0x3421('0x38')],_0x456644[_0x3421('0x39')]);_0x170340[_0x3421('0x3d')]=_[_0x3421('0x3c')](_0x456644[_0x3421('0x38')],qs['fields'](_0x19e35d[_0x3421('0x39')]['fields']));_0x170340[_0x3421('0x3d')]=_0x170340[_0x3421('0x3d')]['length']?_0x170340[_0x3421('0x3d')]:_0x456644['model'];_0x170340['order']=qs[_0x3421('0x40')](_0x19e35d[_0x3421('0x39')][_0x3421('0x40')]);_0x170340['where']=qs[_0x3421('0x3b')](_[_0x3421('0x42')](_0x19e35d[_0x3421('0x39')],_0x456644['filters']));if(_0x19e35d['query'][_0x3421('0x43')]){_0x170340[_0x3421('0x41')]=_[_0x3421('0x44')](_0x170340[_0x3421('0x41')],{'$or':_['map'](_0x170340[_0x3421('0x3d')],function(_0x1fcd4b){var _0x298afc={};_0x298afc[_0x1fcd4b]={'$like':'%'+_0x19e35d[_0x3421('0x39')][_0x3421('0x43')]+'%'};return _0x298afc;})});}_0x170340=_[_0x3421('0x44')]({},_0x170340,_0x19e35d[_0x3421('0x45')]);return _0x355f47[_0x3421('0x76')](_0x170340);}})['then'](function(_0x27967d){if(_0x27967d){_0x826d7c=_0x27967d[_0x3421('0x3f')];if(!_0x19e35d['query']['hasOwnProperty'](_0x3421('0x78'))){_0x170340[_0x3421('0x23')]=qs[_0x3421('0x23')](_0x19e35d[_0x3421('0x39')][_0x3421('0x23')]);_0x170340['offset']=qs['offset'](_0x19e35d[_0x3421('0x39')]['offset']);}return _0x355f47['getAgents'](_0x170340);}})[_0x3421('0x2b')](function(_0x1a5b7c){if(_0x1a5b7c){return _0x1a5b7c?{'count':_0x826d7c,'rows':_0x1a5b7c}:null;}})[_0x3421('0x2b')](respondWithResult(_0x414218,null))[_0x3421('0x4b')](handleError(_0x414218,null));};exports['getTeams']=function(_0x595f0a,_0x335331,_0x5a922d){var _0x5af9c9={};var _0x1fb48f={};var _0x3fc2b6;var _0x4289f3;return db['VoicePrefix']['findOne']({'where':{'id':_0x595f0a['params']['id']}})[_0x3421('0x2b')](handleEntityNotFound(_0x335331,null))[_0x3421('0x2b')](function(_0x176b12){if(_0x176b12){_0x3fc2b6=_0x176b12;_0x1fb48f[_0x3421('0x38')]=_[_0x3421('0x3a')](db[_0x3421('0x79')][_0x3421('0x36')]);_0x1fb48f['query']=_[_0x3421('0x3a')](_0x595f0a[_0x3421('0x39')]);_0x1fb48f[_0x3421('0x3b')]=_[_0x3421('0x3c')](_0x1fb48f[_0x3421('0x38')],_0x1fb48f[_0x3421('0x39')]);_0x5af9c9[_0x3421('0x3d')]=_[_0x3421('0x3c')](_0x1fb48f[_0x3421('0x38')],qs['fields'](_0x595f0a['query'][_0x3421('0x3e')]));_0x5af9c9['attributes']=_0x5af9c9[_0x3421('0x3d')]['length']?_0x5af9c9[_0x3421('0x3d')]:_0x1fb48f[_0x3421('0x38')];_0x5af9c9[_0x3421('0x7a')]=qs[_0x3421('0x40')](_0x595f0a[_0x3421('0x39')]['sort']);_0x5af9c9['where']=qs[_0x3421('0x3b')](_[_0x3421('0x42')](_0x595f0a[_0x3421('0x39')],_0x1fb48f[_0x3421('0x3b')]));if(_0x595f0a['query'][_0x3421('0x43')]){_0x5af9c9[_0x3421('0x41')]=_[_0x3421('0x44')](_0x5af9c9[_0x3421('0x41')],{'$or':_[_0x3421('0x34')](_0x5af9c9[_0x3421('0x3d')],function(_0x31095c){var _0x4c3058={};_0x4c3058[_0x31095c]={'$like':'%'+_0x595f0a[_0x3421('0x39')][_0x3421('0x43')]+'%'};return _0x4c3058;})});}_0x5af9c9=_['merge']({},_0x5af9c9,_0x595f0a[_0x3421('0x45')]);return _0x3fc2b6[_0x3421('0x7b')](_0x5af9c9);}})[_0x3421('0x2b')](function(_0x58b3e4){if(_0x58b3e4){_0x4289f3=_0x58b3e4[_0x3421('0x3f')];if(!_0x595f0a[_0x3421('0x39')]['hasOwnProperty'](_0x3421('0x78'))){_0x5af9c9[_0x3421('0x23')]=qs[_0x3421('0x23')](_0x595f0a[_0x3421('0x39')][_0x3421('0x23')]);_0x5af9c9[_0x3421('0x21')]=qs[_0x3421('0x21')](_0x595f0a[_0x3421('0x39')]['offset']);}return _0x3fc2b6[_0x3421('0x7b')](_0x5af9c9);}})['then'](function(_0x5aaa8a){if(_0x5aaa8a){return _0x5aaa8a?{'count':_0x4289f3,'rows':_0x5aaa8a}:null;}})[_0x3421('0x2b')](respondWithResult(_0x335331,null))[_0x3421('0x4b')](handleError(_0x335331,null));};exports[_0x3421('0x7c')]=function(_0x2c62d7,_0x5cbf21,_0x25c6a0){var _0x44e166=_0x2c62d7[_0x3421('0x50')][_0x3421('0x70')];var _0x13b03f;return db[_0x3421('0x79')][_0x3421('0x47')]({'where':{'id':_0x44e166},'attributes':['id'],'include':[{'model':db[_0x3421('0x77')],'as':_0x3421('0x7d'),'attributes':['id',_0x3421('0x32'),_0x3421('0x7e'),_0x3421('0x7f'),_0x3421('0x80')],'raw':!![]}]})[_0x3421('0x2b')](function(_0x1cde5f){if(_0x1cde5f){_0x13b03f=_0x1cde5f;var _0x1ddc33=_[_0x3421('0x81')](_0x1cde5f,function(_0x34f980){var _0x7d7398=_0x34f980[_0x3421('0x2d')]({'plain':!![]});return _0x7d7398[_0x3421('0x7d')];});return db['VoicePrefix']['find']({'where':{'id':_0x2c62d7[_0x3421('0x49')]['id']}})[_0x3421('0x2b')](function(_0x1a7038){return db[_0x3421('0x4e')]['transaction'](function(_0x18f27a){return _0x1a7038[_0x3421('0x7c')](_0x44e166,{'transaction':_0x18f27a})['then'](function(){return BPromise[_0x3421('0x82')](_0x13b03f,function(_0x2eb3f4){return db[_0x3421('0x83')]['upsert']({'TeamId':_0x2eb3f4['id'],'VoicePrefixId':_0x2c62d7[_0x3421('0x49')]['id']},{'transaction':_0x18f27a});});})['then'](function(){return BPromise[_0x3421('0x82')](_0x1ddc33,function(_0x3f6f2c){return db[_0x3421('0x84')][_0x3421('0x85')]({'where':{'UserId':_0x3f6f2c['id'],'VoicePrefixId':_0x2c62d7[_0x3421('0x49')]['id']},'transaction':_0x18f27a});});})[_0x3421('0x2b')](function(){_0x1ddc33[_0x3421('0x86')](function(_0x50607f){socket[_0x3421('0x72')]('userVoicePrefix:save',{'UserId':_0x50607f['id'],'VoicePrefixId':_0x1a7038['id']});});});});});}})['then'](respondWithStatusCode(_0x5cbf21,null))[_0x3421('0x4b')](handleError(_0x5cbf21,null));};exports[_0x3421('0x87')]=function(_0x4a85d1,_0x1b48e1,_0x4c357e){return db[_0x3421('0x79')][_0x3421('0x47')]({'where':{'id':_0x4a85d1[_0x3421('0x39')][_0x3421('0x70')]},'attributes':['id'],'include':[{'model':db[_0x3421('0x77')],'as':_0x3421('0x7d'),'attributes':['id'],'raw':!![]}]})[_0x3421('0x2b')](handleEntityNotFound(_0x1b48e1,null))[_0x3421('0x2b')](function(_0x2f38ec){var _0x11f294=_[_0x3421('0x34')](_0x2f38ec,'id');var _0x2d7330=[];var _0x5bf9a4=[];var _0x36868f=squel['select']();_0x36868f['field'](_0x3421('0x88'))[_0x3421('0x89')](_0x3421('0x8a'),'tq')[_0x3421('0x8b')]('user_has_teams','ut',_0x3421('0x8c'))[_0x3421('0x41')]('VoicePrefixId\x20=\x20?',_0x4a85d1[_0x3421('0x49')]['id']);for(var _0x4a933a=0x0;_0x4a933a<_0x2f38ec[_0x3421('0x3f')];_0x4a933a+=0x1){let _0x2defcb=_0x2f38ec[_0x4a933a];for(var _0x16735e=0x0;_0x16735e<_0x2defcb['Agents'][_0x3421('0x3f')];_0x16735e+=0x1){let _0x303df7=_0x2defcb[_0x3421('0x7d')][_0x16735e];var _0x1d8163=_0x36868f[_0x3421('0x8d')]();_0x1d8163[_0x3421('0x41')](_0x3421('0x8e'),_0x303df7['id']);_0x5bf9a4[_0x3421('0x8f')](db['sequelize'][_0x3421('0x39')](_0x1d8163[_0x3421('0x90')](),{'type':db[_0x3421('0x4e')][_0x3421('0x91')][_0x3421('0x92')]})[_0x3421('0x2b')](function(_0x3a5346){if(_0x3a5346['length']===0x1){return _0x303df7['id'];}else{var _0x3f64d0=_[_0x3421('0x93')](_['map'](_0x3a5346,'TeamId'),function(_0x4aa261){return _[_0x3421('0x94')](_0x11f294,_0x4aa261);});if(_0x3f64d0){return _0x303df7['id'];}}}));}}return BPromise[_0x3421('0x95')](_0x5bf9a4)['then'](function(_0x256976){_0x2d7330=_(_0x2d7330)[_0x3421('0x96')](_0x256976)[_0x3421('0x97')]()[_0x3421('0x98')]();return db[_0x3421('0x35')][_0x3421('0x4a')]({'where':{'id':_0x4a85d1[_0x3421('0x49')]['id']}})['then'](function(_0x224e26){return db[_0x3421('0x4e')][_0x3421('0x4f')](function(_0x1e2a67){return _0x224e26[_0x3421('0x87')](_0x4a85d1[_0x3421('0x39')]['ids'],{'transaction':_0x1e2a67})[_0x3421('0x2b')](function(){if(!_[_0x3421('0x99')](_0x2d7330)){return _0x224e26['removeAgents'](_0x2d7330,{'transaction':_0x1e2a67});}})[_0x3421('0x2b')](function(){_0x2d7330[_0x3421('0x86')](function(_0x25cc13){socket[_0x3421('0x72')](_0x3421('0x75'),{'UserId':_0x25cc13,'VoicePrefixId':_0x224e26['id']});});});});});});})[_0x3421('0x2b')](respondWithStatusCode(_0x1b48e1,null))[_0x3421('0x4b')](handleError(_0x1b48e1,null));};
\ No newline at end of file