Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / voicePrefix / voicePrefix.controller.js
index 2ab5cf5..8b178e0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x351d=['isEmpty','forEach','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','util','path','to-csv','ejs','fs-extra','squel','crypto','desk.js','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','redis','defaults','localhost','./voicePrefix.socket','sendStatus','status','offset','undefined','limit','count','set','json','reject','save','update','then','destroy','VoicePrefixes','end','error','stack','name','send','index','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields','attributes','hasOwnProperty','nolimit','sort','where','pick','filter','VIRTUAL','includeAll','include','VoicePrefix','findAll','catch','show','params','length','merge','options','describe','create','transaction','body','VoiceExtension','VoiceExtensionId','user','get','find','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','context','from-sip','exten','description','Voice\x20Prefix\x20Extension','priority','appdata','prefix','NoOp','Voice\x20Prefix','VoicePrefixId','Extensions\x20creation\x20failed','CDR(prefix)=','push','No\x20callerid\x20available','goto','${EXTEN:','charAt','system-','addAgents','ids','spread','emit','userVoicePrefix:save','removeAgents','isArray','userVoicePrefix:remove','getAgents','findOne','User','order','Team','getTeams','addTeams','online','voicePause','interface','flatMap','sequelize','each','TeamVoicePrefix','UserVoicePrefix','findOrCreate','removeTeams','Agents','select','tq.TeamId','from','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','VoicePrefixId\x20=\x20?','toString','QueryTypes','TeamId','all','union','compact','value'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x351d,0x90));var _0xd351=function(_0x35e8c8,_0x3a87c5){_0x35e8c8=_0x35e8c8-0x0;var _0x40b0f8=_0x351d[_0x35e8c8];return _0x40b0f8;};'use strict';var emlformat=require(_0xd351('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xd351('0x1'));var jsonpatch=require(_0xd351('0x2'));var rp=require(_0xd351('0x3'));var moment=require('moment');var BPromise=require(_0xd351('0x4'));var Mustache=require('mustache');var util=require(_0xd351('0x5'));var path=require(_0xd351('0x6'));var sox=require('sox');var csv=require(_0xd351('0x7'));var ejs=require(_0xd351('0x8'));var fs=require('fs');var fs_extra=require(_0xd351('0x9'));var _=require('lodash');var squel=require(_0xd351('0xa'));var crypto=require(_0xd351('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xd351('0xc'));var toCsv=require(_0xd351('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xd351('0xd'));var authService=require('../../components/auth/service');var qs=require(_0xd351('0xe'));var as=require(_0xd351('0xf'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xd351('0x10'))(_0xd351('0x11'));var utils=require('../../config/utils');var config=require(_0xd351('0x12'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0xd351('0x13')]=_[_0xd351('0x14')](config[_0xd351('0x13')],{'host':_0xd351('0x15'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd351('0x13')]));require(_0xd351('0x16'))['register'](socket);function respondWithStatusCode(_0xc5a145,_0xb106ef){_0xb106ef=_0xb106ef||0xcc;return function(_0x3c2299){if(_0x3c2299){return _0xc5a145[_0xd351('0x17')](_0xb106ef);}return _0xc5a145[_0xd351('0x18')](_0xb106ef)['end']();};}function respondWithResult(_0x9f790f,_0x49d8bb){_0x49d8bb=_0x49d8bb||0xc8;return function(_0x5bdc03){if(_0x5bdc03){return _0x9f790f[_0xd351('0x18')](_0x49d8bb)['json'](_0x5bdc03);}};}function respondWithFilteredResult(_0x21e591,_0x1de35f){return function(_0x4e0164){if(_0x4e0164){var _0x4c6693=typeof _0x1de35f[_0xd351('0x19')]===_0xd351('0x1a')&&typeof _0x1de35f[_0xd351('0x1b')]===_0xd351('0x1a');var _0x51f265=_0x4e0164[_0xd351('0x1c')];var _0x4abbed=_0x4c6693?0x0:_0x1de35f['offset'];var _0x37d3ac=_0x4c6693?_0x4e0164['count']:_0x1de35f[_0xd351('0x19')]+_0x1de35f[_0xd351('0x1b')];var _0x3634c9;if(_0x37d3ac>=_0x51f265){_0x37d3ac=_0x51f265;_0x3634c9=0xc8;}else{_0x3634c9=0xce;}_0x21e591[_0xd351('0x18')](_0x3634c9);return _0x21e591[_0xd351('0x1d')]('Content-Range',_0x4abbed+'-'+_0x37d3ac+'/'+_0x51f265)[_0xd351('0x1e')](_0x4e0164);}return null;};}function patchUpdates(_0xbbc58){return function(_0x241265){try{jsonpatch['apply'](_0x241265,_0xbbc58,!![]);}catch(_0x1ce7f7){return BPromise[_0xd351('0x1f')](_0x1ce7f7);}return _0x241265[_0xd351('0x20')]();};}function saveUpdates(_0x59fb6d,_0x1ce279){return function(_0x34a5cb){if(_0x34a5cb){return _0x34a5cb[_0xd351('0x21')](_0x59fb6d)[_0xd351('0x22')](function(_0x489c9a){return _0x489c9a;});}return null;};}function removeEntity(_0x40f7f3,_0x483c92){return function(_0x358bff){if(_0x358bff){return _0x358bff[_0xd351('0x23')]()['then'](function(){var _0x2648d0=_0x358bff['get']({'plain':!![]});var _0x50d67e=_0xd351('0x24');return db['UserProfileResource']['destroy']({'where':{'type':_0x50d67e,'resourceId':_0x2648d0['id']}})[_0xd351('0x22')](function(){return _0x358bff;});})['then'](function(){_0x40f7f3[_0xd351('0x18')](0xcc)[_0xd351('0x25')]();});}};}function handleEntityNotFound(_0x407b50,_0x4d3f48){return function(_0x71ce9c){if(!_0x71ce9c){_0x407b50['sendStatus'](0x194);}return _0x71ce9c;};}function handleError(_0x1c826b,_0x50039b){_0x50039b=_0x50039b||0x1f4;return function(_0x5f07b1){logger[_0xd351('0x26')](_0x5f07b1[_0xd351('0x27')]);if(_0x5f07b1[_0xd351('0x28')]){delete _0x5f07b1[_0xd351('0x28')];}_0x1c826b['status'](_0x50039b)[_0xd351('0x29')](_0x5f07b1);};}exports[_0xd351('0x2a')]=function(_0x38023c,_0x41da60){var _0x140591={},_0x205c79={},_0x103a7b={'count':0x0,'rows':[]};var _0x898949=_[_0xd351('0x2b')](db['VoicePrefix'][_0xd351('0x2c')],function(_0x453270){return{'name':_0x453270[_0xd351('0x2d')],'type':_0x453270[_0xd351('0x2e')]['key']};});_0x205c79[_0xd351('0x2f')]=_[_0xd351('0x2b')](_0x898949,_0xd351('0x28'));_0x205c79[_0xd351('0x30')]=_[_0xd351('0x31')](_0x38023c[_0xd351('0x30')]);_0x205c79[_0xd351('0x32')]=_[_0xd351('0x33')](_0x205c79[_0xd351('0x2f')],_0x205c79['query']);_0x140591['attributes']=_[_0xd351('0x33')](_0x205c79[_0xd351('0x2f')],qs[_0xd351('0x34')](_0x38023c[_0xd351('0x30')][_0xd351('0x34')]));_0x140591[_0xd351('0x35')]=_0x140591['attributes']['length']?_0x140591[_0xd351('0x35')]:_0x205c79['model'];if(!_0x38023c[_0xd351('0x30')][_0xd351('0x36')](_0xd351('0x37'))){_0x140591[_0xd351('0x1b')]=qs[_0xd351('0x1b')](_0x38023c[_0xd351('0x30')][_0xd351('0x1b')]);_0x140591[_0xd351('0x19')]=qs[_0xd351('0x19')](_0x38023c[_0xd351('0x30')][_0xd351('0x19')]);}_0x140591['order']=qs[_0xd351('0x38')](_0x38023c['query'][_0xd351('0x38')]);_0x140591[_0xd351('0x39')]=qs[_0xd351('0x32')](_[_0xd351('0x3a')](_0x38023c[_0xd351('0x30')],_0x205c79[_0xd351('0x32')]),_0x898949);if(_0x38023c['query'][_0xd351('0x3b')]){_0x140591[_0xd351('0x39')]=_['merge'](_0x140591[_0xd351('0x39')],{'$or':_[_0xd351('0x2b')](_0x898949,function(_0x382f5b){if(_0x382f5b[_0xd351('0x2e')]!==_0xd351('0x3c')){var _0x5cc105={};_0x5cc105[_0x382f5b['name']]={'$like':'%'+_0x38023c[_0xd351('0x30')][_0xd351('0x3b')]+'%'};return _0x5cc105;}})});}_0x140591=_['merge']({},_0x140591,_0x38023c['options']);var _0x16677f={'where':_0x140591[_0xd351('0x39')]};return db['VoicePrefix']['count'](_0x16677f)[_0xd351('0x22')](function(_0x18f9d1){_0x103a7b[_0xd351('0x1c')]=_0x18f9d1;if(_0x38023c[_0xd351('0x30')][_0xd351('0x3d')]){_0x140591[_0xd351('0x3e')]=[{'all':!![]}];}return db[_0xd351('0x3f')][_0xd351('0x40')](_0x140591);})[_0xd351('0x22')](function(_0x553360){_0x103a7b['rows']=_0x553360;return _0x103a7b;})[_0xd351('0x22')](respondWithFilteredResult(_0x41da60,_0x140591))[_0xd351('0x41')](handleError(_0x41da60,null));};exports[_0xd351('0x42')]=function(_0x35f38f,_0x2bdd8f){var _0x4332e7={'raw':![],'where':{'id':_0x35f38f[_0xd351('0x43')]['id']}},_0xeaf4dc={};_0xeaf4dc[_0xd351('0x2f')]=_[_0xd351('0x31')](db[_0xd351('0x3f')][_0xd351('0x2c')]);_0xeaf4dc[_0xd351('0x30')]=_[_0xd351('0x31')](_0x35f38f[_0xd351('0x30')]);_0xeaf4dc[_0xd351('0x32')]=_['intersection'](_0xeaf4dc[_0xd351('0x2f')],_0xeaf4dc[_0xd351('0x30')]);_0x4332e7[_0xd351('0x35')]=_['intersection'](_0xeaf4dc[_0xd351('0x2f')],qs[_0xd351('0x34')](_0x35f38f[_0xd351('0x30')][_0xd351('0x34')]));_0x4332e7[_0xd351('0x35')]=_0x4332e7['attributes'][_0xd351('0x44')]?_0x4332e7['attributes']:_0xeaf4dc[_0xd351('0x2f')];if(_0x35f38f[_0xd351('0x30')]['includeAll']){_0x4332e7['include']=[{'all':!![]}];}_0x4332e7=_[_0xd351('0x45')]({},_0x4332e7,_0x35f38f[_0xd351('0x46')]);return db[_0xd351('0x3f')]['find'](_0x4332e7)[_0xd351('0x22')](handleEntityNotFound(_0x2bdd8f,null))[_0xd351('0x22')](respondWithResult(_0x2bdd8f,null))['catch'](handleError(_0x2bdd8f,null));};exports[_0xd351('0x23')]=function(_0x53a2e8,_0x1eb5f3){return db[_0xd351('0x3f')]['find']({'where':{'id':_0x53a2e8['params']['id']}})[_0xd351('0x22')](handleEntityNotFound(_0x1eb5f3,null))['then'](removeEntity(_0x1eb5f3,null))[_0xd351('0x41')](handleError(_0x1eb5f3,null));};exports[_0xd351('0x47')]=function(_0x9f1cd0,_0x4a27e3){return db[_0xd351('0x3f')]['describe']()['then'](respondWithResult(_0x4a27e3,null))['catch'](handleError(_0x4a27e3,null));};exports[_0xd351('0x48')]=function(_0x292af3,_0x334029){var _0x5a2e9b;return db['sequelize'][_0xd351('0x49')](function(_0x42f248){return db['VoicePrefix'][_0xd351('0x48')](_0x292af3[_0xd351('0x4a')],{'transaction':_0x42f248})['then'](function(_0x24ee0f){_0x5a2e9b=_0x24ee0f['get']({'plain':!![]});return db[_0xd351('0x4b')]['find']({'where':{'id':_0x5a2e9b[_0xd351('0x4c')]},'raw':!![]})[_0xd351('0x22')](function(_0x169ab1){return createVoicePrefixExtensions(_0x5a2e9b,_0x169ab1,_0x42f248);});});})[_0xd351('0x22')](function(){var _0xb5f3ee=_0x292af3[_0xd351('0x4d')][_0xd351('0x4e')]({'plain':!![]});if(!_0xb5f3ee)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0xb5f3ee['role']===_0xd351('0x4d')){var _0x624224=_0x5a2e9b;return db['UserProfileSection'][_0xd351('0x4f')]({'where':{'name':_0xd351('0x24'),'userProfileId':_0xb5f3ee[_0xd351('0x50')]},'raw':!![]})['then'](function(_0x169122){if(_0x169122&&_0x169122['autoAssociation']===0x0){return db['UserProfileResource'][_0xd351('0x48')]({'name':_0x624224[_0xd351('0x28')],'resourceId':_0x624224['id'],'type':_0x169122['name'],'sectionId':_0x169122['id']},{})[_0xd351('0x22')](function(){return _0x5a2e9b;});}else{return _0x5a2e9b;}})[_0xd351('0x41')](function(_0x2d9747){logger[_0xd351('0x26')](_0xd351('0x51'),_0x2d9747);throw _0x2d9747;});}return _0x5a2e9b;})[_0xd351('0x22')](respondWithResult(_0x334029,null))['catch'](handleError(_0x334029,null));};function Extension(_0x1e1173,_0x2a7390,_0x36fb5b,_0x8461b){this[_0xd351('0x52')]=_0xd351('0x53');this[_0xd351('0x54')]=_0x1e1173;this['app']=_0x36fb5b;this[_0xd351('0x2e')]='system';this[_0xd351('0x55')]=_0xd351('0x56');this[_0xd351('0x57')]=_0x2a7390;this[_0xd351('0x58')]=_0x8461b;}function createVoicePrefixExtensions(_0x70cdb,_0x4eaf18,_0x413931){return new BPromise(function(_0x4c8038,_0x4685fa){var _0x45bcc7=new Extension(formatPrefixName(_0x70cdb[_0xd351('0x59')]),0x1,_0xd351('0x5a'),_0xd351('0x5b'));_0x45bcc7['VoicePrefixId']=_0x70cdb['id'];return db['VoiceExtension'][_0xd351('0x48')](_0x45bcc7,{'transaction':_0x413931})[_0xd351('0x22')](function(_0x4b9367){var _0x2d2655=_0x4b9367[_0xd351('0x4e')]({'plain':!![]});var _0x2718e9=_['map'](addVoicePrefixExtensions(_0x70cdb,_0x4eaf18),function(_0x2b47ab){_0x2b47ab[_0xd351('0x4c')]=_0x2d2655['id'];_0x2b47ab[_0xd351('0x5c')]=_0x70cdb['id'];return _0x2b47ab;});return db[_0xd351('0x4b')]['bulkCreate'](_0x2718e9,{'transaction':_0x413931})['then'](function(_0x40c78b){if(!_0x40c78b){return _0x4685fa(_0xd351('0x5d'));}else{return _0x4c8038(_0x40c78b);}})[_0xd351('0x41')](function(_0xa000b4){return _0x4685fa(_0xa000b4);});});;});};function addVoicePrefixExtensions(_0x36b38f,_0x3b0993){var _0x2c83fe=[];var _0x5e2e06=formatPrefixName(_0x36b38f[_0xd351('0x59')]);_0x2c83fe['push'](new Extension(_0x5e2e06,0x2,'Set',_0xd351('0x5e')+_0x36b38f[_0xd351('0x28')]));if(_0x36b38f['callerIdAll']){_0x2c83fe[_0xd351('0x5f')](new Extension(_0x5e2e06,0x3,'Set','PREFIX-CALLERIDALL='+_0x36b38f['callerIdAll']));}else{_0x2c83fe[_0xd351('0x5f')](new Extension(_0x5e2e06,0x3,_0xd351('0x5a'),_0xd351('0x60')));}_0x2c83fe['push'](new Extension(_0x5e2e06,0x4,_0xd351('0x61'),_0x3b0993[_0xd351('0x52')]+','+_0xd351('0x62')+(0x8+_0x36b38f[_0xd351('0x28')][_0xd351('0x44')])+'}'+','+0x1));return _0x2c83fe;}function formatPrefixName(_0x475534){var _0x15fcab='_';for(var _0x6bf19c=0x0;_0x6bf19c<_0x475534[_0xd351('0x44')];_0x6bf19c++){if(_0x475534[_0xd351('0x63')](_0x6bf19c)=='-'){_0x15fcab+=_0x475534[_0xd351('0x63')](_0x6bf19c);}else{_0x15fcab+='['+_0x475534['charAt'](_0x6bf19c)+']';}}_0x15fcab+='.';return _0x15fcab;}exports[_0xd351('0x21')]=function(_0x2d59a5,_0x431e91,_0xcc7a10){var _0xf24a29=_0x2d59a5[_0xd351('0x4a')];_0xf24a29['prefix']=_0xd351('0x64')+_0xf24a29[_0xd351('0x28')]+'-';return db['sequelize']['transaction'](function(_0x436e1d){return db[_0xd351('0x3f')][_0xd351('0x21')](_0xf24a29,{'where':{'id':_0xf24a29['id']},'transaction':_0x436e1d})[_0xd351('0x22')](function(){return db[_0xd351('0x4b')][_0xd351('0x23')]({'where':{'VoicePrefixId':_0xf24a29['id']},'transaction':_0x436e1d})[_0xd351('0x22')](function(){return db[_0xd351('0x4b')][_0xd351('0x4f')]({'where':{'id':_0xf24a29['VoiceExtensionId']},'raw':!![]})[_0xd351('0x22')](function(_0x129623){return createVoicePrefixExtensions(_0xf24a29,_0x129623,_0x436e1d);});});});})['then'](function(){return db[_0xd351('0x3f')]['findById'](_0xf24a29['id']);})[_0xd351('0x22')](respondWithResult(_0x431e91,null))['catch'](handleError(_0x431e91,null));};exports[_0xd351('0x65')]=function(_0x406d8a,_0xbd31ca,_0x451445){return db[_0xd351('0x3f')][_0xd351('0x4f')]({'where':{'id':_0x406d8a[_0xd351('0x43')]['id']}})['then'](handleEntityNotFound(_0xbd31ca,null))[_0xd351('0x22')](function(_0x2558b4){if(_0x2558b4){return _0x2558b4[_0xd351('0x65')](_0x406d8a[_0xd351('0x4a')][_0xd351('0x66')],_['omit'](_0x406d8a[_0xd351('0x4a')],[_0xd351('0x66'),'id'])||{})[_0xd351('0x67')](function(_0x54b38c){for(var _0x38a3ec=0x0;_0x38a3ec<_0x406d8a[_0xd351('0x4a')][_0xd351('0x66')][_0xd351('0x44')];_0x38a3ec+=0x1){socket[_0xd351('0x68')](_0xd351('0x69'),{'UserId':Number(_0x406d8a[_0xd351('0x4a')][_0xd351('0x66')][_0x38a3ec]),'VoicePrefixId':Number(_0x406d8a[_0xd351('0x43')]['id'])});}return _0x54b38c;});}})['then'](respondWithResult(_0xbd31ca,null))[_0xd351('0x41')](handleError(_0xbd31ca,null));};exports[_0xd351('0x6a')]=function(_0x5036e6,_0x44df63,_0x4c1468){return db['VoicePrefix']['find']({'where':{'id':_0x5036e6[_0xd351('0x43')]['id']}})[_0xd351('0x22')](handleEntityNotFound(_0x44df63,null))[_0xd351('0x22')](function(_0x5b2bf9){if(_0x5b2bf9){return _0x5b2bf9[_0xd351('0x6a')](_0x5036e6['query'][_0xd351('0x66')])['then'](function(){if(_[_0xd351('0x6b')](_0x5036e6[_0xd351('0x30')][_0xd351('0x66')])){for(var _0x16dd16=0x0;_0x16dd16<_0x5036e6[_0xd351('0x30')][_0xd351('0x66')][_0xd351('0x44')];_0x16dd16+=0x1){socket[_0xd351('0x68')](_0xd351('0x6c'),{'UserId':Number(_0x5036e6[_0xd351('0x30')][_0xd351('0x66')][_0x16dd16]),'VoicePrefixId':Number(_0x5036e6[_0xd351('0x43')]['id'])});}}else{socket['emit'](_0xd351('0x6c'),{'UserId':Number(_0x5036e6[_0xd351('0x30')][_0xd351('0x66')]),'VoicePrefixId':Number(_0x5036e6[_0xd351('0x43')]['id'])});}});}})[_0xd351('0x22')](respondWithStatusCode(_0x44df63,null))['catch'](handleError(_0x44df63,null));};exports[_0xd351('0x6d')]=function(_0x1e6c85,_0x2adab4,_0x2a1ea4){var _0x4a4b25={};var _0x1fda25={};var _0x36bbee;var _0x48b5ee;return db[_0xd351('0x3f')][_0xd351('0x6e')]({'where':{'id':_0x1e6c85[_0xd351('0x43')]['id']}})[_0xd351('0x22')](handleEntityNotFound(_0x2adab4,null))['then'](function(_0x523895){if(_0x523895){_0x36bbee=_0x523895;_0x1fda25[_0xd351('0x2f')]=_[_0xd351('0x31')](db[_0xd351('0x6f')][_0xd351('0x2c')]);_0x1fda25['query']=_[_0xd351('0x31')](_0x1e6c85[_0xd351('0x30')]);_0x1fda25[_0xd351('0x32')]=_[_0xd351('0x33')](_0x1fda25[_0xd351('0x2f')],_0x1fda25['query']);_0x4a4b25[_0xd351('0x35')]=_[_0xd351('0x33')](_0x1fda25['model'],qs[_0xd351('0x34')](_0x1e6c85[_0xd351('0x30')]['fields']));_0x4a4b25[_0xd351('0x35')]=_0x4a4b25['attributes'][_0xd351('0x44')]?_0x4a4b25['attributes']:_0x1fda25[_0xd351('0x2f')];_0x4a4b25[_0xd351('0x70')]=qs[_0xd351('0x38')](_0x1e6c85[_0xd351('0x30')][_0xd351('0x38')]);_0x4a4b25[_0xd351('0x39')]=qs[_0xd351('0x32')](_[_0xd351('0x3a')](_0x1e6c85[_0xd351('0x30')],_0x1fda25['filters']));if(_0x1e6c85[_0xd351('0x30')][_0xd351('0x3b')]){_0x4a4b25[_0xd351('0x39')]=_[_0xd351('0x45')](_0x4a4b25[_0xd351('0x39')],{'$or':_[_0xd351('0x2b')](_0x4a4b25[_0xd351('0x35')],function(_0x54041b){var _0x56458b={};_0x56458b[_0x54041b]={'$like':'%'+_0x1e6c85[_0xd351('0x30')]['filter']+'%'};return _0x56458b;})});}_0x4a4b25=_[_0xd351('0x45')]({},_0x4a4b25,_0x1e6c85[_0xd351('0x46')]);return _0x36bbee[_0xd351('0x6d')](_0x4a4b25);}})[_0xd351('0x22')](function(_0x2d5e2b){if(_0x2d5e2b){_0x48b5ee=_0x2d5e2b['length'];if(!_0x1e6c85[_0xd351('0x30')][_0xd351('0x36')](_0xd351('0x37'))){_0x4a4b25[_0xd351('0x1b')]=qs[_0xd351('0x1b')](_0x1e6c85[_0xd351('0x30')][_0xd351('0x1b')]);_0x4a4b25[_0xd351('0x19')]=qs[_0xd351('0x19')](_0x1e6c85[_0xd351('0x30')][_0xd351('0x19')]);}return _0x36bbee[_0xd351('0x6d')](_0x4a4b25);}})[_0xd351('0x22')](function(_0x4ddd65){if(_0x4ddd65){return _0x4ddd65?{'count':_0x48b5ee,'rows':_0x4ddd65}:null;}})['then'](respondWithResult(_0x2adab4,null))[_0xd351('0x41')](handleError(_0x2adab4,null));};exports['getTeams']=function(_0x5c202f,_0x426964,_0x4557ed){var _0x3f6826={};var _0x1a5e8e={};var _0x54fc9c;var _0x2443bd;return db['VoicePrefix']['findOne']({'where':{'id':_0x5c202f[_0xd351('0x43')]['id']}})[_0xd351('0x22')](handleEntityNotFound(_0x426964,null))[_0xd351('0x22')](function(_0x15690b){if(_0x15690b){_0x54fc9c=_0x15690b;_0x1a5e8e[_0xd351('0x2f')]=_[_0xd351('0x31')](db[_0xd351('0x71')]['rawAttributes']);_0x1a5e8e[_0xd351('0x30')]=_[_0xd351('0x31')](_0x5c202f[_0xd351('0x30')]);_0x1a5e8e[_0xd351('0x32')]=_[_0xd351('0x33')](_0x1a5e8e[_0xd351('0x2f')],_0x1a5e8e['query']);_0x3f6826['attributes']=_[_0xd351('0x33')](_0x1a5e8e['model'],qs[_0xd351('0x34')](_0x5c202f[_0xd351('0x30')]['fields']));_0x3f6826[_0xd351('0x35')]=_0x3f6826[_0xd351('0x35')][_0xd351('0x44')]?_0x3f6826[_0xd351('0x35')]:_0x1a5e8e[_0xd351('0x2f')];_0x3f6826['order']=qs[_0xd351('0x38')](_0x5c202f['query'][_0xd351('0x38')]);_0x3f6826[_0xd351('0x39')]=qs['filters'](_[_0xd351('0x3a')](_0x5c202f[_0xd351('0x30')],_0x1a5e8e[_0xd351('0x32')]));if(_0x5c202f[_0xd351('0x30')]['filter']){_0x3f6826['where']=_['merge'](_0x3f6826[_0xd351('0x39')],{'$or':_[_0xd351('0x2b')](_0x3f6826[_0xd351('0x35')],function(_0x40740e){var _0x3606b1={};_0x3606b1[_0x40740e]={'$like':'%'+_0x5c202f[_0xd351('0x30')][_0xd351('0x3b')]+'%'};return _0x3606b1;})});}_0x3f6826=_['merge']({},_0x3f6826,_0x5c202f[_0xd351('0x46')]);return _0x54fc9c['getTeams'](_0x3f6826);}})[_0xd351('0x22')](function(_0x55d564){if(_0x55d564){_0x2443bd=_0x55d564['length'];if(!_0x5c202f[_0xd351('0x30')]['hasOwnProperty'](_0xd351('0x37'))){_0x3f6826[_0xd351('0x1b')]=qs[_0xd351('0x1b')](_0x5c202f[_0xd351('0x30')][_0xd351('0x1b')]);_0x3f6826[_0xd351('0x19')]=qs['offset'](_0x5c202f['query'][_0xd351('0x19')]);}return _0x54fc9c[_0xd351('0x72')](_0x3f6826);}})['then'](function(_0x3d3cfa){if(_0x3d3cfa){return _0x3d3cfa?{'count':_0x2443bd,'rows':_0x3d3cfa}:null;}})['then'](respondWithResult(_0x426964,null))[_0xd351('0x41')](handleError(_0x426964,null));};exports[_0xd351('0x73')]=function(_0x6fd03b,_0x19d16a,_0x127bf9){var _0x4ab9b9=_0x6fd03b[_0xd351('0x4a')]['ids'];var _0x581e66;return db[_0xd351('0x71')][_0xd351('0x40')]({'where':{'id':_0x4ab9b9},'attributes':['id'],'include':[{'model':db[_0xd351('0x6f')],'as':'Agents','attributes':['id','name',_0xd351('0x74'),_0xd351('0x75'),_0xd351('0x76')],'raw':!![]}]})[_0xd351('0x22')](function(_0x1ddacf){if(_0x1ddacf){_0x581e66=_0x1ddacf;var _0x4cadbe=_[_0xd351('0x77')](_0x1ddacf,function(_0x269bf6){var _0x3da123=_0x269bf6[_0xd351('0x4e')]({'plain':!![]});return _0x3da123['Agents'];});return db[_0xd351('0x3f')][_0xd351('0x4f')]({'where':{'id':_0x6fd03b['params']['id']}})[_0xd351('0x22')](function(_0x46745f){return db[_0xd351('0x78')][_0xd351('0x49')](function(_0x37d882){return _0x46745f['addTeams'](_0x4ab9b9,{'transaction':_0x37d882})[_0xd351('0x22')](function(){return BPromise[_0xd351('0x79')](_0x581e66,function(_0x5ceda1){return db[_0xd351('0x7a')]['upsert']({'TeamId':_0x5ceda1['id'],'VoicePrefixId':_0x6fd03b[_0xd351('0x43')]['id']},{'transaction':_0x37d882});});})[_0xd351('0x22')](function(){return BPromise['each'](_0x4cadbe,function(_0x1f0812){return db[_0xd351('0x7b')][_0xd351('0x7c')]({'where':{'UserId':_0x1f0812['id'],'VoicePrefixId':_0x6fd03b[_0xd351('0x43')]['id']},'transaction':_0x37d882});});})[_0xd351('0x22')](function(){_0x4cadbe['forEach'](function(_0x23b2fe){socket['emit'](_0xd351('0x69'),{'UserId':_0x23b2fe['id'],'VoicePrefixId':_0x46745f['id']});});});});});}})[_0xd351('0x22')](respondWithStatusCode(_0x19d16a,null))[_0xd351('0x41')](handleError(_0x19d16a,null));};exports[_0xd351('0x7d')]=function(_0x160102,_0x24ac40,_0x3b2690){return db[_0xd351('0x71')][_0xd351('0x40')]({'where':{'id':_0x160102['query'][_0xd351('0x66')]},'attributes':['id'],'include':[{'model':db[_0xd351('0x6f')],'as':_0xd351('0x7e'),'attributes':['id'],'raw':!![]}]})[_0xd351('0x22')](handleEntityNotFound(_0x24ac40,null))['then'](function(_0x280220){var _0x4f8f00=_[_0xd351('0x2b')](_0x280220,'id');var _0x107886=[];var _0x3a3633=[];var _0x403312=squel[_0xd351('0x7f')]();_0x403312['field'](_0xd351('0x80'))[_0xd351('0x81')]('team_has_voice_prefixes','tq')['join'](_0xd351('0x82'),'ut',_0xd351('0x83'))[_0xd351('0x39')](_0xd351('0x84'),_0x160102[_0xd351('0x43')]['id']);for(var _0x1373c0=0x0;_0x1373c0<_0x280220[_0xd351('0x44')];_0x1373c0+=0x1){let _0x78b55c=_0x280220[_0x1373c0];for(var _0x2de03c=0x0;_0x2de03c<_0x78b55c[_0xd351('0x7e')][_0xd351('0x44')];_0x2de03c+=0x1){let _0x6f4c1e=_0x78b55c[_0xd351('0x7e')][_0x2de03c];var _0x56b88b=_0x403312['clone']();_0x56b88b[_0xd351('0x39')]('ut.UserId\x20=\x20?',_0x6f4c1e['id']);_0x3a3633[_0xd351('0x5f')](db[_0xd351('0x78')][_0xd351('0x30')](_0x56b88b[_0xd351('0x85')](),{'type':db[_0xd351('0x78')][_0xd351('0x86')]['SELECT']})[_0xd351('0x22')](function(_0x2725c4){if(_0x2725c4['length']===0x1){return _0x6f4c1e['id'];}else{var _0x31c1dc=_['every'](_['map'](_0x2725c4,_0xd351('0x87')),function(_0x2f188b){return _['includes'](_0x4f8f00,_0x2f188b);});if(_0x31c1dc){return _0x6f4c1e['id'];}}}));}}return BPromise[_0xd351('0x88')](_0x3a3633)[_0xd351('0x22')](function(_0x5126a1){_0x107886=_(_0x107886)[_0xd351('0x89')](_0x5126a1)[_0xd351('0x8a')]()[_0xd351('0x8b')]();return db[_0xd351('0x3f')][_0xd351('0x4f')]({'where':{'id':_0x160102['params']['id']}})[_0xd351('0x22')](function(_0x1db9db){return db[_0xd351('0x78')][_0xd351('0x49')](function(_0x2ef116){return _0x1db9db[_0xd351('0x7d')](_0x160102[_0xd351('0x30')][_0xd351('0x66')],{'transaction':_0x2ef116})[_0xd351('0x22')](function(){if(!_[_0xd351('0x8c')](_0x107886)){return _0x1db9db[_0xd351('0x6a')](_0x107886,{'transaction':_0x2ef116});}})[_0xd351('0x22')](function(){_0x107886[_0xd351('0x8d')](function(_0x585e94){socket[_0xd351('0x68')](_0xd351('0x6c'),{'UserId':_0x585e94,'VoicePrefixId':_0x1db9db['id']});});});});});});})[_0xd351('0x22')](respondWithStatusCode(_0x24ac40,null))[_0xd351('0x41')](handleError(_0x24ac40,null));};
\ No newline at end of file
+var _0x5f2f=['VoicePrefixes','UserProfileResource','error','stack','name','send','map','VoicePrefix','rawAttributes','type','key','model','query','keys','filters','intersection','fields','attributes','length','nolimit','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','show','params','find','describe','create','transaction','body','get','VoiceExtension','user','role','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','from-sip','app','system','description','Voice\x20Prefix\x20Extension','appdata','Voice\x20Prefix','VoiceExtensionId','VoicePrefixId','Extensions\x20creation\x20failed','push','Set','CDR(prefix)=','callerIdAll','PREFIX-CALLERIDALL=','NoOp','No\x20callerid\x20available','goto','context','charAt','prefix','system-','sequelize','findById','addAgents','ids','omit','spread','emit','removeAgents','isArray','userVoicePrefix:remove','getAgents','order','hasOwnProperty','getTeams','findOne','Team','addTeams','User','Agents','online','voicePause','flatMap','each','TeamVoicePrefix','UserVoicePrefix','findOrCreate','forEach','userVoicePrefix:save','select','tq.TeamId','from','team_has_voice_prefixes','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','VoicePrefixId\x20=\x20?','clone','ut.UserId\x20=\x20?','toString','QueryTypes','SELECT','every','TeamId','all','union','compact','value','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','./voicePrefix.socket','register','sendStatus','status','end','json','offset','undefined','limit','set','Content-Range','apply','reject','save','update','then','destroy'];(function(_0x1177d5,_0x22b649){var _0xc3ddc2=function(_0x43ff95){while(--_0x43ff95){_0x1177d5['push'](_0x1177d5['shift']());}};_0xc3ddc2(++_0x22b649);}(_0x5f2f,0x73));var _0xf5f2=function(_0x25cdd2,_0x1150f9){_0x25cdd2=_0x25cdd2-0x0;var _0x1c76ce=_0x5f2f[_0x25cdd2];return _0x1c76ce;};'use strict';var emlformat=require(_0xf5f2('0x0'));var rimraf=require(_0xf5f2('0x1'));var zipdir=require(_0xf5f2('0x2'));var jsonpatch=require(_0xf5f2('0x3'));var rp=require(_0xf5f2('0x4'));var moment=require(_0xf5f2('0x5'));var BPromise=require(_0xf5f2('0x6'));var Mustache=require(_0xf5f2('0x7'));var util=require('util');var path=require('path');var sox=require(_0xf5f2('0x8'));var csv=require(_0xf5f2('0x9'));var ejs=require(_0xf5f2('0xa'));var fs=require('fs');var fs_extra=require(_0xf5f2('0xb'));var _=require(_0xf5f2('0xc'));var squel=require(_0xf5f2('0xd'));var crypto=require('crypto');var jsforce=require(_0xf5f2('0xe'));var deskjs=require(_0xf5f2('0xf'));var toCsv=require(_0xf5f2('0x9'));var querystring=require('querystring');var Papa=require(_0xf5f2('0x10'));var Redis=require(_0xf5f2('0x11'));var authService=require(_0xf5f2('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xf5f2('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xf5f2('0x14'));var utils=require(_0xf5f2('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xf5f2('0x16'));var db=require(_0xf5f2('0x17'))['db'];config[_0xf5f2('0x18')]=_[_0xf5f2('0x19')](config[_0xf5f2('0x18')],{'host':_0xf5f2('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf5f2('0x18')]));require(_0xf5f2('0x1b'))[_0xf5f2('0x1c')](socket);function respondWithStatusCode(_0x1c1a5c,_0x422b55){_0x422b55=_0x422b55||0xcc;return function(_0x4d97fc){if(_0x4d97fc){return _0x1c1a5c[_0xf5f2('0x1d')](_0x422b55);}return _0x1c1a5c[_0xf5f2('0x1e')](_0x422b55)[_0xf5f2('0x1f')]();};}function respondWithResult(_0x1b6dd2,_0x23e23a){_0x23e23a=_0x23e23a||0xc8;return function(_0x3a9dbb){if(_0x3a9dbb){return _0x1b6dd2[_0xf5f2('0x1e')](_0x23e23a)[_0xf5f2('0x20')](_0x3a9dbb);}};}function respondWithFilteredResult(_0x11f702,_0x228ace){return function(_0x20fccd){if(_0x20fccd){var _0x28e097=typeof _0x228ace[_0xf5f2('0x21')]===_0xf5f2('0x22')&&typeof _0x228ace[_0xf5f2('0x23')]===_0xf5f2('0x22');var _0x1bf655=_0x20fccd['count'];var _0x34706d=_0x28e097?0x0:_0x228ace[_0xf5f2('0x21')];var _0x49dac2=_0x28e097?_0x20fccd['count']:_0x228ace[_0xf5f2('0x21')]+_0x228ace[_0xf5f2('0x23')];var _0x4ae323;if(_0x49dac2>=_0x1bf655){_0x49dac2=_0x1bf655;_0x4ae323=0xc8;}else{_0x4ae323=0xce;}_0x11f702[_0xf5f2('0x1e')](_0x4ae323);return _0x11f702[_0xf5f2('0x24')](_0xf5f2('0x25'),_0x34706d+'-'+_0x49dac2+'/'+_0x1bf655)[_0xf5f2('0x20')](_0x20fccd);}return null;};}function patchUpdates(_0x36f1cb){return function(_0x4c691a){try{jsonpatch[_0xf5f2('0x26')](_0x4c691a,_0x36f1cb,!![]);}catch(_0x4669a6){return BPromise[_0xf5f2('0x27')](_0x4669a6);}return _0x4c691a[_0xf5f2('0x28')]();};}function saveUpdates(_0x287ad5,_0x5bdf4a){return function(_0x529f07){if(_0x529f07){return _0x529f07[_0xf5f2('0x29')](_0x287ad5)[_0xf5f2('0x2a')](function(_0x13da6f){return _0x13da6f;});}return null;};}function removeEntity(_0x1a5bb3,_0xf6c58d){return function(_0x788a8d){if(_0x788a8d){return _0x788a8d[_0xf5f2('0x2b')]()[_0xf5f2('0x2a')](function(){var _0x294414=_0x788a8d['get']({'plain':!![]});var _0xaa2602=_0xf5f2('0x2c');return db[_0xf5f2('0x2d')][_0xf5f2('0x2b')]({'where':{'type':_0xaa2602,'resourceId':_0x294414['id']}})[_0xf5f2('0x2a')](function(){return _0x788a8d;});})[_0xf5f2('0x2a')](function(){_0x1a5bb3['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x22c826,_0x14c829){return function(_0x11c771){if(!_0x11c771){_0x22c826['sendStatus'](0x194);}return _0x11c771;};}function handleError(_0x5a2c7e,_0x29571b){_0x29571b=_0x29571b||0x1f4;return function(_0x50b8a2){logger[_0xf5f2('0x2e')](_0x50b8a2[_0xf5f2('0x2f')]);if(_0x50b8a2[_0xf5f2('0x30')]){delete _0x50b8a2['name'];}_0x5a2c7e['status'](_0x29571b)[_0xf5f2('0x31')](_0x50b8a2);};}exports['index']=function(_0xb744b9,_0x58a4df){var _0x45b643={},_0x31087c={},_0x7b6817={'count':0x0,'rows':[]};var _0x428770=_[_0xf5f2('0x32')](db[_0xf5f2('0x33')][_0xf5f2('0x34')],function(_0x2c0e05){return{'name':_0x2c0e05['fieldName'],'type':_0x2c0e05[_0xf5f2('0x35')][_0xf5f2('0x36')]};});_0x31087c[_0xf5f2('0x37')]=_[_0xf5f2('0x32')](_0x428770,_0xf5f2('0x30'));_0x31087c[_0xf5f2('0x38')]=_[_0xf5f2('0x39')](_0xb744b9['query']);_0x31087c[_0xf5f2('0x3a')]=_[_0xf5f2('0x3b')](_0x31087c['model'],_0x31087c[_0xf5f2('0x38')]);_0x45b643['attributes']=_[_0xf5f2('0x3b')](_0x31087c[_0xf5f2('0x37')],qs[_0xf5f2('0x3c')](_0xb744b9[_0xf5f2('0x38')]['fields']));_0x45b643['attributes']=_0x45b643[_0xf5f2('0x3d')][_0xf5f2('0x3e')]?_0x45b643[_0xf5f2('0x3d')]:_0x31087c['model'];if(!_0xb744b9[_0xf5f2('0x38')]['hasOwnProperty'](_0xf5f2('0x3f'))){_0x45b643['limit']=qs[_0xf5f2('0x23')](_0xb744b9[_0xf5f2('0x38')]['limit']);_0x45b643[_0xf5f2('0x21')]=qs[_0xf5f2('0x21')](_0xb744b9[_0xf5f2('0x38')][_0xf5f2('0x21')]);}_0x45b643['order']=qs['sort'](_0xb744b9[_0xf5f2('0x38')][_0xf5f2('0x40')]);_0x45b643[_0xf5f2('0x41')]=qs[_0xf5f2('0x3a')](_[_0xf5f2('0x42')](_0xb744b9[_0xf5f2('0x38')],_0x31087c[_0xf5f2('0x3a')]),_0x428770);if(_0xb744b9['query'][_0xf5f2('0x43')]){_0x45b643[_0xf5f2('0x41')]=_['merge'](_0x45b643[_0xf5f2('0x41')],{'$or':_[_0xf5f2('0x32')](_0x428770,function(_0x71b0e7){if(_0x71b0e7[_0xf5f2('0x35')]!==_0xf5f2('0x44')){var _0x3b6372={};_0x3b6372[_0x71b0e7[_0xf5f2('0x30')]]={'$like':'%'+_0xb744b9[_0xf5f2('0x38')]['filter']+'%'};return _0x3b6372;}})});}_0x45b643=_[_0xf5f2('0x45')]({},_0x45b643,_0xb744b9[_0xf5f2('0x46')]);var _0x17a78e={'where':_0x45b643['where']};return db['VoicePrefix']['count'](_0x17a78e)[_0xf5f2('0x2a')](function(_0x2ad13c){_0x7b6817['count']=_0x2ad13c;if(_0xb744b9[_0xf5f2('0x38')][_0xf5f2('0x47')]){_0x45b643[_0xf5f2('0x48')]=[{'all':!![]}];}return db[_0xf5f2('0x33')][_0xf5f2('0x49')](_0x45b643);})[_0xf5f2('0x2a')](function(_0x1a6ec1){_0x7b6817[_0xf5f2('0x4a')]=_0x1a6ec1;return _0x7b6817;})[_0xf5f2('0x2a')](respondWithFilteredResult(_0x58a4df,_0x45b643))[_0xf5f2('0x4b')](handleError(_0x58a4df,null));};exports[_0xf5f2('0x4c')]=function(_0x4773cd,_0x4252a3){var _0x2fb67e={'raw':![],'where':{'id':_0x4773cd[_0xf5f2('0x4d')]['id']}},_0x4faeed={};_0x4faeed['model']=_[_0xf5f2('0x39')](db[_0xf5f2('0x33')][_0xf5f2('0x34')]);_0x4faeed[_0xf5f2('0x38')]=_[_0xf5f2('0x39')](_0x4773cd[_0xf5f2('0x38')]);_0x4faeed['filters']=_[_0xf5f2('0x3b')](_0x4faeed[_0xf5f2('0x37')],_0x4faeed[_0xf5f2('0x38')]);_0x2fb67e[_0xf5f2('0x3d')]=_[_0xf5f2('0x3b')](_0x4faeed[_0xf5f2('0x37')],qs[_0xf5f2('0x3c')](_0x4773cd[_0xf5f2('0x38')]['fields']));_0x2fb67e[_0xf5f2('0x3d')]=_0x2fb67e[_0xf5f2('0x3d')][_0xf5f2('0x3e')]?_0x2fb67e['attributes']:_0x4faeed[_0xf5f2('0x37')];if(_0x4773cd[_0xf5f2('0x38')][_0xf5f2('0x47')]){_0x2fb67e['include']=[{'all':!![]}];}_0x2fb67e=_['merge']({},_0x2fb67e,_0x4773cd[_0xf5f2('0x46')]);return db[_0xf5f2('0x33')]['find'](_0x2fb67e)[_0xf5f2('0x2a')](handleEntityNotFound(_0x4252a3,null))['then'](respondWithResult(_0x4252a3,null))[_0xf5f2('0x4b')](handleError(_0x4252a3,null));};exports['destroy']=function(_0x2cbd9d,_0x5d9120){return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x2cbd9d[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x5d9120,null))['then'](removeEntity(_0x5d9120,null))[_0xf5f2('0x4b')](handleError(_0x5d9120,null));};exports[_0xf5f2('0x4f')]=function(_0x4f6b01,_0x58213b){return db[_0xf5f2('0x33')][_0xf5f2('0x4f')]()['then'](respondWithResult(_0x58213b,null))[_0xf5f2('0x4b')](handleError(_0x58213b,null));};exports[_0xf5f2('0x50')]=function(_0x29c9b6,_0x41b1c7){var _0x5d0db0;return db['sequelize'][_0xf5f2('0x51')](function(_0xa3cc67){return db['VoicePrefix'][_0xf5f2('0x50')](_0x29c9b6[_0xf5f2('0x52')],{'transaction':_0xa3cc67})[_0xf5f2('0x2a')](function(_0x14029e){_0x5d0db0=_0x14029e[_0xf5f2('0x53')]({'plain':!![]});return db[_0xf5f2('0x54')][_0xf5f2('0x4e')]({'where':{'id':_0x5d0db0['VoiceExtensionId']},'raw':!![]})['then'](function(_0x330730){return createVoicePrefixExtensions(_0x5d0db0,_0x330730,_0xa3cc67);});});})[_0xf5f2('0x2a')](function(){var _0x3c349f=_0x29c9b6[_0xf5f2('0x55')][_0xf5f2('0x53')]({'plain':!![]});if(!_0x3c349f)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3c349f[_0xf5f2('0x56')]===_0xf5f2('0x55')){var _0x18b124=_0x5d0db0;return db['UserProfileSection'][_0xf5f2('0x4e')]({'where':{'name':'VoicePrefixes','userProfileId':_0x3c349f[_0xf5f2('0x57')]},'raw':!![]})[_0xf5f2('0x2a')](function(_0x28cce5){if(_0x28cce5&&_0x28cce5[_0xf5f2('0x58')]===0x0){return db['UserProfileResource']['create']({'name':_0x18b124[_0xf5f2('0x30')],'resourceId':_0x18b124['id'],'type':_0x28cce5['name'],'sectionId':_0x28cce5['id']},{})[_0xf5f2('0x2a')](function(){return _0x5d0db0;});}else{return _0x5d0db0;}})[_0xf5f2('0x4b')](function(_0x572ec1){logger[_0xf5f2('0x2e')](_0xf5f2('0x59'),_0x572ec1);throw _0x572ec1;});}return _0x5d0db0;})[_0xf5f2('0x2a')](respondWithResult(_0x41b1c7,null))['catch'](handleError(_0x41b1c7,null));};function Extension(_0x397b99,_0xcf7a50,_0x42cc27,_0x4579f4){this['context']=_0xf5f2('0x5a');this['exten']=_0x397b99;this[_0xf5f2('0x5b')]=_0x42cc27;this[_0xf5f2('0x35')]=_0xf5f2('0x5c');this[_0xf5f2('0x5d')]=_0xf5f2('0x5e');this['priority']=_0xcf7a50;this[_0xf5f2('0x5f')]=_0x4579f4;}function createVoicePrefixExtensions(_0xacd80,_0x3461e5,_0x212639){return new BPromise(function(_0x2c5733,_0x5359b5){var _0x31e16b=new Extension(formatPrefixName(_0xacd80['prefix']),0x1,'NoOp',_0xf5f2('0x60'));_0x31e16b['VoicePrefixId']=_0xacd80['id'];return db[_0xf5f2('0x54')][_0xf5f2('0x50')](_0x31e16b,{'transaction':_0x212639})[_0xf5f2('0x2a')](function(_0x123b93){var _0x5767fc=_0x123b93[_0xf5f2('0x53')]({'plain':!![]});var _0x3a53f2=_[_0xf5f2('0x32')](addVoicePrefixExtensions(_0xacd80,_0x3461e5),function(_0x18c41f){_0x18c41f[_0xf5f2('0x61')]=_0x5767fc['id'];_0x18c41f[_0xf5f2('0x62')]=_0xacd80['id'];return _0x18c41f;});return db[_0xf5f2('0x54')]['bulkCreate'](_0x3a53f2,{'transaction':_0x212639})[_0xf5f2('0x2a')](function(_0x2d171d){if(!_0x2d171d){return _0x5359b5(_0xf5f2('0x63'));}else{return _0x2c5733(_0x2d171d);}})[_0xf5f2('0x4b')](function(_0x5a5b2b){return _0x5359b5(_0x5a5b2b);});});;});};function addVoicePrefixExtensions(_0x1de396,_0x4cce08){var _0x410866=[];var _0x1c7f06=formatPrefixName(_0x1de396['prefix']);_0x410866[_0xf5f2('0x64')](new Extension(_0x1c7f06,0x2,_0xf5f2('0x65'),_0xf5f2('0x66')+_0x1de396[_0xf5f2('0x30')]));if(_0x1de396[_0xf5f2('0x67')]){_0x410866['push'](new Extension(_0x1c7f06,0x3,_0xf5f2('0x65'),_0xf5f2('0x68')+_0x1de396[_0xf5f2('0x67')]));}else{_0x410866[_0xf5f2('0x64')](new Extension(_0x1c7f06,0x3,_0xf5f2('0x69'),_0xf5f2('0x6a')));}_0x410866['push'](new Extension(_0x1c7f06,0x4,_0xf5f2('0x6b'),_0x4cce08[_0xf5f2('0x6c')]+','+'${EXTEN:'+(0x8+_0x1de396[_0xf5f2('0x30')][_0xf5f2('0x3e')])+'}'+','+0x1));return _0x410866;}function formatPrefixName(_0x377aad){var _0x51a3c7='_';for(var _0x551cc9=0x0;_0x551cc9<_0x377aad['length'];_0x551cc9++){if(_0x377aad[_0xf5f2('0x6d')](_0x551cc9)=='-'){_0x51a3c7+=_0x377aad[_0xf5f2('0x6d')](_0x551cc9);}else{_0x51a3c7+='['+_0x377aad[_0xf5f2('0x6d')](_0x551cc9)+']';}}_0x51a3c7+='.';return _0x51a3c7;}exports[_0xf5f2('0x29')]=function(_0x55da4d,_0x4d878e,_0x278b76){var _0x3a98b4=_0x55da4d[_0xf5f2('0x52')];_0x3a98b4[_0xf5f2('0x6e')]=_0xf5f2('0x6f')+_0x3a98b4[_0xf5f2('0x30')]+'-';return db[_0xf5f2('0x70')][_0xf5f2('0x51')](function(_0x155f45){return db[_0xf5f2('0x33')][_0xf5f2('0x29')](_0x3a98b4,{'where':{'id':_0x3a98b4['id']},'transaction':_0x155f45})['then'](function(){return db['VoiceExtension']['destroy']({'where':{'VoicePrefixId':_0x3a98b4['id']},'transaction':_0x155f45})[_0xf5f2('0x2a')](function(){return db[_0xf5f2('0x54')][_0xf5f2('0x4e')]({'where':{'id':_0x3a98b4[_0xf5f2('0x61')]},'raw':!![]})[_0xf5f2('0x2a')](function(_0x5c6959){return createVoicePrefixExtensions(_0x3a98b4,_0x5c6959,_0x155f45);});});});})[_0xf5f2('0x2a')](function(){return db[_0xf5f2('0x33')][_0xf5f2('0x71')](_0x3a98b4['id']);})[_0xf5f2('0x2a')](respondWithResult(_0x4d878e,null))[_0xf5f2('0x4b')](handleError(_0x4d878e,null));};exports['addAgents']=function(_0x2986ed,_0x1409b9,_0x517c15){return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x2986ed[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x1409b9,null))['then'](function(_0x40b36e){if(_0x40b36e){return _0x40b36e[_0xf5f2('0x72')](_0x2986ed[_0xf5f2('0x52')][_0xf5f2('0x73')],_[_0xf5f2('0x74')](_0x2986ed['body'],['ids','id'])||{})[_0xf5f2('0x75')](function(_0x30f362){for(var _0x17eb69=0x0;_0x17eb69<_0x2986ed[_0xf5f2('0x52')]['ids']['length'];_0x17eb69+=0x1){socket[_0xf5f2('0x76')]('userVoicePrefix:save',{'UserId':Number(_0x2986ed['body']['ids'][_0x17eb69]),'VoicePrefixId':Number(_0x2986ed['params']['id'])});}return _0x30f362;});}})[_0xf5f2('0x2a')](respondWithResult(_0x1409b9,null))[_0xf5f2('0x4b')](handleError(_0x1409b9,null));};exports[_0xf5f2('0x77')]=function(_0x168092,_0x3de508,_0x9f941e){return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x168092[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x3de508,null))[_0xf5f2('0x2a')](function(_0x2afeac){if(_0x2afeac){return _0x2afeac[_0xf5f2('0x77')](_0x168092[_0xf5f2('0x38')][_0xf5f2('0x73')])[_0xf5f2('0x2a')](function(){if(_[_0xf5f2('0x78')](_0x168092[_0xf5f2('0x38')]['ids'])){for(var _0xe7ac8=0x0;_0xe7ac8<_0x168092[_0xf5f2('0x38')][_0xf5f2('0x73')][_0xf5f2('0x3e')];_0xe7ac8+=0x1){socket[_0xf5f2('0x76')](_0xf5f2('0x79'),{'UserId':Number(_0x168092[_0xf5f2('0x38')][_0xf5f2('0x73')][_0xe7ac8]),'VoicePrefixId':Number(_0x168092['params']['id'])});}}else{socket[_0xf5f2('0x76')]('userVoicePrefix:remove',{'UserId':Number(_0x168092['query']['ids']),'VoicePrefixId':Number(_0x168092['params']['id'])});}});}})['then'](respondWithStatusCode(_0x3de508,null))['catch'](handleError(_0x3de508,null));};exports[_0xf5f2('0x7a')]=function(_0x18ce86,_0x26a57c,_0x375bc9){var _0x145d4d={};var _0x3cf857={};var _0x5dc63f;var _0x4a0005;return db[_0xf5f2('0x33')]['findOne']({'where':{'id':_0x18ce86[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x26a57c,null))['then'](function(_0x4f3ad4){if(_0x4f3ad4){_0x5dc63f=_0x4f3ad4;_0x3cf857[_0xf5f2('0x37')]=_[_0xf5f2('0x39')](db['User'][_0xf5f2('0x34')]);_0x3cf857[_0xf5f2('0x38')]=_['keys'](_0x18ce86[_0xf5f2('0x38')]);_0x3cf857[_0xf5f2('0x3a')]=_[_0xf5f2('0x3b')](_0x3cf857['model'],_0x3cf857[_0xf5f2('0x38')]);_0x145d4d[_0xf5f2('0x3d')]=_[_0xf5f2('0x3b')](_0x3cf857[_0xf5f2('0x37')],qs[_0xf5f2('0x3c')](_0x18ce86[_0xf5f2('0x38')][_0xf5f2('0x3c')]));_0x145d4d[_0xf5f2('0x3d')]=_0x145d4d[_0xf5f2('0x3d')][_0xf5f2('0x3e')]?_0x145d4d[_0xf5f2('0x3d')]:_0x3cf857[_0xf5f2('0x37')];_0x145d4d[_0xf5f2('0x7b')]=qs[_0xf5f2('0x40')](_0x18ce86[_0xf5f2('0x38')][_0xf5f2('0x40')]);_0x145d4d[_0xf5f2('0x41')]=qs[_0xf5f2('0x3a')](_[_0xf5f2('0x42')](_0x18ce86[_0xf5f2('0x38')],_0x3cf857[_0xf5f2('0x3a')]));if(_0x18ce86['query'][_0xf5f2('0x43')]){_0x145d4d[_0xf5f2('0x41')]=_['merge'](_0x145d4d[_0xf5f2('0x41')],{'$or':_[_0xf5f2('0x32')](_0x145d4d['attributes'],function(_0xb56304){var _0x2f54eb={};_0x2f54eb[_0xb56304]={'$like':'%'+_0x18ce86[_0xf5f2('0x38')]['filter']+'%'};return _0x2f54eb;})});}_0x145d4d=_['merge']({},_0x145d4d,_0x18ce86[_0xf5f2('0x46')]);return _0x5dc63f[_0xf5f2('0x7a')](_0x145d4d);}})[_0xf5f2('0x2a')](function(_0x5ba275){if(_0x5ba275){_0x4a0005=_0x5ba275['length'];if(!_0x18ce86[_0xf5f2('0x38')][_0xf5f2('0x7c')](_0xf5f2('0x3f'))){_0x145d4d['limit']=qs['limit'](_0x18ce86['query']['limit']);_0x145d4d['offset']=qs[_0xf5f2('0x21')](_0x18ce86['query'][_0xf5f2('0x21')]);}return _0x5dc63f[_0xf5f2('0x7a')](_0x145d4d);}})[_0xf5f2('0x2a')](function(_0x43a167){if(_0x43a167){return _0x43a167?{'count':_0x4a0005,'rows':_0x43a167}:null;}})[_0xf5f2('0x2a')](respondWithResult(_0x26a57c,null))[_0xf5f2('0x4b')](handleError(_0x26a57c,null));};exports[_0xf5f2('0x7d')]=function(_0x40e921,_0x3dc051,_0x27ca4a){var _0x1bb4ac={};var _0x36c3c8={};var _0x10c982;var _0x5e69a2;return db[_0xf5f2('0x33')][_0xf5f2('0x7e')]({'where':{'id':_0x40e921['params']['id']}})[_0xf5f2('0x2a')](handleEntityNotFound(_0x3dc051,null))[_0xf5f2('0x2a')](function(_0x537a7d){if(_0x537a7d){_0x10c982=_0x537a7d;_0x36c3c8[_0xf5f2('0x37')]=_[_0xf5f2('0x39')](db[_0xf5f2('0x7f')]['rawAttributes']);_0x36c3c8[_0xf5f2('0x38')]=_[_0xf5f2('0x39')](_0x40e921['query']);_0x36c3c8[_0xf5f2('0x3a')]=_[_0xf5f2('0x3b')](_0x36c3c8[_0xf5f2('0x37')],_0x36c3c8['query']);_0x1bb4ac[_0xf5f2('0x3d')]=_['intersection'](_0x36c3c8[_0xf5f2('0x37')],qs['fields'](_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x3c')]));_0x1bb4ac[_0xf5f2('0x3d')]=_0x1bb4ac[_0xf5f2('0x3d')]['length']?_0x1bb4ac[_0xf5f2('0x3d')]:_0x36c3c8['model'];_0x1bb4ac['order']=qs['sort'](_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x40')]);_0x1bb4ac['where']=qs[_0xf5f2('0x3a')](_[_0xf5f2('0x42')](_0x40e921[_0xf5f2('0x38')],_0x36c3c8[_0xf5f2('0x3a')]));if(_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x43')]){_0x1bb4ac['where']=_[_0xf5f2('0x45')](_0x1bb4ac[_0xf5f2('0x41')],{'$or':_['map'](_0x1bb4ac[_0xf5f2('0x3d')],function(_0x19cbff){var _0x58042c={};_0x58042c[_0x19cbff]={'$like':'%'+_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x43')]+'%'};return _0x58042c;})});}_0x1bb4ac=_[_0xf5f2('0x45')]({},_0x1bb4ac,_0x40e921[_0xf5f2('0x46')]);return _0x10c982[_0xf5f2('0x7d')](_0x1bb4ac);}})[_0xf5f2('0x2a')](function(_0x4df05c){if(_0x4df05c){_0x5e69a2=_0x4df05c[_0xf5f2('0x3e')];if(!_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x7c')](_0xf5f2('0x3f'))){_0x1bb4ac[_0xf5f2('0x23')]=qs[_0xf5f2('0x23')](_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x23')]);_0x1bb4ac[_0xf5f2('0x21')]=qs['offset'](_0x40e921[_0xf5f2('0x38')][_0xf5f2('0x21')]);}return _0x10c982[_0xf5f2('0x7d')](_0x1bb4ac);}})[_0xf5f2('0x2a')](function(_0x35fe1a){if(_0x35fe1a){return _0x35fe1a?{'count':_0x5e69a2,'rows':_0x35fe1a}:null;}})[_0xf5f2('0x2a')](respondWithResult(_0x3dc051,null))[_0xf5f2('0x4b')](handleError(_0x3dc051,null));};exports[_0xf5f2('0x80')]=function(_0x33cfe7,_0x40d0eb,_0x4c138c){var _0x52e419=_0x33cfe7[_0xf5f2('0x52')][_0xf5f2('0x73')];var _0x28eda5;return db[_0xf5f2('0x7f')]['findAll']({'where':{'id':_0x52e419},'attributes':['id'],'include':[{'model':db[_0xf5f2('0x81')],'as':_0xf5f2('0x82'),'attributes':['id',_0xf5f2('0x30'),_0xf5f2('0x83'),_0xf5f2('0x84'),'interface'],'raw':!![]}]})[_0xf5f2('0x2a')](function(_0x18d727){if(_0x18d727){_0x28eda5=_0x18d727;var _0x4bdb72=_[_0xf5f2('0x85')](_0x18d727,function(_0x3ff714){var _0x2563fa=_0x3ff714[_0xf5f2('0x53')]({'plain':!![]});return _0x2563fa['Agents'];});return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x33cfe7[_0xf5f2('0x4d')]['id']}})['then'](function(_0x489d4a){return db[_0xf5f2('0x70')][_0xf5f2('0x51')](function(_0x1432ef){return _0x489d4a[_0xf5f2('0x80')](_0x52e419,{'transaction':_0x1432ef})[_0xf5f2('0x2a')](function(){return BPromise[_0xf5f2('0x86')](_0x28eda5,function(_0x58711d){return db[_0xf5f2('0x87')]['upsert']({'TeamId':_0x58711d['id'],'VoicePrefixId':_0x33cfe7[_0xf5f2('0x4d')]['id']},{'transaction':_0x1432ef});});})[_0xf5f2('0x2a')](function(){return BPromise[_0xf5f2('0x86')](_0x4bdb72,function(_0xa74467){return db[_0xf5f2('0x88')][_0xf5f2('0x89')]({'where':{'UserId':_0xa74467['id'],'VoicePrefixId':_0x33cfe7['params']['id']},'transaction':_0x1432ef});});})[_0xf5f2('0x2a')](function(){_0x4bdb72[_0xf5f2('0x8a')](function(_0x457b53){socket[_0xf5f2('0x76')](_0xf5f2('0x8b'),{'UserId':_0x457b53['id'],'VoicePrefixId':_0x489d4a['id']});});});});});}})[_0xf5f2('0x2a')](respondWithStatusCode(_0x40d0eb,null))[_0xf5f2('0x4b')](handleError(_0x40d0eb,null));};exports['removeTeams']=function(_0x1ee541,_0x4a6b83,_0x5857d1){return db['Team'][_0xf5f2('0x49')]({'where':{'id':_0x1ee541[_0xf5f2('0x38')]['ids']},'attributes':['id'],'include':[{'model':db[_0xf5f2('0x81')],'as':_0xf5f2('0x82'),'attributes':['id'],'raw':!![]}]})[_0xf5f2('0x2a')](handleEntityNotFound(_0x4a6b83,null))[_0xf5f2('0x2a')](function(_0x4f2704){var _0x3075b4=_[_0xf5f2('0x32')](_0x4f2704,'id');var _0x10ac11=[];var _0x5d3ca7=[];var _0x29f7bd=squel[_0xf5f2('0x8c')]();_0x29f7bd['field'](_0xf5f2('0x8d'))[_0xf5f2('0x8e')](_0xf5f2('0x8f'),'tq')[_0xf5f2('0x90')](_0xf5f2('0x91'),'ut',_0xf5f2('0x92'))[_0xf5f2('0x41')](_0xf5f2('0x93'),_0x1ee541[_0xf5f2('0x4d')]['id']);for(var _0x4782da=0x0;_0x4782da<_0x4f2704[_0xf5f2('0x3e')];_0x4782da+=0x1){let _0x4b6146=_0x4f2704[_0x4782da];for(var _0x299c53=0x0;_0x299c53<_0x4b6146[_0xf5f2('0x82')]['length'];_0x299c53+=0x1){let _0x2275ba=_0x4b6146['Agents'][_0x299c53];var _0x3b2620=_0x29f7bd[_0xf5f2('0x94')]();_0x3b2620[_0xf5f2('0x41')](_0xf5f2('0x95'),_0x2275ba['id']);_0x5d3ca7['push'](db[_0xf5f2('0x70')]['query'](_0x3b2620[_0xf5f2('0x96')](),{'type':db['sequelize'][_0xf5f2('0x97')][_0xf5f2('0x98')]})['then'](function(_0x2bfc53){if(_0x2bfc53[_0xf5f2('0x3e')]===0x1){return _0x2275ba['id'];}else{var _0x16619b=_[_0xf5f2('0x99')](_[_0xf5f2('0x32')](_0x2bfc53,_0xf5f2('0x9a')),function(_0x54c86e){return _['includes'](_0x3075b4,_0x54c86e);});if(_0x16619b){return _0x2275ba['id'];}}}));}}return BPromise[_0xf5f2('0x9b')](_0x5d3ca7)[_0xf5f2('0x2a')](function(_0x5dc5da){_0x10ac11=_(_0x10ac11)[_0xf5f2('0x9c')](_0x5dc5da)[_0xf5f2('0x9d')]()[_0xf5f2('0x9e')]();return db[_0xf5f2('0x33')][_0xf5f2('0x4e')]({'where':{'id':_0x1ee541[_0xf5f2('0x4d')]['id']}})[_0xf5f2('0x2a')](function(_0x4f9e2d){return db[_0xf5f2('0x70')]['transaction'](function(_0x3ea1aa){return _0x4f9e2d['removeTeams'](_0x1ee541[_0xf5f2('0x38')]['ids'],{'transaction':_0x3ea1aa})[_0xf5f2('0x2a')](function(){if(!_['isEmpty'](_0x10ac11)){return _0x4f9e2d['removeAgents'](_0x10ac11,{'transaction':_0x3ea1aa});}})[_0xf5f2('0x2a')](function(){_0x10ac11[_0xf5f2('0x8a')](function(_0x57708f){socket[_0xf5f2('0x76')](_0xf5f2('0x79'),{'UserId':_0x57708f,'VoicePrefixId':_0x4f9e2d['id']});});});});});});})[_0xf5f2('0x2a')](respondWithStatusCode(_0x4a6b83,null))[_0xf5f2('0x4b')](handleError(_0x4a6b83,null));};
\ No newline at end of file