Built motion from commit bab6f49e.|2.6.17
[motion2.git] / server / api / chatQueue / chatQueue.controller.js
index 6b4a584..be576d5 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb149=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','defaults','redis','socket.io-emitter','jayson/promise','client','http','request','then','info','ChatQueue,\x20%s,\x20%s,\x20%s','request\x20sent','error','ChatQueue,\x20%s,\x20%s','message','result','catch','end','status','json','undefined','limit','count','offset','set','Content-Range','reject','save','destroy','ChatQueues','UserProfileResource','sendStatus','stack','name','send','index','map','ChatQueue','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','params','find','create','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','body','describe','findOne','UserChatQueue','findAndCountAll','UserId','agent','updatedAt','createdAt','rows','format','%s/%s','SIP','chatPause','getTeams','Team','addTeams','User','online','interface','flatMap','sequelize','transaction','each','findOrCreate','forEach','emit','userChatQueue:save','removeTeams','ids','Agents','select','field','tq.TeamId','from','team_has_chat_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','QueryTypes','SELECT','TeamId','union','compact','isEmpty','userChatQueue:remove','addAgents','removeAgents','isArray','getAgents','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/auth/service'];(function(_0x53f37f,_0xfb0b18){var _0x2fe5f8=function(_0x76ef2d){while(--_0x76ef2d){_0x53f37f['push'](_0x53f37f['shift']());}};_0x2fe5f8(++_0xfb0b18);}(_0xb149,0x84));var _0x9b14=function(_0x9e0cb3,_0x9cd497){_0x9e0cb3=_0x9e0cb3-0x0;var _0x5926b7=_0xb149[_0x9e0cb3];return _0x5926b7;};'use strict';var emlformat=require(_0x9b14('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x9b14('0x1'));var jsonpatch=require(_0x9b14('0x2'));var rp=require(_0x9b14('0x3'));var moment=require(_0x9b14('0x4'));var BPromise=require(_0x9b14('0x5'));var Mustache=require(_0x9b14('0x6'));var util=require(_0x9b14('0x7'));var path=require('path');var sox=require(_0x9b14('0x8'));var csv=require(_0x9b14('0x9'));var ejs=require(_0x9b14('0xa'));var fs=require('fs');var fs_extra=require(_0x9b14('0xb'));var _=require(_0x9b14('0xc'));var squel=require(_0x9b14('0xd'));var crypto=require('crypto');var jsforce=require(_0x9b14('0xe'));var deskjs=require(_0x9b14('0xf'));var toCsv=require(_0x9b14('0x9'));var querystring=require(_0x9b14('0x10'));var Papa=require('papaparse');var Redis=require(_0x9b14('0x11'));var authService=require(_0x9b14('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x9b14('0x13'));var hardwareService=require(_0x9b14('0x14'));var logger=require(_0x9b14('0x15'))('api');var utils=require(_0x9b14('0x16'));var config=require(_0x9b14('0x17'));var licenseUtil=require(_0x9b14('0x18'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x9b14('0x19')](config[_0x9b14('0x1a')],{'host':'localhost','port':0x18eb});var socket=require(_0x9b14('0x1b'))(new Redis(config['redis']));require('./chatQueue.socket')['register'](socket);var jayson=require(_0x9b14('0x1c'));var client=jayson[_0x9b14('0x1d')][_0x9b14('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x1d5c94,_0x3e8d95,_0x44af82,_0xce0cdb){return new BPromise(function(_0x261354,_0x11dc7b){var _0x3bffbd=_0xce0cdb||client;return _0x3bffbd[_0x9b14('0x1f')](_0x1d5c94,_0x44af82)[_0x9b14('0x20')](function(_0x23032d){logger[_0x9b14('0x21')]('ChatQueue,\x20%s,\x20%s',_0x3e8d95,'request\x20sent');logger['debug'](_0x9b14('0x22'),_0x3e8d95,_0x9b14('0x23'),JSON['stringify'](_0x23032d));if(_0x23032d[_0x9b14('0x24')]){if(_0x23032d[_0x9b14('0x24')]['code']===0x1f4){logger[_0x9b14('0x24')](_0x9b14('0x25'),_0x3e8d95,_0x23032d[_0x9b14('0x24')][_0x9b14('0x26')]);return _0x11dc7b(_0x23032d['error'][_0x9b14('0x26')]);}logger[_0x9b14('0x24')](_0x9b14('0x25'),_0x3e8d95,_0x23032d['error'][_0x9b14('0x26')]);return _0x261354(_0x23032d[_0x9b14('0x24')][_0x9b14('0x26')]);}else{logger[_0x9b14('0x21')](_0x9b14('0x25'),_0x3e8d95,_0x9b14('0x23'));_0x261354(_0x23032d[_0x9b14('0x27')][_0x9b14('0x26')]);}})[_0x9b14('0x28')](function(_0x27a400){logger[_0x9b14('0x24')]('ChatQueue,\x20%s,\x20%s',_0x3e8d95,_0x27a400);_0x11dc7b(_0x27a400);});});}function respondWithStatusCode(_0x544f83,_0x136303){_0x136303=_0x136303||0xcc;return function(_0x695dc4){if(_0x695dc4){return _0x544f83['sendStatus'](_0x136303);}return _0x544f83['status'](_0x136303)[_0x9b14('0x29')]();};}function respondWithResult(_0x133ed8,_0x54d9f1){_0x54d9f1=_0x54d9f1||0xc8;return function(_0x387331){if(_0x387331){return _0x133ed8[_0x9b14('0x2a')](_0x54d9f1)[_0x9b14('0x2b')](_0x387331);}};}function respondWithFilteredResult(_0x2b70ca,_0x1d8516){return function(_0x3cee4a){if(_0x3cee4a){var _0x158cdc=typeof _0x1d8516['offset']===_0x9b14('0x2c')&&typeof _0x1d8516[_0x9b14('0x2d')]===_0x9b14('0x2c');var _0x22863a=_0x3cee4a[_0x9b14('0x2e')];var _0x5c7813=_0x158cdc?0x0:_0x1d8516['offset'];var _0x10c6cf=_0x158cdc?_0x3cee4a['count']:_0x1d8516[_0x9b14('0x2f')]+_0x1d8516[_0x9b14('0x2d')];var _0x58b313;if(_0x10c6cf>=_0x22863a){_0x10c6cf=_0x22863a;_0x58b313=0xc8;}else{_0x58b313=0xce;}_0x2b70ca['status'](_0x58b313);return _0x2b70ca[_0x9b14('0x30')](_0x9b14('0x31'),_0x5c7813+'-'+_0x10c6cf+'/'+_0x22863a)[_0x9b14('0x2b')](_0x3cee4a);}return null;};}function patchUpdates(_0x2af097){return function(_0x15b0fe){try{jsonpatch['apply'](_0x15b0fe,_0x2af097,!![]);}catch(_0x427b30){return BPromise[_0x9b14('0x32')](_0x427b30);}return _0x15b0fe[_0x9b14('0x33')]();};}function saveUpdates(_0x55a186,_0x3ae480){return function(_0x3d11c1){if(_0x3d11c1){return _0x3d11c1['update'](_0x55a186)[_0x9b14('0x20')](function(_0x5777ef){return _0x5777ef;});}return null;};}function removeEntity(_0x4531ef,_0x1ec6ec){return function(_0xee5797){if(_0xee5797){return _0xee5797[_0x9b14('0x34')]()[_0x9b14('0x20')](function(){var _0x15bd17=_0xee5797['get']({'plain':!![]});var _0x51ba72=_0x9b14('0x35');return db[_0x9b14('0x36')][_0x9b14('0x34')]({'where':{'type':_0x51ba72,'resourceId':_0x15bd17['id']}})['then'](function(){return _0xee5797;});})[_0x9b14('0x20')](function(){_0x4531ef['status'](0xcc)[_0x9b14('0x29')]();});}};}function handleEntityNotFound(_0x3f8ca2,_0x594bc9){return function(_0x19e92d){if(!_0x19e92d){_0x3f8ca2[_0x9b14('0x37')](0x194);}return _0x19e92d;};}function handleError(_0x2e9db9,_0x4a87b5){_0x4a87b5=_0x4a87b5||0x1f4;return function(_0x1ec551){logger['error'](_0x1ec551[_0x9b14('0x38')]);if(_0x1ec551[_0x9b14('0x39')]){delete _0x1ec551[_0x9b14('0x39')];}_0x2e9db9[_0x9b14('0x2a')](_0x4a87b5)[_0x9b14('0x3a')](_0x1ec551);};}exports[_0x9b14('0x3b')]=function(_0x5a9448,_0x2dcbec){var _0x2eb51f={},_0x5db8f8={},_0x1ca82a={'count':0x0,'rows':[]};var _0x82524f=_[_0x9b14('0x3c')](db[_0x9b14('0x3d')][_0x9b14('0x3e')],function(_0x3ca72c){return{'name':_0x3ca72c[_0x9b14('0x3f')],'type':_0x3ca72c[_0x9b14('0x40')]['key']};});_0x5db8f8[_0x9b14('0x41')]=_[_0x9b14('0x3c')](_0x82524f,_0x9b14('0x39'));_0x5db8f8[_0x9b14('0x42')]=_[_0x9b14('0x43')](_0x5a9448[_0x9b14('0x42')]);_0x5db8f8[_0x9b14('0x44')]=_[_0x9b14('0x45')](_0x5db8f8[_0x9b14('0x41')],_0x5db8f8[_0x9b14('0x42')]);_0x2eb51f[_0x9b14('0x46')]=_[_0x9b14('0x45')](_0x5db8f8[_0x9b14('0x41')],qs[_0x9b14('0x47')](_0x5a9448['query'][_0x9b14('0x47')]));_0x2eb51f[_0x9b14('0x46')]=_0x2eb51f['attributes'][_0x9b14('0x48')]?_0x2eb51f[_0x9b14('0x46')]:_0x5db8f8[_0x9b14('0x41')];if(!_0x5a9448['query'][_0x9b14('0x49')](_0x9b14('0x4a'))){_0x2eb51f[_0x9b14('0x2d')]=qs['limit'](_0x5a9448[_0x9b14('0x42')][_0x9b14('0x2d')]);_0x2eb51f[_0x9b14('0x2f')]=qs[_0x9b14('0x2f')](_0x5a9448[_0x9b14('0x42')][_0x9b14('0x2f')]);}_0x2eb51f[_0x9b14('0x4b')]=qs[_0x9b14('0x4c')](_0x5a9448[_0x9b14('0x42')][_0x9b14('0x4c')]);_0x2eb51f[_0x9b14('0x4d')]=qs['filters'](_[_0x9b14('0x4e')](_0x5a9448[_0x9b14('0x42')],_0x5db8f8[_0x9b14('0x44')]),_0x82524f);if(_0x5a9448[_0x9b14('0x42')][_0x9b14('0x4f')]){_0x2eb51f[_0x9b14('0x4d')]=_[_0x9b14('0x50')](_0x2eb51f[_0x9b14('0x4d')],{'$or':_[_0x9b14('0x3c')](_0x82524f,function(_0x268dc4){if(_0x268dc4[_0x9b14('0x40')]!==_0x9b14('0x51')){var _0xc661fa={};_0xc661fa[_0x268dc4[_0x9b14('0x39')]]={'$like':'%'+_0x5a9448[_0x9b14('0x42')][_0x9b14('0x4f')]+'%'};return _0xc661fa;}})});}_0x2eb51f=_['merge']({},_0x2eb51f,_0x5a9448[_0x9b14('0x52')]);var _0x3b0566={'where':_0x2eb51f[_0x9b14('0x4d')]};return db[_0x9b14('0x3d')]['count'](_0x3b0566)[_0x9b14('0x20')](function(_0x193653){_0x1ca82a[_0x9b14('0x2e')]=_0x193653;if(_0x5a9448[_0x9b14('0x42')][_0x9b14('0x53')]){_0x2eb51f[_0x9b14('0x54')]=[{'all':!![]}];}return db[_0x9b14('0x3d')][_0x9b14('0x55')](_0x2eb51f);})['then'](function(_0x178302){_0x1ca82a['rows']=_0x178302;return _0x1ca82a;})[_0x9b14('0x20')](respondWithFilteredResult(_0x2dcbec,_0x2eb51f))[_0x9b14('0x28')](handleError(_0x2dcbec,null));};exports['show']=function(_0x10c549,_0x1d2369){var _0x2369e1={'raw':!![],'where':{'id':_0x10c549[_0x9b14('0x56')]['id']}},_0x37999e={};_0x37999e['model']=_[_0x9b14('0x43')](db[_0x9b14('0x3d')][_0x9b14('0x3e')]);_0x37999e[_0x9b14('0x42')]=_[_0x9b14('0x43')](_0x10c549[_0x9b14('0x42')]);_0x37999e[_0x9b14('0x44')]=_[_0x9b14('0x45')](_0x37999e[_0x9b14('0x41')],_0x37999e[_0x9b14('0x42')]);_0x2369e1[_0x9b14('0x46')]=_[_0x9b14('0x45')](_0x37999e[_0x9b14('0x41')],qs['fields'](_0x10c549[_0x9b14('0x42')][_0x9b14('0x47')]));_0x2369e1[_0x9b14('0x46')]=_0x2369e1['attributes'][_0x9b14('0x48')]?_0x2369e1[_0x9b14('0x46')]:_0x37999e['model'];if(_0x10c549[_0x9b14('0x42')][_0x9b14('0x53')]){_0x2369e1[_0x9b14('0x54')]=[{'all':!![]}];}_0x2369e1=_['merge']({},_0x2369e1,_0x10c549['options']);return db['ChatQueue'][_0x9b14('0x57')](_0x2369e1)[_0x9b14('0x20')](handleEntityNotFound(_0x1d2369,null))[_0x9b14('0x20')](respondWithResult(_0x1d2369,null))[_0x9b14('0x28')](handleError(_0x1d2369,null));};exports[_0x9b14('0x58')]=function(_0x3c5c38,_0x584604){return db[_0x9b14('0x3d')]['create'](_0x3c5c38['body'],{})['then'](function(_0x5c77c4){var _0x5eb4fc=_0x3c5c38['user'][_0x9b14('0x59')]({'plain':!![]});if(!_0x5eb4fc)throw new Error(_0x9b14('0x5a'));if(_0x5eb4fc[_0x9b14('0x5b')]===_0x9b14('0x5c')){var _0x2fd885=_0x5c77c4[_0x9b14('0x59')]({'plain':!![]});var _0x22fc59='ChatQueues';return db[_0x9b14('0x5d')]['find']({'where':{'name':_0x22fc59,'userProfileId':_0x5eb4fc[_0x9b14('0x5e')]},'raw':!![]})[_0x9b14('0x20')](function(_0x5275ce){if(_0x5275ce&&_0x5275ce[_0x9b14('0x5f')]===0x0){return db[_0x9b14('0x36')][_0x9b14('0x58')]({'name':_0x2fd885[_0x9b14('0x39')],'resourceId':_0x2fd885['id'],'type':_0x5275ce[_0x9b14('0x39')],'sectionId':_0x5275ce['id']},{})[_0x9b14('0x20')](function(){return _0x5c77c4;});}else{return _0x5c77c4;}})[_0x9b14('0x28')](function(_0x3f6bbb){logger[_0x9b14('0x24')](_0x9b14('0x60'),_0x3f6bbb);throw _0x3f6bbb;});}return _0x5c77c4;})[_0x9b14('0x20')](respondWithResult(_0x584604,0xc9))[_0x9b14('0x28')](handleError(_0x584604,null));};exports[_0x9b14('0x61')]=function(_0x1675b0,_0x24c0c0){if(_0x1675b0['body']['id']){delete _0x1675b0[_0x9b14('0x62')]['id'];}return db[_0x9b14('0x3d')][_0x9b14('0x57')]({'where':{'id':_0x1675b0[_0x9b14('0x56')]['id']}})[_0x9b14('0x20')](handleEntityNotFound(_0x24c0c0,null))['then'](saveUpdates(_0x1675b0[_0x9b14('0x62')],null))[_0x9b14('0x20')](respondWithResult(_0x24c0c0,null))[_0x9b14('0x28')](handleError(_0x24c0c0,null));};exports[_0x9b14('0x34')]=function(_0x404666,_0x571c70){return db['ChatQueue'][_0x9b14('0x57')]({'where':{'id':_0x404666[_0x9b14('0x56')]['id']}})[_0x9b14('0x20')](handleEntityNotFound(_0x571c70,null))['then'](removeEntity(_0x571c70,null))['catch'](handleError(_0x571c70,null));};exports[_0x9b14('0x63')]=function(_0x14ad75,_0x2ea179){return db[_0x9b14('0x3d')][_0x9b14('0x63')]()[_0x9b14('0x20')](respondWithResult(_0x2ea179,null))[_0x9b14('0x28')](handleError(_0x2ea179,null));};exports['getMembers']=function(_0x3a224a,_0x23093f,_0x44ef7b){var _0x5eaf42={'raw':!![],'where':{}},_0x5528be={},_0xac5734;return db['ChatQueue'][_0x9b14('0x64')]({'where':{'id':_0x3a224a[_0x9b14('0x56')]['id']}})[_0x9b14('0x20')](handleEntityNotFound(_0x23093f,null))[_0x9b14('0x20')](function(_0x25cda0){if(_0x25cda0){_0xac5734=_0x25cda0[_0x9b14('0x59')]({'plain':!![]});_0x5528be[_0x9b14('0x41')]=_['keys'](db[_0x9b14('0x65')]['rawAttributes']);_0x5528be['query']=_['keys'](_0x3a224a[_0x9b14('0x42')]);_0x5528be[_0x9b14('0x44')]=_[_0x9b14('0x45')](_0x5528be[_0x9b14('0x41')],_0x5528be[_0x9b14('0x42')]);_0x5eaf42[_0x9b14('0x46')]=_[_0x9b14('0x45')](_0x5528be[_0x9b14('0x41')],qs[_0x9b14('0x47')](_0x3a224a[_0x9b14('0x42')]['fields']));_0x5eaf42[_0x9b14('0x46')]=_0x5eaf42[_0x9b14('0x46')][_0x9b14('0x48')]?_0x5eaf42['attributes']:_0x5528be[_0x9b14('0x41')];if(!_0x3a224a[_0x9b14('0x42')]['hasOwnProperty'](_0x9b14('0x4a'))){_0x5eaf42[_0x9b14('0x2d')]=qs['limit'](_0x3a224a[_0x9b14('0x42')]['limit']);_0x5eaf42['offset']=qs[_0x9b14('0x2f')](_0x3a224a[_0x9b14('0x42')]['offset']);}_0x5eaf42['order']=qs[_0x9b14('0x4c')](_0x3a224a[_0x9b14('0x42')][_0x9b14('0x4c')]);_0x5eaf42[_0x9b14('0x4d')]=qs[_0x9b14('0x44')](_[_0x9b14('0x4e')](_0x3a224a[_0x9b14('0x42')],_0x5528be[_0x9b14('0x44')]));_0x5eaf42[_0x9b14('0x4d')]['ChatQueueId']=_0x25cda0['id'];if(_0x3a224a[_0x9b14('0x42')][_0x9b14('0x4f')]){_0x5eaf42['where']=_[_0x9b14('0x50')](_0x5eaf42[_0x9b14('0x4d')],{'$or':_[_0x9b14('0x3c')](_0x5eaf42[_0x9b14('0x46')],function(_0x4516c1){var _0x2f9fd7={};_0x2f9fd7[_0x4516c1]={'$like':'%'+_0x3a224a[_0x9b14('0x42')][_0x9b14('0x4f')]+'%'};return _0x2f9fd7;})});}_0x5eaf42=_[_0x9b14('0x50')]({},_0x5eaf42,_0x3a224a['options']);return db[_0x9b14('0x65')]['findAll'](_0x5eaf42);}})['then'](function(_0x2903ed){if(_0x2903ed){return db['User'][_0x9b14('0x66')]({'where':{'id':_['map'](_0x2903ed,_0x9b14('0x67')),'role':_0x9b14('0x68')},'attributes':['id',_0x9b14('0x39'),'chatPause',_0x9b14('0x69'),_0x9b14('0x6a')]});}})[_0x9b14('0x20')](function(_0xac41d5){if(_0xac41d5){return{'count':_0xac41d5['count'],'rows':_['map'](_0xac41d5[_0x9b14('0x6b')],function(_0x2ba08c){return{'membername':_0x2ba08c[_0x9b14('0x39')],'UserId':_0x2ba08c['id'],'queue_name':_0xac5734[_0x9b14('0x39')],'ChatQueueId':_0xac5734['id'],'interface':util[_0x9b14('0x6c')](_0x9b14('0x6d'),_0x9b14('0x6e'),_0x2ba08c[_0x9b14('0x39')]),'penalty':0x0,'paused':_0x2ba08c[_0x9b14('0x6f')],'createdAt':_0x2ba08c[_0x9b14('0x6a')],'updatedAt':_0x2ba08c[_0x9b14('0x69')]};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x23093f,_0x5eaf42))['catch'](handleError(_0x23093f,null));};exports[_0x9b14('0x70')]=function(_0x4c3693,_0x2eb6ce,_0x577042){var _0x15332={};var _0x330e88={};var _0x406231;var _0x315855;return db[_0x9b14('0x3d')][_0x9b14('0x64')]({'where':{'id':_0x4c3693[_0x9b14('0x56')]['id']}})[_0x9b14('0x20')](handleEntityNotFound(_0x2eb6ce,null))[_0x9b14('0x20')](function(_0x5f048d){if(_0x5f048d){_0x406231=_0x5f048d;_0x330e88[_0x9b14('0x41')]=_['keys'](db[_0x9b14('0x71')][_0x9b14('0x3e')]);_0x330e88['query']=_['keys'](_0x4c3693[_0x9b14('0x42')]);_0x330e88[_0x9b14('0x44')]=_[_0x9b14('0x45')](_0x330e88[_0x9b14('0x41')],_0x330e88['query']);_0x15332[_0x9b14('0x46')]=_['intersection'](_0x330e88['model'],qs[_0x9b14('0x47')](_0x4c3693[_0x9b14('0x42')][_0x9b14('0x47')]));_0x15332['attributes']=_0x15332['attributes'][_0x9b14('0x48')]?_0x15332[_0x9b14('0x46')]:_0x330e88['model'];_0x15332[_0x9b14('0x4b')]=qs[_0x9b14('0x4c')](_0x4c3693[_0x9b14('0x42')][_0x9b14('0x4c')]);_0x15332[_0x9b14('0x4d')]=qs['filters'](_['pick'](_0x4c3693[_0x9b14('0x42')],_0x330e88[_0x9b14('0x44')]));if(_0x4c3693[_0x9b14('0x42')]['filter']){_0x15332[_0x9b14('0x4d')]=_[_0x9b14('0x50')](_0x15332[_0x9b14('0x4d')],{'$or':_[_0x9b14('0x3c')](_0x15332[_0x9b14('0x46')],function(_0x4d0cb4){var _0x32aec5={};_0x32aec5[_0x4d0cb4]={'$like':'%'+_0x4c3693[_0x9b14('0x42')][_0x9b14('0x4f')]+'%'};return _0x32aec5;})});}_0x15332=_[_0x9b14('0x50')]({},_0x15332,_0x4c3693[_0x9b14('0x52')]);return _0x406231[_0x9b14('0x70')](_0x15332);}})['then'](function(_0x596e8b){if(_0x596e8b){_0x315855=_0x596e8b[_0x9b14('0x48')];if(!_0x4c3693[_0x9b14('0x42')][_0x9b14('0x49')]('nolimit')){_0x15332['limit']=qs[_0x9b14('0x2d')](_0x4c3693[_0x9b14('0x42')]['limit']);_0x15332['offset']=qs[_0x9b14('0x2f')](_0x4c3693[_0x9b14('0x42')][_0x9b14('0x2f')]);}return _0x406231[_0x9b14('0x70')](_0x15332);}})['then'](function(_0x4faa8c){if(_0x4faa8c){return _0x4faa8c?{'count':_0x315855,'rows':_0x4faa8c}:null;}})['then'](respondWithResult(_0x2eb6ce,null))['catch'](handleError(_0x2eb6ce,null));};exports[_0x9b14('0x72')]=function(_0x5b937c,_0x481c87,_0x2267fc){var _0x5468a2=_0x5b937c[_0x9b14('0x62')]['ids'];return db[_0x9b14('0x71')][_0x9b14('0x55')]({'where':{'id':_0x5468a2},'attributes':['id'],'include':[{'model':db[_0x9b14('0x73')],'as':'Agents','attributes':['id','name',_0x9b14('0x74'),'voicePause',_0x9b14('0x75')],'raw':!![]}]})[_0x9b14('0x20')](function(_0x2b5d5e){if(_0x2b5d5e){var _0x15777a=_[_0x9b14('0x76')](_0x2b5d5e,function(_0x5b7c3b){var _0x1b63a4=_0x5b7c3b[_0x9b14('0x59')]({'plain':!![]});return _0x1b63a4['Agents'];});return db['ChatQueue'][_0x9b14('0x57')]({'where':{'id':_0x5b937c['params']['id']}})['then'](function(_0x413535){return db[_0x9b14('0x77')][_0x9b14('0x78')](function(_0x9d8d16){return _0x413535['addTeams'](_0x5468a2,{'transaction':_0x9d8d16})[_0x9b14('0x20')](function(){return BPromise[_0x9b14('0x79')](_0x15777a,function(_0xeb375b){return db['UserChatQueue'][_0x9b14('0x7a')]({'where':{'UserId':_0xeb375b['id'],'ChatQueueId':_0x5b937c[_0x9b14('0x56')]['id']},'transaction':_0x9d8d16});});})['then'](function(){_0x15777a[_0x9b14('0x7b')](function(_0x4996e7){socket[_0x9b14('0x7c')](_0x9b14('0x7d'),{'UserId':_0x4996e7['id'],'ChatQueueId':_0x413535['id']});});});});});}})[_0x9b14('0x20')](respondWithStatusCode(_0x481c87,null))['catch'](handleError(_0x481c87,null));};exports[_0x9b14('0x7e')]=function(_0x19d6f1,_0x5557d5,_0x328028){return db[_0x9b14('0x71')][_0x9b14('0x55')]({'where':{'id':_0x19d6f1['query'][_0x9b14('0x7f')]},'attributes':['id'],'include':[{'model':db[_0x9b14('0x73')],'as':_0x9b14('0x80'),'attributes':['id'],'raw':!![]}]})[_0x9b14('0x20')](handleEntityNotFound(_0x5557d5,null))[_0x9b14('0x20')](function(_0x4f1d71){var _0x57588c=_[_0x9b14('0x3c')](_0x4f1d71,'id');var _0xb748b8=[];var _0x2bfdd2=[];var _0x12572f=squel[_0x9b14('0x81')]();_0x12572f[_0x9b14('0x82')](_0x9b14('0x83'))[_0x9b14('0x84')](_0x9b14('0x85'),'tq')[_0x9b14('0x86')](_0x9b14('0x87'),'ut',_0x9b14('0x88'))[_0x9b14('0x4d')](_0x9b14('0x89'),_0x19d6f1[_0x9b14('0x56')]['id']);for(var _0x24e29b=0x0;_0x24e29b<_0x4f1d71['length'];_0x24e29b+=0x1){let _0x96ae92=_0x4f1d71[_0x24e29b];for(var _0x18f249=0x0;_0x18f249<_0x96ae92['Agents'][_0x9b14('0x48')];_0x18f249+=0x1){let _0x5b3da5=_0x96ae92[_0x9b14('0x80')][_0x18f249];var _0x2c889e=_0x12572f[_0x9b14('0x8a')]();_0x2c889e[_0x9b14('0x4d')](_0x9b14('0x8b'),_0x5b3da5['id']);_0x2bfdd2['push'](db[_0x9b14('0x77')][_0x9b14('0x42')](_0x2c889e['toString'](),{'type':db['sequelize'][_0x9b14('0x8c')][_0x9b14('0x8d')]})[_0x9b14('0x20')](function(_0x5e1ebe){if(_0x5e1ebe['length']===0x1){return _0x5b3da5['id'];}else{var _0x31999c=_['every'](_['map'](_0x5e1ebe,_0x9b14('0x8e')),function(_0x49fd4c){return _['includes'](_0x57588c,_0x49fd4c);});if(_0x31999c){return _0x5b3da5['id'];}}}));}}return BPromise['all'](_0x2bfdd2)[_0x9b14('0x20')](function(_0x3922e9){_0xb748b8=_(_0xb748b8)[_0x9b14('0x8f')](_0x3922e9)[_0x9b14('0x90')]()['value']();return db[_0x9b14('0x3d')][_0x9b14('0x57')]({'where':{'id':_0x19d6f1[_0x9b14('0x56')]['id']}})['then'](function(_0x458c63){return db[_0x9b14('0x77')][_0x9b14('0x78')](function(_0x3ad21a){return _0x458c63[_0x9b14('0x7e')](_0x19d6f1['query'][_0x9b14('0x7f')],{'transaction':_0x3ad21a})[_0x9b14('0x20')](function(){if(!_[_0x9b14('0x91')](_0xb748b8)){return _0x458c63['removeAgents'](_0xb748b8,{'transaction':_0x3ad21a});}})[_0x9b14('0x20')](function(){_0xb748b8[_0x9b14('0x7b')](function(_0x455dd5){socket[_0x9b14('0x7c')](_0x9b14('0x92'),{'UserId':_0x455dd5,'ChatQueueId':_0x458c63['id']});});});});});});})[_0x9b14('0x20')](respondWithStatusCode(_0x5557d5,null))['catch'](handleError(_0x5557d5,null));};exports[_0x9b14('0x93')]=function(_0x278195,_0x18ad40,_0x1b875c){return db[_0x9b14('0x3d')][_0x9b14('0x57')]({'where':{'id':_0x278195[_0x9b14('0x56')]['id']}})['then'](handleEntityNotFound(_0x18ad40,null))[_0x9b14('0x20')](function(_0x251611){if(_0x251611){return _0x251611[_0x9b14('0x93')](_0x278195['body'][_0x9b14('0x7f')],_['omit'](_0x278195[_0x9b14('0x62')],['ids','id'])||{})['spread'](function(_0x5a9c86){for(var _0x1c173f=0x0;_0x1c173f<_0x278195[_0x9b14('0x62')][_0x9b14('0x7f')][_0x9b14('0x48')];_0x1c173f+=0x1){socket[_0x9b14('0x7c')](_0x9b14('0x7d'),{'UserId':Number(_0x278195[_0x9b14('0x62')]['ids'][_0x1c173f]),'ChatQueueId':Number(_0x278195[_0x9b14('0x56')]['id'])});}return _0x5a9c86;});}})[_0x9b14('0x20')](respondWithResult(_0x18ad40,null))[_0x9b14('0x28')](handleError(_0x18ad40,null));};exports[_0x9b14('0x94')]=function(_0x163bd4,_0x86fb1f,_0xa21e0){return db['ChatQueue'][_0x9b14('0x57')]({'where':{'id':_0x163bd4['params']['id']}})[_0x9b14('0x20')](handleEntityNotFound(_0x86fb1f,null))[_0x9b14('0x20')](function(_0x399e2b){if(_0x399e2b){return _0x399e2b['removeAgents'](_0x163bd4[_0x9b14('0x42')][_0x9b14('0x7f')])[_0x9b14('0x20')](function(){if(_[_0x9b14('0x95')](_0x163bd4['query'][_0x9b14('0x7f')])){for(var _0x192adc=0x0;_0x192adc<_0x163bd4[_0x9b14('0x42')][_0x9b14('0x7f')][_0x9b14('0x48')];_0x192adc+=0x1){socket[_0x9b14('0x7c')]('userChatQueue:remove',{'UserId':Number(_0x163bd4[_0x9b14('0x42')][_0x9b14('0x7f')][_0x192adc]),'ChatQueueId':Number(_0x163bd4[_0x9b14('0x56')]['id'])});}}else{socket['emit'](_0x9b14('0x92'),{'UserId':Number(_0x163bd4[_0x9b14('0x42')][_0x9b14('0x7f')]),'ChatQueueId':Number(_0x163bd4[_0x9b14('0x56')]['id'])});}});}})[_0x9b14('0x20')](respondWithStatusCode(_0x86fb1f,null))[_0x9b14('0x28')](handleError(_0x86fb1f,null));};exports[_0x9b14('0x96')]=function(_0x127cd9,_0x165fe0,_0x45f06c){var _0x1a8bd5={};var _0x41be56={};var _0x48d889;var _0x421224;return db[_0x9b14('0x3d')][_0x9b14('0x64')]({'where':{'id':_0x127cd9[_0x9b14('0x56')]['id']}})[_0x9b14('0x20')](handleEntityNotFound(_0x165fe0,null))[_0x9b14('0x20')](function(_0x5391c9){if(_0x5391c9){_0x48d889=_0x5391c9;_0x41be56[_0x9b14('0x41')]=_[_0x9b14('0x43')](db[_0x9b14('0x73')][_0x9b14('0x3e')]);_0x41be56[_0x9b14('0x42')]=_[_0x9b14('0x43')](_0x127cd9[_0x9b14('0x42')]);_0x41be56['filters']=_['intersection'](_0x41be56[_0x9b14('0x41')],_0x41be56[_0x9b14('0x42')]);_0x1a8bd5[_0x9b14('0x46')]=_[_0x9b14('0x45')](_0x41be56[_0x9b14('0x41')],qs['fields'](_0x127cd9[_0x9b14('0x42')][_0x9b14('0x47')]));_0x1a8bd5[_0x9b14('0x46')]=_0x1a8bd5[_0x9b14('0x46')][_0x9b14('0x48')]?_0x1a8bd5[_0x9b14('0x46')]:_0x41be56[_0x9b14('0x41')];_0x1a8bd5['order']=qs['sort'](_0x127cd9[_0x9b14('0x42')][_0x9b14('0x4c')]);_0x1a8bd5['where']=qs['filters'](_['pick'](_0x127cd9['query'],_0x41be56[_0x9b14('0x44')]));if(_0x127cd9[_0x9b14('0x42')]['filter']){_0x1a8bd5[_0x9b14('0x4d')]=_[_0x9b14('0x50')](_0x1a8bd5['where'],{'$or':_['map'](_0x1a8bd5['attributes'],function(_0x35f1b6){var _0x4bb2ba={};_0x4bb2ba[_0x35f1b6]={'$like':'%'+_0x127cd9[_0x9b14('0x42')][_0x9b14('0x4f')]+'%'};return _0x4bb2ba;})});}_0x1a8bd5=_[_0x9b14('0x50')]({},_0x1a8bd5,_0x127cd9['options']);return _0x48d889[_0x9b14('0x96')](_0x1a8bd5);}})[_0x9b14('0x20')](function(_0x51bc19){if(_0x51bc19){_0x421224=_0x51bc19[_0x9b14('0x48')];if(!_0x127cd9[_0x9b14('0x42')][_0x9b14('0x49')](_0x9b14('0x4a'))){_0x1a8bd5[_0x9b14('0x2d')]=qs[_0x9b14('0x2d')](_0x127cd9['query']['limit']);_0x1a8bd5[_0x9b14('0x2f')]=qs['offset'](_0x127cd9['query']['offset']);}return _0x48d889[_0x9b14('0x96')](_0x1a8bd5);}})[_0x9b14('0x20')](function(_0x5bfa67){if(_0x5bfa67){return _0x5bfa67?{'count':_0x421224,'rows':_0x5bfa67}:null;}})['then'](respondWithResult(_0x165fe0,null))[_0x9b14('0x28')](handleError(_0x165fe0,null));};
\ No newline at end of file
+var _0xfab0=['field','tq.TeamId','from','team_has_chat_queues','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','sequelize','toString','QueryTypes','SELECT','every','union','value','transaction','isEmpty','userChatQueue:remove','omit','spread','userChatQueue:save','isArray','getAgents','findOne','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','path','ejs','lodash','crypto','jsforce','to-csv','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatQueue.socket','register','jayson/promise','client','request','then','info','ChatQueue,\x20%s,\x20%s','request\x20sent','error','code','message','catch','sendStatus','status','json','offset','undefined','count','Content-Range','apply','reject','save','destroy','get','UserProfileResource','end','stack','name','index','ChatQueue','rawAttributes','fieldName','type','key','model','map','keys','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','filters','filter','merge','VIRTUAL','options','rows','show','params','includeAll','include','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','ChatQueues','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','getMembers','pick','ChatQueueId','UserChatQueue','findAndCountAll','UserId','agent','chatPause','updatedAt','createdAt','format','%s/%s','SIP','getTeams','addTeams','ids','Team','User','voicePause','interface','flatMap','Agents','each','findOrCreate','forEach','emit','removeTeams','findAll','select'];(function(_0x20961b,_0x121bba){var _0x48ad1c=function(_0xe59db4){while(--_0xe59db4){_0x20961b['push'](_0x20961b['shift']());}};_0x48ad1c(++_0x121bba);}(_0xfab0,0x1e1));var _0x0fab=function(_0x29d4b5,_0x1913e2){_0x29d4b5=_0x29d4b5-0x0;var _0x3fbb01=_0xfab0[_0x29d4b5];return _0x3fbb01;};'use strict';var emlformat=require(_0x0fab('0x0'));var rimraf=require(_0x0fab('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x0fab('0x2'));var rp=require(_0x0fab('0x3'));var moment=require(_0x0fab('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x0fab('0x5'));var util=require(_0x0fab('0x6'));var path=require(_0x0fab('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x0fab('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x0fab('0x9'));var squel=require('squel');var crypto=require(_0x0fab('0xa'));var jsforce=require(_0x0fab('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x0fab('0xc'));var querystring=require('querystring');var Papa=require(_0x0fab('0xd'));var Redis=require('ioredis');var authService=require(_0x0fab('0xe'));var qs=require(_0x0fab('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x0fab('0x10'));var logger=require(_0x0fab('0x11'))(_0x0fab('0x12'));var utils=require(_0x0fab('0x13'));var config=require(_0x0fab('0x14'));var licenseUtil=require(_0x0fab('0x15'));var db=require(_0x0fab('0x16'))['db'];config[_0x0fab('0x17')]=_[_0x0fab('0x18')](config[_0x0fab('0x17')],{'host':_0x0fab('0x19'),'port':0x18eb});var socket=require(_0x0fab('0x1a'))(new Redis(config['redis']));require(_0x0fab('0x1b'))[_0x0fab('0x1c')](socket);var jayson=require(_0x0fab('0x1d'));var client=jayson[_0x0fab('0x1e')]['http']({'port':0x232a});function respondWithRpcPromise(_0x3cb473,_0xc532ed,_0x1da4c9,_0x50e0bd){return new BPromise(function(_0x37a759,_0x1e8c9c){var _0x871a34=_0x50e0bd||client;return _0x871a34[_0x0fab('0x1f')](_0x3cb473,_0x1da4c9)[_0x0fab('0x20')](function(_0x5d1743){logger[_0x0fab('0x21')](_0x0fab('0x22'),_0xc532ed,'request\x20sent');logger['debug']('ChatQueue,\x20%s,\x20%s,\x20%s',_0xc532ed,_0x0fab('0x23'),JSON['stringify'](_0x5d1743));if(_0x5d1743[_0x0fab('0x24')]){if(_0x5d1743[_0x0fab('0x24')][_0x0fab('0x25')]===0x1f4){logger['error']('ChatQueue,\x20%s,\x20%s',_0xc532ed,_0x5d1743[_0x0fab('0x24')][_0x0fab('0x26')]);return _0x1e8c9c(_0x5d1743[_0x0fab('0x24')][_0x0fab('0x26')]);}logger[_0x0fab('0x24')]('ChatQueue,\x20%s,\x20%s',_0xc532ed,_0x5d1743[_0x0fab('0x24')][_0x0fab('0x26')]);return _0x37a759(_0x5d1743['error'][_0x0fab('0x26')]);}else{logger[_0x0fab('0x21')]('ChatQueue,\x20%s,\x20%s',_0xc532ed,'request\x20sent');_0x37a759(_0x5d1743['result'][_0x0fab('0x26')]);}})[_0x0fab('0x27')](function(_0x4c23f5){logger[_0x0fab('0x24')]('ChatQueue,\x20%s,\x20%s',_0xc532ed,_0x4c23f5);_0x1e8c9c(_0x4c23f5);});});}function respondWithStatusCode(_0x163c34,_0x229b30){_0x229b30=_0x229b30||0xcc;return function(_0x23ea75){if(_0x23ea75){return _0x163c34[_0x0fab('0x28')](_0x229b30);}return _0x163c34[_0x0fab('0x29')](_0x229b30)['end']();};}function respondWithResult(_0x2788df,_0x2a61e2){_0x2a61e2=_0x2a61e2||0xc8;return function(_0x404501){if(_0x404501){return _0x2788df[_0x0fab('0x29')](_0x2a61e2)[_0x0fab('0x2a')](_0x404501);}};}function respondWithFilteredResult(_0x53e595,_0x41b638){return function(_0x16b054){if(_0x16b054){var _0x308e57=typeof _0x41b638[_0x0fab('0x2b')]==='undefined'&&typeof _0x41b638['limit']===_0x0fab('0x2c');var _0x9f6dbf=_0x16b054[_0x0fab('0x2d')];var _0x398fd7=_0x308e57?0x0:_0x41b638[_0x0fab('0x2b')];var _0x338a43=_0x308e57?_0x16b054[_0x0fab('0x2d')]:_0x41b638[_0x0fab('0x2b')]+_0x41b638['limit'];var _0x39acae;if(_0x338a43>=_0x9f6dbf){_0x338a43=_0x9f6dbf;_0x39acae=0xc8;}else{_0x39acae=0xce;}_0x53e595[_0x0fab('0x29')](_0x39acae);return _0x53e595['set'](_0x0fab('0x2e'),_0x398fd7+'-'+_0x338a43+'/'+_0x9f6dbf)[_0x0fab('0x2a')](_0x16b054);}return null;};}function patchUpdates(_0x3adea5){return function(_0x5e947f){try{jsonpatch[_0x0fab('0x2f')](_0x5e947f,_0x3adea5,!![]);}catch(_0x5929a2){return BPromise[_0x0fab('0x30')](_0x5929a2);}return _0x5e947f[_0x0fab('0x31')]();};}function saveUpdates(_0x66fffa,_0x62e53d){return function(_0x294257){if(_0x294257){return _0x294257['update'](_0x66fffa)[_0x0fab('0x20')](function(_0x23751c){return _0x23751c;});}return null;};}function removeEntity(_0x1c705d,_0x25808c){return function(_0xb527fe){if(_0xb527fe){return _0xb527fe[_0x0fab('0x32')]()[_0x0fab('0x20')](function(){var _0x1d90f5=_0xb527fe[_0x0fab('0x33')]({'plain':!![]});var _0xc69907='ChatQueues';return db[_0x0fab('0x34')]['destroy']({'where':{'type':_0xc69907,'resourceId':_0x1d90f5['id']}})[_0x0fab('0x20')](function(){return _0xb527fe;});})['then'](function(){_0x1c705d[_0x0fab('0x29')](0xcc)[_0x0fab('0x35')]();});}};}function handleEntityNotFound(_0x32156c,_0x4d00d5){return function(_0x4ee356){if(!_0x4ee356){_0x32156c[_0x0fab('0x28')](0x194);}return _0x4ee356;};}function handleError(_0x29a473,_0x1d6c94){_0x1d6c94=_0x1d6c94||0x1f4;return function(_0x301a98){logger[_0x0fab('0x24')](_0x301a98[_0x0fab('0x36')]);if(_0x301a98[_0x0fab('0x37')]){delete _0x301a98[_0x0fab('0x37')];}_0x29a473['status'](_0x1d6c94)['send'](_0x301a98);};}exports[_0x0fab('0x38')]=function(_0x435bcc,_0x570dea){var _0x3608c3={},_0x50471e={},_0x193a32={'count':0x0,'rows':[]};var _0x148a76=_['map'](db[_0x0fab('0x39')][_0x0fab('0x3a')],function(_0x15a3d2){return{'name':_0x15a3d2[_0x0fab('0x3b')],'type':_0x15a3d2[_0x0fab('0x3c')][_0x0fab('0x3d')]};});_0x50471e[_0x0fab('0x3e')]=_[_0x0fab('0x3f')](_0x148a76,'name');_0x50471e['query']=_[_0x0fab('0x40')](_0x435bcc[_0x0fab('0x41')]);_0x50471e['filters']=_[_0x0fab('0x42')](_0x50471e[_0x0fab('0x3e')],_0x50471e[_0x0fab('0x41')]);_0x3608c3[_0x0fab('0x43')]=_[_0x0fab('0x42')](_0x50471e[_0x0fab('0x3e')],qs[_0x0fab('0x44')](_0x435bcc[_0x0fab('0x41')][_0x0fab('0x44')]));_0x3608c3[_0x0fab('0x43')]=_0x3608c3[_0x0fab('0x43')][_0x0fab('0x45')]?_0x3608c3[_0x0fab('0x43')]:_0x50471e['model'];if(!_0x435bcc[_0x0fab('0x41')][_0x0fab('0x46')](_0x0fab('0x47'))){_0x3608c3['limit']=qs['limit'](_0x435bcc[_0x0fab('0x41')][_0x0fab('0x48')]);_0x3608c3[_0x0fab('0x2b')]=qs[_0x0fab('0x2b')](_0x435bcc[_0x0fab('0x41')][_0x0fab('0x2b')]);}_0x3608c3[_0x0fab('0x49')]=qs[_0x0fab('0x4a')](_0x435bcc[_0x0fab('0x41')][_0x0fab('0x4a')]);_0x3608c3[_0x0fab('0x4b')]=qs[_0x0fab('0x4c')](_['pick'](_0x435bcc[_0x0fab('0x41')],_0x50471e[_0x0fab('0x4c')]),_0x148a76);if(_0x435bcc[_0x0fab('0x41')][_0x0fab('0x4d')]){_0x3608c3[_0x0fab('0x4b')]=_[_0x0fab('0x4e')](_0x3608c3[_0x0fab('0x4b')],{'$or':_[_0x0fab('0x3f')](_0x148a76,function(_0x1c60e0){if(_0x1c60e0['type']!==_0x0fab('0x4f')){var _0x20425b={};_0x20425b[_0x1c60e0['name']]={'$like':'%'+_0x435bcc[_0x0fab('0x41')]['filter']+'%'};return _0x20425b;}})});}_0x3608c3=_[_0x0fab('0x4e')]({},_0x3608c3,_0x435bcc[_0x0fab('0x50')]);var _0x4751a1={'where':_0x3608c3['where']};return db[_0x0fab('0x39')][_0x0fab('0x2d')](_0x4751a1)[_0x0fab('0x20')](function(_0x3f5bbd){_0x193a32['count']=_0x3f5bbd;if(_0x435bcc[_0x0fab('0x41')]['includeAll']){_0x3608c3['include']=[{'all':!![]}];}return db[_0x0fab('0x39')]['findAll'](_0x3608c3);})[_0x0fab('0x20')](function(_0x55034a){_0x193a32[_0x0fab('0x51')]=_0x55034a;return _0x193a32;})[_0x0fab('0x20')](respondWithFilteredResult(_0x570dea,_0x3608c3))[_0x0fab('0x27')](handleError(_0x570dea,null));};exports[_0x0fab('0x52')]=function(_0x2afb97,_0xcf571e){var _0x18f4f1={'raw':!![],'where':{'id':_0x2afb97[_0x0fab('0x53')]['id']}},_0x25c8c9={};_0x25c8c9[_0x0fab('0x3e')]=_[_0x0fab('0x40')](db[_0x0fab('0x39')]['rawAttributes']);_0x25c8c9[_0x0fab('0x41')]=_['keys'](_0x2afb97[_0x0fab('0x41')]);_0x25c8c9['filters']=_[_0x0fab('0x42')](_0x25c8c9[_0x0fab('0x3e')],_0x25c8c9[_0x0fab('0x41')]);_0x18f4f1[_0x0fab('0x43')]=_['intersection'](_0x25c8c9[_0x0fab('0x3e')],qs['fields'](_0x2afb97[_0x0fab('0x41')][_0x0fab('0x44')]));_0x18f4f1[_0x0fab('0x43')]=_0x18f4f1[_0x0fab('0x43')][_0x0fab('0x45')]?_0x18f4f1[_0x0fab('0x43')]:_0x25c8c9['model'];if(_0x2afb97['query'][_0x0fab('0x54')]){_0x18f4f1[_0x0fab('0x55')]=[{'all':!![]}];}_0x18f4f1=_[_0x0fab('0x4e')]({},_0x18f4f1,_0x2afb97[_0x0fab('0x50')]);return db[_0x0fab('0x39')][_0x0fab('0x56')](_0x18f4f1)[_0x0fab('0x20')](handleEntityNotFound(_0xcf571e,null))[_0x0fab('0x20')](respondWithResult(_0xcf571e,null))[_0x0fab('0x27')](handleError(_0xcf571e,null));};exports[_0x0fab('0x57')]=function(_0x1ea20f,_0x3475fc){return db[_0x0fab('0x39')][_0x0fab('0x57')](_0x1ea20f[_0x0fab('0x58')],{})[_0x0fab('0x20')](function(_0x4aef11){var _0x4a6906=_0x1ea20f[_0x0fab('0x59')]['get']({'plain':!![]});if(!_0x4a6906)throw new Error(_0x0fab('0x5a'));if(_0x4a6906['role']==='user'){var _0x527f35=_0x4aef11[_0x0fab('0x33')]({'plain':!![]});var _0x3b0cb8=_0x0fab('0x5b');return db[_0x0fab('0x5c')][_0x0fab('0x56')]({'where':{'name':_0x3b0cb8,'userProfileId':_0x4a6906[_0x0fab('0x5d')]},'raw':!![]})[_0x0fab('0x20')](function(_0x374021){if(_0x374021&&_0x374021[_0x0fab('0x5e')]===0x0){return db[_0x0fab('0x34')]['create']({'name':_0x527f35[_0x0fab('0x37')],'resourceId':_0x527f35['id'],'type':_0x374021['name'],'sectionId':_0x374021['id']},{})['then'](function(){return _0x4aef11;});}else{return _0x4aef11;}})[_0x0fab('0x27')](function(_0x41cc55){logger[_0x0fab('0x24')](_0x0fab('0x5f'),_0x41cc55);throw _0x41cc55;});}return _0x4aef11;})[_0x0fab('0x20')](respondWithResult(_0x3475fc,0xc9))[_0x0fab('0x27')](handleError(_0x3475fc,null));};exports[_0x0fab('0x60')]=function(_0x4de2cc,_0x558059){if(_0x4de2cc[_0x0fab('0x58')]['id']){delete _0x4de2cc[_0x0fab('0x58')]['id'];}return db[_0x0fab('0x39')]['find']({'where':{'id':_0x4de2cc['params']['id']}})[_0x0fab('0x20')](handleEntityNotFound(_0x558059,null))['then'](saveUpdates(_0x4de2cc[_0x0fab('0x58')],null))['then'](respondWithResult(_0x558059,null))[_0x0fab('0x27')](handleError(_0x558059,null));};exports[_0x0fab('0x32')]=function(_0x267bf4,_0x460c80){return db[_0x0fab('0x39')][_0x0fab('0x56')]({'where':{'id':_0x267bf4[_0x0fab('0x53')]['id']}})['then'](handleEntityNotFound(_0x460c80,null))[_0x0fab('0x20')](removeEntity(_0x460c80,null))[_0x0fab('0x27')](handleError(_0x460c80,null));};exports['describe']=function(_0x2f4ee9,_0x5cc387){return db[_0x0fab('0x39')][_0x0fab('0x61')]()[_0x0fab('0x20')](respondWithResult(_0x5cc387,null))[_0x0fab('0x27')](handleError(_0x5cc387,null));};exports[_0x0fab('0x62')]=function(_0x4702d7,_0x493636,_0x257230){var _0x50f66a={'raw':!![],'where':{}},_0x2f4eed={},_0x2f09b2;return db['ChatQueue']['findOne']({'where':{'id':_0x4702d7['params']['id']}})[_0x0fab('0x20')](handleEntityNotFound(_0x493636,null))[_0x0fab('0x20')](function(_0x58d8d2){if(_0x58d8d2){_0x2f09b2=_0x58d8d2[_0x0fab('0x33')]({'plain':!![]});_0x2f4eed['model']=_[_0x0fab('0x40')](db['UserChatQueue']['rawAttributes']);_0x2f4eed[_0x0fab('0x41')]=_['keys'](_0x4702d7[_0x0fab('0x41')]);_0x2f4eed[_0x0fab('0x4c')]=_[_0x0fab('0x42')](_0x2f4eed['model'],_0x2f4eed[_0x0fab('0x41')]);_0x50f66a[_0x0fab('0x43')]=_['intersection'](_0x2f4eed[_0x0fab('0x3e')],qs['fields'](_0x4702d7[_0x0fab('0x41')]['fields']));_0x50f66a[_0x0fab('0x43')]=_0x50f66a[_0x0fab('0x43')][_0x0fab('0x45')]?_0x50f66a[_0x0fab('0x43')]:_0x2f4eed[_0x0fab('0x3e')];if(!_0x4702d7[_0x0fab('0x41')][_0x0fab('0x46')](_0x0fab('0x47'))){_0x50f66a[_0x0fab('0x48')]=qs[_0x0fab('0x48')](_0x4702d7[_0x0fab('0x41')]['limit']);_0x50f66a[_0x0fab('0x2b')]=qs[_0x0fab('0x2b')](_0x4702d7[_0x0fab('0x41')][_0x0fab('0x2b')]);}_0x50f66a[_0x0fab('0x49')]=qs[_0x0fab('0x4a')](_0x4702d7['query'][_0x0fab('0x4a')]);_0x50f66a['where']=qs[_0x0fab('0x4c')](_[_0x0fab('0x63')](_0x4702d7[_0x0fab('0x41')],_0x2f4eed[_0x0fab('0x4c')]));_0x50f66a[_0x0fab('0x4b')][_0x0fab('0x64')]=_0x58d8d2['id'];if(_0x4702d7[_0x0fab('0x41')][_0x0fab('0x4d')]){_0x50f66a[_0x0fab('0x4b')]=_['merge'](_0x50f66a[_0x0fab('0x4b')],{'$or':_[_0x0fab('0x3f')](_0x50f66a['attributes'],function(_0x48afc8){var _0x5f3186={};_0x5f3186[_0x48afc8]={'$like':'%'+_0x4702d7[_0x0fab('0x41')][_0x0fab('0x4d')]+'%'};return _0x5f3186;})});}_0x50f66a=_[_0x0fab('0x4e')]({},_0x50f66a,_0x4702d7[_0x0fab('0x50')]);return db[_0x0fab('0x65')]['findAll'](_0x50f66a);}})[_0x0fab('0x20')](function(_0x595f74){if(_0x595f74){return db['User'][_0x0fab('0x66')]({'where':{'id':_['map'](_0x595f74,_0x0fab('0x67')),'role':_0x0fab('0x68')},'attributes':['id','name',_0x0fab('0x69'),_0x0fab('0x6a'),_0x0fab('0x6b')]});}})[_0x0fab('0x20')](function(_0x1d9ac7){if(_0x1d9ac7){return{'count':_0x1d9ac7[_0x0fab('0x2d')],'rows':_[_0x0fab('0x3f')](_0x1d9ac7['rows'],function(_0x3c4e81){return{'membername':_0x3c4e81[_0x0fab('0x37')],'UserId':_0x3c4e81['id'],'queue_name':_0x2f09b2['name'],'ChatQueueId':_0x2f09b2['id'],'interface':util[_0x0fab('0x6c')](_0x0fab('0x6d'),_0x0fab('0x6e'),_0x3c4e81[_0x0fab('0x37')]),'penalty':0x0,'paused':_0x3c4e81[_0x0fab('0x69')],'createdAt':_0x3c4e81[_0x0fab('0x6b')],'updatedAt':_0x3c4e81[_0x0fab('0x6a')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x0fab('0x20')](respondWithFilteredResult(_0x493636,_0x50f66a))['catch'](handleError(_0x493636,null));};exports[_0x0fab('0x6f')]=function(_0x14b376,_0xd8b4fd,_0x10fa39){var _0x50ffc8={};var _0x5a74a0={};var _0x59a27b;var _0x895c8c;return db[_0x0fab('0x39')]['findOne']({'where':{'id':_0x14b376[_0x0fab('0x53')]['id']}})['then'](handleEntityNotFound(_0xd8b4fd,null))[_0x0fab('0x20')](function(_0x21d1dd){if(_0x21d1dd){_0x59a27b=_0x21d1dd;_0x5a74a0[_0x0fab('0x3e')]=_['keys'](db['Team'][_0x0fab('0x3a')]);_0x5a74a0[_0x0fab('0x41')]=_[_0x0fab('0x40')](_0x14b376[_0x0fab('0x41')]);_0x5a74a0[_0x0fab('0x4c')]=_['intersection'](_0x5a74a0['model'],_0x5a74a0[_0x0fab('0x41')]);_0x50ffc8[_0x0fab('0x43')]=_['intersection'](_0x5a74a0[_0x0fab('0x3e')],qs[_0x0fab('0x44')](_0x14b376[_0x0fab('0x41')][_0x0fab('0x44')]));_0x50ffc8[_0x0fab('0x43')]=_0x50ffc8['attributes']['length']?_0x50ffc8['attributes']:_0x5a74a0[_0x0fab('0x3e')];_0x50ffc8['order']=qs['sort'](_0x14b376['query']['sort']);_0x50ffc8['where']=qs[_0x0fab('0x4c')](_[_0x0fab('0x63')](_0x14b376[_0x0fab('0x41')],_0x5a74a0['filters']));if(_0x14b376['query']['filter']){_0x50ffc8[_0x0fab('0x4b')]=_['merge'](_0x50ffc8[_0x0fab('0x4b')],{'$or':_[_0x0fab('0x3f')](_0x50ffc8[_0x0fab('0x43')],function(_0x10f8bb){var _0xfd015b={};_0xfd015b[_0x10f8bb]={'$like':'%'+_0x14b376[_0x0fab('0x41')][_0x0fab('0x4d')]+'%'};return _0xfd015b;})});}_0x50ffc8=_[_0x0fab('0x4e')]({},_0x50ffc8,_0x14b376[_0x0fab('0x50')]);return _0x59a27b['getTeams'](_0x50ffc8);}})[_0x0fab('0x20')](function(_0x4c5b20){if(_0x4c5b20){_0x895c8c=_0x4c5b20[_0x0fab('0x45')];if(!_0x14b376[_0x0fab('0x41')]['hasOwnProperty'](_0x0fab('0x47'))){_0x50ffc8['limit']=qs[_0x0fab('0x48')](_0x14b376[_0x0fab('0x41')]['limit']);_0x50ffc8[_0x0fab('0x2b')]=qs[_0x0fab('0x2b')](_0x14b376[_0x0fab('0x41')][_0x0fab('0x2b')]);}return _0x59a27b['getTeams'](_0x50ffc8);}})[_0x0fab('0x20')](function(_0x2e0f2d){if(_0x2e0f2d){return _0x2e0f2d?{'count':_0x895c8c,'rows':_0x2e0f2d}:null;}})[_0x0fab('0x20')](respondWithResult(_0xd8b4fd,null))[_0x0fab('0x27')](handleError(_0xd8b4fd,null));};exports[_0x0fab('0x70')]=function(_0x294933,_0x362329,_0x2cb825){var _0x1d77a8=_0x294933[_0x0fab('0x58')][_0x0fab('0x71')];return db[_0x0fab('0x72')]['findAll']({'where':{'id':_0x1d77a8},'attributes':['id'],'include':[{'model':db[_0x0fab('0x73')],'as':'Agents','attributes':['id',_0x0fab('0x37'),'online',_0x0fab('0x74'),_0x0fab('0x75')],'raw':!![]}]})[_0x0fab('0x20')](function(_0x2adaa2){if(_0x2adaa2){var _0x2be28e=_[_0x0fab('0x76')](_0x2adaa2,function(_0x3ad2f8){var _0x3e3261=_0x3ad2f8[_0x0fab('0x33')]({'plain':!![]});return _0x3e3261[_0x0fab('0x77')];});return db['ChatQueue'][_0x0fab('0x56')]({'where':{'id':_0x294933[_0x0fab('0x53')]['id']}})['then'](function(_0x3d05a2){return db['sequelize']['transaction'](function(_0x343245){return _0x3d05a2[_0x0fab('0x70')](_0x1d77a8,{'transaction':_0x343245})[_0x0fab('0x20')](function(){return BPromise[_0x0fab('0x78')](_0x2be28e,function(_0x26cac6){return db[_0x0fab('0x65')][_0x0fab('0x79')]({'where':{'UserId':_0x26cac6['id'],'ChatQueueId':_0x294933['params']['id']},'transaction':_0x343245});});})[_0x0fab('0x20')](function(){_0x2be28e[_0x0fab('0x7a')](function(_0x568c3b){socket[_0x0fab('0x7b')]('userChatQueue:save',{'UserId':_0x568c3b['id'],'ChatQueueId':_0x3d05a2['id']});});});});});}})[_0x0fab('0x20')](respondWithStatusCode(_0x362329,null))[_0x0fab('0x27')](handleError(_0x362329,null));};exports[_0x0fab('0x7c')]=function(_0x4e284f,_0x6873a6,_0x3f6477){return db[_0x0fab('0x72')][_0x0fab('0x7d')]({'where':{'id':_0x4e284f[_0x0fab('0x41')][_0x0fab('0x71')]},'attributes':['id'],'include':[{'model':db[_0x0fab('0x73')],'as':_0x0fab('0x77'),'attributes':['id'],'raw':!![]}]})[_0x0fab('0x20')](handleEntityNotFound(_0x6873a6,null))[_0x0fab('0x20')](function(_0x25c24d){var _0x99df78=_[_0x0fab('0x3f')](_0x25c24d,'id');var _0x3d22db=[];var _0x5314e2=[];var _0x2cccf4=squel[_0x0fab('0x7e')]();_0x2cccf4[_0x0fab('0x7f')](_0x0fab('0x80'))[_0x0fab('0x81')](_0x0fab('0x82'),'tq')['join']('user_has_teams','ut',_0x0fab('0x83'))[_0x0fab('0x4b')](_0x0fab('0x84'),_0x4e284f[_0x0fab('0x53')]['id']);for(var _0x3f56a1=0x0;_0x3f56a1<_0x25c24d[_0x0fab('0x45')];_0x3f56a1+=0x1){let _0x22ab40=_0x25c24d[_0x3f56a1];for(var _0x3d6a00=0x0;_0x3d6a00<_0x22ab40[_0x0fab('0x77')][_0x0fab('0x45')];_0x3d6a00+=0x1){let _0x370247=_0x22ab40[_0x0fab('0x77')][_0x3d6a00];var _0x360f1e=_0x2cccf4[_0x0fab('0x85')]();_0x360f1e[_0x0fab('0x4b')](_0x0fab('0x86'),_0x370247['id']);_0x5314e2[_0x0fab('0x87')](db[_0x0fab('0x88')][_0x0fab('0x41')](_0x360f1e[_0x0fab('0x89')](),{'type':db[_0x0fab('0x88')][_0x0fab('0x8a')][_0x0fab('0x8b')]})[_0x0fab('0x20')](function(_0x30f257){if(_0x30f257[_0x0fab('0x45')]===0x1){return _0x370247['id'];}else{var _0x14cfbe=_[_0x0fab('0x8c')](_['map'](_0x30f257,'TeamId'),function(_0x1be216){return _['includes'](_0x99df78,_0x1be216);});if(_0x14cfbe){return _0x370247['id'];}}}));}}return BPromise['all'](_0x5314e2)[_0x0fab('0x20')](function(_0x19cb82){_0x3d22db=_(_0x3d22db)[_0x0fab('0x8d')](_0x19cb82)['compact']()[_0x0fab('0x8e')]();return db['ChatQueue'][_0x0fab('0x56')]({'where':{'id':_0x4e284f[_0x0fab('0x53')]['id']}})['then'](function(_0x29d4d3){return db[_0x0fab('0x88')][_0x0fab('0x8f')](function(_0x3c3781){return _0x29d4d3['removeTeams'](_0x4e284f[_0x0fab('0x41')][_0x0fab('0x71')],{'transaction':_0x3c3781})[_0x0fab('0x20')](function(){if(!_[_0x0fab('0x90')](_0x3d22db)){return _0x29d4d3['removeAgents'](_0x3d22db,{'transaction':_0x3c3781});}})[_0x0fab('0x20')](function(){_0x3d22db[_0x0fab('0x7a')](function(_0x47639a){socket[_0x0fab('0x7b')](_0x0fab('0x91'),{'UserId':_0x47639a,'ChatQueueId':_0x29d4d3['id']});});});});});});})[_0x0fab('0x20')](respondWithStatusCode(_0x6873a6,null))[_0x0fab('0x27')](handleError(_0x6873a6,null));};exports['addAgents']=function(_0x200a4d,_0x25653f,_0x82dbd7){return db[_0x0fab('0x39')][_0x0fab('0x56')]({'where':{'id':_0x200a4d[_0x0fab('0x53')]['id']}})['then'](handleEntityNotFound(_0x25653f,null))['then'](function(_0x3c9ffc){if(_0x3c9ffc){return _0x3c9ffc['addAgents'](_0x200a4d[_0x0fab('0x58')]['ids'],_[_0x0fab('0x92')](_0x200a4d['body'],['ids','id'])||{})[_0x0fab('0x93')](function(_0x222bea){for(var _0x132dd3=0x0;_0x132dd3<_0x200a4d['body'][_0x0fab('0x71')]['length'];_0x132dd3+=0x1){socket[_0x0fab('0x7b')](_0x0fab('0x94'),{'UserId':Number(_0x200a4d[_0x0fab('0x58')][_0x0fab('0x71')][_0x132dd3]),'ChatQueueId':Number(_0x200a4d[_0x0fab('0x53')]['id'])});}return _0x222bea;});}})['then'](respondWithResult(_0x25653f,null))[_0x0fab('0x27')](handleError(_0x25653f,null));};exports['removeAgents']=function(_0xdc652a,_0x346e71,_0x231588){return db[_0x0fab('0x39')][_0x0fab('0x56')]({'where':{'id':_0xdc652a[_0x0fab('0x53')]['id']}})[_0x0fab('0x20')](handleEntityNotFound(_0x346e71,null))['then'](function(_0x558e20){if(_0x558e20){return _0x558e20['removeAgents'](_0xdc652a[_0x0fab('0x41')]['ids'])[_0x0fab('0x20')](function(){if(_[_0x0fab('0x95')](_0xdc652a[_0x0fab('0x41')][_0x0fab('0x71')])){for(var _0x69d5a8=0x0;_0x69d5a8<_0xdc652a[_0x0fab('0x41')]['ids']['length'];_0x69d5a8+=0x1){socket[_0x0fab('0x7b')]('userChatQueue:remove',{'UserId':Number(_0xdc652a[_0x0fab('0x41')][_0x0fab('0x71')][_0x69d5a8]),'ChatQueueId':Number(_0xdc652a[_0x0fab('0x53')]['id'])});}}else{socket['emit']('userChatQueue:remove',{'UserId':Number(_0xdc652a[_0x0fab('0x41')]['ids']),'ChatQueueId':Number(_0xdc652a[_0x0fab('0x53')]['id'])});}});}})[_0x0fab('0x20')](respondWithStatusCode(_0x346e71,null))[_0x0fab('0x27')](handleError(_0x346e71,null));};exports[_0x0fab('0x96')]=function(_0x432d49,_0x3a4026,_0x3218cd){var _0x3f9c88={};var _0x466275={};var _0x2305c4;var _0x533dc5;return db[_0x0fab('0x39')][_0x0fab('0x97')]({'where':{'id':_0x432d49[_0x0fab('0x53')]['id']}})['then'](handleEntityNotFound(_0x3a4026,null))['then'](function(_0x487b55){if(_0x487b55){_0x2305c4=_0x487b55;_0x466275[_0x0fab('0x3e')]=_[_0x0fab('0x40')](db[_0x0fab('0x73')][_0x0fab('0x3a')]);_0x466275[_0x0fab('0x41')]=_['keys'](_0x432d49[_0x0fab('0x41')]);_0x466275['filters']=_[_0x0fab('0x42')](_0x466275[_0x0fab('0x3e')],_0x466275[_0x0fab('0x41')]);_0x3f9c88['attributes']=_['intersection'](_0x466275[_0x0fab('0x3e')],qs[_0x0fab('0x44')](_0x432d49[_0x0fab('0x41')][_0x0fab('0x44')]));_0x3f9c88['attributes']=_0x3f9c88[_0x0fab('0x43')][_0x0fab('0x45')]?_0x3f9c88[_0x0fab('0x43')]:_0x466275[_0x0fab('0x3e')];_0x3f9c88['order']=qs[_0x0fab('0x4a')](_0x432d49[_0x0fab('0x41')][_0x0fab('0x4a')]);_0x3f9c88[_0x0fab('0x4b')]=qs[_0x0fab('0x4c')](_[_0x0fab('0x63')](_0x432d49['query'],_0x466275[_0x0fab('0x4c')]));if(_0x432d49[_0x0fab('0x41')][_0x0fab('0x4d')]){_0x3f9c88[_0x0fab('0x4b')]=_['merge'](_0x3f9c88[_0x0fab('0x4b')],{'$or':_[_0x0fab('0x3f')](_0x3f9c88[_0x0fab('0x43')],function(_0x1d0b31){var _0xf7b654={};_0xf7b654[_0x1d0b31]={'$like':'%'+_0x432d49[_0x0fab('0x41')][_0x0fab('0x4d')]+'%'};return _0xf7b654;})});}_0x3f9c88=_[_0x0fab('0x4e')]({},_0x3f9c88,_0x432d49['options']);return _0x2305c4['getAgents'](_0x3f9c88);}})[_0x0fab('0x20')](function(_0xcecac6){if(_0xcecac6){_0x533dc5=_0xcecac6[_0x0fab('0x45')];if(!_0x432d49[_0x0fab('0x41')][_0x0fab('0x46')]('nolimit')){_0x3f9c88['limit']=qs[_0x0fab('0x48')](_0x432d49[_0x0fab('0x41')]['limit']);_0x3f9c88[_0x0fab('0x2b')]=qs[_0x0fab('0x2b')](_0x432d49[_0x0fab('0x41')][_0x0fab('0x2b')]);}return _0x2305c4[_0x0fab('0x96')](_0x3f9c88);}})[_0x0fab('0x20')](function(_0x1c2978){if(_0x1c2978){return _0x1c2978?{'count':_0x533dc5,'rows':_0x1c2978}:null;}})['then'](respondWithResult(_0x3a4026,null))[_0x0fab('0x27')](handleError(_0x3a4026,null));};
\ No newline at end of file