Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / api / mailQueue / mailQueue.controller.js
index 756545e..12f86d8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7dc5=['removeTeams','select','field','tq.TeamId','from','team_has_mail_queues','join','user_has_teams','MailQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','SELECT','every','TeamId','includes','all','union','value','removeAgents','userMailQueue:remove','addAgents','spread','isArray','getAgents','bluebird','squel','../../components/parsers/qs','../../config/logger','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailQueue.socket','status','end','undefined','offset','Content-Range','json','then','destroy','get','MailQueues','UserProfileResource','sendStatus','error','stack','name','map','rawAttributes','fieldName','type','getOptions','where','count','include','query','findAll','rows','catch','show','params','keys','MailQueue','intersection','model','attributes','fields','length','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','describe','getMembers','findOne','filters','hasOwnProperty','nolimit','limit','order','sort','pick','MailQueueId','filter','merge','UserMailQueue','UserId','mailPause','updatedAt','createdAt','format','%s/%s','SIP','getTeams','Team','addTeams','ids','User','Agents','online','interface','flatMap','sequelize','transaction','each','findOrCreate','forEach','emit','userMailQueue:save'];(function(_0x4619ea,_0x29b561){var _0x1b403f=function(_0x553190){while(--_0x553190){_0x4619ea['push'](_0x4619ea['shift']());}};_0x1b403f(++_0x29b561);}(_0x7dc5,0x90));var _0x57dc=function(_0x3a3758,_0x4dd8cf){_0x3a3758=_0x3a3758-0x0;var _0x1a9234=_0x7dc5[_0x3a3758];return _0x1a9234;};'use strict';var BPromise=require(_0x57dc('0x0'));var util=require('util');var _=require('lodash');var squel=require(_0x57dc('0x1'));var Redis=require('ioredis');var qs=require(_0x57dc('0x2'));var logger=require(_0x57dc('0x3'))('api');var config=require('../../config/environment');var db=require(_0x57dc('0x4'))['db'];config[_0x57dc('0x5')]=_[_0x57dc('0x6')](config[_0x57dc('0x5')],{'host':_0x57dc('0x7'),'port':0x18eb});var socket=require(_0x57dc('0x8'))(new Redis(config['redis']));require(_0x57dc('0x9'))['register'](socket);function respondWithStatusCode(_0x46be58,_0x34f1f0){_0x34f1f0=_0x34f1f0||0xcc;return function(_0x437c98){if(_0x437c98){return _0x46be58['sendStatus'](_0x34f1f0);}return _0x46be58[_0x57dc('0xa')](_0x34f1f0)[_0x57dc('0xb')]();};}function respondWithResult(_0x20555b,_0x6db873){_0x6db873=_0x6db873||0xc8;return function(_0x6183e4){if(_0x6183e4){return _0x20555b[_0x57dc('0xa')](_0x6db873)['json'](_0x6183e4);}};}function respondWithFilteredResult(_0x4eec2b,_0x106a0c){return function(_0x202771){if(_0x202771){var _0x3226b8=typeof _0x106a0c['offset']===_0x57dc('0xc')&&typeof _0x106a0c['limit']==='undefined';var _0x45773f=_0x202771['count'];var _0x28e419=_0x3226b8?0x0:_0x106a0c['offset'];var _0x297481=_0x3226b8?_0x202771['count']:_0x106a0c[_0x57dc('0xd')]+_0x106a0c['limit'];var _0xeef558;if(_0x297481>=_0x45773f){_0x297481=_0x45773f;_0xeef558=0xc8;}else{_0xeef558=0xce;}_0x4eec2b[_0x57dc('0xa')](_0xeef558);return _0x4eec2b['set'](_0x57dc('0xe'),_0x28e419+'-'+_0x297481+'/'+_0x45773f)[_0x57dc('0xf')](_0x202771);}return null;};}function saveUpdates(_0x2d8d34){return function(_0x63629d){if(_0x63629d){return _0x63629d['update'](_0x2d8d34)[_0x57dc('0x10')](function(_0x537d85){return _0x537d85;});}return null;};}function removeEntity(_0x396533){return function(_0x16183e){if(_0x16183e){return _0x16183e[_0x57dc('0x11')]()['then'](function(){var _0x3efe4b=_0x16183e[_0x57dc('0x12')]({'plain':!![]});var _0x854348=_0x57dc('0x13');return db[_0x57dc('0x14')][_0x57dc('0x11')]({'where':{'type':_0x854348,'resourceId':_0x3efe4b['id']}})[_0x57dc('0x10')](function(){return _0x16183e;});})[_0x57dc('0x10')](function(){_0x396533[_0x57dc('0xa')](0xcc)['end']();});}};}function handleEntityNotFound(_0x440a4e){return function(_0x11599a){if(!_0x11599a){_0x440a4e[_0x57dc('0x15')](0x194);}return _0x11599a;};}function handleError(_0x4fd52d,_0x35798c){_0x35798c=_0x35798c||0x1f4;return function(_0x3f8570){logger[_0x57dc('0x16')](_0x3f8570[_0x57dc('0x17')]);if(_0x3f8570[_0x57dc('0x18')]){delete _0x3f8570[_0x57dc('0x18')];}_0x4fd52d[_0x57dc('0xa')](_0x35798c)['send'](_0x3f8570);};}exports['index']=function(_0x15767e,_0x49ef3a){var _0x34c39e={};var _0x53dbfc={'count':0x0,'rows':[]};var _0x24bafe=_[_0x57dc('0x19')](db['MailQueue'][_0x57dc('0x1a')],function(_0x2eb8d5){return{'name':_0x2eb8d5[_0x57dc('0x1b')],'type':_0x2eb8d5[_0x57dc('0x1c')]['key']};});_0x34c39e=qs[_0x57dc('0x1d')](_0x24bafe,_0x15767e);var _0x5b637a={'where':_0x34c39e[_0x57dc('0x1e')]};return db['MailQueue'][_0x57dc('0x1f')](_0x5b637a)[_0x57dc('0x10')](function(_0x41eca3){_0x53dbfc[_0x57dc('0x1f')]=_0x41eca3;_0x34c39e['include']=qs[_0x57dc('0x20')](_0x15767e[_0x57dc('0x21')]);return db['MailQueue'][_0x57dc('0x22')](_0x34c39e);})[_0x57dc('0x10')](function(_0x52b116){_0x53dbfc[_0x57dc('0x23')]=_0x52b116;return _0x53dbfc;})['then'](respondWithFilteredResult(_0x49ef3a,_0x34c39e))[_0x57dc('0x24')](handleError(_0x49ef3a,null));};exports[_0x57dc('0x25')]=function(_0x50da8b,_0x55469e){var _0x221b07={'raw':!![],'where':{'id':_0x50da8b[_0x57dc('0x26')]['id']}},_0x204703={};_0x204703['model']=_[_0x57dc('0x27')](db[_0x57dc('0x28')]['rawAttributes']);_0x204703[_0x57dc('0x21')]=_[_0x57dc('0x27')](_0x50da8b[_0x57dc('0x21')]);_0x204703['filters']=_[_0x57dc('0x29')](_0x204703[_0x57dc('0x2a')],_0x204703[_0x57dc('0x21')]);_0x221b07[_0x57dc('0x2b')]=_[_0x57dc('0x29')](_0x204703[_0x57dc('0x2a')],qs[_0x57dc('0x2c')](_0x50da8b[_0x57dc('0x21')][_0x57dc('0x2c')]));_0x221b07[_0x57dc('0x2b')]=_0x221b07['attributes'][_0x57dc('0x2d')]?_0x221b07[_0x57dc('0x2b')]:_0x204703[_0x57dc('0x2a')];if(_0x50da8b[_0x57dc('0x21')]['includeAll']){_0x221b07[_0x57dc('0x20')]=[{'all':!![]}];}_0x221b07=_['merge']({},_0x221b07,_0x50da8b[_0x57dc('0x2e')]);return db[_0x57dc('0x28')][_0x57dc('0x2f')](_0x221b07)[_0x57dc('0x10')](handleEntityNotFound(_0x55469e,null))[_0x57dc('0x10')](respondWithResult(_0x55469e,null))[_0x57dc('0x24')](handleError(_0x55469e,null));};exports[_0x57dc('0x30')]=function(_0x427af8,_0x3e4bca){return db['MailQueue'][_0x57dc('0x30')](_0x427af8[_0x57dc('0x31')],{})[_0x57dc('0x10')](function(_0x57a893){var _0x5acdb5=_0x427af8[_0x57dc('0x32')][_0x57dc('0x12')]({'plain':!![]});if(!_0x5acdb5)throw new Error(_0x57dc('0x33'));if(_0x5acdb5[_0x57dc('0x34')]===_0x57dc('0x32')){var _0x4f8bcb=_0x57a893[_0x57dc('0x12')]({'plain':!![]});var _0x50a900=_0x57dc('0x13');return db[_0x57dc('0x35')][_0x57dc('0x2f')]({'where':{'name':_0x50a900,'userProfileId':_0x5acdb5[_0x57dc('0x36')]},'raw':!![]})[_0x57dc('0x10')](function(_0x3d91a0){if(_0x3d91a0&&_0x3d91a0['autoAssociation']===0x0){return db[_0x57dc('0x14')]['create']({'name':_0x4f8bcb[_0x57dc('0x18')],'resourceId':_0x4f8bcb['id'],'type':_0x3d91a0['name'],'sectionId':_0x3d91a0['id']},{})[_0x57dc('0x10')](function(){return _0x57a893;});}else{return _0x57a893;}})[_0x57dc('0x24')](function(_0x575376){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x575376);throw _0x575376;});}return _0x57a893;})[_0x57dc('0x10')](respondWithResult(_0x3e4bca,0xc9))[_0x57dc('0x24')](handleError(_0x3e4bca,null));};exports['update']=function(_0x150167,_0x631dcb){if(_0x150167[_0x57dc('0x31')]['id']){delete _0x150167[_0x57dc('0x31')]['id'];}return db[_0x57dc('0x28')]['find']({'where':{'id':_0x150167[_0x57dc('0x26')]['id']}})['then'](handleEntityNotFound(_0x631dcb,null))[_0x57dc('0x10')](saveUpdates(_0x150167[_0x57dc('0x31')],null))[_0x57dc('0x10')](respondWithResult(_0x631dcb,null))['catch'](handleError(_0x631dcb,null));};exports[_0x57dc('0x11')]=function(_0x248594,_0x357245){return db['MailQueue'][_0x57dc('0x2f')]({'where':{'id':_0x248594[_0x57dc('0x26')]['id']}})[_0x57dc('0x10')](handleEntityNotFound(_0x357245,null))[_0x57dc('0x10')](removeEntity(_0x357245,null))['catch'](handleError(_0x357245,null));};exports[_0x57dc('0x37')]=function(_0x45b93d,_0x5590c6){return db['MailQueue']['describe']()[_0x57dc('0x10')](respondWithResult(_0x5590c6,null))[_0x57dc('0x24')](handleError(_0x5590c6,null));};exports[_0x57dc('0x38')]=function(_0x4ab347,_0x2f88e3){var _0x569c27={'raw':!![],'where':{}},_0x224725={},_0x534a86;return db[_0x57dc('0x28')][_0x57dc('0x39')]({'where':{'id':_0x4ab347['params']['id']}})['then'](handleEntityNotFound(_0x2f88e3,null))[_0x57dc('0x10')](function(_0x5212b4){if(_0x5212b4){_0x534a86=_0x5212b4[_0x57dc('0x12')]({'plain':!![]});_0x224725[_0x57dc('0x2a')]=_[_0x57dc('0x27')](db['UserMailQueue'][_0x57dc('0x1a')]);_0x224725[_0x57dc('0x21')]=_[_0x57dc('0x27')](_0x4ab347[_0x57dc('0x21')]);_0x224725[_0x57dc('0x3a')]=_[_0x57dc('0x29')](_0x224725['model'],_0x224725[_0x57dc('0x21')]);_0x569c27[_0x57dc('0x2b')]=_['intersection'](_0x224725[_0x57dc('0x2a')],qs['fields'](_0x4ab347[_0x57dc('0x21')][_0x57dc('0x2c')]));_0x569c27[_0x57dc('0x2b')]=_0x569c27[_0x57dc('0x2b')]['length']?_0x569c27[_0x57dc('0x2b')]:_0x224725[_0x57dc('0x2a')];if(!_0x4ab347[_0x57dc('0x21')][_0x57dc('0x3b')](_0x57dc('0x3c'))){_0x569c27[_0x57dc('0x3d')]=qs[_0x57dc('0x3d')](_0x4ab347[_0x57dc('0x21')]['limit']);_0x569c27['offset']=qs['offset'](_0x4ab347[_0x57dc('0x21')][_0x57dc('0xd')]);}_0x569c27[_0x57dc('0x3e')]=qs['sort'](_0x4ab347[_0x57dc('0x21')][_0x57dc('0x3f')]);_0x569c27['where']=qs['filters'](_[_0x57dc('0x40')](_0x4ab347[_0x57dc('0x21')],_0x224725[_0x57dc('0x3a')]));_0x569c27['where'][_0x57dc('0x41')]=_0x5212b4['id'];if(_0x4ab347[_0x57dc('0x21')][_0x57dc('0x42')]){_0x569c27['where']=_['merge'](_0x569c27[_0x57dc('0x1e')],{'$or':_[_0x57dc('0x19')](_0x569c27[_0x57dc('0x2b')],function(_0x2f3b3a){var _0xf84740={};_0xf84740[_0x2f3b3a]={'$like':'%'+_0x4ab347[_0x57dc('0x21')][_0x57dc('0x42')]+'%'};return _0xf84740;})});}_0x569c27=_[_0x57dc('0x43')]({},_0x569c27,_0x4ab347[_0x57dc('0x2e')]);return db[_0x57dc('0x44')]['findAll'](_0x569c27);}})[_0x57dc('0x10')](function(_0x468ebf){if(_0x468ebf){return db['User']['findAndCountAll']({'where':{'id':_['map'](_0x468ebf,_0x57dc('0x45')),'role':'agent'},'attributes':['id',_0x57dc('0x18'),_0x57dc('0x46'),_0x57dc('0x47'),_0x57dc('0x48')]});}})[_0x57dc('0x10')](function(_0x5ecdf9){if(_0x5ecdf9){return{'count':_0x5ecdf9[_0x57dc('0x1f')],'rows':_[_0x57dc('0x19')](_0x5ecdf9['rows'],function(_0x3b8321){return{'membername':_0x3b8321[_0x57dc('0x18')],'UserId':_0x3b8321['id'],'queue_name':_0x534a86['name'],'MailQueueId':_0x534a86['id'],'interface':util[_0x57dc('0x49')](_0x57dc('0x4a'),_0x57dc('0x4b'),_0x3b8321[_0x57dc('0x18')]),'penalty':0x0,'paused':_0x3b8321[_0x57dc('0x46')],'createdAt':_0x3b8321[_0x57dc('0x48')],'updatedAt':_0x3b8321[_0x57dc('0x47')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x57dc('0x10')](respondWithFilteredResult(_0x2f88e3,_0x569c27))[_0x57dc('0x24')](handleError(_0x2f88e3,null));};exports[_0x57dc('0x4c')]=function(_0x20eb5d,_0x1b98ac){var _0x2fe865={};var _0x1aa17a={};var _0x32599e;var _0x39c754;return db[_0x57dc('0x28')][_0x57dc('0x39')]({'where':{'id':_0x20eb5d[_0x57dc('0x26')]['id']}})[_0x57dc('0x10')](handleEntityNotFound(_0x1b98ac,null))['then'](function(_0x455090){if(_0x455090){_0x32599e=_0x455090;_0x1aa17a[_0x57dc('0x2a')]=_['keys'](db[_0x57dc('0x4d')]['rawAttributes']);_0x1aa17a[_0x57dc('0x21')]=_['keys'](_0x20eb5d[_0x57dc('0x21')]);_0x1aa17a[_0x57dc('0x3a')]=_['intersection'](_0x1aa17a['model'],_0x1aa17a[_0x57dc('0x21')]);_0x2fe865[_0x57dc('0x2b')]=_[_0x57dc('0x29')](_0x1aa17a[_0x57dc('0x2a')],qs[_0x57dc('0x2c')](_0x20eb5d[_0x57dc('0x21')][_0x57dc('0x2c')]));_0x2fe865[_0x57dc('0x2b')]=_0x2fe865[_0x57dc('0x2b')][_0x57dc('0x2d')]?_0x2fe865[_0x57dc('0x2b')]:_0x1aa17a[_0x57dc('0x2a')];_0x2fe865['order']=qs[_0x57dc('0x3f')](_0x20eb5d[_0x57dc('0x21')]['sort']);_0x2fe865[_0x57dc('0x1e')]=qs[_0x57dc('0x3a')](_[_0x57dc('0x40')](_0x20eb5d[_0x57dc('0x21')],_0x1aa17a[_0x57dc('0x3a')]));if(_0x20eb5d[_0x57dc('0x21')][_0x57dc('0x42')]){_0x2fe865['where']=_[_0x57dc('0x43')](_0x2fe865[_0x57dc('0x1e')],{'$or':_[_0x57dc('0x19')](_0x2fe865[_0x57dc('0x2b')],function(_0x492525){var _0xe26605={};_0xe26605[_0x492525]={'$like':'%'+_0x20eb5d['query'][_0x57dc('0x42')]+'%'};return _0xe26605;})});}_0x2fe865=_[_0x57dc('0x43')]({},_0x2fe865,_0x20eb5d[_0x57dc('0x2e')]);return _0x32599e['getTeams'](_0x2fe865);}})[_0x57dc('0x10')](function(_0x14a3fc){if(_0x14a3fc){_0x39c754=_0x14a3fc[_0x57dc('0x2d')];if(!_0x20eb5d['query'][_0x57dc('0x3b')](_0x57dc('0x3c'))){_0x2fe865['limit']=qs[_0x57dc('0x3d')](_0x20eb5d['query'][_0x57dc('0x3d')]);_0x2fe865[_0x57dc('0xd')]=qs[_0x57dc('0xd')](_0x20eb5d['query'][_0x57dc('0xd')]);}return _0x32599e[_0x57dc('0x4c')](_0x2fe865);}})[_0x57dc('0x10')](function(_0x4ad380){if(_0x4ad380){return _0x4ad380?{'count':_0x39c754,'rows':_0x4ad380}:null;}})[_0x57dc('0x10')](respondWithResult(_0x1b98ac,null))['catch'](handleError(_0x1b98ac,null));};exports[_0x57dc('0x4e')]=function(_0xd1362e,_0x53fd94){var _0x1b0c06=_0xd1362e[_0x57dc('0x31')][_0x57dc('0x4f')];return db[_0x57dc('0x4d')][_0x57dc('0x22')]({'where':{'id':_0x1b0c06},'attributes':['id'],'include':[{'model':db[_0x57dc('0x50')],'as':_0x57dc('0x51'),'attributes':['id','name',_0x57dc('0x52'),'voicePause',_0x57dc('0x53')],'raw':!![]}]})[_0x57dc('0x10')](function(_0x176ec5){if(_0x176ec5){var _0xba8669=_[_0x57dc('0x54')](_0x176ec5,function(_0x3b6de0){var _0x5efb48=_0x3b6de0[_0x57dc('0x12')]({'plain':!![]});return _0x5efb48[_0x57dc('0x51')];});return db[_0x57dc('0x28')][_0x57dc('0x2f')]({'where':{'id':_0xd1362e['params']['id']}})[_0x57dc('0x10')](function(_0x3b5c61){return db[_0x57dc('0x55')][_0x57dc('0x56')](function(_0x4cdb5b){return _0x3b5c61[_0x57dc('0x4e')](_0x1b0c06,{'transaction':_0x4cdb5b})['then'](function(){return BPromise[_0x57dc('0x57')](_0xba8669,function(_0x152703){return db['UserMailQueue'][_0x57dc('0x58')]({'where':{'UserId':_0x152703['id'],'MailQueueId':_0xd1362e[_0x57dc('0x26')]['id']},'transaction':_0x4cdb5b});});})['then'](function(){_0xba8669[_0x57dc('0x59')](function(_0x14ac2d){socket[_0x57dc('0x5a')](_0x57dc('0x5b'),{'UserId':_0x14ac2d['id'],'MailQueueId':_0x3b5c61['id']});});});});});}})['then'](respondWithStatusCode(_0x53fd94,null))[_0x57dc('0x24')](handleError(_0x53fd94,null));};exports[_0x57dc('0x5c')]=function(_0x4296d2,_0x13b11d){return db['Team']['findAll']({'where':{'id':_0x4296d2[_0x57dc('0x21')][_0x57dc('0x4f')]},'attributes':['id'],'include':[{'model':db[_0x57dc('0x50')],'as':_0x57dc('0x51'),'attributes':['id'],'raw':!![]}]})[_0x57dc('0x10')](handleEntityNotFound(_0x13b11d,null))[_0x57dc('0x10')](function(_0x5618d7){var _0x364111=_[_0x57dc('0x19')](_0x5618d7,'id');var _0x402308=[];var _0x1cc8e2=[];var _0x343f45=squel[_0x57dc('0x5d')]();_0x343f45[_0x57dc('0x5e')](_0x57dc('0x5f'))[_0x57dc('0x60')](_0x57dc('0x61'),'tq')[_0x57dc('0x62')](_0x57dc('0x63'),'ut','ut.TeamId\x20=\x20tq.TeamId')['where'](_0x57dc('0x64'),_0x4296d2[_0x57dc('0x26')]['id']);for(var _0x34cdba=0x0;_0x34cdba<_0x5618d7[_0x57dc('0x2d')];_0x34cdba+=0x1){let _0x165aaf=_0x5618d7[_0x34cdba];for(var _0xfb681d=0x0;_0xfb681d<_0x165aaf[_0x57dc('0x51')][_0x57dc('0x2d')];_0xfb681d+=0x1){let _0x164dba=_0x165aaf[_0x57dc('0x51')][_0xfb681d];var _0x46eba7=_0x343f45[_0x57dc('0x65')]();_0x46eba7[_0x57dc('0x1e')](_0x57dc('0x66'),_0x164dba['id']);_0x1cc8e2[_0x57dc('0x67')](db[_0x57dc('0x55')][_0x57dc('0x21')](_0x46eba7[_0x57dc('0x68')](),{'type':db[_0x57dc('0x55')]['QueryTypes'][_0x57dc('0x69')]})[_0x57dc('0x10')](function(_0x166bca){if(_0x166bca[_0x57dc('0x2d')]===0x1){return _0x164dba['id'];}else{var _0x4f5d11=_[_0x57dc('0x6a')](_['map'](_0x166bca,_0x57dc('0x6b')),function(_0x2e904f){return _[_0x57dc('0x6c')](_0x364111,_0x2e904f);});if(_0x4f5d11){return _0x164dba['id'];}}}));}}return BPromise[_0x57dc('0x6d')](_0x1cc8e2)[_0x57dc('0x10')](function(_0xa1cd87){_0x402308=_(_0x402308)[_0x57dc('0x6e')](_0xa1cd87)['compact']()[_0x57dc('0x6f')]();return db[_0x57dc('0x28')][_0x57dc('0x2f')]({'where':{'id':_0x4296d2[_0x57dc('0x26')]['id']}})[_0x57dc('0x10')](function(_0x24300c){return db[_0x57dc('0x55')]['transaction'](function(_0x27de3c){return _0x24300c['removeTeams'](_0x4296d2['query']['ids'],{'transaction':_0x27de3c})[_0x57dc('0x10')](function(){if(!_['isEmpty'](_0x402308)){return _0x24300c[_0x57dc('0x70')](_0x402308,{'transaction':_0x27de3c});}})[_0x57dc('0x10')](function(){_0x402308[_0x57dc('0x59')](function(_0x1b2f9c){socket[_0x57dc('0x5a')](_0x57dc('0x71'),{'UserId':_0x1b2f9c,'MailQueueId':_0x24300c['id']});});});});});});})[_0x57dc('0x10')](respondWithStatusCode(_0x13b11d,null))[_0x57dc('0x24')](handleError(_0x13b11d,null));};exports['addAgents']=function(_0x2af5ad,_0x3bd407){return db['MailQueue'][_0x57dc('0x2f')]({'where':{'id':_0x2af5ad[_0x57dc('0x26')]['id']}})[_0x57dc('0x10')](handleEntityNotFound(_0x3bd407,null))[_0x57dc('0x10')](function(_0x5a2aa7){if(_0x5a2aa7){return _0x5a2aa7[_0x57dc('0x72')](_0x2af5ad[_0x57dc('0x31')]['ids'],_['omit'](_0x2af5ad[_0x57dc('0x31')],['ids','id'])||{})[_0x57dc('0x73')](function(_0x258286){for(var _0x536367=0x0;_0x536367<_0x2af5ad[_0x57dc('0x31')]['ids'][_0x57dc('0x2d')];_0x536367+=0x1){socket[_0x57dc('0x5a')](_0x57dc('0x5b'),{'UserId':Number(_0x2af5ad[_0x57dc('0x31')][_0x57dc('0x4f')][_0x536367]),'MailQueueId':Number(_0x2af5ad[_0x57dc('0x26')]['id'])});}return _0x258286;});}})[_0x57dc('0x10')](respondWithResult(_0x3bd407,null))['catch'](handleError(_0x3bd407,null));};exports['removeAgents']=function(_0x5d95e2,_0x256813){return db[_0x57dc('0x28')]['find']({'where':{'id':_0x5d95e2[_0x57dc('0x26')]['id']}})[_0x57dc('0x10')](handleEntityNotFound(_0x256813,null))['then'](function(_0x4b81ee){if(_0x4b81ee){return _0x4b81ee[_0x57dc('0x70')](_0x5d95e2[_0x57dc('0x21')][_0x57dc('0x4f')])[_0x57dc('0x10')](function(){if(_[_0x57dc('0x74')](_0x5d95e2['query']['ids'])){for(var _0x5e5e72=0x0;_0x5e5e72<_0x5d95e2[_0x57dc('0x21')][_0x57dc('0x4f')]['length'];_0x5e5e72+=0x1){socket['emit'](_0x57dc('0x71'),{'UserId':Number(_0x5d95e2[_0x57dc('0x21')][_0x57dc('0x4f')][_0x5e5e72]),'MailQueueId':Number(_0x5d95e2['params']['id'])});}}else{socket[_0x57dc('0x5a')](_0x57dc('0x71'),{'UserId':Number(_0x5d95e2[_0x57dc('0x21')][_0x57dc('0x4f')]),'MailQueueId':Number(_0x5d95e2['params']['id'])});}});}})[_0x57dc('0x10')](respondWithStatusCode(_0x256813,null))[_0x57dc('0x24')](handleError(_0x256813,null));};exports['getAgents']=function(_0x18e6ec,_0x38ca2e){var _0x5c95c4={};var _0x94a427={};var _0x46df8d;var _0x58554c;return db[_0x57dc('0x28')][_0x57dc('0x39')]({'where':{'id':_0x18e6ec[_0x57dc('0x26')]['id']}})[_0x57dc('0x10')](handleEntityNotFound(_0x38ca2e,null))[_0x57dc('0x10')](function(_0x189cce){if(_0x189cce){_0x46df8d=_0x189cce;_0x94a427[_0x57dc('0x2a')]=_[_0x57dc('0x27')](db[_0x57dc('0x50')]['rawAttributes']);_0x94a427[_0x57dc('0x21')]=_[_0x57dc('0x27')](_0x18e6ec['query']);_0x94a427[_0x57dc('0x3a')]=_[_0x57dc('0x29')](_0x94a427[_0x57dc('0x2a')],_0x94a427['query']);_0x5c95c4['attributes']=_[_0x57dc('0x29')](_0x94a427['model'],qs[_0x57dc('0x2c')](_0x18e6ec[_0x57dc('0x21')][_0x57dc('0x2c')]));_0x5c95c4['attributes']=_0x5c95c4[_0x57dc('0x2b')]['length']?_0x5c95c4[_0x57dc('0x2b')]:_0x94a427[_0x57dc('0x2a')];_0x5c95c4[_0x57dc('0x3e')]=qs[_0x57dc('0x3f')](_0x18e6ec[_0x57dc('0x21')][_0x57dc('0x3f')]);_0x5c95c4[_0x57dc('0x1e')]=qs[_0x57dc('0x3a')](_[_0x57dc('0x40')](_0x18e6ec[_0x57dc('0x21')],_0x94a427[_0x57dc('0x3a')]));if(_0x18e6ec[_0x57dc('0x21')][_0x57dc('0x42')]){_0x5c95c4['where']=_[_0x57dc('0x43')](_0x5c95c4[_0x57dc('0x1e')],{'$or':_[_0x57dc('0x19')](_0x5c95c4[_0x57dc('0x2b')],function(_0x2f3a0b){var _0x37fc58={};_0x37fc58[_0x2f3a0b]={'$like':'%'+_0x18e6ec['query']['filter']+'%'};return _0x37fc58;})});}_0x5c95c4=_[_0x57dc('0x43')]({},_0x5c95c4,_0x18e6ec[_0x57dc('0x2e')]);return _0x46df8d[_0x57dc('0x75')](_0x5c95c4);}})[_0x57dc('0x10')](function(_0x5c5688){if(_0x5c5688){_0x58554c=_0x5c5688[_0x57dc('0x2d')];if(!_0x18e6ec[_0x57dc('0x21')][_0x57dc('0x3b')](_0x57dc('0x3c'))){_0x5c95c4[_0x57dc('0x3d')]=qs['limit'](_0x18e6ec[_0x57dc('0x21')][_0x57dc('0x3d')]);_0x5c95c4[_0x57dc('0xd')]=qs[_0x57dc('0xd')](_0x18e6ec['query']['offset']);}return _0x46df8d[_0x57dc('0x75')](_0x5c95c4);}})[_0x57dc('0x10')](function(_0x42f36a){if(_0x42f36a){return _0x42f36a?{'count':_0x58554c,'rows':_0x42f36a}:null;}})[_0x57dc('0x10')](respondWithResult(_0x38ca2e,null))[_0x57dc('0x24')](handleError(_0x38ca2e,null));};
\ No newline at end of file
+var _0xf687=['count','offset','set','Content-Range','update','then','get','MailQueues','UserProfileResource','destroy','error','stack','name','send','index','map','MailQueue','rawAttributes','fieldName','type','key','getOptions','where','include','findAll','rows','catch','show','params','model','keys','query','filters','intersection','attributes','fields','includeAll','merge','find','create','user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','getMembers','findOne','UserMailQueue','hasOwnProperty','nolimit','order','sort','pick','MailQueueId','filter','options','findAndCountAll','UserId','agent','mailPause','updatedAt','createdAt','format','%s/%s','getTeams','Team','addTeams','Agents','online','voicePause','interface','sequelize','transaction','forEach','userMailQueue:save','removeTeams','ids','field','tq.TeamId','from','join','user_has_teams','length','clone','ut.UserId\x20=\x20?','push','toString','SELECT','every','TeamId','includes','compact','isEmpty','emit','userMailQueue:remove','addAgents','omit','removeAgents','isArray','getAgents','bluebird','util','lodash','../../components/parsers/qs','api','../../mysqldb','redis','socket.io-emitter','./mailQueue.socket','register','sendStatus','status','end','json','undefined','limit'];(function(_0xf38552,_0x1fcf41){var _0x2c7528=function(_0xc81e3a){while(--_0xc81e3a){_0xf38552['push'](_0xf38552['shift']());}};_0x2c7528(++_0x1fcf41);}(_0xf687,0x155));var _0x7f68=function(_0x23d3da,_0x3ae73b){_0x23d3da=_0x23d3da-0x0;var _0x33cfcb=_0xf687[_0x23d3da];return _0x33cfcb;};'use strict';var BPromise=require(_0x7f68('0x0'));var util=require(_0x7f68('0x1'));var _=require(_0x7f68('0x2'));var squel=require('squel');var Redis=require('ioredis');var qs=require(_0x7f68('0x3'));var logger=require('../../config/logger')(_0x7f68('0x4'));var config=require('../../config/environment');var db=require(_0x7f68('0x5'))['db'];config['redis']=_['defaults'](config[_0x7f68('0x6')],{'host':'localhost','port':0x18eb});var socket=require(_0x7f68('0x7'))(new Redis(config[_0x7f68('0x6')]));require(_0x7f68('0x8'))[_0x7f68('0x9')](socket);function respondWithStatusCode(_0x208d95,_0x5af3ab){_0x5af3ab=_0x5af3ab||0xcc;return function(_0x5573fb){if(_0x5573fb){return _0x208d95[_0x7f68('0xa')](_0x5af3ab);}return _0x208d95[_0x7f68('0xb')](_0x5af3ab)[_0x7f68('0xc')]();};}function respondWithResult(_0x5349ed,_0x9aef41){_0x9aef41=_0x9aef41||0xc8;return function(_0xaafa97){if(_0xaafa97){return _0x5349ed[_0x7f68('0xb')](_0x9aef41)[_0x7f68('0xd')](_0xaafa97);}};}function respondWithFilteredResult(_0x2723a8,_0xac9e17){return function(_0x186e3f){if(_0x186e3f){var _0x5d2b1e=typeof _0xac9e17['offset']===_0x7f68('0xe')&&typeof _0xac9e17[_0x7f68('0xf')]===_0x7f68('0xe');var _0x19630c=_0x186e3f[_0x7f68('0x10')];var _0x1994ef=_0x5d2b1e?0x0:_0xac9e17[_0x7f68('0x11')];var _0x49e7e4=_0x5d2b1e?_0x186e3f[_0x7f68('0x10')]:_0xac9e17[_0x7f68('0x11')]+_0xac9e17['limit'];var _0x5b4f63;if(_0x49e7e4>=_0x19630c){_0x49e7e4=_0x19630c;_0x5b4f63=0xc8;}else{_0x5b4f63=0xce;}_0x2723a8[_0x7f68('0xb')](_0x5b4f63);return _0x2723a8[_0x7f68('0x12')](_0x7f68('0x13'),_0x1994ef+'-'+_0x49e7e4+'/'+_0x19630c)[_0x7f68('0xd')](_0x186e3f);}return null;};}function saveUpdates(_0xe7438d){return function(_0x28220d){if(_0x28220d){return _0x28220d[_0x7f68('0x14')](_0xe7438d)[_0x7f68('0x15')](function(_0x18f0c8){return _0x18f0c8;});}return null;};}function removeEntity(_0x66ab45){return function(_0x1b7628){if(_0x1b7628){return _0x1b7628['destroy']()[_0x7f68('0x15')](function(){var _0x263845=_0x1b7628[_0x7f68('0x16')]({'plain':!![]});var _0x2ca4b5=_0x7f68('0x17');return db[_0x7f68('0x18')][_0x7f68('0x19')]({'where':{'type':_0x2ca4b5,'resourceId':_0x263845['id']}})[_0x7f68('0x15')](function(){return _0x1b7628;});})[_0x7f68('0x15')](function(){_0x66ab45['status'](0xcc)[_0x7f68('0xc')]();});}};}function handleEntityNotFound(_0x5482b4){return function(_0xd58674){if(!_0xd58674){_0x5482b4[_0x7f68('0xa')](0x194);}return _0xd58674;};}function handleError(_0x1df791,_0x307223){_0x307223=_0x307223||0x1f4;return function(_0x2099e1){logger[_0x7f68('0x1a')](_0x2099e1[_0x7f68('0x1b')]);if(_0x2099e1[_0x7f68('0x1c')]){delete _0x2099e1[_0x7f68('0x1c')];}_0x1df791[_0x7f68('0xb')](_0x307223)[_0x7f68('0x1d')](_0x2099e1);};}exports[_0x7f68('0x1e')]=function(_0x487249,_0x364963){var _0x286e8e={};var _0x280ae5={'count':0x0,'rows':[]};var _0x1733bb=_[_0x7f68('0x1f')](db[_0x7f68('0x20')][_0x7f68('0x21')],function(_0x35921f){return{'name':_0x35921f[_0x7f68('0x22')],'type':_0x35921f[_0x7f68('0x23')][_0x7f68('0x24')]};});_0x286e8e=qs[_0x7f68('0x25')](_0x1733bb,_0x487249);var _0x4b3d26={'where':_0x286e8e[_0x7f68('0x26')]};return db[_0x7f68('0x20')][_0x7f68('0x10')](_0x4b3d26)[_0x7f68('0x15')](function(_0x3683b9){_0x280ae5[_0x7f68('0x10')]=_0x3683b9;_0x286e8e[_0x7f68('0x27')]=qs[_0x7f68('0x27')](_0x487249['query']);return db[_0x7f68('0x20')][_0x7f68('0x28')](_0x286e8e);})[_0x7f68('0x15')](function(_0x4b34d0){_0x280ae5[_0x7f68('0x29')]=_0x4b34d0;return _0x280ae5;})[_0x7f68('0x15')](respondWithFilteredResult(_0x364963,_0x286e8e))[_0x7f68('0x2a')](handleError(_0x364963,null));};exports[_0x7f68('0x2b')]=function(_0x293e0d,_0x104eb0){var _0x55bd57={'raw':!![],'where':{'id':_0x293e0d[_0x7f68('0x2c')]['id']}},_0x4bca8a={};_0x4bca8a[_0x7f68('0x2d')]=_[_0x7f68('0x2e')](db[_0x7f68('0x20')]['rawAttributes']);_0x4bca8a[_0x7f68('0x2f')]=_['keys'](_0x293e0d[_0x7f68('0x2f')]);_0x4bca8a[_0x7f68('0x30')]=_[_0x7f68('0x31')](_0x4bca8a['model'],_0x4bca8a[_0x7f68('0x2f')]);_0x55bd57[_0x7f68('0x32')]=_[_0x7f68('0x31')](_0x4bca8a[_0x7f68('0x2d')],qs[_0x7f68('0x33')](_0x293e0d['query'][_0x7f68('0x33')]));_0x55bd57['attributes']=_0x55bd57[_0x7f68('0x32')]['length']?_0x55bd57['attributes']:_0x4bca8a['model'];if(_0x293e0d[_0x7f68('0x2f')][_0x7f68('0x34')]){_0x55bd57['include']=[{'all':!![]}];}_0x55bd57=_[_0x7f68('0x35')]({},_0x55bd57,_0x293e0d['options']);return db['MailQueue'][_0x7f68('0x36')](_0x55bd57)[_0x7f68('0x15')](handleEntityNotFound(_0x104eb0,null))[_0x7f68('0x15')](respondWithResult(_0x104eb0,null))['catch'](handleError(_0x104eb0,null));};exports[_0x7f68('0x37')]=function(_0x4e8ff4,_0x17c315){return db[_0x7f68('0x20')]['create'](_0x4e8ff4['body'],{})[_0x7f68('0x15')](function(_0x3a873b){var _0x18edea=_0x4e8ff4[_0x7f68('0x38')][_0x7f68('0x16')]({'plain':!![]});if(!_0x18edea)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x18edea[_0x7f68('0x39')]===_0x7f68('0x38')){var _0x2da7e5=_0x3a873b[_0x7f68('0x16')]({'plain':!![]});var _0x5811e3=_0x7f68('0x17');return db[_0x7f68('0x3a')][_0x7f68('0x36')]({'where':{'name':_0x5811e3,'userProfileId':_0x18edea[_0x7f68('0x3b')]},'raw':!![]})[_0x7f68('0x15')](function(_0x428c2d){if(_0x428c2d&&_0x428c2d[_0x7f68('0x3c')]===0x0){return db['UserProfileResource']['create']({'name':_0x2da7e5[_0x7f68('0x1c')],'resourceId':_0x2da7e5['id'],'type':_0x428c2d[_0x7f68('0x1c')],'sectionId':_0x428c2d['id']},{})[_0x7f68('0x15')](function(){return _0x3a873b;});}else{return _0x3a873b;}})[_0x7f68('0x2a')](function(_0x182aeb){logger['error'](_0x7f68('0x3d'),_0x182aeb);throw _0x182aeb;});}return _0x3a873b;})[_0x7f68('0x15')](respondWithResult(_0x17c315,0xc9))['catch'](handleError(_0x17c315,null));};exports[_0x7f68('0x14')]=function(_0x4ac33e,_0x410d0b){if(_0x4ac33e[_0x7f68('0x3e')]['id']){delete _0x4ac33e['body']['id'];}return db[_0x7f68('0x20')][_0x7f68('0x36')]({'where':{'id':_0x4ac33e['params']['id']}})['then'](handleEntityNotFound(_0x410d0b,null))[_0x7f68('0x15')](saveUpdates(_0x4ac33e[_0x7f68('0x3e')],null))[_0x7f68('0x15')](respondWithResult(_0x410d0b,null))['catch'](handleError(_0x410d0b,null));};exports['destroy']=function(_0x53731,_0x45101b){return db[_0x7f68('0x20')]['find']({'where':{'id':_0x53731['params']['id']}})[_0x7f68('0x15')](handleEntityNotFound(_0x45101b,null))[_0x7f68('0x15')](removeEntity(_0x45101b,null))[_0x7f68('0x2a')](handleError(_0x45101b,null));};exports[_0x7f68('0x3f')]=function(_0x5db703,_0x30a46f){return db[_0x7f68('0x20')][_0x7f68('0x3f')]()[_0x7f68('0x15')](respondWithResult(_0x30a46f,null))['catch'](handleError(_0x30a46f,null));};exports[_0x7f68('0x40')]=function(_0x15d33d,_0x3b5f79){var _0x1a6cb0={'raw':!![],'where':{}},_0x488c0b={},_0x54abac;return db[_0x7f68('0x20')][_0x7f68('0x41')]({'where':{'id':_0x15d33d['params']['id']}})['then'](handleEntityNotFound(_0x3b5f79,null))[_0x7f68('0x15')](function(_0xcbd787){if(_0xcbd787){_0x54abac=_0xcbd787['get']({'plain':!![]});_0x488c0b['model']=_[_0x7f68('0x2e')](db[_0x7f68('0x42')][_0x7f68('0x21')]);_0x488c0b[_0x7f68('0x2f')]=_['keys'](_0x15d33d[_0x7f68('0x2f')]);_0x488c0b['filters']=_['intersection'](_0x488c0b[_0x7f68('0x2d')],_0x488c0b[_0x7f68('0x2f')]);_0x1a6cb0['attributes']=_[_0x7f68('0x31')](_0x488c0b[_0x7f68('0x2d')],qs['fields'](_0x15d33d['query'][_0x7f68('0x33')]));_0x1a6cb0[_0x7f68('0x32')]=_0x1a6cb0[_0x7f68('0x32')]['length']?_0x1a6cb0['attributes']:_0x488c0b['model'];if(!_0x15d33d[_0x7f68('0x2f')][_0x7f68('0x43')](_0x7f68('0x44'))){_0x1a6cb0[_0x7f68('0xf')]=qs[_0x7f68('0xf')](_0x15d33d[_0x7f68('0x2f')][_0x7f68('0xf')]);_0x1a6cb0[_0x7f68('0x11')]=qs[_0x7f68('0x11')](_0x15d33d[_0x7f68('0x2f')][_0x7f68('0x11')]);}_0x1a6cb0[_0x7f68('0x45')]=qs[_0x7f68('0x46')](_0x15d33d[_0x7f68('0x2f')][_0x7f68('0x46')]);_0x1a6cb0[_0x7f68('0x26')]=qs['filters'](_[_0x7f68('0x47')](_0x15d33d[_0x7f68('0x2f')],_0x488c0b['filters']));_0x1a6cb0['where'][_0x7f68('0x48')]=_0xcbd787['id'];if(_0x15d33d[_0x7f68('0x2f')][_0x7f68('0x49')]){_0x1a6cb0[_0x7f68('0x26')]=_[_0x7f68('0x35')](_0x1a6cb0[_0x7f68('0x26')],{'$or':_[_0x7f68('0x1f')](_0x1a6cb0['attributes'],function(_0x39d796){var _0x175868={};_0x175868[_0x39d796]={'$like':'%'+_0x15d33d['query'][_0x7f68('0x49')]+'%'};return _0x175868;})});}_0x1a6cb0=_[_0x7f68('0x35')]({},_0x1a6cb0,_0x15d33d[_0x7f68('0x4a')]);return db[_0x7f68('0x42')]['findAll'](_0x1a6cb0);}})[_0x7f68('0x15')](function(_0x1f6c29){if(_0x1f6c29){return db['User'][_0x7f68('0x4b')]({'where':{'id':_[_0x7f68('0x1f')](_0x1f6c29,_0x7f68('0x4c')),'role':_0x7f68('0x4d')},'attributes':['id',_0x7f68('0x1c'),_0x7f68('0x4e'),_0x7f68('0x4f'),_0x7f68('0x50')]});}})[_0x7f68('0x15')](function(_0x25f338){if(_0x25f338){return{'count':_0x25f338[_0x7f68('0x10')],'rows':_[_0x7f68('0x1f')](_0x25f338[_0x7f68('0x29')],function(_0x53b728){return{'membername':_0x53b728['name'],'UserId':_0x53b728['id'],'queue_name':_0x54abac[_0x7f68('0x1c')],'MailQueueId':_0x54abac['id'],'interface':util[_0x7f68('0x51')](_0x7f68('0x52'),'SIP',_0x53b728[_0x7f68('0x1c')]),'penalty':0x0,'paused':_0x53b728['mailPause'],'createdAt':_0x53b728['createdAt'],'updatedAt':_0x53b728[_0x7f68('0x4f')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x7f68('0x15')](respondWithFilteredResult(_0x3b5f79,_0x1a6cb0))['catch'](handleError(_0x3b5f79,null));};exports[_0x7f68('0x53')]=function(_0x3ff7c8,_0x6a60e6){var _0x1a890f={};var _0x5e839e={};var _0x520d3b;var _0x58ede8;return db[_0x7f68('0x20')][_0x7f68('0x41')]({'where':{'id':_0x3ff7c8[_0x7f68('0x2c')]['id']}})[_0x7f68('0x15')](handleEntityNotFound(_0x6a60e6,null))[_0x7f68('0x15')](function(_0x24d4d7){if(_0x24d4d7){_0x520d3b=_0x24d4d7;_0x5e839e[_0x7f68('0x2d')]=_['keys'](db[_0x7f68('0x54')][_0x7f68('0x21')]);_0x5e839e['query']=_[_0x7f68('0x2e')](_0x3ff7c8[_0x7f68('0x2f')]);_0x5e839e[_0x7f68('0x30')]=_[_0x7f68('0x31')](_0x5e839e[_0x7f68('0x2d')],_0x5e839e['query']);_0x1a890f[_0x7f68('0x32')]=_[_0x7f68('0x31')](_0x5e839e['model'],qs[_0x7f68('0x33')](_0x3ff7c8[_0x7f68('0x2f')]['fields']));_0x1a890f[_0x7f68('0x32')]=_0x1a890f[_0x7f68('0x32')]['length']?_0x1a890f['attributes']:_0x5e839e['model'];_0x1a890f[_0x7f68('0x45')]=qs[_0x7f68('0x46')](_0x3ff7c8['query'][_0x7f68('0x46')]);_0x1a890f[_0x7f68('0x26')]=qs[_0x7f68('0x30')](_[_0x7f68('0x47')](_0x3ff7c8[_0x7f68('0x2f')],_0x5e839e[_0x7f68('0x30')]));if(_0x3ff7c8['query'][_0x7f68('0x49')]){_0x1a890f[_0x7f68('0x26')]=_[_0x7f68('0x35')](_0x1a890f[_0x7f68('0x26')],{'$or':_[_0x7f68('0x1f')](_0x1a890f[_0x7f68('0x32')],function(_0x340f55){var _0x8f3d={};_0x8f3d[_0x340f55]={'$like':'%'+_0x3ff7c8['query'][_0x7f68('0x49')]+'%'};return _0x8f3d;})});}_0x1a890f=_[_0x7f68('0x35')]({},_0x1a890f,_0x3ff7c8['options']);return _0x520d3b[_0x7f68('0x53')](_0x1a890f);}})[_0x7f68('0x15')](function(_0x537ff3){if(_0x537ff3){_0x58ede8=_0x537ff3['length'];if(!_0x3ff7c8[_0x7f68('0x2f')]['hasOwnProperty'](_0x7f68('0x44'))){_0x1a890f['limit']=qs[_0x7f68('0xf')](_0x3ff7c8[_0x7f68('0x2f')][_0x7f68('0xf')]);_0x1a890f[_0x7f68('0x11')]=qs[_0x7f68('0x11')](_0x3ff7c8[_0x7f68('0x2f')][_0x7f68('0x11')]);}return _0x520d3b['getTeams'](_0x1a890f);}})[_0x7f68('0x15')](function(_0x556666){if(_0x556666){return _0x556666?{'count':_0x58ede8,'rows':_0x556666}:null;}})[_0x7f68('0x15')](respondWithResult(_0x6a60e6,null))[_0x7f68('0x2a')](handleError(_0x6a60e6,null));};exports[_0x7f68('0x55')]=function(_0x89d80b,_0x2052a0){var _0x30153b=_0x89d80b[_0x7f68('0x3e')]['ids'];return db[_0x7f68('0x54')][_0x7f68('0x28')]({'where':{'id':_0x30153b},'attributes':['id'],'include':[{'model':db['User'],'as':_0x7f68('0x56'),'attributes':['id',_0x7f68('0x1c'),_0x7f68('0x57'),_0x7f68('0x58'),_0x7f68('0x59')],'raw':!![]}]})[_0x7f68('0x15')](function(_0x1cc855){if(_0x1cc855){var _0x4c9828=_['flatMap'](_0x1cc855,function(_0x50eb6a){var _0xa5db2e=_0x50eb6a[_0x7f68('0x16')]({'plain':!![]});return _0xa5db2e['Agents'];});return db[_0x7f68('0x20')][_0x7f68('0x36')]({'where':{'id':_0x89d80b[_0x7f68('0x2c')]['id']}})[_0x7f68('0x15')](function(_0x12ee94){return db[_0x7f68('0x5a')][_0x7f68('0x5b')](function(_0x2de4ca){return _0x12ee94[_0x7f68('0x55')](_0x30153b,{'transaction':_0x2de4ca})[_0x7f68('0x15')](function(){return BPromise['each'](_0x4c9828,function(_0x16e27f){return db[_0x7f68('0x42')]['findOrCreate']({'where':{'UserId':_0x16e27f['id'],'MailQueueId':_0x89d80b[_0x7f68('0x2c')]['id']},'transaction':_0x2de4ca});});})[_0x7f68('0x15')](function(){_0x4c9828[_0x7f68('0x5c')](function(_0x1126a5){socket['emit'](_0x7f68('0x5d'),{'UserId':_0x1126a5['id'],'MailQueueId':_0x12ee94['id']});});});});});}})[_0x7f68('0x15')](respondWithStatusCode(_0x2052a0,null))[_0x7f68('0x2a')](handleError(_0x2052a0,null));};exports[_0x7f68('0x5e')]=function(_0x169270,_0x4534a3){return db[_0x7f68('0x54')][_0x7f68('0x28')]({'where':{'id':_0x169270['query'][_0x7f68('0x5f')]},'attributes':['id'],'include':[{'model':db['User'],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0x7f68('0x15')](handleEntityNotFound(_0x4534a3,null))[_0x7f68('0x15')](function(_0x45cdb3){var _0x508361=_[_0x7f68('0x1f')](_0x45cdb3,'id');var _0xea623b=[];var _0x114789=[];var _0x3b7bf2=squel['select']();_0x3b7bf2[_0x7f68('0x60')](_0x7f68('0x61'))[_0x7f68('0x62')]('team_has_mail_queues','tq')[_0x7f68('0x63')](_0x7f68('0x64'),'ut','ut.TeamId\x20=\x20tq.TeamId')[_0x7f68('0x26')]('MailQueueId\x20=\x20?',_0x169270[_0x7f68('0x2c')]['id']);for(var _0x318d6c=0x0;_0x318d6c<_0x45cdb3['length'];_0x318d6c+=0x1){let _0x304025=_0x45cdb3[_0x318d6c];for(var _0x3fba72=0x0;_0x3fba72<_0x304025['Agents'][_0x7f68('0x65')];_0x3fba72+=0x1){let _0x37db8f=_0x304025[_0x7f68('0x56')][_0x3fba72];var _0x2b50f4=_0x3b7bf2[_0x7f68('0x66')]();_0x2b50f4[_0x7f68('0x26')](_0x7f68('0x67'),_0x37db8f['id']);_0x114789[_0x7f68('0x68')](db['sequelize'][_0x7f68('0x2f')](_0x2b50f4[_0x7f68('0x69')](),{'type':db[_0x7f68('0x5a')]['QueryTypes'][_0x7f68('0x6a')]})['then'](function(_0x5622ad){if(_0x5622ad[_0x7f68('0x65')]===0x1){return _0x37db8f['id'];}else{var _0x17249d=_[_0x7f68('0x6b')](_[_0x7f68('0x1f')](_0x5622ad,_0x7f68('0x6c')),function(_0x52a6e9){return _[_0x7f68('0x6d')](_0x508361,_0x52a6e9);});if(_0x17249d){return _0x37db8f['id'];}}}));}}return BPromise['all'](_0x114789)[_0x7f68('0x15')](function(_0x556a47){_0xea623b=_(_0xea623b)['union'](_0x556a47)[_0x7f68('0x6e')]()['value']();return db[_0x7f68('0x20')][_0x7f68('0x36')]({'where':{'id':_0x169270[_0x7f68('0x2c')]['id']}})[_0x7f68('0x15')](function(_0x3b91c1){return db[_0x7f68('0x5a')][_0x7f68('0x5b')](function(_0x291b1f){return _0x3b91c1['removeTeams'](_0x169270['query'][_0x7f68('0x5f')],{'transaction':_0x291b1f})[_0x7f68('0x15')](function(){if(!_[_0x7f68('0x6f')](_0xea623b)){return _0x3b91c1['removeAgents'](_0xea623b,{'transaction':_0x291b1f});}})[_0x7f68('0x15')](function(){_0xea623b[_0x7f68('0x5c')](function(_0x3ba51b){socket[_0x7f68('0x70')](_0x7f68('0x71'),{'UserId':_0x3ba51b,'MailQueueId':_0x3b91c1['id']});});});});});});})[_0x7f68('0x15')](respondWithStatusCode(_0x4534a3,null))[_0x7f68('0x2a')](handleError(_0x4534a3,null));};exports[_0x7f68('0x72')]=function(_0x3473ad,_0x45f758){return db['MailQueue'][_0x7f68('0x36')]({'where':{'id':_0x3473ad[_0x7f68('0x2c')]['id']}})[_0x7f68('0x15')](handleEntityNotFound(_0x45f758,null))[_0x7f68('0x15')](function(_0x339b48){if(_0x339b48){return _0x339b48['addAgents'](_0x3473ad['body']['ids'],_[_0x7f68('0x73')](_0x3473ad[_0x7f68('0x3e')],[_0x7f68('0x5f'),'id'])||{})['spread'](function(_0x1cbd4f){for(var _0x9e7b76=0x0;_0x9e7b76<_0x3473ad[_0x7f68('0x3e')][_0x7f68('0x5f')][_0x7f68('0x65')];_0x9e7b76+=0x1){socket[_0x7f68('0x70')](_0x7f68('0x5d'),{'UserId':Number(_0x3473ad[_0x7f68('0x3e')][_0x7f68('0x5f')][_0x9e7b76]),'MailQueueId':Number(_0x3473ad[_0x7f68('0x2c')]['id'])});}return _0x1cbd4f;});}})[_0x7f68('0x15')](respondWithResult(_0x45f758,null))[_0x7f68('0x2a')](handleError(_0x45f758,null));};exports[_0x7f68('0x74')]=function(_0x2969cc,_0x521af4){return db[_0x7f68('0x20')][_0x7f68('0x36')]({'where':{'id':_0x2969cc[_0x7f68('0x2c')]['id']}})['then'](handleEntityNotFound(_0x521af4,null))[_0x7f68('0x15')](function(_0x13fa4c){if(_0x13fa4c){return _0x13fa4c[_0x7f68('0x74')](_0x2969cc[_0x7f68('0x2f')][_0x7f68('0x5f')])[_0x7f68('0x15')](function(){if(_[_0x7f68('0x75')](_0x2969cc[_0x7f68('0x2f')]['ids'])){for(var _0x2e1b3f=0x0;_0x2e1b3f<_0x2969cc[_0x7f68('0x2f')][_0x7f68('0x5f')][_0x7f68('0x65')];_0x2e1b3f+=0x1){socket['emit'](_0x7f68('0x71'),{'UserId':Number(_0x2969cc[_0x7f68('0x2f')]['ids'][_0x2e1b3f]),'MailQueueId':Number(_0x2969cc[_0x7f68('0x2c')]['id'])});}}else{socket[_0x7f68('0x70')](_0x7f68('0x71'),{'UserId':Number(_0x2969cc[_0x7f68('0x2f')][_0x7f68('0x5f')]),'MailQueueId':Number(_0x2969cc[_0x7f68('0x2c')]['id'])});}});}})[_0x7f68('0x15')](respondWithStatusCode(_0x521af4,null))['catch'](handleError(_0x521af4,null));};exports['getAgents']=function(_0x24e1a2,_0x181b03){var _0x19425c={};var _0x1a3fee={};var _0x31476b;var _0x516145;return db['MailQueue'][_0x7f68('0x41')]({'where':{'id':_0x24e1a2[_0x7f68('0x2c')]['id']}})[_0x7f68('0x15')](handleEntityNotFound(_0x181b03,null))[_0x7f68('0x15')](function(_0x320f81){if(_0x320f81){_0x31476b=_0x320f81;_0x1a3fee[_0x7f68('0x2d')]=_['keys'](db['User'][_0x7f68('0x21')]);_0x1a3fee['query']=_['keys'](_0x24e1a2[_0x7f68('0x2f')]);_0x1a3fee[_0x7f68('0x30')]=_[_0x7f68('0x31')](_0x1a3fee['model'],_0x1a3fee[_0x7f68('0x2f')]);_0x19425c[_0x7f68('0x32')]=_[_0x7f68('0x31')](_0x1a3fee['model'],qs['fields'](_0x24e1a2[_0x7f68('0x2f')][_0x7f68('0x33')]));_0x19425c[_0x7f68('0x32')]=_0x19425c[_0x7f68('0x32')]['length']?_0x19425c[_0x7f68('0x32')]:_0x1a3fee[_0x7f68('0x2d')];_0x19425c[_0x7f68('0x45')]=qs['sort'](_0x24e1a2[_0x7f68('0x2f')][_0x7f68('0x46')]);_0x19425c[_0x7f68('0x26')]=qs[_0x7f68('0x30')](_[_0x7f68('0x47')](_0x24e1a2[_0x7f68('0x2f')],_0x1a3fee[_0x7f68('0x30')]));if(_0x24e1a2[_0x7f68('0x2f')][_0x7f68('0x49')]){_0x19425c['where']=_[_0x7f68('0x35')](_0x19425c[_0x7f68('0x26')],{'$or':_[_0x7f68('0x1f')](_0x19425c[_0x7f68('0x32')],function(_0x17f5cd){var _0x2978c0={};_0x2978c0[_0x17f5cd]={'$like':'%'+_0x24e1a2[_0x7f68('0x2f')][_0x7f68('0x49')]+'%'};return _0x2978c0;})});}_0x19425c=_[_0x7f68('0x35')]({},_0x19425c,_0x24e1a2[_0x7f68('0x4a')]);return _0x31476b[_0x7f68('0x76')](_0x19425c);}})[_0x7f68('0x15')](function(_0x5b82cd){if(_0x5b82cd){_0x516145=_0x5b82cd[_0x7f68('0x65')];if(!_0x24e1a2[_0x7f68('0x2f')]['hasOwnProperty'](_0x7f68('0x44'))){_0x19425c[_0x7f68('0xf')]=qs[_0x7f68('0xf')](_0x24e1a2[_0x7f68('0x2f')][_0x7f68('0xf')]);_0x19425c[_0x7f68('0x11')]=qs[_0x7f68('0x11')](_0x24e1a2[_0x7f68('0x2f')]['offset']);}return _0x31476b[_0x7f68('0x76')](_0x19425c);}})[_0x7f68('0x15')](function(_0x22de1b){if(_0x22de1b){return _0x22de1b?{'count':_0x516145,'rows':_0x22de1b}:null;}})[_0x7f68('0x15')](respondWithResult(_0x181b03,null))[_0x7f68('0x2a')](handleError(_0x181b03,null));};
\ No newline at end of file