Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / chatQueue / chatQueue.controller.js
index a556ebc..63ee294 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2e5a=['fields','includeAll','merge','options','create','user','UserProfileSection','find','userProfileId','UserProfileResource','update','body','getMembers','findOne','UserChatQueue','length','hasOwnProperty','nolimit','order','sort','ChatQueueId','filter','User','findAndCountAll','agent','chatPause','updatedAt','createdAt','%s/%s','Team','pick','getTeams','addTeams','voicePause','interface','Agents','sequelize','transaction','each','findOrCreate','forEach','emit','userChatQueue:save','removeTeams','ids','select','from','team_has_chat_queues','join','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','QueryTypes','TeamId','all','compact','value','isEmpty','userChatQueue:remove','addAgents','omit','spread','removeAgents','isArray','getAgents','util','ioredis','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./chatQueue.socket','register','sendStatus','status','json','offset','undefined','limit','set','Content-Range','then','get','ChatQueues','destroy','end','error','stack','name','index','map','rawAttributes','fieldName','type','key','getOptions','where','include','query','findAll','catch','show','params','keys','ChatQueue','filters','intersection','model','attributes'];(function(_0x523e3f,_0xbdbe8b){var _0x71967f=function(_0x2c2c2b){while(--_0x2c2c2b){_0x523e3f['push'](_0x523e3f['shift']());}};_0x71967f(++_0xbdbe8b);}(_0x2e5a,0x199));var _0xa2e5=function(_0x4945b8,_0x28d659){_0x4945b8=_0x4945b8-0x0;var _0x38a136=_0x2e5a[_0x4945b8];return _0x38a136;};'use strict';var BPromise=require('bluebird');var util=require(_0xa2e5('0x0'));var _=require('lodash');var squel=require('squel');var Redis=require(_0xa2e5('0x1'));var qs=require('../../components/parsers/qs');var logger=require(_0xa2e5('0x2'))(_0xa2e5('0x3'));var config=require(_0xa2e5('0x4'));var db=require(_0xa2e5('0x5'))['db'];config[_0xa2e5('0x6')]=_[_0xa2e5('0x7')](config[_0xa2e5('0x6')],{'host':'localhost','port':0x18eb});var socket=require(_0xa2e5('0x8'))(new Redis(config['redis']));require(_0xa2e5('0x9'))[_0xa2e5('0xa')](socket);function respondWithStatusCode(_0x23364a,_0x2c1b4f){_0x2c1b4f=_0x2c1b4f||0xcc;return function(_0x2d7fc3){if(_0x2d7fc3){return _0x23364a[_0xa2e5('0xb')](_0x2c1b4f);}return _0x23364a[_0xa2e5('0xc')](_0x2c1b4f)['end']();};}function respondWithResult(_0xfa5952,_0x4b237d){_0x4b237d=_0x4b237d||0xc8;return function(_0x25a9e3){if(_0x25a9e3){return _0xfa5952[_0xa2e5('0xc')](_0x4b237d)[_0xa2e5('0xd')](_0x25a9e3);}};}function respondWithFilteredResult(_0x4a95ff,_0x405a75){return function(_0x2a3362){if(_0x2a3362){var _0x586280=typeof _0x405a75[_0xa2e5('0xe')]===_0xa2e5('0xf')&&typeof _0x405a75[_0xa2e5('0x10')]==='undefined';var _0x39d049=_0x2a3362['count'];var _0x4235a9=_0x586280?0x0:_0x405a75[_0xa2e5('0xe')];var _0x4bdab6=_0x586280?_0x2a3362['count']:_0x405a75[_0xa2e5('0xe')]+_0x405a75[_0xa2e5('0x10')];var _0x2c4e67;if(_0x4bdab6>=_0x39d049){_0x4bdab6=_0x39d049;_0x2c4e67=0xc8;}else{_0x2c4e67=0xce;}_0x4a95ff[_0xa2e5('0xc')](_0x2c4e67);return _0x4a95ff[_0xa2e5('0x11')](_0xa2e5('0x12'),_0x4235a9+'-'+_0x4bdab6+'/'+_0x39d049)[_0xa2e5('0xd')](_0x2a3362);}return null;};}function saveUpdates(_0x57f785){return function(_0x282ff3){if(_0x282ff3){return _0x282ff3['update'](_0x57f785)[_0xa2e5('0x13')](function(_0x596262){return _0x596262;});}return null;};}function removeEntity(_0x3cf06a){return function(_0x2741f9){if(_0x2741f9){return _0x2741f9['destroy']()['then'](function(){var _0x2e774c=_0x2741f9[_0xa2e5('0x14')]({'plain':!![]});var _0x1d506a=_0xa2e5('0x15');return db['UserProfileResource'][_0xa2e5('0x16')]({'where':{'type':_0x1d506a,'resourceId':_0x2e774c['id']}})[_0xa2e5('0x13')](function(){return _0x2741f9;});})[_0xa2e5('0x13')](function(){_0x3cf06a[_0xa2e5('0xc')](0xcc)[_0xa2e5('0x17')]();});}};}function handleEntityNotFound(_0x227428){return function(_0x398e13){if(!_0x398e13){_0x227428['sendStatus'](0x194);}return _0x398e13;};}function handleError(_0x547b88,_0x332999){_0x332999=_0x332999||0x1f4;return function(_0x21800f){logger[_0xa2e5('0x18')](_0x21800f[_0xa2e5('0x19')]);if(_0x21800f[_0xa2e5('0x1a')]){delete _0x21800f[_0xa2e5('0x1a')];}_0x547b88[_0xa2e5('0xc')](_0x332999)['send'](_0x21800f);};}exports[_0xa2e5('0x1b')]=function(_0x379f1b,_0x412ac4){var _0x514be3={};var _0xc0d3da={'count':0x0,'rows':[]};var _0x37a889=_[_0xa2e5('0x1c')](db['ChatQueue'][_0xa2e5('0x1d')],function(_0x5cb4de){return{'name':_0x5cb4de[_0xa2e5('0x1e')],'type':_0x5cb4de[_0xa2e5('0x1f')][_0xa2e5('0x20')]};});_0x514be3=qs[_0xa2e5('0x21')](_0x37a889,_0x379f1b);var _0x77200e={'where':_0x514be3[_0xa2e5('0x22')]};return db['ChatQueue']['count'](_0x77200e)[_0xa2e5('0x13')](function(_0x5447d9){_0xc0d3da['count']=_0x5447d9;_0x514be3[_0xa2e5('0x23')]=qs['include'](_0x379f1b[_0xa2e5('0x24')]);return db['ChatQueue'][_0xa2e5('0x25')](_0x514be3);})[_0xa2e5('0x13')](function(_0x4145bd){_0xc0d3da['rows']=_0x4145bd;return _0xc0d3da;})['then'](respondWithFilteredResult(_0x412ac4,_0x514be3))[_0xa2e5('0x26')](handleError(_0x412ac4,null));};exports[_0xa2e5('0x27')]=function(_0xf29f7d,_0x21c474){var _0x2c18e7={'raw':!![],'where':{'id':_0xf29f7d[_0xa2e5('0x28')]['id']}},_0x533ab2={};_0x533ab2['model']=_[_0xa2e5('0x29')](db[_0xa2e5('0x2a')][_0xa2e5('0x1d')]);_0x533ab2[_0xa2e5('0x24')]=_[_0xa2e5('0x29')](_0xf29f7d['query']);_0x533ab2[_0xa2e5('0x2b')]=_[_0xa2e5('0x2c')](_0x533ab2[_0xa2e5('0x2d')],_0x533ab2[_0xa2e5('0x24')]);_0x2c18e7[_0xa2e5('0x2e')]=_[_0xa2e5('0x2c')](_0x533ab2[_0xa2e5('0x2d')],qs[_0xa2e5('0x2f')](_0xf29f7d[_0xa2e5('0x24')][_0xa2e5('0x2f')]));_0x2c18e7['attributes']=_0x2c18e7[_0xa2e5('0x2e')]['length']?_0x2c18e7['attributes']:_0x533ab2[_0xa2e5('0x2d')];if(_0xf29f7d[_0xa2e5('0x24')][_0xa2e5('0x30')]){_0x2c18e7[_0xa2e5('0x23')]=[{'all':!![]}];}_0x2c18e7=_[_0xa2e5('0x31')]({},_0x2c18e7,_0xf29f7d[_0xa2e5('0x32')]);return db['ChatQueue']['find'](_0x2c18e7)[_0xa2e5('0x13')](handleEntityNotFound(_0x21c474,null))['then'](respondWithResult(_0x21c474,null))[_0xa2e5('0x26')](handleError(_0x21c474,null));};exports[_0xa2e5('0x33')]=function(_0xd6bb94,_0x4da0db){return db[_0xa2e5('0x2a')][_0xa2e5('0x33')](_0xd6bb94['body'],{})[_0xa2e5('0x13')](function(_0x2d7882){var _0x527134=_0xd6bb94[_0xa2e5('0x34')]['get']({'plain':!![]});if(!_0x527134)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x527134['role']===_0xa2e5('0x34')){var _0x22e450=_0x2d7882[_0xa2e5('0x14')]({'plain':!![]});var _0x3c5e22=_0xa2e5('0x15');return db[_0xa2e5('0x35')][_0xa2e5('0x36')]({'where':{'name':_0x3c5e22,'userProfileId':_0x527134[_0xa2e5('0x37')]},'raw':!![]})['then'](function(_0xcaa90b){if(_0xcaa90b&&_0xcaa90b['autoAssociation']===0x0){return db[_0xa2e5('0x38')][_0xa2e5('0x33')]({'name':_0x22e450[_0xa2e5('0x1a')],'resourceId':_0x22e450['id'],'type':_0xcaa90b['name'],'sectionId':_0xcaa90b['id']},{})[_0xa2e5('0x13')](function(){return _0x2d7882;});}else{return _0x2d7882;}})[_0xa2e5('0x26')](function(_0x346324){logger[_0xa2e5('0x18')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x346324);throw _0x346324;});}return _0x2d7882;})[_0xa2e5('0x13')](respondWithResult(_0x4da0db,0xc9))[_0xa2e5('0x26')](handleError(_0x4da0db,null));};exports[_0xa2e5('0x39')]=function(_0x3e858d,_0x5a20ad){if(_0x3e858d[_0xa2e5('0x3a')]['id']){delete _0x3e858d[_0xa2e5('0x3a')]['id'];}return db[_0xa2e5('0x2a')][_0xa2e5('0x36')]({'where':{'id':_0x3e858d[_0xa2e5('0x28')]['id']}})[_0xa2e5('0x13')](handleEntityNotFound(_0x5a20ad,null))['then'](saveUpdates(_0x3e858d['body'],null))[_0xa2e5('0x13')](respondWithResult(_0x5a20ad,null))[_0xa2e5('0x26')](handleError(_0x5a20ad,null));};exports[_0xa2e5('0x16')]=function(_0x3d49ee,_0x4c11c2){return db[_0xa2e5('0x2a')][_0xa2e5('0x36')]({'where':{'id':_0x3d49ee['params']['id']}})[_0xa2e5('0x13')](handleEntityNotFound(_0x4c11c2,null))[_0xa2e5('0x13')](removeEntity(_0x4c11c2,null))['catch'](handleError(_0x4c11c2,null));};exports['describe']=function(_0x164276,_0x595521){return db[_0xa2e5('0x2a')]['describe']()[_0xa2e5('0x13')](respondWithResult(_0x595521,null))[_0xa2e5('0x26')](handleError(_0x595521,null));};exports[_0xa2e5('0x3b')]=function(_0x229904,_0xd682fb){var _0x8e46bb={'raw':!![],'where':{}},_0x58a6ea={},_0x4c1b86;return db[_0xa2e5('0x2a')][_0xa2e5('0x3c')]({'where':{'id':_0x229904[_0xa2e5('0x28')]['id']}})['then'](handleEntityNotFound(_0xd682fb,null))[_0xa2e5('0x13')](function(_0x12bf33){if(_0x12bf33){_0x4c1b86=_0x12bf33[_0xa2e5('0x14')]({'plain':!![]});_0x58a6ea['model']=_[_0xa2e5('0x29')](db[_0xa2e5('0x3d')][_0xa2e5('0x1d')]);_0x58a6ea[_0xa2e5('0x24')]=_[_0xa2e5('0x29')](_0x229904[_0xa2e5('0x24')]);_0x58a6ea[_0xa2e5('0x2b')]=_[_0xa2e5('0x2c')](_0x58a6ea[_0xa2e5('0x2d')],_0x58a6ea[_0xa2e5('0x24')]);_0x8e46bb['attributes']=_[_0xa2e5('0x2c')](_0x58a6ea[_0xa2e5('0x2d')],qs[_0xa2e5('0x2f')](_0x229904[_0xa2e5('0x24')][_0xa2e5('0x2f')]));_0x8e46bb[_0xa2e5('0x2e')]=_0x8e46bb['attributes'][_0xa2e5('0x3e')]?_0x8e46bb[_0xa2e5('0x2e')]:_0x58a6ea[_0xa2e5('0x2d')];if(!_0x229904[_0xa2e5('0x24')][_0xa2e5('0x3f')](_0xa2e5('0x40'))){_0x8e46bb[_0xa2e5('0x10')]=qs[_0xa2e5('0x10')](_0x229904['query'][_0xa2e5('0x10')]);_0x8e46bb[_0xa2e5('0xe')]=qs[_0xa2e5('0xe')](_0x229904[_0xa2e5('0x24')][_0xa2e5('0xe')]);}_0x8e46bb[_0xa2e5('0x41')]=qs['sort'](_0x229904[_0xa2e5('0x24')][_0xa2e5('0x42')]);_0x8e46bb[_0xa2e5('0x22')]=qs[_0xa2e5('0x2b')](_['pick'](_0x229904[_0xa2e5('0x24')],_0x58a6ea[_0xa2e5('0x2b')]));_0x8e46bb[_0xa2e5('0x22')][_0xa2e5('0x43')]=_0x12bf33['id'];if(_0x229904[_0xa2e5('0x24')][_0xa2e5('0x44')]){_0x8e46bb[_0xa2e5('0x22')]=_[_0xa2e5('0x31')](_0x8e46bb[_0xa2e5('0x22')],{'$or':_[_0xa2e5('0x1c')](_0x8e46bb[_0xa2e5('0x2e')],function(_0x3394f9){var _0x32a3de={};_0x32a3de[_0x3394f9]={'$like':'%'+_0x229904[_0xa2e5('0x24')][_0xa2e5('0x44')]+'%'};return _0x32a3de;})});}_0x8e46bb=_[_0xa2e5('0x31')]({},_0x8e46bb,_0x229904[_0xa2e5('0x32')]);return db[_0xa2e5('0x3d')][_0xa2e5('0x25')](_0x8e46bb);}})[_0xa2e5('0x13')](function(_0x89bc78){if(_0x89bc78){return db[_0xa2e5('0x45')][_0xa2e5('0x46')]({'where':{'id':_[_0xa2e5('0x1c')](_0x89bc78,'UserId'),'role':_0xa2e5('0x47')},'attributes':['id',_0xa2e5('0x1a'),_0xa2e5('0x48'),_0xa2e5('0x49'),_0xa2e5('0x4a')]});}})[_0xa2e5('0x13')](function(_0x2fa455){if(_0x2fa455){return{'count':_0x2fa455['count'],'rows':_['map'](_0x2fa455['rows'],function(_0x589eaa){return{'membername':_0x589eaa[_0xa2e5('0x1a')],'UserId':_0x589eaa['id'],'queue_name':_0x4c1b86['name'],'ChatQueueId':_0x4c1b86['id'],'interface':util['format'](_0xa2e5('0x4b'),'SIP',_0x589eaa[_0xa2e5('0x1a')]),'penalty':0x0,'paused':_0x589eaa[_0xa2e5('0x48')],'createdAt':_0x589eaa[_0xa2e5('0x4a')],'updatedAt':_0x589eaa[_0xa2e5('0x49')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xa2e5('0x13')](respondWithFilteredResult(_0xd682fb,_0x8e46bb))[_0xa2e5('0x26')](handleError(_0xd682fb,null));};exports['getTeams']=function(_0x5cd7a9,_0x3dba64){var _0x35d322={};var _0x13b3c6={};var _0x38bc23;var _0x59ee9e;return db[_0xa2e5('0x2a')][_0xa2e5('0x3c')]({'where':{'id':_0x5cd7a9[_0xa2e5('0x28')]['id']}})['then'](handleEntityNotFound(_0x3dba64,null))[_0xa2e5('0x13')](function(_0x133753){if(_0x133753){_0x38bc23=_0x133753;_0x13b3c6['model']=_['keys'](db[_0xa2e5('0x4c')][_0xa2e5('0x1d')]);_0x13b3c6[_0xa2e5('0x24')]=_[_0xa2e5('0x29')](_0x5cd7a9[_0xa2e5('0x24')]);_0x13b3c6[_0xa2e5('0x2b')]=_['intersection'](_0x13b3c6[_0xa2e5('0x2d')],_0x13b3c6[_0xa2e5('0x24')]);_0x35d322[_0xa2e5('0x2e')]=_[_0xa2e5('0x2c')](_0x13b3c6[_0xa2e5('0x2d')],qs[_0xa2e5('0x2f')](_0x5cd7a9['query'][_0xa2e5('0x2f')]));_0x35d322['attributes']=_0x35d322['attributes']['length']?_0x35d322[_0xa2e5('0x2e')]:_0x13b3c6[_0xa2e5('0x2d')];_0x35d322[_0xa2e5('0x41')]=qs[_0xa2e5('0x42')](_0x5cd7a9[_0xa2e5('0x24')][_0xa2e5('0x42')]);_0x35d322[_0xa2e5('0x22')]=qs[_0xa2e5('0x2b')](_[_0xa2e5('0x4d')](_0x5cd7a9[_0xa2e5('0x24')],_0x13b3c6[_0xa2e5('0x2b')]));if(_0x5cd7a9[_0xa2e5('0x24')]['filter']){_0x35d322['where']=_[_0xa2e5('0x31')](_0x35d322[_0xa2e5('0x22')],{'$or':_[_0xa2e5('0x1c')](_0x35d322[_0xa2e5('0x2e')],function(_0x450dbb){var _0x101afa={};_0x101afa[_0x450dbb]={'$like':'%'+_0x5cd7a9[_0xa2e5('0x24')][_0xa2e5('0x44')]+'%'};return _0x101afa;})});}_0x35d322=_[_0xa2e5('0x31')]({},_0x35d322,_0x5cd7a9[_0xa2e5('0x32')]);return _0x38bc23[_0xa2e5('0x4e')](_0x35d322);}})[_0xa2e5('0x13')](function(_0x4182c8){if(_0x4182c8){_0x59ee9e=_0x4182c8['length'];if(!_0x5cd7a9[_0xa2e5('0x24')]['hasOwnProperty'](_0xa2e5('0x40'))){_0x35d322[_0xa2e5('0x10')]=qs[_0xa2e5('0x10')](_0x5cd7a9[_0xa2e5('0x24')]['limit']);_0x35d322[_0xa2e5('0xe')]=qs[_0xa2e5('0xe')](_0x5cd7a9[_0xa2e5('0x24')][_0xa2e5('0xe')]);}return _0x38bc23[_0xa2e5('0x4e')](_0x35d322);}})[_0xa2e5('0x13')](function(_0x11bb3c){if(_0x11bb3c){return _0x11bb3c?{'count':_0x59ee9e,'rows':_0x11bb3c}:null;}})[_0xa2e5('0x13')](respondWithResult(_0x3dba64,null))[_0xa2e5('0x26')](handleError(_0x3dba64,null));};exports[_0xa2e5('0x4f')]=function(_0xd3b153,_0x2b84b5){var _0x507e80=_0xd3b153[_0xa2e5('0x3a')]['ids'];return db[_0xa2e5('0x4c')]['findAll']({'where':{'id':_0x507e80},'attributes':['id'],'include':[{'model':db[_0xa2e5('0x45')],'as':'Agents','attributes':['id',_0xa2e5('0x1a'),'online',_0xa2e5('0x50'),_0xa2e5('0x51')],'raw':!![]}]})['then'](function(_0x4763b7){if(_0x4763b7){var _0x446803=_['flatMap'](_0x4763b7,function(_0x594c60){var _0x502b59=_0x594c60[_0xa2e5('0x14')]({'plain':!![]});return _0x502b59[_0xa2e5('0x52')];});return db[_0xa2e5('0x2a')][_0xa2e5('0x36')]({'where':{'id':_0xd3b153[_0xa2e5('0x28')]['id']}})[_0xa2e5('0x13')](function(_0x435558){return db[_0xa2e5('0x53')][_0xa2e5('0x54')](function(_0xa535cd){return _0x435558['addTeams'](_0x507e80,{'transaction':_0xa535cd})[_0xa2e5('0x13')](function(){return BPromise[_0xa2e5('0x55')](_0x446803,function(_0x5af0c2){return db[_0xa2e5('0x3d')][_0xa2e5('0x56')]({'where':{'UserId':_0x5af0c2['id'],'ChatQueueId':_0xd3b153['params']['id']},'transaction':_0xa535cd});});})[_0xa2e5('0x13')](function(){_0x446803[_0xa2e5('0x57')](function(_0x49e8a8){socket[_0xa2e5('0x58')](_0xa2e5('0x59'),{'UserId':_0x49e8a8['id'],'ChatQueueId':_0x435558['id']});});});});});}})[_0xa2e5('0x13')](respondWithStatusCode(_0x2b84b5,null))[_0xa2e5('0x26')](handleError(_0x2b84b5,null));};exports[_0xa2e5('0x5a')]=function(_0x18e8dd,_0xa8b922){return db[_0xa2e5('0x4c')][_0xa2e5('0x25')]({'where':{'id':_0x18e8dd[_0xa2e5('0x24')][_0xa2e5('0x5b')]},'attributes':['id'],'include':[{'model':db[_0xa2e5('0x45')],'as':_0xa2e5('0x52'),'attributes':['id'],'raw':!![]}]})[_0xa2e5('0x13')](handleEntityNotFound(_0xa8b922,null))[_0xa2e5('0x13')](function(_0x2556a4){var _0x5997eb=_['map'](_0x2556a4,'id');var _0x279f03=[];var _0x334aeb=[];var _0x34f5bb=squel[_0xa2e5('0x5c')]();_0x34f5bb['field']('tq.TeamId')[_0xa2e5('0x5d')](_0xa2e5('0x5e'),'tq')[_0xa2e5('0x5f')]('user_has_teams','ut',_0xa2e5('0x60'))[_0xa2e5('0x22')](_0xa2e5('0x61'),_0x18e8dd[_0xa2e5('0x28')]['id']);for(var _0x18c51=0x0;_0x18c51<_0x2556a4['length'];_0x18c51+=0x1){let _0x3c4177=_0x2556a4[_0x18c51];for(var _0x55e20e=0x0;_0x55e20e<_0x3c4177['Agents'][_0xa2e5('0x3e')];_0x55e20e+=0x1){let _0x15d694=_0x3c4177[_0xa2e5('0x52')][_0x55e20e];var _0x3fddbe=_0x34f5bb[_0xa2e5('0x62')]();_0x3fddbe[_0xa2e5('0x22')](_0xa2e5('0x63'),_0x15d694['id']);_0x334aeb[_0xa2e5('0x64')](db[_0xa2e5('0x53')][_0xa2e5('0x24')](_0x3fddbe['toString'](),{'type':db[_0xa2e5('0x53')][_0xa2e5('0x65')]['SELECT']})['then'](function(_0x569ac3){if(_0x569ac3[_0xa2e5('0x3e')]===0x1){return _0x15d694['id'];}else{var _0xea878=_['every'](_[_0xa2e5('0x1c')](_0x569ac3,_0xa2e5('0x66')),function(_0x50190c){return _['includes'](_0x5997eb,_0x50190c);});if(_0xea878){return _0x15d694['id'];}}}));}}return BPromise[_0xa2e5('0x67')](_0x334aeb)[_0xa2e5('0x13')](function(_0x498e2c){_0x279f03=_(_0x279f03)['union'](_0x498e2c)[_0xa2e5('0x68')]()[_0xa2e5('0x69')]();return db['ChatQueue'][_0xa2e5('0x36')]({'where':{'id':_0x18e8dd['params']['id']}})[_0xa2e5('0x13')](function(_0x36f8cd){return db[_0xa2e5('0x53')][_0xa2e5('0x54')](function(_0x2816f1){return _0x36f8cd['removeTeams'](_0x18e8dd[_0xa2e5('0x24')][_0xa2e5('0x5b')],{'transaction':_0x2816f1})[_0xa2e5('0x13')](function(){if(!_[_0xa2e5('0x6a')](_0x279f03)){return _0x36f8cd['removeAgents'](_0x279f03,{'transaction':_0x2816f1});}})[_0xa2e5('0x13')](function(){_0x279f03['forEach'](function(_0x5d1db3){socket[_0xa2e5('0x58')](_0xa2e5('0x6b'),{'UserId':_0x5d1db3,'ChatQueueId':_0x36f8cd['id']});});});});});});})['then'](respondWithStatusCode(_0xa8b922,null))[_0xa2e5('0x26')](handleError(_0xa8b922,null));};exports['addAgents']=function(_0x5aa27a,_0x2b42bd){return db[_0xa2e5('0x2a')][_0xa2e5('0x36')]({'where':{'id':_0x5aa27a[_0xa2e5('0x28')]['id']}})[_0xa2e5('0x13')](handleEntityNotFound(_0x2b42bd,null))[_0xa2e5('0x13')](function(_0x39c316){if(_0x39c316){return _0x39c316[_0xa2e5('0x6c')](_0x5aa27a[_0xa2e5('0x3a')][_0xa2e5('0x5b')],_[_0xa2e5('0x6d')](_0x5aa27a[_0xa2e5('0x3a')],[_0xa2e5('0x5b'),'id'])||{})[_0xa2e5('0x6e')](function(_0x4323f7){for(var _0x38641c=0x0;_0x38641c<_0x5aa27a[_0xa2e5('0x3a')]['ids'][_0xa2e5('0x3e')];_0x38641c+=0x1){socket[_0xa2e5('0x58')](_0xa2e5('0x59'),{'UserId':Number(_0x5aa27a[_0xa2e5('0x3a')][_0xa2e5('0x5b')][_0x38641c]),'ChatQueueId':Number(_0x5aa27a[_0xa2e5('0x28')]['id'])});}return _0x4323f7;});}})[_0xa2e5('0x13')](respondWithResult(_0x2b42bd,null))['catch'](handleError(_0x2b42bd,null));};exports[_0xa2e5('0x6f')]=function(_0x9a17c8,_0xabde46){return db[_0xa2e5('0x2a')][_0xa2e5('0x36')]({'where':{'id':_0x9a17c8[_0xa2e5('0x28')]['id']}})[_0xa2e5('0x13')](handleEntityNotFound(_0xabde46,null))[_0xa2e5('0x13')](function(_0xaf9ee1){if(_0xaf9ee1){return _0xaf9ee1[_0xa2e5('0x6f')](_0x9a17c8['query'][_0xa2e5('0x5b')])[_0xa2e5('0x13')](function(){if(_[_0xa2e5('0x70')](_0x9a17c8[_0xa2e5('0x24')][_0xa2e5('0x5b')])){for(var _0x476e97=0x0;_0x476e97<_0x9a17c8['query'][_0xa2e5('0x5b')]['length'];_0x476e97+=0x1){socket[_0xa2e5('0x58')]('userChatQueue:remove',{'UserId':Number(_0x9a17c8['query'][_0xa2e5('0x5b')][_0x476e97]),'ChatQueueId':Number(_0x9a17c8[_0xa2e5('0x28')]['id'])});}}else{socket['emit'](_0xa2e5('0x6b'),{'UserId':Number(_0x9a17c8[_0xa2e5('0x24')]['ids']),'ChatQueueId':Number(_0x9a17c8[_0xa2e5('0x28')]['id'])});}});}})[_0xa2e5('0x13')](respondWithStatusCode(_0xabde46,null))[_0xa2e5('0x26')](handleError(_0xabde46,null));};exports[_0xa2e5('0x71')]=function(_0x416327,_0x438bfe){var _0x331675={};var _0x4a8ed0={};var _0x3ff9e9;var _0x40dd9e;return db['ChatQueue'][_0xa2e5('0x3c')]({'where':{'id':_0x416327[_0xa2e5('0x28')]['id']}})[_0xa2e5('0x13')](handleEntityNotFound(_0x438bfe,null))[_0xa2e5('0x13')](function(_0x336b48){if(_0x336b48){_0x3ff9e9=_0x336b48;_0x4a8ed0[_0xa2e5('0x2d')]=_['keys'](db[_0xa2e5('0x45')][_0xa2e5('0x1d')]);_0x4a8ed0[_0xa2e5('0x24')]=_[_0xa2e5('0x29')](_0x416327[_0xa2e5('0x24')]);_0x4a8ed0['filters']=_[_0xa2e5('0x2c')](_0x4a8ed0[_0xa2e5('0x2d')],_0x4a8ed0[_0xa2e5('0x24')]);_0x331675['attributes']=_['intersection'](_0x4a8ed0[_0xa2e5('0x2d')],qs[_0xa2e5('0x2f')](_0x416327[_0xa2e5('0x24')][_0xa2e5('0x2f')]));_0x331675['attributes']=_0x331675[_0xa2e5('0x2e')][_0xa2e5('0x3e')]?_0x331675['attributes']:_0x4a8ed0[_0xa2e5('0x2d')];_0x331675[_0xa2e5('0x41')]=qs[_0xa2e5('0x42')](_0x416327[_0xa2e5('0x24')]['sort']);_0x331675['where']=qs[_0xa2e5('0x2b')](_[_0xa2e5('0x4d')](_0x416327[_0xa2e5('0x24')],_0x4a8ed0['filters']));if(_0x416327['query'][_0xa2e5('0x44')]){_0x331675[_0xa2e5('0x22')]=_[_0xa2e5('0x31')](_0x331675[_0xa2e5('0x22')],{'$or':_[_0xa2e5('0x1c')](_0x331675[_0xa2e5('0x2e')],function(_0x44f1af){var _0x3914ce={};_0x3914ce[_0x44f1af]={'$like':'%'+_0x416327[_0xa2e5('0x24')][_0xa2e5('0x44')]+'%'};return _0x3914ce;})});}_0x331675=_[_0xa2e5('0x31')]({},_0x331675,_0x416327[_0xa2e5('0x32')]);return _0x3ff9e9[_0xa2e5('0x71')](_0x331675);}})[_0xa2e5('0x13')](function(_0x5693f8){if(_0x5693f8){_0x40dd9e=_0x5693f8[_0xa2e5('0x3e')];if(!_0x416327[_0xa2e5('0x24')][_0xa2e5('0x3f')](_0xa2e5('0x40'))){_0x331675[_0xa2e5('0x10')]=qs[_0xa2e5('0x10')](_0x416327['query'][_0xa2e5('0x10')]);_0x331675[_0xa2e5('0xe')]=qs[_0xa2e5('0xe')](_0x416327['query'][_0xa2e5('0xe')]);}return _0x3ff9e9[_0xa2e5('0x71')](_0x331675);}})['then'](function(_0x278555){if(_0x278555){return _0x278555?{'count':_0x40dd9e,'rows':_0x278555}:null;}})[_0xa2e5('0x13')](respondWithResult(_0x438bfe,null))[_0xa2e5('0x26')](handleError(_0x438bfe,null));};
\ No newline at end of file
+var _0xabf4=['redis','defaults','localhost','./chatQueue.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','update','then','destroy','get','ChatQueues','UserProfileResource','error','stack','name','send','index','map','ChatQueue','rawAttributes','type','key','where','include','query','findAll','show','params','model','keys','filters','attributes','intersection','fields','length','includeAll','merge','find','catch','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','UserChatQueue','hasOwnProperty','nolimit','order','sort','pick','filter','options','findAndCountAll','UserId','agent','chatPause','updatedAt','createdAt','rows','format','%s/%s','SIP','getTeams','findOne','Team','ids','User','Agents','online','voicePause','flatMap','transaction','addTeams','each','findOrCreate','forEach','emit','userChatQueue:save','removeTeams','select','field','tq.TeamId','from','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','sequelize','QueryTypes','every','includes','all','union','value','userChatQueue:remove','addAgents','omit','spread','removeAgents','getAgents','util','lodash','squel','../../components/parsers/qs','../../config/logger','api','../../mysqldb'];(function(_0x3d79ac,_0x222051){var _0x475b30=function(_0x119831){while(--_0x119831){_0x3d79ac['push'](_0x3d79ac['shift']());}};_0x475b30(++_0x222051);}(_0xabf4,0x77));var _0x4abf=function(_0x34f41a,_0x5f1d24){_0x34f41a=_0x34f41a-0x0;var _0x4bfb9b=_0xabf4[_0x34f41a];return _0x4bfb9b;};'use strict';var BPromise=require('bluebird');var util=require(_0x4abf('0x0'));var _=require(_0x4abf('0x1'));var squel=require(_0x4abf('0x2'));var Redis=require('ioredis');var qs=require(_0x4abf('0x3'));var logger=require(_0x4abf('0x4'))(_0x4abf('0x5'));var config=require('../../config/environment');var db=require(_0x4abf('0x6'))['db'];config[_0x4abf('0x7')]=_[_0x4abf('0x8')](config['redis'],{'host':_0x4abf('0x9'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4abf('0x7')]));require(_0x4abf('0xa'))[_0x4abf('0xb')](socket);function respondWithStatusCode(_0x53a02a,_0x211221){_0x211221=_0x211221||0xcc;return function(_0x3c47e4){if(_0x3c47e4){return _0x53a02a[_0x4abf('0xc')](_0x211221);}return _0x53a02a[_0x4abf('0xd')](_0x211221)[_0x4abf('0xe')]();};}function respondWithResult(_0x155768,_0xc4914){_0xc4914=_0xc4914||0xc8;return function(_0x473f5a){if(_0x473f5a){return _0x155768['status'](_0xc4914)[_0x4abf('0xf')](_0x473f5a);}};}function respondWithFilteredResult(_0x41b901,_0x2b6cae){return function(_0x2a9487){if(_0x2a9487){var _0x5169cf=typeof _0x2b6cae[_0x4abf('0x10')]===_0x4abf('0x11')&&typeof _0x2b6cae[_0x4abf('0x12')]==='undefined';var _0x2ad0a1=_0x2a9487[_0x4abf('0x13')];var _0x188a43=_0x5169cf?0x0:_0x2b6cae[_0x4abf('0x10')];var _0x5f452f=_0x5169cf?_0x2a9487[_0x4abf('0x13')]:_0x2b6cae[_0x4abf('0x10')]+_0x2b6cae[_0x4abf('0x12')];var _0x470aaa;if(_0x5f452f>=_0x2ad0a1){_0x5f452f=_0x2ad0a1;_0x470aaa=0xc8;}else{_0x470aaa=0xce;}_0x41b901['status'](_0x470aaa);return _0x41b901[_0x4abf('0x14')](_0x4abf('0x15'),_0x188a43+'-'+_0x5f452f+'/'+_0x2ad0a1)[_0x4abf('0xf')](_0x2a9487);}return null;};}function saveUpdates(_0x1f0bce){return function(_0xc2b78d){if(_0xc2b78d){return _0xc2b78d[_0x4abf('0x16')](_0x1f0bce)[_0x4abf('0x17')](function(_0x1d9bfa){return _0x1d9bfa;});}return null;};}function removeEntity(_0x178917){return function(_0x79d84f){if(_0x79d84f){return _0x79d84f[_0x4abf('0x18')]()['then'](function(){var _0x2072f1=_0x79d84f[_0x4abf('0x19')]({'plain':!![]});var _0x3745da=_0x4abf('0x1a');return db[_0x4abf('0x1b')][_0x4abf('0x18')]({'where':{'type':_0x3745da,'resourceId':_0x2072f1['id']}})[_0x4abf('0x17')](function(){return _0x79d84f;});})['then'](function(){_0x178917[_0x4abf('0xd')](0xcc)['end']();});}};}function handleEntityNotFound(_0x11b45b){return function(_0x38768b){if(!_0x38768b){_0x11b45b[_0x4abf('0xc')](0x194);}return _0x38768b;};}function handleError(_0xfa066e,_0x2044f9){_0x2044f9=_0x2044f9||0x1f4;return function(_0x186023){logger[_0x4abf('0x1c')](_0x186023[_0x4abf('0x1d')]);if(_0x186023[_0x4abf('0x1e')]){delete _0x186023[_0x4abf('0x1e')];}_0xfa066e[_0x4abf('0xd')](_0x2044f9)[_0x4abf('0x1f')](_0x186023);};}exports[_0x4abf('0x20')]=function(_0x5cb8dc,_0x58f8d7){var _0x56c923={};var _0x5de50d={'count':0x0,'rows':[]};var _0x42c656=_[_0x4abf('0x21')](db[_0x4abf('0x22')][_0x4abf('0x23')],function(_0x3a3668){return{'name':_0x3a3668['fieldName'],'type':_0x3a3668[_0x4abf('0x24')][_0x4abf('0x25')]};});_0x56c923=qs['getOptions'](_0x42c656,_0x5cb8dc);var _0xd08200={'where':_0x56c923[_0x4abf('0x26')]};return db[_0x4abf('0x22')][_0x4abf('0x13')](_0xd08200)[_0x4abf('0x17')](function(_0xec4417){_0x5de50d[_0x4abf('0x13')]=_0xec4417;_0x56c923[_0x4abf('0x27')]=qs['include'](_0x5cb8dc[_0x4abf('0x28')]);return db['ChatQueue'][_0x4abf('0x29')](_0x56c923);})[_0x4abf('0x17')](function(_0x2c4650){_0x5de50d['rows']=_0x2c4650;return _0x5de50d;})[_0x4abf('0x17')](respondWithFilteredResult(_0x58f8d7,_0x56c923))['catch'](handleError(_0x58f8d7,null));};exports[_0x4abf('0x2a')]=function(_0x231b39,_0x12a277){var _0x34a12f={'raw':!![],'where':{'id':_0x231b39[_0x4abf('0x2b')]['id']}},_0x5d90e9={};_0x5d90e9[_0x4abf('0x2c')]=_[_0x4abf('0x2d')](db['ChatQueue']['rawAttributes']);_0x5d90e9[_0x4abf('0x28')]=_[_0x4abf('0x2d')](_0x231b39[_0x4abf('0x28')]);_0x5d90e9[_0x4abf('0x2e')]=_['intersection'](_0x5d90e9['model'],_0x5d90e9[_0x4abf('0x28')]);_0x34a12f[_0x4abf('0x2f')]=_[_0x4abf('0x30')](_0x5d90e9['model'],qs[_0x4abf('0x31')](_0x231b39[_0x4abf('0x28')]['fields']));_0x34a12f['attributes']=_0x34a12f[_0x4abf('0x2f')][_0x4abf('0x32')]?_0x34a12f[_0x4abf('0x2f')]:_0x5d90e9[_0x4abf('0x2c')];if(_0x231b39['query'][_0x4abf('0x33')]){_0x34a12f[_0x4abf('0x27')]=[{'all':!![]}];}_0x34a12f=_[_0x4abf('0x34')]({},_0x34a12f,_0x231b39['options']);return db[_0x4abf('0x22')][_0x4abf('0x35')](_0x34a12f)[_0x4abf('0x17')](handleEntityNotFound(_0x12a277,null))['then'](respondWithResult(_0x12a277,null))[_0x4abf('0x36')](handleError(_0x12a277,null));};exports[_0x4abf('0x37')]=function(_0x3d78f4,_0x2a243e){return db[_0x4abf('0x22')][_0x4abf('0x37')](_0x3d78f4[_0x4abf('0x38')],{})[_0x4abf('0x17')](function(_0x574548){var _0x1c17cd=_0x3d78f4['user']['get']({'plain':!![]});if(!_0x1c17cd)throw new Error(_0x4abf('0x39'));if(_0x1c17cd[_0x4abf('0x3a')]===_0x4abf('0x3b')){var _0x1e2377=_0x574548[_0x4abf('0x19')]({'plain':!![]});var _0x505339=_0x4abf('0x1a');return db[_0x4abf('0x3c')][_0x4abf('0x35')]({'where':{'name':_0x505339,'userProfileId':_0x1c17cd[_0x4abf('0x3d')]},'raw':!![]})[_0x4abf('0x17')](function(_0x49e4fd){if(_0x49e4fd&&_0x49e4fd[_0x4abf('0x3e')]===0x0){return db[_0x4abf('0x1b')][_0x4abf('0x37')]({'name':_0x1e2377[_0x4abf('0x1e')],'resourceId':_0x1e2377['id'],'type':_0x49e4fd['name'],'sectionId':_0x49e4fd['id']},{})[_0x4abf('0x17')](function(){return _0x574548;});}else{return _0x574548;}})[_0x4abf('0x36')](function(_0x531abe){logger[_0x4abf('0x1c')](_0x4abf('0x3f'),_0x531abe);throw _0x531abe;});}return _0x574548;})[_0x4abf('0x17')](respondWithResult(_0x2a243e,0xc9))[_0x4abf('0x36')](handleError(_0x2a243e,null));};exports[_0x4abf('0x16')]=function(_0x31ac3d,_0x40055d){if(_0x31ac3d[_0x4abf('0x38')]['id']){delete _0x31ac3d[_0x4abf('0x38')]['id'];}return db[_0x4abf('0x22')]['find']({'where':{'id':_0x31ac3d[_0x4abf('0x2b')]['id']}})['then'](handleEntityNotFound(_0x40055d,null))[_0x4abf('0x17')](saveUpdates(_0x31ac3d['body'],null))[_0x4abf('0x17')](respondWithResult(_0x40055d,null))[_0x4abf('0x36')](handleError(_0x40055d,null));};exports[_0x4abf('0x18')]=function(_0x2a90be,_0x2695e3){return db[_0x4abf('0x22')][_0x4abf('0x35')]({'where':{'id':_0x2a90be['params']['id']}})[_0x4abf('0x17')](handleEntityNotFound(_0x2695e3,null))[_0x4abf('0x17')](removeEntity(_0x2695e3,null))[_0x4abf('0x36')](handleError(_0x2695e3,null));};exports['describe']=function(_0x54d590,_0x2c6b76){return db[_0x4abf('0x22')][_0x4abf('0x40')]()['then'](respondWithResult(_0x2c6b76,null))[_0x4abf('0x36')](handleError(_0x2c6b76,null));};exports[_0x4abf('0x41')]=function(_0x28a756,_0xec661a){var _0x1f3a7d={'raw':!![],'where':{}},_0x14ac29={},_0x2fbf68;return db[_0x4abf('0x22')]['findOne']({'where':{'id':_0x28a756['params']['id']}})['then'](handleEntityNotFound(_0xec661a,null))[_0x4abf('0x17')](function(_0xec48ef){if(_0xec48ef){_0x2fbf68=_0xec48ef[_0x4abf('0x19')]({'plain':!![]});_0x14ac29[_0x4abf('0x2c')]=_[_0x4abf('0x2d')](db[_0x4abf('0x42')][_0x4abf('0x23')]);_0x14ac29['query']=_[_0x4abf('0x2d')](_0x28a756[_0x4abf('0x28')]);_0x14ac29[_0x4abf('0x2e')]=_[_0x4abf('0x30')](_0x14ac29[_0x4abf('0x2c')],_0x14ac29[_0x4abf('0x28')]);_0x1f3a7d[_0x4abf('0x2f')]=_[_0x4abf('0x30')](_0x14ac29[_0x4abf('0x2c')],qs[_0x4abf('0x31')](_0x28a756['query'][_0x4abf('0x31')]));_0x1f3a7d['attributes']=_0x1f3a7d[_0x4abf('0x2f')][_0x4abf('0x32')]?_0x1f3a7d[_0x4abf('0x2f')]:_0x14ac29[_0x4abf('0x2c')];if(!_0x28a756[_0x4abf('0x28')][_0x4abf('0x43')](_0x4abf('0x44'))){_0x1f3a7d[_0x4abf('0x12')]=qs[_0x4abf('0x12')](_0x28a756[_0x4abf('0x28')][_0x4abf('0x12')]);_0x1f3a7d['offset']=qs[_0x4abf('0x10')](_0x28a756[_0x4abf('0x28')]['offset']);}_0x1f3a7d[_0x4abf('0x45')]=qs[_0x4abf('0x46')](_0x28a756[_0x4abf('0x28')][_0x4abf('0x46')]);_0x1f3a7d[_0x4abf('0x26')]=qs[_0x4abf('0x2e')](_[_0x4abf('0x47')](_0x28a756[_0x4abf('0x28')],_0x14ac29[_0x4abf('0x2e')]));_0x1f3a7d[_0x4abf('0x26')]['ChatQueueId']=_0xec48ef['id'];if(_0x28a756[_0x4abf('0x28')][_0x4abf('0x48')]){_0x1f3a7d[_0x4abf('0x26')]=_['merge'](_0x1f3a7d[_0x4abf('0x26')],{'$or':_[_0x4abf('0x21')](_0x1f3a7d['attributes'],function(_0x1f531f){var _0x47f0ec={};_0x47f0ec[_0x1f531f]={'$like':'%'+_0x28a756[_0x4abf('0x28')][_0x4abf('0x48')]+'%'};return _0x47f0ec;})});}_0x1f3a7d=_[_0x4abf('0x34')]({},_0x1f3a7d,_0x28a756[_0x4abf('0x49')]);return db[_0x4abf('0x42')]['findAll'](_0x1f3a7d);}})['then'](function(_0x24cff2){if(_0x24cff2){return db['User'][_0x4abf('0x4a')]({'where':{'id':_['map'](_0x24cff2,_0x4abf('0x4b')),'role':_0x4abf('0x4c')},'attributes':['id',_0x4abf('0x1e'),_0x4abf('0x4d'),_0x4abf('0x4e'),_0x4abf('0x4f')]});}})['then'](function(_0xe7383e){if(_0xe7383e){return{'count':_0xe7383e['count'],'rows':_[_0x4abf('0x21')](_0xe7383e[_0x4abf('0x50')],function(_0x185d54){return{'membername':_0x185d54[_0x4abf('0x1e')],'UserId':_0x185d54['id'],'queue_name':_0x2fbf68[_0x4abf('0x1e')],'ChatQueueId':_0x2fbf68['id'],'interface':util[_0x4abf('0x51')](_0x4abf('0x52'),_0x4abf('0x53'),_0x185d54['name']),'penalty':0x0,'paused':_0x185d54['chatPause'],'createdAt':_0x185d54[_0x4abf('0x4f')],'updatedAt':_0x185d54[_0x4abf('0x4e')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x4abf('0x17')](respondWithFilteredResult(_0xec661a,_0x1f3a7d))[_0x4abf('0x36')](handleError(_0xec661a,null));};exports[_0x4abf('0x54')]=function(_0x281c85,_0xd468a9){var _0x584084={};var _0x34232e={};var _0x4d89de;var _0xcf48fd;return db[_0x4abf('0x22')][_0x4abf('0x55')]({'where':{'id':_0x281c85['params']['id']}})[_0x4abf('0x17')](handleEntityNotFound(_0xd468a9,null))[_0x4abf('0x17')](function(_0xec860){if(_0xec860){_0x4d89de=_0xec860;_0x34232e[_0x4abf('0x2c')]=_[_0x4abf('0x2d')](db[_0x4abf('0x56')][_0x4abf('0x23')]);_0x34232e[_0x4abf('0x28')]=_['keys'](_0x281c85[_0x4abf('0x28')]);_0x34232e['filters']=_[_0x4abf('0x30')](_0x34232e[_0x4abf('0x2c')],_0x34232e['query']);_0x584084['attributes']=_[_0x4abf('0x30')](_0x34232e['model'],qs['fields'](_0x281c85[_0x4abf('0x28')]['fields']));_0x584084['attributes']=_0x584084['attributes']['length']?_0x584084[_0x4abf('0x2f')]:_0x34232e[_0x4abf('0x2c')];_0x584084['order']=qs['sort'](_0x281c85[_0x4abf('0x28')][_0x4abf('0x46')]);_0x584084['where']=qs['filters'](_[_0x4abf('0x47')](_0x281c85[_0x4abf('0x28')],_0x34232e[_0x4abf('0x2e')]));if(_0x281c85[_0x4abf('0x28')]['filter']){_0x584084['where']=_[_0x4abf('0x34')](_0x584084[_0x4abf('0x26')],{'$or':_[_0x4abf('0x21')](_0x584084['attributes'],function(_0x4937b8){var _0xd6f5e5={};_0xd6f5e5[_0x4937b8]={'$like':'%'+_0x281c85[_0x4abf('0x28')][_0x4abf('0x48')]+'%'};return _0xd6f5e5;})});}_0x584084=_[_0x4abf('0x34')]({},_0x584084,_0x281c85['options']);return _0x4d89de[_0x4abf('0x54')](_0x584084);}})[_0x4abf('0x17')](function(_0x484881){if(_0x484881){_0xcf48fd=_0x484881[_0x4abf('0x32')];if(!_0x281c85[_0x4abf('0x28')]['hasOwnProperty'](_0x4abf('0x44'))){_0x584084[_0x4abf('0x12')]=qs[_0x4abf('0x12')](_0x281c85[_0x4abf('0x28')][_0x4abf('0x12')]);_0x584084[_0x4abf('0x10')]=qs[_0x4abf('0x10')](_0x281c85[_0x4abf('0x28')]['offset']);}return _0x4d89de[_0x4abf('0x54')](_0x584084);}})['then'](function(_0x4012a0){if(_0x4012a0){return _0x4012a0?{'count':_0xcf48fd,'rows':_0x4012a0}:null;}})[_0x4abf('0x17')](respondWithResult(_0xd468a9,null))[_0x4abf('0x36')](handleError(_0xd468a9,null));};exports['addTeams']=function(_0x519fb7,_0x4da9a2){var _0x91f1e4=_0x519fb7['body'][_0x4abf('0x57')];return db[_0x4abf('0x56')][_0x4abf('0x29')]({'where':{'id':_0x91f1e4},'attributes':['id'],'include':[{'model':db[_0x4abf('0x58')],'as':_0x4abf('0x59'),'attributes':['id','name',_0x4abf('0x5a'),_0x4abf('0x5b'),'interface'],'raw':!![]}]})[_0x4abf('0x17')](function(_0x4f9a08){if(_0x4f9a08){var _0x73ebb=_[_0x4abf('0x5c')](_0x4f9a08,function(_0x1284a9){var _0x7d871f=_0x1284a9[_0x4abf('0x19')]({'plain':!![]});return _0x7d871f[_0x4abf('0x59')];});return db[_0x4abf('0x22')][_0x4abf('0x35')]({'where':{'id':_0x519fb7[_0x4abf('0x2b')]['id']}})[_0x4abf('0x17')](function(_0x413c32){return db['sequelize'][_0x4abf('0x5d')](function(_0x545df7){return _0x413c32[_0x4abf('0x5e')](_0x91f1e4,{'transaction':_0x545df7})[_0x4abf('0x17')](function(){return BPromise[_0x4abf('0x5f')](_0x73ebb,function(_0x466fe5){return db[_0x4abf('0x42')][_0x4abf('0x60')]({'where':{'UserId':_0x466fe5['id'],'ChatQueueId':_0x519fb7[_0x4abf('0x2b')]['id']},'transaction':_0x545df7});});})['then'](function(){_0x73ebb[_0x4abf('0x61')](function(_0x23a2d4){socket[_0x4abf('0x62')](_0x4abf('0x63'),{'UserId':_0x23a2d4['id'],'ChatQueueId':_0x413c32['id']});});});});});}})['then'](respondWithStatusCode(_0x4da9a2,null))[_0x4abf('0x36')](handleError(_0x4da9a2,null));};exports[_0x4abf('0x64')]=function(_0x5ea920,_0x25ee71){return db[_0x4abf('0x56')][_0x4abf('0x29')]({'where':{'id':_0x5ea920['query'][_0x4abf('0x57')]},'attributes':['id'],'include':[{'model':db[_0x4abf('0x58')],'as':_0x4abf('0x59'),'attributes':['id'],'raw':!![]}]})[_0x4abf('0x17')](handleEntityNotFound(_0x25ee71,null))[_0x4abf('0x17')](function(_0x115e27){var _0x3809ff=_[_0x4abf('0x21')](_0x115e27,'id');var _0x15b882=[];var _0x5475ca=[];var _0x4ef80d=squel[_0x4abf('0x65')]();_0x4ef80d[_0x4abf('0x66')](_0x4abf('0x67'))[_0x4abf('0x68')]('team_has_chat_queues','tq')[_0x4abf('0x69')](_0x4abf('0x6a'),'ut',_0x4abf('0x6b'))[_0x4abf('0x26')](_0x4abf('0x6c'),_0x5ea920[_0x4abf('0x2b')]['id']);for(var _0x3a056b=0x0;_0x3a056b<_0x115e27[_0x4abf('0x32')];_0x3a056b+=0x1){let _0x305d12=_0x115e27[_0x3a056b];for(var _0x156fdd=0x0;_0x156fdd<_0x305d12[_0x4abf('0x59')][_0x4abf('0x32')];_0x156fdd+=0x1){let _0x4b3e33=_0x305d12[_0x4abf('0x59')][_0x156fdd];var _0x5bf25d=_0x4ef80d[_0x4abf('0x6d')]();_0x5bf25d[_0x4abf('0x26')](_0x4abf('0x6e'),_0x4b3e33['id']);_0x5475ca[_0x4abf('0x6f')](db['sequelize'][_0x4abf('0x28')](_0x5bf25d[_0x4abf('0x70')](),{'type':db[_0x4abf('0x71')][_0x4abf('0x72')]['SELECT']})[_0x4abf('0x17')](function(_0x23aa05){if(_0x23aa05[_0x4abf('0x32')]===0x1){return _0x4b3e33['id'];}else{var _0x4b8da9=_[_0x4abf('0x73')](_[_0x4abf('0x21')](_0x23aa05,'TeamId'),function(_0x4bb8f){return _[_0x4abf('0x74')](_0x3809ff,_0x4bb8f);});if(_0x4b8da9){return _0x4b3e33['id'];}}}));}}return BPromise[_0x4abf('0x75')](_0x5475ca)[_0x4abf('0x17')](function(_0x4a39f6){_0x15b882=_(_0x15b882)[_0x4abf('0x76')](_0x4a39f6)['compact']()[_0x4abf('0x77')]();return db[_0x4abf('0x22')]['find']({'where':{'id':_0x5ea920[_0x4abf('0x2b')]['id']}})[_0x4abf('0x17')](function(_0x1bc6fa){return db[_0x4abf('0x71')][_0x4abf('0x5d')](function(_0x109c52){return _0x1bc6fa[_0x4abf('0x64')](_0x5ea920[_0x4abf('0x28')]['ids'],{'transaction':_0x109c52})[_0x4abf('0x17')](function(){if(!_['isEmpty'](_0x15b882)){return _0x1bc6fa['removeAgents'](_0x15b882,{'transaction':_0x109c52});}})[_0x4abf('0x17')](function(){_0x15b882[_0x4abf('0x61')](function(_0x38a577){socket['emit'](_0x4abf('0x78'),{'UserId':_0x38a577,'ChatQueueId':_0x1bc6fa['id']});});});});});});})[_0x4abf('0x17')](respondWithStatusCode(_0x25ee71,null))[_0x4abf('0x36')](handleError(_0x25ee71,null));};exports[_0x4abf('0x79')]=function(_0x474fdd,_0x1ad492){return db[_0x4abf('0x22')][_0x4abf('0x35')]({'where':{'id':_0x474fdd[_0x4abf('0x2b')]['id']}})[_0x4abf('0x17')](handleEntityNotFound(_0x1ad492,null))['then'](function(_0x371639){if(_0x371639){return _0x371639['addAgents'](_0x474fdd['body'][_0x4abf('0x57')],_[_0x4abf('0x7a')](_0x474fdd[_0x4abf('0x38')],[_0x4abf('0x57'),'id'])||{})[_0x4abf('0x7b')](function(_0x67f9a4){for(var _0x5aef6e=0x0;_0x5aef6e<_0x474fdd[_0x4abf('0x38')]['ids'][_0x4abf('0x32')];_0x5aef6e+=0x1){socket[_0x4abf('0x62')](_0x4abf('0x63'),{'UserId':Number(_0x474fdd[_0x4abf('0x38')][_0x4abf('0x57')][_0x5aef6e]),'ChatQueueId':Number(_0x474fdd['params']['id'])});}return _0x67f9a4;});}})['then'](respondWithResult(_0x1ad492,null))[_0x4abf('0x36')](handleError(_0x1ad492,null));};exports[_0x4abf('0x7c')]=function(_0x56df70,_0x3e70bd){return db['ChatQueue'][_0x4abf('0x35')]({'where':{'id':_0x56df70[_0x4abf('0x2b')]['id']}})['then'](handleEntityNotFound(_0x3e70bd,null))[_0x4abf('0x17')](function(_0x198776){if(_0x198776){return _0x198776[_0x4abf('0x7c')](_0x56df70[_0x4abf('0x28')][_0x4abf('0x57')])[_0x4abf('0x17')](function(){if(_['isArray'](_0x56df70[_0x4abf('0x28')]['ids'])){for(var _0x2d9aeb=0x0;_0x2d9aeb<_0x56df70[_0x4abf('0x28')]['ids'][_0x4abf('0x32')];_0x2d9aeb+=0x1){socket[_0x4abf('0x62')](_0x4abf('0x78'),{'UserId':Number(_0x56df70[_0x4abf('0x28')][_0x4abf('0x57')][_0x2d9aeb]),'ChatQueueId':Number(_0x56df70[_0x4abf('0x2b')]['id'])});}}else{socket[_0x4abf('0x62')]('userChatQueue:remove',{'UserId':Number(_0x56df70[_0x4abf('0x28')][_0x4abf('0x57')]),'ChatQueueId':Number(_0x56df70[_0x4abf('0x2b')]['id'])});}});}})[_0x4abf('0x17')](respondWithStatusCode(_0x3e70bd,null))['catch'](handleError(_0x3e70bd,null));};exports[_0x4abf('0x7d')]=function(_0x36c929,_0x43f626){var _0x235b68={};var _0xb55a4={};var _0x498ceb;var _0x476963;return db['ChatQueue'][_0x4abf('0x55')]({'where':{'id':_0x36c929['params']['id']}})[_0x4abf('0x17')](handleEntityNotFound(_0x43f626,null))[_0x4abf('0x17')](function(_0x1d9ac3){if(_0x1d9ac3){_0x498ceb=_0x1d9ac3;_0xb55a4[_0x4abf('0x2c')]=_['keys'](db[_0x4abf('0x58')][_0x4abf('0x23')]);_0xb55a4['query']=_[_0x4abf('0x2d')](_0x36c929[_0x4abf('0x28')]);_0xb55a4[_0x4abf('0x2e')]=_[_0x4abf('0x30')](_0xb55a4[_0x4abf('0x2c')],_0xb55a4[_0x4abf('0x28')]);_0x235b68[_0x4abf('0x2f')]=_[_0x4abf('0x30')](_0xb55a4[_0x4abf('0x2c')],qs[_0x4abf('0x31')](_0x36c929['query']['fields']));_0x235b68[_0x4abf('0x2f')]=_0x235b68[_0x4abf('0x2f')][_0x4abf('0x32')]?_0x235b68[_0x4abf('0x2f')]:_0xb55a4[_0x4abf('0x2c')];_0x235b68[_0x4abf('0x45')]=qs[_0x4abf('0x46')](_0x36c929[_0x4abf('0x28')][_0x4abf('0x46')]);_0x235b68[_0x4abf('0x26')]=qs[_0x4abf('0x2e')](_[_0x4abf('0x47')](_0x36c929[_0x4abf('0x28')],_0xb55a4['filters']));if(_0x36c929[_0x4abf('0x28')][_0x4abf('0x48')]){_0x235b68[_0x4abf('0x26')]=_[_0x4abf('0x34')](_0x235b68[_0x4abf('0x26')],{'$or':_[_0x4abf('0x21')](_0x235b68['attributes'],function(_0x41c95f){var _0x192c85={};_0x192c85[_0x41c95f]={'$like':'%'+_0x36c929[_0x4abf('0x28')][_0x4abf('0x48')]+'%'};return _0x192c85;})});}_0x235b68=_['merge']({},_0x235b68,_0x36c929[_0x4abf('0x49')]);return _0x498ceb[_0x4abf('0x7d')](_0x235b68);}})[_0x4abf('0x17')](function(_0x2d9546){if(_0x2d9546){_0x476963=_0x2d9546[_0x4abf('0x32')];if(!_0x36c929[_0x4abf('0x28')][_0x4abf('0x43')]('nolimit')){_0x235b68['limit']=qs[_0x4abf('0x12')](_0x36c929[_0x4abf('0x28')][_0x4abf('0x12')]);_0x235b68[_0x4abf('0x10')]=qs[_0x4abf('0x10')](_0x36c929[_0x4abf('0x28')][_0x4abf('0x10')]);}return _0x498ceb[_0x4abf('0x7d')](_0x235b68);}})['then'](function(_0x1063b8){if(_0x1063b8){return _0x1063b8?{'count':_0x476963,'rows':_0x1063b8}:null;}})[_0x4abf('0x17')](respondWithResult(_0x43f626,null))[_0x4abf('0x36')](handleError(_0x43f626,null));};
\ No newline at end of file