Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / api / mailQueue / mailQueue.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 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));};