Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / api / chatQueue / chatQueue.controller.js
index 75f53af..94b5de3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb680=['rows','show','params','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','get','UserProfileSection','find','autoAssociation','describe','getMembers','findOne','keys','UserChatQueue','nolimit','ChatQueueId','findAndCountAll','UserId','agent','chatPause','%s/%s','SIP','createdAt','updatedAt','getTeams','hasOwnProperty','addTeams','ids','Team','online','voicePause','flatMap','Agents','each','findOrCreate','forEach','emit','userChatQueue:save','removeTeams','User','select','tq.TeamId','team_has_chat_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','every','TeamId','includes','all','union','compact','value','sequelize','transaction','isEmpty','removeAgents','userChatQueue:remove','addAgents','spread','getAgents','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','squel','crypto','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatQueue.socket','register','jayson/promise','client','http','then','debug','ChatQueue,\x20%s,\x20%s,\x20%s','request\x20sent','code','error','ChatQueue,\x20%s,\x20%s','message','info','result','catch','sendStatus','status','end','count','offset','limit','set','Content-Range','json','apply','reject','update','ChatQueues','UserProfileResource','destroy','stack','name','send','map','ChatQueue','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll'];(function(_0x58a4ac,_0x26f3e7){var _0x435e2d=function(_0x1a5660){while(--_0x1a5660){_0x58a4ac['push'](_0x58a4ac['shift']());}};_0x435e2d(++_0x26f3e7);}(_0xb680,0x177));var _0x0b68=function(_0x871ef5,_0x58880b){_0x871ef5=_0x871ef5-0x0;var _0x1f62ea=_0xb680[_0x871ef5];return _0x1f62ea;};'use strict';var pdf=require(_0x0b68('0x0'));var emlformat=require(_0x0b68('0x1'));var rimraf=require(_0x0b68('0x2'));var zipdir=require(_0x0b68('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x0b68('0x4'));var moment=require(_0x0b68('0x5'));var BPromise=require(_0x0b68('0x6'));var Mustache=require(_0x0b68('0x7'));var util=require(_0x0b68('0x8'));var path=require('path');var sox=require(_0x0b68('0x9'));var csv=require(_0x0b68('0xa'));var ejs=require(_0x0b68('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0x0b68('0xc'));var crypto=require(_0x0b68('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x0b68('0xa'));var querystring=require(_0x0b68('0xe'));var Papa=require(_0x0b68('0xf'));var Redis=require(_0x0b68('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x0b68('0x11'));var as=require(_0x0b68('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x0b68('0x13'))(_0x0b68('0x14'));var utils=require(_0x0b68('0x15'));var config=require(_0x0b68('0x16'));var licenseUtil=require(_0x0b68('0x17'));var db=require(_0x0b68('0x18'))['db'];config[_0x0b68('0x19')]=_[_0x0b68('0x1a')](config['redis'],{'host':_0x0b68('0x1b'),'port':0x18eb});var socket=require(_0x0b68('0x1c'))(new Redis(config[_0x0b68('0x19')]));require(_0x0b68('0x1d'))[_0x0b68('0x1e')](socket);var jayson=require(_0x0b68('0x1f'));var client=jayson[_0x0b68('0x20')][_0x0b68('0x21')]({'port':0x232a});function respondWithRpcPromise(_0x307c99,_0x90b9a5,_0x10a434,_0x297377){return new BPromise(function(_0x5a77b1,_0x27fd5c){var _0x3dd613=_0x297377||client;return _0x3dd613['request'](_0x307c99,_0x10a434)[_0x0b68('0x22')](function(_0x147f6c){logger['info']('ChatQueue,\x20%s,\x20%s',_0x90b9a5,'request\x20sent');logger[_0x0b68('0x23')](_0x0b68('0x24'),_0x90b9a5,_0x0b68('0x25'),JSON['stringify'](_0x147f6c));if(_0x147f6c['error']){if(_0x147f6c['error'][_0x0b68('0x26')]===0x1f4){logger[_0x0b68('0x27')](_0x0b68('0x28'),_0x90b9a5,_0x147f6c[_0x0b68('0x27')][_0x0b68('0x29')]);return _0x27fd5c(_0x147f6c[_0x0b68('0x27')][_0x0b68('0x29')]);}logger['error'](_0x0b68('0x28'),_0x90b9a5,_0x147f6c[_0x0b68('0x27')]['message']);return _0x5a77b1(_0x147f6c[_0x0b68('0x27')][_0x0b68('0x29')]);}else{logger[_0x0b68('0x2a')]('ChatQueue,\x20%s,\x20%s',_0x90b9a5,_0x0b68('0x25'));_0x5a77b1(_0x147f6c[_0x0b68('0x2b')][_0x0b68('0x29')]);}})[_0x0b68('0x2c')](function(_0x16ac28){logger[_0x0b68('0x27')](_0x0b68('0x28'),_0x90b9a5,_0x16ac28);_0x27fd5c(_0x16ac28);});});}function respondWithStatusCode(_0x1b31de,_0x52fca7){_0x52fca7=_0x52fca7||0xcc;return function(_0x5637b6){if(_0x5637b6){return _0x1b31de[_0x0b68('0x2d')](_0x52fca7);}return _0x1b31de[_0x0b68('0x2e')](_0x52fca7)[_0x0b68('0x2f')]();};}function respondWithResult(_0xb754fc,_0x16b6e5){_0x16b6e5=_0x16b6e5||0xc8;return function(_0x2ffabc){if(_0x2ffabc){return _0xb754fc[_0x0b68('0x2e')](_0x16b6e5)['json'](_0x2ffabc);}};}function respondWithFilteredResult(_0x4e6652,_0x330a34){return function(_0x22d08c){if(_0x22d08c){var _0x20bad7=_0x22d08c[_0x0b68('0x30')],_0x16efb9=_0x330a34[_0x0b68('0x31')],_0x3d8fb7=_0x330a34[_0x0b68('0x31')]+_0x330a34[_0x0b68('0x32')],_0x1d734f;if(_0x3d8fb7>=_0x20bad7){_0x3d8fb7=_0x20bad7;_0x1d734f=0xc8;}else{_0x1d734f=0xce;}_0x4e6652[_0x0b68('0x2e')](_0x1d734f);return _0x4e6652[_0x0b68('0x33')](_0x0b68('0x34'),_0x16efb9+'-'+_0x3d8fb7+'/'+_0x20bad7)[_0x0b68('0x35')](_0x22d08c);}return null;};}function patchUpdates(_0x40198d){return function(_0x5b3068){try{jsonpatch[_0x0b68('0x36')](_0x5b3068,_0x40198d,!![]);}catch(_0x2025a5){return BPromise[_0x0b68('0x37')](_0x2025a5);}return _0x5b3068['save']();};}function saveUpdates(_0x259b0f,_0x4201e0){return function(_0x5ba379){if(_0x5ba379){return _0x5ba379[_0x0b68('0x38')](_0x259b0f)[_0x0b68('0x22')](function(_0xddaa43){return _0xddaa43;});}return null;};}function removeEntity(_0x534a19,_0x577aba){return function(_0x3cb5bb){if(_0x3cb5bb){return _0x3cb5bb['destroy']()[_0x0b68('0x22')](function(){var _0x2062f3=_0x3cb5bb['get']({'plain':!![]});var _0x5c20ab=_0x0b68('0x39');return db[_0x0b68('0x3a')][_0x0b68('0x3b')]({'where':{'type':_0x5c20ab,'resourceId':_0x2062f3['id']}})[_0x0b68('0x22')](function(){return _0x3cb5bb;});})[_0x0b68('0x22')](function(){_0x534a19[_0x0b68('0x2e')](0xcc)[_0x0b68('0x2f')]();});}};}function handleEntityNotFound(_0x25b22d,_0x1a2ef1){return function(_0x444ef0){if(!_0x444ef0){_0x25b22d[_0x0b68('0x2d')](0x194);}return _0x444ef0;};}function handleError(_0x279f06,_0x10656a){_0x10656a=_0x10656a||0x1f4;return function(_0x57c69d){logger['error'](_0x57c69d[_0x0b68('0x3c')]);if(_0x57c69d['name']){delete _0x57c69d[_0x0b68('0x3d')];}_0x279f06[_0x0b68('0x2e')](_0x10656a)[_0x0b68('0x3e')](_0x57c69d);};}exports['index']=function(_0x3ad6d9,_0xab3bc9){var _0x227a3f={},_0x240543={},_0x4e26d0={'count':0x0,'rows':[]};var _0x3bc96c=_[_0x0b68('0x3f')](db[_0x0b68('0x40')][_0x0b68('0x41')],function(_0x5281a5){return{'name':_0x5281a5[_0x0b68('0x42')],'type':_0x5281a5[_0x0b68('0x43')][_0x0b68('0x44')]};});_0x240543['model']=_[_0x0b68('0x3f')](_0x3bc96c,_0x0b68('0x3d'));_0x240543['query']=_['keys'](_0x3ad6d9[_0x0b68('0x45')]);_0x240543[_0x0b68('0x46')]=_[_0x0b68('0x47')](_0x240543[_0x0b68('0x48')],_0x240543[_0x0b68('0x45')]);_0x227a3f[_0x0b68('0x49')]=_[_0x0b68('0x47')](_0x240543[_0x0b68('0x48')],qs[_0x0b68('0x4a')](_0x3ad6d9[_0x0b68('0x45')][_0x0b68('0x4a')]));_0x227a3f[_0x0b68('0x49')]=_0x227a3f[_0x0b68('0x49')][_0x0b68('0x4b')]?_0x227a3f[_0x0b68('0x49')]:_0x240543[_0x0b68('0x48')];if(!_0x3ad6d9[_0x0b68('0x45')]['hasOwnProperty']('nolimit')){_0x227a3f[_0x0b68('0x32')]=qs[_0x0b68('0x32')](_0x3ad6d9['query'][_0x0b68('0x32')]);_0x227a3f[_0x0b68('0x31')]=qs[_0x0b68('0x31')](_0x3ad6d9[_0x0b68('0x45')][_0x0b68('0x31')]);}_0x227a3f[_0x0b68('0x4c')]=qs['sort'](_0x3ad6d9['query'][_0x0b68('0x4d')]);_0x227a3f[_0x0b68('0x4e')]=qs[_0x0b68('0x46')](_[_0x0b68('0x4f')](_0x3ad6d9[_0x0b68('0x45')],_0x240543[_0x0b68('0x46')]),_0x3bc96c);if(_0x3ad6d9[_0x0b68('0x45')][_0x0b68('0x50')]){_0x227a3f[_0x0b68('0x4e')]=_[_0x0b68('0x51')](_0x227a3f[_0x0b68('0x4e')],{'$or':_['map'](_0x3bc96c,function(_0x425571){if(_0x425571[_0x0b68('0x43')]!==_0x0b68('0x52')){var _0x1c23b6={};_0x1c23b6[_0x425571[_0x0b68('0x3d')]]={'$like':'%'+_0x3ad6d9[_0x0b68('0x45')][_0x0b68('0x50')]+'%'};return _0x1c23b6;}})});}_0x227a3f=_['merge']({},_0x227a3f,_0x3ad6d9[_0x0b68('0x53')]);var _0x15bef4={'where':_0x227a3f[_0x0b68('0x4e')]};return db[_0x0b68('0x40')][_0x0b68('0x30')](_0x15bef4)[_0x0b68('0x22')](function(_0x21cbec){_0x4e26d0[_0x0b68('0x30')]=_0x21cbec;if(_0x3ad6d9[_0x0b68('0x45')][_0x0b68('0x54')]){_0x227a3f[_0x0b68('0x55')]=[{'all':!![]}];}return db[_0x0b68('0x40')][_0x0b68('0x56')](_0x227a3f);})[_0x0b68('0x22')](function(_0x3189ea){_0x4e26d0[_0x0b68('0x57')]=_0x3189ea;return _0x4e26d0;})['then'](respondWithFilteredResult(_0xab3bc9,_0x227a3f))['catch'](handleError(_0xab3bc9,null));};exports[_0x0b68('0x58')]=function(_0xaa6d53,_0x1d9557){var _0x462cf5={'raw':!![],'where':{'id':_0xaa6d53[_0x0b68('0x59')]['id']}},_0x501fac={};_0x501fac[_0x0b68('0x48')]=_['keys'](db[_0x0b68('0x40')][_0x0b68('0x41')]);_0x501fac[_0x0b68('0x45')]=_['keys'](_0xaa6d53[_0x0b68('0x45')]);_0x501fac[_0x0b68('0x46')]=_[_0x0b68('0x47')](_0x501fac[_0x0b68('0x48')],_0x501fac[_0x0b68('0x45')]);_0x462cf5[_0x0b68('0x49')]=_['intersection'](_0x501fac[_0x0b68('0x48')],qs['fields'](_0xaa6d53[_0x0b68('0x45')]['fields']));_0x462cf5[_0x0b68('0x49')]=_0x462cf5[_0x0b68('0x49')][_0x0b68('0x4b')]?_0x462cf5['attributes']:_0x501fac[_0x0b68('0x48')];if(_0xaa6d53[_0x0b68('0x45')][_0x0b68('0x54')]){_0x462cf5[_0x0b68('0x55')]=[{'all':!![]}];}_0x462cf5=_[_0x0b68('0x51')]({},_0x462cf5,_0xaa6d53[_0x0b68('0x53')]);return db[_0x0b68('0x40')]['find'](_0x462cf5)[_0x0b68('0x22')](handleEntityNotFound(_0x1d9557,null))[_0x0b68('0x22')](respondWithResult(_0x1d9557,null))[_0x0b68('0x2c')](handleError(_0x1d9557,null));};exports[_0x0b68('0x5a')]=function(_0x34eff4,_0xd3a2e1){return db[_0x0b68('0x40')]['create'](_0x34eff4[_0x0b68('0x5b')],{})[_0x0b68('0x22')](function(_0x59b1f9){var _0x5b858f=_0x34eff4[_0x0b68('0x5c')]['get']({'plain':!![]});if(!_0x5b858f)throw new Error(_0x0b68('0x5d'));if(_0x5b858f['role']===_0x0b68('0x5c')){var _0x24498a=_0x59b1f9[_0x0b68('0x5e')]({'plain':!![]});var _0x591f89=_0x0b68('0x39');return db[_0x0b68('0x5f')][_0x0b68('0x60')]({'where':{'name':_0x591f89,'userProfileId':_0x5b858f['userProfileId']},'raw':!![]})['then'](function(_0x328476){if(_0x328476&&_0x328476[_0x0b68('0x61')]===0x0){return db[_0x0b68('0x3a')]['create']({'name':_0x24498a['name'],'resourceId':_0x24498a['id'],'type':_0x328476[_0x0b68('0x3d')],'sectionId':_0x328476['id']},{})[_0x0b68('0x22')](function(){return _0x59b1f9;});}else{return _0x59b1f9;}})[_0x0b68('0x2c')](function(_0x12f798){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x12f798);throw _0x12f798;});}return _0x59b1f9;})['then'](respondWithResult(_0xd3a2e1,0xc9))[_0x0b68('0x2c')](handleError(_0xd3a2e1,null));};exports[_0x0b68('0x38')]=function(_0x1ce6c3,_0x1a231d){if(_0x1ce6c3[_0x0b68('0x5b')]['id']){delete _0x1ce6c3[_0x0b68('0x5b')]['id'];}return db[_0x0b68('0x40')][_0x0b68('0x60')]({'where':{'id':_0x1ce6c3[_0x0b68('0x59')]['id']}})['then'](handleEntityNotFound(_0x1a231d,null))['then'](saveUpdates(_0x1ce6c3['body'],null))['then'](respondWithResult(_0x1a231d,null))[_0x0b68('0x2c')](handleError(_0x1a231d,null));};exports[_0x0b68('0x3b')]=function(_0x59c6fa,_0x11196b){return db[_0x0b68('0x40')]['find']({'where':{'id':_0x59c6fa[_0x0b68('0x59')]['id']}})[_0x0b68('0x22')](handleEntityNotFound(_0x11196b,null))[_0x0b68('0x22')](removeEntity(_0x11196b,null))[_0x0b68('0x2c')](handleError(_0x11196b,null));};exports[_0x0b68('0x62')]=function(_0x12852d,_0x3b2ab2){return db['ChatQueue'][_0x0b68('0x62')]()[_0x0b68('0x22')](respondWithResult(_0x3b2ab2,null))[_0x0b68('0x2c')](handleError(_0x3b2ab2,null));};exports[_0x0b68('0x63')]=function(_0x5bb45f,_0xd26664,_0x157116){var _0x29e9ea={'raw':!![],'where':{}},_0x1a5fea={},_0x32eed2;return db['ChatQueue'][_0x0b68('0x64')]({'where':{'id':_0x5bb45f[_0x0b68('0x59')]['id']}})[_0x0b68('0x22')](handleEntityNotFound(_0xd26664,null))[_0x0b68('0x22')](function(_0x117935){if(_0x117935){_0x32eed2=_0x117935['get']({'plain':!![]});_0x1a5fea[_0x0b68('0x48')]=_[_0x0b68('0x65')](db[_0x0b68('0x66')][_0x0b68('0x41')]);_0x1a5fea[_0x0b68('0x45')]=_[_0x0b68('0x65')](_0x5bb45f[_0x0b68('0x45')]);_0x1a5fea[_0x0b68('0x46')]=_[_0x0b68('0x47')](_0x1a5fea['model'],_0x1a5fea[_0x0b68('0x45')]);_0x29e9ea[_0x0b68('0x49')]=_[_0x0b68('0x47')](_0x1a5fea[_0x0b68('0x48')],qs[_0x0b68('0x4a')](_0x5bb45f[_0x0b68('0x45')][_0x0b68('0x4a')]));_0x29e9ea[_0x0b68('0x49')]=_0x29e9ea['attributes'][_0x0b68('0x4b')]?_0x29e9ea[_0x0b68('0x49')]:_0x1a5fea[_0x0b68('0x48')];if(!_0x5bb45f[_0x0b68('0x45')]['hasOwnProperty'](_0x0b68('0x67'))){_0x29e9ea[_0x0b68('0x32')]=qs[_0x0b68('0x32')](_0x5bb45f[_0x0b68('0x45')][_0x0b68('0x32')]);_0x29e9ea['offset']=qs[_0x0b68('0x31')](_0x5bb45f['query']['offset']);}_0x29e9ea[_0x0b68('0x4c')]=qs[_0x0b68('0x4d')](_0x5bb45f[_0x0b68('0x45')][_0x0b68('0x4d')]);_0x29e9ea[_0x0b68('0x4e')]=qs[_0x0b68('0x46')](_[_0x0b68('0x4f')](_0x5bb45f[_0x0b68('0x45')],_0x1a5fea[_0x0b68('0x46')]));_0x29e9ea[_0x0b68('0x4e')][_0x0b68('0x68')]=_0x117935['id'];if(_0x5bb45f[_0x0b68('0x45')][_0x0b68('0x50')]){_0x29e9ea['where']=_[_0x0b68('0x51')](_0x29e9ea[_0x0b68('0x4e')],{'$or':_[_0x0b68('0x3f')](_0x29e9ea[_0x0b68('0x49')],function(_0x236265){var _0x85e510={};_0x85e510[_0x236265]={'$like':'%'+_0x5bb45f[_0x0b68('0x45')][_0x0b68('0x50')]+'%'};return _0x85e510;})});}_0x29e9ea=_[_0x0b68('0x51')]({},_0x29e9ea,_0x5bb45f[_0x0b68('0x53')]);return db['UserChatQueue'][_0x0b68('0x56')](_0x29e9ea);}})[_0x0b68('0x22')](function(_0x4691dd){if(_0x4691dd){return db['User'][_0x0b68('0x69')]({'where':{'id':_[_0x0b68('0x3f')](_0x4691dd,_0x0b68('0x6a')),'role':_0x0b68('0x6b')},'attributes':['id',_0x0b68('0x3d'),_0x0b68('0x6c'),'updatedAt','createdAt']});}})[_0x0b68('0x22')](function(_0x4f7e4a){if(_0x4f7e4a){return{'count':_0x4f7e4a[_0x0b68('0x30')],'rows':_[_0x0b68('0x3f')](_0x4f7e4a['rows'],function(_0x50b7e5){return{'membername':_0x50b7e5[_0x0b68('0x3d')],'UserId':_0x50b7e5['id'],'queue_name':_0x32eed2[_0x0b68('0x3d')],'ChatQueueId':_0x32eed2['id'],'interface':util['format'](_0x0b68('0x6d'),_0x0b68('0x6e'),_0x50b7e5[_0x0b68('0x3d')]),'penalty':0x0,'paused':_0x50b7e5[_0x0b68('0x6c')],'createdAt':_0x50b7e5[_0x0b68('0x6f')],'updatedAt':_0x50b7e5[_0x0b68('0x70')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x0b68('0x22')](respondWithFilteredResult(_0xd26664,_0x29e9ea))[_0x0b68('0x2c')](handleError(_0xd26664,null));};exports[_0x0b68('0x71')]=function(_0x43ceaf,_0x5ba2b2,_0x2529b0){var _0x31d4e2={};var _0x1f9c83={};var _0x397c38;var _0x48133c;return db[_0x0b68('0x40')][_0x0b68('0x64')]({'where':{'id':_0x43ceaf[_0x0b68('0x59')]['id']}})[_0x0b68('0x22')](handleEntityNotFound(_0x5ba2b2,null))[_0x0b68('0x22')](function(_0x458170){if(_0x458170){_0x397c38=_0x458170;_0x1f9c83[_0x0b68('0x48')]=_['keys'](db['Team'][_0x0b68('0x41')]);_0x1f9c83['query']=_[_0x0b68('0x65')](_0x43ceaf[_0x0b68('0x45')]);_0x1f9c83[_0x0b68('0x46')]=_[_0x0b68('0x47')](_0x1f9c83[_0x0b68('0x48')],_0x1f9c83[_0x0b68('0x45')]);_0x31d4e2[_0x0b68('0x49')]=_[_0x0b68('0x47')](_0x1f9c83['model'],qs[_0x0b68('0x4a')](_0x43ceaf['query']['fields']));_0x31d4e2['attributes']=_0x31d4e2[_0x0b68('0x49')][_0x0b68('0x4b')]?_0x31d4e2[_0x0b68('0x49')]:_0x1f9c83[_0x0b68('0x48')];_0x31d4e2['order']=qs[_0x0b68('0x4d')](_0x43ceaf[_0x0b68('0x45')][_0x0b68('0x4d')]);_0x31d4e2[_0x0b68('0x4e')]=qs[_0x0b68('0x46')](_[_0x0b68('0x4f')](_0x43ceaf[_0x0b68('0x45')],_0x1f9c83[_0x0b68('0x46')]));if(_0x43ceaf['query'][_0x0b68('0x50')]){_0x31d4e2[_0x0b68('0x4e')]=_['merge'](_0x31d4e2['where'],{'$or':_['map'](_0x31d4e2['attributes'],function(_0x232866){var _0x3869ac={};_0x3869ac[_0x232866]={'$like':'%'+_0x43ceaf[_0x0b68('0x45')][_0x0b68('0x50')]+'%'};return _0x3869ac;})});}_0x31d4e2=_['merge']({},_0x31d4e2,_0x43ceaf[_0x0b68('0x53')]);return _0x397c38[_0x0b68('0x71')](_0x31d4e2);}})[_0x0b68('0x22')](function(_0xc70db7){if(_0xc70db7){_0x48133c=_0xc70db7['length'];if(!_0x43ceaf[_0x0b68('0x45')][_0x0b68('0x72')](_0x0b68('0x67'))){_0x31d4e2['limit']=qs[_0x0b68('0x32')](_0x43ceaf['query'][_0x0b68('0x32')]);_0x31d4e2[_0x0b68('0x31')]=qs['offset'](_0x43ceaf[_0x0b68('0x45')][_0x0b68('0x31')]);}return _0x397c38[_0x0b68('0x71')](_0x31d4e2);}})[_0x0b68('0x22')](function(_0x3a304e){if(_0x3a304e){return _0x3a304e?{'count':_0x48133c,'rows':_0x3a304e}:null;}})[_0x0b68('0x22')](respondWithResult(_0x5ba2b2,null))[_0x0b68('0x2c')](handleError(_0x5ba2b2,null));};exports[_0x0b68('0x73')]=function(_0x47d711,_0x28d224,_0x5712ad){var _0x472940=_0x47d711[_0x0b68('0x5b')][_0x0b68('0x74')];return db[_0x0b68('0x75')]['findAll']({'where':{'id':_0x472940},'attributes':['id'],'include':[{'model':db['User'],'as':'Agents','attributes':['id',_0x0b68('0x3d'),_0x0b68('0x76'),_0x0b68('0x77'),'interface'],'raw':!![]}]})['then'](function(_0x470e02){if(_0x470e02){var _0x1f927e=_[_0x0b68('0x78')](_0x470e02,function(_0x43aac9){var _0x367b57=_0x43aac9[_0x0b68('0x5e')]({'plain':!![]});return _0x367b57[_0x0b68('0x79')];});return db[_0x0b68('0x40')][_0x0b68('0x60')]({'where':{'id':_0x47d711['params']['id']}})['then'](function(_0x301f80){return db['sequelize']['transaction'](function(_0x1af5f2){return _0x301f80['addTeams'](_0x472940,{'transaction':_0x1af5f2})[_0x0b68('0x22')](function(){return BPromise[_0x0b68('0x7a')](_0x1f927e,function(_0x255b23){return db[_0x0b68('0x66')][_0x0b68('0x7b')]({'where':{'UserId':_0x255b23['id'],'ChatQueueId':_0x47d711[_0x0b68('0x59')]['id']},'transaction':_0x1af5f2});});})[_0x0b68('0x22')](function(){_0x1f927e[_0x0b68('0x7c')](function(_0x27e4fc){socket[_0x0b68('0x7d')](_0x0b68('0x7e'),{'UserId':_0x27e4fc['id'],'ChatQueueId':_0x301f80['id']});});});});});}})[_0x0b68('0x22')](respondWithStatusCode(_0x28d224,null))[_0x0b68('0x2c')](handleError(_0x28d224,null));};exports[_0x0b68('0x7f')]=function(_0x2acacb,_0x3fadd0,_0xe0f964){return db['Team'][_0x0b68('0x56')]({'where':{'id':_0x2acacb['query'][_0x0b68('0x74')]},'attributes':['id'],'include':[{'model':db[_0x0b68('0x80')],'as':_0x0b68('0x79'),'attributes':['id'],'raw':!![]}]})[_0x0b68('0x22')](handleEntityNotFound(_0x3fadd0,null))[_0x0b68('0x22')](function(_0x3ee6c1){var _0x36d0bf=_[_0x0b68('0x3f')](_0x3ee6c1,'id');var _0x5c000b=[];var _0xc4b958=[];var _0x35acbc=squel[_0x0b68('0x81')]();_0x35acbc['field'](_0x0b68('0x82'))['from'](_0x0b68('0x83'),'tq')[_0x0b68('0x84')](_0x0b68('0x85'),'ut',_0x0b68('0x86'))[_0x0b68('0x4e')](_0x0b68('0x87'),_0x2acacb[_0x0b68('0x59')]['id']);for(var _0x3f01ea=0x0;_0x3f01ea<_0x3ee6c1['length'];_0x3f01ea+=0x1){let _0x495f80=_0x3ee6c1[_0x3f01ea];for(var _0x36785c=0x0;_0x36785c<_0x495f80['Agents'][_0x0b68('0x4b')];_0x36785c+=0x1){let _0x2b9595=_0x495f80['Agents'][_0x36785c];var _0x247ab0=_0x35acbc[_0x0b68('0x88')]();_0x247ab0[_0x0b68('0x4e')](_0x0b68('0x89'),_0x2b9595['id']);_0xc4b958[_0x0b68('0x8a')](db['sequelize']['query'](_0x247ab0['toString'](),{'type':db['sequelize']['QueryTypes']['SELECT']})[_0x0b68('0x22')](function(_0x4a95a1){if(_0x4a95a1[_0x0b68('0x4b')]===0x1){return _0x2b9595['id'];}else{var _0x5c3624=_[_0x0b68('0x8b')](_[_0x0b68('0x3f')](_0x4a95a1,_0x0b68('0x8c')),function(_0x154383){return _[_0x0b68('0x8d')](_0x36d0bf,_0x154383);});if(_0x5c3624){return _0x2b9595['id'];}}}));}}return BPromise[_0x0b68('0x8e')](_0xc4b958)[_0x0b68('0x22')](function(_0x26b358){_0x5c000b=_(_0x5c000b)[_0x0b68('0x8f')](_0x26b358)[_0x0b68('0x90')]()[_0x0b68('0x91')]();return db[_0x0b68('0x40')]['find']({'where':{'id':_0x2acacb[_0x0b68('0x59')]['id']}})['then'](function(_0x1a8353){return db[_0x0b68('0x92')][_0x0b68('0x93')](function(_0x2a4378){return _0x1a8353[_0x0b68('0x7f')](_0x2acacb[_0x0b68('0x45')]['ids'],{'transaction':_0x2a4378})['then'](function(){if(!_[_0x0b68('0x94')](_0x5c000b)){return _0x1a8353[_0x0b68('0x95')](_0x5c000b,{'transaction':_0x2a4378});}})[_0x0b68('0x22')](function(){_0x5c000b['forEach'](function(_0xad0874){socket[_0x0b68('0x7d')](_0x0b68('0x96'),{'UserId':_0xad0874,'ChatQueueId':_0x1a8353['id']});});});});});});})['then'](respondWithStatusCode(_0x3fadd0,null))[_0x0b68('0x2c')](handleError(_0x3fadd0,null));};exports[_0x0b68('0x97')]=function(_0x33644e,_0x38b0bb,_0xdb8201){return db['ChatQueue'][_0x0b68('0x60')]({'where':{'id':_0x33644e[_0x0b68('0x59')]['id']}})[_0x0b68('0x22')](handleEntityNotFound(_0x38b0bb,null))[_0x0b68('0x22')](function(_0x413ab9){if(_0x413ab9){return _0x413ab9[_0x0b68('0x97')](_0x33644e['body']['ids'],_['omit'](_0x33644e[_0x0b68('0x5b')],['ids','id'])||{})[_0x0b68('0x98')](function(_0x5060f5){for(var _0x16e4b8=0x0;_0x16e4b8<_0x33644e[_0x0b68('0x5b')][_0x0b68('0x74')][_0x0b68('0x4b')];_0x16e4b8+=0x1){socket[_0x0b68('0x7d')]('userChatQueue:save',{'UserId':_0x33644e[_0x0b68('0x5b')][_0x0b68('0x74')][_0x16e4b8],'ChatQueueId':_0x33644e[_0x0b68('0x59')]['id']});}return _0x5060f5;});}})[_0x0b68('0x22')](respondWithResult(_0x38b0bb,null))[_0x0b68('0x2c')](handleError(_0x38b0bb,null));};exports[_0x0b68('0x95')]=function(_0x20c61a,_0x347577,_0x361da2){return db[_0x0b68('0x40')][_0x0b68('0x60')]({'where':{'id':_0x20c61a[_0x0b68('0x59')]['id']}})[_0x0b68('0x22')](handleEntityNotFound(_0x347577,null))[_0x0b68('0x22')](function(_0x5500db){if(_0x5500db){return _0x5500db[_0x0b68('0x95')](_0x20c61a['query'][_0x0b68('0x74')])[_0x0b68('0x22')](function(){if(_['isArray'](_0x20c61a[_0x0b68('0x45')][_0x0b68('0x74')])){for(var _0x4d6185=0x0;_0x4d6185<_0x20c61a[_0x0b68('0x45')][_0x0b68('0x74')][_0x0b68('0x4b')];_0x4d6185+=0x1){socket['emit'](_0x0b68('0x96'),{'UserId':Number(_0x20c61a['query']['ids'][_0x4d6185]),'ChatQueueId':Number(_0x20c61a['params']['id'])});}}else{socket['emit']('userChatQueue:remove',{'UserId':Number(_0x20c61a['query']['ids']),'ChatQueueId':Number(_0x20c61a['params']['id'])});}});}})[_0x0b68('0x22')](respondWithStatusCode(_0x347577,null))[_0x0b68('0x2c')](handleError(_0x347577,null));};exports[_0x0b68('0x99')]=function(_0x5af9bb,_0x24c2e9,_0x1fa6d1){var _0x3daf26={};var _0x13e396={};var _0x11f318;var _0x3dcb00;return db[_0x0b68('0x40')][_0x0b68('0x64')]({'where':{'id':_0x5af9bb['params']['id']}})['then'](handleEntityNotFound(_0x24c2e9,null))['then'](function(_0x37c1b5){if(_0x37c1b5){_0x11f318=_0x37c1b5;_0x13e396[_0x0b68('0x48')]=_[_0x0b68('0x65')](db[_0x0b68('0x80')]['rawAttributes']);_0x13e396[_0x0b68('0x45')]=_[_0x0b68('0x65')](_0x5af9bb[_0x0b68('0x45')]);_0x13e396[_0x0b68('0x46')]=_[_0x0b68('0x47')](_0x13e396[_0x0b68('0x48')],_0x13e396[_0x0b68('0x45')]);_0x3daf26[_0x0b68('0x49')]=_['intersection'](_0x13e396['model'],qs[_0x0b68('0x4a')](_0x5af9bb[_0x0b68('0x45')][_0x0b68('0x4a')]));_0x3daf26[_0x0b68('0x49')]=_0x3daf26['attributes'][_0x0b68('0x4b')]?_0x3daf26[_0x0b68('0x49')]:_0x13e396[_0x0b68('0x48')];_0x3daf26[_0x0b68('0x4c')]=qs['sort'](_0x5af9bb[_0x0b68('0x45')][_0x0b68('0x4d')]);_0x3daf26['where']=qs[_0x0b68('0x46')](_[_0x0b68('0x4f')](_0x5af9bb[_0x0b68('0x45')],_0x13e396['filters']));if(_0x5af9bb[_0x0b68('0x45')][_0x0b68('0x50')]){_0x3daf26[_0x0b68('0x4e')]=_[_0x0b68('0x51')](_0x3daf26[_0x0b68('0x4e')],{'$or':_[_0x0b68('0x3f')](_0x3daf26[_0x0b68('0x49')],function(_0xa606b6){var _0x430eb5={};_0x430eb5[_0xa606b6]={'$like':'%'+_0x5af9bb['query']['filter']+'%'};return _0x430eb5;})});}_0x3daf26=_['merge']({},_0x3daf26,_0x5af9bb[_0x0b68('0x53')]);return _0x11f318[_0x0b68('0x99')](_0x3daf26);}})[_0x0b68('0x22')](function(_0x328923){if(_0x328923){_0x3dcb00=_0x328923[_0x0b68('0x4b')];if(!_0x5af9bb['query'][_0x0b68('0x72')]('nolimit')){_0x3daf26[_0x0b68('0x32')]=qs[_0x0b68('0x32')](_0x5af9bb[_0x0b68('0x45')][_0x0b68('0x32')]);_0x3daf26[_0x0b68('0x31')]=qs[_0x0b68('0x31')](_0x5af9bb[_0x0b68('0x45')][_0x0b68('0x31')]);}return _0x11f318[_0x0b68('0x99')](_0x3daf26);}})[_0x0b68('0x22')](function(_0x303226){if(_0x303226){return _0x303226?{'count':_0x3dcb00,'rows':_0x303226}:null;}})['then'](respondWithResult(_0x24c2e9,null))[_0x0b68('0x2c')](handleError(_0x24c2e9,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