Built motion from commit e1760111.|2.6.18
[motion2.git] / server / api / voicePrefix / voicePrefix.controller.js
index c9ed323..680871a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8e3f=['charAt','update','system-','findById','addAgents','ids','omit','userVoicePrefix:save','isArray','emit','userVoicePrefix:remove','getAgents','findOne','User','getTeams','online','voicePause','interface','flatMap','get','Agents','addTeams','each','UserVoicePrefix','forEach','Team','select','field','tq.TeamId','join','VoicePrefixId\x20=\x20?','clone','ut.UserId\x20=\x20?','QueryTypes','every','includes','all','union','compact','removeTeams','isEmpty','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','util','path','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','./voicePrefix.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','then','destroy','VoicePrefixes','UserProfileResource','error','stack','name','send','index','map','rawAttributes','fieldName','type','query','keys','filters','model','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','VoicePrefix','findAll','catch','includeAll','include','find','params','describe','create','sequelize','transaction','body','VoiceExtension','VoiceExtensionId','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','userProfileId','context','from-sip','exten','app','description','Voice\x20Prefix\x20Extension','priority','prefix','NoOp','VoicePrefixId','bulkCreate','push','Set','CDR(prefix)=','callerIdAll','PREFIX-CALLERIDALL=','No\x20callerid\x20available','goto','${EXTEN:'];(function(_0x112dd7,_0x19749a){var _0x1d0353=function(_0x566923){while(--_0x566923){_0x112dd7['push'](_0x112dd7['shift']());}};_0x1d0353(++_0x19749a);}(_0x8e3f,0xc1));var _0xf8e3=function(_0x122ef9,_0x451d2a){_0x122ef9=_0x122ef9-0x0;var _0x42fba0=_0x8e3f[_0x122ef9];return _0x42fba0;};'use strict';var emlformat=require(_0xf8e3('0x0'));var rimraf=require(_0xf8e3('0x1'));var zipdir=require(_0xf8e3('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf8e3('0x3'));var moment=require(_0xf8e3('0x4'));var BPromise=require(_0xf8e3('0x5'));var Mustache=require('mustache');var util=require(_0xf8e3('0x6'));var path=require(_0xf8e3('0x7'));var sox=require('sox');var csv=require(_0xf8e3('0x8'));var ejs=require(_0xf8e3('0x9'));var fs=require('fs');var fs_extra=require(_0xf8e3('0xa'));var _=require(_0xf8e3('0xb'));var squel=require('squel');var crypto=require(_0xf8e3('0xc'));var jsforce=require(_0xf8e3('0xd'));var deskjs=require(_0xf8e3('0xe'));var toCsv=require(_0xf8e3('0x8'));var querystring=require(_0xf8e3('0xf'));var Papa=require(_0xf8e3('0x10'));var Redis=require(_0xf8e3('0x11'));var authService=require(_0xf8e3('0x12'));var qs=require(_0xf8e3('0x13'));var as=require(_0xf8e3('0x14'));var hardwareService=require(_0xf8e3('0x15'));var logger=require(_0xf8e3('0x16'))('api');var utils=require(_0xf8e3('0x17'));var config=require(_0xf8e3('0x18'));var licenseUtil=require(_0xf8e3('0x19'));var db=require('../../mysqldb')['db'];config[_0xf8e3('0x1a')]=_[_0xf8e3('0x1b')](config[_0xf8e3('0x1a')],{'host':_0xf8e3('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf8e3('0x1a')]));require(_0xf8e3('0x1d'))[_0xf8e3('0x1e')](socket);function respondWithStatusCode(_0x4af736,_0x44f631){_0x44f631=_0x44f631||0xcc;return function(_0x5136c6){if(_0x5136c6){return _0x4af736[_0xf8e3('0x1f')](_0x44f631);}return _0x4af736[_0xf8e3('0x20')](_0x44f631)[_0xf8e3('0x21')]();};}function respondWithResult(_0x570ee3,_0x529c92){_0x529c92=_0x529c92||0xc8;return function(_0x564f43){if(_0x564f43){return _0x570ee3[_0xf8e3('0x20')](_0x529c92)[_0xf8e3('0x22')](_0x564f43);}};}function respondWithFilteredResult(_0x3b01ac,_0x110a78){return function(_0x11d4cc){if(_0x11d4cc){var _0x7a81c3=typeof _0x110a78[_0xf8e3('0x23')]===_0xf8e3('0x24')&&typeof _0x110a78[_0xf8e3('0x25')]==='undefined';var _0x20cc64=_0x11d4cc[_0xf8e3('0x26')];var _0x24e8d6=_0x7a81c3?0x0:_0x110a78[_0xf8e3('0x23')];var _0x3128ad=_0x7a81c3?_0x11d4cc[_0xf8e3('0x26')]:_0x110a78[_0xf8e3('0x23')]+_0x110a78[_0xf8e3('0x25')];var _0x5b99b1;if(_0x3128ad>=_0x20cc64){_0x3128ad=_0x20cc64;_0x5b99b1=0xc8;}else{_0x5b99b1=0xce;}_0x3b01ac[_0xf8e3('0x20')](_0x5b99b1);return _0x3b01ac[_0xf8e3('0x27')](_0xf8e3('0x28'),_0x24e8d6+'-'+_0x3128ad+'/'+_0x20cc64)[_0xf8e3('0x22')](_0x11d4cc);}return null;};}function patchUpdates(_0x4a1e5f){return function(_0x39df34){try{jsonpatch['apply'](_0x39df34,_0x4a1e5f,!![]);}catch(_0x286059){return BPromise[_0xf8e3('0x29')](_0x286059);}return _0x39df34[_0xf8e3('0x2a')]();};}function saveUpdates(_0x2dc856,_0x1f4b68){return function(_0x3ac384){if(_0x3ac384){return _0x3ac384['update'](_0x2dc856)[_0xf8e3('0x2b')](function(_0x2fc674){return _0x2fc674;});}return null;};}function removeEntity(_0x3373ca,_0x417b42){return function(_0x1f1363){if(_0x1f1363){return _0x1f1363[_0xf8e3('0x2c')]()[_0xf8e3('0x2b')](function(){var _0x157a2d=_0x1f1363['get']({'plain':!![]});var _0x356e0a=_0xf8e3('0x2d');return db[_0xf8e3('0x2e')][_0xf8e3('0x2c')]({'where':{'type':_0x356e0a,'resourceId':_0x157a2d['id']}})[_0xf8e3('0x2b')](function(){return _0x1f1363;});})[_0xf8e3('0x2b')](function(){_0x3373ca[_0xf8e3('0x20')](0xcc)[_0xf8e3('0x21')]();});}};}function handleEntityNotFound(_0x4f2ae9,_0x21e1c0){return function(_0x243e28){if(!_0x243e28){_0x4f2ae9[_0xf8e3('0x1f')](0x194);}return _0x243e28;};}function handleError(_0x28b2f2,_0x567153){_0x567153=_0x567153||0x1f4;return function(_0x2e507c){logger[_0xf8e3('0x2f')](_0x2e507c[_0xf8e3('0x30')]);if(_0x2e507c[_0xf8e3('0x31')]){delete _0x2e507c[_0xf8e3('0x31')];}_0x28b2f2[_0xf8e3('0x20')](_0x567153)[_0xf8e3('0x32')](_0x2e507c);};}exports[_0xf8e3('0x33')]=function(_0x50ad3f,_0x2c07bf){var _0x527337={},_0x4acd6c={},_0x5d2dd5={'count':0x0,'rows':[]};var _0x5cc1ed=_[_0xf8e3('0x34')](db['VoicePrefix'][_0xf8e3('0x35')],function(_0x41faaa){return{'name':_0x41faaa[_0xf8e3('0x36')],'type':_0x41faaa[_0xf8e3('0x37')]['key']};});_0x4acd6c['model']=_[_0xf8e3('0x34')](_0x5cc1ed,_0xf8e3('0x31'));_0x4acd6c[_0xf8e3('0x38')]=_[_0xf8e3('0x39')](_0x50ad3f[_0xf8e3('0x38')]);_0x4acd6c[_0xf8e3('0x3a')]=_['intersection'](_0x4acd6c[_0xf8e3('0x3b')],_0x4acd6c['query']);_0x527337['attributes']=_[_0xf8e3('0x3c')](_0x4acd6c[_0xf8e3('0x3b')],qs[_0xf8e3('0x3d')](_0x50ad3f[_0xf8e3('0x38')]['fields']));_0x527337['attributes']=_0x527337[_0xf8e3('0x3e')][_0xf8e3('0x3f')]?_0x527337['attributes']:_0x4acd6c[_0xf8e3('0x3b')];if(!_0x50ad3f[_0xf8e3('0x38')][_0xf8e3('0x40')](_0xf8e3('0x41'))){_0x527337['limit']=qs['limit'](_0x50ad3f['query'][_0xf8e3('0x25')]);_0x527337[_0xf8e3('0x23')]=qs[_0xf8e3('0x23')](_0x50ad3f[_0xf8e3('0x38')]['offset']);}_0x527337[_0xf8e3('0x42')]=qs['sort'](_0x50ad3f[_0xf8e3('0x38')][_0xf8e3('0x43')]);_0x527337[_0xf8e3('0x44')]=qs[_0xf8e3('0x3a')](_[_0xf8e3('0x45')](_0x50ad3f[_0xf8e3('0x38')],_0x4acd6c[_0xf8e3('0x3a')]),_0x5cc1ed);if(_0x50ad3f[_0xf8e3('0x38')][_0xf8e3('0x46')]){_0x527337['where']=_[_0xf8e3('0x47')](_0x527337['where'],{'$or':_[_0xf8e3('0x34')](_0x5cc1ed,function(_0x1e8917){if(_0x1e8917[_0xf8e3('0x37')]!==_0xf8e3('0x48')){var _0x64bfc6={};_0x64bfc6[_0x1e8917[_0xf8e3('0x31')]]={'$like':'%'+_0x50ad3f[_0xf8e3('0x38')][_0xf8e3('0x46')]+'%'};return _0x64bfc6;}})});}_0x527337=_['merge']({},_0x527337,_0x50ad3f[_0xf8e3('0x49')]);var _0x108b81={'where':_0x527337[_0xf8e3('0x44')]};return db[_0xf8e3('0x4a')][_0xf8e3('0x26')](_0x108b81)[_0xf8e3('0x2b')](function(_0x792190){_0x5d2dd5[_0xf8e3('0x26')]=_0x792190;if(_0x50ad3f['query']['includeAll']){_0x527337['include']=[{'all':!![]}];}return db[_0xf8e3('0x4a')][_0xf8e3('0x4b')](_0x527337);})['then'](function(_0x181908){_0x5d2dd5['rows']=_0x181908;return _0x5d2dd5;})[_0xf8e3('0x2b')](respondWithFilteredResult(_0x2c07bf,_0x527337))[_0xf8e3('0x4c')](handleError(_0x2c07bf,null));};exports['show']=function(_0x1fb64d,_0x4b0791){var _0x679519={'raw':![],'where':{'id':_0x1fb64d['params']['id']}},_0x6875a6={};_0x6875a6[_0xf8e3('0x3b')]=_[_0xf8e3('0x39')](db[_0xf8e3('0x4a')][_0xf8e3('0x35')]);_0x6875a6['query']=_['keys'](_0x1fb64d['query']);_0x6875a6[_0xf8e3('0x3a')]=_[_0xf8e3('0x3c')](_0x6875a6[_0xf8e3('0x3b')],_0x6875a6['query']);_0x679519[_0xf8e3('0x3e')]=_['intersection'](_0x6875a6[_0xf8e3('0x3b')],qs[_0xf8e3('0x3d')](_0x1fb64d['query']['fields']));_0x679519[_0xf8e3('0x3e')]=_0x679519[_0xf8e3('0x3e')][_0xf8e3('0x3f')]?_0x679519[_0xf8e3('0x3e')]:_0x6875a6[_0xf8e3('0x3b')];if(_0x1fb64d[_0xf8e3('0x38')][_0xf8e3('0x4d')]){_0x679519[_0xf8e3('0x4e')]=[{'all':!![]}];}_0x679519=_[_0xf8e3('0x47')]({},_0x679519,_0x1fb64d[_0xf8e3('0x49')]);return db[_0xf8e3('0x4a')]['find'](_0x679519)[_0xf8e3('0x2b')](handleEntityNotFound(_0x4b0791,null))[_0xf8e3('0x2b')](respondWithResult(_0x4b0791,null))[_0xf8e3('0x4c')](handleError(_0x4b0791,null));};exports[_0xf8e3('0x2c')]=function(_0x385a8f,_0x3256e6){return db['VoicePrefix'][_0xf8e3('0x4f')]({'where':{'id':_0x385a8f[_0xf8e3('0x50')]['id']}})[_0xf8e3('0x2b')](handleEntityNotFound(_0x3256e6,null))[_0xf8e3('0x2b')](removeEntity(_0x3256e6,null))[_0xf8e3('0x4c')](handleError(_0x3256e6,null));};exports[_0xf8e3('0x51')]=function(_0x5855f2,_0x260f67){return db[_0xf8e3('0x4a')][_0xf8e3('0x51')]()[_0xf8e3('0x2b')](respondWithResult(_0x260f67,null))[_0xf8e3('0x4c')](handleError(_0x260f67,null));};exports[_0xf8e3('0x52')]=function(_0x5990fc,_0x394e45){var _0x1f425f;return db[_0xf8e3('0x53')][_0xf8e3('0x54')](function(_0x452b00){return db['VoicePrefix'][_0xf8e3('0x52')](_0x5990fc[_0xf8e3('0x55')],{'transaction':_0x452b00})[_0xf8e3('0x2b')](function(_0x53c897){_0x1f425f=_0x53c897['get']({'plain':!![]});return db[_0xf8e3('0x56')][_0xf8e3('0x4f')]({'where':{'id':_0x1f425f[_0xf8e3('0x57')]},'raw':!![]})[_0xf8e3('0x2b')](function(_0x58ad2f){return createVoicePrefixExtensions(_0x1f425f,_0x58ad2f,_0x452b00);});});})[_0xf8e3('0x2b')](function(){var _0x16bddb=_0x5990fc['user']['get']({'plain':!![]});if(!_0x16bddb)throw new Error(_0xf8e3('0x58'));if(_0x16bddb[_0xf8e3('0x59')]===_0xf8e3('0x5a')){var _0x505477=_0x1f425f;return db['UserProfileSection']['find']({'where':{'name':_0xf8e3('0x2d'),'userProfileId':_0x16bddb[_0xf8e3('0x5b')]},'raw':!![]})['then'](function(_0x4937fc){if(_0x4937fc&&_0x4937fc['autoAssociation']===0x0){return db[_0xf8e3('0x2e')][_0xf8e3('0x52')]({'name':_0x505477['name'],'resourceId':_0x505477['id'],'type':_0x4937fc[_0xf8e3('0x31')],'sectionId':_0x4937fc['id']},{})[_0xf8e3('0x2b')](function(){return _0x1f425f;});}else{return _0x1f425f;}})[_0xf8e3('0x4c')](function(_0x560f42){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x560f42);throw _0x560f42;});}return _0x1f425f;})['then'](respondWithResult(_0x394e45,null))[_0xf8e3('0x4c')](handleError(_0x394e45,null));};function Extension(_0x3b120a,_0x3ef144,_0x447efe,_0x442349){this[_0xf8e3('0x5c')]=_0xf8e3('0x5d');this[_0xf8e3('0x5e')]=_0x3b120a;this[_0xf8e3('0x5f')]=_0x447efe;this['type']='system';this[_0xf8e3('0x60')]=_0xf8e3('0x61');this[_0xf8e3('0x62')]=_0x3ef144;this['appdata']=_0x442349;}function createVoicePrefixExtensions(_0x234b06,_0x131c0b,_0x4879c7){return new BPromise(function(_0x48bb3f,_0x256cd5){var _0x4763eb=new Extension(formatPrefixName(_0x234b06[_0xf8e3('0x63')]),0x1,_0xf8e3('0x64'),'Voice\x20Prefix');_0x4763eb['VoicePrefixId']=_0x234b06['id'];return db[_0xf8e3('0x56')][_0xf8e3('0x52')](_0x4763eb,{'transaction':_0x4879c7})[_0xf8e3('0x2b')](function(_0x392d99){var _0x4f1ddb=_0x392d99['get']({'plain':!![]});var _0x324ad5=_[_0xf8e3('0x34')](addVoicePrefixExtensions(_0x234b06,_0x131c0b),function(_0x56a07e){_0x56a07e[_0xf8e3('0x57')]=_0x4f1ddb['id'];_0x56a07e[_0xf8e3('0x65')]=_0x234b06['id'];return _0x56a07e;});return db[_0xf8e3('0x56')][_0xf8e3('0x66')](_0x324ad5,{'transaction':_0x4879c7})['then'](function(_0x11ebb2){if(!_0x11ebb2){return _0x256cd5('Extensions\x20creation\x20failed');}else{return _0x48bb3f(_0x11ebb2);}})[_0xf8e3('0x4c')](function(_0x1cad38){return _0x256cd5(_0x1cad38);});});;});};function addVoicePrefixExtensions(_0x5cbdc6,_0x2ec4f6){var _0x31568b=[];var _0x55418c=formatPrefixName(_0x5cbdc6[_0xf8e3('0x63')]);_0x31568b[_0xf8e3('0x67')](new Extension(_0x55418c,0x2,_0xf8e3('0x68'),_0xf8e3('0x69')+_0x5cbdc6['name']));if(_0x5cbdc6[_0xf8e3('0x6a')]){_0x31568b[_0xf8e3('0x67')](new Extension(_0x55418c,0x3,_0xf8e3('0x68'),_0xf8e3('0x6b')+_0x5cbdc6[_0xf8e3('0x6a')]));}else{_0x31568b[_0xf8e3('0x67')](new Extension(_0x55418c,0x3,_0xf8e3('0x64'),_0xf8e3('0x6c')));}_0x31568b[_0xf8e3('0x67')](new Extension(_0x55418c,0x4,_0xf8e3('0x6d'),_0x2ec4f6[_0xf8e3('0x5c')]+','+_0xf8e3('0x6e')+(0x8+_0x5cbdc6['name']['length'])+'}'+','+0x1));return _0x31568b;}function formatPrefixName(_0x2f6cf4){var _0x32eaab='_';for(var _0x5ccdb2=0x0;_0x5ccdb2<_0x2f6cf4[_0xf8e3('0x3f')];_0x5ccdb2++){if(_0x2f6cf4[_0xf8e3('0x6f')](_0x5ccdb2)=='-'){_0x32eaab+=_0x2f6cf4[_0xf8e3('0x6f')](_0x5ccdb2);}else{_0x32eaab+='['+_0x2f6cf4[_0xf8e3('0x6f')](_0x5ccdb2)+']';}}_0x32eaab+='.';return _0x32eaab;}exports[_0xf8e3('0x70')]=function(_0x5804eb,_0x3e501c,_0x1dcd23){var _0x52e996=_0x5804eb[_0xf8e3('0x55')];_0x52e996['prefix']=_0xf8e3('0x71')+_0x52e996['name']+'-';return db[_0xf8e3('0x53')][_0xf8e3('0x54')](function(_0x45361d){return db[_0xf8e3('0x4a')][_0xf8e3('0x70')](_0x52e996,{'where':{'id':_0x52e996['id']},'transaction':_0x45361d})['then'](function(){return db[_0xf8e3('0x56')][_0xf8e3('0x2c')]({'where':{'VoicePrefixId':_0x52e996['id']},'transaction':_0x45361d})[_0xf8e3('0x2b')](function(){return db[_0xf8e3('0x56')][_0xf8e3('0x4f')]({'where':{'id':_0x52e996[_0xf8e3('0x57')]},'raw':!![]})[_0xf8e3('0x2b')](function(_0x2ccd34){return createVoicePrefixExtensions(_0x52e996,_0x2ccd34,_0x45361d);});});});})[_0xf8e3('0x2b')](function(){return db[_0xf8e3('0x4a')][_0xf8e3('0x72')](_0x52e996['id']);})[_0xf8e3('0x2b')](respondWithResult(_0x3e501c,null))['catch'](handleError(_0x3e501c,null));};exports[_0xf8e3('0x73')]=function(_0x280f06,_0x3dc049,_0x4b69db){return db[_0xf8e3('0x4a')][_0xf8e3('0x4f')]({'where':{'id':_0x280f06[_0xf8e3('0x50')]['id']}})[_0xf8e3('0x2b')](handleEntityNotFound(_0x3dc049,null))[_0xf8e3('0x2b')](function(_0x40174a){if(_0x40174a){return _0x40174a[_0xf8e3('0x73')](_0x280f06[_0xf8e3('0x55')][_0xf8e3('0x74')],_[_0xf8e3('0x75')](_0x280f06[_0xf8e3('0x55')],[_0xf8e3('0x74'),'id'])||{})['spread'](function(_0x118cc6){for(var _0xf7cb3a=0x0;_0xf7cb3a<_0x280f06[_0xf8e3('0x55')][_0xf8e3('0x74')]['length'];_0xf7cb3a+=0x1){socket['emit'](_0xf8e3('0x76'),{'UserId':Number(_0x280f06[_0xf8e3('0x55')]['ids'][_0xf7cb3a]),'VoicePrefixId':Number(_0x280f06['params']['id'])});}return _0x118cc6;});}})[_0xf8e3('0x2b')](respondWithResult(_0x3dc049,null))[_0xf8e3('0x4c')](handleError(_0x3dc049,null));};exports['removeAgents']=function(_0x2a2c6,_0xca5962,_0x16e69a){return db[_0xf8e3('0x4a')][_0xf8e3('0x4f')]({'where':{'id':_0x2a2c6['params']['id']}})[_0xf8e3('0x2b')](handleEntityNotFound(_0xca5962,null))[_0xf8e3('0x2b')](function(_0x54db4e){if(_0x54db4e){return _0x54db4e['removeAgents'](_0x2a2c6[_0xf8e3('0x38')][_0xf8e3('0x74')])[_0xf8e3('0x2b')](function(){if(_[_0xf8e3('0x77')](_0x2a2c6[_0xf8e3('0x38')][_0xf8e3('0x74')])){for(var _0x3823b9=0x0;_0x3823b9<_0x2a2c6[_0xf8e3('0x38')]['ids'][_0xf8e3('0x3f')];_0x3823b9+=0x1){socket[_0xf8e3('0x78')](_0xf8e3('0x79'),{'UserId':Number(_0x2a2c6[_0xf8e3('0x38')][_0xf8e3('0x74')][_0x3823b9]),'VoicePrefixId':Number(_0x2a2c6[_0xf8e3('0x50')]['id'])});}}else{socket['emit'](_0xf8e3('0x79'),{'UserId':Number(_0x2a2c6[_0xf8e3('0x38')][_0xf8e3('0x74')]),'VoicePrefixId':Number(_0x2a2c6['params']['id'])});}});}})['then'](respondWithStatusCode(_0xca5962,null))[_0xf8e3('0x4c')](handleError(_0xca5962,null));};exports[_0xf8e3('0x7a')]=function(_0x25805c,_0xc01ac,_0x4659ed){var _0x5b8840={};var _0x25bf6c={};var _0x1f5a80;var _0x1bfe33;return db[_0xf8e3('0x4a')][_0xf8e3('0x7b')]({'where':{'id':_0x25805c[_0xf8e3('0x50')]['id']}})[_0xf8e3('0x2b')](handleEntityNotFound(_0xc01ac,null))[_0xf8e3('0x2b')](function(_0x40b66c){if(_0x40b66c){_0x1f5a80=_0x40b66c;_0x25bf6c['model']=_[_0xf8e3('0x39')](db[_0xf8e3('0x7c')][_0xf8e3('0x35')]);_0x25bf6c[_0xf8e3('0x38')]=_[_0xf8e3('0x39')](_0x25805c[_0xf8e3('0x38')]);_0x25bf6c[_0xf8e3('0x3a')]=_['intersection'](_0x25bf6c['model'],_0x25bf6c[_0xf8e3('0x38')]);_0x5b8840[_0xf8e3('0x3e')]=_['intersection'](_0x25bf6c[_0xf8e3('0x3b')],qs[_0xf8e3('0x3d')](_0x25805c[_0xf8e3('0x38')][_0xf8e3('0x3d')]));_0x5b8840[_0xf8e3('0x3e')]=_0x5b8840[_0xf8e3('0x3e')][_0xf8e3('0x3f')]?_0x5b8840['attributes']:_0x25bf6c[_0xf8e3('0x3b')];_0x5b8840[_0xf8e3('0x42')]=qs[_0xf8e3('0x43')](_0x25805c[_0xf8e3('0x38')][_0xf8e3('0x43')]);_0x5b8840[_0xf8e3('0x44')]=qs[_0xf8e3('0x3a')](_[_0xf8e3('0x45')](_0x25805c[_0xf8e3('0x38')],_0x25bf6c[_0xf8e3('0x3a')]));if(_0x25805c[_0xf8e3('0x38')]['filter']){_0x5b8840['where']=_[_0xf8e3('0x47')](_0x5b8840['where'],{'$or':_[_0xf8e3('0x34')](_0x5b8840['attributes'],function(_0x1a3843){var _0x1b2249={};_0x1b2249[_0x1a3843]={'$like':'%'+_0x25805c[_0xf8e3('0x38')]['filter']+'%'};return _0x1b2249;})});}_0x5b8840=_[_0xf8e3('0x47')]({},_0x5b8840,_0x25805c[_0xf8e3('0x49')]);return _0x1f5a80[_0xf8e3('0x7a')](_0x5b8840);}})[_0xf8e3('0x2b')](function(_0x3619cd){if(_0x3619cd){_0x1bfe33=_0x3619cd['length'];if(!_0x25805c[_0xf8e3('0x38')]['hasOwnProperty'](_0xf8e3('0x41'))){_0x5b8840[_0xf8e3('0x25')]=qs[_0xf8e3('0x25')](_0x25805c[_0xf8e3('0x38')][_0xf8e3('0x25')]);_0x5b8840[_0xf8e3('0x23')]=qs[_0xf8e3('0x23')](_0x25805c['query'][_0xf8e3('0x23')]);}return _0x1f5a80[_0xf8e3('0x7a')](_0x5b8840);}})[_0xf8e3('0x2b')](function(_0x1a9ba6){if(_0x1a9ba6){return _0x1a9ba6?{'count':_0x1bfe33,'rows':_0x1a9ba6}:null;}})['then'](respondWithResult(_0xc01ac,null))[_0xf8e3('0x4c')](handleError(_0xc01ac,null));};exports[_0xf8e3('0x7d')]=function(_0x3f7c0e,_0x2da8fb,_0x22fa2f){var _0x18fbd2={};var _0x477589={};var _0x1bb12c;var _0x4a5ad8;return db['VoicePrefix'][_0xf8e3('0x7b')]({'where':{'id':_0x3f7c0e[_0xf8e3('0x50')]['id']}})[_0xf8e3('0x2b')](handleEntityNotFound(_0x2da8fb,null))[_0xf8e3('0x2b')](function(_0x131625){if(_0x131625){_0x1bb12c=_0x131625;_0x477589[_0xf8e3('0x3b')]=_[_0xf8e3('0x39')](db['Team'][_0xf8e3('0x35')]);_0x477589['query']=_[_0xf8e3('0x39')](_0x3f7c0e[_0xf8e3('0x38')]);_0x477589[_0xf8e3('0x3a')]=_[_0xf8e3('0x3c')](_0x477589['model'],_0x477589[_0xf8e3('0x38')]);_0x18fbd2['attributes']=_['intersection'](_0x477589[_0xf8e3('0x3b')],qs[_0xf8e3('0x3d')](_0x3f7c0e[_0xf8e3('0x38')][_0xf8e3('0x3d')]));_0x18fbd2['attributes']=_0x18fbd2['attributes'][_0xf8e3('0x3f')]?_0x18fbd2[_0xf8e3('0x3e')]:_0x477589['model'];_0x18fbd2['order']=qs[_0xf8e3('0x43')](_0x3f7c0e[_0xf8e3('0x38')]['sort']);_0x18fbd2[_0xf8e3('0x44')]=qs[_0xf8e3('0x3a')](_[_0xf8e3('0x45')](_0x3f7c0e[_0xf8e3('0x38')],_0x477589[_0xf8e3('0x3a')]));if(_0x3f7c0e[_0xf8e3('0x38')][_0xf8e3('0x46')]){_0x18fbd2['where']=_[_0xf8e3('0x47')](_0x18fbd2[_0xf8e3('0x44')],{'$or':_['map'](_0x18fbd2[_0xf8e3('0x3e')],function(_0x4a8866){var _0x1ca81d={};_0x1ca81d[_0x4a8866]={'$like':'%'+_0x3f7c0e[_0xf8e3('0x38')][_0xf8e3('0x46')]+'%'};return _0x1ca81d;})});}_0x18fbd2=_['merge']({},_0x18fbd2,_0x3f7c0e[_0xf8e3('0x49')]);return _0x1bb12c['getTeams'](_0x18fbd2);}})[_0xf8e3('0x2b')](function(_0x41ca1b){if(_0x41ca1b){_0x4a5ad8=_0x41ca1b[_0xf8e3('0x3f')];if(!_0x3f7c0e[_0xf8e3('0x38')]['hasOwnProperty']('nolimit')){_0x18fbd2[_0xf8e3('0x25')]=qs[_0xf8e3('0x25')](_0x3f7c0e[_0xf8e3('0x38')][_0xf8e3('0x25')]);_0x18fbd2[_0xf8e3('0x23')]=qs[_0xf8e3('0x23')](_0x3f7c0e['query'][_0xf8e3('0x23')]);}return _0x1bb12c[_0xf8e3('0x7d')](_0x18fbd2);}})[_0xf8e3('0x2b')](function(_0x348e59){if(_0x348e59){return _0x348e59?{'count':_0x4a5ad8,'rows':_0x348e59}:null;}})['then'](respondWithResult(_0x2da8fb,null))[_0xf8e3('0x4c')](handleError(_0x2da8fb,null));};exports['addTeams']=function(_0x3b51c7,_0xf88bb2,_0x4b27e3){var _0x108168=_0x3b51c7['body'][_0xf8e3('0x74')];var _0x3fba66;return db['Team'][_0xf8e3('0x4b')]({'where':{'id':_0x108168},'attributes':['id'],'include':[{'model':db[_0xf8e3('0x7c')],'as':'Agents','attributes':['id',_0xf8e3('0x31'),_0xf8e3('0x7e'),_0xf8e3('0x7f'),_0xf8e3('0x80')],'raw':!![]}]})[_0xf8e3('0x2b')](function(_0x3b79e1){if(_0x3b79e1){_0x3fba66=_0x3b79e1;var _0x13f467=_[_0xf8e3('0x81')](_0x3b79e1,function(_0x29c04b){var _0x271ed0=_0x29c04b[_0xf8e3('0x82')]({'plain':!![]});return _0x271ed0[_0xf8e3('0x83')];});return db['VoicePrefix'][_0xf8e3('0x4f')]({'where':{'id':_0x3b51c7[_0xf8e3('0x50')]['id']}})[_0xf8e3('0x2b')](function(_0x48230e){return db[_0xf8e3('0x53')][_0xf8e3('0x54')](function(_0x7e83fd){return _0x48230e[_0xf8e3('0x84')](_0x108168,{'transaction':_0x7e83fd})[_0xf8e3('0x2b')](function(){return BPromise[_0xf8e3('0x85')](_0x3fba66,function(_0x6d4c09){return db['TeamVoicePrefix']['upsert']({'TeamId':_0x6d4c09['id'],'VoicePrefixId':_0x3b51c7[_0xf8e3('0x50')]['id']},{'transaction':_0x7e83fd});});})[_0xf8e3('0x2b')](function(){return BPromise['each'](_0x13f467,function(_0x1a85cf){return db[_0xf8e3('0x86')]['findOrCreate']({'where':{'UserId':_0x1a85cf['id'],'VoicePrefixId':_0x3b51c7[_0xf8e3('0x50')]['id']},'transaction':_0x7e83fd});});})[_0xf8e3('0x2b')](function(){_0x13f467[_0xf8e3('0x87')](function(_0x27d0b6){socket[_0xf8e3('0x78')]('userVoicePrefix:save',{'UserId':_0x27d0b6['id'],'VoicePrefixId':_0x48230e['id']});});});});});}})[_0xf8e3('0x2b')](respondWithStatusCode(_0xf88bb2,null))[_0xf8e3('0x4c')](handleError(_0xf88bb2,null));};exports['removeTeams']=function(_0x4f02bb,_0x237eb6,_0xd9e796){return db[_0xf8e3('0x88')][_0xf8e3('0x4b')]({'where':{'id':_0x4f02bb[_0xf8e3('0x38')][_0xf8e3('0x74')]},'attributes':['id'],'include':[{'model':db['User'],'as':_0xf8e3('0x83'),'attributes':['id'],'raw':!![]}]})[_0xf8e3('0x2b')](handleEntityNotFound(_0x237eb6,null))['then'](function(_0x5ae078){var _0x512d8d=_[_0xf8e3('0x34')](_0x5ae078,'id');var _0x186e42=[];var _0x417af2=[];var _0x29f5d0=squel[_0xf8e3('0x89')]();_0x29f5d0[_0xf8e3('0x8a')](_0xf8e3('0x8b'))['from']('team_has_voice_prefixes','tq')[_0xf8e3('0x8c')]('user_has_teams','ut','ut.TeamId\x20=\x20tq.TeamId')[_0xf8e3('0x44')](_0xf8e3('0x8d'),_0x4f02bb['params']['id']);for(var _0x1cff32=0x0;_0x1cff32<_0x5ae078[_0xf8e3('0x3f')];_0x1cff32+=0x1){let _0x876d0c=_0x5ae078[_0x1cff32];for(var _0x2c4060=0x0;_0x2c4060<_0x876d0c[_0xf8e3('0x83')][_0xf8e3('0x3f')];_0x2c4060+=0x1){let _0x1b8e99=_0x876d0c[_0xf8e3('0x83')][_0x2c4060];var _0x107896=_0x29f5d0[_0xf8e3('0x8e')]();_0x107896[_0xf8e3('0x44')](_0xf8e3('0x8f'),_0x1b8e99['id']);_0x417af2[_0xf8e3('0x67')](db[_0xf8e3('0x53')][_0xf8e3('0x38')](_0x107896['toString'](),{'type':db[_0xf8e3('0x53')][_0xf8e3('0x90')]['SELECT']})[_0xf8e3('0x2b')](function(_0x4e8329){if(_0x4e8329['length']===0x1){return _0x1b8e99['id'];}else{var _0x5a66ee=_[_0xf8e3('0x91')](_[_0xf8e3('0x34')](_0x4e8329,'TeamId'),function(_0x207393){return _[_0xf8e3('0x92')](_0x512d8d,_0x207393);});if(_0x5a66ee){return _0x1b8e99['id'];}}}));}}return BPromise[_0xf8e3('0x93')](_0x417af2)['then'](function(_0x3a39a8){_0x186e42=_(_0x186e42)[_0xf8e3('0x94')](_0x3a39a8)[_0xf8e3('0x95')]()['value']();return db[_0xf8e3('0x4a')][_0xf8e3('0x4f')]({'where':{'id':_0x4f02bb[_0xf8e3('0x50')]['id']}})['then'](function(_0x42d800){return db[_0xf8e3('0x53')][_0xf8e3('0x54')](function(_0x13782d){return _0x42d800[_0xf8e3('0x96')](_0x4f02bb[_0xf8e3('0x38')]['ids'],{'transaction':_0x13782d})[_0xf8e3('0x2b')](function(){if(!_[_0xf8e3('0x97')](_0x186e42)){return _0x42d800['removeAgents'](_0x186e42,{'transaction':_0x13782d});}})[_0xf8e3('0x2b')](function(){_0x186e42[_0xf8e3('0x87')](function(_0xcf534f){socket[_0xf8e3('0x78')]('userVoicePrefix:remove',{'UserId':_0xcf534f,'VoicePrefixId':_0x42d800['id']});});});});});});})[_0xf8e3('0x2b')](respondWithStatusCode(_0x237eb6,null))['catch'](handleError(_0x237eb6,null));};
\ No newline at end of file
+var _0xbaf0=['querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','redis','defaults','localhost','register','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','update','then','destroy','get','VoicePrefixes','UserProfileResource','end','error','stack','name','send','index','map','VoicePrefix','rawAttributes','fieldName','type','model','query','keys','intersection','attributes','fields','hasOwnProperty','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','length','find','catch','describe','create','sequelize','VoiceExtensionId','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','context','from-sip','exten','app','description','Voice\x20Prefix\x20Extension','priority','appdata','NoOp','VoiceExtension','VoicePrefixId','bulkCreate','push','Set','CDR(prefix)=','callerIdAll','PREFIX-CALLERIDALL=','No\x20callerid\x20available','${EXTEN:','charAt','body','prefix','system-','ids','omit','spread','userVoicePrefix:save','params','removeAgents','emit','userVoicePrefix:remove','getAgents','findOne','User','nolimit','getTeams','Team','addTeams','Agents','online','voicePause','interface','flatMap','transaction','each','TeamVoicePrefix','upsert','UserVoicePrefix','findOrCreate','forEach','removeTeams','select','field','tq.TeamId','from','team_has_voice_prefixes','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','clone','QueryTypes','SELECT','TeamId','includes','compact','isEmpty','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js'];(function(_0x3d83cd,_0x34b54a){var _0x51e93c=function(_0x403b46){while(--_0x403b46){_0x3d83cd['push'](_0x3d83cd['shift']());}};_0x51e93c(++_0x34b54a);}(_0xbaf0,0x12a));var _0x0baf=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0xbaf0[_0x14add3];return _0x4a174f;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x0baf('0x0'));var zipdir=require(_0x0baf('0x1'));var jsonpatch=require(_0x0baf('0x2'));var rp=require(_0x0baf('0x3'));var moment=require(_0x0baf('0x4'));var BPromise=require(_0x0baf('0x5'));var Mustache=require('mustache');var util=require(_0x0baf('0x6'));var path=require(_0x0baf('0x7'));var sox=require(_0x0baf('0x8'));var csv=require(_0x0baf('0x9'));var ejs=require(_0x0baf('0xa'));var fs=require('fs');var fs_extra=require(_0x0baf('0xb'));var _=require(_0x0baf('0xc'));var squel=require(_0x0baf('0xd'));var crypto=require(_0x0baf('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x0baf('0xf'));var toCsv=require('to-csv');var querystring=require(_0x0baf('0x10'));var Papa=require(_0x0baf('0x11'));var Redis=require(_0x0baf('0x12'));var authService=require(_0x0baf('0x13'));var qs=require(_0x0baf('0x14'));var as=require(_0x0baf('0x15'));var hardwareService=require(_0x0baf('0x16'));var logger=require(_0x0baf('0x17'))(_0x0baf('0x18'));var utils=require(_0x0baf('0x19'));var config=require(_0x0baf('0x1a'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0x0baf('0x1b')]=_[_0x0baf('0x1c')](config[_0x0baf('0x1b')],{'host':_0x0baf('0x1d'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x0baf('0x1b')]));require('./voicePrefix.socket')[_0x0baf('0x1e')](socket);function respondWithStatusCode(_0x1f50c3,_0x7fbf67){_0x7fbf67=_0x7fbf67||0xcc;return function(_0x2bc381){if(_0x2bc381){return _0x1f50c3[_0x0baf('0x1f')](_0x7fbf67);}return _0x1f50c3[_0x0baf('0x20')](_0x7fbf67)['end']();};}function respondWithResult(_0x4cd79d,_0x2312c7){_0x2312c7=_0x2312c7||0xc8;return function(_0x38395b){if(_0x38395b){return _0x4cd79d[_0x0baf('0x20')](_0x2312c7)[_0x0baf('0x21')](_0x38395b);}};}function respondWithFilteredResult(_0x2cf7da,_0x288a98){return function(_0x53c338){if(_0x53c338){var _0x63c820=typeof _0x288a98[_0x0baf('0x22')]===_0x0baf('0x23')&&typeof _0x288a98[_0x0baf('0x24')]===_0x0baf('0x23');var _0x42b7f2=_0x53c338['count'];var _0x5cff5d=_0x63c820?0x0:_0x288a98[_0x0baf('0x22')];var _0x154f48=_0x63c820?_0x53c338[_0x0baf('0x25')]:_0x288a98[_0x0baf('0x22')]+_0x288a98[_0x0baf('0x24')];var _0x3e3e20;if(_0x154f48>=_0x42b7f2){_0x154f48=_0x42b7f2;_0x3e3e20=0xc8;}else{_0x3e3e20=0xce;}_0x2cf7da[_0x0baf('0x20')](_0x3e3e20);return _0x2cf7da[_0x0baf('0x26')](_0x0baf('0x27'),_0x5cff5d+'-'+_0x154f48+'/'+_0x42b7f2)[_0x0baf('0x21')](_0x53c338);}return null;};}function patchUpdates(_0x54f2fa){return function(_0x334bd6){try{jsonpatch['apply'](_0x334bd6,_0x54f2fa,!![]);}catch(_0xf6c158){return BPromise['reject'](_0xf6c158);}return _0x334bd6['save']();};}function saveUpdates(_0x2ef0aa,_0x48a0e9){return function(_0x4be1b9){if(_0x4be1b9){return _0x4be1b9[_0x0baf('0x28')](_0x2ef0aa)[_0x0baf('0x29')](function(_0x34e264){return _0x34e264;});}return null;};}function removeEntity(_0x19d9fd,_0x3a1ba1){return function(_0x56b299){if(_0x56b299){return _0x56b299[_0x0baf('0x2a')]()[_0x0baf('0x29')](function(){var _0x1ca35a=_0x56b299[_0x0baf('0x2b')]({'plain':!![]});var _0x3843b8=_0x0baf('0x2c');return db[_0x0baf('0x2d')]['destroy']({'where':{'type':_0x3843b8,'resourceId':_0x1ca35a['id']}})[_0x0baf('0x29')](function(){return _0x56b299;});})[_0x0baf('0x29')](function(){_0x19d9fd[_0x0baf('0x20')](0xcc)[_0x0baf('0x2e')]();});}};}function handleEntityNotFound(_0x55c715,_0x29dbdf){return function(_0x34a58a){if(!_0x34a58a){_0x55c715['sendStatus'](0x194);}return _0x34a58a;};}function handleError(_0x44ec31,_0x32e4fb){_0x32e4fb=_0x32e4fb||0x1f4;return function(_0x478ce8){logger[_0x0baf('0x2f')](_0x478ce8[_0x0baf('0x30')]);if(_0x478ce8[_0x0baf('0x31')]){delete _0x478ce8[_0x0baf('0x31')];}_0x44ec31['status'](_0x32e4fb)[_0x0baf('0x32')](_0x478ce8);};}exports[_0x0baf('0x33')]=function(_0x37be4e,_0x3ed995){var _0x24ecee={},_0x275ea1={},_0x2fc983={'count':0x0,'rows':[]};var _0x2f0a45=_[_0x0baf('0x34')](db[_0x0baf('0x35')][_0x0baf('0x36')],function(_0x165d14){return{'name':_0x165d14[_0x0baf('0x37')],'type':_0x165d14[_0x0baf('0x38')]['key']};});_0x275ea1[_0x0baf('0x39')]=_['map'](_0x2f0a45,_0x0baf('0x31'));_0x275ea1[_0x0baf('0x3a')]=_[_0x0baf('0x3b')](_0x37be4e[_0x0baf('0x3a')]);_0x275ea1['filters']=_[_0x0baf('0x3c')](_0x275ea1[_0x0baf('0x39')],_0x275ea1['query']);_0x24ecee[_0x0baf('0x3d')]=_[_0x0baf('0x3c')](_0x275ea1[_0x0baf('0x39')],qs[_0x0baf('0x3e')](_0x37be4e[_0x0baf('0x3a')][_0x0baf('0x3e')]));_0x24ecee[_0x0baf('0x3d')]=_0x24ecee[_0x0baf('0x3d')]['length']?_0x24ecee[_0x0baf('0x3d')]:_0x275ea1[_0x0baf('0x39')];if(!_0x37be4e['query'][_0x0baf('0x3f')]('nolimit')){_0x24ecee['limit']=qs[_0x0baf('0x24')](_0x37be4e[_0x0baf('0x3a')]['limit']);_0x24ecee['offset']=qs[_0x0baf('0x22')](_0x37be4e[_0x0baf('0x3a')][_0x0baf('0x22')]);}_0x24ecee[_0x0baf('0x40')]=qs[_0x0baf('0x41')](_0x37be4e[_0x0baf('0x3a')][_0x0baf('0x41')]);_0x24ecee[_0x0baf('0x42')]=qs[_0x0baf('0x43')](_[_0x0baf('0x44')](_0x37be4e[_0x0baf('0x3a')],_0x275ea1[_0x0baf('0x43')]),_0x2f0a45);if(_0x37be4e[_0x0baf('0x3a')][_0x0baf('0x45')]){_0x24ecee['where']=_[_0x0baf('0x46')](_0x24ecee[_0x0baf('0x42')],{'$or':_['map'](_0x2f0a45,function(_0x38006a){if(_0x38006a[_0x0baf('0x38')]!==_0x0baf('0x47')){var _0x299f93={};_0x299f93[_0x38006a[_0x0baf('0x31')]]={'$like':'%'+_0x37be4e[_0x0baf('0x3a')]['filter']+'%'};return _0x299f93;}})});}_0x24ecee=_[_0x0baf('0x46')]({},_0x24ecee,_0x37be4e[_0x0baf('0x48')]);var _0x540c41={'where':_0x24ecee[_0x0baf('0x42')]};return db[_0x0baf('0x35')][_0x0baf('0x25')](_0x540c41)[_0x0baf('0x29')](function(_0x504031){_0x2fc983[_0x0baf('0x25')]=_0x504031;if(_0x37be4e[_0x0baf('0x3a')][_0x0baf('0x49')]){_0x24ecee[_0x0baf('0x4a')]=[{'all':!![]}];}return db[_0x0baf('0x35')][_0x0baf('0x4b')](_0x24ecee);})[_0x0baf('0x29')](function(_0x1fa237){_0x2fc983[_0x0baf('0x4c')]=_0x1fa237;return _0x2fc983;})[_0x0baf('0x29')](respondWithFilteredResult(_0x3ed995,_0x24ecee))['catch'](handleError(_0x3ed995,null));};exports[_0x0baf('0x4d')]=function(_0x2bc755,_0x1daf1d){var _0x339aff={'raw':![],'where':{'id':_0x2bc755['params']['id']}},_0x22207a={};_0x22207a[_0x0baf('0x39')]=_[_0x0baf('0x3b')](db[_0x0baf('0x35')][_0x0baf('0x36')]);_0x22207a[_0x0baf('0x3a')]=_['keys'](_0x2bc755[_0x0baf('0x3a')]);_0x22207a[_0x0baf('0x43')]=_[_0x0baf('0x3c')](_0x22207a[_0x0baf('0x39')],_0x22207a[_0x0baf('0x3a')]);_0x339aff[_0x0baf('0x3d')]=_[_0x0baf('0x3c')](_0x22207a['model'],qs[_0x0baf('0x3e')](_0x2bc755[_0x0baf('0x3a')][_0x0baf('0x3e')]));_0x339aff['attributes']=_0x339aff[_0x0baf('0x3d')][_0x0baf('0x4e')]?_0x339aff[_0x0baf('0x3d')]:_0x22207a[_0x0baf('0x39')];if(_0x2bc755[_0x0baf('0x3a')][_0x0baf('0x49')]){_0x339aff[_0x0baf('0x4a')]=[{'all':!![]}];}_0x339aff=_['merge']({},_0x339aff,_0x2bc755[_0x0baf('0x48')]);return db[_0x0baf('0x35')][_0x0baf('0x4f')](_0x339aff)[_0x0baf('0x29')](handleEntityNotFound(_0x1daf1d,null))[_0x0baf('0x29')](respondWithResult(_0x1daf1d,null))[_0x0baf('0x50')](handleError(_0x1daf1d,null));};exports[_0x0baf('0x2a')]=function(_0x1af4aa,_0x2be7fe){return db[_0x0baf('0x35')][_0x0baf('0x4f')]({'where':{'id':_0x1af4aa['params']['id']}})['then'](handleEntityNotFound(_0x2be7fe,null))[_0x0baf('0x29')](removeEntity(_0x2be7fe,null))[_0x0baf('0x50')](handleError(_0x2be7fe,null));};exports[_0x0baf('0x51')]=function(_0xb8fa28,_0x21b108){return db[_0x0baf('0x35')][_0x0baf('0x51')]()['then'](respondWithResult(_0x21b108,null))[_0x0baf('0x50')](handleError(_0x21b108,null));};exports[_0x0baf('0x52')]=function(_0xf2424,_0x16d9fb){var _0x3fdb41;return db[_0x0baf('0x53')]['transaction'](function(_0x3eebe5){return db['VoicePrefix'][_0x0baf('0x52')](_0xf2424['body'],{'transaction':_0x3eebe5})[_0x0baf('0x29')](function(_0x5eaeb2){_0x3fdb41=_0x5eaeb2[_0x0baf('0x2b')]({'plain':!![]});return db['VoiceExtension'][_0x0baf('0x4f')]({'where':{'id':_0x3fdb41[_0x0baf('0x54')]},'raw':!![]})[_0x0baf('0x29')](function(_0x4520d1){return createVoicePrefixExtensions(_0x3fdb41,_0x4520d1,_0x3eebe5);});});})[_0x0baf('0x29')](function(){var _0x576475=_0xf2424[_0x0baf('0x55')][_0x0baf('0x2b')]({'plain':!![]});if(!_0x576475)throw new Error(_0x0baf('0x56'));if(_0x576475[_0x0baf('0x57')]===_0x0baf('0x55')){var _0xa19b21=_0x3fdb41;return db['UserProfileSection'][_0x0baf('0x4f')]({'where':{'name':_0x0baf('0x2c'),'userProfileId':_0x576475[_0x0baf('0x58')]},'raw':!![]})[_0x0baf('0x29')](function(_0xbc7cc2){if(_0xbc7cc2&&_0xbc7cc2[_0x0baf('0x59')]===0x0){return db[_0x0baf('0x2d')]['create']({'name':_0xa19b21['name'],'resourceId':_0xa19b21['id'],'type':_0xbc7cc2[_0x0baf('0x31')],'sectionId':_0xbc7cc2['id']},{})[_0x0baf('0x29')](function(){return _0x3fdb41;});}else{return _0x3fdb41;}})[_0x0baf('0x50')](function(_0x337d94){logger[_0x0baf('0x2f')](_0x0baf('0x5a'),_0x337d94);throw _0x337d94;});}return _0x3fdb41;})[_0x0baf('0x29')](respondWithResult(_0x16d9fb,null))[_0x0baf('0x50')](handleError(_0x16d9fb,null));};function Extension(_0x3d9a32,_0x585969,_0x3238f9,_0x268be8){this[_0x0baf('0x5b')]=_0x0baf('0x5c');this[_0x0baf('0x5d')]=_0x3d9a32;this[_0x0baf('0x5e')]=_0x3238f9;this[_0x0baf('0x38')]='system';this[_0x0baf('0x5f')]=_0x0baf('0x60');this[_0x0baf('0x61')]=_0x585969;this[_0x0baf('0x62')]=_0x268be8;}function createVoicePrefixExtensions(_0x1c7d88,_0x1a6d22,_0x14e6d0){return new BPromise(function(_0x12543e,_0x498405){var _0x178495=new Extension(formatPrefixName(_0x1c7d88['prefix']),0x1,_0x0baf('0x63'),'Voice\x20Prefix');_0x178495['VoicePrefixId']=_0x1c7d88['id'];return db[_0x0baf('0x64')]['create'](_0x178495,{'transaction':_0x14e6d0})[_0x0baf('0x29')](function(_0x2b17f8){var _0x49d713=_0x2b17f8[_0x0baf('0x2b')]({'plain':!![]});var _0xfb6708=_[_0x0baf('0x34')](addVoicePrefixExtensions(_0x1c7d88,_0x1a6d22),function(_0x5b3c1d){_0x5b3c1d['VoiceExtensionId']=_0x49d713['id'];_0x5b3c1d[_0x0baf('0x65')]=_0x1c7d88['id'];return _0x5b3c1d;});return db[_0x0baf('0x64')][_0x0baf('0x66')](_0xfb6708,{'transaction':_0x14e6d0})[_0x0baf('0x29')](function(_0x784e1a){if(!_0x784e1a){return _0x498405('Extensions\x20creation\x20failed');}else{return _0x12543e(_0x784e1a);}})[_0x0baf('0x50')](function(_0x4c02ca){return _0x498405(_0x4c02ca);});});;});};function addVoicePrefixExtensions(_0x5d5751,_0x59a0b2){var _0x427ed1=[];var _0x58a366=formatPrefixName(_0x5d5751['prefix']);_0x427ed1[_0x0baf('0x67')](new Extension(_0x58a366,0x2,_0x0baf('0x68'),_0x0baf('0x69')+_0x5d5751[_0x0baf('0x31')]));if(_0x5d5751[_0x0baf('0x6a')]){_0x427ed1[_0x0baf('0x67')](new Extension(_0x58a366,0x3,'Set',_0x0baf('0x6b')+_0x5d5751[_0x0baf('0x6a')]));}else{_0x427ed1[_0x0baf('0x67')](new Extension(_0x58a366,0x3,_0x0baf('0x63'),_0x0baf('0x6c')));}_0x427ed1[_0x0baf('0x67')](new Extension(_0x58a366,0x4,'goto',_0x59a0b2[_0x0baf('0x5b')]+','+_0x0baf('0x6d')+(0x8+_0x5d5751[_0x0baf('0x31')]['length'])+'}'+','+0x1));return _0x427ed1;}function formatPrefixName(_0x89484d){var _0x1e474f='_';for(var _0x3d333d=0x0;_0x3d333d<_0x89484d[_0x0baf('0x4e')];_0x3d333d++){if(_0x89484d[_0x0baf('0x6e')](_0x3d333d)=='-'){_0x1e474f+=_0x89484d[_0x0baf('0x6e')](_0x3d333d);}else{_0x1e474f+='['+_0x89484d[_0x0baf('0x6e')](_0x3d333d)+']';}}_0x1e474f+='.';return _0x1e474f;}exports['update']=function(_0x54353a,_0x4b7caa,_0x6ce83c){var _0x89bec7=_0x54353a[_0x0baf('0x6f')];_0x89bec7[_0x0baf('0x70')]=_0x0baf('0x71')+_0x89bec7[_0x0baf('0x31')]+'-';return db['sequelize']['transaction'](function(_0x34c1f4){return db['VoicePrefix'][_0x0baf('0x28')](_0x89bec7,{'where':{'id':_0x89bec7['id']},'transaction':_0x34c1f4})[_0x0baf('0x29')](function(){return db['VoiceExtension'][_0x0baf('0x2a')]({'where':{'VoicePrefixId':_0x89bec7['id']},'transaction':_0x34c1f4})[_0x0baf('0x29')](function(){return db[_0x0baf('0x64')][_0x0baf('0x4f')]({'where':{'id':_0x89bec7[_0x0baf('0x54')]},'raw':!![]})[_0x0baf('0x29')](function(_0x1b6b73){return createVoicePrefixExtensions(_0x89bec7,_0x1b6b73,_0x34c1f4);});});});})[_0x0baf('0x29')](function(){return db[_0x0baf('0x35')]['findById'](_0x89bec7['id']);})['then'](respondWithResult(_0x4b7caa,null))['catch'](handleError(_0x4b7caa,null));};exports['addAgents']=function(_0x5361a5,_0x418c45,_0x18963f){return db[_0x0baf('0x35')][_0x0baf('0x4f')]({'where':{'id':_0x5361a5['params']['id']}})[_0x0baf('0x29')](handleEntityNotFound(_0x418c45,null))[_0x0baf('0x29')](function(_0x58caee){if(_0x58caee){return _0x58caee['addAgents'](_0x5361a5[_0x0baf('0x6f')][_0x0baf('0x72')],_[_0x0baf('0x73')](_0x5361a5[_0x0baf('0x6f')],[_0x0baf('0x72'),'id'])||{})[_0x0baf('0x74')](function(_0x3ce111){for(var _0x399f40=0x0;_0x399f40<_0x5361a5['body'][_0x0baf('0x72')][_0x0baf('0x4e')];_0x399f40+=0x1){socket['emit'](_0x0baf('0x75'),{'UserId':Number(_0x5361a5[_0x0baf('0x6f')]['ids'][_0x399f40]),'VoicePrefixId':Number(_0x5361a5[_0x0baf('0x76')]['id'])});}return _0x3ce111;});}})[_0x0baf('0x29')](respondWithResult(_0x418c45,null))[_0x0baf('0x50')](handleError(_0x418c45,null));};exports[_0x0baf('0x77')]=function(_0x167977,_0x4fc5af,_0x4807fc){return db[_0x0baf('0x35')][_0x0baf('0x4f')]({'where':{'id':_0x167977['params']['id']}})[_0x0baf('0x29')](handleEntityNotFound(_0x4fc5af,null))[_0x0baf('0x29')](function(_0x21ad25){if(_0x21ad25){return _0x21ad25['removeAgents'](_0x167977[_0x0baf('0x3a')][_0x0baf('0x72')])[_0x0baf('0x29')](function(){if(_['isArray'](_0x167977[_0x0baf('0x3a')]['ids'])){for(var _0x316397=0x0;_0x316397<_0x167977[_0x0baf('0x3a')][_0x0baf('0x72')][_0x0baf('0x4e')];_0x316397+=0x1){socket[_0x0baf('0x78')]('userVoicePrefix:remove',{'UserId':Number(_0x167977[_0x0baf('0x3a')][_0x0baf('0x72')][_0x316397]),'VoicePrefixId':Number(_0x167977['params']['id'])});}}else{socket[_0x0baf('0x78')](_0x0baf('0x79'),{'UserId':Number(_0x167977[_0x0baf('0x3a')][_0x0baf('0x72')]),'VoicePrefixId':Number(_0x167977[_0x0baf('0x76')]['id'])});}});}})[_0x0baf('0x29')](respondWithStatusCode(_0x4fc5af,null))[_0x0baf('0x50')](handleError(_0x4fc5af,null));};exports[_0x0baf('0x7a')]=function(_0x44ef57,_0x1ca3a6,_0x3b7abf){var _0x2c2f09={};var _0x5985f9={};var _0x599ac0;var _0x29a036;return db[_0x0baf('0x35')][_0x0baf('0x7b')]({'where':{'id':_0x44ef57['params']['id']}})['then'](handleEntityNotFound(_0x1ca3a6,null))[_0x0baf('0x29')](function(_0x368e23){if(_0x368e23){_0x599ac0=_0x368e23;_0x5985f9[_0x0baf('0x39')]=_[_0x0baf('0x3b')](db[_0x0baf('0x7c')][_0x0baf('0x36')]);_0x5985f9[_0x0baf('0x3a')]=_[_0x0baf('0x3b')](_0x44ef57[_0x0baf('0x3a')]);_0x5985f9['filters']=_[_0x0baf('0x3c')](_0x5985f9[_0x0baf('0x39')],_0x5985f9[_0x0baf('0x3a')]);_0x2c2f09[_0x0baf('0x3d')]=_['intersection'](_0x5985f9['model'],qs['fields'](_0x44ef57[_0x0baf('0x3a')][_0x0baf('0x3e')]));_0x2c2f09['attributes']=_0x2c2f09['attributes'][_0x0baf('0x4e')]?_0x2c2f09[_0x0baf('0x3d')]:_0x5985f9['model'];_0x2c2f09[_0x0baf('0x40')]=qs[_0x0baf('0x41')](_0x44ef57[_0x0baf('0x3a')][_0x0baf('0x41')]);_0x2c2f09[_0x0baf('0x42')]=qs[_0x0baf('0x43')](_[_0x0baf('0x44')](_0x44ef57[_0x0baf('0x3a')],_0x5985f9[_0x0baf('0x43')]));if(_0x44ef57[_0x0baf('0x3a')][_0x0baf('0x45')]){_0x2c2f09[_0x0baf('0x42')]=_['merge'](_0x2c2f09[_0x0baf('0x42')],{'$or':_[_0x0baf('0x34')](_0x2c2f09[_0x0baf('0x3d')],function(_0x3bd15b){var _0x3c37b4={};_0x3c37b4[_0x3bd15b]={'$like':'%'+_0x44ef57[_0x0baf('0x3a')]['filter']+'%'};return _0x3c37b4;})});}_0x2c2f09=_[_0x0baf('0x46')]({},_0x2c2f09,_0x44ef57[_0x0baf('0x48')]);return _0x599ac0[_0x0baf('0x7a')](_0x2c2f09);}})[_0x0baf('0x29')](function(_0x4376a1){if(_0x4376a1){_0x29a036=_0x4376a1['length'];if(!_0x44ef57[_0x0baf('0x3a')][_0x0baf('0x3f')](_0x0baf('0x7d'))){_0x2c2f09[_0x0baf('0x24')]=qs[_0x0baf('0x24')](_0x44ef57['query']['limit']);_0x2c2f09[_0x0baf('0x22')]=qs['offset'](_0x44ef57[_0x0baf('0x3a')]['offset']);}return _0x599ac0[_0x0baf('0x7a')](_0x2c2f09);}})[_0x0baf('0x29')](function(_0x1ce7bb){if(_0x1ce7bb){return _0x1ce7bb?{'count':_0x29a036,'rows':_0x1ce7bb}:null;}})[_0x0baf('0x29')](respondWithResult(_0x1ca3a6,null))['catch'](handleError(_0x1ca3a6,null));};exports[_0x0baf('0x7e')]=function(_0x106ffa,_0xf7a9d0,_0x551df3){var _0x487aec={};var _0x591cc2={};var _0x4d4884;var _0x427638;return db[_0x0baf('0x35')][_0x0baf('0x7b')]({'where':{'id':_0x106ffa[_0x0baf('0x76')]['id']}})['then'](handleEntityNotFound(_0xf7a9d0,null))[_0x0baf('0x29')](function(_0x37594e){if(_0x37594e){_0x4d4884=_0x37594e;_0x591cc2[_0x0baf('0x39')]=_['keys'](db[_0x0baf('0x7f')][_0x0baf('0x36')]);_0x591cc2['query']=_[_0x0baf('0x3b')](_0x106ffa['query']);_0x591cc2[_0x0baf('0x43')]=_[_0x0baf('0x3c')](_0x591cc2[_0x0baf('0x39')],_0x591cc2[_0x0baf('0x3a')]);_0x487aec['attributes']=_['intersection'](_0x591cc2[_0x0baf('0x39')],qs['fields'](_0x106ffa[_0x0baf('0x3a')][_0x0baf('0x3e')]));_0x487aec[_0x0baf('0x3d')]=_0x487aec[_0x0baf('0x3d')][_0x0baf('0x4e')]?_0x487aec['attributes']:_0x591cc2[_0x0baf('0x39')];_0x487aec['order']=qs[_0x0baf('0x41')](_0x106ffa['query'][_0x0baf('0x41')]);_0x487aec['where']=qs[_0x0baf('0x43')](_[_0x0baf('0x44')](_0x106ffa[_0x0baf('0x3a')],_0x591cc2['filters']));if(_0x106ffa['query'][_0x0baf('0x45')]){_0x487aec[_0x0baf('0x42')]=_[_0x0baf('0x46')](_0x487aec[_0x0baf('0x42')],{'$or':_[_0x0baf('0x34')](_0x487aec[_0x0baf('0x3d')],function(_0x4e6059){var _0xd4170d={};_0xd4170d[_0x4e6059]={'$like':'%'+_0x106ffa['query'][_0x0baf('0x45')]+'%'};return _0xd4170d;})});}_0x487aec=_['merge']({},_0x487aec,_0x106ffa[_0x0baf('0x48')]);return _0x4d4884[_0x0baf('0x7e')](_0x487aec);}})[_0x0baf('0x29')](function(_0x557a38){if(_0x557a38){_0x427638=_0x557a38[_0x0baf('0x4e')];if(!_0x106ffa[_0x0baf('0x3a')]['hasOwnProperty']('nolimit')){_0x487aec[_0x0baf('0x24')]=qs[_0x0baf('0x24')](_0x106ffa[_0x0baf('0x3a')][_0x0baf('0x24')]);_0x487aec['offset']=qs['offset'](_0x106ffa[_0x0baf('0x3a')][_0x0baf('0x22')]);}return _0x4d4884[_0x0baf('0x7e')](_0x487aec);}})[_0x0baf('0x29')](function(_0xfc91ce){if(_0xfc91ce){return _0xfc91ce?{'count':_0x427638,'rows':_0xfc91ce}:null;}})[_0x0baf('0x29')](respondWithResult(_0xf7a9d0,null))[_0x0baf('0x50')](handleError(_0xf7a9d0,null));};exports[_0x0baf('0x80')]=function(_0x205de6,_0x2369f0,_0x58f95c){var _0xdb96c0=_0x205de6['body'][_0x0baf('0x72')];var _0x42abcf;return db[_0x0baf('0x7f')][_0x0baf('0x4b')]({'where':{'id':_0xdb96c0},'attributes':['id'],'include':[{'model':db['User'],'as':_0x0baf('0x81'),'attributes':['id',_0x0baf('0x31'),_0x0baf('0x82'),_0x0baf('0x83'),_0x0baf('0x84')],'raw':!![]}]})[_0x0baf('0x29')](function(_0x3b9101){if(_0x3b9101){_0x42abcf=_0x3b9101;var _0x205075=_[_0x0baf('0x85')](_0x3b9101,function(_0x4b6cd5){var _0x8d1bae=_0x4b6cd5[_0x0baf('0x2b')]({'plain':!![]});return _0x8d1bae['Agents'];});return db[_0x0baf('0x35')][_0x0baf('0x4f')]({'where':{'id':_0x205de6[_0x0baf('0x76')]['id']}})[_0x0baf('0x29')](function(_0x97f5d6){return db[_0x0baf('0x53')][_0x0baf('0x86')](function(_0x8c1dc2){return _0x97f5d6[_0x0baf('0x80')](_0xdb96c0,{'transaction':_0x8c1dc2})['then'](function(){return BPromise[_0x0baf('0x87')](_0x42abcf,function(_0x218fc5){return db[_0x0baf('0x88')][_0x0baf('0x89')]({'TeamId':_0x218fc5['id'],'VoicePrefixId':_0x205de6[_0x0baf('0x76')]['id']},{'transaction':_0x8c1dc2});});})[_0x0baf('0x29')](function(){return BPromise['each'](_0x205075,function(_0x121718){return db[_0x0baf('0x8a')][_0x0baf('0x8b')]({'where':{'UserId':_0x121718['id'],'VoicePrefixId':_0x205de6['params']['id']},'transaction':_0x8c1dc2});});})['then'](function(){_0x205075[_0x0baf('0x8c')](function(_0x1adb84){socket[_0x0baf('0x78')]('userVoicePrefix:save',{'UserId':_0x1adb84['id'],'VoicePrefixId':_0x97f5d6['id']});});});});});}})[_0x0baf('0x29')](respondWithStatusCode(_0x2369f0,null))['catch'](handleError(_0x2369f0,null));};exports[_0x0baf('0x8d')]=function(_0x5f09be,_0x41b216,_0x3f2838){return db['Team'][_0x0baf('0x4b')]({'where':{'id':_0x5f09be[_0x0baf('0x3a')][_0x0baf('0x72')]},'attributes':['id'],'include':[{'model':db[_0x0baf('0x7c')],'as':_0x0baf('0x81'),'attributes':['id'],'raw':!![]}]})[_0x0baf('0x29')](handleEntityNotFound(_0x41b216,null))[_0x0baf('0x29')](function(_0x5508db){var _0x727cad=_[_0x0baf('0x34')](_0x5508db,'id');var _0x2766fb=[];var _0x2e1629=[];var _0x275cc4=squel[_0x0baf('0x8e')]();_0x275cc4[_0x0baf('0x8f')](_0x0baf('0x90'))[_0x0baf('0x91')](_0x0baf('0x92'),'tq')[_0x0baf('0x93')](_0x0baf('0x94'),'ut',_0x0baf('0x95'))[_0x0baf('0x42')]('VoicePrefixId\x20=\x20?',_0x5f09be['params']['id']);for(var _0x1cd215=0x0;_0x1cd215<_0x5508db[_0x0baf('0x4e')];_0x1cd215+=0x1){let _0x3b9429=_0x5508db[_0x1cd215];for(var _0x41d397=0x0;_0x41d397<_0x3b9429['Agents'][_0x0baf('0x4e')];_0x41d397+=0x1){let _0xc6c049=_0x3b9429[_0x0baf('0x81')][_0x41d397];var _0x2fb267=_0x275cc4[_0x0baf('0x96')]();_0x2fb267[_0x0baf('0x42')]('ut.UserId\x20=\x20?',_0xc6c049['id']);_0x2e1629[_0x0baf('0x67')](db[_0x0baf('0x53')][_0x0baf('0x3a')](_0x2fb267['toString'](),{'type':db[_0x0baf('0x53')][_0x0baf('0x97')][_0x0baf('0x98')]})['then'](function(_0x4f7145){if(_0x4f7145['length']===0x1){return _0xc6c049['id'];}else{var _0x11a85a=_['every'](_[_0x0baf('0x34')](_0x4f7145,_0x0baf('0x99')),function(_0x55124b){return _[_0x0baf('0x9a')](_0x727cad,_0x55124b);});if(_0x11a85a){return _0xc6c049['id'];}}}));}}return BPromise['all'](_0x2e1629)['then'](function(_0x21516f){_0x2766fb=_(_0x2766fb)['union'](_0x21516f)[_0x0baf('0x9b')]()['value']();return db['VoicePrefix']['find']({'where':{'id':_0x5f09be[_0x0baf('0x76')]['id']}})[_0x0baf('0x29')](function(_0x3d1f80){return db[_0x0baf('0x53')][_0x0baf('0x86')](function(_0x4f9904){return _0x3d1f80[_0x0baf('0x8d')](_0x5f09be['query'][_0x0baf('0x72')],{'transaction':_0x4f9904})[_0x0baf('0x29')](function(){if(!_[_0x0baf('0x9c')](_0x2766fb)){return _0x3d1f80['removeAgents'](_0x2766fb,{'transaction':_0x4f9904});}})[_0x0baf('0x29')](function(){_0x2766fb[_0x0baf('0x8c')](function(_0x12311d){socket['emit'](_0x0baf('0x79'),{'UserId':_0x12311d,'VoicePrefixId':_0x3d1f80['id']});});});});});});})['then'](respondWithStatusCode(_0x41b216,null))[_0x0baf('0x50')](handleError(_0x41b216,null));};
\ No newline at end of file