Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / api / team / team.controller.js
index 06cf3da..cca3bca 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x23bb=['request-promise','bluebird','mustache','util','ejs','jsforce','to-csv','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./team.socket','register','sendStatus','status','end','json','count','offset','set','Content-Range','apply','reject','save','update','then','Teams','UserProfileResource','destroy','error','stack','name','send','index','map','Team','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','length','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','params','options','find','create','body','user','get','role','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','getQueues','findOne','channel','isValidChannel','Sequelize','ValidationError','capitalize','Queue','fields','Queues','addQueues','Unknown\x20channel','add','toLowerCase','ids','addAgents','Voice','Chat','Sms','Fax','Openchannel','each','User','online','voicePause','UserVoiceQueueRt','interface','SIP/%s','omit','spread','userTeam:save','removeAgents','chat','sms','fax','voice','isArray','emit','userTeam:remove','getAgents','hasOwnProperty','html-pdf','zip-dir','fast-json-patch'];(function(_0x1f9fe1,_0x55e3bf){var _0x504a2f=function(_0x1c0e3e){while(--_0x1c0e3e){_0x1f9fe1['push'](_0x1f9fe1['shift']());}};_0x504a2f(++_0x55e3bf);}(_0x23bb,0x79));var _0xb23b=function(_0xaaa4fd,_0x9c5f4b){_0xaaa4fd=_0xaaa4fd-0x0;var _0xd428ce=_0x23bb[_0xaaa4fd];return _0xd428ce;};'use strict';var pdf=require(_0xb23b('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xb23b('0x1'));var jsonpatch=require(_0xb23b('0x2'));var rp=require(_0xb23b('0x3'));var moment=require('moment');var BPromise=require(_0xb23b('0x4'));var Mustache=require(_0xb23b('0x5'));var util=require(_0xb23b('0x6'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xb23b('0x7'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xb23b('0x8'));var deskjs=require('desk.js');var toCsv=require(_0xb23b('0x9'));var querystring=require('querystring');var Papa=require(_0xb23b('0xa'));var Redis=require(_0xb23b('0xb'));var authService=require('../../components/auth/service');var qs=require(_0xb23b('0xc'));var as=require(_0xb23b('0xd'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb23b('0xe'))(_0xb23b('0xf'));var utils=require(_0xb23b('0x10'));var config=require('../../config/environment');var db=require(_0xb23b('0x11'))['db'];config[_0xb23b('0x12')]=_[_0xb23b('0x13')](config[_0xb23b('0x12')],{'host':_0xb23b('0x14'),'port':0x18eb});var socket=require(_0xb23b('0x15'))(new Redis(config[_0xb23b('0x12')]));require(_0xb23b('0x16'))[_0xb23b('0x17')](socket);function respondWithStatusCode(_0x2ff6e8,_0x3ff740){_0x3ff740=_0x3ff740||0xcc;return function(_0xc07d9b){if(_0xc07d9b){return _0x2ff6e8[_0xb23b('0x18')](_0x3ff740);}return _0x2ff6e8[_0xb23b('0x19')](_0x3ff740)[_0xb23b('0x1a')]();};}function respondWithResult(_0x1a03a6,_0xaa2b4e){_0xaa2b4e=_0xaa2b4e||0xc8;return function(_0x55670e){if(_0x55670e){return _0x1a03a6[_0xb23b('0x19')](_0xaa2b4e)[_0xb23b('0x1b')](_0x55670e);}};}function respondWithFilteredResult(_0xe66b4c,_0x2d9584){return function(_0x158e02){if(_0x158e02){var _0x582554=_0x158e02[_0xb23b('0x1c')],_0x1db9a7=_0x2d9584[_0xb23b('0x1d')],_0x547704=_0x2d9584['offset']+_0x2d9584['limit'],_0x2cd266;if(_0x547704>=_0x582554){_0x547704=_0x582554;_0x2cd266=0xc8;}else{_0x2cd266=0xce;}_0xe66b4c[_0xb23b('0x19')](_0x2cd266);return _0xe66b4c[_0xb23b('0x1e')](_0xb23b('0x1f'),_0x1db9a7+'-'+_0x547704+'/'+_0x582554)[_0xb23b('0x1b')](_0x158e02);}return null;};}function patchUpdates(_0x1ca831){return function(_0x3b27f8){try{jsonpatch[_0xb23b('0x20')](_0x3b27f8,_0x1ca831,!![]);}catch(_0x4e2b33){return BPromise[_0xb23b('0x21')](_0x4e2b33);}return _0x3b27f8[_0xb23b('0x22')]();};}function saveUpdates(_0xe57b69,_0x2ea872){return function(_0x5f55fe){if(_0x5f55fe){return _0x5f55fe[_0xb23b('0x23')](_0xe57b69)[_0xb23b('0x24')](function(_0x4c2d1d){return _0x4c2d1d;});}return null;};}function removeEntity(_0x11aaac,_0x5b7777){return function(_0x41ddae){if(_0x41ddae){return _0x41ddae['destroy']()[_0xb23b('0x24')](function(){var _0x38b4ae=_0x41ddae['get']({'plain':!![]});var _0x2040c6=_0xb23b('0x25');return db[_0xb23b('0x26')][_0xb23b('0x27')]({'where':{'type':_0x2040c6,'resourceId':_0x38b4ae['id']}})[_0xb23b('0x24')](function(){return _0x41ddae;});})['then'](function(){_0x11aaac[_0xb23b('0x19')](0xcc)[_0xb23b('0x1a')]();});}};}function handleEntityNotFound(_0x21c17c,_0x35a723){return function(_0x3c8256){if(!_0x3c8256){_0x21c17c[_0xb23b('0x18')](0x194);}return _0x3c8256;};}function handleError(_0x405fe7,_0x40622d){_0x40622d=_0x40622d||0x1f4;return function(_0x4b3eb5){logger[_0xb23b('0x28')](_0x4b3eb5[_0xb23b('0x29')]);if(_0x4b3eb5[_0xb23b('0x2a')]){delete _0x4b3eb5['name'];}_0x405fe7[_0xb23b('0x19')](_0x40622d)[_0xb23b('0x2b')](_0x4b3eb5);};}exports[_0xb23b('0x2c')]=function(_0x307367,_0x8a9bf2){var _0x496a38={},_0x8c65f3={},_0xe7193d={'count':0x0,'rows':[]};var _0x3d39f4=_[_0xb23b('0x2d')](db[_0xb23b('0x2e')][_0xb23b('0x2f')],function(_0x2f4823){return{'name':_0x2f4823[_0xb23b('0x30')],'type':_0x2f4823[_0xb23b('0x31')][_0xb23b('0x32')]};});_0x8c65f3[_0xb23b('0x33')]=_[_0xb23b('0x2d')](_0x3d39f4,'name');_0x8c65f3[_0xb23b('0x34')]=_[_0xb23b('0x35')](_0x307367[_0xb23b('0x34')]);_0x8c65f3[_0xb23b('0x36')]=_['intersection'](_0x8c65f3[_0xb23b('0x33')],_0x8c65f3[_0xb23b('0x34')]);_0x496a38[_0xb23b('0x37')]=_[_0xb23b('0x38')](_0x8c65f3[_0xb23b('0x33')],qs['fields'](_0x307367[_0xb23b('0x34')]['fields']));_0x496a38[_0xb23b('0x37')]=_0x496a38['attributes'][_0xb23b('0x39')]?_0x496a38['attributes']:_0x8c65f3[_0xb23b('0x33')];if(!_0x307367['query']['hasOwnProperty'](_0xb23b('0x3a'))){_0x496a38[_0xb23b('0x3b')]=qs[_0xb23b('0x3b')](_0x307367['query'][_0xb23b('0x3b')]);_0x496a38[_0xb23b('0x1d')]=qs[_0xb23b('0x1d')](_0x307367[_0xb23b('0x34')][_0xb23b('0x1d')]);}_0x496a38[_0xb23b('0x3c')]=qs[_0xb23b('0x3d')](_0x307367[_0xb23b('0x34')][_0xb23b('0x3d')]);_0x496a38[_0xb23b('0x3e')]=qs['filters'](_[_0xb23b('0x3f')](_0x307367[_0xb23b('0x34')],_0x8c65f3[_0xb23b('0x36')]));if(_0x307367[_0xb23b('0x34')][_0xb23b('0x40')]){_0x496a38[_0xb23b('0x3e')]=_[_0xb23b('0x41')](_0x496a38[_0xb23b('0x3e')],{'$or':_[_0xb23b('0x2d')](_0x3d39f4,function(_0x24b7a7){if(_0x24b7a7[_0xb23b('0x31')]!==_0xb23b('0x42')){var _0x3555f2={};_0x3555f2[_0x24b7a7[_0xb23b('0x2a')]]={'$like':'%'+_0x307367[_0xb23b('0x34')]['filter']+'%'};return _0x3555f2;}})});}_0x496a38=_[_0xb23b('0x41')]({},_0x496a38,_0x307367['options']);var _0xb2312f={'where':_0x496a38[_0xb23b('0x3e')]};return db[_0xb23b('0x2e')][_0xb23b('0x1c')](_0xb2312f)[_0xb23b('0x24')](function(_0xea6928){_0xe7193d['count']=_0xea6928;if(_0x307367[_0xb23b('0x34')][_0xb23b('0x43')]){_0x496a38[_0xb23b('0x44')]=[{'all':!![]}];}return db[_0xb23b('0x2e')][_0xb23b('0x45')](_0x496a38);})[_0xb23b('0x24')](function(_0x1f42da){_0xe7193d[_0xb23b('0x46')]=_0x1f42da;return _0xe7193d;})[_0xb23b('0x24')](respondWithFilteredResult(_0x8a9bf2,_0x496a38))[_0xb23b('0x47')](handleError(_0x8a9bf2,null));};exports[_0xb23b('0x48')]=function(_0x4d9a62,_0xb075e7){var _0x20643f={'raw':![],'where':{'id':_0x4d9a62[_0xb23b('0x49')]['id']}},_0x54c3fd={};_0x54c3fd[_0xb23b('0x33')]=_['keys'](db[_0xb23b('0x2e')][_0xb23b('0x2f')]);_0x54c3fd[_0xb23b('0x34')]=_[_0xb23b('0x35')](_0x4d9a62[_0xb23b('0x34')]);_0x54c3fd[_0xb23b('0x36')]=_[_0xb23b('0x38')](_0x54c3fd['model'],_0x54c3fd[_0xb23b('0x34')]);_0x20643f[_0xb23b('0x37')]=_[_0xb23b('0x38')](_0x54c3fd['model'],qs['fields'](_0x4d9a62[_0xb23b('0x34')]['fields']));_0x20643f[_0xb23b('0x37')]=_0x20643f[_0xb23b('0x37')]['length']?_0x20643f[_0xb23b('0x37')]:_0x54c3fd[_0xb23b('0x33')];if(_0x4d9a62[_0xb23b('0x34')]['includeAll']){_0x20643f[_0xb23b('0x44')]=[{'all':!![]}];}_0x20643f=_[_0xb23b('0x41')]({},_0x20643f,_0x4d9a62[_0xb23b('0x4a')]);return db['Team'][_0xb23b('0x4b')](_0x20643f)[_0xb23b('0x24')](handleEntityNotFound(_0xb075e7,null))[_0xb23b('0x24')](respondWithResult(_0xb075e7,null))[_0xb23b('0x47')](handleError(_0xb075e7,null));};exports[_0xb23b('0x4c')]=function(_0x3dd7a1,_0x3b9170){return db[_0xb23b('0x2e')][_0xb23b('0x4c')](_0x3dd7a1[_0xb23b('0x4d')],{})[_0xb23b('0x24')](function(_0x304851){var _0xabc356=_0x3dd7a1[_0xb23b('0x4e')][_0xb23b('0x4f')]({'plain':!![]});if(!_0xabc356)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0xabc356[_0xb23b('0x50')]==='user'){var _0xb6460b=_0x304851['get']({'plain':!![]});var _0x516cc2=_0xb23b('0x25');return db['UserProfileSection'][_0xb23b('0x4b')]({'where':{'name':_0x516cc2,'userProfileId':_0xabc356[_0xb23b('0x51')]},'raw':!![]})['then'](function(_0x192d69){if(_0x192d69&&_0x192d69['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0xb6460b[_0xb23b('0x2a')],'resourceId':_0xb6460b['id'],'type':_0x192d69[_0xb23b('0x2a')],'sectionId':_0x192d69['id']},{})[_0xb23b('0x24')](function(){return _0x304851;});}else{return _0x304851;}})[_0xb23b('0x47')](function(_0x49878f){logger['error'](_0xb23b('0x52'),_0x49878f);throw _0x49878f;});}return _0x304851;})['then'](respondWithResult(_0x3b9170,0xc9))[_0xb23b('0x47')](handleError(_0x3b9170,null));};exports[_0xb23b('0x23')]=function(_0x32ae92,_0x125077){if(_0x32ae92[_0xb23b('0x4d')]['id']){delete _0x32ae92[_0xb23b('0x4d')]['id'];}return db[_0xb23b('0x2e')][_0xb23b('0x4b')]({'where':{'id':_0x32ae92['params']['id']}})[_0xb23b('0x24')](handleEntityNotFound(_0x125077,null))[_0xb23b('0x24')](saveUpdates(_0x32ae92[_0xb23b('0x4d')],null))[_0xb23b('0x24')](respondWithResult(_0x125077,null))[_0xb23b('0x47')](handleError(_0x125077,null));};exports[_0xb23b('0x27')]=function(_0x487536,_0x583875){return db['Team'][_0xb23b('0x4b')]({'where':{'id':_0x487536[_0xb23b('0x49')]['id']}})['then'](handleEntityNotFound(_0x583875,null))[_0xb23b('0x24')](removeEntity(_0x583875,null))['catch'](handleError(_0x583875,null));};exports[_0xb23b('0x53')]=function(_0x284092,_0x630faf,_0x11085e){return db[_0xb23b('0x2e')][_0xb23b('0x54')]({'where':{'id':_0x284092[_0xb23b('0x49')]['id']}})[_0xb23b('0x24')](handleEntityNotFound(_0x630faf,null))[_0xb23b('0x24')](function(_0x2583c3){if(!_0x284092['query'][_0xb23b('0x55')]||!utils[_0xb23b('0x56')](_0x284092[_0xb23b('0x34')][_0xb23b('0x55')])){throw new db[(_0xb23b('0x57'))][(_0xb23b('0x58'))]('Unknown\x20channel');}var _0x43c6a9={};var _0x1aa2b6={};_0x1aa2b6[_0xb23b('0x33')]=_[_0xb23b('0x35')](db[_[_0xb23b('0x59')](_0x284092['query'][_0xb23b('0x55')]['toLowerCase']())+_0xb23b('0x5a')][_0xb23b('0x2f')]);_0x1aa2b6[_0xb23b('0x34')]=_[_0xb23b('0x35')](_0x284092[_0xb23b('0x34')]);_0x1aa2b6[_0xb23b('0x36')]=_[_0xb23b('0x38')](_0x1aa2b6[_0xb23b('0x33')],_0x1aa2b6[_0xb23b('0x34')]);_0x43c6a9[_0xb23b('0x37')]=_[_0xb23b('0x38')](_0x1aa2b6[_0xb23b('0x33')],qs[_0xb23b('0x5b')](_0x284092[_0xb23b('0x34')][_0xb23b('0x5b')]));_0x43c6a9['attributes']=_0x43c6a9[_0xb23b('0x37')][_0xb23b('0x39')]?_0x43c6a9[_0xb23b('0x37')]:_0x1aa2b6[_0xb23b('0x33')];_0x43c6a9[_0xb23b('0x3b')]=qs[_0xb23b('0x3b')](_0x284092[_0xb23b('0x34')][_0xb23b('0x3b')]);_0x43c6a9['offset']=qs[_0xb23b('0x1d')](_0x284092['query'][_0xb23b('0x1d')]);_0x43c6a9['order']=qs['sort'](_0x284092[_0xb23b('0x34')][_0xb23b('0x3d')]);_0x43c6a9['where']=qs[_0xb23b('0x36')](_[_0xb23b('0x3f')](_0x284092['query'],_0x1aa2b6[_0xb23b('0x36')]));_0x43c6a9=_[_0xb23b('0x41')]({},_0x43c6a9,_0x284092['options']);return _0x2583c3[_0xb23b('0x4f')+_[_0xb23b('0x59')](_0x284092[_0xb23b('0x34')]['channel']['toLowerCase']())+_0xb23b('0x5c')](_0x43c6a9);})[_0xb23b('0x24')](respondWithResult(_0x630faf,null))[_0xb23b('0x47')](handleError(_0x630faf,null));};exports[_0xb23b('0x5d')]=function(_0x2ed5ec,_0x48735f,_0x604b0d){return db[_0xb23b('0x2e')][_0xb23b('0x54')]({'where':{'id':_0x2ed5ec[_0xb23b('0x49')]['id']}})['then'](function(_0x310bfa){if(_0x310bfa){if(!_0x2ed5ec[_0xb23b('0x4d')][_0xb23b('0x55')]||!utils['isValidChannel'](_0x2ed5ec['body']['channel'])){throw new db[(_0xb23b('0x57'))][(_0xb23b('0x58'))](_0xb23b('0x5e'));}return _0x310bfa[_0xb23b('0x5f')+_[_0xb23b('0x59')](_0x2ed5ec[_0xb23b('0x4d')][_0xb23b('0x55')][_0xb23b('0x60')]())+_0xb23b('0x5c')](_0x2ed5ec[_0xb23b('0x4d')][_0xb23b('0x61')]);}return null;})[_0xb23b('0x24')](handleEntityNotFound(_0x48735f,null))['then'](respondWithStatusCode(_0x48735f,null))[_0xb23b('0x47')](handleError(_0x48735f,null));};exports['removeQueues']=function(_0x25cfa0,_0x5387f4,_0x170e35){return db[_0xb23b('0x2e')]['findOne']({'where':{'id':_0x25cfa0['params']['id']}})[_0xb23b('0x24')](function(_0x56044d){if(_0x56044d){if(!_0x25cfa0[_0xb23b('0x34')]['channel']||!utils[_0xb23b('0x56')](_0x25cfa0['query']['channel'])){throw new db['Sequelize']['ValidationError'](_0xb23b('0x5e'));}return _0x56044d['remove'+_[_0xb23b('0x59')](_0x25cfa0[_0xb23b('0x34')][_0xb23b('0x55')][_0xb23b('0x60')]())+'Queues'](_0x25cfa0[_0xb23b('0x34')][_0xb23b('0x61')]);}return null;})[_0xb23b('0x24')](handleEntityNotFound(_0x5387f4,null))['then'](respondWithStatusCode(_0x5387f4,null))['catch'](handleError(_0x5387f4,null));};exports[_0xb23b('0x62')]=function(_0x4eb44b,_0x4e9781,_0x4745e9){return db[_0xb23b('0x2e')][_0xb23b('0x4b')]({'where':{'id':_0x4eb44b['params']['id']}})[_0xb23b('0x24')](handleEntityNotFound(_0x4e9781,null))[_0xb23b('0x24')](function(_0x4aa507){if(_0x4aa507){var _0x36a825=[_0xb23b('0x63'),_0xb23b('0x64'),'Mail',_0xb23b('0x65'),_0xb23b('0x66'),_0xb23b('0x67')];return BPromise[_0xb23b('0x68')](_0x36a825,function(_0x2285a1){return _0x4aa507[_0xb23b('0x4f')+_0x2285a1+_0xb23b('0x5c')]({'attributes':['id',_0xb23b('0x2a')]})['then'](function(_0x4b2fe1){return BPromise[_0xb23b('0x68')](_0x4b2fe1,function(_0x43c8d8){return _0x43c8d8[_0xb23b('0x62')](_0x4eb44b[_0xb23b('0x4d')][_0xb23b('0x61')])[_0xb23b('0x24')](function(){if(_0x2285a1===_0xb23b('0x63')){return db[_0xb23b('0x69')][_0xb23b('0x45')]({'where':{'id':_0x4eb44b[_0xb23b('0x4d')]['ids']},'attributes':['id',_0xb23b('0x2a'),_0xb23b('0x6a'),_0xb23b('0x6b'),'interface'],'raw':!![]})[_0xb23b('0x24')](function(_0x53440c){return BPromise[_0xb23b('0x68')](_[_0xb23b('0x40')](_0x53440c,{'online':0x1}),function(_0x38216b){return db[_0xb23b('0x6c')]['upsert']({'membername':_0x38216b[_0xb23b('0x2a')],'UserId':_0x38216b['id'],'queue_name':_0x43c8d8[_0xb23b('0x2a')],'VoiceQueueId':_0x43c8d8['id'],'interface':_['isNil'](_0x38216b[_0xb23b('0x6d')])?util['format'](_0xb23b('0x6e'),_0x38216b[_0xb23b('0x2a')]):_0x38216b['interface'],'paused':_0x38216b['voicePause']||![],'penalty':0x0});});});}});});})['then'](function(){return _0x4aa507;});})[_0xb23b('0x24')](function(){return _0x4aa507;});}})[_0xb23b('0x24')](function(_0x4c0baa){if(_0x4c0baa){return _0x4c0baa[_0xb23b('0x62')](_0x4eb44b[_0xb23b('0x4d')][_0xb23b('0x61')],_[_0xb23b('0x6f')](_0x4eb44b[_0xb23b('0x4d')],['ids','id'])||{})[_0xb23b('0x70')](function(_0x3f17a3){for(var _0x1369cb=0x0;_0x1369cb<_0x4eb44b[_0xb23b('0x4d')][_0xb23b('0x61')][_0xb23b('0x39')];_0x1369cb+=0x1){socket['emit'](_0xb23b('0x71'),{'UserId':_0x4eb44b[_0xb23b('0x4d')][_0xb23b('0x61')][_0x1369cb],'TeamId':_0x4eb44b[_0xb23b('0x49')]['id']});}return _0x3f17a3;});}})[_0xb23b('0x24')](respondWithResult(_0x4e9781,null))['catch'](handleError(_0x4e9781,null));};exports[_0xb23b('0x72')]=function(_0xf301d7,_0x274dc2,_0x1c57da){return db[_0xb23b('0x2e')]['find']({'where':{'id':_0xf301d7[_0xb23b('0x49')]['id']}})[_0xb23b('0x24')](handleEntityNotFound(_0x274dc2,null))[_0xb23b('0x24')](function(_0x409984){if(_0x409984){return BPromise[_0xb23b('0x68')](['voice',_0xb23b('0x73'),'mail',_0xb23b('0x74'),_0xb23b('0x75'),'openchannel'],function(_0x570cbf){return _0x409984['get'+_[_0xb23b('0x59')](_0x570cbf)+_0xb23b('0x5c')]({'attributes':['id',_0xb23b('0x2a')]})[_0xb23b('0x24')](function(_0xeb0d07){return BPromise['each'](_0xeb0d07,function(_0x347248){return _0x347248[_0xb23b('0x72')](_0xf301d7[_0xb23b('0x34')][_0xb23b('0x61')])[_0xb23b('0x24')](function(){if(_0x570cbf===_0xb23b('0x76')){return db[_0xb23b('0x6c')][_0xb23b('0x27')]({'where':{'VoiceQueueId':_0x347248['id'],'UserId':_0xf301d7[_0xb23b('0x34')][_0xb23b('0x61')]}});}});});})[_0xb23b('0x24')](function(){return _0x409984;});})[_0xb23b('0x24')](function(){return _0x409984;});}})['then'](function(_0x2a8d4f){if(_0x2a8d4f){return _0x2a8d4f[_0xb23b('0x72')](_0xf301d7['query'][_0xb23b('0x61')])['then'](function(){if(_[_0xb23b('0x77')](_0xf301d7[_0xb23b('0x34')]['ids'])){for(var _0x3649f0=0x0;_0x3649f0<_0xf301d7[_0xb23b('0x34')][_0xb23b('0x61')]['length'];_0x3649f0+=0x1){socket[_0xb23b('0x78')](_0xb23b('0x79'),{'UserId':Number(_0xf301d7['query'][_0xb23b('0x61')][_0x3649f0]),'TeamId':Number(_0xf301d7[_0xb23b('0x49')]['id'])});}}else{socket[_0xb23b('0x78')](_0xb23b('0x79'),{'UserId':Number(_0xf301d7[_0xb23b('0x34')][_0xb23b('0x61')]),'TeamId':Number(_0xf301d7[_0xb23b('0x49')]['id'])});}});}})[_0xb23b('0x24')](respondWithStatusCode(_0x274dc2,null))[_0xb23b('0x47')](handleError(_0x274dc2,null));};exports[_0xb23b('0x7a')]=function(_0x3d9c08,_0x497b04,_0x15e385){var _0x35195a={};var _0x3f058e={};var _0x495ce1;var _0x4647f2;return db[_0xb23b('0x2e')][_0xb23b('0x54')]({'where':{'id':_0x3d9c08[_0xb23b('0x49')]['id']}})['then'](handleEntityNotFound(_0x497b04,null))['then'](function(_0x525ae6){if(_0x525ae6){_0x495ce1=_0x525ae6;_0x3f058e[_0xb23b('0x33')]=_[_0xb23b('0x35')](db['User'][_0xb23b('0x2f')]);_0x3f058e[_0xb23b('0x34')]=_['keys'](_0x3d9c08['query']);_0x3f058e[_0xb23b('0x36')]=_[_0xb23b('0x38')](_0x3f058e[_0xb23b('0x33')],_0x3f058e[_0xb23b('0x34')]);_0x35195a[_0xb23b('0x37')]=_[_0xb23b('0x38')](_0x3f058e[_0xb23b('0x33')],qs[_0xb23b('0x5b')](_0x3d9c08[_0xb23b('0x34')]['fields']));_0x35195a[_0xb23b('0x37')]=_0x35195a[_0xb23b('0x37')][_0xb23b('0x39')]?_0x35195a[_0xb23b('0x37')]:_0x3f058e['model'];_0x35195a[_0xb23b('0x3c')]=qs['sort'](_0x3d9c08[_0xb23b('0x34')]['sort']);_0x35195a['where']=qs[_0xb23b('0x36')](_[_0xb23b('0x3f')](_0x3d9c08[_0xb23b('0x34')],_0x3f058e[_0xb23b('0x36')]));if(_0x3d9c08['query'][_0xb23b('0x40')]){_0x35195a[_0xb23b('0x3e')]=_[_0xb23b('0x41')](_0x35195a[_0xb23b('0x3e')],{'$or':_[_0xb23b('0x2d')](_0x35195a['attributes'],function(_0xc327ca){var _0x1968dd={};_0x1968dd[_0xc327ca]={'$like':'%'+_0x3d9c08['query'][_0xb23b('0x40')]+'%'};return _0x1968dd;})});}_0x35195a=_[_0xb23b('0x41')]({},_0x35195a,_0x3d9c08[_0xb23b('0x4a')]);return _0x495ce1[_0xb23b('0x7a')](_0x35195a);}})[_0xb23b('0x24')](function(_0x5bce53){if(_0x5bce53){_0x4647f2=_0x5bce53[_0xb23b('0x39')];if(!_0x3d9c08['query'][_0xb23b('0x7b')](_0xb23b('0x3a'))){_0x35195a['limit']=qs[_0xb23b('0x3b')](_0x3d9c08[_0xb23b('0x34')]['limit']);_0x35195a[_0xb23b('0x1d')]=qs[_0xb23b('0x1d')](_0x3d9c08[_0xb23b('0x34')]['offset']);}return _0x495ce1['getAgents'](_0x35195a);}})['then'](function(_0x2b0705){if(_0x2b0705){return _0x2b0705?{'count':_0x4647f2,'rows':_0x2b0705}:null;}})[_0xb23b('0x24')](respondWithResult(_0x497b04,null))['catch'](handleError(_0x497b04,null));};
\ No newline at end of file
+var _0xa4b7=['limit','set','apply','update','then','stack','name','send','index','map','Team','rawAttributes','fieldName','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','pick','filter','where','type','VIRTUAL','merge','options','includeAll','include','findAll','rows','catch','show','find','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Teams','UserProfileSection','autoAssociation','UserProfileResource','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','destroy','sequelize','SELECT\x20UserId\x20FROM\x20user_has_teams\x20WHERE\x20TeamId\x20=\x20','Sequelize','QueryTypes','SELECT','SELECT\x20VoiceQueueId\x20FROM\x20team_has_voice_queues\x20WHERE\x20TeamId\x20=\x20','UserVoiceQueue','SELECT\x20MailQueueId\x20FROM\x20team_has_mail_queues\x20WHERE\x20TeamId\x20=\x20','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','ChatQueueId','FaxQueueId','UserFaxQueue','SELECT\x20OpenchannelQueueId\x20FROM\x20team_has_openchannel_queues\x20WHERE\x20TeamId\x20=\x20','OpenchannelQueueId','UserOpenchannelQueue','SELECT\x20WhatsappQueueId\x20FROM\x20team_has_whatsapp_queues\x20WHERE\x20TeamId\x20=\x20','WhatsappQueueId','UserWhatsappQueue','TeamVoicePrefix','UserVoicePrefix','VoicePrefixId','end','getQueues','params','isValidChannel','ValidationError','capitalize','channel','toLowerCase','length','order','sort','findOne','add','Queues','ids','Unknown\x20channel','remove','addAgents','isArray','Chat','Sms','Fax','Openchannel','Whatsapp','transaction','Voice','penalty','QueueId','TeamVoiceQueue','User','Queue','findOrCreate','Queue:save','voicePause','interface','UserVoiceQueueRt','isNil','format','SIP/%s','all','removeAgents','Mail','emit','Queue:remove','getAgents','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','ejs','fs-extra','squel','crypto','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./team.socket','register','sendStatus','status','json','offset','undefined','count'];(function(_0x42afb8,_0x3a71cd){var _0x439f98=function(_0x86906){while(--_0x86906){_0x42afb8['push'](_0x42afb8['shift']());}};_0x439f98(++_0x3a71cd);}(_0xa4b7,0x77));var _0x7a4b=function(_0x119ee6,_0x2f0686){_0x119ee6=_0x119ee6-0x0;var _0x3f42b2=_0xa4b7[_0x119ee6];return _0x3f42b2;};'use strict';var emlformat=require(_0x7a4b('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x7a4b('0x1'));var jsonpatch=require(_0x7a4b('0x2'));var rp=require(_0x7a4b('0x3'));var moment=require('moment');var BPromise=require(_0x7a4b('0x4'));var Mustache=require(_0x7a4b('0x5'));var util=require('util');var path=require(_0x7a4b('0x6'));var sox=require(_0x7a4b('0x7'));var csv=require('to-csv');var ejs=require(_0x7a4b('0x8'));var fs=require('fs');var fs_extra=require(_0x7a4b('0x9'));var _=require('lodash');var squel=require(_0x7a4b('0xa'));var crypto=require(_0x7a4b('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x7a4b('0xc'));var toCsv=require(_0x7a4b('0xd'));var querystring=require('querystring');var Papa=require(_0x7a4b('0xe'));var Redis=require(_0x7a4b('0xf'));var authService=require(_0x7a4b('0x10'));var qs=require(_0x7a4b('0x11'));var as=require(_0x7a4b('0x12'));var hardwareService=require(_0x7a4b('0x13'));var logger=require(_0x7a4b('0x14'))(_0x7a4b('0x15'));var utils=require(_0x7a4b('0x16'));var config=require(_0x7a4b('0x17'));var licenseUtil=require(_0x7a4b('0x18'));var db=require(_0x7a4b('0x19'))['db'];config['redis']=_[_0x7a4b('0x1a')](config[_0x7a4b('0x1b')],{'host':_0x7a4b('0x1c'),'port':0x18eb});var socket=require(_0x7a4b('0x1d'))(new Redis(config[_0x7a4b('0x1b')]));require(_0x7a4b('0x1e'))[_0x7a4b('0x1f')](socket);function respondWithStatusCode(_0x28ec14,_0x2f2c2b){_0x2f2c2b=_0x2f2c2b||0xcc;return function(_0x58072d){if(_0x58072d){return _0x28ec14[_0x7a4b('0x20')](_0x2f2c2b);}return _0x28ec14['status'](_0x2f2c2b)['end']();};}function respondWithResult(_0x53ac6f,_0x30a5ac){_0x30a5ac=_0x30a5ac||0xc8;return function(_0x401dab){if(_0x401dab){return _0x53ac6f[_0x7a4b('0x21')](_0x30a5ac)[_0x7a4b('0x22')](_0x401dab);}};}function respondWithFilteredResult(_0x3601e5,_0x4ad69d){return function(_0x2b2573){if(_0x2b2573){var _0x16c6c2=typeof _0x4ad69d[_0x7a4b('0x23')]===_0x7a4b('0x24')&&typeof _0x4ad69d['limit']==='undefined';var _0x279dbe=_0x2b2573[_0x7a4b('0x25')];var _0x34cfe4=_0x16c6c2?0x0:_0x4ad69d[_0x7a4b('0x23')];var _0x4f0909=_0x16c6c2?_0x2b2573['count']:_0x4ad69d[_0x7a4b('0x23')]+_0x4ad69d[_0x7a4b('0x26')];var _0x60579;if(_0x4f0909>=_0x279dbe){_0x4f0909=_0x279dbe;_0x60579=0xc8;}else{_0x60579=0xce;}_0x3601e5[_0x7a4b('0x21')](_0x60579);return _0x3601e5[_0x7a4b('0x27')]('Content-Range',_0x34cfe4+'-'+_0x4f0909+'/'+_0x279dbe)[_0x7a4b('0x22')](_0x2b2573);}return null;};}function patchUpdates(_0x2fb309){return function(_0x5d79f9){try{jsonpatch[_0x7a4b('0x28')](_0x5d79f9,_0x2fb309,!![]);}catch(_0x5a355f){return BPromise['reject'](_0x5a355f);}return _0x5d79f9['save']();};}function saveUpdates(_0x2ae4c7,_0x4385ec){return function(_0x3e9ec0){if(_0x3e9ec0){return _0x3e9ec0[_0x7a4b('0x29')](_0x2ae4c7)[_0x7a4b('0x2a')](function(_0x5aeebf){return _0x5aeebf;});}return null;};}function handleEntityNotFound(_0x4a3b04,_0x16d78a){return function(_0xeeb4b5){if(!_0xeeb4b5){_0x4a3b04[_0x7a4b('0x20')](0x194);}return _0xeeb4b5;};}function handleError(_0x28c118,_0x4822ee){_0x4822ee=_0x4822ee||0x1f4;return function(_0x26ac4c){logger['error'](_0x26ac4c[_0x7a4b('0x2b')]);if(_0x26ac4c[_0x7a4b('0x2c')]){delete _0x26ac4c['name'];}_0x28c118[_0x7a4b('0x21')](_0x4822ee)[_0x7a4b('0x2d')](_0x26ac4c);};}exports[_0x7a4b('0x2e')]=function(_0x3b00a9,_0x1c9002){var _0x374e6f={},_0x21677b={},_0x322c8a={'count':0x0,'rows':[]};var _0x5abffd=_[_0x7a4b('0x2f')](db[_0x7a4b('0x30')][_0x7a4b('0x31')],function(_0x275d28){return{'name':_0x275d28[_0x7a4b('0x32')],'type':_0x275d28['type']['key']};});_0x21677b[_0x7a4b('0x33')]=_[_0x7a4b('0x2f')](_0x5abffd,_0x7a4b('0x2c'));_0x21677b[_0x7a4b('0x34')]=_[_0x7a4b('0x35')](_0x3b00a9[_0x7a4b('0x34')]);_0x21677b[_0x7a4b('0x36')]=_[_0x7a4b('0x37')](_0x21677b[_0x7a4b('0x33')],_0x21677b['query']);_0x374e6f[_0x7a4b('0x38')]=_[_0x7a4b('0x37')](_0x21677b['model'],qs['fields'](_0x3b00a9[_0x7a4b('0x34')][_0x7a4b('0x39')]));_0x374e6f[_0x7a4b('0x38')]=_0x374e6f[_0x7a4b('0x38')]['length']?_0x374e6f[_0x7a4b('0x38')]:_0x21677b[_0x7a4b('0x33')];if(!_0x3b00a9[_0x7a4b('0x34')][_0x7a4b('0x3a')](_0x7a4b('0x3b'))){_0x374e6f['limit']=qs[_0x7a4b('0x26')](_0x3b00a9['query'][_0x7a4b('0x26')]);_0x374e6f[_0x7a4b('0x23')]=qs[_0x7a4b('0x23')](_0x3b00a9[_0x7a4b('0x34')][_0x7a4b('0x23')]);}_0x374e6f['order']=qs['sort'](_0x3b00a9[_0x7a4b('0x34')]['sort']);_0x374e6f['where']=qs[_0x7a4b('0x36')](_[_0x7a4b('0x3c')](_0x3b00a9[_0x7a4b('0x34')],_0x21677b[_0x7a4b('0x36')]),_0x5abffd);if(_0x3b00a9[_0x7a4b('0x34')][_0x7a4b('0x3d')]){_0x374e6f[_0x7a4b('0x3e')]=_['merge'](_0x374e6f[_0x7a4b('0x3e')],{'$or':_[_0x7a4b('0x2f')](_0x5abffd,function(_0x442fba){if(_0x442fba[_0x7a4b('0x3f')]!==_0x7a4b('0x40')){var _0x51f85a={};_0x51f85a[_0x442fba[_0x7a4b('0x2c')]]={'$like':'%'+_0x3b00a9['query'][_0x7a4b('0x3d')]+'%'};return _0x51f85a;}})});}_0x374e6f=_[_0x7a4b('0x41')]({},_0x374e6f,_0x3b00a9[_0x7a4b('0x42')]);var _0x3c30ad={'where':_0x374e6f[_0x7a4b('0x3e')]};return db['Team'][_0x7a4b('0x25')](_0x3c30ad)[_0x7a4b('0x2a')](function(_0x390ad9){_0x322c8a[_0x7a4b('0x25')]=_0x390ad9;if(_0x3b00a9['query'][_0x7a4b('0x43')]){_0x374e6f[_0x7a4b('0x44')]=[{'all':!![]}];}return db[_0x7a4b('0x30')][_0x7a4b('0x45')](_0x374e6f);})[_0x7a4b('0x2a')](function(_0x1338fb){_0x322c8a[_0x7a4b('0x46')]=_0x1338fb;return _0x322c8a;})['then'](respondWithFilteredResult(_0x1c9002,_0x374e6f))[_0x7a4b('0x47')](handleError(_0x1c9002,null));};exports[_0x7a4b('0x48')]=function(_0x4806de,_0x15076f){var _0x435de6={'raw':![],'where':{'id':_0x4806de['params']['id']}},_0x41df46={};_0x41df46[_0x7a4b('0x33')]=_['keys'](db['Team'][_0x7a4b('0x31')]);_0x41df46[_0x7a4b('0x34')]=_[_0x7a4b('0x35')](_0x4806de[_0x7a4b('0x34')]);_0x41df46[_0x7a4b('0x36')]=_[_0x7a4b('0x37')](_0x41df46[_0x7a4b('0x33')],_0x41df46[_0x7a4b('0x34')]);_0x435de6[_0x7a4b('0x38')]=_[_0x7a4b('0x37')](_0x41df46[_0x7a4b('0x33')],qs['fields'](_0x4806de[_0x7a4b('0x34')][_0x7a4b('0x39')]));_0x435de6[_0x7a4b('0x38')]=_0x435de6[_0x7a4b('0x38')]['length']?_0x435de6['attributes']:_0x41df46[_0x7a4b('0x33')];if(_0x4806de[_0x7a4b('0x34')][_0x7a4b('0x43')]){_0x435de6['include']=[{'all':!![]}];}_0x435de6=_[_0x7a4b('0x41')]({},_0x435de6,_0x4806de['options']);return db[_0x7a4b('0x30')][_0x7a4b('0x49')](_0x435de6)[_0x7a4b('0x2a')](handleEntityNotFound(_0x15076f,null))['then'](respondWithResult(_0x15076f,null))[_0x7a4b('0x47')](handleError(_0x15076f,null));};exports[_0x7a4b('0x4a')]=function(_0x4ea4a2,_0x43fe4f){return db[_0x7a4b('0x30')][_0x7a4b('0x4a')](_0x4ea4a2['body'],{})[_0x7a4b('0x2a')](function(_0x1b296b){var _0x5e4537=_0x4ea4a2[_0x7a4b('0x4b')][_0x7a4b('0x4c')]({'plain':!![]});if(!_0x5e4537)throw new Error(_0x7a4b('0x4d'));if(_0x5e4537[_0x7a4b('0x4e')]===_0x7a4b('0x4b')){var _0x1c957a=_0x1b296b[_0x7a4b('0x4c')]({'plain':!![]});var _0x3cc753=_0x7a4b('0x4f');return db[_0x7a4b('0x50')][_0x7a4b('0x49')]({'where':{'name':_0x3cc753,'userProfileId':_0x5e4537['userProfileId']},'raw':!![]})[_0x7a4b('0x2a')](function(_0x3ecde4){if(_0x3ecde4&&_0x3ecde4[_0x7a4b('0x51')]===0x0){return db[_0x7a4b('0x52')][_0x7a4b('0x4a')]({'name':_0x1c957a[_0x7a4b('0x2c')],'resourceId':_0x1c957a['id'],'type':_0x3ecde4['name'],'sectionId':_0x3ecde4['id']},{})['then'](function(){return _0x1b296b;});}else{return _0x1b296b;}})[_0x7a4b('0x47')](function(_0x544631){logger[_0x7a4b('0x53')](_0x7a4b('0x54'),_0x544631);throw _0x544631;});}return _0x1b296b;})[_0x7a4b('0x2a')](respondWithResult(_0x43fe4f,0xc9))['catch'](handleError(_0x43fe4f,null));};exports['update']=function(_0x4eca4b,_0x1006bd){if(_0x4eca4b[_0x7a4b('0x55')]['id']){delete _0x4eca4b[_0x7a4b('0x55')]['id'];}return db['Team'][_0x7a4b('0x49')]({'where':{'id':_0x4eca4b['params']['id']}})['then'](handleEntityNotFound(_0x1006bd,null))['then'](saveUpdates(_0x4eca4b[_0x7a4b('0x55')],null))[_0x7a4b('0x2a')](respondWithResult(_0x1006bd,null))['catch'](handleError(_0x1006bd,null));};exports[_0x7a4b('0x56')]=function(_0xa60cf6,_0x21a21a){var _0x13cbe0=_0xa60cf6['params']['id'];var _0x2379f3=[];return db[_0x7a4b('0x57')]['transaction'](function(_0x38ca42){var _0x1da4c7=_0x7a4b('0x58')+_0x13cbe0;return db[_0x7a4b('0x57')][_0x7a4b('0x34')](_0x1da4c7,{'type':db[_0x7a4b('0x59')][_0x7a4b('0x5a')][_0x7a4b('0x5b')],'raw':!![],'transaction':_0x38ca42})[_0x7a4b('0x2a')](function(_0x42f336){_0x2379f3=_[_0x7a4b('0x2f')](_0x42f336,function(_0x1538d8){return Number(_0x1538d8['UserId']);});})[_0x7a4b('0x2a')](function(){var _0xe5fd4f=_0x7a4b('0x5c')+_0x13cbe0;return db['sequelize'][_0x7a4b('0x34')](_0xe5fd4f,{'type':db[_0x7a4b('0x59')][_0x7a4b('0x5a')]['SELECT'],'raw':!![],'transaction':_0x38ca42});})['then'](function(_0x3d610f){var _0x4a5c02=_['map'](_0x3d610f,function(_0x51e42e){return Number(_0x51e42e['VoiceQueueId']);});return db[_0x7a4b('0x5d')][_0x7a4b('0x56')]({'where':{'UserId':{'$in':_0x2379f3},'VoiceQueueId':{'$in':_0x4a5c02}},'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(){var _0x329634=_0x7a4b('0x5e')+_0x13cbe0;return db[_0x7a4b('0x57')]['query'](_0x329634,{'type':db['Sequelize'][_0x7a4b('0x5a')][_0x7a4b('0x5b')],'raw':!![],'transaction':_0x38ca42});})['then'](function(_0x234cb5){var _0x409c90=_[_0x7a4b('0x2f')](_0x234cb5,function(_0x456750){return Number(_0x456750['MailQueueId']);});return db[_0x7a4b('0x5f')]['destroy']({'where':{'UserId':{'$in':_0x2379f3},'MailQueueId':{'$in':_0x409c90}},'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(){var _0x5eb621=_0x7a4b('0x60')+_0x13cbe0;return db[_0x7a4b('0x57')][_0x7a4b('0x34')](_0x5eb621,{'type':db[_0x7a4b('0x59')][_0x7a4b('0x5a')][_0x7a4b('0x5b')],'raw':!![],'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(_0x562be7){var _0x9165ff=_[_0x7a4b('0x2f')](_0x562be7,function(_0x192c58){return Number(_0x192c58[_0x7a4b('0x61')]);});return db[_0x7a4b('0x62')][_0x7a4b('0x56')]({'where':{'UserId':{'$in':_0x2379f3},'SmsQueueId':{'$in':_0x9165ff}},'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(){var _0x39ce13=_0x7a4b('0x63')+_0x13cbe0;return db[_0x7a4b('0x57')]['query'](_0x39ce13,{'type':db['Sequelize'][_0x7a4b('0x5a')][_0x7a4b('0x5b')],'raw':!![],'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(_0x21dd54){var _0x108deb=_['map'](_0x21dd54,function(_0x2178b3){return Number(_0x2178b3[_0x7a4b('0x64')]);});return db['UserChatQueue'][_0x7a4b('0x56')]({'where':{'UserId':{'$in':_0x2379f3},'ChatQueueId':{'$in':_0x108deb}},'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(){var _0x47ce6b='SELECT\x20FaxQueueId\x20FROM\x20team_has_fax_queues\x20WHERE\x20TeamId\x20=\x20'+_0x13cbe0;return db[_0x7a4b('0x57')][_0x7a4b('0x34')](_0x47ce6b,{'type':db[_0x7a4b('0x59')][_0x7a4b('0x5a')][_0x7a4b('0x5b')],'raw':!![],'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(_0x78f7e9){var _0x5259b8=_[_0x7a4b('0x2f')](_0x78f7e9,function(_0x55fde9){return Number(_0x55fde9[_0x7a4b('0x65')]);});return db[_0x7a4b('0x66')][_0x7a4b('0x56')]({'where':{'UserId':{'$in':_0x2379f3},'FaxQueueId':{'$in':_0x5259b8}},'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(){var _0x47901d=_0x7a4b('0x67')+_0x13cbe0;return db['sequelize'][_0x7a4b('0x34')](_0x47901d,{'type':db[_0x7a4b('0x59')][_0x7a4b('0x5a')]['SELECT'],'raw':!![],'transaction':_0x38ca42});})['then'](function(_0x207832){var _0x2da6ef=_['map'](_0x207832,function(_0x3c5e68){return Number(_0x3c5e68[_0x7a4b('0x68')]);});return db[_0x7a4b('0x69')][_0x7a4b('0x56')]({'where':{'UserId':{'$in':_0x2379f3},'OpenchannelQueueId':{'$in':_0x2da6ef}},'transaction':_0x38ca42});})['then'](function(){var _0x7091d0=_0x7a4b('0x6a')+_0x13cbe0;return db['sequelize']['query'](_0x7091d0,{'type':db[_0x7a4b('0x59')][_0x7a4b('0x5a')][_0x7a4b('0x5b')],'raw':!![],'transaction':_0x38ca42});})['then'](function(_0x1149f6){var _0x54639b=_[_0x7a4b('0x2f')](_0x1149f6,function(_0x4d7ae7){return Number(_0x4d7ae7[_0x7a4b('0x6b')]);});return db[_0x7a4b('0x6c')]['destroy']({'where':{'UserId':{'$in':_0x2379f3},'WhatsappQueueId':{'$in':_0x54639b}},'transaction':_0x38ca42});})['then'](function(){return db[_0x7a4b('0x6d')][_0x7a4b('0x49')]({'where':{'TeamId':_0x13cbe0}});})[_0x7a4b('0x2a')](function(_0x19a741){if(_0x19a741===null){return;}return db[_0x7a4b('0x6e')]['destroy']({'where':{'UserId':{'$in':_0x2379f3},'VoicePrefixId':_0x19a741[_0x7a4b('0x6f')]},'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(){return db['Team'][_0x7a4b('0x56')]({'where':{'id':_0x13cbe0},'cascade':!![],'transaction':_0x38ca42});})[_0x7a4b('0x2a')](function(_0x1a9160){if(_0x1a9160===0x0){_0x21a21a[_0x7a4b('0x20')](0x194);}else{return db[_0x7a4b('0x52')][_0x7a4b('0x56')]({'where':{'type':'Teams','resourceId':_0x13cbe0},'cascade':!![],'transaction':_0x38ca42})['then'](function(){_0x21a21a[_0x7a4b('0x21')](0xcc)[_0x7a4b('0x70')]();});}})['catch'](function(_0x228f4a){_0x21a21a[_0x7a4b('0x21')](0x1f4)['send'](_0x228f4a);});});};exports[_0x7a4b('0x71')]=function(_0x1805c7,_0x4554ba,_0x4950c9){return db['Team']['findOne']({'where':{'id':_0x1805c7[_0x7a4b('0x72')]['id']}})['then'](handleEntityNotFound(_0x4554ba,null))[_0x7a4b('0x2a')](function(_0x51b2b8){if(!_0x1805c7[_0x7a4b('0x34')]['channel']||!utils[_0x7a4b('0x73')](_0x1805c7[_0x7a4b('0x34')]['channel'])){throw new db[(_0x7a4b('0x59'))][(_0x7a4b('0x74'))]('Unknown\x20channel');}var _0x564b9b={};var _0x4c44ff={};_0x4c44ff[_0x7a4b('0x33')]=_[_0x7a4b('0x35')](db[_[_0x7a4b('0x75')](_0x1805c7['query'][_0x7a4b('0x76')][_0x7a4b('0x77')]())+'Queue'][_0x7a4b('0x31')]);_0x4c44ff[_0x7a4b('0x34')]=_[_0x7a4b('0x35')](_0x1805c7['query']);_0x4c44ff[_0x7a4b('0x36')]=_[_0x7a4b('0x37')](_0x4c44ff[_0x7a4b('0x33')],_0x4c44ff['query']);_0x564b9b['attributes']=_['intersection'](_0x4c44ff[_0x7a4b('0x33')],qs[_0x7a4b('0x39')](_0x1805c7[_0x7a4b('0x34')][_0x7a4b('0x39')]));_0x564b9b['attributes']=_0x564b9b['attributes'][_0x7a4b('0x78')]?_0x564b9b['attributes']:_0x4c44ff[_0x7a4b('0x33')];_0x564b9b['limit']=qs[_0x7a4b('0x26')](_0x1805c7[_0x7a4b('0x34')]['limit']);_0x564b9b['offset']=qs[_0x7a4b('0x23')](_0x1805c7['query'][_0x7a4b('0x23')]);_0x564b9b[_0x7a4b('0x79')]=qs[_0x7a4b('0x7a')](_0x1805c7[_0x7a4b('0x34')]['sort']);_0x564b9b[_0x7a4b('0x3e')]=qs[_0x7a4b('0x36')](_[_0x7a4b('0x3c')](_0x1805c7['query'],_0x4c44ff[_0x7a4b('0x36')]));_0x564b9b=_[_0x7a4b('0x41')]({},_0x564b9b,_0x1805c7[_0x7a4b('0x42')]);return _0x51b2b8[_0x7a4b('0x4c')+_['capitalize'](_0x1805c7['query']['channel']['toLowerCase']())+'Queues'](_0x564b9b);})['then'](respondWithResult(_0x4554ba,null))[_0x7a4b('0x47')](handleError(_0x4554ba,null));};exports['addQueues']=function(_0x366e0f,_0x166e75,_0x2526b1){return db['Team'][_0x7a4b('0x7b')]({'where':{'id':_0x366e0f[_0x7a4b('0x72')]['id']}})[_0x7a4b('0x2a')](function(_0x2000ea){if(_0x2000ea){if(!_0x366e0f[_0x7a4b('0x55')]['channel']||!utils[_0x7a4b('0x73')](_0x366e0f[_0x7a4b('0x55')][_0x7a4b('0x76')])){throw new db[(_0x7a4b('0x59'))][(_0x7a4b('0x74'))]('Unknown\x20channel');}return _0x2000ea[_0x7a4b('0x7c')+_[_0x7a4b('0x75')](_0x366e0f[_0x7a4b('0x55')][_0x7a4b('0x76')][_0x7a4b('0x77')]())+_0x7a4b('0x7d')](_0x366e0f[_0x7a4b('0x55')][_0x7a4b('0x7e')]);}return null;})['then'](handleEntityNotFound(_0x166e75,null))[_0x7a4b('0x2a')](respondWithStatusCode(_0x166e75,null))['catch'](handleError(_0x166e75,null));};exports['removeQueues']=function(_0x10e702,_0x128b05,_0x56e657){return db[_0x7a4b('0x30')][_0x7a4b('0x7b')]({'where':{'id':_0x10e702['params']['id']}})[_0x7a4b('0x2a')](function(_0x565f49){if(_0x565f49){if(!_0x10e702['query'][_0x7a4b('0x76')]||!utils[_0x7a4b('0x73')](_0x10e702[_0x7a4b('0x34')][_0x7a4b('0x76')])){throw new db[(_0x7a4b('0x59'))][(_0x7a4b('0x74'))](_0x7a4b('0x7f'));}return _0x565f49[_0x7a4b('0x80')+_[_0x7a4b('0x75')](_0x10e702[_0x7a4b('0x34')][_0x7a4b('0x76')][_0x7a4b('0x77')]())+'Queues'](_0x10e702['query'][_0x7a4b('0x7e')]);}return null;})[_0x7a4b('0x2a')](handleEntityNotFound(_0x128b05,null))[_0x7a4b('0x2a')](respondWithStatusCode(_0x128b05,null))[_0x7a4b('0x47')](handleError(_0x128b05,null));};exports[_0x7a4b('0x81')]=function(_0x53944e,_0x459377){var _0x2355f9=_[_0x7a4b('0x82')](_0x53944e['body']['ids'])?_0x53944e[_0x7a4b('0x55')]['ids']:[_0x53944e[_0x7a4b('0x55')][_0x7a4b('0x7e')]];var _0x504905=_0x53944e[_0x7a4b('0x72')]['id'];return db[_0x7a4b('0x30')]['find']({'where':{'id':_0x504905}})[_0x7a4b('0x2a')](handleEntityNotFound(_0x459377,null))[_0x7a4b('0x2a')](function(_0x548f32){if(_0x548f32){var _0x25045d=['Voice',_0x7a4b('0x83'),'Mail',_0x7a4b('0x84'),_0x7a4b('0x85'),_0x7a4b('0x86'),_0x7a4b('0x87')];return db[_0x7a4b('0x57')][_0x7a4b('0x88')](function(_0x3f4307){var _0x12ad0c=_['map'](_0x25045d,function(_0x383e5e){var _0xaf126d={'attributes':['id',_0x7a4b('0x2c')]};if(_0x383e5e===_0x7a4b('0x89')){_0xaf126d['through']={'attributes':[_0x7a4b('0x8a')]};}return _0x548f32[_0x7a4b('0x4c')+_0x383e5e+'Queues'](_0xaf126d)['then'](function(_0x485e45){var _0x4dcecb=_[_0x7a4b('0x2f')](_0x485e45,function(_0x4ac38e){var _0x49f06b=_[_0x7a4b('0x2f')](_0x2355f9,function(_0x81236f){var _0x29114e={'where':{'UserId':_0x81236f,[_0x383e5e+_0x7a4b('0x8b')]:_0x4ac38e['id']},'transaction':_0x3f4307};if(_0x383e5e===_0x7a4b('0x89')){_0x29114e[_0x7a4b('0x1a')]={'penalty':_0x4ac38e[_0x7a4b('0x8c')]['penalty']};}return db[_0x7a4b('0x8d')+_0x383e5e+_0x7a4b('0x8e')][_0x7a4b('0x8f')](_0x29114e)[_0x7a4b('0x2a')](function(){socket['emit'](_0x7a4b('0x4b')+_0x383e5e+_0x7a4b('0x90'),{'UserId':_0x81236f,[_0x383e5e+_0x7a4b('0x8b')]:_0x4ac38e['id']});if(_0x383e5e!==_0x7a4b('0x89')){return;}return db[_0x7a4b('0x8d')][_0x7a4b('0x45')]({'where':{'id':_0x2355f9,'online':0x1},'attributes':['id',_0x7a4b('0x2c'),'online',_0x7a4b('0x91'),_0x7a4b('0x92')],'raw':!![]})[_0x7a4b('0x2a')](function(_0x329654){var _0x7efc92=_[_0x7a4b('0x2f')](_0x329654,function(_0x4b1c26){return db[_0x7a4b('0x93')]['upsert']({'membername':_0x4b1c26[_0x7a4b('0x2c')],'UserId':_0x4b1c26['id'],'queue_name':_0x4ac38e[_0x7a4b('0x2c')],'VoiceQueueId':_0x4ac38e['id'],'interface':_[_0x7a4b('0x94')](_0x4b1c26[_0x7a4b('0x92')])?util[_0x7a4b('0x95')](_0x7a4b('0x96'),_0x4b1c26[_0x7a4b('0x2c')]):_0x4b1c26['interface'],'paused':_0x4b1c26['voicePause']||![],'penalty':_0x4ac38e[_0x7a4b('0x8c')]['penalty']},{'transaction':_0x3f4307});});return Promise[_0x7a4b('0x97')](_0x7efc92);});});});return Promise['all'](_0x49f06b);});return Promise[_0x7a4b('0x97')](_0x4dcecb);})[_0x7a4b('0x2a')](function(){return db[_0x7a4b('0x6d')][_0x7a4b('0x7b')]({'where':{'teamId':_0x504905}})[_0x7a4b('0x2a')](function(_0x2023f9){if(_0x2023f9){var _0x20ada4=_[_0x7a4b('0x2f')](_0x2355f9,function(_0x57847d){db[_0x7a4b('0x6e')]['upsert']({'UserId':_0x57847d,'VoicePrefixId':_0x2023f9[_0x7a4b('0x6f')]});});return Promise[_0x7a4b('0x97')](_0x20ada4);}});});});return Promise[_0x7a4b('0x97')](_0x12ad0c)[_0x7a4b('0x2a')](function(){return _0x548f32[_0x7a4b('0x81')](_0x2355f9,{'transaction':_0x3f4307})['spread'](function(_0x5c23a7){return _0x5c23a7;});});});}})[_0x7a4b('0x2a')](respondWithResult(_0x459377,null))[_0x7a4b('0x47')](handleError(_0x459377,null));};exports[_0x7a4b('0x98')]=function(_0x447e91,_0x44b20c){var _0xc019f6=_[_0x7a4b('0x82')](_0x447e91['query'][_0x7a4b('0x7e')])?_0x447e91[_0x7a4b('0x34')][_0x7a4b('0x7e')]:[_0x447e91[_0x7a4b('0x34')][_0x7a4b('0x7e')]];var _0x1b4f07=_0x447e91['params']['id'];return db['Team'][_0x7a4b('0x49')]({'where':{'id':_0x1b4f07}})['then'](handleEntityNotFound(_0x44b20c,null))[_0x7a4b('0x2a')](function(_0x35d3f9){if(_0x35d3f9){var _0x41d061=[_0x7a4b('0x89'),'Chat',_0x7a4b('0x99'),_0x7a4b('0x84'),_0x7a4b('0x85'),'Openchannel',_0x7a4b('0x87')];return db['sequelize'][_0x7a4b('0x88')](function(_0x23e76f){var _0x57120c=_[_0x7a4b('0x2f')](_0x41d061,function(_0x200831){var _0x7699a3={'attributes':['id',_0x7a4b('0x2c')]};return _0x35d3f9[_0x7a4b('0x4c')+_0x200831+_0x7a4b('0x7d')](_0x7699a3)['then'](function(_0x3bf703){var _0x1ab8a7=_[_0x7a4b('0x2f')](_0x3bf703,function(_0xc7324b){return _0xc7324b[_0x7a4b('0x98')](_0xc019f6,{'transaction':_0x23e76f})[_0x7a4b('0x2a')](function(){var _0x51a786=_[_0x7a4b('0x2f')](_0xc019f6,function(_0x42af14){socket[_0x7a4b('0x9a')](_0x7a4b('0x4b')+_0x200831+_0x7a4b('0x9b'),{'UserId':Number(_0x42af14),[_0x200831+_0x7a4b('0x8b')]:_0xc7324b['id']});if(_0x200831!==_0x7a4b('0x89')){return;}return db[_0x7a4b('0x93')][_0x7a4b('0x56')]({'where':{'VoiceQueueId':_0xc7324b['id'],'UserId':_0x42af14},'transaction':_0x23e76f});});return Promise[_0x7a4b('0x97')](_0x51a786);});});return Promise[_0x7a4b('0x97')](_0x1ab8a7);});});return Promise[_0x7a4b('0x97')](_0x57120c)[_0x7a4b('0x2a')](function(){return _0x35d3f9[_0x7a4b('0x98')](_0xc019f6,{'transaction':_0x23e76f});})[_0x7a4b('0x2a')](function(){return db['TeamVoicePrefix'][_0x7a4b('0x7b')]({'where':{'teamId':_0x1b4f07}})['then'](function(_0x53e66d){if(_0x53e66d){var _0x444826=_[_0x7a4b('0x2f')](_0xc019f6,function(_0x35e32c){db[_0x7a4b('0x6e')][_0x7a4b('0x56')]({'where':{'UserId':_0x35e32c,'VoicePrefixId':_0x53e66d[_0x7a4b('0x6f')]}});});return Promise[_0x7a4b('0x97')](_0x444826);}});});});}})[_0x7a4b('0x2a')](respondWithStatusCode(_0x44b20c,null))[_0x7a4b('0x47')](handleError(_0x44b20c,null));};exports[_0x7a4b('0x9c')]=function(_0x7237e8,_0x368248,_0x39ea1c){var _0x31a8a9={};var _0x1e6a25={};var _0x123890;var _0x4f25aa;return db[_0x7a4b('0x30')][_0x7a4b('0x7b')]({'where':{'id':_0x7237e8[_0x7a4b('0x72')]['id']}})[_0x7a4b('0x2a')](handleEntityNotFound(_0x368248,null))['then'](function(_0x2acf65){if(_0x2acf65){_0x123890=_0x2acf65;_0x1e6a25['model']=_[_0x7a4b('0x35')](db[_0x7a4b('0x8d')]['rawAttributes']);_0x1e6a25[_0x7a4b('0x34')]=_['keys'](_0x7237e8[_0x7a4b('0x34')]);_0x1e6a25[_0x7a4b('0x36')]=_['intersection'](_0x1e6a25[_0x7a4b('0x33')],_0x1e6a25[_0x7a4b('0x34')]);_0x31a8a9[_0x7a4b('0x38')]=_[_0x7a4b('0x37')](_0x1e6a25['model'],qs['fields'](_0x7237e8[_0x7a4b('0x34')]['fields']));_0x31a8a9['attributes']=_0x31a8a9[_0x7a4b('0x38')][_0x7a4b('0x78')]?_0x31a8a9[_0x7a4b('0x38')]:_0x1e6a25[_0x7a4b('0x33')];_0x31a8a9[_0x7a4b('0x79')]=qs[_0x7a4b('0x7a')](_0x7237e8[_0x7a4b('0x34')][_0x7a4b('0x7a')]);_0x31a8a9[_0x7a4b('0x3e')]=qs[_0x7a4b('0x36')](_[_0x7a4b('0x3c')](_0x7237e8[_0x7a4b('0x34')],_0x1e6a25[_0x7a4b('0x36')]));if(_0x7237e8['query'][_0x7a4b('0x3d')]){_0x31a8a9['where']=_[_0x7a4b('0x41')](_0x31a8a9[_0x7a4b('0x3e')],{'$or':_['map'](_0x31a8a9[_0x7a4b('0x38')],function(_0x1ee402){var _0xe02628={};_0xe02628[_0x1ee402]={'$like':'%'+_0x7237e8[_0x7a4b('0x34')]['filter']+'%'};return _0xe02628;})});}_0x31a8a9=_[_0x7a4b('0x41')]({},_0x31a8a9,_0x7237e8[_0x7a4b('0x42')]);return _0x123890[_0x7a4b('0x9c')](_0x31a8a9);}})[_0x7a4b('0x2a')](function(_0x3d796c){if(_0x3d796c){_0x4f25aa=_0x3d796c['length'];if(!_0x7237e8[_0x7a4b('0x34')]['hasOwnProperty'](_0x7a4b('0x3b'))){_0x31a8a9['limit']=qs[_0x7a4b('0x26')](_0x7237e8[_0x7a4b('0x34')]['limit']);_0x31a8a9['offset']=qs['offset'](_0x7237e8[_0x7a4b('0x34')][_0x7a4b('0x23')]);}return _0x123890['getAgents'](_0x31a8a9);}})[_0x7a4b('0x2a')](function(_0x87ce3c){if(_0x87ce3c){return _0x87ce3c?{'count':_0x4f25aa,'rows':_0x87ce3c}:null;}})[_0x7a4b('0x2a')](respondWithResult(_0x368248,null))[_0x7a4b('0x47')](handleError(_0x368248,null));};
\ No newline at end of file