Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / mailQueue / mailQueue.controller.js
index 496f0ac..ae8b151 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3f48=['socket.io-emitter','./mailQueue.socket','register','sendStatus','status','end','json','count','offset','limit','set','Content-Range','reject','save','update','then','destroy','get','MailQueues','UserProfileResource','error','send','index','map','MailQueue','rawAttributes','type','model','name','keys','query','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','options','includeAll','include','rows','catch','show','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','getMembers','UserMailQueue','MailQueueId','merge','findAll','User','findAndCountAll','updatedAt','createdAt','format','%s/%s','mailPause','getTeams','findOne','Team','ids','Agents','flatMap','transaction','addTeams','each','findOrCreate','forEach','emit','userMailQueue:save','tq.TeamId','from','team_has_mail_queues','join','user_has_teams','MailQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','sequelize','QueryTypes','every','TeamId','includes','all','compact','value','isEmpty','removeAgents','addAgents','omit','spread','isArray','userMailQueue:remove','getAgents','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','redis','localhost'];(function(_0x7200b4,_0x3c4b55){var _0xb19924=function(_0x3430b3){while(--_0x3430b3){_0x7200b4['push'](_0x7200b4['shift']());}};_0xb19924(++_0x3c4b55);}(_0x3f48,0x17c));var _0x83f4=function(_0x26b98a,_0x24ee21){_0x26b98a=_0x26b98a-0x0;var _0x5bc294=_0x3f48[_0x26b98a];return _0x5bc294;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x83f4('0x0'));var zipdir=require(_0x83f4('0x1'));var jsonpatch=require(_0x83f4('0x2'));var rp=require(_0x83f4('0x3'));var moment=require('moment');var BPromise=require(_0x83f4('0x4'));var Mustache=require(_0x83f4('0x5'));var util=require('util');var path=require(_0x83f4('0x6'));var sox=require('sox');var csv=require(_0x83f4('0x7'));var ejs=require(_0x83f4('0x8'));var fs=require('fs');var _=require(_0x83f4('0x9'));var squel=require(_0x83f4('0xa'));var crypto=require(_0x83f4('0xb'));var jsforce=require(_0x83f4('0xc'));var deskjs=require(_0x83f4('0xd'));var toCsv=require(_0x83f4('0x7'));var querystring=require('querystring');var Papa=require(_0x83f4('0xe'));var Redis=require(_0x83f4('0xf'));var authService=require(_0x83f4('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x83f4('0x11'))(_0x83f4('0x12'));var utils=require(_0x83f4('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x83f4('0x14'));var db=require(_0x83f4('0x15'))['db'];config['redis']=_[_0x83f4('0x16')](config[_0x83f4('0x17')],{'host':_0x83f4('0x18'),'port':0x18eb});var socket=require(_0x83f4('0x19'))(new Redis(config[_0x83f4('0x17')]));require(_0x83f4('0x1a'))[_0x83f4('0x1b')](socket);function respondWithStatusCode(_0x48944b,_0x310374){_0x310374=_0x310374||0xcc;return function(_0x18c56d){if(_0x18c56d){return _0x48944b[_0x83f4('0x1c')](_0x310374);}return _0x48944b[_0x83f4('0x1d')](_0x310374)[_0x83f4('0x1e')]();};}function respondWithResult(_0x11dc6d,_0x4f0f62){_0x4f0f62=_0x4f0f62||0xc8;return function(_0x1b5626){if(_0x1b5626){return _0x11dc6d[_0x83f4('0x1d')](_0x4f0f62)[_0x83f4('0x1f')](_0x1b5626);}};}function respondWithFilteredResult(_0x202511,_0x10f04c){return function(_0x5db794){if(_0x5db794){var _0x1b4702=_0x5db794[_0x83f4('0x20')],_0x495305=_0x10f04c[_0x83f4('0x21')],_0x302089=_0x10f04c[_0x83f4('0x21')]+_0x10f04c[_0x83f4('0x22')],_0x3b08d8;if(_0x302089>=_0x1b4702){_0x302089=_0x1b4702;_0x3b08d8=0xc8;}else{_0x3b08d8=0xce;}_0x202511['status'](_0x3b08d8);return _0x202511[_0x83f4('0x23')](_0x83f4('0x24'),_0x495305+'-'+_0x302089+'/'+_0x1b4702)[_0x83f4('0x1f')](_0x5db794);}return null;};}function patchUpdates(_0x3e70ff){return function(_0x5bb5f1){try{jsonpatch['apply'](_0x5bb5f1,_0x3e70ff,!![]);}catch(_0x2522da){return BPromise[_0x83f4('0x25')](_0x2522da);}return _0x5bb5f1[_0x83f4('0x26')]();};}function saveUpdates(_0x3cfc10,_0x487262){return function(_0x362b6b){if(_0x362b6b){return _0x362b6b[_0x83f4('0x27')](_0x3cfc10)[_0x83f4('0x28')](function(_0x10c3b8){return _0x10c3b8;});}return null;};}function removeEntity(_0x5e4f28,_0x1ff942){return function(_0x570ec3){if(_0x570ec3){return _0x570ec3[_0x83f4('0x29')]()[_0x83f4('0x28')](function(){var _0x224d63=_0x570ec3[_0x83f4('0x2a')]({'plain':!![]});var _0x27623d=_0x83f4('0x2b');return db[_0x83f4('0x2c')][_0x83f4('0x29')]({'where':{'type':_0x27623d,'resourceId':_0x224d63['id']}})[_0x83f4('0x28')](function(){return _0x570ec3;});})[_0x83f4('0x28')](function(){_0x5e4f28[_0x83f4('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2530be,_0x4eeab6){return function(_0x5d260d){if(!_0x5d260d){_0x2530be[_0x83f4('0x1c')](0x194);}return _0x5d260d;};}function handleError(_0x5f17f5,_0x250693){_0x250693=_0x250693||0x1f4;return function(_0xbc819e){logger[_0x83f4('0x2d')](_0xbc819e['stack']);if(_0xbc819e['name']){delete _0xbc819e['name'];}_0x5f17f5[_0x83f4('0x1d')](_0x250693)[_0x83f4('0x2e')](_0xbc819e);};}exports[_0x83f4('0x2f')]=function(_0x1b48fa,_0x57fd72){var _0x29350b={},_0xb60421={},_0x28521e={'count':0x0,'rows':[]};var _0x14f6b8=_[_0x83f4('0x30')](db[_0x83f4('0x31')][_0x83f4('0x32')],function(_0x162f06){return{'name':_0x162f06['fieldName'],'type':_0x162f06[_0x83f4('0x33')]['key']};});_0xb60421[_0x83f4('0x34')]=_['map'](_0x14f6b8,_0x83f4('0x35'));_0xb60421['query']=_[_0x83f4('0x36')](_0x1b48fa[_0x83f4('0x37')]);_0xb60421['filters']=_[_0x83f4('0x38')](_0xb60421['model'],_0xb60421[_0x83f4('0x37')]);_0x29350b['attributes']=_[_0x83f4('0x38')](_0xb60421['model'],qs[_0x83f4('0x39')](_0x1b48fa[_0x83f4('0x37')][_0x83f4('0x39')]));_0x29350b[_0x83f4('0x3a')]=_0x29350b[_0x83f4('0x3a')][_0x83f4('0x3b')]?_0x29350b['attributes']:_0xb60421[_0x83f4('0x34')];if(!_0x1b48fa[_0x83f4('0x37')][_0x83f4('0x3c')](_0x83f4('0x3d'))){_0x29350b[_0x83f4('0x22')]=qs[_0x83f4('0x22')](_0x1b48fa[_0x83f4('0x37')][_0x83f4('0x22')]);_0x29350b[_0x83f4('0x21')]=qs[_0x83f4('0x21')](_0x1b48fa[_0x83f4('0x37')][_0x83f4('0x21')]);}_0x29350b[_0x83f4('0x3e')]=qs[_0x83f4('0x3f')](_0x1b48fa[_0x83f4('0x37')][_0x83f4('0x3f')]);_0x29350b[_0x83f4('0x40')]=qs[_0x83f4('0x41')](_[_0x83f4('0x42')](_0x1b48fa[_0x83f4('0x37')],_0xb60421[_0x83f4('0x41')]),_0x14f6b8);if(_0x1b48fa['query'][_0x83f4('0x43')]){_0x29350b['where']=_['merge'](_0x29350b[_0x83f4('0x40')],{'$or':_[_0x83f4('0x30')](_0x14f6b8,function(_0x452cc6){if(_0x452cc6[_0x83f4('0x33')]!=='VIRTUAL'){var _0x20566f={};_0x20566f[_0x452cc6[_0x83f4('0x35')]]={'$like':'%'+_0x1b48fa[_0x83f4('0x37')][_0x83f4('0x43')]+'%'};return _0x20566f;}})});}_0x29350b=_['merge']({},_0x29350b,_0x1b48fa[_0x83f4('0x44')]);var _0x24b091={'where':_0x29350b[_0x83f4('0x40')]};return db[_0x83f4('0x31')][_0x83f4('0x20')](_0x24b091)[_0x83f4('0x28')](function(_0x3bbdae){_0x28521e[_0x83f4('0x20')]=_0x3bbdae;if(_0x1b48fa['query'][_0x83f4('0x45')]){_0x29350b[_0x83f4('0x46')]=[{'all':!![]}];}return db['MailQueue']['findAll'](_0x29350b);})[_0x83f4('0x28')](function(_0x39a9a9){_0x28521e[_0x83f4('0x47')]=_0x39a9a9;return _0x28521e;})[_0x83f4('0x28')](respondWithFilteredResult(_0x57fd72,_0x29350b))[_0x83f4('0x48')](handleError(_0x57fd72,null));};exports[_0x83f4('0x49')]=function(_0x205881,_0x3564ce){var _0x543974={'raw':!![],'where':{'id':_0x205881['params']['id']}},_0x8a0029={};_0x8a0029[_0x83f4('0x34')]=_[_0x83f4('0x36')](db[_0x83f4('0x31')][_0x83f4('0x32')]);_0x8a0029[_0x83f4('0x37')]=_['keys'](_0x205881['query']);_0x8a0029[_0x83f4('0x41')]=_[_0x83f4('0x38')](_0x8a0029[_0x83f4('0x34')],_0x8a0029[_0x83f4('0x37')]);_0x543974[_0x83f4('0x3a')]=_['intersection'](_0x8a0029[_0x83f4('0x34')],qs[_0x83f4('0x39')](_0x205881[_0x83f4('0x37')][_0x83f4('0x39')]));_0x543974[_0x83f4('0x3a')]=_0x543974['attributes'][_0x83f4('0x3b')]?_0x543974[_0x83f4('0x3a')]:_0x8a0029[_0x83f4('0x34')];if(_0x205881['query'][_0x83f4('0x45')]){_0x543974['include']=[{'all':!![]}];}_0x543974=_['merge']({},_0x543974,_0x205881['options']);return db[_0x83f4('0x31')][_0x83f4('0x4a')](_0x543974)[_0x83f4('0x28')](handleEntityNotFound(_0x3564ce,null))[_0x83f4('0x28')](respondWithResult(_0x3564ce,null))[_0x83f4('0x48')](handleError(_0x3564ce,null));};exports[_0x83f4('0x4b')]=function(_0x48d265,_0xa35ad9){return db[_0x83f4('0x31')][_0x83f4('0x4b')](_0x48d265[_0x83f4('0x4c')],{})['then'](function(_0x47bb2d){var _0x49e769=_0x48d265[_0x83f4('0x4d')][_0x83f4('0x2a')]({'plain':!![]});if(!_0x49e769)throw new Error(_0x83f4('0x4e'));if(_0x49e769[_0x83f4('0x4f')]==='user'){var _0x3d5d61=_0x47bb2d[_0x83f4('0x2a')]({'plain':!![]});var _0x5e4d7b='MailQueues';return db[_0x83f4('0x50')][_0x83f4('0x4a')]({'where':{'name':_0x5e4d7b,'userProfileId':_0x49e769['userProfileId']},'raw':!![]})[_0x83f4('0x28')](function(_0x1bfd81){if(_0x1bfd81&&_0x1bfd81[_0x83f4('0x51')]===0x0){return db['UserProfileResource'][_0x83f4('0x4b')]({'name':_0x3d5d61[_0x83f4('0x35')],'resourceId':_0x3d5d61['id'],'type':_0x1bfd81[_0x83f4('0x35')],'sectionId':_0x1bfd81['id']},{})[_0x83f4('0x28')](function(){return _0x47bb2d;});}else{return _0x47bb2d;}})[_0x83f4('0x48')](function(_0x2e2b2f){logger[_0x83f4('0x2d')](_0x83f4('0x52'),_0x2e2b2f);throw _0x2e2b2f;});}return _0x47bb2d;})['then'](respondWithResult(_0xa35ad9,0xc9))['catch'](handleError(_0xa35ad9,null));};exports[_0x83f4('0x27')]=function(_0x113590,_0xfce4a4){if(_0x113590[_0x83f4('0x4c')]['id']){delete _0x113590['body']['id'];}return db[_0x83f4('0x31')][_0x83f4('0x4a')]({'where':{'id':_0x113590['params']['id']}})['then'](handleEntityNotFound(_0xfce4a4,null))['then'](saveUpdates(_0x113590[_0x83f4('0x4c')],null))[_0x83f4('0x28')](respondWithResult(_0xfce4a4,null))[_0x83f4('0x48')](handleError(_0xfce4a4,null));};exports[_0x83f4('0x29')]=function(_0x272691,_0x4af554){return db[_0x83f4('0x31')][_0x83f4('0x4a')]({'where':{'id':_0x272691[_0x83f4('0x53')]['id']}})['then'](handleEntityNotFound(_0x4af554,null))[_0x83f4('0x28')](removeEntity(_0x4af554,null))[_0x83f4('0x48')](handleError(_0x4af554,null));};exports[_0x83f4('0x54')]=function(_0x5f25a1,_0x587b02){return db[_0x83f4('0x31')][_0x83f4('0x54')]()['then'](respondWithResult(_0x587b02,null))[_0x83f4('0x48')](handleError(_0x587b02,null));};exports[_0x83f4('0x55')]=function(_0x2e84db,_0x52888b,_0x360396){var _0x42a1ea={'raw':!![],'where':{}},_0x301292={},_0x552621;return db[_0x83f4('0x31')]['findOne']({'where':{'id':_0x2e84db[_0x83f4('0x53')]['id']}})[_0x83f4('0x28')](handleEntityNotFound(_0x52888b,null))[_0x83f4('0x28')](function(_0x36b804){if(_0x36b804){_0x552621=_0x36b804[_0x83f4('0x2a')]({'plain':!![]});_0x301292[_0x83f4('0x34')]=_[_0x83f4('0x36')](db[_0x83f4('0x56')][_0x83f4('0x32')]);_0x301292[_0x83f4('0x37')]=_[_0x83f4('0x36')](_0x2e84db[_0x83f4('0x37')]);_0x301292[_0x83f4('0x41')]=_['intersection'](_0x301292[_0x83f4('0x34')],_0x301292['query']);_0x42a1ea['attributes']=_[_0x83f4('0x38')](_0x301292[_0x83f4('0x34')],qs['fields'](_0x2e84db[_0x83f4('0x37')][_0x83f4('0x39')]));_0x42a1ea[_0x83f4('0x3a')]=_0x42a1ea[_0x83f4('0x3a')]['length']?_0x42a1ea[_0x83f4('0x3a')]:_0x301292[_0x83f4('0x34')];if(!_0x2e84db[_0x83f4('0x37')][_0x83f4('0x3c')](_0x83f4('0x3d'))){_0x42a1ea[_0x83f4('0x22')]=qs[_0x83f4('0x22')](_0x2e84db[_0x83f4('0x37')][_0x83f4('0x22')]);_0x42a1ea['offset']=qs[_0x83f4('0x21')](_0x2e84db['query'][_0x83f4('0x21')]);}_0x42a1ea[_0x83f4('0x3e')]=qs[_0x83f4('0x3f')](_0x2e84db[_0x83f4('0x37')]['sort']);_0x42a1ea['where']=qs[_0x83f4('0x41')](_[_0x83f4('0x42')](_0x2e84db[_0x83f4('0x37')],_0x301292[_0x83f4('0x41')]));_0x42a1ea[_0x83f4('0x40')][_0x83f4('0x57')]=_0x36b804['id'];if(_0x2e84db[_0x83f4('0x37')][_0x83f4('0x43')]){_0x42a1ea[_0x83f4('0x40')]=_[_0x83f4('0x58')](_0x42a1ea[_0x83f4('0x40')],{'$or':_[_0x83f4('0x30')](_0x42a1ea[_0x83f4('0x3a')],function(_0x3b1a50){var _0xfa522c={};_0xfa522c[_0x3b1a50]={'$like':'%'+_0x2e84db['query'][_0x83f4('0x43')]+'%'};return _0xfa522c;})});}_0x42a1ea=_[_0x83f4('0x58')]({},_0x42a1ea,_0x2e84db[_0x83f4('0x44')]);return db[_0x83f4('0x56')][_0x83f4('0x59')](_0x42a1ea);}})[_0x83f4('0x28')](function(_0x4e9096){if(_0x4e9096){return db[_0x83f4('0x5a')][_0x83f4('0x5b')]({'where':{'id':_[_0x83f4('0x30')](_0x4e9096,'UserId'),'role':'agent'},'attributes':['id',_0x83f4('0x35'),'mailPause',_0x83f4('0x5c'),_0x83f4('0x5d')]});}})['then'](function(_0x299552){if(_0x299552){return{'count':_0x299552[_0x83f4('0x20')],'rows':_[_0x83f4('0x30')](_0x299552[_0x83f4('0x47')],function(_0x1312fb){return{'membername':_0x1312fb[_0x83f4('0x35')],'UserId':_0x1312fb['id'],'queue_name':_0x552621[_0x83f4('0x35')],'MailQueueId':_0x552621['id'],'interface':util[_0x83f4('0x5e')](_0x83f4('0x5f'),'SIP',_0x1312fb[_0x83f4('0x35')]),'penalty':0x0,'paused':_0x1312fb[_0x83f4('0x60')],'createdAt':_0x1312fb['createdAt'],'updatedAt':_0x1312fb['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0x83f4('0x28')](respondWithFilteredResult(_0x52888b,_0x42a1ea))[_0x83f4('0x48')](handleError(_0x52888b,null));};exports[_0x83f4('0x61')]=function(_0x44c26f,_0x4d518e,_0x1b3666){var _0xca39ce={};var _0x259fa2={};var _0x12efd8;var _0x5a88c8;return db[_0x83f4('0x31')][_0x83f4('0x62')]({'where':{'id':_0x44c26f[_0x83f4('0x53')]['id']}})[_0x83f4('0x28')](handleEntityNotFound(_0x4d518e,null))['then'](function(_0xa337a1){if(_0xa337a1){_0x12efd8=_0xa337a1;_0x259fa2[_0x83f4('0x34')]=_[_0x83f4('0x36')](db[_0x83f4('0x63')][_0x83f4('0x32')]);_0x259fa2[_0x83f4('0x37')]=_[_0x83f4('0x36')](_0x44c26f['query']);_0x259fa2[_0x83f4('0x41')]=_[_0x83f4('0x38')](_0x259fa2[_0x83f4('0x34')],_0x259fa2['query']);_0xca39ce[_0x83f4('0x3a')]=_[_0x83f4('0x38')](_0x259fa2[_0x83f4('0x34')],qs[_0x83f4('0x39')](_0x44c26f[_0x83f4('0x37')][_0x83f4('0x39')]));_0xca39ce[_0x83f4('0x3a')]=_0xca39ce['attributes'][_0x83f4('0x3b')]?_0xca39ce[_0x83f4('0x3a')]:_0x259fa2[_0x83f4('0x34')];_0xca39ce[_0x83f4('0x3e')]=qs['sort'](_0x44c26f[_0x83f4('0x37')][_0x83f4('0x3f')]);_0xca39ce[_0x83f4('0x40')]=qs['filters'](_['pick'](_0x44c26f['query'],_0x259fa2[_0x83f4('0x41')]));if(_0x44c26f['query']['filter']){_0xca39ce[_0x83f4('0x40')]=_[_0x83f4('0x58')](_0xca39ce[_0x83f4('0x40')],{'$or':_[_0x83f4('0x30')](_0xca39ce[_0x83f4('0x3a')],function(_0x44202a){var _0x2a42dd={};_0x2a42dd[_0x44202a]={'$like':'%'+_0x44c26f[_0x83f4('0x37')][_0x83f4('0x43')]+'%'};return _0x2a42dd;})});}_0xca39ce=_['merge']({},_0xca39ce,_0x44c26f[_0x83f4('0x44')]);return _0x12efd8[_0x83f4('0x61')](_0xca39ce);}})[_0x83f4('0x28')](function(_0x3a1355){if(_0x3a1355){_0x5a88c8=_0x3a1355[_0x83f4('0x3b')];if(!_0x44c26f[_0x83f4('0x37')][_0x83f4('0x3c')]('nolimit')){_0xca39ce[_0x83f4('0x22')]=qs[_0x83f4('0x22')](_0x44c26f[_0x83f4('0x37')][_0x83f4('0x22')]);_0xca39ce['offset']=qs['offset'](_0x44c26f['query']['offset']);}return _0x12efd8[_0x83f4('0x61')](_0xca39ce);}})[_0x83f4('0x28')](function(_0x49f63e){if(_0x49f63e){return _0x49f63e?{'count':_0x5a88c8,'rows':_0x49f63e}:null;}})[_0x83f4('0x28')](respondWithResult(_0x4d518e,null))[_0x83f4('0x48')](handleError(_0x4d518e,null));};exports['addTeams']=function(_0x1b381c,_0x19d65e,_0x13035c){var _0x40100c=_0x1b381c[_0x83f4('0x4c')][_0x83f4('0x64')];return db[_0x83f4('0x63')][_0x83f4('0x59')]({'where':{'id':_0x40100c},'attributes':['id'],'include':[{'model':db[_0x83f4('0x5a')],'as':_0x83f4('0x65'),'attributes':['id',_0x83f4('0x35'),'online','voicePause','interface'],'raw':!![]}]})['then'](function(_0x553e09){if(_0x553e09){var _0x538fbb=_[_0x83f4('0x66')](_0x553e09,function(_0x385816){var _0x1f1245=_0x385816[_0x83f4('0x2a')]({'plain':!![]});return _0x1f1245[_0x83f4('0x65')];});return db[_0x83f4('0x31')]['find']({'where':{'id':_0x1b381c[_0x83f4('0x53')]['id']}})[_0x83f4('0x28')](function(_0xb8f2c4){return db['sequelize'][_0x83f4('0x67')](function(_0x571032){return _0xb8f2c4[_0x83f4('0x68')](_0x40100c,{'transaction':_0x571032})[_0x83f4('0x28')](function(){return BPromise[_0x83f4('0x69')](_0x538fbb,function(_0x2b3201){return db[_0x83f4('0x56')][_0x83f4('0x6a')]({'where':{'UserId':_0x2b3201['id'],'MailQueueId':_0x1b381c[_0x83f4('0x53')]['id']},'transaction':_0x571032});});})['then'](function(){_0x538fbb[_0x83f4('0x6b')](function(_0x5cf383){socket[_0x83f4('0x6c')](_0x83f4('0x6d'),{'UserId':_0x5cf383['id'],'MailQueueId':_0xb8f2c4['id']});});});});});}})[_0x83f4('0x28')](respondWithStatusCode(_0x19d65e,null))[_0x83f4('0x48')](handleError(_0x19d65e,null));};exports['removeTeams']=function(_0x58156e,_0x5d75e0,_0x475dfd){return db[_0x83f4('0x63')][_0x83f4('0x59')]({'where':{'id':_0x58156e[_0x83f4('0x37')]['ids']},'attributes':['id'],'include':[{'model':db[_0x83f4('0x5a')],'as':'Agents','attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x5d75e0,null))[_0x83f4('0x28')](function(_0x2cc4b7){var _0x46247b=_[_0x83f4('0x30')](_0x2cc4b7,'id');var _0x513e9f=[];var _0xa6afd=[];var _0x12b7fd=squel['select']();_0x12b7fd['field'](_0x83f4('0x6e'))[_0x83f4('0x6f')](_0x83f4('0x70'),'tq')[_0x83f4('0x71')](_0x83f4('0x72'),'ut','ut.TeamId\x20=\x20tq.TeamId')[_0x83f4('0x40')](_0x83f4('0x73'),_0x58156e[_0x83f4('0x53')]['id']);for(var _0x331b4a=0x0;_0x331b4a<_0x2cc4b7[_0x83f4('0x3b')];_0x331b4a+=0x1){let _0x2d755a=_0x2cc4b7[_0x331b4a];for(var _0x59acd4=0x0;_0x59acd4<_0x2d755a[_0x83f4('0x65')][_0x83f4('0x3b')];_0x59acd4+=0x1){let _0x24e3d3=_0x2d755a[_0x83f4('0x65')][_0x59acd4];var _0xbfa991=_0x12b7fd[_0x83f4('0x74')]();_0xbfa991[_0x83f4('0x40')](_0x83f4('0x75'),_0x24e3d3['id']);_0xa6afd[_0x83f4('0x76')](db['sequelize']['query'](_0xbfa991['toString'](),{'type':db[_0x83f4('0x77')][_0x83f4('0x78')]['SELECT']})[_0x83f4('0x28')](function(_0xbb170d){if(_0xbb170d['length']===0x1){return _0x24e3d3['id'];}else{var _0x2a2499=_[_0x83f4('0x79')](_[_0x83f4('0x30')](_0xbb170d,_0x83f4('0x7a')),function(_0x5f2bee){return _[_0x83f4('0x7b')](_0x46247b,_0x5f2bee);});if(_0x2a2499){return _0x24e3d3['id'];}}}));}}return BPromise[_0x83f4('0x7c')](_0xa6afd)[_0x83f4('0x28')](function(_0x22aef0){_0x513e9f=_(_0x513e9f)['union'](_0x22aef0)[_0x83f4('0x7d')]()[_0x83f4('0x7e')]();return db['MailQueue'][_0x83f4('0x4a')]({'where':{'id':_0x58156e[_0x83f4('0x53')]['id']}})[_0x83f4('0x28')](function(_0x57007f){return db[_0x83f4('0x77')][_0x83f4('0x67')](function(_0x4e9aaf){return _0x57007f['removeTeams'](_0x58156e[_0x83f4('0x37')][_0x83f4('0x64')],{'transaction':_0x4e9aaf})[_0x83f4('0x28')](function(){if(!_[_0x83f4('0x7f')](_0x513e9f)){return _0x57007f[_0x83f4('0x80')](_0x513e9f,{'transaction':_0x4e9aaf});}})[_0x83f4('0x28')](function(){_0x513e9f['forEach'](function(_0x3248e4){socket['emit']('userMailQueue:remove',{'UserId':_0x3248e4,'MailQueueId':_0x57007f['id']});});});});});});})[_0x83f4('0x28')](respondWithStatusCode(_0x5d75e0,null))[_0x83f4('0x48')](handleError(_0x5d75e0,null));};exports[_0x83f4('0x81')]=function(_0x236535,_0x4cf16c,_0x10ac91){return db[_0x83f4('0x31')][_0x83f4('0x4a')]({'where':{'id':_0x236535[_0x83f4('0x53')]['id']}})[_0x83f4('0x28')](handleEntityNotFound(_0x4cf16c,null))[_0x83f4('0x28')](function(_0x3dea5f){if(_0x3dea5f){return _0x3dea5f[_0x83f4('0x81')](_0x236535[_0x83f4('0x4c')][_0x83f4('0x64')],_[_0x83f4('0x82')](_0x236535['body'],['ids','id'])||{})[_0x83f4('0x83')](function(_0x4d2276){for(var _0x368063=0x0;_0x368063<_0x236535[_0x83f4('0x4c')][_0x83f4('0x64')][_0x83f4('0x3b')];_0x368063+=0x1){socket['emit']('userMailQueue:save',{'UserId':_0x236535[_0x83f4('0x4c')][_0x83f4('0x64')][_0x368063],'MailQueueId':_0x236535[_0x83f4('0x53')]['id']});}return _0x4d2276;});}})[_0x83f4('0x28')](respondWithResult(_0x4cf16c,null))[_0x83f4('0x48')](handleError(_0x4cf16c,null));};exports['removeAgents']=function(_0x379060,_0x215030,_0x1fd8c3){return db['MailQueue'][_0x83f4('0x4a')]({'where':{'id':_0x379060[_0x83f4('0x53')]['id']}})[_0x83f4('0x28')](handleEntityNotFound(_0x215030,null))[_0x83f4('0x28')](function(_0x1c47b9){if(_0x1c47b9){return _0x1c47b9[_0x83f4('0x80')](_0x379060[_0x83f4('0x37')][_0x83f4('0x64')])['then'](function(){if(_[_0x83f4('0x84')](_0x379060[_0x83f4('0x37')][_0x83f4('0x64')])){for(var _0x398cee=0x0;_0x398cee<_0x379060[_0x83f4('0x37')][_0x83f4('0x64')]['length'];_0x398cee+=0x1){socket[_0x83f4('0x6c')]('userMailQueue:remove',{'UserId':Number(_0x379060[_0x83f4('0x37')][_0x83f4('0x64')][_0x398cee]),'MailQueueId':Number(_0x379060[_0x83f4('0x53')]['id'])});}}else{socket[_0x83f4('0x6c')](_0x83f4('0x85'),{'UserId':Number(_0x379060[_0x83f4('0x37')][_0x83f4('0x64')]),'MailQueueId':Number(_0x379060[_0x83f4('0x53')]['id'])});}});}})[_0x83f4('0x28')](respondWithStatusCode(_0x215030,null))['catch'](handleError(_0x215030,null));};exports[_0x83f4('0x86')]=function(_0x218d8f,_0x4ba3c8,_0x1081b0){var _0x335450={};var _0x2b8e6e={};var _0x597014;var _0x52eaf6;return db[_0x83f4('0x31')][_0x83f4('0x62')]({'where':{'id':_0x218d8f[_0x83f4('0x53')]['id']}})['then'](handleEntityNotFound(_0x4ba3c8,null))[_0x83f4('0x28')](function(_0x106944){if(_0x106944){_0x597014=_0x106944;_0x2b8e6e[_0x83f4('0x34')]=_['keys'](db[_0x83f4('0x5a')][_0x83f4('0x32')]);_0x2b8e6e[_0x83f4('0x37')]=_[_0x83f4('0x36')](_0x218d8f['query']);_0x2b8e6e[_0x83f4('0x41')]=_[_0x83f4('0x38')](_0x2b8e6e['model'],_0x2b8e6e[_0x83f4('0x37')]);_0x335450['attributes']=_[_0x83f4('0x38')](_0x2b8e6e[_0x83f4('0x34')],qs[_0x83f4('0x39')](_0x218d8f[_0x83f4('0x37')][_0x83f4('0x39')]));_0x335450[_0x83f4('0x3a')]=_0x335450[_0x83f4('0x3a')][_0x83f4('0x3b')]?_0x335450[_0x83f4('0x3a')]:_0x2b8e6e[_0x83f4('0x34')];_0x335450[_0x83f4('0x3e')]=qs[_0x83f4('0x3f')](_0x218d8f['query'][_0x83f4('0x3f')]);_0x335450['where']=qs[_0x83f4('0x41')](_[_0x83f4('0x42')](_0x218d8f['query'],_0x2b8e6e[_0x83f4('0x41')]));if(_0x218d8f[_0x83f4('0x37')]['filter']){_0x335450['where']=_[_0x83f4('0x58')](_0x335450[_0x83f4('0x40')],{'$or':_['map'](_0x335450[_0x83f4('0x3a')],function(_0xf77b12){var _0x3e38cc={};_0x3e38cc[_0xf77b12]={'$like':'%'+_0x218d8f['query'][_0x83f4('0x43')]+'%'};return _0x3e38cc;})});}_0x335450=_[_0x83f4('0x58')]({},_0x335450,_0x218d8f[_0x83f4('0x44')]);return _0x597014[_0x83f4('0x86')](_0x335450);}})[_0x83f4('0x28')](function(_0x19089e){if(_0x19089e){_0x52eaf6=_0x19089e[_0x83f4('0x3b')];if(!_0x218d8f[_0x83f4('0x37')][_0x83f4('0x3c')](_0x83f4('0x3d'))){_0x335450[_0x83f4('0x22')]=qs['limit'](_0x218d8f[_0x83f4('0x37')][_0x83f4('0x22')]);_0x335450[_0x83f4('0x21')]=qs[_0x83f4('0x21')](_0x218d8f[_0x83f4('0x37')][_0x83f4('0x21')]);}return _0x597014['getAgents'](_0x335450);}})[_0x83f4('0x28')](function(_0x176013){if(_0x176013){return _0x176013?{'count':_0x52eaf6,'rows':_0x176013}:null;}})[_0x83f4('0x28')](respondWithResult(_0x4ba3c8,null))[_0x83f4('0x48')](handleError(_0x4ba3c8,null));};
\ No newline at end of file
+var _0x3a67=['../../components/parsers/qs','api','../../mysqldb','redis','localhost','socket.io-emitter','register','sendStatus','status','json','offset','limit','undefined','count','set','Content-Range','update','then','get','MailQueues','UserProfileResource','destroy','end','error','stack','name','map','MailQueue','rawAttributes','type','key','getOptions','include','query','findAll','rows','catch','show','params','model','intersection','attributes','fields','length','includeAll','merge','options','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','getMembers','findOne','keys','UserMailQueue','filters','nolimit','sort','where','pick','MailQueueId','filter','User','findAndCountAll','agent','mailPause','updatedAt','format','SIP','createdAt','Team','order','getTeams','addTeams','Agents','online','voicePause','interface','flatMap','sequelize','transaction','findOrCreate','forEach','emit','userMailQueue:save','removeTeams','ids','select','field','tq.TeamId','from','team_has_mail_queues','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','MailQueueId\x20=\x20?','clone','push','toString','QueryTypes','every','TeamId','includes','all','union','compact','value','isEmpty','userMailQueue:remove','addAgents','omit','removeAgents','isArray','getAgents','hasOwnProperty','bluebird','util','lodash','squel','ioredis'];(function(_0x181ccd,_0x16c825){var _0x2df44c=function(_0xa6a905){while(--_0xa6a905){_0x181ccd['push'](_0x181ccd['shift']());}};_0x2df44c(++_0x16c825);}(_0x3a67,0x78));var _0x73a6=function(_0x29ed3e,_0x37521f){_0x29ed3e=_0x29ed3e-0x0;var _0x3b9b69=_0x3a67[_0x29ed3e];return _0x3b9b69;};'use strict';var BPromise=require(_0x73a6('0x0'));var util=require(_0x73a6('0x1'));var _=require(_0x73a6('0x2'));var squel=require(_0x73a6('0x3'));var Redis=require(_0x73a6('0x4'));var qs=require(_0x73a6('0x5'));var logger=require('../../config/logger')(_0x73a6('0x6'));var config=require('../../config/environment');var db=require(_0x73a6('0x7'))['db'];config['redis']=_['defaults'](config[_0x73a6('0x8')],{'host':_0x73a6('0x9'),'port':0x18eb});var socket=require(_0x73a6('0xa'))(new Redis(config[_0x73a6('0x8')]));require('./mailQueue.socket')[_0x73a6('0xb')](socket);function respondWithStatusCode(_0x2fcdc8,_0x22c71e){_0x22c71e=_0x22c71e||0xcc;return function(_0x545ac1){if(_0x545ac1){return _0x2fcdc8[_0x73a6('0xc')](_0x22c71e);}return _0x2fcdc8['status'](_0x22c71e)['end']();};}function respondWithResult(_0x1e6b4c,_0x51f70a){_0x51f70a=_0x51f70a||0xc8;return function(_0x22d62e){if(_0x22d62e){return _0x1e6b4c[_0x73a6('0xd')](_0x51f70a)[_0x73a6('0xe')](_0x22d62e);}};}function respondWithFilteredResult(_0x48b291,_0x2a3d8a){return function(_0xb01f5d){if(_0xb01f5d){var _0x1fdea1=typeof _0x2a3d8a[_0x73a6('0xf')]==='undefined'&&typeof _0x2a3d8a[_0x73a6('0x10')]===_0x73a6('0x11');var _0x7c3704=_0xb01f5d[_0x73a6('0x12')];var _0x2f58a3=_0x1fdea1?0x0:_0x2a3d8a['offset'];var _0x35a9fc=_0x1fdea1?_0xb01f5d['count']:_0x2a3d8a['offset']+_0x2a3d8a[_0x73a6('0x10')];var _0x46b6e0;if(_0x35a9fc>=_0x7c3704){_0x35a9fc=_0x7c3704;_0x46b6e0=0xc8;}else{_0x46b6e0=0xce;}_0x48b291['status'](_0x46b6e0);return _0x48b291[_0x73a6('0x13')](_0x73a6('0x14'),_0x2f58a3+'-'+_0x35a9fc+'/'+_0x7c3704)[_0x73a6('0xe')](_0xb01f5d);}return null;};}function saveUpdates(_0x4b1afd){return function(_0x4c73ab){if(_0x4c73ab){return _0x4c73ab[_0x73a6('0x15')](_0x4b1afd)[_0x73a6('0x16')](function(_0xc2fbb1){return _0xc2fbb1;});}return null;};}function removeEntity(_0x34f4b6){return function(_0xfd2c6a){if(_0xfd2c6a){return _0xfd2c6a['destroy']()[_0x73a6('0x16')](function(){var _0x31e3fc=_0xfd2c6a[_0x73a6('0x17')]({'plain':!![]});var _0x42b18c=_0x73a6('0x18');return db[_0x73a6('0x19')][_0x73a6('0x1a')]({'where':{'type':_0x42b18c,'resourceId':_0x31e3fc['id']}})[_0x73a6('0x16')](function(){return _0xfd2c6a;});})[_0x73a6('0x16')](function(){_0x34f4b6['status'](0xcc)[_0x73a6('0x1b')]();});}};}function handleEntityNotFound(_0x31d94d){return function(_0x118e0e){if(!_0x118e0e){_0x31d94d['sendStatus'](0x194);}return _0x118e0e;};}function handleError(_0x21d663,_0x331fc4){_0x331fc4=_0x331fc4||0x1f4;return function(_0x574111){logger[_0x73a6('0x1c')](_0x574111[_0x73a6('0x1d')]);if(_0x574111[_0x73a6('0x1e')]){delete _0x574111[_0x73a6('0x1e')];}_0x21d663[_0x73a6('0xd')](_0x331fc4)['send'](_0x574111);};}exports['index']=function(_0x5c6528,_0x37564d){var _0x50bf0d={};var _0x1268a4={'count':0x0,'rows':[]};var _0x2e9b6d=_[_0x73a6('0x1f')](db[_0x73a6('0x20')][_0x73a6('0x21')],function(_0x315616){return{'name':_0x315616['fieldName'],'type':_0x315616[_0x73a6('0x22')][_0x73a6('0x23')]};});_0x50bf0d=qs[_0x73a6('0x24')](_0x2e9b6d,_0x5c6528);var _0x25867f={'where':_0x50bf0d['where']};return db['MailQueue'][_0x73a6('0x12')](_0x25867f)[_0x73a6('0x16')](function(_0x32b727){_0x1268a4['count']=_0x32b727;_0x50bf0d['include']=qs[_0x73a6('0x25')](_0x5c6528[_0x73a6('0x26')]);return db[_0x73a6('0x20')][_0x73a6('0x27')](_0x50bf0d);})[_0x73a6('0x16')](function(_0x466c8b){_0x1268a4[_0x73a6('0x28')]=_0x466c8b;return _0x1268a4;})[_0x73a6('0x16')](respondWithFilteredResult(_0x37564d,_0x50bf0d))[_0x73a6('0x29')](handleError(_0x37564d,null));};exports[_0x73a6('0x2a')]=function(_0x4a9a78,_0x41ee32){var _0x2eb035={'raw':!![],'where':{'id':_0x4a9a78[_0x73a6('0x2b')]['id']}},_0x32d08f={};_0x32d08f[_0x73a6('0x2c')]=_['keys'](db[_0x73a6('0x20')][_0x73a6('0x21')]);_0x32d08f[_0x73a6('0x26')]=_['keys'](_0x4a9a78[_0x73a6('0x26')]);_0x32d08f['filters']=_[_0x73a6('0x2d')](_0x32d08f[_0x73a6('0x2c')],_0x32d08f[_0x73a6('0x26')]);_0x2eb035[_0x73a6('0x2e')]=_[_0x73a6('0x2d')](_0x32d08f[_0x73a6('0x2c')],qs[_0x73a6('0x2f')](_0x4a9a78[_0x73a6('0x26')][_0x73a6('0x2f')]));_0x2eb035['attributes']=_0x2eb035[_0x73a6('0x2e')][_0x73a6('0x30')]?_0x2eb035[_0x73a6('0x2e')]:_0x32d08f['model'];if(_0x4a9a78[_0x73a6('0x26')][_0x73a6('0x31')]){_0x2eb035[_0x73a6('0x25')]=[{'all':!![]}];}_0x2eb035=_[_0x73a6('0x32')]({},_0x2eb035,_0x4a9a78[_0x73a6('0x33')]);return db[_0x73a6('0x20')][_0x73a6('0x34')](_0x2eb035)[_0x73a6('0x16')](handleEntityNotFound(_0x41ee32,null))[_0x73a6('0x16')](respondWithResult(_0x41ee32,null))[_0x73a6('0x29')](handleError(_0x41ee32,null));};exports['create']=function(_0x58a42d,_0x1d5af4){return db['MailQueue'][_0x73a6('0x35')](_0x58a42d['body'],{})[_0x73a6('0x16')](function(_0x4893b6){var _0x518254=_0x58a42d[_0x73a6('0x36')][_0x73a6('0x17')]({'plain':!![]});if(!_0x518254)throw new Error(_0x73a6('0x37'));if(_0x518254['role']===_0x73a6('0x36')){var _0x17c1b9=_0x4893b6[_0x73a6('0x17')]({'plain':!![]});var _0x3376c2=_0x73a6('0x18');return db[_0x73a6('0x38')][_0x73a6('0x34')]({'where':{'name':_0x3376c2,'userProfileId':_0x518254[_0x73a6('0x39')]},'raw':!![]})[_0x73a6('0x16')](function(_0x2bb6b4){if(_0x2bb6b4&&_0x2bb6b4[_0x73a6('0x3a')]===0x0){return db['UserProfileResource'][_0x73a6('0x35')]({'name':_0x17c1b9[_0x73a6('0x1e')],'resourceId':_0x17c1b9['id'],'type':_0x2bb6b4[_0x73a6('0x1e')],'sectionId':_0x2bb6b4['id']},{})[_0x73a6('0x16')](function(){return _0x4893b6;});}else{return _0x4893b6;}})[_0x73a6('0x29')](function(_0x3ac82e){logger['error'](_0x73a6('0x3b'),_0x3ac82e);throw _0x3ac82e;});}return _0x4893b6;})[_0x73a6('0x16')](respondWithResult(_0x1d5af4,0xc9))[_0x73a6('0x29')](handleError(_0x1d5af4,null));};exports[_0x73a6('0x15')]=function(_0x178212,_0x5dd4d7){if(_0x178212['body']['id']){delete _0x178212[_0x73a6('0x3c')]['id'];}return db[_0x73a6('0x20')][_0x73a6('0x34')]({'where':{'id':_0x178212[_0x73a6('0x2b')]['id']}})[_0x73a6('0x16')](handleEntityNotFound(_0x5dd4d7,null))[_0x73a6('0x16')](saveUpdates(_0x178212[_0x73a6('0x3c')],null))[_0x73a6('0x16')](respondWithResult(_0x5dd4d7,null))[_0x73a6('0x29')](handleError(_0x5dd4d7,null));};exports[_0x73a6('0x1a')]=function(_0x391fec,_0x1f5e94){return db[_0x73a6('0x20')][_0x73a6('0x34')]({'where':{'id':_0x391fec[_0x73a6('0x2b')]['id']}})[_0x73a6('0x16')](handleEntityNotFound(_0x1f5e94,null))['then'](removeEntity(_0x1f5e94,null))[_0x73a6('0x29')](handleError(_0x1f5e94,null));};exports[_0x73a6('0x3d')]=function(_0x382166,_0x56685f){return db[_0x73a6('0x20')]['describe']()[_0x73a6('0x16')](respondWithResult(_0x56685f,null))[_0x73a6('0x29')](handleError(_0x56685f,null));};exports[_0x73a6('0x3e')]=function(_0x348284,_0x28a3fe){var _0x2f5fe5={'raw':!![],'where':{}},_0xb1a205={},_0x173eaa;return db[_0x73a6('0x20')][_0x73a6('0x3f')]({'where':{'id':_0x348284[_0x73a6('0x2b')]['id']}})[_0x73a6('0x16')](handleEntityNotFound(_0x28a3fe,null))[_0x73a6('0x16')](function(_0x1f9e0b){if(_0x1f9e0b){_0x173eaa=_0x1f9e0b[_0x73a6('0x17')]({'plain':!![]});_0xb1a205['model']=_[_0x73a6('0x40')](db[_0x73a6('0x41')][_0x73a6('0x21')]);_0xb1a205[_0x73a6('0x26')]=_[_0x73a6('0x40')](_0x348284[_0x73a6('0x26')]);_0xb1a205[_0x73a6('0x42')]=_[_0x73a6('0x2d')](_0xb1a205[_0x73a6('0x2c')],_0xb1a205['query']);_0x2f5fe5[_0x73a6('0x2e')]=_[_0x73a6('0x2d')](_0xb1a205[_0x73a6('0x2c')],qs[_0x73a6('0x2f')](_0x348284[_0x73a6('0x26')][_0x73a6('0x2f')]));_0x2f5fe5[_0x73a6('0x2e')]=_0x2f5fe5[_0x73a6('0x2e')][_0x73a6('0x30')]?_0x2f5fe5[_0x73a6('0x2e')]:_0xb1a205[_0x73a6('0x2c')];if(!_0x348284[_0x73a6('0x26')]['hasOwnProperty'](_0x73a6('0x43'))){_0x2f5fe5[_0x73a6('0x10')]=qs['limit'](_0x348284[_0x73a6('0x26')][_0x73a6('0x10')]);_0x2f5fe5['offset']=qs['offset'](_0x348284['query'][_0x73a6('0xf')]);}_0x2f5fe5['order']=qs['sort'](_0x348284['query'][_0x73a6('0x44')]);_0x2f5fe5[_0x73a6('0x45')]=qs['filters'](_[_0x73a6('0x46')](_0x348284['query'],_0xb1a205['filters']));_0x2f5fe5[_0x73a6('0x45')][_0x73a6('0x47')]=_0x1f9e0b['id'];if(_0x348284[_0x73a6('0x26')][_0x73a6('0x48')]){_0x2f5fe5['where']=_[_0x73a6('0x32')](_0x2f5fe5[_0x73a6('0x45')],{'$or':_['map'](_0x2f5fe5['attributes'],function(_0x5c0016){var _0x2cc525={};_0x2cc525[_0x5c0016]={'$like':'%'+_0x348284[_0x73a6('0x26')][_0x73a6('0x48')]+'%'};return _0x2cc525;})});}_0x2f5fe5=_[_0x73a6('0x32')]({},_0x2f5fe5,_0x348284[_0x73a6('0x33')]);return db[_0x73a6('0x41')][_0x73a6('0x27')](_0x2f5fe5);}})[_0x73a6('0x16')](function(_0x11d0bc){if(_0x11d0bc){return db[_0x73a6('0x49')][_0x73a6('0x4a')]({'where':{'id':_[_0x73a6('0x1f')](_0x11d0bc,'UserId'),'role':_0x73a6('0x4b')},'attributes':['id',_0x73a6('0x1e'),_0x73a6('0x4c'),_0x73a6('0x4d'),'createdAt']});}})[_0x73a6('0x16')](function(_0xceb2fa){if(_0xceb2fa){return{'count':_0xceb2fa[_0x73a6('0x12')],'rows':_[_0x73a6('0x1f')](_0xceb2fa[_0x73a6('0x28')],function(_0x1205f2){return{'membername':_0x1205f2[_0x73a6('0x1e')],'UserId':_0x1205f2['id'],'queue_name':_0x173eaa[_0x73a6('0x1e')],'MailQueueId':_0x173eaa['id'],'interface':util[_0x73a6('0x4e')]('%s/%s',_0x73a6('0x4f'),_0x1205f2[_0x73a6('0x1e')]),'penalty':0x0,'paused':_0x1205f2['mailPause'],'createdAt':_0x1205f2[_0x73a6('0x50')],'updatedAt':_0x1205f2[_0x73a6('0x4d')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x73a6('0x16')](respondWithFilteredResult(_0x28a3fe,_0x2f5fe5))[_0x73a6('0x29')](handleError(_0x28a3fe,null));};exports['getTeams']=function(_0x1672e5,_0x1c41c7){var _0x49c41a={};var _0x15e505={};var _0x5d9038;var _0x2b3236;return db[_0x73a6('0x20')][_0x73a6('0x3f')]({'where':{'id':_0x1672e5[_0x73a6('0x2b')]['id']}})[_0x73a6('0x16')](handleEntityNotFound(_0x1c41c7,null))[_0x73a6('0x16')](function(_0x5549b4){if(_0x5549b4){_0x5d9038=_0x5549b4;_0x15e505[_0x73a6('0x2c')]=_[_0x73a6('0x40')](db[_0x73a6('0x51')][_0x73a6('0x21')]);_0x15e505[_0x73a6('0x26')]=_['keys'](_0x1672e5['query']);_0x15e505[_0x73a6('0x42')]=_[_0x73a6('0x2d')](_0x15e505[_0x73a6('0x2c')],_0x15e505[_0x73a6('0x26')]);_0x49c41a[_0x73a6('0x2e')]=_[_0x73a6('0x2d')](_0x15e505[_0x73a6('0x2c')],qs['fields'](_0x1672e5[_0x73a6('0x26')][_0x73a6('0x2f')]));_0x49c41a[_0x73a6('0x2e')]=_0x49c41a[_0x73a6('0x2e')][_0x73a6('0x30')]?_0x49c41a[_0x73a6('0x2e')]:_0x15e505['model'];_0x49c41a[_0x73a6('0x52')]=qs[_0x73a6('0x44')](_0x1672e5[_0x73a6('0x26')][_0x73a6('0x44')]);_0x49c41a[_0x73a6('0x45')]=qs['filters'](_[_0x73a6('0x46')](_0x1672e5[_0x73a6('0x26')],_0x15e505['filters']));if(_0x1672e5[_0x73a6('0x26')][_0x73a6('0x48')]){_0x49c41a[_0x73a6('0x45')]=_[_0x73a6('0x32')](_0x49c41a[_0x73a6('0x45')],{'$or':_[_0x73a6('0x1f')](_0x49c41a[_0x73a6('0x2e')],function(_0x23ead8){var _0x49f714={};_0x49f714[_0x23ead8]={'$like':'%'+_0x1672e5['query'][_0x73a6('0x48')]+'%'};return _0x49f714;})});}_0x49c41a=_[_0x73a6('0x32')]({},_0x49c41a,_0x1672e5[_0x73a6('0x33')]);return _0x5d9038['getTeams'](_0x49c41a);}})['then'](function(_0x4d5f8f){if(_0x4d5f8f){_0x2b3236=_0x4d5f8f[_0x73a6('0x30')];if(!_0x1672e5[_0x73a6('0x26')]['hasOwnProperty'](_0x73a6('0x43'))){_0x49c41a[_0x73a6('0x10')]=qs['limit'](_0x1672e5['query'][_0x73a6('0x10')]);_0x49c41a[_0x73a6('0xf')]=qs[_0x73a6('0xf')](_0x1672e5[_0x73a6('0x26')][_0x73a6('0xf')]);}return _0x5d9038[_0x73a6('0x53')](_0x49c41a);}})[_0x73a6('0x16')](function(_0x5e7403){if(_0x5e7403){return _0x5e7403?{'count':_0x2b3236,'rows':_0x5e7403}:null;}})['then'](respondWithResult(_0x1c41c7,null))['catch'](handleError(_0x1c41c7,null));};exports[_0x73a6('0x54')]=function(_0x25e7c7,_0x2379cd){var _0x5d6a9=_0x25e7c7[_0x73a6('0x3c')]['ids'];return db['Team'][_0x73a6('0x27')]({'where':{'id':_0x5d6a9},'attributes':['id'],'include':[{'model':db['User'],'as':_0x73a6('0x55'),'attributes':['id','name',_0x73a6('0x56'),_0x73a6('0x57'),_0x73a6('0x58')],'raw':!![]}]})['then'](function(_0x36d1d0){if(_0x36d1d0){var _0x5d2967=_[_0x73a6('0x59')](_0x36d1d0,function(_0x1d8c52){var _0x2e51ac=_0x1d8c52[_0x73a6('0x17')]({'plain':!![]});return _0x2e51ac['Agents'];});return db['MailQueue']['find']({'where':{'id':_0x25e7c7[_0x73a6('0x2b')]['id']}})[_0x73a6('0x16')](function(_0x1ff3b2){return db[_0x73a6('0x5a')][_0x73a6('0x5b')](function(_0x59ba20){return _0x1ff3b2[_0x73a6('0x54')](_0x5d6a9,{'transaction':_0x59ba20})['then'](function(){return BPromise['each'](_0x5d2967,function(_0x3e4cfd){return db[_0x73a6('0x41')][_0x73a6('0x5c')]({'where':{'UserId':_0x3e4cfd['id'],'MailQueueId':_0x25e7c7[_0x73a6('0x2b')]['id']},'transaction':_0x59ba20});});})['then'](function(){_0x5d2967[_0x73a6('0x5d')](function(_0x4b4652){socket[_0x73a6('0x5e')](_0x73a6('0x5f'),{'UserId':_0x4b4652['id'],'MailQueueId':_0x1ff3b2['id']});});});});});}})['then'](respondWithStatusCode(_0x2379cd,null))[_0x73a6('0x29')](handleError(_0x2379cd,null));};exports[_0x73a6('0x60')]=function(_0x139084,_0x34dbce){return db[_0x73a6('0x51')]['findAll']({'where':{'id':_0x139084['query'][_0x73a6('0x61')]},'attributes':['id'],'include':[{'model':db['User'],'as':_0x73a6('0x55'),'attributes':['id'],'raw':!![]}]})[_0x73a6('0x16')](handleEntityNotFound(_0x34dbce,null))[_0x73a6('0x16')](function(_0x6faf3){var _0x21e7b6=_[_0x73a6('0x1f')](_0x6faf3,'id');var _0x2196c9=[];var _0x2490ab=[];var _0x9b89ee=squel[_0x73a6('0x62')]();_0x9b89ee[_0x73a6('0x63')](_0x73a6('0x64'))[_0x73a6('0x65')](_0x73a6('0x66'),'tq')['join'](_0x73a6('0x67'),'ut',_0x73a6('0x68'))[_0x73a6('0x45')](_0x73a6('0x69'),_0x139084[_0x73a6('0x2b')]['id']);for(var _0x37411f=0x0;_0x37411f<_0x6faf3[_0x73a6('0x30')];_0x37411f+=0x1){let _0x18ddbe=_0x6faf3[_0x37411f];for(var _0x2aca36=0x0;_0x2aca36<_0x18ddbe[_0x73a6('0x55')][_0x73a6('0x30')];_0x2aca36+=0x1){let _0x1dfeb9=_0x18ddbe['Agents'][_0x2aca36];var _0x154180=_0x9b89ee[_0x73a6('0x6a')]();_0x154180[_0x73a6('0x45')]('ut.UserId\x20=\x20?',_0x1dfeb9['id']);_0x2490ab[_0x73a6('0x6b')](db[_0x73a6('0x5a')][_0x73a6('0x26')](_0x154180[_0x73a6('0x6c')](),{'type':db['sequelize'][_0x73a6('0x6d')]['SELECT']})[_0x73a6('0x16')](function(_0x279fd7){if(_0x279fd7[_0x73a6('0x30')]===0x1){return _0x1dfeb9['id'];}else{var _0x4967aa=_[_0x73a6('0x6e')](_[_0x73a6('0x1f')](_0x279fd7,_0x73a6('0x6f')),function(_0x210a4d){return _[_0x73a6('0x70')](_0x21e7b6,_0x210a4d);});if(_0x4967aa){return _0x1dfeb9['id'];}}}));}}return BPromise[_0x73a6('0x71')](_0x2490ab)['then'](function(_0x2b89ef){_0x2196c9=_(_0x2196c9)[_0x73a6('0x72')](_0x2b89ef)[_0x73a6('0x73')]()[_0x73a6('0x74')]();return db[_0x73a6('0x20')][_0x73a6('0x34')]({'where':{'id':_0x139084[_0x73a6('0x2b')]['id']}})[_0x73a6('0x16')](function(_0x31cf10){return db[_0x73a6('0x5a')][_0x73a6('0x5b')](function(_0x11b218){return _0x31cf10[_0x73a6('0x60')](_0x139084['query'][_0x73a6('0x61')],{'transaction':_0x11b218})[_0x73a6('0x16')](function(){if(!_[_0x73a6('0x75')](_0x2196c9)){return _0x31cf10['removeAgents'](_0x2196c9,{'transaction':_0x11b218});}})[_0x73a6('0x16')](function(){_0x2196c9[_0x73a6('0x5d')](function(_0x477f29){socket[_0x73a6('0x5e')](_0x73a6('0x76'),{'UserId':_0x477f29,'MailQueueId':_0x31cf10['id']});});});});});});})[_0x73a6('0x16')](respondWithStatusCode(_0x34dbce,null))[_0x73a6('0x29')](handleError(_0x34dbce,null));};exports['addAgents']=function(_0x495c6a,_0x2a827a){return db[_0x73a6('0x20')][_0x73a6('0x34')]({'where':{'id':_0x495c6a[_0x73a6('0x2b')]['id']}})[_0x73a6('0x16')](handleEntityNotFound(_0x2a827a,null))['then'](function(_0x3e851a){if(_0x3e851a){return _0x3e851a[_0x73a6('0x77')](_0x495c6a[_0x73a6('0x3c')]['ids'],_[_0x73a6('0x78')](_0x495c6a['body'],[_0x73a6('0x61'),'id'])||{})['spread'](function(_0x493ff0){for(var _0x4e6add=0x0;_0x4e6add<_0x495c6a[_0x73a6('0x3c')][_0x73a6('0x61')][_0x73a6('0x30')];_0x4e6add+=0x1){socket[_0x73a6('0x5e')](_0x73a6('0x5f'),{'UserId':Number(_0x495c6a[_0x73a6('0x3c')][_0x73a6('0x61')][_0x4e6add]),'MailQueueId':Number(_0x495c6a[_0x73a6('0x2b')]['id'])});}return _0x493ff0;});}})[_0x73a6('0x16')](respondWithResult(_0x2a827a,null))[_0x73a6('0x29')](handleError(_0x2a827a,null));};exports[_0x73a6('0x79')]=function(_0x23c4e9,_0x530451){return db[_0x73a6('0x20')][_0x73a6('0x34')]({'where':{'id':_0x23c4e9[_0x73a6('0x2b')]['id']}})['then'](handleEntityNotFound(_0x530451,null))[_0x73a6('0x16')](function(_0x1dd175){if(_0x1dd175){return _0x1dd175[_0x73a6('0x79')](_0x23c4e9[_0x73a6('0x26')]['ids'])['then'](function(){if(_[_0x73a6('0x7a')](_0x23c4e9[_0x73a6('0x26')][_0x73a6('0x61')])){for(var _0x32c35b=0x0;_0x32c35b<_0x23c4e9['query'][_0x73a6('0x61')][_0x73a6('0x30')];_0x32c35b+=0x1){socket[_0x73a6('0x5e')]('userMailQueue:remove',{'UserId':Number(_0x23c4e9['query']['ids'][_0x32c35b]),'MailQueueId':Number(_0x23c4e9[_0x73a6('0x2b')]['id'])});}}else{socket['emit']('userMailQueue:remove',{'UserId':Number(_0x23c4e9['query'][_0x73a6('0x61')]),'MailQueueId':Number(_0x23c4e9[_0x73a6('0x2b')]['id'])});}});}})[_0x73a6('0x16')](respondWithStatusCode(_0x530451,null))[_0x73a6('0x29')](handleError(_0x530451,null));};exports[_0x73a6('0x7b')]=function(_0x571f14,_0x11ab3f){var _0x18b4ae={};var _0x117266={};var _0x2408ca;var _0x472b6b;return db['MailQueue'][_0x73a6('0x3f')]({'where':{'id':_0x571f14[_0x73a6('0x2b')]['id']}})['then'](handleEntityNotFound(_0x11ab3f,null))['then'](function(_0x558863){if(_0x558863){_0x2408ca=_0x558863;_0x117266['model']=_[_0x73a6('0x40')](db['User'][_0x73a6('0x21')]);_0x117266[_0x73a6('0x26')]=_[_0x73a6('0x40')](_0x571f14['query']);_0x117266[_0x73a6('0x42')]=_[_0x73a6('0x2d')](_0x117266[_0x73a6('0x2c')],_0x117266[_0x73a6('0x26')]);_0x18b4ae[_0x73a6('0x2e')]=_[_0x73a6('0x2d')](_0x117266[_0x73a6('0x2c')],qs[_0x73a6('0x2f')](_0x571f14[_0x73a6('0x26')][_0x73a6('0x2f')]));_0x18b4ae[_0x73a6('0x2e')]=_0x18b4ae[_0x73a6('0x2e')]['length']?_0x18b4ae[_0x73a6('0x2e')]:_0x117266[_0x73a6('0x2c')];_0x18b4ae[_0x73a6('0x52')]=qs[_0x73a6('0x44')](_0x571f14['query'][_0x73a6('0x44')]);_0x18b4ae[_0x73a6('0x45')]=qs['filters'](_[_0x73a6('0x46')](_0x571f14['query'],_0x117266[_0x73a6('0x42')]));if(_0x571f14[_0x73a6('0x26')][_0x73a6('0x48')]){_0x18b4ae[_0x73a6('0x45')]=_[_0x73a6('0x32')](_0x18b4ae[_0x73a6('0x45')],{'$or':_[_0x73a6('0x1f')](_0x18b4ae[_0x73a6('0x2e')],function(_0x5a9ca7){var _0x407f1c={};_0x407f1c[_0x5a9ca7]={'$like':'%'+_0x571f14[_0x73a6('0x26')]['filter']+'%'};return _0x407f1c;})});}_0x18b4ae=_[_0x73a6('0x32')]({},_0x18b4ae,_0x571f14[_0x73a6('0x33')]);return _0x2408ca[_0x73a6('0x7b')](_0x18b4ae);}})[_0x73a6('0x16')](function(_0x2aa3a9){if(_0x2aa3a9){_0x472b6b=_0x2aa3a9[_0x73a6('0x30')];if(!_0x571f14[_0x73a6('0x26')][_0x73a6('0x7c')](_0x73a6('0x43'))){_0x18b4ae[_0x73a6('0x10')]=qs['limit'](_0x571f14[_0x73a6('0x26')][_0x73a6('0x10')]);_0x18b4ae[_0x73a6('0xf')]=qs[_0x73a6('0xf')](_0x571f14[_0x73a6('0x26')][_0x73a6('0xf')]);}return _0x2408ca[_0x73a6('0x7b')](_0x18b4ae);}})[_0x73a6('0x16')](function(_0x188687){if(_0x188687){return _0x188687?{'count':_0x472b6b,'rows':_0x188687}:null;}})[_0x73a6('0x16')](respondWithResult(_0x11ab3f,null))[_0x73a6('0x29')](handleError(_0x11ab3f,null));};
\ No newline at end of file