Built motion from commit b5996064.|2.6.21
[motion2.git] / server / api / voicePrefix / voicePrefix.controller.js
index b50586b..7e68c3f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xff24=['catch','params','include','find','describe','create','sequelize','transaction','body','VoiceExtension','VoiceExtensionId','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','context','app','system','description','Voice\x20Prefix\x20Extension','priority','appdata','prefix','Voice\x20Prefix','VoicePrefixId','bulkCreate','Extensions\x20creation\x20failed','push','Set','CDR(prefix)=','callerIdAll','No\x20callerid\x20available','goto','charAt','system-','findById','addAgents','ids','omit','spread','emit','userVoicePrefix:save','removeAgents','isArray','getAgents','findOne','User','rimraf','zip-dir','bluebird','mustache','util','path','sox','to-csv','lodash','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','./voicePrefix.socket','register','sendStatus','status','offset','limit','set','apply','reject','save','update','destroy','get','VoicePrefixes','UserProfileResource','then','end','error','stack','name','index','map','rawAttributes','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','type','VIRTUAL','options','VoicePrefix','count','includeAll','rows'];(function(_0x4b2863,_0x494899){var _0x567d67=function(_0x751f03){while(--_0x751f03){_0x4b2863['push'](_0x4b2863['shift']());}};_0x567d67(++_0x494899);}(_0xff24,0xa6));var _0x4ff2=function(_0x5934eb,_0x20167a){_0x5934eb=_0x5934eb-0x0;var _0xf5f2f6=_0xff24[_0x5934eb];return _0xf5f2f6;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x4ff2('0x0'));var zipdir=require(_0x4ff2('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x4ff2('0x2'));var Mustache=require(_0x4ff2('0x3'));var util=require(_0x4ff2('0x4'));var path=require(_0x4ff2('0x5'));var sox=require(_0x4ff2('0x6'));var csv=require(_0x4ff2('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x4ff2('0x8'));var squel=require(_0x4ff2('0x9'));var crypto=require(_0x4ff2('0xa'));var jsforce=require('jsforce');var deskjs=require(_0x4ff2('0xb'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x4ff2('0xc'));var Redis=require(_0x4ff2('0xd'));var authService=require(_0x4ff2('0xe'));var qs=require(_0x4ff2('0xf'));var as=require(_0x4ff2('0x10'));var hardwareService=require(_0x4ff2('0x11'));var logger=require(_0x4ff2('0x12'))(_0x4ff2('0x13'));var utils=require('../../config/utils');var config=require(_0x4ff2('0x14'));var db=require(_0x4ff2('0x15'))['db'];config[_0x4ff2('0x16')]=_[_0x4ff2('0x17')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4ff2('0x16')]));require(_0x4ff2('0x18'))[_0x4ff2('0x19')](socket);function respondWithStatusCode(_0x2aa440,_0xc2e081){_0xc2e081=_0xc2e081||0xcc;return function(_0x383e4e){if(_0x383e4e){return _0x2aa440[_0x4ff2('0x1a')](_0xc2e081);}return _0x2aa440[_0x4ff2('0x1b')](_0xc2e081)['end']();};}function respondWithResult(_0x1eba42,_0xb5dd63){_0xb5dd63=_0xb5dd63||0xc8;return function(_0x540438){if(_0x540438){return _0x1eba42[_0x4ff2('0x1b')](_0xb5dd63)['json'](_0x540438);}};}function respondWithFilteredResult(_0x5b19d9,_0x5b9bc7){return function(_0x613fac){if(_0x613fac){var _0x4eb779=_0x613fac['count'],_0x1011d1=_0x5b9bc7[_0x4ff2('0x1c')],_0xf9900=_0x5b9bc7[_0x4ff2('0x1c')]+_0x5b9bc7[_0x4ff2('0x1d')],_0x72dbf9;if(_0xf9900>=_0x4eb779){_0xf9900=_0x4eb779;_0x72dbf9=0xc8;}else{_0x72dbf9=0xce;}_0x5b19d9[_0x4ff2('0x1b')](_0x72dbf9);return _0x5b19d9[_0x4ff2('0x1e')]('Content-Range',_0x1011d1+'-'+_0xf9900+'/'+_0x4eb779)['json'](_0x613fac);}return null;};}function patchUpdates(_0x4c6052){return function(_0x3f3b4f){try{jsonpatch[_0x4ff2('0x1f')](_0x3f3b4f,_0x4c6052,!![]);}catch(_0x191eb7){return BPromise[_0x4ff2('0x20')](_0x191eb7);}return _0x3f3b4f[_0x4ff2('0x21')]();};}function saveUpdates(_0x400f83,_0xb92773){return function(_0x4d4249){if(_0x4d4249){return _0x4d4249[_0x4ff2('0x22')](_0x400f83)['then'](function(_0x3c24d5){return _0x3c24d5;});}return null;};}function removeEntity(_0x27dab5,_0x202c5c){return function(_0x362b7f){if(_0x362b7f){return _0x362b7f[_0x4ff2('0x23')]()['then'](function(){var _0x30ee5d=_0x362b7f[_0x4ff2('0x24')]({'plain':!![]});var _0x312e31=_0x4ff2('0x25');return db[_0x4ff2('0x26')][_0x4ff2('0x23')]({'where':{'type':_0x312e31,'resourceId':_0x30ee5d['id']}})[_0x4ff2('0x27')](function(){return _0x362b7f;});})[_0x4ff2('0x27')](function(){_0x27dab5[_0x4ff2('0x1b')](0xcc)[_0x4ff2('0x28')]();});}};}function handleEntityNotFound(_0x16ecf2,_0x267d8d){return function(_0x27e8fd){if(!_0x27e8fd){_0x16ecf2[_0x4ff2('0x1a')](0x194);}return _0x27e8fd;};}function handleError(_0x35f070,_0x311a6f){_0x311a6f=_0x311a6f||0x1f4;return function(_0x4558c3){logger[_0x4ff2('0x29')](_0x4558c3[_0x4ff2('0x2a')]);if(_0x4558c3[_0x4ff2('0x2b')]){delete _0x4558c3[_0x4ff2('0x2b')];}_0x35f070[_0x4ff2('0x1b')](_0x311a6f)['send'](_0x4558c3);};}exports[_0x4ff2('0x2c')]=function(_0x21edc9,_0x4f0375){var _0x55bb4e={},_0x533350={},_0x177088={'count':0x0,'rows':[]};var _0x2827dc=_[_0x4ff2('0x2d')](db['VoicePrefix'][_0x4ff2('0x2e')],function(_0x180ace){return{'name':_0x180ace['fieldName'],'type':_0x180ace['type']['key']};});_0x533350[_0x4ff2('0x2f')]=_['map'](_0x2827dc,'name');_0x533350[_0x4ff2('0x30')]=_[_0x4ff2('0x31')](_0x21edc9[_0x4ff2('0x30')]);_0x533350[_0x4ff2('0x32')]=_[_0x4ff2('0x33')](_0x533350[_0x4ff2('0x2f')],_0x533350['query']);_0x55bb4e['attributes']=_[_0x4ff2('0x33')](_0x533350[_0x4ff2('0x2f')],qs[_0x4ff2('0x34')](_0x21edc9['query'][_0x4ff2('0x34')]));_0x55bb4e[_0x4ff2('0x35')]=_0x55bb4e[_0x4ff2('0x35')][_0x4ff2('0x36')]?_0x55bb4e['attributes']:_0x533350[_0x4ff2('0x2f')];if(!_0x21edc9['query'][_0x4ff2('0x37')](_0x4ff2('0x38'))){_0x55bb4e[_0x4ff2('0x1d')]=qs[_0x4ff2('0x1d')](_0x21edc9[_0x4ff2('0x30')][_0x4ff2('0x1d')]);_0x55bb4e['offset']=qs[_0x4ff2('0x1c')](_0x21edc9['query'][_0x4ff2('0x1c')]);}_0x55bb4e[_0x4ff2('0x39')]=qs[_0x4ff2('0x3a')](_0x21edc9['query'][_0x4ff2('0x3a')]);_0x55bb4e['where']=qs[_0x4ff2('0x32')](_[_0x4ff2('0x3b')](_0x21edc9['query'],_0x533350[_0x4ff2('0x32')]));if(_0x21edc9[_0x4ff2('0x30')][_0x4ff2('0x3c')]){_0x55bb4e[_0x4ff2('0x3d')]=_[_0x4ff2('0x3e')](_0x55bb4e[_0x4ff2('0x3d')],{'$or':_['map'](_0x2827dc,function(_0xdc70aa){if(_0xdc70aa[_0x4ff2('0x3f')]!==_0x4ff2('0x40')){var _0x515b4e={};_0x515b4e[_0xdc70aa[_0x4ff2('0x2b')]]={'$like':'%'+_0x21edc9['query'][_0x4ff2('0x3c')]+'%'};return _0x515b4e;}})});}_0x55bb4e=_[_0x4ff2('0x3e')]({},_0x55bb4e,_0x21edc9[_0x4ff2('0x41')]);var _0x314145={'where':_0x55bb4e[_0x4ff2('0x3d')]};return db[_0x4ff2('0x42')][_0x4ff2('0x43')](_0x314145)[_0x4ff2('0x27')](function(_0x5c373b){_0x177088[_0x4ff2('0x43')]=_0x5c373b;if(_0x21edc9[_0x4ff2('0x30')][_0x4ff2('0x44')]){_0x55bb4e['include']=[{'all':!![]}];}return db[_0x4ff2('0x42')]['findAll'](_0x55bb4e);})[_0x4ff2('0x27')](function(_0x172441){_0x177088[_0x4ff2('0x45')]=_0x172441;return _0x177088;})[_0x4ff2('0x27')](respondWithFilteredResult(_0x4f0375,_0x55bb4e))[_0x4ff2('0x46')](handleError(_0x4f0375,null));};exports['show']=function(_0x3baaeb,_0x56d650){var _0x39e11a={'raw':![],'where':{'id':_0x3baaeb[_0x4ff2('0x47')]['id']}},_0x5b10e6={};_0x5b10e6[_0x4ff2('0x2f')]=_[_0x4ff2('0x31')](db[_0x4ff2('0x42')][_0x4ff2('0x2e')]);_0x5b10e6[_0x4ff2('0x30')]=_['keys'](_0x3baaeb[_0x4ff2('0x30')]);_0x5b10e6[_0x4ff2('0x32')]=_['intersection'](_0x5b10e6['model'],_0x5b10e6[_0x4ff2('0x30')]);_0x39e11a[_0x4ff2('0x35')]=_['intersection'](_0x5b10e6[_0x4ff2('0x2f')],qs[_0x4ff2('0x34')](_0x3baaeb[_0x4ff2('0x30')][_0x4ff2('0x34')]));_0x39e11a[_0x4ff2('0x35')]=_0x39e11a['attributes'][_0x4ff2('0x36')]?_0x39e11a[_0x4ff2('0x35')]:_0x5b10e6[_0x4ff2('0x2f')];if(_0x3baaeb[_0x4ff2('0x30')]['includeAll']){_0x39e11a[_0x4ff2('0x48')]=[{'all':!![]}];}_0x39e11a=_[_0x4ff2('0x3e')]({},_0x39e11a,_0x3baaeb['options']);return db[_0x4ff2('0x42')][_0x4ff2('0x49')](_0x39e11a)[_0x4ff2('0x27')](handleEntityNotFound(_0x56d650,null))[_0x4ff2('0x27')](respondWithResult(_0x56d650,null))[_0x4ff2('0x46')](handleError(_0x56d650,null));};exports['destroy']=function(_0x239be6,_0x4af616){return db[_0x4ff2('0x42')][_0x4ff2('0x49')]({'where':{'id':_0x239be6['params']['id']}})[_0x4ff2('0x27')](handleEntityNotFound(_0x4af616,null))[_0x4ff2('0x27')](removeEntity(_0x4af616,null))['catch'](handleError(_0x4af616,null));};exports[_0x4ff2('0x4a')]=function(_0x5d4a58,_0x35a9b9){return db[_0x4ff2('0x42')][_0x4ff2('0x4a')]()[_0x4ff2('0x27')](respondWithResult(_0x35a9b9,null))[_0x4ff2('0x46')](handleError(_0x35a9b9,null));};exports[_0x4ff2('0x4b')]=function(_0x37ae7b,_0x504b0f){var _0x3e2e5f;return db[_0x4ff2('0x4c')][_0x4ff2('0x4d')](function(_0xeeb06e){return db[_0x4ff2('0x42')][_0x4ff2('0x4b')](_0x37ae7b[_0x4ff2('0x4e')],{'transaction':_0xeeb06e})[_0x4ff2('0x27')](function(_0x465c08){_0x3e2e5f=_0x465c08[_0x4ff2('0x24')]({'plain':!![]});return db[_0x4ff2('0x4f')][_0x4ff2('0x49')]({'where':{'id':_0x3e2e5f[_0x4ff2('0x50')]},'raw':!![]})[_0x4ff2('0x27')](function(_0x4bbaff){return createVoicePrefixExtensions(_0x3e2e5f,_0x4bbaff,_0xeeb06e);});});})['then'](function(){var _0x35f287=_0x37ae7b[_0x4ff2('0x51')][_0x4ff2('0x24')]({'plain':!![]});if(!_0x35f287)throw new Error(_0x4ff2('0x52'));if(_0x35f287[_0x4ff2('0x53')]===_0x4ff2('0x51')){var _0x59029b=_0x3e2e5f;return db['UserProfileSection']['find']({'where':{'name':_0x4ff2('0x25'),'userProfileId':_0x35f287[_0x4ff2('0x54')]},'raw':!![]})[_0x4ff2('0x27')](function(_0x3b06a4){if(_0x3b06a4&&_0x3b06a4['autoAssociation']===0x0){return db['UserProfileResource'][_0x4ff2('0x4b')]({'name':_0x59029b[_0x4ff2('0x2b')],'resourceId':_0x59029b['id'],'type':_0x3b06a4[_0x4ff2('0x2b')],'sectionId':_0x3b06a4['id']},{})[_0x4ff2('0x27')](function(){return _0x3e2e5f;});}else{return _0x3e2e5f;}})[_0x4ff2('0x46')](function(_0x31f686){logger[_0x4ff2('0x29')](_0x4ff2('0x55'),_0x31f686);throw _0x31f686;});}return _0x3e2e5f;})[_0x4ff2('0x27')](respondWithResult(_0x504b0f,null))[_0x4ff2('0x46')](handleError(_0x504b0f,null));};function Extension(_0x43a1ef,_0x1443e2,_0x4dd425,_0x502924){this[_0x4ff2('0x56')]='from-sip';this['exten']=_0x43a1ef;this[_0x4ff2('0x57')]=_0x4dd425;this['type']=_0x4ff2('0x58');this[_0x4ff2('0x59')]=_0x4ff2('0x5a');this[_0x4ff2('0x5b')]=_0x1443e2;this[_0x4ff2('0x5c')]=_0x502924;}function createVoicePrefixExtensions(_0x231796,_0x267737,_0x135b3a){return new BPromise(function(_0x3d7707,_0x39347b){var _0x2c86c2=new Extension(formatPrefixName(_0x231796[_0x4ff2('0x5d')]),0x1,'NoOp',_0x4ff2('0x5e'));_0x2c86c2[_0x4ff2('0x5f')]=_0x231796['id'];return db[_0x4ff2('0x4f')]['create'](_0x2c86c2,{'transaction':_0x135b3a})['then'](function(_0xfaac8c){var _0x523ecd=_0xfaac8c[_0x4ff2('0x24')]({'plain':!![]});var _0x27ca49=_[_0x4ff2('0x2d')](addVoicePrefixExtensions(_0x231796,_0x267737),function(_0xea3fda){_0xea3fda['VoiceExtensionId']=_0x523ecd['id'];_0xea3fda[_0x4ff2('0x5f')]=_0x231796['id'];return _0xea3fda;});return db[_0x4ff2('0x4f')][_0x4ff2('0x60')](_0x27ca49,{'transaction':_0x135b3a})['then'](function(_0x52736b){if(!_0x52736b){return _0x39347b(_0x4ff2('0x61'));}else{return _0x3d7707(_0x52736b);}})[_0x4ff2('0x46')](function(_0x4da4e3){return _0x39347b(_0x4da4e3);});});;});};function addVoicePrefixExtensions(_0x2c14c3,_0x530f5a){var _0x3c0a11=[];var _0x598a29=formatPrefixName(_0x2c14c3[_0x4ff2('0x5d')]);_0x3c0a11[_0x4ff2('0x62')](new Extension(_0x598a29,0x2,_0x4ff2('0x63'),_0x4ff2('0x64')+_0x2c14c3[_0x4ff2('0x2b')]));if(_0x2c14c3['callerIdAll']){_0x3c0a11[_0x4ff2('0x62')](new Extension(_0x598a29,0x3,_0x4ff2('0x63'),'PREFIX-CALLERIDALL='+_0x2c14c3[_0x4ff2('0x65')]));}else{_0x3c0a11[_0x4ff2('0x62')](new Extension(_0x598a29,0x3,'NoOp',_0x4ff2('0x66')));}_0x3c0a11[_0x4ff2('0x62')](new Extension(_0x598a29,0x4,_0x4ff2('0x67'),_0x530f5a[_0x4ff2('0x56')]+','+'${EXTEN:'+(0x8+_0x2c14c3[_0x4ff2('0x2b')][_0x4ff2('0x36')])+'}'+','+0x1));return _0x3c0a11;}function formatPrefixName(_0xf3360e){var _0x43a8='_';for(var _0xfa0f97=0x0;_0xfa0f97<_0xf3360e[_0x4ff2('0x36')];_0xfa0f97++){if(_0xf3360e[_0x4ff2('0x68')](_0xfa0f97)=='-'){_0x43a8+=_0xf3360e[_0x4ff2('0x68')](_0xfa0f97);}else{_0x43a8+='['+_0xf3360e['charAt'](_0xfa0f97)+']';}}_0x43a8+='.';return _0x43a8;}exports[_0x4ff2('0x22')]=function(_0x82a694,_0xeadd04,_0x35d176){var _0x5a0541=_0x82a694[_0x4ff2('0x4e')];_0x5a0541['prefix']=_0x4ff2('0x69')+_0x5a0541[_0x4ff2('0x2b')]+'-';return db['sequelize'][_0x4ff2('0x4d')](function(_0x2caed7){return db['VoicePrefix'][_0x4ff2('0x22')](_0x5a0541,{'where':{'id':_0x5a0541['id']},'transaction':_0x2caed7})['then'](function(){return db['VoiceExtension']['destroy']({'where':{'VoicePrefixId':_0x5a0541['id']},'transaction':_0x2caed7})[_0x4ff2('0x27')](function(){return db[_0x4ff2('0x4f')][_0x4ff2('0x49')]({'where':{'id':_0x5a0541[_0x4ff2('0x50')]},'raw':!![]})[_0x4ff2('0x27')](function(_0x385902){return createVoicePrefixExtensions(_0x5a0541,_0x385902,_0x2caed7);});});});})[_0x4ff2('0x27')](function(){return db['VoicePrefix'][_0x4ff2('0x6a')](_0x5a0541['id']);})[_0x4ff2('0x27')](respondWithResult(_0xeadd04,null))[_0x4ff2('0x46')](handleError(_0xeadd04,null));};exports[_0x4ff2('0x6b')]=function(_0x14751b,_0x2e53fb,_0xb679ee){return db[_0x4ff2('0x42')][_0x4ff2('0x49')]({'where':{'id':_0x14751b[_0x4ff2('0x47')]['id']}})['then'](handleEntityNotFound(_0x2e53fb,null))[_0x4ff2('0x27')](function(_0x34c5e8){if(_0x34c5e8){return _0x34c5e8[_0x4ff2('0x6b')](_0x14751b[_0x4ff2('0x4e')][_0x4ff2('0x6c')],_[_0x4ff2('0x6d')](_0x14751b[_0x4ff2('0x4e')],[_0x4ff2('0x6c'),'id'])||{})[_0x4ff2('0x6e')](function(_0x40ca01){for(var _0x3bc549=0x0;_0x3bc549<_0x14751b[_0x4ff2('0x4e')][_0x4ff2('0x6c')][_0x4ff2('0x36')];_0x3bc549+=0x1){socket[_0x4ff2('0x6f')](_0x4ff2('0x70'),{'UserId':_0x14751b['body']['ids'][_0x3bc549],'VoicePrefixId':_0x14751b[_0x4ff2('0x47')]['id']});}return _0x40ca01;});}})[_0x4ff2('0x27')](respondWithResult(_0x2e53fb,null))[_0x4ff2('0x46')](handleError(_0x2e53fb,null));};exports[_0x4ff2('0x71')]=function(_0x3c9ab7,_0x30674d,_0xf2d75a){return db[_0x4ff2('0x42')][_0x4ff2('0x49')]({'where':{'id':_0x3c9ab7[_0x4ff2('0x47')]['id']}})[_0x4ff2('0x27')](handleEntityNotFound(_0x30674d,null))['then'](function(_0x2e4f5b){if(_0x2e4f5b){return _0x2e4f5b[_0x4ff2('0x71')](_0x3c9ab7['query'][_0x4ff2('0x6c')])[_0x4ff2('0x27')](function(){if(_[_0x4ff2('0x72')](_0x3c9ab7[_0x4ff2('0x30')][_0x4ff2('0x6c')])){for(var _0x165e36=0x0;_0x165e36<_0x3c9ab7[_0x4ff2('0x30')][_0x4ff2('0x6c')]['length'];_0x165e36+=0x1){socket[_0x4ff2('0x6f')]('userVoicePrefix:remove',{'UserId':Number(_0x3c9ab7[_0x4ff2('0x30')][_0x4ff2('0x6c')][_0x165e36]),'VoicePrefixId':Number(_0x3c9ab7[_0x4ff2('0x47')]['id'])});}}else{socket[_0x4ff2('0x6f')]('userVoicePrefix:remove',{'UserId':Number(_0x3c9ab7[_0x4ff2('0x30')][_0x4ff2('0x6c')]),'VoicePrefixId':Number(_0x3c9ab7[_0x4ff2('0x47')]['id'])});}});}})[_0x4ff2('0x27')](respondWithStatusCode(_0x30674d,null))[_0x4ff2('0x46')](handleError(_0x30674d,null));};exports[_0x4ff2('0x73')]=function(_0x621a54,_0x5c760b,_0x353d41){var _0x535a08={};var _0x41d8a3={};var _0x58b772;var _0xc965a3;return db[_0x4ff2('0x42')][_0x4ff2('0x74')]({'where':{'id':_0x621a54[_0x4ff2('0x47')]['id']}})[_0x4ff2('0x27')](handleEntityNotFound(_0x5c760b,null))[_0x4ff2('0x27')](function(_0x16510f){if(_0x16510f){_0x58b772=_0x16510f;_0x41d8a3[_0x4ff2('0x2f')]=_['keys'](db[_0x4ff2('0x75')][_0x4ff2('0x2e')]);_0x41d8a3[_0x4ff2('0x30')]=_[_0x4ff2('0x31')](_0x621a54[_0x4ff2('0x30')]);_0x41d8a3['filters']=_['intersection'](_0x41d8a3[_0x4ff2('0x2f')],_0x41d8a3[_0x4ff2('0x30')]);_0x535a08[_0x4ff2('0x35')]=_[_0x4ff2('0x33')](_0x41d8a3[_0x4ff2('0x2f')],qs['fields'](_0x621a54['query'][_0x4ff2('0x34')]));_0x535a08[_0x4ff2('0x35')]=_0x535a08[_0x4ff2('0x35')][_0x4ff2('0x36')]?_0x535a08[_0x4ff2('0x35')]:_0x41d8a3[_0x4ff2('0x2f')];_0x535a08['order']=qs['sort'](_0x621a54['query']['sort']);_0x535a08['where']=qs['filters'](_['pick'](_0x621a54[_0x4ff2('0x30')],_0x41d8a3[_0x4ff2('0x32')]));if(_0x621a54[_0x4ff2('0x30')][_0x4ff2('0x3c')]){_0x535a08['where']=_[_0x4ff2('0x3e')](_0x535a08['where'],{'$or':_[_0x4ff2('0x2d')](_0x535a08['attributes'],function(_0x36c9ec){var _0x15463b={};_0x15463b[_0x36c9ec]={'$like':'%'+_0x621a54['query']['filter']+'%'};return _0x15463b;})});}_0x535a08=_['merge']({},_0x535a08,_0x621a54[_0x4ff2('0x41')]);return _0x58b772[_0x4ff2('0x73')](_0x535a08);}})[_0x4ff2('0x27')](function(_0x2a5bc2){if(_0x2a5bc2){_0xc965a3=_0x2a5bc2['length'];if(!_0x621a54[_0x4ff2('0x30')][_0x4ff2('0x37')](_0x4ff2('0x38'))){_0x535a08[_0x4ff2('0x1d')]=qs[_0x4ff2('0x1d')](_0x621a54[_0x4ff2('0x30')]['limit']);_0x535a08[_0x4ff2('0x1c')]=qs[_0x4ff2('0x1c')](_0x621a54['query'][_0x4ff2('0x1c')]);}return _0x58b772['getAgents'](_0x535a08);}})[_0x4ff2('0x27')](function(_0x193051){if(_0x193051){return _0x193051?{'count':_0xc965a3,'rows':_0x193051}:null;}})[_0x4ff2('0x27')](respondWithResult(_0x5c760b,null))[_0x4ff2('0x46')](handleError(_0x5c760b,null));};
\ No newline at end of file
+var _0xd824=['NoOp','charAt','system-','transaction','findById','addAgents','spread','ids','emit','userVoicePrefix:save','removeAgents','isArray','userVoicePrefix:remove','getAgents','findOne','User','rawAttributes','sort','pick','nolimit','Team','getTeams','Agents','online','voicePause','interface','flatMap','addTeams','each','TeamVoicePrefix','upsert','UserVoicePrefix','findOrCreate','select','from','team_has_voice_prefixes','join','user_has_teams','VoicePrefixId\x20=\x20?','ut.UserId\x20=\x20?','toString','QueryTypes','every','includes','all','value','removeTeams','isEmpty','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','path','ejs','squel','crypto','jsforce','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','redis','defaults','localhost','./voicePrefix.socket','register','sendStatus','end','status','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','update','then','get','VoicePrefixes','destroy','error','name','index','map','VoicePrefix','fieldName','type','key','model','query','keys','filters','attributes','fields','hasOwnProperty','order','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','intersection','length','describe','create','sequelize','body','VoiceExtension','find','VoiceExtensionId','user','role','userProfileId','autoAssociation','UserProfileResource','context','app','system','Voice\x20Prefix\x20Extension','priority','appdata','prefix','VoicePrefixId','bulkCreate','Set','CDR(prefix)=','push','PREFIX-CALLERIDALL='];(function(_0x47b2bf,_0x58101d){var _0x5204df=function(_0x2b0a8a){while(--_0x2b0a8a){_0x47b2bf['push'](_0x47b2bf['shift']());}};_0x5204df(++_0x58101d);}(_0xd824,0xc2));var _0x4d82=function(_0x4a9fb1,_0x273043){_0x4a9fb1=_0x4a9fb1-0x0;var _0x348672=_0xd824[_0x4a9fb1];return _0x348672;};'use strict';var emlformat=require(_0x4d82('0x0'));var rimraf=require(_0x4d82('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x4d82('0x2'));var moment=require(_0x4d82('0x3'));var BPromise=require(_0x4d82('0x4'));var Mustache=require(_0x4d82('0x5'));var util=require(_0x4d82('0x6'));var path=require(_0x4d82('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x4d82('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x4d82('0x9'));var crypto=require(_0x4d82('0xa'));var jsforce=require(_0x4d82('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x4d82('0xc'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x4d82('0xd'));var authService=require(_0x4d82('0xe'));var qs=require(_0x4d82('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x4d82('0x10'));var logger=require('../../config/logger')(_0x4d82('0x11'));var utils=require(_0x4d82('0x12'));var config=require(_0x4d82('0x13'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0x4d82('0x14')]=_[_0x4d82('0x15')](config[_0x4d82('0x14')],{'host':_0x4d82('0x16'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4d82('0x14')]));require(_0x4d82('0x17'))[_0x4d82('0x18')](socket);function respondWithStatusCode(_0x486152,_0x70c598){_0x70c598=_0x70c598||0xcc;return function(_0x4f4c45){if(_0x4f4c45){return _0x486152[_0x4d82('0x19')](_0x70c598);}return _0x486152['status'](_0x70c598)[_0x4d82('0x1a')]();};}function respondWithResult(_0x496f3b,_0x474acf){_0x474acf=_0x474acf||0xc8;return function(_0xb1640d){if(_0xb1640d){return _0x496f3b[_0x4d82('0x1b')](_0x474acf)[_0x4d82('0x1c')](_0xb1640d);}};}function respondWithFilteredResult(_0x2648a8,_0x7c03fc){return function(_0x258c59){if(_0x258c59){var _0x217b72=typeof _0x7c03fc[_0x4d82('0x1d')]==='undefined'&&typeof _0x7c03fc[_0x4d82('0x1e')]===_0x4d82('0x1f');var _0x1b1e39=_0x258c59[_0x4d82('0x20')];var _0xe6260=_0x217b72?0x0:_0x7c03fc[_0x4d82('0x1d')];var _0x1a513d=_0x217b72?_0x258c59[_0x4d82('0x20')]:_0x7c03fc[_0x4d82('0x1d')]+_0x7c03fc[_0x4d82('0x1e')];var _0xf2f5a5;if(_0x1a513d>=_0x1b1e39){_0x1a513d=_0x1b1e39;_0xf2f5a5=0xc8;}else{_0xf2f5a5=0xce;}_0x2648a8['status'](_0xf2f5a5);return _0x2648a8[_0x4d82('0x21')](_0x4d82('0x22'),_0xe6260+'-'+_0x1a513d+'/'+_0x1b1e39)['json'](_0x258c59);}return null;};}function patchUpdates(_0x1a419f){return function(_0x41f194){try{jsonpatch[_0x4d82('0x23')](_0x41f194,_0x1a419f,!![]);}catch(_0x14a2d4){return BPromise[_0x4d82('0x24')](_0x14a2d4);}return _0x41f194[_0x4d82('0x25')]();};}function saveUpdates(_0x11c043,_0x462258){return function(_0x12feab){if(_0x12feab){return _0x12feab[_0x4d82('0x26')](_0x11c043)[_0x4d82('0x27')](function(_0x395efc){return _0x395efc;});}return null;};}function removeEntity(_0x7404ba,_0x284c66){return function(_0x1940ef){if(_0x1940ef){return _0x1940ef['destroy']()['then'](function(){var _0x3dcb0f=_0x1940ef[_0x4d82('0x28')]({'plain':!![]});var _0x2a0572=_0x4d82('0x29');return db['UserProfileResource'][_0x4d82('0x2a')]({'where':{'type':_0x2a0572,'resourceId':_0x3dcb0f['id']}})[_0x4d82('0x27')](function(){return _0x1940ef;});})[_0x4d82('0x27')](function(){_0x7404ba[_0x4d82('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4081f6,_0x4a7444){return function(_0x4d9ac4){if(!_0x4d9ac4){_0x4081f6['sendStatus'](0x194);}return _0x4d9ac4;};}function handleError(_0x52533b,_0x3d2229){_0x3d2229=_0x3d2229||0x1f4;return function(_0x8cfbf1){logger[_0x4d82('0x2b')](_0x8cfbf1['stack']);if(_0x8cfbf1[_0x4d82('0x2c')]){delete _0x8cfbf1[_0x4d82('0x2c')];}_0x52533b['status'](_0x3d2229)['send'](_0x8cfbf1);};}exports[_0x4d82('0x2d')]=function(_0x46a058,_0x16d30a){var _0x175961={},_0x5447f8={},_0x33d2a9={'count':0x0,'rows':[]};var _0x59cd4f=_[_0x4d82('0x2e')](db[_0x4d82('0x2f')]['rawAttributes'],function(_0x583cc5){return{'name':_0x583cc5[_0x4d82('0x30')],'type':_0x583cc5[_0x4d82('0x31')][_0x4d82('0x32')]};});_0x5447f8[_0x4d82('0x33')]=_[_0x4d82('0x2e')](_0x59cd4f,_0x4d82('0x2c'));_0x5447f8[_0x4d82('0x34')]=_[_0x4d82('0x35')](_0x46a058[_0x4d82('0x34')]);_0x5447f8[_0x4d82('0x36')]=_['intersection'](_0x5447f8[_0x4d82('0x33')],_0x5447f8[_0x4d82('0x34')]);_0x175961[_0x4d82('0x37')]=_['intersection'](_0x5447f8[_0x4d82('0x33')],qs[_0x4d82('0x38')](_0x46a058['query'][_0x4d82('0x38')]));_0x175961[_0x4d82('0x37')]=_0x175961[_0x4d82('0x37')]['length']?_0x175961[_0x4d82('0x37')]:_0x5447f8[_0x4d82('0x33')];if(!_0x46a058['query'][_0x4d82('0x39')]('nolimit')){_0x175961[_0x4d82('0x1e')]=qs[_0x4d82('0x1e')](_0x46a058['query'][_0x4d82('0x1e')]);_0x175961['offset']=qs[_0x4d82('0x1d')](_0x46a058['query']['offset']);}_0x175961[_0x4d82('0x3a')]=qs['sort'](_0x46a058[_0x4d82('0x34')]['sort']);_0x175961[_0x4d82('0x3b')]=qs[_0x4d82('0x36')](_['pick'](_0x46a058[_0x4d82('0x34')],_0x5447f8['filters']),_0x59cd4f);if(_0x46a058[_0x4d82('0x34')][_0x4d82('0x3c')]){_0x175961['where']=_[_0x4d82('0x3d')](_0x175961['where'],{'$or':_[_0x4d82('0x2e')](_0x59cd4f,function(_0x54f714){if(_0x54f714[_0x4d82('0x31')]!==_0x4d82('0x3e')){var _0x1d9e8b={};_0x1d9e8b[_0x54f714[_0x4d82('0x2c')]]={'$like':'%'+_0x46a058['query'][_0x4d82('0x3c')]+'%'};return _0x1d9e8b;}})});}_0x175961=_[_0x4d82('0x3d')]({},_0x175961,_0x46a058[_0x4d82('0x3f')]);var _0x3e29a6={'where':_0x175961[_0x4d82('0x3b')]};return db[_0x4d82('0x2f')][_0x4d82('0x20')](_0x3e29a6)['then'](function(_0x3c80d6){_0x33d2a9[_0x4d82('0x20')]=_0x3c80d6;if(_0x46a058[_0x4d82('0x34')][_0x4d82('0x40')]){_0x175961[_0x4d82('0x41')]=[{'all':!![]}];}return db['VoicePrefix'][_0x4d82('0x42')](_0x175961);})[_0x4d82('0x27')](function(_0x3f0a9f){_0x33d2a9[_0x4d82('0x43')]=_0x3f0a9f;return _0x33d2a9;})[_0x4d82('0x27')](respondWithFilteredResult(_0x16d30a,_0x175961))[_0x4d82('0x44')](handleError(_0x16d30a,null));};exports[_0x4d82('0x45')]=function(_0x5847c0,_0xe8c15f){var _0x1909da={'raw':![],'where':{'id':_0x5847c0[_0x4d82('0x46')]['id']}},_0x55e2f7={};_0x55e2f7['model']=_[_0x4d82('0x35')](db[_0x4d82('0x2f')]['rawAttributes']);_0x55e2f7[_0x4d82('0x34')]=_[_0x4d82('0x35')](_0x5847c0['query']);_0x55e2f7[_0x4d82('0x36')]=_[_0x4d82('0x47')](_0x55e2f7[_0x4d82('0x33')],_0x55e2f7['query']);_0x1909da[_0x4d82('0x37')]=_[_0x4d82('0x47')](_0x55e2f7['model'],qs['fields'](_0x5847c0[_0x4d82('0x34')][_0x4d82('0x38')]));_0x1909da[_0x4d82('0x37')]=_0x1909da[_0x4d82('0x37')][_0x4d82('0x48')]?_0x1909da[_0x4d82('0x37')]:_0x55e2f7[_0x4d82('0x33')];if(_0x5847c0['query'][_0x4d82('0x40')]){_0x1909da[_0x4d82('0x41')]=[{'all':!![]}];}_0x1909da=_[_0x4d82('0x3d')]({},_0x1909da,_0x5847c0[_0x4d82('0x3f')]);return db['VoicePrefix']['find'](_0x1909da)['then'](handleEntityNotFound(_0xe8c15f,null))[_0x4d82('0x27')](respondWithResult(_0xe8c15f,null))[_0x4d82('0x44')](handleError(_0xe8c15f,null));};exports[_0x4d82('0x2a')]=function(_0x34a08b,_0x25fc80){return db[_0x4d82('0x2f')]['find']({'where':{'id':_0x34a08b[_0x4d82('0x46')]['id']}})[_0x4d82('0x27')](handleEntityNotFound(_0x25fc80,null))[_0x4d82('0x27')](removeEntity(_0x25fc80,null))[_0x4d82('0x44')](handleError(_0x25fc80,null));};exports[_0x4d82('0x49')]=function(_0x33f498,_0x127ef3){return db[_0x4d82('0x2f')][_0x4d82('0x49')]()['then'](respondWithResult(_0x127ef3,null))[_0x4d82('0x44')](handleError(_0x127ef3,null));};exports[_0x4d82('0x4a')]=function(_0x1822db,_0x25e8b9){var _0x1d853f;return db[_0x4d82('0x4b')]['transaction'](function(_0x5cf138){return db[_0x4d82('0x2f')][_0x4d82('0x4a')](_0x1822db[_0x4d82('0x4c')],{'transaction':_0x5cf138})[_0x4d82('0x27')](function(_0x2e373a){_0x1d853f=_0x2e373a[_0x4d82('0x28')]({'plain':!![]});return db[_0x4d82('0x4d')][_0x4d82('0x4e')]({'where':{'id':_0x1d853f[_0x4d82('0x4f')]},'raw':!![]})[_0x4d82('0x27')](function(_0x367c82){return createVoicePrefixExtensions(_0x1d853f,_0x367c82,_0x5cf138);});});})[_0x4d82('0x27')](function(){var _0x517f87=_0x1822db[_0x4d82('0x50')]['get']({'plain':!![]});if(!_0x517f87)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x517f87[_0x4d82('0x51')]===_0x4d82('0x50')){var _0x257dc4=_0x1d853f;return db['UserProfileSection'][_0x4d82('0x4e')]({'where':{'name':_0x4d82('0x29'),'userProfileId':_0x517f87[_0x4d82('0x52')]},'raw':!![]})[_0x4d82('0x27')](function(_0x4aaa65){if(_0x4aaa65&&_0x4aaa65[_0x4d82('0x53')]===0x0){return db[_0x4d82('0x54')][_0x4d82('0x4a')]({'name':_0x257dc4[_0x4d82('0x2c')],'resourceId':_0x257dc4['id'],'type':_0x4aaa65[_0x4d82('0x2c')],'sectionId':_0x4aaa65['id']},{})['then'](function(){return _0x1d853f;});}else{return _0x1d853f;}})[_0x4d82('0x44')](function(_0x3297ce){logger[_0x4d82('0x2b')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3297ce);throw _0x3297ce;});}return _0x1d853f;})[_0x4d82('0x27')](respondWithResult(_0x25e8b9,null))[_0x4d82('0x44')](handleError(_0x25e8b9,null));};function Extension(_0x131bb5,_0x189e3f,_0x14e621,_0x3148bd){this[_0x4d82('0x55')]='from-sip';this['exten']=_0x131bb5;this[_0x4d82('0x56')]=_0x14e621;this[_0x4d82('0x31')]=_0x4d82('0x57');this['description']=_0x4d82('0x58');this[_0x4d82('0x59')]=_0x189e3f;this[_0x4d82('0x5a')]=_0x3148bd;}function createVoicePrefixExtensions(_0x3d85c2,_0x238459,_0x2aec60){return new BPromise(function(_0xa2cdb3,_0xc70504){var _0x131a10=new Extension(formatPrefixName(_0x3d85c2[_0x4d82('0x5b')]),0x1,'NoOp','Voice\x20Prefix');_0x131a10[_0x4d82('0x5c')]=_0x3d85c2['id'];return db[_0x4d82('0x4d')][_0x4d82('0x4a')](_0x131a10,{'transaction':_0x2aec60})['then'](function(_0x471349){var _0xc80c61=_0x471349[_0x4d82('0x28')]({'plain':!![]});var _0x328991=_[_0x4d82('0x2e')](addVoicePrefixExtensions(_0x3d85c2,_0x238459),function(_0x43c72e){_0x43c72e[_0x4d82('0x4f')]=_0xc80c61['id'];_0x43c72e[_0x4d82('0x5c')]=_0x3d85c2['id'];return _0x43c72e;});return db['VoiceExtension'][_0x4d82('0x5d')](_0x328991,{'transaction':_0x2aec60})[_0x4d82('0x27')](function(_0x279172){if(!_0x279172){return _0xc70504('Extensions\x20creation\x20failed');}else{return _0xa2cdb3(_0x279172);}})['catch'](function(_0x1d3e90){return _0xc70504(_0x1d3e90);});});;});};function addVoicePrefixExtensions(_0xc5b353,_0x1a785a){var _0x15d620=[];var _0x2872bf=formatPrefixName(_0xc5b353[_0x4d82('0x5b')]);_0x15d620['push'](new Extension(_0x2872bf,0x2,_0x4d82('0x5e'),_0x4d82('0x5f')+_0xc5b353[_0x4d82('0x2c')]));if(_0xc5b353['callerIdAll']){_0x15d620[_0x4d82('0x60')](new Extension(_0x2872bf,0x3,_0x4d82('0x5e'),_0x4d82('0x61')+_0xc5b353['callerIdAll']));}else{_0x15d620[_0x4d82('0x60')](new Extension(_0x2872bf,0x3,_0x4d82('0x62'),'No\x20callerid\x20available'));}_0x15d620[_0x4d82('0x60')](new Extension(_0x2872bf,0x4,'goto',_0x1a785a[_0x4d82('0x55')]+','+'${EXTEN:'+(0x8+_0xc5b353['name'][_0x4d82('0x48')])+'}'+','+0x1));return _0x15d620;}function formatPrefixName(_0x32e291){var _0x5279e3='_';for(var _0x307592=0x0;_0x307592<_0x32e291['length'];_0x307592++){if(_0x32e291[_0x4d82('0x63')](_0x307592)=='-'){_0x5279e3+=_0x32e291['charAt'](_0x307592);}else{_0x5279e3+='['+_0x32e291[_0x4d82('0x63')](_0x307592)+']';}}_0x5279e3+='.';return _0x5279e3;}exports[_0x4d82('0x26')]=function(_0x2fcf61,_0x75900c,_0x9c5e5c){var _0x456f33=_0x2fcf61[_0x4d82('0x4c')];_0x456f33[_0x4d82('0x5b')]=_0x4d82('0x64')+_0x456f33[_0x4d82('0x2c')]+'-';return db[_0x4d82('0x4b')][_0x4d82('0x65')](function(_0x14d697){return db[_0x4d82('0x2f')][_0x4d82('0x26')](_0x456f33,{'where':{'id':_0x456f33['id']},'transaction':_0x14d697})[_0x4d82('0x27')](function(){return db[_0x4d82('0x4d')][_0x4d82('0x2a')]({'where':{'VoicePrefixId':_0x456f33['id']},'transaction':_0x14d697})['then'](function(){return db['VoiceExtension'][_0x4d82('0x4e')]({'where':{'id':_0x456f33['VoiceExtensionId']},'raw':!![]})[_0x4d82('0x27')](function(_0x47644d){return createVoicePrefixExtensions(_0x456f33,_0x47644d,_0x14d697);});});});})[_0x4d82('0x27')](function(){return db[_0x4d82('0x2f')][_0x4d82('0x66')](_0x456f33['id']);})[_0x4d82('0x27')](respondWithResult(_0x75900c,null))['catch'](handleError(_0x75900c,null));};exports[_0x4d82('0x67')]=function(_0x220e87,_0x554778,_0x80d688){return db[_0x4d82('0x2f')][_0x4d82('0x4e')]({'where':{'id':_0x220e87[_0x4d82('0x46')]['id']}})[_0x4d82('0x27')](handleEntityNotFound(_0x554778,null))[_0x4d82('0x27')](function(_0x212561){if(_0x212561){return _0x212561[_0x4d82('0x67')](_0x220e87['body']['ids'],_['omit'](_0x220e87['body'],['ids','id'])||{})[_0x4d82('0x68')](function(_0x245e97){for(var _0x1fe26a=0x0;_0x1fe26a<_0x220e87['body'][_0x4d82('0x69')][_0x4d82('0x48')];_0x1fe26a+=0x1){socket[_0x4d82('0x6a')](_0x4d82('0x6b'),{'UserId':Number(_0x220e87[_0x4d82('0x4c')]['ids'][_0x1fe26a]),'VoicePrefixId':Number(_0x220e87['params']['id'])});}return _0x245e97;});}})[_0x4d82('0x27')](respondWithResult(_0x554778,null))[_0x4d82('0x44')](handleError(_0x554778,null));};exports[_0x4d82('0x6c')]=function(_0x2471b8,_0xd64d2a,_0x353c18){return db['VoicePrefix'][_0x4d82('0x4e')]({'where':{'id':_0x2471b8['params']['id']}})[_0x4d82('0x27')](handleEntityNotFound(_0xd64d2a,null))[_0x4d82('0x27')](function(_0x28a256){if(_0x28a256){return _0x28a256[_0x4d82('0x6c')](_0x2471b8[_0x4d82('0x34')]['ids'])[_0x4d82('0x27')](function(){if(_[_0x4d82('0x6d')](_0x2471b8[_0x4d82('0x34')][_0x4d82('0x69')])){for(var _0x2a50b3=0x0;_0x2a50b3<_0x2471b8[_0x4d82('0x34')][_0x4d82('0x69')][_0x4d82('0x48')];_0x2a50b3+=0x1){socket[_0x4d82('0x6a')](_0x4d82('0x6e'),{'UserId':Number(_0x2471b8[_0x4d82('0x34')]['ids'][_0x2a50b3]),'VoicePrefixId':Number(_0x2471b8[_0x4d82('0x46')]['id'])});}}else{socket[_0x4d82('0x6a')](_0x4d82('0x6e'),{'UserId':Number(_0x2471b8[_0x4d82('0x34')][_0x4d82('0x69')]),'VoicePrefixId':Number(_0x2471b8[_0x4d82('0x46')]['id'])});}});}})[_0x4d82('0x27')](respondWithStatusCode(_0xd64d2a,null))['catch'](handleError(_0xd64d2a,null));};exports[_0x4d82('0x6f')]=function(_0x3b7592,_0x5380ce,_0x21ea7c){var _0x588471={};var _0x634bfb={};var _0x5092ff;var _0x472666;return db['VoicePrefix'][_0x4d82('0x70')]({'where':{'id':_0x3b7592[_0x4d82('0x46')]['id']}})[_0x4d82('0x27')](handleEntityNotFound(_0x5380ce,null))['then'](function(_0x960e9){if(_0x960e9){_0x5092ff=_0x960e9;_0x634bfb[_0x4d82('0x33')]=_['keys'](db[_0x4d82('0x71')][_0x4d82('0x72')]);_0x634bfb[_0x4d82('0x34')]=_['keys'](_0x3b7592['query']);_0x634bfb[_0x4d82('0x36')]=_[_0x4d82('0x47')](_0x634bfb[_0x4d82('0x33')],_0x634bfb[_0x4d82('0x34')]);_0x588471[_0x4d82('0x37')]=_[_0x4d82('0x47')](_0x634bfb['model'],qs[_0x4d82('0x38')](_0x3b7592[_0x4d82('0x34')]['fields']));_0x588471[_0x4d82('0x37')]=_0x588471[_0x4d82('0x37')][_0x4d82('0x48')]?_0x588471['attributes']:_0x634bfb[_0x4d82('0x33')];_0x588471[_0x4d82('0x3a')]=qs[_0x4d82('0x73')](_0x3b7592[_0x4d82('0x34')]['sort']);_0x588471[_0x4d82('0x3b')]=qs[_0x4d82('0x36')](_[_0x4d82('0x74')](_0x3b7592[_0x4d82('0x34')],_0x634bfb['filters']));if(_0x3b7592[_0x4d82('0x34')]['filter']){_0x588471['where']=_[_0x4d82('0x3d')](_0x588471[_0x4d82('0x3b')],{'$or':_[_0x4d82('0x2e')](_0x588471[_0x4d82('0x37')],function(_0xb2d707){var _0x49d4ed={};_0x49d4ed[_0xb2d707]={'$like':'%'+_0x3b7592[_0x4d82('0x34')][_0x4d82('0x3c')]+'%'};return _0x49d4ed;})});}_0x588471=_['merge']({},_0x588471,_0x3b7592[_0x4d82('0x3f')]);return _0x5092ff[_0x4d82('0x6f')](_0x588471);}})[_0x4d82('0x27')](function(_0x210ed6){if(_0x210ed6){_0x472666=_0x210ed6['length'];if(!_0x3b7592[_0x4d82('0x34')]['hasOwnProperty'](_0x4d82('0x75'))){_0x588471[_0x4d82('0x1e')]=qs[_0x4d82('0x1e')](_0x3b7592[_0x4d82('0x34')][_0x4d82('0x1e')]);_0x588471[_0x4d82('0x1d')]=qs['offset'](_0x3b7592[_0x4d82('0x34')][_0x4d82('0x1d')]);}return _0x5092ff[_0x4d82('0x6f')](_0x588471);}})[_0x4d82('0x27')](function(_0x2c80ae){if(_0x2c80ae){return _0x2c80ae?{'count':_0x472666,'rows':_0x2c80ae}:null;}})[_0x4d82('0x27')](respondWithResult(_0x5380ce,null))[_0x4d82('0x44')](handleError(_0x5380ce,null));};exports['getTeams']=function(_0xfb0987,_0x5a65e4,_0x252db4){var _0x24a63a={};var _0x2d0b29={};var _0x44c35f;var _0x54fcd4;return db['VoicePrefix'][_0x4d82('0x70')]({'where':{'id':_0xfb0987[_0x4d82('0x46')]['id']}})[_0x4d82('0x27')](handleEntityNotFound(_0x5a65e4,null))[_0x4d82('0x27')](function(_0x45b2e3){if(_0x45b2e3){_0x44c35f=_0x45b2e3;_0x2d0b29[_0x4d82('0x33')]=_['keys'](db[_0x4d82('0x76')][_0x4d82('0x72')]);_0x2d0b29[_0x4d82('0x34')]=_[_0x4d82('0x35')](_0xfb0987[_0x4d82('0x34')]);_0x2d0b29['filters']=_[_0x4d82('0x47')](_0x2d0b29[_0x4d82('0x33')],_0x2d0b29[_0x4d82('0x34')]);_0x24a63a[_0x4d82('0x37')]=_[_0x4d82('0x47')](_0x2d0b29['model'],qs[_0x4d82('0x38')](_0xfb0987[_0x4d82('0x34')][_0x4d82('0x38')]));_0x24a63a[_0x4d82('0x37')]=_0x24a63a[_0x4d82('0x37')][_0x4d82('0x48')]?_0x24a63a['attributes']:_0x2d0b29['model'];_0x24a63a[_0x4d82('0x3a')]=qs[_0x4d82('0x73')](_0xfb0987[_0x4d82('0x34')]['sort']);_0x24a63a[_0x4d82('0x3b')]=qs[_0x4d82('0x36')](_['pick'](_0xfb0987[_0x4d82('0x34')],_0x2d0b29[_0x4d82('0x36')]));if(_0xfb0987[_0x4d82('0x34')][_0x4d82('0x3c')]){_0x24a63a[_0x4d82('0x3b')]=_[_0x4d82('0x3d')](_0x24a63a[_0x4d82('0x3b')],{'$or':_[_0x4d82('0x2e')](_0x24a63a['attributes'],function(_0x5471c3){var _0x1d1329={};_0x1d1329[_0x5471c3]={'$like':'%'+_0xfb0987[_0x4d82('0x34')][_0x4d82('0x3c')]+'%'};return _0x1d1329;})});}_0x24a63a=_['merge']({},_0x24a63a,_0xfb0987[_0x4d82('0x3f')]);return _0x44c35f[_0x4d82('0x77')](_0x24a63a);}})[_0x4d82('0x27')](function(_0x5a9056){if(_0x5a9056){_0x54fcd4=_0x5a9056[_0x4d82('0x48')];if(!_0xfb0987['query']['hasOwnProperty'](_0x4d82('0x75'))){_0x24a63a[_0x4d82('0x1e')]=qs[_0x4d82('0x1e')](_0xfb0987[_0x4d82('0x34')][_0x4d82('0x1e')]);_0x24a63a[_0x4d82('0x1d')]=qs[_0x4d82('0x1d')](_0xfb0987[_0x4d82('0x34')]['offset']);}return _0x44c35f[_0x4d82('0x77')](_0x24a63a);}})['then'](function(_0xc764bb){if(_0xc764bb){return _0xc764bb?{'count':_0x54fcd4,'rows':_0xc764bb}:null;}})[_0x4d82('0x27')](respondWithResult(_0x5a65e4,null))[_0x4d82('0x44')](handleError(_0x5a65e4,null));};exports['addTeams']=function(_0xead937,_0x59e1bc,_0x521566){var _0x1eda7c=_0xead937['body'][_0x4d82('0x69')];var _0x5ac864;return db[_0x4d82('0x76')][_0x4d82('0x42')]({'where':{'id':_0x1eda7c},'attributes':['id'],'include':[{'model':db['User'],'as':_0x4d82('0x78'),'attributes':['id',_0x4d82('0x2c'),_0x4d82('0x79'),_0x4d82('0x7a'),_0x4d82('0x7b')],'raw':!![]}]})[_0x4d82('0x27')](function(_0x2b832e){if(_0x2b832e){_0x5ac864=_0x2b832e;var _0x402626=_[_0x4d82('0x7c')](_0x2b832e,function(_0x3be4f9){var _0x47c734=_0x3be4f9[_0x4d82('0x28')]({'plain':!![]});return _0x47c734[_0x4d82('0x78')];});return db[_0x4d82('0x2f')][_0x4d82('0x4e')]({'where':{'id':_0xead937[_0x4d82('0x46')]['id']}})[_0x4d82('0x27')](function(_0x1768e2){return db[_0x4d82('0x4b')][_0x4d82('0x65')](function(_0x1c61f5){return _0x1768e2[_0x4d82('0x7d')](_0x1eda7c,{'transaction':_0x1c61f5})[_0x4d82('0x27')](function(){return BPromise[_0x4d82('0x7e')](_0x5ac864,function(_0x44729c){return db[_0x4d82('0x7f')][_0x4d82('0x80')]({'TeamId':_0x44729c['id'],'VoicePrefixId':_0xead937[_0x4d82('0x46')]['id']},{'transaction':_0x1c61f5});});})[_0x4d82('0x27')](function(){return BPromise['each'](_0x402626,function(_0x2867e7){return db[_0x4d82('0x81')][_0x4d82('0x82')]({'where':{'UserId':_0x2867e7['id'],'VoicePrefixId':_0xead937[_0x4d82('0x46')]['id']},'transaction':_0x1c61f5});});})[_0x4d82('0x27')](function(){_0x402626['forEach'](function(_0x14b0cb){socket[_0x4d82('0x6a')](_0x4d82('0x6b'),{'UserId':_0x14b0cb['id'],'VoicePrefixId':_0x1768e2['id']});});});});});}})[_0x4d82('0x27')](respondWithStatusCode(_0x59e1bc,null))[_0x4d82('0x44')](handleError(_0x59e1bc,null));};exports['removeTeams']=function(_0xc56d02,_0x34234c,_0x23778f){return db['Team'][_0x4d82('0x42')]({'where':{'id':_0xc56d02['query']['ids']},'attributes':['id'],'include':[{'model':db[_0x4d82('0x71')],'as':'Agents','attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x34234c,null))[_0x4d82('0x27')](function(_0x1d32c3){var _0x4d0047=_['map'](_0x1d32c3,'id');var _0x4f7c18=[];var _0x4277b7=[];var _0x2b7c2c=squel[_0x4d82('0x83')]();_0x2b7c2c['field']('tq.TeamId')[_0x4d82('0x84')](_0x4d82('0x85'),'tq')[_0x4d82('0x86')](_0x4d82('0x87'),'ut','ut.TeamId\x20=\x20tq.TeamId')[_0x4d82('0x3b')](_0x4d82('0x88'),_0xc56d02[_0x4d82('0x46')]['id']);for(var _0x2c18b2=0x0;_0x2c18b2<_0x1d32c3[_0x4d82('0x48')];_0x2c18b2+=0x1){let _0x37cac6=_0x1d32c3[_0x2c18b2];for(var _0x642d9=0x0;_0x642d9<_0x37cac6['Agents'][_0x4d82('0x48')];_0x642d9+=0x1){let _0x3097f8=_0x37cac6[_0x4d82('0x78')][_0x642d9];var _0x5ccadb=_0x2b7c2c['clone']();_0x5ccadb[_0x4d82('0x3b')](_0x4d82('0x89'),_0x3097f8['id']);_0x4277b7[_0x4d82('0x60')](db['sequelize'][_0x4d82('0x34')](_0x5ccadb[_0x4d82('0x8a')](),{'type':db[_0x4d82('0x4b')][_0x4d82('0x8b')]['SELECT']})[_0x4d82('0x27')](function(_0x3f0228){if(_0x3f0228['length']===0x1){return _0x3097f8['id'];}else{var _0x5f4633=_[_0x4d82('0x8c')](_['map'](_0x3f0228,'TeamId'),function(_0x3e4fb1){return _[_0x4d82('0x8d')](_0x4d0047,_0x3e4fb1);});if(_0x5f4633){return _0x3097f8['id'];}}}));}}return BPromise[_0x4d82('0x8e')](_0x4277b7)['then'](function(_0x4d6de5){_0x4f7c18=_(_0x4f7c18)['union'](_0x4d6de5)['compact']()[_0x4d82('0x8f')]();return db[_0x4d82('0x2f')][_0x4d82('0x4e')]({'where':{'id':_0xc56d02['params']['id']}})[_0x4d82('0x27')](function(_0x227e2c){return db[_0x4d82('0x4b')][_0x4d82('0x65')](function(_0x4f36f5){return _0x227e2c[_0x4d82('0x90')](_0xc56d02['query'][_0x4d82('0x69')],{'transaction':_0x4f36f5})[_0x4d82('0x27')](function(){if(!_[_0x4d82('0x91')](_0x4f7c18)){return _0x227e2c[_0x4d82('0x6c')](_0x4f7c18,{'transaction':_0x4f36f5});}})[_0x4d82('0x27')](function(){_0x4f7c18['forEach'](function(_0x3a0735){socket[_0x4d82('0x6a')]('userVoicePrefix:remove',{'UserId':_0x3a0735,'VoicePrefixId':_0x227e2c['id']});});});});});});})['then'](respondWithStatusCode(_0x34234c,null))['catch'](handleError(_0x34234c,null));};
\ No newline at end of file