Built motion from commit bab6f49e.|2.6.17
[motion2.git] / server / api / chatQueue / chatQueue.controller.js
index 75f53af..be576d5 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 _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