Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / chatQueue / chatQueue.controller.js
index 268ce8b..94b5de3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xacd5=['hasOwnProperty','nolimit','order','sort','where','filter','merge','type','options','count','findAll','rows','show','params','rawAttributes','length','include','find','create','body','role','user','ChatQueues','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','pick','UserChatQueue','User','findAndCountAll','UserId','agent','updatedAt','createdAt','format','%s/%s','chatPause','Agents','online','voicePause','interface','sequelize','transaction','addTeams','each','findOrCreate','forEach','emit','userChatQueue:save','Team','ids','select','field','tq.TeamId','from','team_has_chat_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','push','toString','every','includes','all','union','compact','value','removeAgents','userChatQueue:remove','addAgents','spread','isArray','getAgents','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','squel','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./chatQueue.socket','register','jayson/promise','client','http','request','then','info','ChatQueue,\x20%s,\x20%s','debug','ChatQueue,\x20%s,\x20%s,\x20%s','error','code','message','request\x20sent','catch','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','reject','update','get','destroy','stack','name','send','map','ChatQueue','fieldName','key','model','query','keys','filters','attributes','intersection','fields'];(function(_0x389ebe,_0x37984f){var _0xad4009=function(_0x4d67e7){while(--_0x4d67e7){_0x389ebe['push'](_0x389ebe['shift']());}};_0xad4009(++_0x37984f);}(_0xacd5,0x174));var _0x5acd=function(_0x3f9a64,_0x224930){_0x3f9a64=_0x3f9a64-0x0;var _0x353b88=_0xacd5[_0x3f9a64];return _0x353b88;};'use strict';var emlformat=require(_0x5acd('0x0'));var rimraf=require(_0x5acd('0x1'));var zipdir=require(_0x5acd('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x5acd('0x3'));var moment=require(_0x5acd('0x4'));var BPromise=require(_0x5acd('0x5'));var Mustache=require(_0x5acd('0x6'));var util=require(_0x5acd('0x7'));var path=require(_0x5acd('0x8'));var sox=require(_0x5acd('0x9'));var csv=require(_0x5acd('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x5acd('0xb'));var crypto=require('crypto');var jsforce=require(_0x5acd('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x5acd('0xd'));var Redis=require(_0x5acd('0xe'));var authService=require(_0x5acd('0xf'));var qs=require(_0x5acd('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5acd('0x11'));var logger=require(_0x5acd('0x12'))('api');var utils=require(_0x5acd('0x13'));var config=require(_0x5acd('0x14'));var licenseUtil=require(_0x5acd('0x15'));var db=require(_0x5acd('0x16'))['db'];config[_0x5acd('0x17')]=_['defaults'](config[_0x5acd('0x17')],{'host':_0x5acd('0x18'),'port':0x18eb});var socket=require(_0x5acd('0x19'))(new Redis(config[_0x5acd('0x17')]));require(_0x5acd('0x1a'))[_0x5acd('0x1b')](socket);var jayson=require(_0x5acd('0x1c'));var client=jayson[_0x5acd('0x1d')][_0x5acd('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x237a36,_0x3018ba,_0x5a0d4e,_0x3a27c4){return new BPromise(function(_0x4968c1,_0x364e2d){var _0x2d8551=_0x3a27c4||client;return _0x2d8551[_0x5acd('0x1f')](_0x237a36,_0x5a0d4e)[_0x5acd('0x20')](function(_0x52f885){logger[_0x5acd('0x21')](_0x5acd('0x22'),_0x3018ba,'request\x20sent');logger[_0x5acd('0x23')](_0x5acd('0x24'),_0x3018ba,'request\x20sent',JSON['stringify'](_0x52f885));if(_0x52f885['error']){if(_0x52f885[_0x5acd('0x25')][_0x5acd('0x26')]===0x1f4){logger[_0x5acd('0x25')](_0x5acd('0x22'),_0x3018ba,_0x52f885['error'][_0x5acd('0x27')]);return _0x364e2d(_0x52f885[_0x5acd('0x25')][_0x5acd('0x27')]);}logger[_0x5acd('0x25')](_0x5acd('0x22'),_0x3018ba,_0x52f885[_0x5acd('0x25')]['message']);return _0x4968c1(_0x52f885[_0x5acd('0x25')]['message']);}else{logger[_0x5acd('0x21')](_0x5acd('0x22'),_0x3018ba,_0x5acd('0x28'));_0x4968c1(_0x52f885['result'][_0x5acd('0x27')]);}})[_0x5acd('0x29')](function(_0x4de296){logger['error']('ChatQueue,\x20%s,\x20%s',_0x3018ba,_0x4de296);_0x364e2d(_0x4de296);});});}function respondWithStatusCode(_0x3ba2ea,_0x175c3c){_0x175c3c=_0x175c3c||0xcc;return function(_0x294d13){if(_0x294d13){return _0x3ba2ea[_0x5acd('0x2a')](_0x175c3c);}return _0x3ba2ea[_0x5acd('0x2b')](_0x175c3c)[_0x5acd('0x2c')]();};}function respondWithResult(_0x10f6f7,_0x1b85c9){_0x1b85c9=_0x1b85c9||0xc8;return function(_0x155625){if(_0x155625){return _0x10f6f7[_0x5acd('0x2b')](_0x1b85c9)[_0x5acd('0x2d')](_0x155625);}};}function respondWithFilteredResult(_0xe0eae4,_0x13fa6b){return function(_0x3ee85c){if(_0x3ee85c){var _0x38bf8b=_0x3ee85c['count'],_0x16b2c1=_0x13fa6b[_0x5acd('0x2e')],_0x11a458=_0x13fa6b[_0x5acd('0x2e')]+_0x13fa6b[_0x5acd('0x2f')],_0x389dcb;if(_0x11a458>=_0x38bf8b){_0x11a458=_0x38bf8b;_0x389dcb=0xc8;}else{_0x389dcb=0xce;}_0xe0eae4['status'](_0x389dcb);return _0xe0eae4[_0x5acd('0x30')](_0x5acd('0x31'),_0x16b2c1+'-'+_0x11a458+'/'+_0x38bf8b)['json'](_0x3ee85c);}return null;};}function patchUpdates(_0x2f10f9){return function(_0x1eccda){try{jsonpatch[_0x5acd('0x32')](_0x1eccda,_0x2f10f9,!![]);}catch(_0x38bdd5){return BPromise[_0x5acd('0x33')](_0x38bdd5);}return _0x1eccda['save']();};}function saveUpdates(_0x22facb,_0x24829f){return function(_0x9141f4){if(_0x9141f4){return _0x9141f4[_0x5acd('0x34')](_0x22facb)[_0x5acd('0x20')](function(_0x4b7d61){return _0x4b7d61;});}return null;};}function removeEntity(_0x11f5b0,_0x105d85){return function(_0x5825eb){if(_0x5825eb){return _0x5825eb['destroy']()[_0x5acd('0x20')](function(){var _0x3f542f=_0x5825eb[_0x5acd('0x35')]({'plain':!![]});var _0xb68d72='ChatQueues';return db['UserProfileResource'][_0x5acd('0x36')]({'where':{'type':_0xb68d72,'resourceId':_0x3f542f['id']}})[_0x5acd('0x20')](function(){return _0x5825eb;});})[_0x5acd('0x20')](function(){_0x11f5b0[_0x5acd('0x2b')](0xcc)[_0x5acd('0x2c')]();});}};}function handleEntityNotFound(_0x4210fb,_0x3b040a){return function(_0x2d6efb){if(!_0x2d6efb){_0x4210fb[_0x5acd('0x2a')](0x194);}return _0x2d6efb;};}function handleError(_0x1bc96a,_0xe647bc){_0xe647bc=_0xe647bc||0x1f4;return function(_0xb4a6c1){logger['error'](_0xb4a6c1[_0x5acd('0x37')]);if(_0xb4a6c1[_0x5acd('0x38')]){delete _0xb4a6c1['name'];}_0x1bc96a['status'](_0xe647bc)[_0x5acd('0x39')](_0xb4a6c1);};}exports['index']=function(_0x3ee921,_0x57d39d){var _0x5ae8d5={},_0x1bb138={},_0x52b445={'count':0x0,'rows':[]};var _0x4d7db5=_[_0x5acd('0x3a')](db[_0x5acd('0x3b')]['rawAttributes'],function(_0x5b015c){return{'name':_0x5b015c[_0x5acd('0x3c')],'type':_0x5b015c['type'][_0x5acd('0x3d')]};});_0x1bb138[_0x5acd('0x3e')]=_[_0x5acd('0x3a')](_0x4d7db5,_0x5acd('0x38'));_0x1bb138[_0x5acd('0x3f')]=_[_0x5acd('0x40')](_0x3ee921['query']);_0x1bb138[_0x5acd('0x41')]=_['intersection'](_0x1bb138[_0x5acd('0x3e')],_0x1bb138[_0x5acd('0x3f')]);_0x5ae8d5[_0x5acd('0x42')]=_[_0x5acd('0x43')](_0x1bb138['model'],qs['fields'](_0x3ee921[_0x5acd('0x3f')][_0x5acd('0x44')]));_0x5ae8d5['attributes']=_0x5ae8d5[_0x5acd('0x42')]['length']?_0x5ae8d5[_0x5acd('0x42')]:_0x1bb138[_0x5acd('0x3e')];if(!_0x3ee921['query'][_0x5acd('0x45')](_0x5acd('0x46'))){_0x5ae8d5[_0x5acd('0x2f')]=qs['limit'](_0x3ee921['query']['limit']);_0x5ae8d5[_0x5acd('0x2e')]=qs[_0x5acd('0x2e')](_0x3ee921[_0x5acd('0x3f')][_0x5acd('0x2e')]);}_0x5ae8d5[_0x5acd('0x47')]=qs['sort'](_0x3ee921[_0x5acd('0x3f')][_0x5acd('0x48')]);_0x5ae8d5[_0x5acd('0x49')]=qs[_0x5acd('0x41')](_['pick'](_0x3ee921[_0x5acd('0x3f')],_0x1bb138[_0x5acd('0x41')]),_0x4d7db5);if(_0x3ee921[_0x5acd('0x3f')][_0x5acd('0x4a')]){_0x5ae8d5[_0x5acd('0x49')]=_[_0x5acd('0x4b')](_0x5ae8d5[_0x5acd('0x49')],{'$or':_['map'](_0x4d7db5,function(_0x30f27b){if(_0x30f27b[_0x5acd('0x4c')]!=='VIRTUAL'){var _0x368b34={};_0x368b34[_0x30f27b[_0x5acd('0x38')]]={'$like':'%'+_0x3ee921[_0x5acd('0x3f')]['filter']+'%'};return _0x368b34;}})});}_0x5ae8d5=_[_0x5acd('0x4b')]({},_0x5ae8d5,_0x3ee921[_0x5acd('0x4d')]);var _0x29a179={'where':_0x5ae8d5[_0x5acd('0x49')]};return db[_0x5acd('0x3b')][_0x5acd('0x4e')](_0x29a179)['then'](function(_0x24611f){_0x52b445['count']=_0x24611f;if(_0x3ee921[_0x5acd('0x3f')]['includeAll']){_0x5ae8d5['include']=[{'all':!![]}];}return db['ChatQueue'][_0x5acd('0x4f')](_0x5ae8d5);})[_0x5acd('0x20')](function(_0x145c0d){_0x52b445[_0x5acd('0x50')]=_0x145c0d;return _0x52b445;})[_0x5acd('0x20')](respondWithFilteredResult(_0x57d39d,_0x5ae8d5))['catch'](handleError(_0x57d39d,null));};exports[_0x5acd('0x51')]=function(_0x38781b,_0x1a58b0){var _0xb49262={'raw':!![],'where':{'id':_0x38781b[_0x5acd('0x52')]['id']}},_0x39f08a={};_0x39f08a[_0x5acd('0x3e')]=_[_0x5acd('0x40')](db['ChatQueue'][_0x5acd('0x53')]);_0x39f08a[_0x5acd('0x3f')]=_[_0x5acd('0x40')](_0x38781b[_0x5acd('0x3f')]);_0x39f08a[_0x5acd('0x41')]=_[_0x5acd('0x43')](_0x39f08a[_0x5acd('0x3e')],_0x39f08a['query']);_0xb49262[_0x5acd('0x42')]=_[_0x5acd('0x43')](_0x39f08a[_0x5acd('0x3e')],qs[_0x5acd('0x44')](_0x38781b[_0x5acd('0x3f')][_0x5acd('0x44')]));_0xb49262['attributes']=_0xb49262[_0x5acd('0x42')][_0x5acd('0x54')]?_0xb49262[_0x5acd('0x42')]:_0x39f08a[_0x5acd('0x3e')];if(_0x38781b[_0x5acd('0x3f')]['includeAll']){_0xb49262[_0x5acd('0x55')]=[{'all':!![]}];}_0xb49262=_[_0x5acd('0x4b')]({},_0xb49262,_0x38781b[_0x5acd('0x4d')]);return db[_0x5acd('0x3b')][_0x5acd('0x56')](_0xb49262)[_0x5acd('0x20')](handleEntityNotFound(_0x1a58b0,null))['then'](respondWithResult(_0x1a58b0,null))[_0x5acd('0x29')](handleError(_0x1a58b0,null));};exports[_0x5acd('0x57')]=function(_0x3ae5de,_0x28fa5e){return db[_0x5acd('0x3b')][_0x5acd('0x57')](_0x3ae5de[_0x5acd('0x58')],{})[_0x5acd('0x20')](function(_0x599859){var _0x306fe6=_0x3ae5de['user'][_0x5acd('0x35')]({'plain':!![]});if(!_0x306fe6)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x306fe6[_0x5acd('0x59')]===_0x5acd('0x5a')){var _0x322fb8=_0x599859[_0x5acd('0x35')]({'plain':!![]});var _0x2f0f3f=_0x5acd('0x5b');return db[_0x5acd('0x5c')]['find']({'where':{'name':_0x2f0f3f,'userProfileId':_0x306fe6[_0x5acd('0x5d')]},'raw':!![]})['then'](function(_0x4261d8){if(_0x4261d8&&_0x4261d8[_0x5acd('0x5e')]===0x0){return db['UserProfileResource']['create']({'name':_0x322fb8[_0x5acd('0x38')],'resourceId':_0x322fb8['id'],'type':_0x4261d8[_0x5acd('0x38')],'sectionId':_0x4261d8['id']},{})[_0x5acd('0x20')](function(){return _0x599859;});}else{return _0x599859;}})[_0x5acd('0x29')](function(_0x1e5d46){logger[_0x5acd('0x25')](_0x5acd('0x5f'),_0x1e5d46);throw _0x1e5d46;});}return _0x599859;})['then'](respondWithResult(_0x28fa5e,0xc9))['catch'](handleError(_0x28fa5e,null));};exports[_0x5acd('0x34')]=function(_0x408e2a,_0x1437e1){if(_0x408e2a['body']['id']){delete _0x408e2a[_0x5acd('0x58')]['id'];}return db[_0x5acd('0x3b')]['find']({'where':{'id':_0x408e2a[_0x5acd('0x52')]['id']}})['then'](handleEntityNotFound(_0x1437e1,null))[_0x5acd('0x20')](saveUpdates(_0x408e2a['body'],null))[_0x5acd('0x20')](respondWithResult(_0x1437e1,null))[_0x5acd('0x29')](handleError(_0x1437e1,null));};exports[_0x5acd('0x36')]=function(_0x36cee1,_0x5c004c){return db[_0x5acd('0x3b')]['find']({'where':{'id':_0x36cee1[_0x5acd('0x52')]['id']}})['then'](handleEntityNotFound(_0x5c004c,null))[_0x5acd('0x20')](removeEntity(_0x5c004c,null))[_0x5acd('0x29')](handleError(_0x5c004c,null));};exports[_0x5acd('0x60')]=function(_0x4d4c7c,_0x905873){return db[_0x5acd('0x3b')]['describe']()[_0x5acd('0x20')](respondWithResult(_0x905873,null))['catch'](handleError(_0x905873,null));};exports[_0x5acd('0x61')]=function(_0x53f964,_0x14eab7,_0xff8039){var _0x27b532={'raw':!![],'where':{}},_0xaa8edb={},_0x28d032;return db['ChatQueue']['findOne']({'where':{'id':_0x53f964[_0x5acd('0x52')]['id']}})['then'](handleEntityNotFound(_0x14eab7,null))['then'](function(_0x49a43e){if(_0x49a43e){_0x28d032=_0x49a43e[_0x5acd('0x35')]({'plain':!![]});_0xaa8edb['model']=_[_0x5acd('0x40')](db['UserChatQueue'][_0x5acd('0x53')]);_0xaa8edb['query']=_[_0x5acd('0x40')](_0x53f964[_0x5acd('0x3f')]);_0xaa8edb['filters']=_[_0x5acd('0x43')](_0xaa8edb['model'],_0xaa8edb[_0x5acd('0x3f')]);_0x27b532[_0x5acd('0x42')]=_[_0x5acd('0x43')](_0xaa8edb[_0x5acd('0x3e')],qs[_0x5acd('0x44')](_0x53f964[_0x5acd('0x3f')]['fields']));_0x27b532[_0x5acd('0x42')]=_0x27b532['attributes'][_0x5acd('0x54')]?_0x27b532[_0x5acd('0x42')]:_0xaa8edb[_0x5acd('0x3e')];if(!_0x53f964[_0x5acd('0x3f')][_0x5acd('0x45')](_0x5acd('0x46'))){_0x27b532[_0x5acd('0x2f')]=qs['limit'](_0x53f964[_0x5acd('0x3f')]['limit']);_0x27b532[_0x5acd('0x2e')]=qs[_0x5acd('0x2e')](_0x53f964[_0x5acd('0x3f')]['offset']);}_0x27b532[_0x5acd('0x47')]=qs[_0x5acd('0x48')](_0x53f964[_0x5acd('0x3f')][_0x5acd('0x48')]);_0x27b532['where']=qs[_0x5acd('0x41')](_[_0x5acd('0x62')](_0x53f964[_0x5acd('0x3f')],_0xaa8edb[_0x5acd('0x41')]));_0x27b532[_0x5acd('0x49')]['ChatQueueId']=_0x49a43e['id'];if(_0x53f964['query'][_0x5acd('0x4a')]){_0x27b532[_0x5acd('0x49')]=_['merge'](_0x27b532[_0x5acd('0x49')],{'$or':_[_0x5acd('0x3a')](_0x27b532['attributes'],function(_0x2523cd){var _0x34d425={};_0x34d425[_0x2523cd]={'$like':'%'+_0x53f964['query'][_0x5acd('0x4a')]+'%'};return _0x34d425;})});}_0x27b532=_[_0x5acd('0x4b')]({},_0x27b532,_0x53f964[_0x5acd('0x4d')]);return db[_0x5acd('0x63')][_0x5acd('0x4f')](_0x27b532);}})[_0x5acd('0x20')](function(_0x253131){if(_0x253131){return db[_0x5acd('0x64')][_0x5acd('0x65')]({'where':{'id':_[_0x5acd('0x3a')](_0x253131,_0x5acd('0x66')),'role':_0x5acd('0x67')},'attributes':['id','name','chatPause',_0x5acd('0x68'),_0x5acd('0x69')]});}})[_0x5acd('0x20')](function(_0x35728d){if(_0x35728d){return{'count':_0x35728d[_0x5acd('0x4e')],'rows':_[_0x5acd('0x3a')](_0x35728d[_0x5acd('0x50')],function(_0x2a667c){return{'membername':_0x2a667c[_0x5acd('0x38')],'UserId':_0x2a667c['id'],'queue_name':_0x28d032[_0x5acd('0x38')],'ChatQueueId':_0x28d032['id'],'interface':util[_0x5acd('0x6a')](_0x5acd('0x6b'),'SIP',_0x2a667c[_0x5acd('0x38')]),'penalty':0x0,'paused':_0x2a667c[_0x5acd('0x6c')],'createdAt':_0x2a667c[_0x5acd('0x69')],'updatedAt':_0x2a667c[_0x5acd('0x68')]};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x14eab7,_0x27b532))[_0x5acd('0x29')](handleError(_0x14eab7,null));};exports['getTeams']=function(_0x3dcc40,_0x2f2a3e,_0x51d030){var _0x415274={};var _0x3bea72={};var _0x65c19c;var _0x585de7;return db['ChatQueue']['findOne']({'where':{'id':_0x3dcc40[_0x5acd('0x52')]['id']}})['then'](handleEntityNotFound(_0x2f2a3e,null))['then'](function(_0x943fbf){if(_0x943fbf){_0x65c19c=_0x943fbf;_0x3bea72['model']=_[_0x5acd('0x40')](db['Team'][_0x5acd('0x53')]);_0x3bea72['query']=_[_0x5acd('0x40')](_0x3dcc40[_0x5acd('0x3f')]);_0x3bea72[_0x5acd('0x41')]=_[_0x5acd('0x43')](_0x3bea72[_0x5acd('0x3e')],_0x3bea72[_0x5acd('0x3f')]);_0x415274[_0x5acd('0x42')]=_['intersection'](_0x3bea72['model'],qs[_0x5acd('0x44')](_0x3dcc40['query'][_0x5acd('0x44')]));_0x415274[_0x5acd('0x42')]=_0x415274[_0x5acd('0x42')][_0x5acd('0x54')]?_0x415274[_0x5acd('0x42')]:_0x3bea72[_0x5acd('0x3e')];_0x415274['order']=qs[_0x5acd('0x48')](_0x3dcc40[_0x5acd('0x3f')]['sort']);_0x415274['where']=qs[_0x5acd('0x41')](_['pick'](_0x3dcc40[_0x5acd('0x3f')],_0x3bea72['filters']));if(_0x3dcc40[_0x5acd('0x3f')][_0x5acd('0x4a')]){_0x415274[_0x5acd('0x49')]=_['merge'](_0x415274[_0x5acd('0x49')],{'$or':_['map'](_0x415274['attributes'],function(_0xda24a3){var _0x4c0c4d={};_0x4c0c4d[_0xda24a3]={'$like':'%'+_0x3dcc40[_0x5acd('0x3f')][_0x5acd('0x4a')]+'%'};return _0x4c0c4d;})});}_0x415274=_['merge']({},_0x415274,_0x3dcc40[_0x5acd('0x4d')]);return _0x65c19c['getTeams'](_0x415274);}})[_0x5acd('0x20')](function(_0x850061){if(_0x850061){_0x585de7=_0x850061['length'];if(!_0x3dcc40[_0x5acd('0x3f')][_0x5acd('0x45')](_0x5acd('0x46'))){_0x415274[_0x5acd('0x2f')]=qs[_0x5acd('0x2f')](_0x3dcc40[_0x5acd('0x3f')][_0x5acd('0x2f')]);_0x415274['offset']=qs[_0x5acd('0x2e')](_0x3dcc40['query'][_0x5acd('0x2e')]);}return _0x65c19c['getTeams'](_0x415274);}})[_0x5acd('0x20')](function(_0xad905b){if(_0xad905b){return _0xad905b?{'count':_0x585de7,'rows':_0xad905b}:null;}})['then'](respondWithResult(_0x2f2a3e,null))['catch'](handleError(_0x2f2a3e,null));};exports['addTeams']=function(_0x3a52cd,_0x22dfe4,_0x1243fa){var _0x2c17d3=_0x3a52cd['body']['ids'];return db['Team'][_0x5acd('0x4f')]({'where':{'id':_0x2c17d3},'attributes':['id'],'include':[{'model':db['User'],'as':_0x5acd('0x6d'),'attributes':['id','name',_0x5acd('0x6e'),_0x5acd('0x6f'),_0x5acd('0x70')],'raw':!![]}]})['then'](function(_0x2f5335){if(_0x2f5335){var _0x4c1d7d=_['flatMap'](_0x2f5335,function(_0x6d24df){var _0x33c27b=_0x6d24df['get']({'plain':!![]});return _0x33c27b[_0x5acd('0x6d')];});return db['ChatQueue']['find']({'where':{'id':_0x3a52cd[_0x5acd('0x52')]['id']}})[_0x5acd('0x20')](function(_0x3845bf){return db[_0x5acd('0x71')][_0x5acd('0x72')](function(_0x561c8d){return _0x3845bf[_0x5acd('0x73')](_0x2c17d3,{'transaction':_0x561c8d})['then'](function(){return BPromise[_0x5acd('0x74')](_0x4c1d7d,function(_0xec1b1e){return db[_0x5acd('0x63')][_0x5acd('0x75')]({'where':{'UserId':_0xec1b1e['id'],'ChatQueueId':_0x3a52cd['params']['id']},'transaction':_0x561c8d});});})[_0x5acd('0x20')](function(){_0x4c1d7d[_0x5acd('0x76')](function(_0x85af4e){socket[_0x5acd('0x77')](_0x5acd('0x78'),{'UserId':_0x85af4e['id'],'ChatQueueId':_0x3845bf['id']});});});});});}})[_0x5acd('0x20')](respondWithStatusCode(_0x22dfe4,null))[_0x5acd('0x29')](handleError(_0x22dfe4,null));};exports['removeTeams']=function(_0x3687a5,_0x171ff9,_0x1ea327){return db[_0x5acd('0x79')][_0x5acd('0x4f')]({'where':{'id':_0x3687a5[_0x5acd('0x3f')][_0x5acd('0x7a')]},'attributes':['id'],'include':[{'model':db[_0x5acd('0x64')],'as':_0x5acd('0x6d'),'attributes':['id'],'raw':!![]}]})[_0x5acd('0x20')](handleEntityNotFound(_0x171ff9,null))['then'](function(_0x29bca8){var _0x34fa49=_[_0x5acd('0x3a')](_0x29bca8,'id');var _0x3f4b4a=[];var _0x31ab0e=[];var _0x54b0d0=squel[_0x5acd('0x7b')]();_0x54b0d0[_0x5acd('0x7c')](_0x5acd('0x7d'))[_0x5acd('0x7e')](_0x5acd('0x7f'),'tq')[_0x5acd('0x80')](_0x5acd('0x81'),'ut',_0x5acd('0x82'))['where'](_0x5acd('0x83'),_0x3687a5['params']['id']);for(var _0x312e4f=0x0;_0x312e4f<_0x29bca8['length'];_0x312e4f+=0x1){let _0x5524b9=_0x29bca8[_0x312e4f];for(var _0x32183c=0x0;_0x32183c<_0x5524b9[_0x5acd('0x6d')][_0x5acd('0x54')];_0x32183c+=0x1){let _0x86e94b=_0x5524b9['Agents'][_0x32183c];var _0x2fb085=_0x54b0d0[_0x5acd('0x84')]();_0x2fb085[_0x5acd('0x49')]('ut.UserId\x20=\x20?',_0x86e94b['id']);_0x31ab0e[_0x5acd('0x85')](db[_0x5acd('0x71')]['query'](_0x2fb085[_0x5acd('0x86')](),{'type':db[_0x5acd('0x71')]['QueryTypes']['SELECT']})['then'](function(_0x37c639){if(_0x37c639[_0x5acd('0x54')]===0x1){return _0x86e94b['id'];}else{var _0x2364ca=_[_0x5acd('0x87')](_[_0x5acd('0x3a')](_0x37c639,'TeamId'),function(_0x24d596){return _[_0x5acd('0x88')](_0x34fa49,_0x24d596);});if(_0x2364ca){return _0x86e94b['id'];}}}));}}return BPromise[_0x5acd('0x89')](_0x31ab0e)[_0x5acd('0x20')](function(_0x46ee22){_0x3f4b4a=_(_0x3f4b4a)[_0x5acd('0x8a')](_0x46ee22)[_0x5acd('0x8b')]()[_0x5acd('0x8c')]();return db[_0x5acd('0x3b')][_0x5acd('0x56')]({'where':{'id':_0x3687a5[_0x5acd('0x52')]['id']}})[_0x5acd('0x20')](function(_0x2b7540){return db['sequelize'][_0x5acd('0x72')](function(_0x31929a){return _0x2b7540['removeTeams'](_0x3687a5['query']['ids'],{'transaction':_0x31929a})['then'](function(){if(!_['isEmpty'](_0x3f4b4a)){return _0x2b7540[_0x5acd('0x8d')](_0x3f4b4a,{'transaction':_0x31929a});}})[_0x5acd('0x20')](function(){_0x3f4b4a['forEach'](function(_0xf33b19){socket[_0x5acd('0x77')](_0x5acd('0x8e'),{'UserId':_0xf33b19,'ChatQueueId':_0x2b7540['id']});});});});});});})[_0x5acd('0x20')](respondWithStatusCode(_0x171ff9,null))[_0x5acd('0x29')](handleError(_0x171ff9,null));};exports[_0x5acd('0x8f')]=function(_0x2c4690,_0x51cc27,_0x2f2dc5){return db[_0x5acd('0x3b')][_0x5acd('0x56')]({'where':{'id':_0x2c4690['params']['id']}})['then'](handleEntityNotFound(_0x51cc27,null))[_0x5acd('0x20')](function(_0x72607c){if(_0x72607c){return _0x72607c[_0x5acd('0x8f')](_0x2c4690[_0x5acd('0x58')][_0x5acd('0x7a')],_['omit'](_0x2c4690[_0x5acd('0x58')],[_0x5acd('0x7a'),'id'])||{})[_0x5acd('0x90')](function(_0x5c5bde){for(var _0x2ef8e6=0x0;_0x2ef8e6<_0x2c4690[_0x5acd('0x58')][_0x5acd('0x7a')][_0x5acd('0x54')];_0x2ef8e6+=0x1){socket[_0x5acd('0x77')](_0x5acd('0x78'),{'UserId':_0x2c4690['body'][_0x5acd('0x7a')][_0x2ef8e6],'ChatQueueId':_0x2c4690[_0x5acd('0x52')]['id']});}return _0x5c5bde;});}})[_0x5acd('0x20')](respondWithResult(_0x51cc27,null))[_0x5acd('0x29')](handleError(_0x51cc27,null));};exports[_0x5acd('0x8d')]=function(_0x242f83,_0x2168ee,_0x1bd82d){return db[_0x5acd('0x3b')]['find']({'where':{'id':_0x242f83[_0x5acd('0x52')]['id']}})[_0x5acd('0x20')](handleEntityNotFound(_0x2168ee,null))[_0x5acd('0x20')](function(_0x3054d9){if(_0x3054d9){return _0x3054d9[_0x5acd('0x8d')](_0x242f83['query'][_0x5acd('0x7a')])[_0x5acd('0x20')](function(){if(_[_0x5acd('0x91')](_0x242f83[_0x5acd('0x3f')][_0x5acd('0x7a')])){for(var _0x108a41=0x0;_0x108a41<_0x242f83[_0x5acd('0x3f')]['ids'][_0x5acd('0x54')];_0x108a41+=0x1){socket[_0x5acd('0x77')]('userChatQueue:remove',{'UserId':Number(_0x242f83['query'][_0x5acd('0x7a')][_0x108a41]),'ChatQueueId':Number(_0x242f83[_0x5acd('0x52')]['id'])});}}else{socket[_0x5acd('0x77')]('userChatQueue:remove',{'UserId':Number(_0x242f83['query'][_0x5acd('0x7a')]),'ChatQueueId':Number(_0x242f83['params']['id'])});}});}})[_0x5acd('0x20')](respondWithStatusCode(_0x2168ee,null))[_0x5acd('0x29')](handleError(_0x2168ee,null));};exports['getAgents']=function(_0x2ce8fb,_0x2900c9,_0x46ee8b){var _0x32a84c={};var _0xe34c70={};var _0x469294;var _0x58b690;return db[_0x5acd('0x3b')]['findOne']({'where':{'id':_0x2ce8fb[_0x5acd('0x52')]['id']}})[_0x5acd('0x20')](handleEntityNotFound(_0x2900c9,null))['then'](function(_0x5cfbf7){if(_0x5cfbf7){_0x469294=_0x5cfbf7;_0xe34c70['model']=_[_0x5acd('0x40')](db[_0x5acd('0x64')][_0x5acd('0x53')]);_0xe34c70[_0x5acd('0x3f')]=_[_0x5acd('0x40')](_0x2ce8fb['query']);_0xe34c70['filters']=_[_0x5acd('0x43')](_0xe34c70[_0x5acd('0x3e')],_0xe34c70[_0x5acd('0x3f')]);_0x32a84c[_0x5acd('0x42')]=_[_0x5acd('0x43')](_0xe34c70[_0x5acd('0x3e')],qs[_0x5acd('0x44')](_0x2ce8fb['query'][_0x5acd('0x44')]));_0x32a84c[_0x5acd('0x42')]=_0x32a84c['attributes'][_0x5acd('0x54')]?_0x32a84c[_0x5acd('0x42')]:_0xe34c70['model'];_0x32a84c[_0x5acd('0x47')]=qs[_0x5acd('0x48')](_0x2ce8fb['query']['sort']);_0x32a84c['where']=qs[_0x5acd('0x41')](_[_0x5acd('0x62')](_0x2ce8fb[_0x5acd('0x3f')],_0xe34c70[_0x5acd('0x41')]));if(_0x2ce8fb[_0x5acd('0x3f')][_0x5acd('0x4a')]){_0x32a84c[_0x5acd('0x49')]=_[_0x5acd('0x4b')](_0x32a84c[_0x5acd('0x49')],{'$or':_['map'](_0x32a84c[_0x5acd('0x42')],function(_0x1c8959){var _0x46ab74={};_0x46ab74[_0x1c8959]={'$like':'%'+_0x2ce8fb['query'][_0x5acd('0x4a')]+'%'};return _0x46ab74;})});}_0x32a84c=_[_0x5acd('0x4b')]({},_0x32a84c,_0x2ce8fb['options']);return _0x469294['getAgents'](_0x32a84c);}})['then'](function(_0x4f36fa){if(_0x4f36fa){_0x58b690=_0x4f36fa[_0x5acd('0x54')];if(!_0x2ce8fb[_0x5acd('0x3f')]['hasOwnProperty'](_0x5acd('0x46'))){_0x32a84c[_0x5acd('0x2f')]=qs['limit'](_0x2ce8fb['query'][_0x5acd('0x2f')]);_0x32a84c[_0x5acd('0x2e')]=qs[_0x5acd('0x2e')](_0x2ce8fb['query']['offset']);}return _0x469294[_0x5acd('0x92')](_0x32a84c);}})['then'](function(_0x4bba93){if(_0x4bba93){return _0x4bba93?{'count':_0x58b690,'rows':_0x4bba93}:null;}})[_0x5acd('0x20')](respondWithResult(_0x2900c9,null))[_0x5acd('0x29')](handleError(_0x2900c9,null));};
\ No newline at end of file
+var _0x7b3b=['voicePause','flatMap','sequelize','transaction','forEach','emit','removeTeams','field','tq.TeamId','from','team_has_chat_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','all','removeAgents','addAgents','spread','userChatQueue:save','getAgents','hasOwnProperty','bluebird','util','lodash','squel','ioredis','../../components/parsers/qs','api','../../config/environment','redis','defaults','localhost','socket.io-emitter','register','status','end','json','offset','undefined','limit','count','set','Content-Range','update','destroy','then','get','ChatQueues','error','stack','name','send','index','map','ChatQueue','rawAttributes','type','key','getOptions','where','include','query','catch','params','model','keys','filters','intersection','attributes','length','merge','options','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','findOne','UserChatQueue','fields','nolimit','order','sort','pick','ChatQueueId','filter','findAll','User','UserId','agent','chatPause','updatedAt','createdAt','rows','format','%s/%s','SIP','getTeams','Team','addTeams','ids','Agents','online'];(function(_0x24d8ec,_0x5f1552){var _0x409280=function(_0x3d085b){while(--_0x3d085b){_0x24d8ec['push'](_0x24d8ec['shift']());}};_0x409280(++_0x5f1552);}(_0x7b3b,0x92));var _0xb7b3=function(_0x23fa2a,_0x3816a3){_0x23fa2a=_0x23fa2a-0x0;var _0x783fba=_0x7b3b[_0x23fa2a];return _0x783fba;};'use strict';var BPromise=require(_0xb7b3('0x0'));var util=require(_0xb7b3('0x1'));var _=require(_0xb7b3('0x2'));var squel=require(_0xb7b3('0x3'));var Redis=require(_0xb7b3('0x4'));var qs=require(_0xb7b3('0x5'));var logger=require('../../config/logger')(_0xb7b3('0x6'));var config=require(_0xb7b3('0x7'));var db=require('../../mysqldb')['db'];config[_0xb7b3('0x8')]=_[_0xb7b3('0x9')](config[_0xb7b3('0x8')],{'host':_0xb7b3('0xa'),'port':0x18eb});var socket=require(_0xb7b3('0xb'))(new Redis(config[_0xb7b3('0x8')]));require('./chatQueue.socket')[_0xb7b3('0xc')](socket);function respondWithStatusCode(_0x187639,_0x202d7e){_0x202d7e=_0x202d7e||0xcc;return function(_0x4a000a){if(_0x4a000a){return _0x187639['sendStatus'](_0x202d7e);}return _0x187639[_0xb7b3('0xd')](_0x202d7e)[_0xb7b3('0xe')]();};}function respondWithResult(_0x58ad4c,_0x46a558){_0x46a558=_0x46a558||0xc8;return function(_0x2e1acd){if(_0x2e1acd){return _0x58ad4c[_0xb7b3('0xd')](_0x46a558)[_0xb7b3('0xf')](_0x2e1acd);}};}function respondWithFilteredResult(_0x281146,_0x4ce771){return function(_0x5e950e){if(_0x5e950e){var _0x2650fc=typeof _0x4ce771[_0xb7b3('0x10')]===_0xb7b3('0x11')&&typeof _0x4ce771[_0xb7b3('0x12')]==='undefined';var _0x21b5fe=_0x5e950e['count'];var _0x2bee56=_0x2650fc?0x0:_0x4ce771[_0xb7b3('0x10')];var _0x5780ec=_0x2650fc?_0x5e950e[_0xb7b3('0x13')]:_0x4ce771[_0xb7b3('0x10')]+_0x4ce771['limit'];var _0x279a15;if(_0x5780ec>=_0x21b5fe){_0x5780ec=_0x21b5fe;_0x279a15=0xc8;}else{_0x279a15=0xce;}_0x281146['status'](_0x279a15);return _0x281146[_0xb7b3('0x14')](_0xb7b3('0x15'),_0x2bee56+'-'+_0x5780ec+'/'+_0x21b5fe)[_0xb7b3('0xf')](_0x5e950e);}return null;};}function saveUpdates(_0x22f42e){return function(_0x3e85ce){if(_0x3e85ce){return _0x3e85ce[_0xb7b3('0x16')](_0x22f42e)['then'](function(_0x2086c3){return _0x2086c3;});}return null;};}function removeEntity(_0x381d18){return function(_0x28c4be){if(_0x28c4be){return _0x28c4be[_0xb7b3('0x17')]()[_0xb7b3('0x18')](function(){var _0x3ebfea=_0x28c4be[_0xb7b3('0x19')]({'plain':!![]});var _0xc0e079=_0xb7b3('0x1a');return db['UserProfileResource'][_0xb7b3('0x17')]({'where':{'type':_0xc0e079,'resourceId':_0x3ebfea['id']}})[_0xb7b3('0x18')](function(){return _0x28c4be;});})[_0xb7b3('0x18')](function(){_0x381d18[_0xb7b3('0xd')](0xcc)[_0xb7b3('0xe')]();});}};}function handleEntityNotFound(_0xae4788){return function(_0x524e72){if(!_0x524e72){_0xae4788['sendStatus'](0x194);}return _0x524e72;};}function handleError(_0x2271ad,_0x18cba1){_0x18cba1=_0x18cba1||0x1f4;return function(_0x261634){logger[_0xb7b3('0x1b')](_0x261634[_0xb7b3('0x1c')]);if(_0x261634[_0xb7b3('0x1d')]){delete _0x261634[_0xb7b3('0x1d')];}_0x2271ad[_0xb7b3('0xd')](_0x18cba1)[_0xb7b3('0x1e')](_0x261634);};}exports[_0xb7b3('0x1f')]=function(_0x27fd41,_0x1b5ce5){var _0x4e8ccb={};var _0x2dc648={'count':0x0,'rows':[]};var _0x58222a=_[_0xb7b3('0x20')](db[_0xb7b3('0x21')][_0xb7b3('0x22')],function(_0xd0bea4){return{'name':_0xd0bea4['fieldName'],'type':_0xd0bea4[_0xb7b3('0x23')][_0xb7b3('0x24')]};});_0x4e8ccb=qs[_0xb7b3('0x25')](_0x58222a,_0x27fd41);var _0x18b938={'where':_0x4e8ccb[_0xb7b3('0x26')]};return db[_0xb7b3('0x21')]['count'](_0x18b938)['then'](function(_0x5612b8){_0x2dc648[_0xb7b3('0x13')]=_0x5612b8;_0x4e8ccb['include']=qs[_0xb7b3('0x27')](_0x27fd41[_0xb7b3('0x28')]);return db['ChatQueue']['findAll'](_0x4e8ccb);})[_0xb7b3('0x18')](function(_0x5f19cc){_0x2dc648['rows']=_0x5f19cc;return _0x2dc648;})[_0xb7b3('0x18')](respondWithFilteredResult(_0x1b5ce5,_0x4e8ccb))[_0xb7b3('0x29')](handleError(_0x1b5ce5,null));};exports['show']=function(_0x102c7f,_0xef5975){var _0x3d858e={'raw':!![],'where':{'id':_0x102c7f[_0xb7b3('0x2a')]['id']}},_0x53d006={};_0x53d006[_0xb7b3('0x2b')]=_[_0xb7b3('0x2c')](db['ChatQueue'][_0xb7b3('0x22')]);_0x53d006[_0xb7b3('0x28')]=_[_0xb7b3('0x2c')](_0x102c7f[_0xb7b3('0x28')]);_0x53d006[_0xb7b3('0x2d')]=_[_0xb7b3('0x2e')](_0x53d006[_0xb7b3('0x2b')],_0x53d006[_0xb7b3('0x28')]);_0x3d858e[_0xb7b3('0x2f')]=_[_0xb7b3('0x2e')](_0x53d006['model'],qs['fields'](_0x102c7f['query']['fields']));_0x3d858e[_0xb7b3('0x2f')]=_0x3d858e[_0xb7b3('0x2f')][_0xb7b3('0x30')]?_0x3d858e[_0xb7b3('0x2f')]:_0x53d006[_0xb7b3('0x2b')];if(_0x102c7f[_0xb7b3('0x28')]['includeAll']){_0x3d858e[_0xb7b3('0x27')]=[{'all':!![]}];}_0x3d858e=_[_0xb7b3('0x31')]({},_0x3d858e,_0x102c7f[_0xb7b3('0x32')]);return db[_0xb7b3('0x21')][_0xb7b3('0x33')](_0x3d858e)['then'](handleEntityNotFound(_0xef5975,null))[_0xb7b3('0x18')](respondWithResult(_0xef5975,null))[_0xb7b3('0x29')](handleError(_0xef5975,null));};exports['create']=function(_0xa6615c,_0x6c473e){return db[_0xb7b3('0x21')][_0xb7b3('0x34')](_0xa6615c[_0xb7b3('0x35')],{})[_0xb7b3('0x18')](function(_0x24c940){var _0x3e4cd5=_0xa6615c['user']['get']({'plain':!![]});if(!_0x3e4cd5)throw new Error(_0xb7b3('0x36'));if(_0x3e4cd5[_0xb7b3('0x37')]===_0xb7b3('0x38')){var _0x5a2075=_0x24c940[_0xb7b3('0x19')]({'plain':!![]});var _0xe7f5a8='ChatQueues';return db['UserProfileSection']['find']({'where':{'name':_0xe7f5a8,'userProfileId':_0x3e4cd5[_0xb7b3('0x39')]},'raw':!![]})[_0xb7b3('0x18')](function(_0x446fc7){if(_0x446fc7&&_0x446fc7[_0xb7b3('0x3a')]===0x0){return db[_0xb7b3('0x3b')][_0xb7b3('0x34')]({'name':_0x5a2075[_0xb7b3('0x1d')],'resourceId':_0x5a2075['id'],'type':_0x446fc7[_0xb7b3('0x1d')],'sectionId':_0x446fc7['id']},{})[_0xb7b3('0x18')](function(){return _0x24c940;});}else{return _0x24c940;}})['catch'](function(_0x4219a4){logger[_0xb7b3('0x1b')](_0xb7b3('0x3c'),_0x4219a4);throw _0x4219a4;});}return _0x24c940;})['then'](respondWithResult(_0x6c473e,0xc9))[_0xb7b3('0x29')](handleError(_0x6c473e,null));};exports['update']=function(_0x45ee14,_0x27d95f){if(_0x45ee14[_0xb7b3('0x35')]['id']){delete _0x45ee14[_0xb7b3('0x35')]['id'];}return db[_0xb7b3('0x21')][_0xb7b3('0x33')]({'where':{'id':_0x45ee14['params']['id']}})[_0xb7b3('0x18')](handleEntityNotFound(_0x27d95f,null))[_0xb7b3('0x18')](saveUpdates(_0x45ee14[_0xb7b3('0x35')],null))['then'](respondWithResult(_0x27d95f,null))['catch'](handleError(_0x27d95f,null));};exports[_0xb7b3('0x17')]=function(_0x273c2d,_0x4aa25a){return db['ChatQueue'][_0xb7b3('0x33')]({'where':{'id':_0x273c2d[_0xb7b3('0x2a')]['id']}})[_0xb7b3('0x18')](handleEntityNotFound(_0x4aa25a,null))[_0xb7b3('0x18')](removeEntity(_0x4aa25a,null))[_0xb7b3('0x29')](handleError(_0x4aa25a,null));};exports[_0xb7b3('0x3d')]=function(_0x53454d,_0x1b1936){return db[_0xb7b3('0x21')][_0xb7b3('0x3d')]()[_0xb7b3('0x18')](respondWithResult(_0x1b1936,null))[_0xb7b3('0x29')](handleError(_0x1b1936,null));};exports['getMembers']=function(_0x300009,_0x16ad16){var _0x9899cf={'raw':!![],'where':{}},_0x5b429a={},_0x355b7f;return db[_0xb7b3('0x21')][_0xb7b3('0x3e')]({'where':{'id':_0x300009[_0xb7b3('0x2a')]['id']}})[_0xb7b3('0x18')](handleEntityNotFound(_0x16ad16,null))[_0xb7b3('0x18')](function(_0x56c874){if(_0x56c874){_0x355b7f=_0x56c874['get']({'plain':!![]});_0x5b429a[_0xb7b3('0x2b')]=_[_0xb7b3('0x2c')](db[_0xb7b3('0x3f')][_0xb7b3('0x22')]);_0x5b429a['query']=_['keys'](_0x300009[_0xb7b3('0x28')]);_0x5b429a[_0xb7b3('0x2d')]=_[_0xb7b3('0x2e')](_0x5b429a[_0xb7b3('0x2b')],_0x5b429a[_0xb7b3('0x28')]);_0x9899cf[_0xb7b3('0x2f')]=_['intersection'](_0x5b429a[_0xb7b3('0x2b')],qs[_0xb7b3('0x40')](_0x300009[_0xb7b3('0x28')][_0xb7b3('0x40')]));_0x9899cf[_0xb7b3('0x2f')]=_0x9899cf[_0xb7b3('0x2f')][_0xb7b3('0x30')]?_0x9899cf[_0xb7b3('0x2f')]:_0x5b429a[_0xb7b3('0x2b')];if(!_0x300009['query']['hasOwnProperty'](_0xb7b3('0x41'))){_0x9899cf['limit']=qs['limit'](_0x300009[_0xb7b3('0x28')]['limit']);_0x9899cf[_0xb7b3('0x10')]=qs[_0xb7b3('0x10')](_0x300009['query'][_0xb7b3('0x10')]);}_0x9899cf[_0xb7b3('0x42')]=qs[_0xb7b3('0x43')](_0x300009[_0xb7b3('0x28')][_0xb7b3('0x43')]);_0x9899cf[_0xb7b3('0x26')]=qs[_0xb7b3('0x2d')](_[_0xb7b3('0x44')](_0x300009[_0xb7b3('0x28')],_0x5b429a[_0xb7b3('0x2d')]));_0x9899cf['where'][_0xb7b3('0x45')]=_0x56c874['id'];if(_0x300009['query'][_0xb7b3('0x46')]){_0x9899cf[_0xb7b3('0x26')]=_[_0xb7b3('0x31')](_0x9899cf['where'],{'$or':_[_0xb7b3('0x20')](_0x9899cf['attributes'],function(_0x370392){var _0x5d9e2c={};_0x5d9e2c[_0x370392]={'$like':'%'+_0x300009[_0xb7b3('0x28')][_0xb7b3('0x46')]+'%'};return _0x5d9e2c;})});}_0x9899cf=_[_0xb7b3('0x31')]({},_0x9899cf,_0x300009[_0xb7b3('0x32')]);return db[_0xb7b3('0x3f')][_0xb7b3('0x47')](_0x9899cf);}})[_0xb7b3('0x18')](function(_0x552415){if(_0x552415){return db[_0xb7b3('0x48')]['findAndCountAll']({'where':{'id':_['map'](_0x552415,_0xb7b3('0x49')),'role':_0xb7b3('0x4a')},'attributes':['id',_0xb7b3('0x1d'),_0xb7b3('0x4b'),_0xb7b3('0x4c'),_0xb7b3('0x4d')]});}})[_0xb7b3('0x18')](function(_0x1c6797){if(_0x1c6797){return{'count':_0x1c6797[_0xb7b3('0x13')],'rows':_['map'](_0x1c6797[_0xb7b3('0x4e')],function(_0x2bb5b1){return{'membername':_0x2bb5b1[_0xb7b3('0x1d')],'UserId':_0x2bb5b1['id'],'queue_name':_0x355b7f[_0xb7b3('0x1d')],'ChatQueueId':_0x355b7f['id'],'interface':util[_0xb7b3('0x4f')](_0xb7b3('0x50'),_0xb7b3('0x51'),_0x2bb5b1[_0xb7b3('0x1d')]),'penalty':0x0,'paused':_0x2bb5b1[_0xb7b3('0x4b')],'createdAt':_0x2bb5b1[_0xb7b3('0x4d')],'updatedAt':_0x2bb5b1[_0xb7b3('0x4c')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xb7b3('0x18')](respondWithFilteredResult(_0x16ad16,_0x9899cf))[_0xb7b3('0x29')](handleError(_0x16ad16,null));};exports[_0xb7b3('0x52')]=function(_0x44bc4b,_0x40a7f9){var _0x2fdbe5={};var _0x3d9ce5={};var _0x293c83;var _0x633055;return db['ChatQueue'][_0xb7b3('0x3e')]({'where':{'id':_0x44bc4b[_0xb7b3('0x2a')]['id']}})[_0xb7b3('0x18')](handleEntityNotFound(_0x40a7f9,null))[_0xb7b3('0x18')](function(_0x2ca86d){if(_0x2ca86d){_0x293c83=_0x2ca86d;_0x3d9ce5[_0xb7b3('0x2b')]=_[_0xb7b3('0x2c')](db[_0xb7b3('0x53')]['rawAttributes']);_0x3d9ce5['query']=_[_0xb7b3('0x2c')](_0x44bc4b[_0xb7b3('0x28')]);_0x3d9ce5[_0xb7b3('0x2d')]=_[_0xb7b3('0x2e')](_0x3d9ce5['model'],_0x3d9ce5[_0xb7b3('0x28')]);_0x2fdbe5['attributes']=_['intersection'](_0x3d9ce5[_0xb7b3('0x2b')],qs[_0xb7b3('0x40')](_0x44bc4b[_0xb7b3('0x28')][_0xb7b3('0x40')]));_0x2fdbe5[_0xb7b3('0x2f')]=_0x2fdbe5[_0xb7b3('0x2f')][_0xb7b3('0x30')]?_0x2fdbe5[_0xb7b3('0x2f')]:_0x3d9ce5['model'];_0x2fdbe5['order']=qs[_0xb7b3('0x43')](_0x44bc4b[_0xb7b3('0x28')][_0xb7b3('0x43')]);_0x2fdbe5['where']=qs['filters'](_[_0xb7b3('0x44')](_0x44bc4b[_0xb7b3('0x28')],_0x3d9ce5[_0xb7b3('0x2d')]));if(_0x44bc4b[_0xb7b3('0x28')]['filter']){_0x2fdbe5[_0xb7b3('0x26')]=_['merge'](_0x2fdbe5['where'],{'$or':_['map'](_0x2fdbe5[_0xb7b3('0x2f')],function(_0x3c05a6){var _0x5f6362={};_0x5f6362[_0x3c05a6]={'$like':'%'+_0x44bc4b['query'][_0xb7b3('0x46')]+'%'};return _0x5f6362;})});}_0x2fdbe5=_[_0xb7b3('0x31')]({},_0x2fdbe5,_0x44bc4b[_0xb7b3('0x32')]);return _0x293c83[_0xb7b3('0x52')](_0x2fdbe5);}})[_0xb7b3('0x18')](function(_0x4ad27d){if(_0x4ad27d){_0x633055=_0x4ad27d[_0xb7b3('0x30')];if(!_0x44bc4b[_0xb7b3('0x28')]['hasOwnProperty']('nolimit')){_0x2fdbe5[_0xb7b3('0x12')]=qs['limit'](_0x44bc4b[_0xb7b3('0x28')][_0xb7b3('0x12')]);_0x2fdbe5['offset']=qs[_0xb7b3('0x10')](_0x44bc4b[_0xb7b3('0x28')][_0xb7b3('0x10')]);}return _0x293c83['getTeams'](_0x2fdbe5);}})[_0xb7b3('0x18')](function(_0x10df96){if(_0x10df96){return _0x10df96?{'count':_0x633055,'rows':_0x10df96}:null;}})[_0xb7b3('0x18')](respondWithResult(_0x40a7f9,null))[_0xb7b3('0x29')](handleError(_0x40a7f9,null));};exports[_0xb7b3('0x54')]=function(_0x44cb51,_0x2afb57){var _0x19006a=_0x44cb51['body'][_0xb7b3('0x55')];return db[_0xb7b3('0x53')][_0xb7b3('0x47')]({'where':{'id':_0x19006a},'attributes':['id'],'include':[{'model':db[_0xb7b3('0x48')],'as':_0xb7b3('0x56'),'attributes':['id',_0xb7b3('0x1d'),_0xb7b3('0x57'),_0xb7b3('0x58'),'interface'],'raw':!![]}]})['then'](function(_0x2618ea){if(_0x2618ea){var _0x4fa4d5=_[_0xb7b3('0x59')](_0x2618ea,function(_0x270be7){var _0x367418=_0x270be7[_0xb7b3('0x19')]({'plain':!![]});return _0x367418[_0xb7b3('0x56')];});return db[_0xb7b3('0x21')][_0xb7b3('0x33')]({'where':{'id':_0x44cb51[_0xb7b3('0x2a')]['id']}})[_0xb7b3('0x18')](function(_0x1d4f86){return db[_0xb7b3('0x5a')][_0xb7b3('0x5b')](function(_0x265bfd){return _0x1d4f86['addTeams'](_0x19006a,{'transaction':_0x265bfd})[_0xb7b3('0x18')](function(){return BPromise['each'](_0x4fa4d5,function(_0x39de53){return db[_0xb7b3('0x3f')]['findOrCreate']({'where':{'UserId':_0x39de53['id'],'ChatQueueId':_0x44cb51[_0xb7b3('0x2a')]['id']},'transaction':_0x265bfd});});})[_0xb7b3('0x18')](function(){_0x4fa4d5[_0xb7b3('0x5c')](function(_0x5e2943){socket[_0xb7b3('0x5d')]('userChatQueue:save',{'UserId':_0x5e2943['id'],'ChatQueueId':_0x1d4f86['id']});});});});});}})[_0xb7b3('0x18')](respondWithStatusCode(_0x2afb57,null))[_0xb7b3('0x29')](handleError(_0x2afb57,null));};exports[_0xb7b3('0x5e')]=function(_0x4f7461,_0xd56f49){return db['Team'][_0xb7b3('0x47')]({'where':{'id':_0x4f7461[_0xb7b3('0x28')]['ids']},'attributes':['id'],'include':[{'model':db[_0xb7b3('0x48')],'as':_0xb7b3('0x56'),'attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0xd56f49,null))[_0xb7b3('0x18')](function(_0x389fac){var _0x23bf90=_[_0xb7b3('0x20')](_0x389fac,'id');var _0x4e7f24=[];var _0x5c6b27=[];var _0x2e383c=squel['select']();_0x2e383c[_0xb7b3('0x5f')](_0xb7b3('0x60'))[_0xb7b3('0x61')](_0xb7b3('0x62'),'tq')[_0xb7b3('0x63')](_0xb7b3('0x64'),'ut',_0xb7b3('0x65'))[_0xb7b3('0x26')](_0xb7b3('0x66'),_0x4f7461['params']['id']);for(var _0x4b46f5=0x0;_0x4b46f5<_0x389fac['length'];_0x4b46f5+=0x1){let _0x2e1ae3=_0x389fac[_0x4b46f5];for(var _0x4dec0a=0x0;_0x4dec0a<_0x2e1ae3[_0xb7b3('0x56')]['length'];_0x4dec0a+=0x1){let _0x17ffee=_0x2e1ae3['Agents'][_0x4dec0a];var _0x41eb65=_0x2e383c['clone']();_0x41eb65[_0xb7b3('0x26')]('ut.UserId\x20=\x20?',_0x17ffee['id']);_0x5c6b27[_0xb7b3('0x67')](db[_0xb7b3('0x5a')][_0xb7b3('0x28')](_0x41eb65[_0xb7b3('0x68')](),{'type':db[_0xb7b3('0x5a')][_0xb7b3('0x69')][_0xb7b3('0x6a')]})['then'](function(_0x47a65a){if(_0x47a65a[_0xb7b3('0x30')]===0x1){return _0x17ffee['id'];}else{var _0x2be45a=_[_0xb7b3('0x6b')](_[_0xb7b3('0x20')](_0x47a65a,_0xb7b3('0x6c')),function(_0x3583b2){return _[_0xb7b3('0x6d')](_0x23bf90,_0x3583b2);});if(_0x2be45a){return _0x17ffee['id'];}}}));}}return BPromise[_0xb7b3('0x6e')](_0x5c6b27)[_0xb7b3('0x18')](function(_0x25d8bd){_0x4e7f24=_(_0x4e7f24)['union'](_0x25d8bd)['compact']()['value']();return db[_0xb7b3('0x21')][_0xb7b3('0x33')]({'where':{'id':_0x4f7461[_0xb7b3('0x2a')]['id']}})['then'](function(_0x20f337){return db['sequelize'][_0xb7b3('0x5b')](function(_0x400032){return _0x20f337[_0xb7b3('0x5e')](_0x4f7461[_0xb7b3('0x28')][_0xb7b3('0x55')],{'transaction':_0x400032})[_0xb7b3('0x18')](function(){if(!_['isEmpty'](_0x4e7f24)){return _0x20f337[_0xb7b3('0x6f')](_0x4e7f24,{'transaction':_0x400032});}})[_0xb7b3('0x18')](function(){_0x4e7f24[_0xb7b3('0x5c')](function(_0x43a2bf){socket[_0xb7b3('0x5d')]('userChatQueue:remove',{'UserId':_0x43a2bf,'ChatQueueId':_0x20f337['id']});});});});});});})[_0xb7b3('0x18')](respondWithStatusCode(_0xd56f49,null))[_0xb7b3('0x29')](handleError(_0xd56f49,null));};exports['addAgents']=function(_0x4f2e10,_0x17332d){return db[_0xb7b3('0x21')]['find']({'where':{'id':_0x4f2e10[_0xb7b3('0x2a')]['id']}})[_0xb7b3('0x18')](handleEntityNotFound(_0x17332d,null))[_0xb7b3('0x18')](function(_0x2d23d6){if(_0x2d23d6){return _0x2d23d6[_0xb7b3('0x70')](_0x4f2e10['body']['ids'],_['omit'](_0x4f2e10['body'],['ids','id'])||{})[_0xb7b3('0x71')](function(_0x31d5d9){for(var _0x13cd15=0x0;_0x13cd15<_0x4f2e10[_0xb7b3('0x35')][_0xb7b3('0x55')][_0xb7b3('0x30')];_0x13cd15+=0x1){socket[_0xb7b3('0x5d')](_0xb7b3('0x72'),{'UserId':Number(_0x4f2e10[_0xb7b3('0x35')]['ids'][_0x13cd15]),'ChatQueueId':Number(_0x4f2e10['params']['id'])});}return _0x31d5d9;});}})['then'](respondWithResult(_0x17332d,null))['catch'](handleError(_0x17332d,null));};exports[_0xb7b3('0x6f')]=function(_0x239445,_0x5ed5e5){return db[_0xb7b3('0x21')][_0xb7b3('0x33')]({'where':{'id':_0x239445[_0xb7b3('0x2a')]['id']}})['then'](handleEntityNotFound(_0x5ed5e5,null))[_0xb7b3('0x18')](function(_0x292b07){if(_0x292b07){return _0x292b07[_0xb7b3('0x6f')](_0x239445[_0xb7b3('0x28')][_0xb7b3('0x55')])['then'](function(){if(_['isArray'](_0x239445['query'][_0xb7b3('0x55')])){for(var _0x4f7ec3=0x0;_0x4f7ec3<_0x239445[_0xb7b3('0x28')][_0xb7b3('0x55')][_0xb7b3('0x30')];_0x4f7ec3+=0x1){socket[_0xb7b3('0x5d')]('userChatQueue:remove',{'UserId':Number(_0x239445[_0xb7b3('0x28')][_0xb7b3('0x55')][_0x4f7ec3]),'ChatQueueId':Number(_0x239445['params']['id'])});}}else{socket[_0xb7b3('0x5d')]('userChatQueue:remove',{'UserId':Number(_0x239445[_0xb7b3('0x28')][_0xb7b3('0x55')]),'ChatQueueId':Number(_0x239445['params']['id'])});}});}})['then'](respondWithStatusCode(_0x5ed5e5,null))[_0xb7b3('0x29')](handleError(_0x5ed5e5,null));};exports[_0xb7b3('0x73')]=function(_0x525e23,_0xb37a68){var _0x54adff={};var _0x1b4f42={};var _0x576079;var _0xea55b;return db[_0xb7b3('0x21')]['findOne']({'where':{'id':_0x525e23[_0xb7b3('0x2a')]['id']}})['then'](handleEntityNotFound(_0xb37a68,null))[_0xb7b3('0x18')](function(_0x12b4c5){if(_0x12b4c5){_0x576079=_0x12b4c5;_0x1b4f42['model']=_[_0xb7b3('0x2c')](db['User'][_0xb7b3('0x22')]);_0x1b4f42[_0xb7b3('0x28')]=_[_0xb7b3('0x2c')](_0x525e23['query']);_0x1b4f42[_0xb7b3('0x2d')]=_['intersection'](_0x1b4f42[_0xb7b3('0x2b')],_0x1b4f42[_0xb7b3('0x28')]);_0x54adff[_0xb7b3('0x2f')]=_[_0xb7b3('0x2e')](_0x1b4f42[_0xb7b3('0x2b')],qs['fields'](_0x525e23[_0xb7b3('0x28')][_0xb7b3('0x40')]));_0x54adff[_0xb7b3('0x2f')]=_0x54adff['attributes'][_0xb7b3('0x30')]?_0x54adff[_0xb7b3('0x2f')]:_0x1b4f42['model'];_0x54adff['order']=qs[_0xb7b3('0x43')](_0x525e23[_0xb7b3('0x28')][_0xb7b3('0x43')]);_0x54adff[_0xb7b3('0x26')]=qs[_0xb7b3('0x2d')](_[_0xb7b3('0x44')](_0x525e23[_0xb7b3('0x28')],_0x1b4f42[_0xb7b3('0x2d')]));if(_0x525e23[_0xb7b3('0x28')][_0xb7b3('0x46')]){_0x54adff[_0xb7b3('0x26')]=_[_0xb7b3('0x31')](_0x54adff['where'],{'$or':_['map'](_0x54adff[_0xb7b3('0x2f')],function(_0x4696c7){var _0x6e3f63={};_0x6e3f63[_0x4696c7]={'$like':'%'+_0x525e23[_0xb7b3('0x28')][_0xb7b3('0x46')]+'%'};return _0x6e3f63;})});}_0x54adff=_['merge']({},_0x54adff,_0x525e23['options']);return _0x576079[_0xb7b3('0x73')](_0x54adff);}})[_0xb7b3('0x18')](function(_0x19c3d3){if(_0x19c3d3){_0xea55b=_0x19c3d3[_0xb7b3('0x30')];if(!_0x525e23['query'][_0xb7b3('0x74')]('nolimit')){_0x54adff['limit']=qs[_0xb7b3('0x12')](_0x525e23[_0xb7b3('0x28')]['limit']);_0x54adff[_0xb7b3('0x10')]=qs['offset'](_0x525e23[_0xb7b3('0x28')][_0xb7b3('0x10')]);}return _0x576079['getAgents'](_0x54adff);}})[_0xb7b3('0x18')](function(_0xf97ab8){if(_0xf97ab8){return _0xf97ab8?{'count':_0xea55b,'rows':_0xf97ab8}:null;}})[_0xb7b3('0x18')](respondWithResult(_0xb37a68,null))[_0xb7b3('0x29')](handleError(_0xb37a68,null));};
\ No newline at end of file