Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / api / mailQueue / mailQueue.controller.js
index 3015af9..6538a1a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x117b=['spread','userMailQueue:remove','getAgents','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','squel','crypto','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailQueue.socket','register','sendStatus','status','json','count','offset','limit','Content-Range','apply','update','then','destroy','get','MailQueues','UserProfileResource','end','stack','name','send','index','map','MailQueue','rawAttributes','fieldName','type','key','query','filters','model','intersection','attributes','hasOwnProperty','order','where','pick','merge','VIRTUAL','filter','options','include','findAll','rows','catch','params','fields','length','includeAll','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','find','userProfileId','autoAssociation','error','getMembers','keys','UserMailQueue','nolimit','sort','User','findAndCountAll','UserId','agent','updatedAt','createdAt','%s/%s','SIP','mailPause','getTeams','findOne','Team','addTeams','voicePause','interface','sequelize','forEach','emit','userMailQueue:save','ids','Agents','select','field','tq.TeamId','from','team_has_mail_queues','join','ut.TeamId\x20=\x20tq.TeamId','MailQueueId\x20=\x20?','ut.UserId\x20=\x20?','push','toString','QueryTypes','every','includes','all','compact','value','removeTeams','isEmpty','removeAgents','addAgents','omit'];(function(_0x32e37f,_0x5f33c6){var _0xa44d8f=function(_0x42258c){while(--_0x42258c){_0x32e37f['push'](_0x32e37f['shift']());}};_0xa44d8f(++_0x5f33c6);}(_0x117b,0x198));var _0xb117=function(_0x515462,_0x2b65f3){_0x515462=_0x515462-0x0;var _0x58f682=_0x117b[_0x515462];return _0x58f682;};'use strict';var pdf=require(_0xb117('0x0'));var emlformat=require(_0xb117('0x1'));var rimraf=require(_0xb117('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb117('0x3'));var rp=require(_0xb117('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xb117('0x5'));var util=require(_0xb117('0x6'));var path=require(_0xb117('0x7'));var sox=require(_0xb117('0x8'));var csv=require(_0xb117('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0xb117('0xa'));var crypto=require(_0xb117('0xb'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xb117('0x9'));var querystring=require(_0xb117('0xc'));var Papa=require(_0xb117('0xd'));var Redis=require('ioredis');var authService=require(_0xb117('0xe'));var qs=require(_0xb117('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb117('0x10'));var logger=require(_0xb117('0x11'))(_0xb117('0x12'));var utils=require(_0xb117('0x13'));var config=require(_0xb117('0x14'));var db=require(_0xb117('0x15'))['db'];config[_0xb117('0x16')]=_[_0xb117('0x17')](config['redis'],{'host':_0xb117('0x18'),'port':0x18eb});var socket=require(_0xb117('0x19'))(new Redis(config[_0xb117('0x16')]));require(_0xb117('0x1a'))[_0xb117('0x1b')](socket);function respondWithStatusCode(_0x4db091,_0x5c8dda){_0x5c8dda=_0x5c8dda||0xcc;return function(_0x42254d){if(_0x42254d){return _0x4db091[_0xb117('0x1c')](_0x5c8dda);}return _0x4db091['status'](_0x5c8dda)['end']();};}function respondWithResult(_0xd7d005,_0xfb0423){_0xfb0423=_0xfb0423||0xc8;return function(_0x4c6986){if(_0x4c6986){return _0xd7d005[_0xb117('0x1d')](_0xfb0423)[_0xb117('0x1e')](_0x4c6986);}};}function respondWithFilteredResult(_0xd4ee11,_0x4a4900){return function(_0x1e2c71){if(_0x1e2c71){var _0x5b3f9c=_0x1e2c71[_0xb117('0x1f')],_0x2fc1c7=_0x4a4900['offset'],_0x5603f4=_0x4a4900[_0xb117('0x20')]+_0x4a4900[_0xb117('0x21')],_0x1c5cfe;if(_0x5603f4>=_0x5b3f9c){_0x5603f4=_0x5b3f9c;_0x1c5cfe=0xc8;}else{_0x1c5cfe=0xce;}_0xd4ee11[_0xb117('0x1d')](_0x1c5cfe);return _0xd4ee11['set'](_0xb117('0x22'),_0x2fc1c7+'-'+_0x5603f4+'/'+_0x5b3f9c)[_0xb117('0x1e')](_0x1e2c71);}return null;};}function patchUpdates(_0x4eedea){return function(_0x5c3d37){try{jsonpatch[_0xb117('0x23')](_0x5c3d37,_0x4eedea,!![]);}catch(_0x4b2035){return BPromise['reject'](_0x4b2035);}return _0x5c3d37['save']();};}function saveUpdates(_0x14ec71,_0x29c770){return function(_0x40ce47){if(_0x40ce47){return _0x40ce47[_0xb117('0x24')](_0x14ec71)[_0xb117('0x25')](function(_0x133d2b){return _0x133d2b;});}return null;};}function removeEntity(_0x3ca26e,_0x4873a4){return function(_0x28eedc){if(_0x28eedc){return _0x28eedc[_0xb117('0x26')]()[_0xb117('0x25')](function(){var _0x2a95bd=_0x28eedc[_0xb117('0x27')]({'plain':!![]});var _0x3ee112=_0xb117('0x28');return db[_0xb117('0x29')][_0xb117('0x26')]({'where':{'type':_0x3ee112,'resourceId':_0x2a95bd['id']}})[_0xb117('0x25')](function(){return _0x28eedc;});})[_0xb117('0x25')](function(){_0x3ca26e['status'](0xcc)[_0xb117('0x2a')]();});}};}function handleEntityNotFound(_0x38f34d,_0x3fcbfb){return function(_0x1057ab){if(!_0x1057ab){_0x38f34d['sendStatus'](0x194);}return _0x1057ab;};}function handleError(_0x5268b4,_0x50b28c){_0x50b28c=_0x50b28c||0x1f4;return function(_0x11c943){logger['error'](_0x11c943[_0xb117('0x2b')]);if(_0x11c943[_0xb117('0x2c')]){delete _0x11c943[_0xb117('0x2c')];}_0x5268b4[_0xb117('0x1d')](_0x50b28c)[_0xb117('0x2d')](_0x11c943);};}exports[_0xb117('0x2e')]=function(_0x146ecf,_0x36a443){var _0x2c8bbc={},_0x444a81={},_0x1d686c={'count':0x0,'rows':[]};var _0x4bb723=_[_0xb117('0x2f')](db[_0xb117('0x30')][_0xb117('0x31')],function(_0x1bda68){return{'name':_0x1bda68[_0xb117('0x32')],'type':_0x1bda68[_0xb117('0x33')][_0xb117('0x34')]};});_0x444a81['model']=_['map'](_0x4bb723,_0xb117('0x2c'));_0x444a81[_0xb117('0x35')]=_['keys'](_0x146ecf[_0xb117('0x35')]);_0x444a81[_0xb117('0x36')]=_['intersection'](_0x444a81[_0xb117('0x37')],_0x444a81[_0xb117('0x35')]);_0x2c8bbc['attributes']=_[_0xb117('0x38')](_0x444a81[_0xb117('0x37')],qs['fields'](_0x146ecf[_0xb117('0x35')]['fields']));_0x2c8bbc['attributes']=_0x2c8bbc[_0xb117('0x39')]['length']?_0x2c8bbc[_0xb117('0x39')]:_0x444a81[_0xb117('0x37')];if(!_0x146ecf[_0xb117('0x35')][_0xb117('0x3a')]('nolimit')){_0x2c8bbc[_0xb117('0x21')]=qs['limit'](_0x146ecf['query'][_0xb117('0x21')]);_0x2c8bbc[_0xb117('0x20')]=qs[_0xb117('0x20')](_0x146ecf[_0xb117('0x35')][_0xb117('0x20')]);}_0x2c8bbc[_0xb117('0x3b')]=qs['sort'](_0x146ecf[_0xb117('0x35')]['sort']);_0x2c8bbc[_0xb117('0x3c')]=qs[_0xb117('0x36')](_[_0xb117('0x3d')](_0x146ecf[_0xb117('0x35')],_0x444a81[_0xb117('0x36')]),_0x4bb723);if(_0x146ecf[_0xb117('0x35')]['filter']){_0x2c8bbc['where']=_[_0xb117('0x3e')](_0x2c8bbc[_0xb117('0x3c')],{'$or':_['map'](_0x4bb723,function(_0x3e93d9){if(_0x3e93d9[_0xb117('0x33')]!==_0xb117('0x3f')){var _0x551078={};_0x551078[_0x3e93d9[_0xb117('0x2c')]]={'$like':'%'+_0x146ecf[_0xb117('0x35')][_0xb117('0x40')]+'%'};return _0x551078;}})});}_0x2c8bbc=_[_0xb117('0x3e')]({},_0x2c8bbc,_0x146ecf[_0xb117('0x41')]);var _0x317beb={'where':_0x2c8bbc[_0xb117('0x3c')]};return db['MailQueue'][_0xb117('0x1f')](_0x317beb)['then'](function(_0x4b7530){_0x1d686c[_0xb117('0x1f')]=_0x4b7530;if(_0x146ecf['query']['includeAll']){_0x2c8bbc[_0xb117('0x42')]=[{'all':!![]}];}return db['MailQueue'][_0xb117('0x43')](_0x2c8bbc);})[_0xb117('0x25')](function(_0x325184){_0x1d686c[_0xb117('0x44')]=_0x325184;return _0x1d686c;})[_0xb117('0x25')](respondWithFilteredResult(_0x36a443,_0x2c8bbc))[_0xb117('0x45')](handleError(_0x36a443,null));};exports['show']=function(_0x5acfb8,_0xa4f1f1){var _0x588ee8={'raw':!![],'where':{'id':_0x5acfb8[_0xb117('0x46')]['id']}},_0x3cc8be={};_0x3cc8be[_0xb117('0x37')]=_['keys'](db['MailQueue'][_0xb117('0x31')]);_0x3cc8be[_0xb117('0x35')]=_['keys'](_0x5acfb8[_0xb117('0x35')]);_0x3cc8be[_0xb117('0x36')]=_[_0xb117('0x38')](_0x3cc8be[_0xb117('0x37')],_0x3cc8be[_0xb117('0x35')]);_0x588ee8[_0xb117('0x39')]=_[_0xb117('0x38')](_0x3cc8be['model'],qs[_0xb117('0x47')](_0x5acfb8['query'][_0xb117('0x47')]));_0x588ee8[_0xb117('0x39')]=_0x588ee8['attributes'][_0xb117('0x48')]?_0x588ee8['attributes']:_0x3cc8be[_0xb117('0x37')];if(_0x5acfb8[_0xb117('0x35')][_0xb117('0x49')]){_0x588ee8[_0xb117('0x42')]=[{'all':!![]}];}_0x588ee8=_[_0xb117('0x3e')]({},_0x588ee8,_0x5acfb8[_0xb117('0x41')]);return db[_0xb117('0x30')]['find'](_0x588ee8)[_0xb117('0x25')](handleEntityNotFound(_0xa4f1f1,null))[_0xb117('0x25')](respondWithResult(_0xa4f1f1,null))[_0xb117('0x45')](handleError(_0xa4f1f1,null));};exports[_0xb117('0x4a')]=function(_0x113e61,_0x4c827e){return db[_0xb117('0x30')][_0xb117('0x4a')](_0x113e61[_0xb117('0x4b')],{})[_0xb117('0x25')](function(_0x511342){var _0x27825b=_0x113e61['user'][_0xb117('0x27')]({'plain':!![]});if(!_0x27825b)throw new Error(_0xb117('0x4c'));if(_0x27825b[_0xb117('0x4d')]===_0xb117('0x4e')){var _0x45c14b=_0x511342[_0xb117('0x27')]({'plain':!![]});var _0x4cf442=_0xb117('0x28');return db[_0xb117('0x4f')][_0xb117('0x50')]({'where':{'name':_0x4cf442,'userProfileId':_0x27825b[_0xb117('0x51')]},'raw':!![]})[_0xb117('0x25')](function(_0x18003a){if(_0x18003a&&_0x18003a[_0xb117('0x52')]===0x0){return db[_0xb117('0x29')][_0xb117('0x4a')]({'name':_0x45c14b['name'],'resourceId':_0x45c14b['id'],'type':_0x18003a['name'],'sectionId':_0x18003a['id']},{})[_0xb117('0x25')](function(){return _0x511342;});}else{return _0x511342;}})[_0xb117('0x45')](function(_0x3d7341){logger[_0xb117('0x53')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3d7341);throw _0x3d7341;});}return _0x511342;})[_0xb117('0x25')](respondWithResult(_0x4c827e,0xc9))[_0xb117('0x45')](handleError(_0x4c827e,null));};exports[_0xb117('0x24')]=function(_0x5794e4,_0x4b12f9){if(_0x5794e4[_0xb117('0x4b')]['id']){delete _0x5794e4[_0xb117('0x4b')]['id'];}return db['MailQueue'][_0xb117('0x50')]({'where':{'id':_0x5794e4[_0xb117('0x46')]['id']}})['then'](handleEntityNotFound(_0x4b12f9,null))[_0xb117('0x25')](saveUpdates(_0x5794e4[_0xb117('0x4b')],null))[_0xb117('0x25')](respondWithResult(_0x4b12f9,null))[_0xb117('0x45')](handleError(_0x4b12f9,null));};exports[_0xb117('0x26')]=function(_0x5d032e,_0x5bd2af){return db[_0xb117('0x30')]['find']({'where':{'id':_0x5d032e['params']['id']}})[_0xb117('0x25')](handleEntityNotFound(_0x5bd2af,null))[_0xb117('0x25')](removeEntity(_0x5bd2af,null))[_0xb117('0x45')](handleError(_0x5bd2af,null));};exports['describe']=function(_0xa8352f,_0x4525cd){return db[_0xb117('0x30')]['describe']()[_0xb117('0x25')](respondWithResult(_0x4525cd,null))[_0xb117('0x45')](handleError(_0x4525cd,null));};exports[_0xb117('0x54')]=function(_0x4f4fc6,_0xb4d61,_0x485791){var _0x1abe06={'raw':!![],'where':{}},_0x3f40b7={},_0x2114e5;return db[_0xb117('0x30')]['findOne']({'where':{'id':_0x4f4fc6[_0xb117('0x46')]['id']}})[_0xb117('0x25')](handleEntityNotFound(_0xb4d61,null))[_0xb117('0x25')](function(_0x1bf414){if(_0x1bf414){_0x2114e5=_0x1bf414[_0xb117('0x27')]({'plain':!![]});_0x3f40b7[_0xb117('0x37')]=_[_0xb117('0x55')](db[_0xb117('0x56')][_0xb117('0x31')]);_0x3f40b7[_0xb117('0x35')]=_[_0xb117('0x55')](_0x4f4fc6[_0xb117('0x35')]);_0x3f40b7[_0xb117('0x36')]=_[_0xb117('0x38')](_0x3f40b7[_0xb117('0x37')],_0x3f40b7[_0xb117('0x35')]);_0x1abe06[_0xb117('0x39')]=_[_0xb117('0x38')](_0x3f40b7['model'],qs[_0xb117('0x47')](_0x4f4fc6['query']['fields']));_0x1abe06[_0xb117('0x39')]=_0x1abe06['attributes'][_0xb117('0x48')]?_0x1abe06[_0xb117('0x39')]:_0x3f40b7[_0xb117('0x37')];if(!_0x4f4fc6['query'][_0xb117('0x3a')](_0xb117('0x57'))){_0x1abe06[_0xb117('0x21')]=qs['limit'](_0x4f4fc6[_0xb117('0x35')][_0xb117('0x21')]);_0x1abe06[_0xb117('0x20')]=qs['offset'](_0x4f4fc6[_0xb117('0x35')]['offset']);}_0x1abe06[_0xb117('0x3b')]=qs[_0xb117('0x58')](_0x4f4fc6[_0xb117('0x35')]['sort']);_0x1abe06[_0xb117('0x3c')]=qs[_0xb117('0x36')](_['pick'](_0x4f4fc6[_0xb117('0x35')],_0x3f40b7[_0xb117('0x36')]));_0x1abe06[_0xb117('0x3c')]['MailQueueId']=_0x1bf414['id'];if(_0x4f4fc6[_0xb117('0x35')][_0xb117('0x40')]){_0x1abe06[_0xb117('0x3c')]=_['merge'](_0x1abe06['where'],{'$or':_[_0xb117('0x2f')](_0x1abe06['attributes'],function(_0x35494f){var _0x5f1234={};_0x5f1234[_0x35494f]={'$like':'%'+_0x4f4fc6[_0xb117('0x35')][_0xb117('0x40')]+'%'};return _0x5f1234;})});}_0x1abe06=_['merge']({},_0x1abe06,_0x4f4fc6['options']);return db[_0xb117('0x56')]['findAll'](_0x1abe06);}})[_0xb117('0x25')](function(_0xc310d1){if(_0xc310d1){return db[_0xb117('0x59')][_0xb117('0x5a')]({'where':{'id':_[_0xb117('0x2f')](_0xc310d1,_0xb117('0x5b')),'role':_0xb117('0x5c')},'attributes':['id','name','mailPause',_0xb117('0x5d'),_0xb117('0x5e')]});}})['then'](function(_0x3d883f){if(_0x3d883f){return{'count':_0x3d883f[_0xb117('0x1f')],'rows':_[_0xb117('0x2f')](_0x3d883f[_0xb117('0x44')],function(_0x42749a){return{'membername':_0x42749a[_0xb117('0x2c')],'UserId':_0x42749a['id'],'queue_name':_0x2114e5['name'],'MailQueueId':_0x2114e5['id'],'interface':util['format'](_0xb117('0x5f'),_0xb117('0x60'),_0x42749a['name']),'penalty':0x0,'paused':_0x42749a[_0xb117('0x61')],'createdAt':_0x42749a[_0xb117('0x5e')],'updatedAt':_0x42749a[_0xb117('0x5d')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xb117('0x25')](respondWithFilteredResult(_0xb4d61,_0x1abe06))[_0xb117('0x45')](handleError(_0xb4d61,null));};exports[_0xb117('0x62')]=function(_0x10110f,_0x40813a,_0x1ed757){var _0x5a577b={};var _0x1a3501={};var _0x250a46;var _0x37ad82;return db[_0xb117('0x30')][_0xb117('0x63')]({'where':{'id':_0x10110f['params']['id']}})[_0xb117('0x25')](handleEntityNotFound(_0x40813a,null))[_0xb117('0x25')](function(_0x203327){if(_0x203327){_0x250a46=_0x203327;_0x1a3501[_0xb117('0x37')]=_[_0xb117('0x55')](db[_0xb117('0x64')][_0xb117('0x31')]);_0x1a3501['query']=_[_0xb117('0x55')](_0x10110f[_0xb117('0x35')]);_0x1a3501[_0xb117('0x36')]=_['intersection'](_0x1a3501[_0xb117('0x37')],_0x1a3501[_0xb117('0x35')]);_0x5a577b[_0xb117('0x39')]=_['intersection'](_0x1a3501[_0xb117('0x37')],qs['fields'](_0x10110f[_0xb117('0x35')][_0xb117('0x47')]));_0x5a577b[_0xb117('0x39')]=_0x5a577b[_0xb117('0x39')]['length']?_0x5a577b['attributes']:_0x1a3501[_0xb117('0x37')];_0x5a577b[_0xb117('0x3b')]=qs['sort'](_0x10110f[_0xb117('0x35')]['sort']);_0x5a577b[_0xb117('0x3c')]=qs['filters'](_[_0xb117('0x3d')](_0x10110f[_0xb117('0x35')],_0x1a3501[_0xb117('0x36')]));if(_0x10110f[_0xb117('0x35')][_0xb117('0x40')]){_0x5a577b[_0xb117('0x3c')]=_[_0xb117('0x3e')](_0x5a577b[_0xb117('0x3c')],{'$or':_[_0xb117('0x2f')](_0x5a577b[_0xb117('0x39')],function(_0x51ef87){var _0x303df2={};_0x303df2[_0x51ef87]={'$like':'%'+_0x10110f[_0xb117('0x35')]['filter']+'%'};return _0x303df2;})});}_0x5a577b=_['merge']({},_0x5a577b,_0x10110f[_0xb117('0x41')]);return _0x250a46[_0xb117('0x62')](_0x5a577b);}})[_0xb117('0x25')](function(_0x409230){if(_0x409230){_0x37ad82=_0x409230[_0xb117('0x48')];if(!_0x10110f[_0xb117('0x35')][_0xb117('0x3a')](_0xb117('0x57'))){_0x5a577b[_0xb117('0x21')]=qs['limit'](_0x10110f[_0xb117('0x35')][_0xb117('0x21')]);_0x5a577b[_0xb117('0x20')]=qs[_0xb117('0x20')](_0x10110f[_0xb117('0x35')]['offset']);}return _0x250a46['getTeams'](_0x5a577b);}})['then'](function(_0x48ca19){if(_0x48ca19){return _0x48ca19?{'count':_0x37ad82,'rows':_0x48ca19}:null;}})[_0xb117('0x25')](respondWithResult(_0x40813a,null))['catch'](handleError(_0x40813a,null));};exports[_0xb117('0x65')]=function(_0x4b7af2,_0x44fd47,_0x1aaf1a){var _0x1f500c=_0x4b7af2[_0xb117('0x4b')]['ids'];return db[_0xb117('0x64')][_0xb117('0x43')]({'where':{'id':_0x1f500c},'attributes':['id'],'include':[{'model':db[_0xb117('0x59')],'as':'Agents','attributes':['id',_0xb117('0x2c'),'online',_0xb117('0x66'),_0xb117('0x67')],'raw':!![]}]})[_0xb117('0x25')](function(_0x27d709){if(_0x27d709){var _0x1926be=_['flatMap'](_0x27d709,function(_0x1dfa04){var _0x416ae5=_0x1dfa04[_0xb117('0x27')]({'plain':!![]});return _0x416ae5['Agents'];});return db['MailQueue'][_0xb117('0x50')]({'where':{'id':_0x4b7af2['params']['id']}})[_0xb117('0x25')](function(_0x33455c){return db[_0xb117('0x68')]['transaction'](function(_0x36803f){return _0x33455c[_0xb117('0x65')](_0x1f500c,{'transaction':_0x36803f})[_0xb117('0x25')](function(){return BPromise['each'](_0x1926be,function(_0x7982f8){return db[_0xb117('0x56')]['findOrCreate']({'where':{'UserId':_0x7982f8['id'],'MailQueueId':_0x4b7af2[_0xb117('0x46')]['id']},'transaction':_0x36803f});});})[_0xb117('0x25')](function(){_0x1926be[_0xb117('0x69')](function(_0xacd7df){socket[_0xb117('0x6a')](_0xb117('0x6b'),{'UserId':_0xacd7df['id'],'MailQueueId':_0x33455c['id']});});});});});}})[_0xb117('0x25')](respondWithStatusCode(_0x44fd47,null))[_0xb117('0x45')](handleError(_0x44fd47,null));};exports['removeTeams']=function(_0x35e1c1,_0x3ad4df,_0x588c33){return db[_0xb117('0x64')]['findAll']({'where':{'id':_0x35e1c1[_0xb117('0x35')][_0xb117('0x6c')]},'attributes':['id'],'include':[{'model':db['User'],'as':_0xb117('0x6d'),'attributes':['id'],'raw':!![]}]})[_0xb117('0x25')](handleEntityNotFound(_0x3ad4df,null))[_0xb117('0x25')](function(_0x327af8){var _0x32819f=_[_0xb117('0x2f')](_0x327af8,'id');var _0x15df2f=[];var _0x58e890=[];var _0x5f50d5=squel[_0xb117('0x6e')]();_0x5f50d5[_0xb117('0x6f')](_0xb117('0x70'))[_0xb117('0x71')](_0xb117('0x72'),'tq')[_0xb117('0x73')]('user_has_teams','ut',_0xb117('0x74'))[_0xb117('0x3c')](_0xb117('0x75'),_0x35e1c1[_0xb117('0x46')]['id']);for(var _0x10d88e=0x0;_0x10d88e<_0x327af8[_0xb117('0x48')];_0x10d88e+=0x1){let _0x381d17=_0x327af8[_0x10d88e];for(var _0x67acb9=0x0;_0x67acb9<_0x381d17[_0xb117('0x6d')][_0xb117('0x48')];_0x67acb9+=0x1){let _0x1cd8e7=_0x381d17[_0xb117('0x6d')][_0x67acb9];var _0x2020a2=_0x5f50d5['clone']();_0x2020a2['where'](_0xb117('0x76'),_0x1cd8e7['id']);_0x58e890[_0xb117('0x77')](db[_0xb117('0x68')]['query'](_0x2020a2[_0xb117('0x78')](),{'type':db[_0xb117('0x68')][_0xb117('0x79')]['SELECT']})[_0xb117('0x25')](function(_0x1a9874){if(_0x1a9874['length']===0x1){return _0x1cd8e7['id'];}else{var _0x375ec1=_[_0xb117('0x7a')](_[_0xb117('0x2f')](_0x1a9874,'TeamId'),function(_0x518695){return _[_0xb117('0x7b')](_0x32819f,_0x518695);});if(_0x375ec1){return _0x1cd8e7['id'];}}}));}}return BPromise[_0xb117('0x7c')](_0x58e890)[_0xb117('0x25')](function(_0xb42b02){_0x15df2f=_(_0x15df2f)['union'](_0xb42b02)[_0xb117('0x7d')]()[_0xb117('0x7e')]();return db[_0xb117('0x30')][_0xb117('0x50')]({'where':{'id':_0x35e1c1[_0xb117('0x46')]['id']}})[_0xb117('0x25')](function(_0x48b413){return db[_0xb117('0x68')]['transaction'](function(_0x4b7514){return _0x48b413[_0xb117('0x7f')](_0x35e1c1[_0xb117('0x35')][_0xb117('0x6c')],{'transaction':_0x4b7514})[_0xb117('0x25')](function(){if(!_[_0xb117('0x80')](_0x15df2f)){return _0x48b413[_0xb117('0x81')](_0x15df2f,{'transaction':_0x4b7514});}})[_0xb117('0x25')](function(){_0x15df2f['forEach'](function(_0x5b1dcb){socket[_0xb117('0x6a')]('userMailQueue:remove',{'UserId':_0x5b1dcb,'MailQueueId':_0x48b413['id']});});});});});});})[_0xb117('0x25')](respondWithStatusCode(_0x3ad4df,null))['catch'](handleError(_0x3ad4df,null));};exports[_0xb117('0x82')]=function(_0x204f3c,_0x1fe5e4,_0x31af39){return db[_0xb117('0x30')][_0xb117('0x50')]({'where':{'id':_0x204f3c[_0xb117('0x46')]['id']}})['then'](handleEntityNotFound(_0x1fe5e4,null))[_0xb117('0x25')](function(_0x3c1fcb){if(_0x3c1fcb){return _0x3c1fcb[_0xb117('0x82')](_0x204f3c[_0xb117('0x4b')]['ids'],_[_0xb117('0x83')](_0x204f3c['body'],['ids','id'])||{})[_0xb117('0x84')](function(_0x59a3e5){for(var _0x90e0a=0x0;_0x90e0a<_0x204f3c['body'][_0xb117('0x6c')][_0xb117('0x48')];_0x90e0a+=0x1){socket[_0xb117('0x6a')]('userMailQueue:save',{'UserId':_0x204f3c[_0xb117('0x4b')][_0xb117('0x6c')][_0x90e0a],'MailQueueId':_0x204f3c[_0xb117('0x46')]['id']});}return _0x59a3e5;});}})['then'](respondWithResult(_0x1fe5e4,null))[_0xb117('0x45')](handleError(_0x1fe5e4,null));};exports['removeAgents']=function(_0x25b263,_0x37b180,_0x34b5d6){return db[_0xb117('0x30')][_0xb117('0x50')]({'where':{'id':_0x25b263[_0xb117('0x46')]['id']}})[_0xb117('0x25')](handleEntityNotFound(_0x37b180,null))[_0xb117('0x25')](function(_0x54278e){if(_0x54278e){return _0x54278e[_0xb117('0x81')](_0x25b263[_0xb117('0x35')][_0xb117('0x6c')])['then'](function(){if(_['isArray'](_0x25b263[_0xb117('0x35')][_0xb117('0x6c')])){for(var _0x1079f3=0x0;_0x1079f3<_0x25b263[_0xb117('0x35')][_0xb117('0x6c')][_0xb117('0x48')];_0x1079f3+=0x1){socket['emit'](_0xb117('0x85'),{'UserId':Number(_0x25b263['query']['ids'][_0x1079f3]),'MailQueueId':Number(_0x25b263[_0xb117('0x46')]['id'])});}}else{socket[_0xb117('0x6a')](_0xb117('0x85'),{'UserId':Number(_0x25b263[_0xb117('0x35')]['ids']),'MailQueueId':Number(_0x25b263[_0xb117('0x46')]['id'])});}});}})['then'](respondWithStatusCode(_0x37b180,null))[_0xb117('0x45')](handleError(_0x37b180,null));};exports['getAgents']=function(_0x1fdbea,_0x520cd6,_0x3c99b3){var _0x26be0a={};var _0x11c578={};var _0x2bc48c;var _0x19ae56;return db[_0xb117('0x30')]['findOne']({'where':{'id':_0x1fdbea[_0xb117('0x46')]['id']}})[_0xb117('0x25')](handleEntityNotFound(_0x520cd6,null))[_0xb117('0x25')](function(_0x20928e){if(_0x20928e){_0x2bc48c=_0x20928e;_0x11c578[_0xb117('0x37')]=_[_0xb117('0x55')](db[_0xb117('0x59')][_0xb117('0x31')]);_0x11c578[_0xb117('0x35')]=_[_0xb117('0x55')](_0x1fdbea[_0xb117('0x35')]);_0x11c578[_0xb117('0x36')]=_[_0xb117('0x38')](_0x11c578['model'],_0x11c578['query']);_0x26be0a[_0xb117('0x39')]=_[_0xb117('0x38')](_0x11c578['model'],qs[_0xb117('0x47')](_0x1fdbea[_0xb117('0x35')][_0xb117('0x47')]));_0x26be0a[_0xb117('0x39')]=_0x26be0a[_0xb117('0x39')][_0xb117('0x48')]?_0x26be0a['attributes']:_0x11c578[_0xb117('0x37')];_0x26be0a[_0xb117('0x3b')]=qs[_0xb117('0x58')](_0x1fdbea[_0xb117('0x35')]['sort']);_0x26be0a[_0xb117('0x3c')]=qs[_0xb117('0x36')](_[_0xb117('0x3d')](_0x1fdbea[_0xb117('0x35')],_0x11c578[_0xb117('0x36')]));if(_0x1fdbea['query']['filter']){_0x26be0a[_0xb117('0x3c')]=_[_0xb117('0x3e')](_0x26be0a[_0xb117('0x3c')],{'$or':_[_0xb117('0x2f')](_0x26be0a[_0xb117('0x39')],function(_0x425b30){var _0x437807={};_0x437807[_0x425b30]={'$like':'%'+_0x1fdbea[_0xb117('0x35')][_0xb117('0x40')]+'%'};return _0x437807;})});}_0x26be0a=_[_0xb117('0x3e')]({},_0x26be0a,_0x1fdbea[_0xb117('0x41')]);return _0x2bc48c[_0xb117('0x86')](_0x26be0a);}})[_0xb117('0x25')](function(_0x311a58){if(_0x311a58){_0x19ae56=_0x311a58['length'];if(!_0x1fdbea[_0xb117('0x35')][_0xb117('0x3a')](_0xb117('0x57'))){_0x26be0a[_0xb117('0x21')]=qs[_0xb117('0x21')](_0x1fdbea[_0xb117('0x35')][_0xb117('0x21')]);_0x26be0a['offset']=qs[_0xb117('0x20')](_0x1fdbea[_0xb117('0x35')]['offset']);}return _0x2bc48c[_0xb117('0x86')](_0x26be0a);}})['then'](function(_0x41a07e){if(_0x41a07e){return _0x41a07e?{'count':_0x19ae56,'rows':_0x41a07e}:null;}})['then'](respondWithResult(_0x520cd6,null))['catch'](handleError(_0x520cd6,null));};
\ No newline at end of file
+var _0x3773=['field','from','team_has_mail_queues','join','ut.TeamId\x20=\x20tq.TeamId','MailQueueId\x20=\x20?','clone','push','QueryTypes','TeamId','all','union','compact','value','ids','isEmpty','addAgents','omit','spread','userMailQueue:save','removeAgents','userMailQueue:remove','getAgents','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','./mailQueue.socket','end','status','undefined','limit','count','offset','apply','save','update','destroy','then','get','UserProfileResource','sendStatus','stack','send','map','MailQueue','rawAttributes','fieldName','key','model','query','keys','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','filters','pick','filter','merge','type','VIRTUAL','includeAll','findAll','rows','include','find','create','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','MailQueues','UserProfileSection','name','catch','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','params','describe','getMembers','findOne','order','MailQueueId','UserMailQueue','User','agent','mailPause','updatedAt','createdAt','SIP','getTeams','Team','options','Agents','online','voicePause','interface','flatMap','sequelize','transaction','addTeams','each','findOrCreate','forEach','emit','removeTeams','select'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x3773,0x1a9));var _0x3377=function(_0x46698a,_0x8de1e4){_0x46698a=_0x46698a-0x0;var _0x356db0=_0x3773[_0x46698a];return _0x356db0;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x3377('0x0'));var zipdir=require(_0x3377('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x3377('0x2'));var moment=require(_0x3377('0x3'));var BPromise=require(_0x3377('0x4'));var Mustache=require(_0x3377('0x5'));var util=require(_0x3377('0x6'));var path=require(_0x3377('0x7'));var sox=require(_0x3377('0x8'));var csv=require('to-csv');var ejs=require(_0x3377('0x9'));var fs=require('fs');var fs_extra=require(_0x3377('0xa'));var _=require(_0x3377('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x3377('0xc'));var deskjs=require(_0x3377('0xd'));var toCsv=require(_0x3377('0xe'));var querystring=require(_0x3377('0xf'));var Papa=require(_0x3377('0x10'));var Redis=require(_0x3377('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x3377('0x12'));var hardwareService=require(_0x3377('0x13'));var logger=require(_0x3377('0x14'))(_0x3377('0x15'));var utils=require('../../config/utils');var config=require(_0x3377('0x16'));var licenseUtil=require(_0x3377('0x17'));var db=require(_0x3377('0x18'))['db'];config[_0x3377('0x19')]=_['defaults'](config[_0x3377('0x19')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x3377('0x1a'))['register'](socket);function respondWithStatusCode(_0x37dd34,_0x319638){_0x319638=_0x319638||0xcc;return function(_0x4143e8){if(_0x4143e8){return _0x37dd34['sendStatus'](_0x319638);}return _0x37dd34['status'](_0x319638)[_0x3377('0x1b')]();};}function respondWithResult(_0x49fb17,_0x561df0){_0x561df0=_0x561df0||0xc8;return function(_0x6e50f8){if(_0x6e50f8){return _0x49fb17[_0x3377('0x1c')](_0x561df0)['json'](_0x6e50f8);}};}function respondWithFilteredResult(_0x3774e3,_0x569891){return function(_0x16b959){if(_0x16b959){var _0xf4073c=typeof _0x569891['offset']===_0x3377('0x1d')&&typeof _0x569891[_0x3377('0x1e')]==='undefined';var _0x845eb7=_0x16b959[_0x3377('0x1f')];var _0x314af7=_0xf4073c?0x0:_0x569891[_0x3377('0x20')];var _0x503760=_0xf4073c?_0x16b959[_0x3377('0x1f')]:_0x569891[_0x3377('0x20')]+_0x569891[_0x3377('0x1e')];var _0x307992;if(_0x503760>=_0x845eb7){_0x503760=_0x845eb7;_0x307992=0xc8;}else{_0x307992=0xce;}_0x3774e3[_0x3377('0x1c')](_0x307992);return _0x3774e3['set']('Content-Range',_0x314af7+'-'+_0x503760+'/'+_0x845eb7)['json'](_0x16b959);}return null;};}function patchUpdates(_0x3343b5){return function(_0x139d30){try{jsonpatch[_0x3377('0x21')](_0x139d30,_0x3343b5,!![]);}catch(_0x4ac578){return BPromise['reject'](_0x4ac578);}return _0x139d30[_0x3377('0x22')]();};}function saveUpdates(_0x152453,_0x4156a0){return function(_0x1674ae){if(_0x1674ae){return _0x1674ae[_0x3377('0x23')](_0x152453)['then'](function(_0x3c37e6){return _0x3c37e6;});}return null;};}function removeEntity(_0x1204d0,_0x5035e4){return function(_0x5e3578){if(_0x5e3578){return _0x5e3578[_0x3377('0x24')]()[_0x3377('0x25')](function(){var _0x4709c7=_0x5e3578[_0x3377('0x26')]({'plain':!![]});var _0x170661='MailQueues';return db[_0x3377('0x27')][_0x3377('0x24')]({'where':{'type':_0x170661,'resourceId':_0x4709c7['id']}})['then'](function(){return _0x5e3578;});})[_0x3377('0x25')](function(){_0x1204d0['status'](0xcc)[_0x3377('0x1b')]();});}};}function handleEntityNotFound(_0x49070c,_0x3d673b){return function(_0x239a98){if(!_0x239a98){_0x49070c[_0x3377('0x28')](0x194);}return _0x239a98;};}function handleError(_0x12cbdd,_0x22503f){_0x22503f=_0x22503f||0x1f4;return function(_0x4cc256){logger['error'](_0x4cc256[_0x3377('0x29')]);if(_0x4cc256['name']){delete _0x4cc256['name'];}_0x12cbdd[_0x3377('0x1c')](_0x22503f)[_0x3377('0x2a')](_0x4cc256);};}exports['index']=function(_0x368998,_0x281fbb){var _0x2a7dbd={},_0x2f3884={},_0x3d3387={'count':0x0,'rows':[]};var _0x5a2b4b=_[_0x3377('0x2b')](db[_0x3377('0x2c')][_0x3377('0x2d')],function(_0x2e1b64){return{'name':_0x2e1b64[_0x3377('0x2e')],'type':_0x2e1b64['type'][_0x3377('0x2f')]};});_0x2f3884[_0x3377('0x30')]=_['map'](_0x5a2b4b,'name');_0x2f3884[_0x3377('0x31')]=_[_0x3377('0x32')](_0x368998[_0x3377('0x31')]);_0x2f3884['filters']=_[_0x3377('0x33')](_0x2f3884['model'],_0x2f3884['query']);_0x2a7dbd['attributes']=_[_0x3377('0x33')](_0x2f3884[_0x3377('0x30')],qs[_0x3377('0x34')](_0x368998[_0x3377('0x31')]['fields']));_0x2a7dbd[_0x3377('0x35')]=_0x2a7dbd[_0x3377('0x35')][_0x3377('0x36')]?_0x2a7dbd[_0x3377('0x35')]:_0x2f3884[_0x3377('0x30')];if(!_0x368998[_0x3377('0x31')][_0x3377('0x37')](_0x3377('0x38'))){_0x2a7dbd[_0x3377('0x1e')]=qs['limit'](_0x368998[_0x3377('0x31')]['limit']);_0x2a7dbd[_0x3377('0x20')]=qs['offset'](_0x368998[_0x3377('0x31')][_0x3377('0x20')]);}_0x2a7dbd['order']=qs[_0x3377('0x39')](_0x368998[_0x3377('0x31')]['sort']);_0x2a7dbd[_0x3377('0x3a')]=qs[_0x3377('0x3b')](_[_0x3377('0x3c')](_0x368998[_0x3377('0x31')],_0x2f3884[_0x3377('0x3b')]),_0x5a2b4b);if(_0x368998[_0x3377('0x31')][_0x3377('0x3d')]){_0x2a7dbd['where']=_[_0x3377('0x3e')](_0x2a7dbd[_0x3377('0x3a')],{'$or':_[_0x3377('0x2b')](_0x5a2b4b,function(_0x287271){if(_0x287271[_0x3377('0x3f')]!==_0x3377('0x40')){var _0x492b20={};_0x492b20[_0x287271['name']]={'$like':'%'+_0x368998[_0x3377('0x31')][_0x3377('0x3d')]+'%'};return _0x492b20;}})});}_0x2a7dbd=_[_0x3377('0x3e')]({},_0x2a7dbd,_0x368998['options']);var _0x5d2b53={'where':_0x2a7dbd['where']};return db[_0x3377('0x2c')][_0x3377('0x1f')](_0x5d2b53)[_0x3377('0x25')](function(_0x1abeac){_0x3d3387[_0x3377('0x1f')]=_0x1abeac;if(_0x368998['query'][_0x3377('0x41')]){_0x2a7dbd['include']=[{'all':!![]}];}return db['MailQueue'][_0x3377('0x42')](_0x2a7dbd);})[_0x3377('0x25')](function(_0x5ef78e){_0x3d3387[_0x3377('0x43')]=_0x5ef78e;return _0x3d3387;})[_0x3377('0x25')](respondWithFilteredResult(_0x281fbb,_0x2a7dbd))['catch'](handleError(_0x281fbb,null));};exports['show']=function(_0x27f0bf,_0x491674){var _0x536e34={'raw':!![],'where':{'id':_0x27f0bf['params']['id']}},_0x1e8b3f={};_0x1e8b3f[_0x3377('0x30')]=_[_0x3377('0x32')](db['MailQueue'][_0x3377('0x2d')]);_0x1e8b3f[_0x3377('0x31')]=_[_0x3377('0x32')](_0x27f0bf[_0x3377('0x31')]);_0x1e8b3f[_0x3377('0x3b')]=_['intersection'](_0x1e8b3f[_0x3377('0x30')],_0x1e8b3f[_0x3377('0x31')]);_0x536e34['attributes']=_[_0x3377('0x33')](_0x1e8b3f[_0x3377('0x30')],qs[_0x3377('0x34')](_0x27f0bf['query'][_0x3377('0x34')]));_0x536e34[_0x3377('0x35')]=_0x536e34[_0x3377('0x35')][_0x3377('0x36')]?_0x536e34[_0x3377('0x35')]:_0x1e8b3f[_0x3377('0x30')];if(_0x27f0bf['query'][_0x3377('0x41')]){_0x536e34[_0x3377('0x44')]=[{'all':!![]}];}_0x536e34=_[_0x3377('0x3e')]({},_0x536e34,_0x27f0bf['options']);return db[_0x3377('0x2c')][_0x3377('0x45')](_0x536e34)[_0x3377('0x25')](handleEntityNotFound(_0x491674,null))[_0x3377('0x25')](respondWithResult(_0x491674,null))['catch'](handleError(_0x491674,null));};exports[_0x3377('0x46')]=function(_0x1407b0,_0x5e748f){return db[_0x3377('0x2c')][_0x3377('0x46')](_0x1407b0['body'],{})[_0x3377('0x25')](function(_0x4d29c0){var _0x1e75dd=_0x1407b0['user'][_0x3377('0x26')]({'plain':!![]});if(!_0x1e75dd)throw new Error(_0x3377('0x47'));if(_0x1e75dd[_0x3377('0x48')]===_0x3377('0x49')){var _0x2651a1=_0x4d29c0['get']({'plain':!![]});var _0x24d7ef=_0x3377('0x4a');return db[_0x3377('0x4b')][_0x3377('0x45')]({'where':{'name':_0x24d7ef,'userProfileId':_0x1e75dd['userProfileId']},'raw':!![]})[_0x3377('0x25')](function(_0x293f09){if(_0x293f09&&_0x293f09['autoAssociation']===0x0){return db[_0x3377('0x27')][_0x3377('0x46')]({'name':_0x2651a1[_0x3377('0x4c')],'resourceId':_0x2651a1['id'],'type':_0x293f09['name'],'sectionId':_0x293f09['id']},{})[_0x3377('0x25')](function(){return _0x4d29c0;});}else{return _0x4d29c0;}})[_0x3377('0x4d')](function(_0x33bea7){logger[_0x3377('0x4e')](_0x3377('0x4f'),_0x33bea7);throw _0x33bea7;});}return _0x4d29c0;})[_0x3377('0x25')](respondWithResult(_0x5e748f,0xc9))[_0x3377('0x4d')](handleError(_0x5e748f,null));};exports[_0x3377('0x23')]=function(_0x43d93d,_0x55d4ef){if(_0x43d93d[_0x3377('0x50')]['id']){delete _0x43d93d[_0x3377('0x50')]['id'];}return db[_0x3377('0x2c')][_0x3377('0x45')]({'where':{'id':_0x43d93d[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0x55d4ef,null))['then'](saveUpdates(_0x43d93d[_0x3377('0x50')],null))[_0x3377('0x25')](respondWithResult(_0x55d4ef,null))[_0x3377('0x4d')](handleError(_0x55d4ef,null));};exports['destroy']=function(_0x2a46b0,_0x6b0f16){return db[_0x3377('0x2c')][_0x3377('0x45')]({'where':{'id':_0x2a46b0[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0x6b0f16,null))[_0x3377('0x25')](removeEntity(_0x6b0f16,null))[_0x3377('0x4d')](handleError(_0x6b0f16,null));};exports[_0x3377('0x52')]=function(_0x316971,_0x5b400f){return db[_0x3377('0x2c')][_0x3377('0x52')]()['then'](respondWithResult(_0x5b400f,null))[_0x3377('0x4d')](handleError(_0x5b400f,null));};exports[_0x3377('0x53')]=function(_0x3ac7d6,_0x156b89,_0x3df36e){var _0x27f9fe={'raw':!![],'where':{}},_0x5e9407={},_0xa9d4d1;return db[_0x3377('0x2c')][_0x3377('0x54')]({'where':{'id':_0x3ac7d6[_0x3377('0x51')]['id']}})['then'](handleEntityNotFound(_0x156b89,null))[_0x3377('0x25')](function(_0x242912){if(_0x242912){_0xa9d4d1=_0x242912[_0x3377('0x26')]({'plain':!![]});_0x5e9407[_0x3377('0x30')]=_['keys'](db['UserMailQueue'][_0x3377('0x2d')]);_0x5e9407[_0x3377('0x31')]=_['keys'](_0x3ac7d6[_0x3377('0x31')]);_0x5e9407[_0x3377('0x3b')]=_[_0x3377('0x33')](_0x5e9407[_0x3377('0x30')],_0x5e9407[_0x3377('0x31')]);_0x27f9fe[_0x3377('0x35')]=_[_0x3377('0x33')](_0x5e9407[_0x3377('0x30')],qs[_0x3377('0x34')](_0x3ac7d6[_0x3377('0x31')][_0x3377('0x34')]));_0x27f9fe['attributes']=_0x27f9fe[_0x3377('0x35')][_0x3377('0x36')]?_0x27f9fe[_0x3377('0x35')]:_0x5e9407['model'];if(!_0x3ac7d6[_0x3377('0x31')][_0x3377('0x37')](_0x3377('0x38'))){_0x27f9fe['limit']=qs[_0x3377('0x1e')](_0x3ac7d6[_0x3377('0x31')][_0x3377('0x1e')]);_0x27f9fe[_0x3377('0x20')]=qs['offset'](_0x3ac7d6[_0x3377('0x31')][_0x3377('0x20')]);}_0x27f9fe[_0x3377('0x55')]=qs[_0x3377('0x39')](_0x3ac7d6[_0x3377('0x31')][_0x3377('0x39')]);_0x27f9fe[_0x3377('0x3a')]=qs[_0x3377('0x3b')](_[_0x3377('0x3c')](_0x3ac7d6['query'],_0x5e9407[_0x3377('0x3b')]));_0x27f9fe[_0x3377('0x3a')][_0x3377('0x56')]=_0x242912['id'];if(_0x3ac7d6[_0x3377('0x31')][_0x3377('0x3d')]){_0x27f9fe[_0x3377('0x3a')]=_['merge'](_0x27f9fe[_0x3377('0x3a')],{'$or':_[_0x3377('0x2b')](_0x27f9fe[_0x3377('0x35')],function(_0x5a163b){var _0x161ab3={};_0x161ab3[_0x5a163b]={'$like':'%'+_0x3ac7d6[_0x3377('0x31')][_0x3377('0x3d')]+'%'};return _0x161ab3;})});}_0x27f9fe=_['merge']({},_0x27f9fe,_0x3ac7d6['options']);return db[_0x3377('0x57')][_0x3377('0x42')](_0x27f9fe);}})[_0x3377('0x25')](function(_0x1a1d3b){if(_0x1a1d3b){return db[_0x3377('0x58')]['findAndCountAll']({'where':{'id':_['map'](_0x1a1d3b,'UserId'),'role':_0x3377('0x59')},'attributes':['id','name',_0x3377('0x5a'),_0x3377('0x5b'),_0x3377('0x5c')]});}})[_0x3377('0x25')](function(_0x58f1fe){if(_0x58f1fe){return{'count':_0x58f1fe[_0x3377('0x1f')],'rows':_[_0x3377('0x2b')](_0x58f1fe['rows'],function(_0xd67d2d){return{'membername':_0xd67d2d[_0x3377('0x4c')],'UserId':_0xd67d2d['id'],'queue_name':_0xa9d4d1[_0x3377('0x4c')],'MailQueueId':_0xa9d4d1['id'],'interface':util['format']('%s/%s',_0x3377('0x5d'),_0xd67d2d[_0x3377('0x4c')]),'penalty':0x0,'paused':_0xd67d2d['mailPause'],'createdAt':_0xd67d2d[_0x3377('0x5c')],'updatedAt':_0xd67d2d[_0x3377('0x5b')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x3377('0x25')](respondWithFilteredResult(_0x156b89,_0x27f9fe))[_0x3377('0x4d')](handleError(_0x156b89,null));};exports[_0x3377('0x5e')]=function(_0x4c1d8c,_0x5e90aa,_0x1d00b8){var _0x3ba74d={};var _0x4f2121={};var _0x27745d;var _0x5436fa;return db[_0x3377('0x2c')]['findOne']({'where':{'id':_0x4c1d8c[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0x5e90aa,null))[_0x3377('0x25')](function(_0x4bf7f1){if(_0x4bf7f1){_0x27745d=_0x4bf7f1;_0x4f2121[_0x3377('0x30')]=_['keys'](db[_0x3377('0x5f')]['rawAttributes']);_0x4f2121[_0x3377('0x31')]=_['keys'](_0x4c1d8c[_0x3377('0x31')]);_0x4f2121[_0x3377('0x3b')]=_[_0x3377('0x33')](_0x4f2121[_0x3377('0x30')],_0x4f2121['query']);_0x3ba74d[_0x3377('0x35')]=_[_0x3377('0x33')](_0x4f2121[_0x3377('0x30')],qs['fields'](_0x4c1d8c[_0x3377('0x31')][_0x3377('0x34')]));_0x3ba74d[_0x3377('0x35')]=_0x3ba74d[_0x3377('0x35')]['length']?_0x3ba74d[_0x3377('0x35')]:_0x4f2121['model'];_0x3ba74d[_0x3377('0x55')]=qs[_0x3377('0x39')](_0x4c1d8c['query'][_0x3377('0x39')]);_0x3ba74d[_0x3377('0x3a')]=qs[_0x3377('0x3b')](_[_0x3377('0x3c')](_0x4c1d8c[_0x3377('0x31')],_0x4f2121[_0x3377('0x3b')]));if(_0x4c1d8c[_0x3377('0x31')][_0x3377('0x3d')]){_0x3ba74d[_0x3377('0x3a')]=_[_0x3377('0x3e')](_0x3ba74d[_0x3377('0x3a')],{'$or':_['map'](_0x3ba74d['attributes'],function(_0x2c93a0){var _0x132b28={};_0x132b28[_0x2c93a0]={'$like':'%'+_0x4c1d8c[_0x3377('0x31')][_0x3377('0x3d')]+'%'};return _0x132b28;})});}_0x3ba74d=_[_0x3377('0x3e')]({},_0x3ba74d,_0x4c1d8c[_0x3377('0x60')]);return _0x27745d[_0x3377('0x5e')](_0x3ba74d);}})['then'](function(_0x1511f9){if(_0x1511f9){_0x5436fa=_0x1511f9[_0x3377('0x36')];if(!_0x4c1d8c[_0x3377('0x31')]['hasOwnProperty'](_0x3377('0x38'))){_0x3ba74d['limit']=qs['limit'](_0x4c1d8c[_0x3377('0x31')][_0x3377('0x1e')]);_0x3ba74d[_0x3377('0x20')]=qs[_0x3377('0x20')](_0x4c1d8c['query']['offset']);}return _0x27745d[_0x3377('0x5e')](_0x3ba74d);}})['then'](function(_0x17e7f4){if(_0x17e7f4){return _0x17e7f4?{'count':_0x5436fa,'rows':_0x17e7f4}:null;}})[_0x3377('0x25')](respondWithResult(_0x5e90aa,null))[_0x3377('0x4d')](handleError(_0x5e90aa,null));};exports['addTeams']=function(_0x5e33d9,_0x24dd1c,_0x99f1a){var _0x1405b0=_0x5e33d9[_0x3377('0x50')]['ids'];return db[_0x3377('0x5f')][_0x3377('0x42')]({'where':{'id':_0x1405b0},'attributes':['id'],'include':[{'model':db[_0x3377('0x58')],'as':_0x3377('0x61'),'attributes':['id',_0x3377('0x4c'),_0x3377('0x62'),_0x3377('0x63'),_0x3377('0x64')],'raw':!![]}]})[_0x3377('0x25')](function(_0x11df46){if(_0x11df46){var _0x39fd8b=_[_0x3377('0x65')](_0x11df46,function(_0x4c4ba5){var _0x4b6125=_0x4c4ba5[_0x3377('0x26')]({'plain':!![]});return _0x4b6125['Agents'];});return db[_0x3377('0x2c')][_0x3377('0x45')]({'where':{'id':_0x5e33d9[_0x3377('0x51')]['id']}})[_0x3377('0x25')](function(_0x333ee3){return db[_0x3377('0x66')][_0x3377('0x67')](function(_0x1d5c7e){return _0x333ee3[_0x3377('0x68')](_0x1405b0,{'transaction':_0x1d5c7e})[_0x3377('0x25')](function(){return BPromise[_0x3377('0x69')](_0x39fd8b,function(_0x3f96e3){return db[_0x3377('0x57')][_0x3377('0x6a')]({'where':{'UserId':_0x3f96e3['id'],'MailQueueId':_0x5e33d9[_0x3377('0x51')]['id']},'transaction':_0x1d5c7e});});})['then'](function(){_0x39fd8b[_0x3377('0x6b')](function(_0x2e6639){socket[_0x3377('0x6c')]('userMailQueue:save',{'UserId':_0x2e6639['id'],'MailQueueId':_0x333ee3['id']});});});});});}})['then'](respondWithStatusCode(_0x24dd1c,null))[_0x3377('0x4d')](handleError(_0x24dd1c,null));};exports[_0x3377('0x6d')]=function(_0x51ee26,_0x429a15,_0x14e783){return db['Team'][_0x3377('0x42')]({'where':{'id':_0x51ee26['query']['ids']},'attributes':['id'],'include':[{'model':db[_0x3377('0x58')],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0x3377('0x25')](handleEntityNotFound(_0x429a15,null))[_0x3377('0x25')](function(_0x213776){var _0x595691=_[_0x3377('0x2b')](_0x213776,'id');var _0x54be59=[];var _0x3ecf8e=[];var _0xe688ce=squel[_0x3377('0x6e')]();_0xe688ce[_0x3377('0x6f')]('tq.TeamId')[_0x3377('0x70')](_0x3377('0x71'),'tq')[_0x3377('0x72')]('user_has_teams','ut',_0x3377('0x73'))[_0x3377('0x3a')](_0x3377('0x74'),_0x51ee26['params']['id']);for(var _0x10625b=0x0;_0x10625b<_0x213776[_0x3377('0x36')];_0x10625b+=0x1){let _0x2b5404=_0x213776[_0x10625b];for(var _0x9258f2=0x0;_0x9258f2<_0x2b5404['Agents'][_0x3377('0x36')];_0x9258f2+=0x1){let _0x1ae3f4=_0x2b5404['Agents'][_0x9258f2];var _0x1eae4b=_0xe688ce[_0x3377('0x75')]();_0x1eae4b[_0x3377('0x3a')]('ut.UserId\x20=\x20?',_0x1ae3f4['id']);_0x3ecf8e[_0x3377('0x76')](db[_0x3377('0x66')][_0x3377('0x31')](_0x1eae4b['toString'](),{'type':db[_0x3377('0x66')][_0x3377('0x77')]['SELECT']})[_0x3377('0x25')](function(_0x315ad1){if(_0x315ad1[_0x3377('0x36')]===0x1){return _0x1ae3f4['id'];}else{var _0x40564e=_['every'](_[_0x3377('0x2b')](_0x315ad1,_0x3377('0x78')),function(_0x13e1f0){return _['includes'](_0x595691,_0x13e1f0);});if(_0x40564e){return _0x1ae3f4['id'];}}}));}}return BPromise[_0x3377('0x79')](_0x3ecf8e)['then'](function(_0x4f573d){_0x54be59=_(_0x54be59)[_0x3377('0x7a')](_0x4f573d)[_0x3377('0x7b')]()[_0x3377('0x7c')]();return db[_0x3377('0x2c')]['find']({'where':{'id':_0x51ee26[_0x3377('0x51')]['id']}})[_0x3377('0x25')](function(_0x376bfd){return db[_0x3377('0x66')][_0x3377('0x67')](function(_0x2ff317){return _0x376bfd[_0x3377('0x6d')](_0x51ee26[_0x3377('0x31')][_0x3377('0x7d')],{'transaction':_0x2ff317})['then'](function(){if(!_[_0x3377('0x7e')](_0x54be59)){return _0x376bfd['removeAgents'](_0x54be59,{'transaction':_0x2ff317});}})[_0x3377('0x25')](function(){_0x54be59['forEach'](function(_0x350ee){socket[_0x3377('0x6c')]('userMailQueue:remove',{'UserId':_0x350ee,'MailQueueId':_0x376bfd['id']});});});});});});})[_0x3377('0x25')](respondWithStatusCode(_0x429a15,null))[_0x3377('0x4d')](handleError(_0x429a15,null));};exports['addAgents']=function(_0x434046,_0xb798b0,_0x5b5a74){return db['MailQueue'][_0x3377('0x45')]({'where':{'id':_0x434046[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0xb798b0,null))[_0x3377('0x25')](function(_0x1d1c8b){if(_0x1d1c8b){return _0x1d1c8b[_0x3377('0x7f')](_0x434046[_0x3377('0x50')][_0x3377('0x7d')],_[_0x3377('0x80')](_0x434046[_0x3377('0x50')],[_0x3377('0x7d'),'id'])||{})[_0x3377('0x81')](function(_0x58abc9){for(var _0x1028d9=0x0;_0x1028d9<_0x434046[_0x3377('0x50')][_0x3377('0x7d')]['length'];_0x1028d9+=0x1){socket['emit'](_0x3377('0x82'),{'UserId':Number(_0x434046['body'][_0x3377('0x7d')][_0x1028d9]),'MailQueueId':Number(_0x434046[_0x3377('0x51')]['id'])});}return _0x58abc9;});}})['then'](respondWithResult(_0xb798b0,null))[_0x3377('0x4d')](handleError(_0xb798b0,null));};exports['removeAgents']=function(_0x36fbf9,_0x217820,_0x3d5859){return db[_0x3377('0x2c')][_0x3377('0x45')]({'where':{'id':_0x36fbf9[_0x3377('0x51')]['id']}})[_0x3377('0x25')](handleEntityNotFound(_0x217820,null))[_0x3377('0x25')](function(_0x30432a){if(_0x30432a){return _0x30432a[_0x3377('0x83')](_0x36fbf9[_0x3377('0x31')][_0x3377('0x7d')])['then'](function(){if(_['isArray'](_0x36fbf9[_0x3377('0x31')][_0x3377('0x7d')])){for(var _0xcc833f=0x0;_0xcc833f<_0x36fbf9['query'][_0x3377('0x7d')]['length'];_0xcc833f+=0x1){socket[_0x3377('0x6c')](_0x3377('0x84'),{'UserId':Number(_0x36fbf9[_0x3377('0x31')]['ids'][_0xcc833f]),'MailQueueId':Number(_0x36fbf9[_0x3377('0x51')]['id'])});}}else{socket[_0x3377('0x6c')]('userMailQueue:remove',{'UserId':Number(_0x36fbf9['query']['ids']),'MailQueueId':Number(_0x36fbf9[_0x3377('0x51')]['id'])});}});}})[_0x3377('0x25')](respondWithStatusCode(_0x217820,null))[_0x3377('0x4d')](handleError(_0x217820,null));};exports['getAgents']=function(_0xe52892,_0x13b19f,_0x28c6a0){var _0x225456={};var _0x5637af={};var _0x5d152a;var _0x4460e0;return db[_0x3377('0x2c')]['findOne']({'where':{'id':_0xe52892[_0x3377('0x51')]['id']}})['then'](handleEntityNotFound(_0x13b19f,null))[_0x3377('0x25')](function(_0x2dbe0b){if(_0x2dbe0b){_0x5d152a=_0x2dbe0b;_0x5637af[_0x3377('0x30')]=_[_0x3377('0x32')](db[_0x3377('0x58')]['rawAttributes']);_0x5637af[_0x3377('0x31')]=_['keys'](_0xe52892[_0x3377('0x31')]);_0x5637af[_0x3377('0x3b')]=_['intersection'](_0x5637af[_0x3377('0x30')],_0x5637af['query']);_0x225456['attributes']=_[_0x3377('0x33')](_0x5637af['model'],qs[_0x3377('0x34')](_0xe52892[_0x3377('0x31')][_0x3377('0x34')]));_0x225456['attributes']=_0x225456[_0x3377('0x35')][_0x3377('0x36')]?_0x225456[_0x3377('0x35')]:_0x5637af[_0x3377('0x30')];_0x225456[_0x3377('0x55')]=qs['sort'](_0xe52892[_0x3377('0x31')]['sort']);_0x225456['where']=qs['filters'](_[_0x3377('0x3c')](_0xe52892[_0x3377('0x31')],_0x5637af['filters']));if(_0xe52892[_0x3377('0x31')][_0x3377('0x3d')]){_0x225456['where']=_[_0x3377('0x3e')](_0x225456['where'],{'$or':_['map'](_0x225456[_0x3377('0x35')],function(_0x5dc369){var _0x48f97f={};_0x48f97f[_0x5dc369]={'$like':'%'+_0xe52892[_0x3377('0x31')]['filter']+'%'};return _0x48f97f;})});}_0x225456=_[_0x3377('0x3e')]({},_0x225456,_0xe52892[_0x3377('0x60')]);return _0x5d152a[_0x3377('0x85')](_0x225456);}})['then'](function(_0x4173bc){if(_0x4173bc){_0x4460e0=_0x4173bc['length'];if(!_0xe52892[_0x3377('0x31')][_0x3377('0x37')]('nolimit')){_0x225456[_0x3377('0x1e')]=qs['limit'](_0xe52892[_0x3377('0x31')]['limit']);_0x225456['offset']=qs['offset'](_0xe52892[_0x3377('0x31')][_0x3377('0x20')]);}return _0x5d152a[_0x3377('0x85')](_0x225456);}})[_0x3377('0x25')](function(_0x17351e){if(_0x17351e){return _0x17351e?{'count':_0x4460e0,'rows':_0x17351e}:null;}})[_0x3377('0x25')](respondWithResult(_0x13b19f,null))[_0x3377('0x4d')](handleError(_0x13b19f,null));};
\ No newline at end of file