Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / team / team.controller.js
index 8ef9538..04748ee 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x1020=['Queue','capitalize','addQueues','Sequelize','Queues','ids','removeQueues','findOne','addAgents','Mail','Sms','Fax','sequelize','transaction','Voice','penalty','QueueId','TeamVoiceQueue','User','findOrCreate','emit','online','voicePause','interface','isNil','format','SIP/%s','all','spread','removeAgents','Chat','Openchannel','Whatsapp','Queue:remove','UserVoiceQueueRt','getAgents','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','sendStatus','status','end','offset','undefined','limit','count','set','json','apply','save','update','then','destroy','get','Teams','UserProfileResource','error','stack','name','map','Team','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','catch','show','params','find','create','body','user','UserProfileSection','autoAssociation','getQueues','channel','isValidChannel','ValidationError','Unknown\x20channel','toLowerCase'];(function(_0x581fa7,_0x9ce527){var _0x151fa1=function(_0x119702){while(--_0x119702){_0x581fa7['push'](_0x581fa7['shift']());}};_0x151fa1(++_0x9ce527);}(_0x1020,0x1a4));var _0x0102=function(_0x1c289a,_0x277fe7){_0x1c289a=_0x1c289a-0x0;var _0x28d68e=_0x1020[_0x1c289a];return _0x28d68e;};'use strict';var emlformat=require(_0x0102('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x0102('0x1'));var jsonpatch=require(_0x0102('0x2'));var rp=require(_0x0102('0x3'));var moment=require(_0x0102('0x4'));var BPromise=require(_0x0102('0x5'));var Mustache=require(_0x0102('0x6'));var util=require(_0x0102('0x7'));var path=require(_0x0102('0x8'));var sox=require(_0x0102('0x9'));var csv=require(_0x0102('0xa'));var ejs=require(_0x0102('0xb'));var fs=require('fs');var fs_extra=require(_0x0102('0xc'));var _=require('lodash');var squel=require(_0x0102('0xd'));var crypto=require(_0x0102('0xe'));var jsforce=require(_0x0102('0xf'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x0102('0x10'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x0102('0x11'));var qs=require(_0x0102('0x12'));var as=require(_0x0102('0x13'));var hardwareService=require(_0x0102('0x14'));var logger=require(_0x0102('0x15'))('api');var utils=require(_0x0102('0x16'));var config=require(_0x0102('0x17'));var licenseUtil=require(_0x0102('0x18'));var db=require(_0x0102('0x19'))['db'];config[_0x0102('0x1a')]=_[_0x0102('0x1b')](config[_0x0102('0x1a')],{'host':_0x0102('0x1c'),'port':0x18eb});var socket=require(_0x0102('0x1d'))(new Redis(config['redis']));require('./team.socket')[_0x0102('0x1e')](socket);function respondWithStatusCode(_0x20f557,_0x3d0f4b){_0x3d0f4b=_0x3d0f4b||0xcc;return function(_0x21d392){if(_0x21d392){return _0x20f557[_0x0102('0x1f')](_0x3d0f4b);}return _0x20f557[_0x0102('0x20')](_0x3d0f4b)[_0x0102('0x21')]();};}function respondWithResult(_0x2e0c35,_0x3b7253){_0x3b7253=_0x3b7253||0xc8;return function(_0x2493fe){if(_0x2493fe){return _0x2e0c35[_0x0102('0x20')](_0x3b7253)['json'](_0x2493fe);}};}function respondWithFilteredResult(_0x2ca87b,_0x560b74){return function(_0x58ba05){if(_0x58ba05){var _0x4f3266=typeof _0x560b74[_0x0102('0x22')]===_0x0102('0x23')&&typeof _0x560b74[_0x0102('0x24')]===_0x0102('0x23');var _0x1da56c=_0x58ba05[_0x0102('0x25')];var _0x74533b=_0x4f3266?0x0:_0x560b74[_0x0102('0x22')];var _0x3da475=_0x4f3266?_0x58ba05[_0x0102('0x25')]:_0x560b74[_0x0102('0x22')]+_0x560b74[_0x0102('0x24')];var _0x1cc7bb;if(_0x3da475>=_0x1da56c){_0x3da475=_0x1da56c;_0x1cc7bb=0xc8;}else{_0x1cc7bb=0xce;}_0x2ca87b[_0x0102('0x20')](_0x1cc7bb);return _0x2ca87b[_0x0102('0x26')]('Content-Range',_0x74533b+'-'+_0x3da475+'/'+_0x1da56c)[_0x0102('0x27')](_0x58ba05);}return null;};}function patchUpdates(_0x2dc5f5){return function(_0x34cb74){try{jsonpatch[_0x0102('0x28')](_0x34cb74,_0x2dc5f5,!![]);}catch(_0x2787aa){return BPromise['reject'](_0x2787aa);}return _0x34cb74[_0x0102('0x29')]();};}function saveUpdates(_0x3d0fa7,_0x3d33db){return function(_0x11d9f4){if(_0x11d9f4){return _0x11d9f4[_0x0102('0x2a')](_0x3d0fa7)[_0x0102('0x2b')](function(_0x5ea683){return _0x5ea683;});}return null;};}function removeEntity(_0x6938fc,_0x42e908){return function(_0x462eb2){if(_0x462eb2){return _0x462eb2[_0x0102('0x2c')]()['then'](function(){var _0x2013c=_0x462eb2[_0x0102('0x2d')]({'plain':!![]});var _0xe613b5=_0x0102('0x2e');return db[_0x0102('0x2f')]['destroy']({'where':{'type':_0xe613b5,'resourceId':_0x2013c['id']}})[_0x0102('0x2b')](function(){return _0x462eb2;});})[_0x0102('0x2b')](function(){_0x6938fc[_0x0102('0x20')](0xcc)[_0x0102('0x21')]();});}};}function handleEntityNotFound(_0x5944de,_0x3e5d95){return function(_0x28ddb5){if(!_0x28ddb5){_0x5944de[_0x0102('0x1f')](0x194);}return _0x28ddb5;};}function handleError(_0x5116bb,_0x51ee86){_0x51ee86=_0x51ee86||0x1f4;return function(_0x4fbc76){logger[_0x0102('0x30')](_0x4fbc76[_0x0102('0x31')]);if(_0x4fbc76['name']){delete _0x4fbc76[_0x0102('0x32')];}_0x5116bb[_0x0102('0x20')](_0x51ee86)['send'](_0x4fbc76);};}exports['index']=function(_0x4ec0a1,_0xaeae20){var _0x15aba7={},_0x5c854b={},_0x3fb9df={'count':0x0,'rows':[]};var _0x37620b=_[_0x0102('0x33')](db[_0x0102('0x34')][_0x0102('0x35')],function(_0x38def2){return{'name':_0x38def2[_0x0102('0x36')],'type':_0x38def2[_0x0102('0x37')][_0x0102('0x38')]};});_0x5c854b[_0x0102('0x39')]=_[_0x0102('0x33')](_0x37620b,'name');_0x5c854b['query']=_[_0x0102('0x3a')](_0x4ec0a1[_0x0102('0x3b')]);_0x5c854b[_0x0102('0x3c')]=_[_0x0102('0x3d')](_0x5c854b[_0x0102('0x39')],_0x5c854b['query']);_0x15aba7[_0x0102('0x3e')]=_[_0x0102('0x3d')](_0x5c854b[_0x0102('0x39')],qs['fields'](_0x4ec0a1[_0x0102('0x3b')][_0x0102('0x3f')]));_0x15aba7[_0x0102('0x3e')]=_0x15aba7[_0x0102('0x3e')][_0x0102('0x40')]?_0x15aba7[_0x0102('0x3e')]:_0x5c854b[_0x0102('0x39')];if(!_0x4ec0a1[_0x0102('0x3b')][_0x0102('0x41')](_0x0102('0x42'))){_0x15aba7[_0x0102('0x24')]=qs[_0x0102('0x24')](_0x4ec0a1[_0x0102('0x3b')]['limit']);_0x15aba7[_0x0102('0x22')]=qs[_0x0102('0x22')](_0x4ec0a1[_0x0102('0x3b')][_0x0102('0x22')]);}_0x15aba7[_0x0102('0x43')]=qs['sort'](_0x4ec0a1[_0x0102('0x3b')][_0x0102('0x44')]);_0x15aba7[_0x0102('0x45')]=qs['filters'](_[_0x0102('0x46')](_0x4ec0a1[_0x0102('0x3b')],_0x5c854b[_0x0102('0x3c')]),_0x37620b);if(_0x4ec0a1[_0x0102('0x3b')][_0x0102('0x47')]){_0x15aba7[_0x0102('0x45')]=_['merge'](_0x15aba7['where'],{'$or':_[_0x0102('0x33')](_0x37620b,function(_0x39ba70){if(_0x39ba70['type']!==_0x0102('0x48')){var _0x2cf876={};_0x2cf876[_0x39ba70[_0x0102('0x32')]]={'$like':'%'+_0x4ec0a1[_0x0102('0x3b')][_0x0102('0x47')]+'%'};return _0x2cf876;}})});}_0x15aba7=_[_0x0102('0x49')]({},_0x15aba7,_0x4ec0a1[_0x0102('0x4a')]);var _0x3b0171={'where':_0x15aba7[_0x0102('0x45')]};return db[_0x0102('0x34')][_0x0102('0x25')](_0x3b0171)['then'](function(_0x2743e4){_0x3fb9df['count']=_0x2743e4;if(_0x4ec0a1[_0x0102('0x3b')][_0x0102('0x4b')]){_0x15aba7[_0x0102('0x4c')]=[{'all':!![]}];}return db[_0x0102('0x34')]['findAll'](_0x15aba7);})[_0x0102('0x2b')](function(_0x3607a6){_0x3fb9df['rows']=_0x3607a6;return _0x3fb9df;})[_0x0102('0x2b')](respondWithFilteredResult(_0xaeae20,_0x15aba7))[_0x0102('0x4d')](handleError(_0xaeae20,null));};exports[_0x0102('0x4e')]=function(_0x35040a,_0xb78550){var _0x5cbd34={'raw':![],'where':{'id':_0x35040a[_0x0102('0x4f')]['id']}},_0x230005={};_0x230005[_0x0102('0x39')]=_[_0x0102('0x3a')](db[_0x0102('0x34')]['rawAttributes']);_0x230005[_0x0102('0x3b')]=_['keys'](_0x35040a['query']);_0x230005[_0x0102('0x3c')]=_[_0x0102('0x3d')](_0x230005['model'],_0x230005[_0x0102('0x3b')]);_0x5cbd34[_0x0102('0x3e')]=_[_0x0102('0x3d')](_0x230005[_0x0102('0x39')],qs[_0x0102('0x3f')](_0x35040a['query'][_0x0102('0x3f')]));_0x5cbd34[_0x0102('0x3e')]=_0x5cbd34[_0x0102('0x3e')][_0x0102('0x40')]?_0x5cbd34['attributes']:_0x230005[_0x0102('0x39')];if(_0x35040a[_0x0102('0x3b')][_0x0102('0x4b')]){_0x5cbd34[_0x0102('0x4c')]=[{'all':!![]}];}_0x5cbd34=_[_0x0102('0x49')]({},_0x5cbd34,_0x35040a[_0x0102('0x4a')]);return db[_0x0102('0x34')][_0x0102('0x50')](_0x5cbd34)[_0x0102('0x2b')](handleEntityNotFound(_0xb78550,null))[_0x0102('0x2b')](respondWithResult(_0xb78550,null))[_0x0102('0x4d')](handleError(_0xb78550,null));};exports[_0x0102('0x51')]=function(_0x575862,_0x4ee019){return db[_0x0102('0x34')][_0x0102('0x51')](_0x575862[_0x0102('0x52')],{})['then'](function(_0x14c812){var _0x5b43f7=_0x575862['user'][_0x0102('0x2d')]({'plain':!![]});if(!_0x5b43f7)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x5b43f7['role']===_0x0102('0x53')){var _0x33cf95=_0x14c812[_0x0102('0x2d')]({'plain':!![]});var _0xf3e903=_0x0102('0x2e');return db[_0x0102('0x54')][_0x0102('0x50')]({'where':{'name':_0xf3e903,'userProfileId':_0x5b43f7['userProfileId']},'raw':!![]})['then'](function(_0x17bb0b){if(_0x17bb0b&&_0x17bb0b[_0x0102('0x55')]===0x0){return db[_0x0102('0x2f')][_0x0102('0x51')]({'name':_0x33cf95[_0x0102('0x32')],'resourceId':_0x33cf95['id'],'type':_0x17bb0b[_0x0102('0x32')],'sectionId':_0x17bb0b['id']},{})[_0x0102('0x2b')](function(){return _0x14c812;});}else{return _0x14c812;}})[_0x0102('0x4d')](function(_0x393a1f){logger[_0x0102('0x30')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x393a1f);throw _0x393a1f;});}return _0x14c812;})[_0x0102('0x2b')](respondWithResult(_0x4ee019,0xc9))['catch'](handleError(_0x4ee019,null));};exports[_0x0102('0x2a')]=function(_0x8af559,_0x3c9001){if(_0x8af559['body']['id']){delete _0x8af559[_0x0102('0x52')]['id'];}return db[_0x0102('0x34')]['find']({'where':{'id':_0x8af559[_0x0102('0x4f')]['id']}})[_0x0102('0x2b')](handleEntityNotFound(_0x3c9001,null))[_0x0102('0x2b')](saveUpdates(_0x8af559[_0x0102('0x52')],null))[_0x0102('0x2b')](respondWithResult(_0x3c9001,null))[_0x0102('0x4d')](handleError(_0x3c9001,null));};exports['destroy']=function(_0x3a35b3,_0x46f204){return db[_0x0102('0x34')][_0x0102('0x50')]({'where':{'id':_0x3a35b3[_0x0102('0x4f')]['id']}})[_0x0102('0x2b')](handleEntityNotFound(_0x46f204,null))[_0x0102('0x2b')](removeEntity(_0x46f204,null))[_0x0102('0x4d')](handleError(_0x46f204,null));};exports[_0x0102('0x56')]=function(_0x4b3571,_0x4cfc09,_0x55e8c0){return db[_0x0102('0x34')]['findOne']({'where':{'id':_0x4b3571[_0x0102('0x4f')]['id']}})['then'](handleEntityNotFound(_0x4cfc09,null))[_0x0102('0x2b')](function(_0x22b2bd){if(!_0x4b3571[_0x0102('0x3b')][_0x0102('0x57')]||!utils[_0x0102('0x58')](_0x4b3571[_0x0102('0x3b')]['channel'])){throw new db['Sequelize'][(_0x0102('0x59'))](_0x0102('0x5a'));}var _0x20f068={};var _0xa60117={};_0xa60117[_0x0102('0x39')]=_[_0x0102('0x3a')](db[_['capitalize'](_0x4b3571['query']['channel'][_0x0102('0x5b')]())+_0x0102('0x5c')][_0x0102('0x35')]);_0xa60117['query']=_['keys'](_0x4b3571[_0x0102('0x3b')]);_0xa60117[_0x0102('0x3c')]=_['intersection'](_0xa60117[_0x0102('0x39')],_0xa60117[_0x0102('0x3b')]);_0x20f068[_0x0102('0x3e')]=_[_0x0102('0x3d')](_0xa60117[_0x0102('0x39')],qs['fields'](_0x4b3571[_0x0102('0x3b')][_0x0102('0x3f')]));_0x20f068[_0x0102('0x3e')]=_0x20f068['attributes'][_0x0102('0x40')]?_0x20f068[_0x0102('0x3e')]:_0xa60117[_0x0102('0x39')];_0x20f068[_0x0102('0x24')]=qs[_0x0102('0x24')](_0x4b3571['query'][_0x0102('0x24')]);_0x20f068[_0x0102('0x22')]=qs['offset'](_0x4b3571[_0x0102('0x3b')]['offset']);_0x20f068[_0x0102('0x43')]=qs['sort'](_0x4b3571['query']['sort']);_0x20f068[_0x0102('0x45')]=qs[_0x0102('0x3c')](_['pick'](_0x4b3571[_0x0102('0x3b')],_0xa60117[_0x0102('0x3c')]));_0x20f068=_[_0x0102('0x49')]({},_0x20f068,_0x4b3571[_0x0102('0x4a')]);return _0x22b2bd[_0x0102('0x2d')+_[_0x0102('0x5d')](_0x4b3571[_0x0102('0x3b')][_0x0102('0x57')][_0x0102('0x5b')]())+'Queues'](_0x20f068);})[_0x0102('0x2b')](respondWithResult(_0x4cfc09,null))[_0x0102('0x4d')](handleError(_0x4cfc09,null));};exports[_0x0102('0x5e')]=function(_0xfdb1e4,_0x20ec50,_0x24dfdb){return db[_0x0102('0x34')]['findOne']({'where':{'id':_0xfdb1e4['params']['id']}})[_0x0102('0x2b')](function(_0x29b26a){if(_0x29b26a){if(!_0xfdb1e4[_0x0102('0x52')][_0x0102('0x57')]||!utils[_0x0102('0x58')](_0xfdb1e4['body'][_0x0102('0x57')])){throw new db[(_0x0102('0x5f'))][(_0x0102('0x59'))]('Unknown\x20channel');}return _0x29b26a['add'+_['capitalize'](_0xfdb1e4[_0x0102('0x52')][_0x0102('0x57')][_0x0102('0x5b')]())+_0x0102('0x60')](_0xfdb1e4[_0x0102('0x52')][_0x0102('0x61')]);}return null;})[_0x0102('0x2b')](handleEntityNotFound(_0x20ec50,null))[_0x0102('0x2b')](respondWithStatusCode(_0x20ec50,null))[_0x0102('0x4d')](handleError(_0x20ec50,null));};exports[_0x0102('0x62')]=function(_0xd869b9,_0x5c6814,_0x48b920){return db[_0x0102('0x34')][_0x0102('0x63')]({'where':{'id':_0xd869b9['params']['id']}})[_0x0102('0x2b')](function(_0x211bf7){if(_0x211bf7){if(!_0xd869b9[_0x0102('0x3b')][_0x0102('0x57')]||!utils[_0x0102('0x58')](_0xd869b9[_0x0102('0x3b')][_0x0102('0x57')])){throw new db[(_0x0102('0x5f'))]['ValidationError']('Unknown\x20channel');}return _0x211bf7['remove'+_[_0x0102('0x5d')](_0xd869b9['query']['channel'][_0x0102('0x5b')]())+_0x0102('0x60')](_0xd869b9[_0x0102('0x3b')][_0x0102('0x61')]);}return null;})['then'](handleEntityNotFound(_0x5c6814,null))[_0x0102('0x2b')](respondWithStatusCode(_0x5c6814,null))[_0x0102('0x4d')](handleError(_0x5c6814,null));};exports[_0x0102('0x64')]=function(_0x2f68d1,_0x4fbd28){return db[_0x0102('0x34')]['find']({'where':{'id':_0x2f68d1[_0x0102('0x4f')]['id']}})['then'](handleEntityNotFound(_0x4fbd28,null))[_0x0102('0x2b')](function(_0x334f9c){if(_0x334f9c){var _0x2b27b7=['Voice','Chat',_0x0102('0x65'),_0x0102('0x66'),_0x0102('0x67'),'Openchannel','Whatsapp'];return db[_0x0102('0x68')][_0x0102('0x69')](function(_0x597743){var _0x24d969=_[_0x0102('0x33')](_0x2b27b7,function(_0xe6e097){var _0x4863c0={'attributes':['id',_0x0102('0x32')]};if(_0xe6e097===_0x0102('0x6a')){_0x4863c0['through']={'attributes':[_0x0102('0x6b')]};}return _0x334f9c[_0x0102('0x2d')+_0xe6e097+'Queues'](_0x4863c0)[_0x0102('0x2b')](function(_0x208f90){var _0x526808=_[_0x0102('0x33')](_0x208f90,function(_0x1de614){var _0x55dbba=_[_0x0102('0x33')](_0x2f68d1['body']['ids'],function(_0x1836c7){var _0x16efaf={'where':{'UserId':_0x1836c7,[_0xe6e097+_0x0102('0x6c')]:_0x1de614['id']},'transaction':_0x597743};if(_0xe6e097===_0x0102('0x6a')){_0x16efaf[_0x0102('0x1b')]={'penalty':_0x1de614[_0x0102('0x6d')]['penalty']};}return db[_0x0102('0x6e')+_0xe6e097+_0x0102('0x5c')][_0x0102('0x6f')](_0x16efaf)['then'](function(){socket[_0x0102('0x70')](_0x0102('0x53')+_0xe6e097+'Queue:save',{'UserId':_0x1836c7,[_0xe6e097+_0x0102('0x6c')]:_0x1de614['id']});if(_0xe6e097!==_0x0102('0x6a'))return;return db[_0x0102('0x6e')]['findAll']({'where':{'id':_0x2f68d1['body'][_0x0102('0x61')],'online':0x1},'attributes':['id','name',_0x0102('0x71'),_0x0102('0x72'),_0x0102('0x73')],'raw':!![]})['then'](function(_0x214ba3){var _0x11962a=_[_0x0102('0x33')](_0x214ba3,function(_0x4cbffe){return db['UserVoiceQueueRt']['upsert']({'membername':_0x4cbffe[_0x0102('0x32')],'UserId':_0x4cbffe['id'],'queue_name':_0x1de614[_0x0102('0x32')],'VoiceQueueId':_0x1de614['id'],'interface':_[_0x0102('0x74')](_0x4cbffe['interface'])?util[_0x0102('0x75')](_0x0102('0x76'),_0x4cbffe['name']):_0x4cbffe[_0x0102('0x73')],'paused':_0x4cbffe[_0x0102('0x72')]||![],'penalty':_0x1de614[_0x0102('0x6d')][_0x0102('0x6b')]},{'transaction':_0x597743});});return Promise[_0x0102('0x77')](_0x11962a);});});});return Promise[_0x0102('0x77')](_0x55dbba);});return Promise[_0x0102('0x77')](_0x526808);});});return Promise[_0x0102('0x77')](_0x24d969)['then'](function(){return _0x334f9c['addAgents'](_0x2f68d1[_0x0102('0x52')]['ids'],{'transaction':_0x597743})[_0x0102('0x78')](function(_0x2b209c){return _0x2b209c;});});});}})[_0x0102('0x2b')](respondWithResult(_0x4fbd28,null))[_0x0102('0x4d')](handleError(_0x4fbd28,null));};exports[_0x0102('0x79')]=function(_0x34ae9e,_0x4e08e7){return db[_0x0102('0x34')][_0x0102('0x50')]({'where':{'id':_0x34ae9e[_0x0102('0x4f')]['id']}})[_0x0102('0x2b')](handleEntityNotFound(_0x4e08e7,null))[_0x0102('0x2b')](function(_0x5b392c){if(_0x5b392c){var _0xc6f67f=[_0x0102('0x6a'),_0x0102('0x7a'),_0x0102('0x65'),_0x0102('0x66'),_0x0102('0x67'),_0x0102('0x7b'),_0x0102('0x7c')];return db[_0x0102('0x68')][_0x0102('0x69')](function(_0x3c1c38){var _0x595076=_[_0x0102('0x33')](_0xc6f67f,function(_0x17f78c){var _0xbf910f={'attributes':['id',_0x0102('0x32')]};return _0x5b392c[_0x0102('0x2d')+_0x17f78c+'Queues'](_0xbf910f)[_0x0102('0x2b')](function(_0x2f9ff3){var _0x28fabe=_['map'](_0x2f9ff3,function(_0x1ff669){return _0x1ff669[_0x0102('0x79')](_0x34ae9e[_0x0102('0x3b')][_0x0102('0x61')],{'transaction':_0x3c1c38})[_0x0102('0x2b')](function(){var _0x3aab78=JSON['parse']('['+_0x34ae9e[_0x0102('0x3b')][_0x0102('0x61')]+']');var _0x7abb3c=_[_0x0102('0x33')](_0x3aab78,function(_0x2bc2fd){socket[_0x0102('0x70')]('user'+_0x17f78c+_0x0102('0x7d'),{'UserId':Number(_0x2bc2fd),[_0x17f78c+'QueueId']:_0x1ff669['id']});if(_0x17f78c!==_0x0102('0x6a'))return;return db[_0x0102('0x7e')][_0x0102('0x2c')]({'where':{'VoiceQueueId':_0x1ff669['id'],'UserId':_0x2bc2fd},'transaction':_0x3c1c38});});return Promise[_0x0102('0x77')](_0x7abb3c);});});return Promise[_0x0102('0x77')](_0x28fabe);});});return Promise['all'](_0x595076)[_0x0102('0x2b')](function(){return _0x5b392c['removeAgents'](_0x34ae9e[_0x0102('0x3b')]['ids'],{'transaction':_0x3c1c38});});});}})['then'](respondWithStatusCode(_0x4e08e7,null))[_0x0102('0x4d')](handleError(_0x4e08e7,null));};exports[_0x0102('0x7f')]=function(_0x4afaa0,_0x2144f4,_0x4b8b8a){var _0x355bb8={};var _0x36bec5={};var _0xd80198;var _0x405b26;return db[_0x0102('0x34')][_0x0102('0x63')]({'where':{'id':_0x4afaa0[_0x0102('0x4f')]['id']}})[_0x0102('0x2b')](handleEntityNotFound(_0x2144f4,null))[_0x0102('0x2b')](function(_0x51a07b){if(_0x51a07b){_0xd80198=_0x51a07b;_0x36bec5[_0x0102('0x39')]=_[_0x0102('0x3a')](db['User'][_0x0102('0x35')]);_0x36bec5[_0x0102('0x3b')]=_[_0x0102('0x3a')](_0x4afaa0[_0x0102('0x3b')]);_0x36bec5[_0x0102('0x3c')]=_[_0x0102('0x3d')](_0x36bec5['model'],_0x36bec5[_0x0102('0x3b')]);_0x355bb8[_0x0102('0x3e')]=_[_0x0102('0x3d')](_0x36bec5[_0x0102('0x39')],qs['fields'](_0x4afaa0[_0x0102('0x3b')]['fields']));_0x355bb8[_0x0102('0x3e')]=_0x355bb8['attributes'][_0x0102('0x40')]?_0x355bb8[_0x0102('0x3e')]:_0x36bec5[_0x0102('0x39')];_0x355bb8['order']=qs[_0x0102('0x44')](_0x4afaa0['query']['sort']);_0x355bb8[_0x0102('0x45')]=qs['filters'](_[_0x0102('0x46')](_0x4afaa0['query'],_0x36bec5[_0x0102('0x3c')]));if(_0x4afaa0[_0x0102('0x3b')]['filter']){_0x355bb8[_0x0102('0x45')]=_[_0x0102('0x49')](_0x355bb8[_0x0102('0x45')],{'$or':_[_0x0102('0x33')](_0x355bb8[_0x0102('0x3e')],function(_0x35df7d){var _0x5ba6ee={};_0x5ba6ee[_0x35df7d]={'$like':'%'+_0x4afaa0[_0x0102('0x3b')][_0x0102('0x47')]+'%'};return _0x5ba6ee;})});}_0x355bb8=_[_0x0102('0x49')]({},_0x355bb8,_0x4afaa0[_0x0102('0x4a')]);return _0xd80198[_0x0102('0x7f')](_0x355bb8);}})[_0x0102('0x2b')](function(_0x27a0fb){if(_0x27a0fb){_0x405b26=_0x27a0fb[_0x0102('0x40')];if(!_0x4afaa0[_0x0102('0x3b')][_0x0102('0x41')](_0x0102('0x42'))){_0x355bb8[_0x0102('0x24')]=qs[_0x0102('0x24')](_0x4afaa0[_0x0102('0x3b')][_0x0102('0x24')]);_0x355bb8[_0x0102('0x22')]=qs[_0x0102('0x22')](_0x4afaa0[_0x0102('0x3b')][_0x0102('0x22')]);}return _0xd80198['getAgents'](_0x355bb8);}})[_0x0102('0x2b')](function(_0x1ad36e){if(_0x1ad36e){return _0x1ad36e?{'count':_0x405b26,'rows':_0x1ad36e}:null;}})['then'](respondWithResult(_0x2144f4,null))[_0x0102('0x4d')](handleError(_0x2144f4,null));};
\ No newline at end of file
+var _0x855e=['TeamVoiceQueue','User','findOrCreate','emit','QueueId','online','voicePause','interface','UserVoiceQueueRt','upsert','isNil','all','TeamVoicePrefix','UserVoicePrefix','VoicePrefixId','spread','removeAgents','Whatsapp','Queue:remove','getAgents','eml-format','rimraf','zip-dir','request-promise','bluebird','util','path','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./team.socket','register','status','end','offset','undefined','limit','json','apply','reject','update','then','sendStatus','error','stack','name','map','rawAttributes','fieldName','type','key','query','keys','attributes','intersection','model','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','VIRTUAL','merge','options','Team','count','include','findAll','rows','show','params','includeAll','find','catch','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Teams','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','destroy','sequelize','SELECT\x20UserId\x20FROM\x20user_has_teams\x20WHERE\x20TeamId\x20=\x20','Sequelize','QueryTypes','SELECT\x20VoiceQueueId\x20FROM\x20team_has_voice_queues\x20WHERE\x20TeamId\x20=\x20','SELECT','VoiceQueueId','SELECT\x20MailQueueId\x20FROM\x20team_has_mail_queues\x20WHERE\x20TeamId\x20=\x20','MailQueueId','UserMailQueue','SELECT\x20SmsQueueId\x20FROM\x20team_has_sms_queues\x20WHERE\x20TeamId\x20=\x20','SmsQueueId','UserSmsQueue','SELECT\x20ChatQueueId\x20FROM\x20team_has_chat_queues\x20WHERE\x20TeamId\x20=\x20','FaxQueueId','UserFaxQueue','OpenchannelQueueId','UserOpenchannelQueue','SELECT\x20WhatsappQueueId\x20FROM\x20team_has_whatsapp_queues\x20WHERE\x20TeamId\x20=\x20','UserProfileResource','send','channel','ValidationError','Unknown\x20channel','capitalize','toLowerCase','Queue','addQueues','findOne','Queues','ids','removeQueues','isValidChannel','remove','addAgents','isArray','Voice','Chat','Sms','Fax','Openchannel','transaction','through','penalty','defaults'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x855e,0x146));var _0xe855=function(_0x275fa1,_0x28af28){_0x275fa1=_0x275fa1-0x0;var _0x5c04db=_0x855e[_0x275fa1];return _0x5c04db;};'use strict';var emlformat=require(_0xe855('0x0'));var rimraf=require(_0xe855('0x1'));var zipdir=require(_0xe855('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xe855('0x3'));var moment=require('moment');var BPromise=require(_0xe855('0x4'));var Mustache=require('mustache');var util=require(_0xe855('0x5'));var path=require(_0xe855('0x6'));var sox=require('sox');var csv=require(_0xe855('0x7'));var ejs=require(_0xe855('0x8'));var fs=require('fs');var fs_extra=require(_0xe855('0x9'));var _=require('lodash');var squel=require(_0xe855('0xa'));var crypto=require(_0xe855('0xb'));var jsforce=require(_0xe855('0xc'));var deskjs=require(_0xe855('0xd'));var toCsv=require(_0xe855('0x7'));var querystring=require(_0xe855('0xe'));var Papa=require(_0xe855('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xe855('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xe855('0x11'));var logger=require(_0xe855('0x12'))(_0xe855('0x13'));var utils=require(_0xe855('0x14'));var config=require(_0xe855('0x15'));var licenseUtil=require(_0xe855('0x16'));var db=require(_0xe855('0x17'))['db'];config['redis']=_['defaults'](config[_0xe855('0x18')],{'host':_0xe855('0x19'),'port':0x18eb});var socket=require(_0xe855('0x1a'))(new Redis(config[_0xe855('0x18')]));require(_0xe855('0x1b'))[_0xe855('0x1c')](socket);function respondWithStatusCode(_0x3fa9e3,_0x15cdd1){_0x15cdd1=_0x15cdd1||0xcc;return function(_0x24dd78){if(_0x24dd78){return _0x3fa9e3['sendStatus'](_0x15cdd1);}return _0x3fa9e3[_0xe855('0x1d')](_0x15cdd1)[_0xe855('0x1e')]();};}function respondWithResult(_0x49c438,_0x42f5ad){_0x42f5ad=_0x42f5ad||0xc8;return function(_0x1805ba){if(_0x1805ba){return _0x49c438[_0xe855('0x1d')](_0x42f5ad)['json'](_0x1805ba);}};}function respondWithFilteredResult(_0x37447f,_0x1b1a2a){return function(_0x359d81){if(_0x359d81){var _0x285ee5=typeof _0x1b1a2a[_0xe855('0x1f')]===_0xe855('0x20')&&typeof _0x1b1a2a[_0xe855('0x21')]==='undefined';var _0x1183a0=_0x359d81['count'];var _0x5592be=_0x285ee5?0x0:_0x1b1a2a['offset'];var _0x2d0b61=_0x285ee5?_0x359d81['count']:_0x1b1a2a[_0xe855('0x1f')]+_0x1b1a2a[_0xe855('0x21')];var _0x4d84b8;if(_0x2d0b61>=_0x1183a0){_0x2d0b61=_0x1183a0;_0x4d84b8=0xc8;}else{_0x4d84b8=0xce;}_0x37447f[_0xe855('0x1d')](_0x4d84b8);return _0x37447f['set']('Content-Range',_0x5592be+'-'+_0x2d0b61+'/'+_0x1183a0)[_0xe855('0x22')](_0x359d81);}return null;};}function patchUpdates(_0x36271b){return function(_0x3081ff){try{jsonpatch[_0xe855('0x23')](_0x3081ff,_0x36271b,!![]);}catch(_0x10536a){return BPromise[_0xe855('0x24')](_0x10536a);}return _0x3081ff['save']();};}function saveUpdates(_0x3419fe,_0x4fd7ee){return function(_0x1b6ac6){if(_0x1b6ac6){return _0x1b6ac6[_0xe855('0x25')](_0x3419fe)[_0xe855('0x26')](function(_0x3b6b95){return _0x3b6b95;});}return null;};}function handleEntityNotFound(_0x4fc339,_0x474216){return function(_0xfbcda0){if(!_0xfbcda0){_0x4fc339[_0xe855('0x27')](0x194);}return _0xfbcda0;};}function handleError(_0x3822ab,_0x1aa372){_0x1aa372=_0x1aa372||0x1f4;return function(_0x4d5b9f){logger[_0xe855('0x28')](_0x4d5b9f[_0xe855('0x29')]);if(_0x4d5b9f[_0xe855('0x2a')]){delete _0x4d5b9f[_0xe855('0x2a')];}_0x3822ab[_0xe855('0x1d')](_0x1aa372)['send'](_0x4d5b9f);};}exports['index']=function(_0x54de1b,_0x11e8b4){var _0x1b001e={},_0x33eb02={},_0x147b9f={'count':0x0,'rows':[]};var _0x2e6f0f=_[_0xe855('0x2b')](db['Team'][_0xe855('0x2c')],function(_0x1646af){return{'name':_0x1646af[_0xe855('0x2d')],'type':_0x1646af[_0xe855('0x2e')][_0xe855('0x2f')]};});_0x33eb02['model']=_['map'](_0x2e6f0f,'name');_0x33eb02[_0xe855('0x30')]=_[_0xe855('0x31')](_0x54de1b[_0xe855('0x30')]);_0x33eb02['filters']=_['intersection'](_0x33eb02['model'],_0x33eb02[_0xe855('0x30')]);_0x1b001e[_0xe855('0x32')]=_[_0xe855('0x33')](_0x33eb02[_0xe855('0x34')],qs[_0xe855('0x35')](_0x54de1b[_0xe855('0x30')][_0xe855('0x35')]));_0x1b001e['attributes']=_0x1b001e[_0xe855('0x32')][_0xe855('0x36')]?_0x1b001e[_0xe855('0x32')]:_0x33eb02['model'];if(!_0x54de1b[_0xe855('0x30')][_0xe855('0x37')](_0xe855('0x38'))){_0x1b001e[_0xe855('0x21')]=qs[_0xe855('0x21')](_0x54de1b[_0xe855('0x30')][_0xe855('0x21')]);_0x1b001e[_0xe855('0x1f')]=qs[_0xe855('0x1f')](_0x54de1b[_0xe855('0x30')][_0xe855('0x1f')]);}_0x1b001e[_0xe855('0x39')]=qs[_0xe855('0x3a')](_0x54de1b[_0xe855('0x30')][_0xe855('0x3a')]);_0x1b001e[_0xe855('0x3b')]=qs[_0xe855('0x3c')](_[_0xe855('0x3d')](_0x54de1b[_0xe855('0x30')],_0x33eb02['filters']),_0x2e6f0f);if(_0x54de1b[_0xe855('0x30')][_0xe855('0x3e')]){_0x1b001e[_0xe855('0x3b')]=_['merge'](_0x1b001e[_0xe855('0x3b')],{'$or':_[_0xe855('0x2b')](_0x2e6f0f,function(_0x1c09d5){if(_0x1c09d5[_0xe855('0x2e')]!==_0xe855('0x3f')){var _0x3b298b={};_0x3b298b[_0x1c09d5['name']]={'$like':'%'+_0x54de1b[_0xe855('0x30')][_0xe855('0x3e')]+'%'};return _0x3b298b;}})});}_0x1b001e=_[_0xe855('0x40')]({},_0x1b001e,_0x54de1b[_0xe855('0x41')]);var _0x19f2cc={'where':_0x1b001e[_0xe855('0x3b')]};return db[_0xe855('0x42')][_0xe855('0x43')](_0x19f2cc)[_0xe855('0x26')](function(_0x930699){_0x147b9f[_0xe855('0x43')]=_0x930699;if(_0x54de1b[_0xe855('0x30')]['includeAll']){_0x1b001e[_0xe855('0x44')]=[{'all':!![]}];}return db[_0xe855('0x42')][_0xe855('0x45')](_0x1b001e);})['then'](function(_0x29e0db){_0x147b9f[_0xe855('0x46')]=_0x29e0db;return _0x147b9f;})['then'](respondWithFilteredResult(_0x11e8b4,_0x1b001e))['catch'](handleError(_0x11e8b4,null));};exports[_0xe855('0x47')]=function(_0x25920d,_0x55e766){var _0x38e942={'raw':![],'where':{'id':_0x25920d[_0xe855('0x48')]['id']}},_0x222a68={};_0x222a68[_0xe855('0x34')]=_[_0xe855('0x31')](db[_0xe855('0x42')][_0xe855('0x2c')]);_0x222a68['query']=_[_0xe855('0x31')](_0x25920d[_0xe855('0x30')]);_0x222a68['filters']=_[_0xe855('0x33')](_0x222a68[_0xe855('0x34')],_0x222a68['query']);_0x38e942[_0xe855('0x32')]=_[_0xe855('0x33')](_0x222a68[_0xe855('0x34')],qs[_0xe855('0x35')](_0x25920d[_0xe855('0x30')][_0xe855('0x35')]));_0x38e942['attributes']=_0x38e942['attributes']['length']?_0x38e942['attributes']:_0x222a68[_0xe855('0x34')];if(_0x25920d[_0xe855('0x30')][_0xe855('0x49')]){_0x38e942[_0xe855('0x44')]=[{'all':!![]}];}_0x38e942=_[_0xe855('0x40')]({},_0x38e942,_0x25920d['options']);return db[_0xe855('0x42')][_0xe855('0x4a')](_0x38e942)['then'](handleEntityNotFound(_0x55e766,null))[_0xe855('0x26')](respondWithResult(_0x55e766,null))[_0xe855('0x4b')](handleError(_0x55e766,null));};exports['create']=function(_0x1c4168,_0x94abd4){return db['Team'][_0xe855('0x4c')](_0x1c4168[_0xe855('0x4d')],{})[_0xe855('0x26')](function(_0x34016d){var _0xf8fb17=_0x1c4168[_0xe855('0x4e')][_0xe855('0x4f')]({'plain':!![]});if(!_0xf8fb17)throw new Error(_0xe855('0x50'));if(_0xf8fb17[_0xe855('0x51')]==='user'){var _0x530f4d=_0x34016d[_0xe855('0x4f')]({'plain':!![]});var _0x121fb1=_0xe855('0x52');return db[_0xe855('0x53')][_0xe855('0x4a')]({'where':{'name':_0x121fb1,'userProfileId':_0xf8fb17[_0xe855('0x54')]},'raw':!![]})[_0xe855('0x26')](function(_0x592267){if(_0x592267&&_0x592267[_0xe855('0x55')]===0x0){return db['UserProfileResource'][_0xe855('0x4c')]({'name':_0x530f4d['name'],'resourceId':_0x530f4d['id'],'type':_0x592267[_0xe855('0x2a')],'sectionId':_0x592267['id']},{})[_0xe855('0x26')](function(){return _0x34016d;});}else{return _0x34016d;}})[_0xe855('0x4b')](function(_0x230fbf){logger['error'](_0xe855('0x56'),_0x230fbf);throw _0x230fbf;});}return _0x34016d;})['then'](respondWithResult(_0x94abd4,0xc9))[_0xe855('0x4b')](handleError(_0x94abd4,null));};exports['update']=function(_0x37d0f4,_0x5e09be){if(_0x37d0f4[_0xe855('0x4d')]['id']){delete _0x37d0f4['body']['id'];}return db[_0xe855('0x42')][_0xe855('0x4a')]({'where':{'id':_0x37d0f4[_0xe855('0x48')]['id']}})[_0xe855('0x26')](handleEntityNotFound(_0x5e09be,null))[_0xe855('0x26')](saveUpdates(_0x37d0f4['body'],null))['then'](respondWithResult(_0x5e09be,null))[_0xe855('0x4b')](handleError(_0x5e09be,null));};exports[_0xe855('0x57')]=function(_0x100ecc,_0x120056){var _0x438a74=_0x100ecc[_0xe855('0x48')]['id'];var _0x53db82=[];return db[_0xe855('0x58')]['transaction'](function(_0x251057){var _0x51a829=_0xe855('0x59')+_0x438a74;return db[_0xe855('0x58')][_0xe855('0x30')](_0x51a829,{'type':db[_0xe855('0x5a')][_0xe855('0x5b')]['SELECT'],'raw':!![],'transaction':_0x251057})['then'](function(_0x3a0a0b){_0x53db82=_[_0xe855('0x2b')](_0x3a0a0b,function(_0x2d17a0){return Number(_0x2d17a0['UserId']);});})[_0xe855('0x26')](function(){var _0x448142=_0xe855('0x5c')+_0x438a74;return db[_0xe855('0x58')][_0xe855('0x30')](_0x448142,{'type':db['Sequelize'][_0xe855('0x5b')][_0xe855('0x5d')],'raw':!![],'transaction':_0x251057});})[_0xe855('0x26')](function(_0x464756){var _0x3139e7=_[_0xe855('0x2b')](_0x464756,function(_0x415461){return Number(_0x415461[_0xe855('0x5e')]);});return db['UserVoiceQueue']['destroy']({'where':{'UserId':{'$in':_0x53db82},'VoiceQueueId':{'$in':_0x3139e7}},'transaction':_0x251057});})[_0xe855('0x26')](function(){var _0x3ea669=_0xe855('0x5f')+_0x438a74;return db['sequelize']['query'](_0x3ea669,{'type':db[_0xe855('0x5a')]['QueryTypes'][_0xe855('0x5d')],'raw':!![],'transaction':_0x251057});})[_0xe855('0x26')](function(_0x458d73){var _0x56bf5c=_['map'](_0x458d73,function(_0xdc8834){return Number(_0xdc8834[_0xe855('0x60')]);});return db[_0xe855('0x61')][_0xe855('0x57')]({'where':{'UserId':{'$in':_0x53db82},'MailQueueId':{'$in':_0x56bf5c}},'transaction':_0x251057});})[_0xe855('0x26')](function(){var _0x412d65=_0xe855('0x62')+_0x438a74;return db[_0xe855('0x58')]['query'](_0x412d65,{'type':db[_0xe855('0x5a')]['QueryTypes'][_0xe855('0x5d')],'raw':!![],'transaction':_0x251057});})['then'](function(_0x440f7c){var _0x4b30c1=_[_0xe855('0x2b')](_0x440f7c,function(_0x562847){return Number(_0x562847[_0xe855('0x63')]);});return db[_0xe855('0x64')]['destroy']({'where':{'UserId':{'$in':_0x53db82},'SmsQueueId':{'$in':_0x4b30c1}},'transaction':_0x251057});})[_0xe855('0x26')](function(){var _0x2e35d2=_0xe855('0x65')+_0x438a74;return db['sequelize'][_0xe855('0x30')](_0x2e35d2,{'type':db['Sequelize'][_0xe855('0x5b')][_0xe855('0x5d')],'raw':!![],'transaction':_0x251057});})[_0xe855('0x26')](function(_0x1189d4){var _0x3ef368=_[_0xe855('0x2b')](_0x1189d4,function(_0x20bfd3){return Number(_0x20bfd3['ChatQueueId']);});return db['UserChatQueue'][_0xe855('0x57')]({'where':{'UserId':{'$in':_0x53db82},'ChatQueueId':{'$in':_0x3ef368}},'transaction':_0x251057});})['then'](function(){var _0x3069a7='SELECT\x20FaxQueueId\x20FROM\x20team_has_fax_queues\x20WHERE\x20TeamId\x20=\x20'+_0x438a74;return db[_0xe855('0x58')][_0xe855('0x30')](_0x3069a7,{'type':db['Sequelize']['QueryTypes'][_0xe855('0x5d')],'raw':!![],'transaction':_0x251057});})['then'](function(_0x4c67e8){var _0x1955f2=_[_0xe855('0x2b')](_0x4c67e8,function(_0x228ea0){return Number(_0x228ea0[_0xe855('0x66')]);});return db[_0xe855('0x67')][_0xe855('0x57')]({'where':{'UserId':{'$in':_0x53db82},'FaxQueueId':{'$in':_0x1955f2}},'transaction':_0x251057});})['then'](function(){var _0x3d292e='SELECT\x20OpenchannelQueueId\x20FROM\x20team_has_openchannel_queues\x20WHERE\x20TeamId\x20=\x20'+_0x438a74;return db[_0xe855('0x58')][_0xe855('0x30')](_0x3d292e,{'type':db[_0xe855('0x5a')][_0xe855('0x5b')][_0xe855('0x5d')],'raw':!![],'transaction':_0x251057});})[_0xe855('0x26')](function(_0x385a2c){var _0x4a07cb=_['map'](_0x385a2c,function(_0x45d2b5){return Number(_0x45d2b5[_0xe855('0x68')]);});return db[_0xe855('0x69')][_0xe855('0x57')]({'where':{'UserId':{'$in':_0x53db82},'OpenchannelQueueId':{'$in':_0x4a07cb}},'transaction':_0x251057});})[_0xe855('0x26')](function(){var _0x272c85=_0xe855('0x6a')+_0x438a74;return db[_0xe855('0x58')][_0xe855('0x30')](_0x272c85,{'type':db[_0xe855('0x5a')][_0xe855('0x5b')]['SELECT'],'raw':!![],'transaction':_0x251057});})[_0xe855('0x26')](function(_0x25bf4c){var _0x38729a=_[_0xe855('0x2b')](_0x25bf4c,function(_0x2488e7){return Number(_0x2488e7['WhatsappQueueId']);});return db['UserWhatsappQueue'][_0xe855('0x57')]({'where':{'UserId':{'$in':_0x53db82},'WhatsappQueueId':{'$in':_0x38729a}},'transaction':_0x251057});})[_0xe855('0x26')](function(){return db['TeamVoicePrefix']['find']({'where':{'TeamId':_0x438a74}});})[_0xe855('0x26')](function(_0x152f15){if(_0x152f15===null){return;}return db['UserVoicePrefix']['destroy']({'where':{'UserId':{'$in':_0x53db82},'VoicePrefixId':_0x152f15['VoicePrefixId']},'transaction':_0x251057});})['then'](function(){return db[_0xe855('0x42')][_0xe855('0x57')]({'where':{'id':_0x438a74},'cascade':!![],'transaction':_0x251057});})[_0xe855('0x26')](function(_0x5f50c0){if(_0x5f50c0===0x0){_0x120056[_0xe855('0x27')](0x194);}else{return db[_0xe855('0x6b')]['destroy']({'where':{'type':_0xe855('0x52'),'resourceId':_0x438a74},'cascade':!![],'transaction':_0x251057})['then'](function(){_0x120056[_0xe855('0x1d')](0xcc)['end']();});}})[_0xe855('0x4b')](function(_0x3fc212){_0x120056[_0xe855('0x1d')](0x1f4)[_0xe855('0x6c')](_0x3fc212);});});};exports['getQueues']=function(_0x2a3490,_0x26c342,_0x335e46){return db['Team']['findOne']({'where':{'id':_0x2a3490[_0xe855('0x48')]['id']}})[_0xe855('0x26')](handleEntityNotFound(_0x26c342,null))[_0xe855('0x26')](function(_0x2bae25){if(!_0x2a3490[_0xe855('0x30')][_0xe855('0x6d')]||!utils['isValidChannel'](_0x2a3490['query'][_0xe855('0x6d')])){throw new db[(_0xe855('0x5a'))][(_0xe855('0x6e'))](_0xe855('0x6f'));}var _0x41c186={};var _0x177946={};_0x177946[_0xe855('0x34')]=_[_0xe855('0x31')](db[_[_0xe855('0x70')](_0x2a3490[_0xe855('0x30')][_0xe855('0x6d')][_0xe855('0x71')]())+_0xe855('0x72')]['rawAttributes']);_0x177946['query']=_[_0xe855('0x31')](_0x2a3490[_0xe855('0x30')]);_0x177946['filters']=_[_0xe855('0x33')](_0x177946['model'],_0x177946[_0xe855('0x30')]);_0x41c186[_0xe855('0x32')]=_[_0xe855('0x33')](_0x177946['model'],qs[_0xe855('0x35')](_0x2a3490[_0xe855('0x30')]['fields']));_0x41c186['attributes']=_0x41c186[_0xe855('0x32')][_0xe855('0x36')]?_0x41c186[_0xe855('0x32')]:_0x177946[_0xe855('0x34')];_0x41c186[_0xe855('0x21')]=qs[_0xe855('0x21')](_0x2a3490[_0xe855('0x30')][_0xe855('0x21')]);_0x41c186['offset']=qs[_0xe855('0x1f')](_0x2a3490[_0xe855('0x30')][_0xe855('0x1f')]);_0x41c186[_0xe855('0x39')]=qs[_0xe855('0x3a')](_0x2a3490['query'][_0xe855('0x3a')]);_0x41c186['where']=qs[_0xe855('0x3c')](_['pick'](_0x2a3490[_0xe855('0x30')],_0x177946[_0xe855('0x3c')]));_0x41c186=_[_0xe855('0x40')]({},_0x41c186,_0x2a3490['options']);return _0x2bae25['get'+_[_0xe855('0x70')](_0x2a3490[_0xe855('0x30')][_0xe855('0x6d')]['toLowerCase']())+'Queues'](_0x41c186);})['then'](respondWithResult(_0x26c342,null))[_0xe855('0x4b')](handleError(_0x26c342,null));};exports[_0xe855('0x73')]=function(_0x25e625,_0x3ab2e9,_0x4de4cb){return db[_0xe855('0x42')][_0xe855('0x74')]({'where':{'id':_0x25e625['params']['id']}})[_0xe855('0x26')](function(_0xd5d6bf){if(_0xd5d6bf){if(!_0x25e625['body']['channel']||!utils['isValidChannel'](_0x25e625[_0xe855('0x4d')][_0xe855('0x6d')])){throw new db['Sequelize'][(_0xe855('0x6e'))](_0xe855('0x6f'));}return _0xd5d6bf['add'+_[_0xe855('0x70')](_0x25e625[_0xe855('0x4d')][_0xe855('0x6d')][_0xe855('0x71')]())+_0xe855('0x75')](_0x25e625[_0xe855('0x4d')][_0xe855('0x76')]);}return null;})[_0xe855('0x26')](handleEntityNotFound(_0x3ab2e9,null))[_0xe855('0x26')](respondWithStatusCode(_0x3ab2e9,null))[_0xe855('0x4b')](handleError(_0x3ab2e9,null));};exports[_0xe855('0x77')]=function(_0x471207,_0x15bb1d,_0x7fa765){return db[_0xe855('0x42')][_0xe855('0x74')]({'where':{'id':_0x471207[_0xe855('0x48')]['id']}})['then'](function(_0x551fa4){if(_0x551fa4){if(!_0x471207[_0xe855('0x30')][_0xe855('0x6d')]||!utils[_0xe855('0x78')](_0x471207[_0xe855('0x30')][_0xe855('0x6d')])){throw new db['Sequelize'][(_0xe855('0x6e'))](_0xe855('0x6f'));}return _0x551fa4[_0xe855('0x79')+_[_0xe855('0x70')](_0x471207[_0xe855('0x30')][_0xe855('0x6d')][_0xe855('0x71')]())+_0xe855('0x75')](_0x471207[_0xe855('0x30')][_0xe855('0x76')]);}return null;})[_0xe855('0x26')](handleEntityNotFound(_0x15bb1d,null))[_0xe855('0x26')](respondWithStatusCode(_0x15bb1d,null))[_0xe855('0x4b')](handleError(_0x15bb1d,null));};exports[_0xe855('0x7a')]=function(_0x53e2de,_0xf6bc0c){var _0x4f7120=_[_0xe855('0x7b')](_0x53e2de[_0xe855('0x4d')][_0xe855('0x76')])?_0x53e2de['body'][_0xe855('0x76')]:[_0x53e2de[_0xe855('0x4d')][_0xe855('0x76')]];var _0x1048c3=_0x53e2de['params']['id'];return db[_0xe855('0x42')][_0xe855('0x4a')]({'where':{'id':_0x1048c3}})[_0xe855('0x26')](handleEntityNotFound(_0xf6bc0c,null))[_0xe855('0x26')](function(_0x5bec13){if(_0x5bec13){var _0x5a2b19=[_0xe855('0x7c'),_0xe855('0x7d'),'Mail',_0xe855('0x7e'),_0xe855('0x7f'),_0xe855('0x80'),'Whatsapp'];return db[_0xe855('0x58')][_0xe855('0x81')](function(_0x3ed76b){var _0x49717e=_[_0xe855('0x2b')](_0x5a2b19,function(_0xdceae0){var _0x4d53b0={'attributes':['id',_0xe855('0x2a')]};if(_0xdceae0===_0xe855('0x7c')){_0x4d53b0[_0xe855('0x82')]={'attributes':[_0xe855('0x83')]};}return _0x5bec13[_0xe855('0x4f')+_0xdceae0+'Queues'](_0x4d53b0)['then'](function(_0x497e97){var _0x3d240e=_[_0xe855('0x2b')](_0x497e97,function(_0x29604b){var _0x2c1126=_[_0xe855('0x2b')](_0x4f7120,function(_0x480c69){var _0x4a0dd8={'where':{'UserId':_0x480c69,[_0xdceae0+'QueueId']:_0x29604b['id']},'transaction':_0x3ed76b};if(_0xdceae0===_0xe855('0x7c')){_0x4a0dd8[_0xe855('0x84')]={'penalty':_0x29604b[_0xe855('0x85')]['penalty']};}return db[_0xe855('0x86')+_0xdceae0+_0xe855('0x72')][_0xe855('0x87')](_0x4a0dd8)[_0xe855('0x26')](function(){socket[_0xe855('0x88')]('user'+_0xdceae0+'Queue:save',{'UserId':_0x480c69,[_0xdceae0+_0xe855('0x89')]:_0x29604b['id']});if(_0xdceae0!==_0xe855('0x7c')){return;}return db[_0xe855('0x86')][_0xe855('0x45')]({'where':{'id':_0x4f7120,'online':0x1},'attributes':['id',_0xe855('0x2a'),_0xe855('0x8a'),_0xe855('0x8b'),_0xe855('0x8c')],'raw':!![]})[_0xe855('0x26')](function(_0x4cc594){var _0x55b964=_[_0xe855('0x2b')](_0x4cc594,function(_0x457509){return db[_0xe855('0x8d')][_0xe855('0x8e')]({'membername':_0x457509[_0xe855('0x2a')],'UserId':_0x457509['id'],'queue_name':_0x29604b[_0xe855('0x2a')],'VoiceQueueId':_0x29604b['id'],'interface':_[_0xe855('0x8f')](_0x457509[_0xe855('0x8c')])?util['format']('SIP/%s',_0x457509[_0xe855('0x2a')]):_0x457509[_0xe855('0x8c')],'paused':_0x457509['voicePause']||![],'penalty':_0x29604b[_0xe855('0x85')]['penalty']},{'transaction':_0x3ed76b});});return Promise[_0xe855('0x90')](_0x55b964);});});});return Promise[_0xe855('0x90')](_0x2c1126);});return Promise['all'](_0x3d240e);})[_0xe855('0x26')](function(){return db[_0xe855('0x91')][_0xe855('0x74')]({'where':{'teamId':_0x1048c3}})[_0xe855('0x26')](function(_0x45a22a){if(_0x45a22a){var _0x554b59=_[_0xe855('0x2b')](_0x4f7120,function(_0xda8f4){db[_0xe855('0x92')][_0xe855('0x8e')]({'UserId':_0xda8f4,'VoicePrefixId':_0x45a22a[_0xe855('0x93')]});});return Promise['all'](_0x554b59);}});});});return Promise[_0xe855('0x90')](_0x49717e)['then'](function(){return _0x5bec13[_0xe855('0x7a')](_0x4f7120,{'transaction':_0x3ed76b})[_0xe855('0x94')](function(_0x2e82e7){return _0x2e82e7;});});});}})[_0xe855('0x26')](respondWithResult(_0xf6bc0c,null))[_0xe855('0x4b')](handleError(_0xf6bc0c,null));};exports[_0xe855('0x95')]=function(_0x34ecf7,_0x39a375){var _0x17eae9=_[_0xe855('0x7b')](_0x34ecf7[_0xe855('0x30')][_0xe855('0x76')])?_0x34ecf7[_0xe855('0x30')][_0xe855('0x76')]:[_0x34ecf7[_0xe855('0x30')]['ids']];var _0x395396=_0x34ecf7['params']['id'];return db[_0xe855('0x42')][_0xe855('0x4a')]({'where':{'id':_0x395396}})[_0xe855('0x26')](handleEntityNotFound(_0x39a375,null))['then'](function(_0x5c8651){if(_0x5c8651){var _0x2cb71f=['Voice',_0xe855('0x7d'),'Mail',_0xe855('0x7e'),_0xe855('0x7f'),_0xe855('0x80'),_0xe855('0x96')];return db['sequelize'][_0xe855('0x81')](function(_0x4c359c){var _0x3a3f6a=_[_0xe855('0x2b')](_0x2cb71f,function(_0x4c475c){var _0x377ed6={'attributes':['id',_0xe855('0x2a')]};return _0x5c8651['get'+_0x4c475c+_0xe855('0x75')](_0x377ed6)['then'](function(_0x393a36){var _0x42b7b7=_[_0xe855('0x2b')](_0x393a36,function(_0x4afb88){return _0x4afb88[_0xe855('0x95')](_0x17eae9,{'transaction':_0x4c359c})['then'](function(){var _0x19a509=_[_0xe855('0x2b')](_0x17eae9,function(_0x1aff6a){socket[_0xe855('0x88')]('user'+_0x4c475c+_0xe855('0x97'),{'UserId':Number(_0x1aff6a),[_0x4c475c+_0xe855('0x89')]:_0x4afb88['id']});if(_0x4c475c!=='Voice'){return;}return db[_0xe855('0x8d')][_0xe855('0x57')]({'where':{'VoiceQueueId':_0x4afb88['id'],'UserId':_0x1aff6a},'transaction':_0x4c359c});});return Promise[_0xe855('0x90')](_0x19a509);});});return Promise['all'](_0x42b7b7);});});return Promise[_0xe855('0x90')](_0x3a3f6a)[_0xe855('0x26')](function(){return _0x5c8651['removeAgents'](_0x17eae9,{'transaction':_0x4c359c});})[_0xe855('0x26')](function(){return db[_0xe855('0x91')][_0xe855('0x74')]({'where':{'teamId':_0x395396}})[_0xe855('0x26')](function(_0x5330c7){if(_0x5330c7){var _0x512312=_['map'](_0x17eae9,function(_0xa056ef){db[_0xe855('0x92')][_0xe855('0x57')]({'where':{'UserId':_0xa056ef,'VoicePrefixId':_0x5330c7[_0xe855('0x93')]}});});return Promise['all'](_0x512312);}});});});}})[_0xe855('0x26')](respondWithStatusCode(_0x39a375,null))[_0xe855('0x4b')](handleError(_0x39a375,null));};exports[_0xe855('0x98')]=function(_0xa56ab9,_0x5235eb,_0x123d70){var _0x551989={};var _0x3b9f5e={};var _0x3a0e78;var _0x22622d;return db[_0xe855('0x42')][_0xe855('0x74')]({'where':{'id':_0xa56ab9[_0xe855('0x48')]['id']}})[_0xe855('0x26')](handleEntityNotFound(_0x5235eb,null))[_0xe855('0x26')](function(_0x5eabbb){if(_0x5eabbb){_0x3a0e78=_0x5eabbb;_0x3b9f5e[_0xe855('0x34')]=_[_0xe855('0x31')](db['User'][_0xe855('0x2c')]);_0x3b9f5e[_0xe855('0x30')]=_[_0xe855('0x31')](_0xa56ab9['query']);_0x3b9f5e['filters']=_[_0xe855('0x33')](_0x3b9f5e[_0xe855('0x34')],_0x3b9f5e['query']);_0x551989['attributes']=_[_0xe855('0x33')](_0x3b9f5e[_0xe855('0x34')],qs['fields'](_0xa56ab9[_0xe855('0x30')][_0xe855('0x35')]));_0x551989[_0xe855('0x32')]=_0x551989[_0xe855('0x32')][_0xe855('0x36')]?_0x551989[_0xe855('0x32')]:_0x3b9f5e['model'];_0x551989[_0xe855('0x39')]=qs[_0xe855('0x3a')](_0xa56ab9[_0xe855('0x30')][_0xe855('0x3a')]);_0x551989['where']=qs['filters'](_['pick'](_0xa56ab9[_0xe855('0x30')],_0x3b9f5e[_0xe855('0x3c')]));if(_0xa56ab9[_0xe855('0x30')][_0xe855('0x3e')]){_0x551989[_0xe855('0x3b')]=_[_0xe855('0x40')](_0x551989[_0xe855('0x3b')],{'$or':_['map'](_0x551989[_0xe855('0x32')],function(_0x87cb48){var _0x2f84ae={};_0x2f84ae[_0x87cb48]={'$like':'%'+_0xa56ab9[_0xe855('0x30')][_0xe855('0x3e')]+'%'};return _0x2f84ae;})});}_0x551989=_[_0xe855('0x40')]({},_0x551989,_0xa56ab9['options']);return _0x3a0e78[_0xe855('0x98')](_0x551989);}})['then'](function(_0x426058){if(_0x426058){_0x22622d=_0x426058['length'];if(!_0xa56ab9[_0xe855('0x30')]['hasOwnProperty'](_0xe855('0x38'))){_0x551989[_0xe855('0x21')]=qs[_0xe855('0x21')](_0xa56ab9[_0xe855('0x30')]['limit']);_0x551989['offset']=qs[_0xe855('0x1f')](_0xa56ab9[_0xe855('0x30')]['offset']);}return _0x3a0e78[_0xe855('0x98')](_0x551989);}})['then'](function(_0x2c0f3a){if(_0x2c0f3a){return _0x2c0f3a?{'count':_0x22622d,'rows':_0x2c0f3a}:null;}})[_0xe855('0x26')](respondWithResult(_0x5235eb,null))[_0xe855('0x4b')](handleError(_0x5235eb,null));};
\ No newline at end of file