Built motion from commit 64440dd5.|2.6.29
[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 _0x3bf2=['attributes','fields','length','merge','options','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','getMembers','findOne','hasOwnProperty','nolimit','sort','pick','MailQueueId','filter','UserMailQueue','findAll','findAndCountAll','UserId','agent','mailPause','updatedAt','createdAt','SIP','getTeams','Team','order','addTeams','ids','User','Agents','online','voicePause','sequelize','transaction','forEach','removeTeams','field','from','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','MailQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','TeamId','includes','all','compact','isEmpty','removeAgents','emit','userMailQueue:remove','addAgents','omit','spread','userMailQueue:save','isArray','getAgents','bluebird','util','lodash','squel','../../components/parsers/qs','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','sendStatus','status','json','offset','undefined','count','limit','set','Content-Range','update','destroy','get','MailQueues','UserProfileResource','then','end','error','stack','name','map','MailQueue','rawAttributes','type','key','where','include','query','rows','catch','params','model','keys','filters','intersection'];(function(_0x2cac89,_0x134362){var _0x375819=function(_0x1be5d5){while(--_0x1be5d5){_0x2cac89['push'](_0x2cac89['shift']());}};_0x375819(++_0x134362);}(_0x3bf2,0x1a6));var _0x23bf=function(_0x1bae3e,_0x12950c){_0x1bae3e=_0x1bae3e-0x0;var _0x170b37=_0x3bf2[_0x1bae3e];return _0x170b37;};'use strict';var BPromise=require(_0x23bf('0x0'));var util=require(_0x23bf('0x1'));var _=require(_0x23bf('0x2'));var squel=require(_0x23bf('0x3'));var Redis=require('ioredis');var qs=require(_0x23bf('0x4'));var logger=require('../../config/logger')('api');var config=require(_0x23bf('0x5'));var db=require(_0x23bf('0x6'))['db'];config[_0x23bf('0x7')]=_[_0x23bf('0x8')](config[_0x23bf('0x7')],{'host':_0x23bf('0x9'),'port':0x18eb});var socket=require(_0x23bf('0xa'))(new Redis(config['redis']));require('./mailQueue.socket')[_0x23bf('0xb')](socket);function respondWithStatusCode(_0x32f64a,_0x5a8a5d){_0x5a8a5d=_0x5a8a5d||0xcc;return function(_0x186404){if(_0x186404){return _0x32f64a[_0x23bf('0xc')](_0x5a8a5d);}return _0x32f64a[_0x23bf('0xd')](_0x5a8a5d)['end']();};}function respondWithResult(_0x3e9a55,_0x421b13){_0x421b13=_0x421b13||0xc8;return function(_0xa87b23){if(_0xa87b23){return _0x3e9a55['status'](_0x421b13)[_0x23bf('0xe')](_0xa87b23);}};}function respondWithFilteredResult(_0xfa1b98,_0x2439da){return function(_0x3d79f4){if(_0x3d79f4){var _0x15d493=typeof _0x2439da[_0x23bf('0xf')]===_0x23bf('0x10')&&typeof _0x2439da['limit']===_0x23bf('0x10');var _0x1a33c5=_0x3d79f4[_0x23bf('0x11')];var _0x468222=_0x15d493?0x0:_0x2439da[_0x23bf('0xf')];var _0x59b9c0=_0x15d493?_0x3d79f4[_0x23bf('0x11')]:_0x2439da[_0x23bf('0xf')]+_0x2439da[_0x23bf('0x12')];var _0x1acc04;if(_0x59b9c0>=_0x1a33c5){_0x59b9c0=_0x1a33c5;_0x1acc04=0xc8;}else{_0x1acc04=0xce;}_0xfa1b98['status'](_0x1acc04);return _0xfa1b98[_0x23bf('0x13')](_0x23bf('0x14'),_0x468222+'-'+_0x59b9c0+'/'+_0x1a33c5)[_0x23bf('0xe')](_0x3d79f4);}return null;};}function saveUpdates(_0x4fab2a){return function(_0x19a683){if(_0x19a683){return _0x19a683[_0x23bf('0x15')](_0x4fab2a)['then'](function(_0x4daa94){return _0x4daa94;});}return null;};}function removeEntity(_0x190da4){return function(_0x547340){if(_0x547340){return _0x547340[_0x23bf('0x16')]()['then'](function(){var _0x3907fc=_0x547340[_0x23bf('0x17')]({'plain':!![]});var _0x24d59b=_0x23bf('0x18');return db[_0x23bf('0x19')]['destroy']({'where':{'type':_0x24d59b,'resourceId':_0x3907fc['id']}})[_0x23bf('0x1a')](function(){return _0x547340;});})['then'](function(){_0x190da4[_0x23bf('0xd')](0xcc)[_0x23bf('0x1b')]();});}};}function handleEntityNotFound(_0xba483f){return function(_0x528979){if(!_0x528979){_0xba483f[_0x23bf('0xc')](0x194);}return _0x528979;};}function handleError(_0x3455ae,_0x25374c){_0x25374c=_0x25374c||0x1f4;return function(_0x4fe2e1){logger[_0x23bf('0x1c')](_0x4fe2e1[_0x23bf('0x1d')]);if(_0x4fe2e1[_0x23bf('0x1e')]){delete _0x4fe2e1[_0x23bf('0x1e')];}_0x3455ae[_0x23bf('0xd')](_0x25374c)['send'](_0x4fe2e1);};}exports['index']=function(_0x4be0f9,_0x1feda9){var _0x3c161a={};var _0x53bf73={'count':0x0,'rows':[]};var _0x5ec7ee=_[_0x23bf('0x1f')](db[_0x23bf('0x20')][_0x23bf('0x21')],function(_0x3cc7bd){return{'name':_0x3cc7bd['fieldName'],'type':_0x3cc7bd[_0x23bf('0x22')][_0x23bf('0x23')]};});_0x3c161a=qs['getOptions'](_0x5ec7ee,_0x4be0f9);var _0x55326d={'where':_0x3c161a[_0x23bf('0x24')]};return db[_0x23bf('0x20')][_0x23bf('0x11')](_0x55326d)[_0x23bf('0x1a')](function(_0x57ecdc){_0x53bf73[_0x23bf('0x11')]=_0x57ecdc;_0x3c161a['include']=qs[_0x23bf('0x25')](_0x4be0f9[_0x23bf('0x26')]);return db['MailQueue']['findAll'](_0x3c161a);})[_0x23bf('0x1a')](function(_0x213027){_0x53bf73[_0x23bf('0x27')]=_0x213027;return _0x53bf73;})['then'](respondWithFilteredResult(_0x1feda9,_0x3c161a))[_0x23bf('0x28')](handleError(_0x1feda9,null));};exports['show']=function(_0x28d5b8,_0x35feb1){var _0xef337c={'raw':!![],'where':{'id':_0x28d5b8[_0x23bf('0x29')]['id']}},_0x14a2d2={};_0x14a2d2[_0x23bf('0x2a')]=_[_0x23bf('0x2b')](db[_0x23bf('0x20')]['rawAttributes']);_0x14a2d2['query']=_[_0x23bf('0x2b')](_0x28d5b8[_0x23bf('0x26')]);_0x14a2d2[_0x23bf('0x2c')]=_[_0x23bf('0x2d')](_0x14a2d2['model'],_0x14a2d2[_0x23bf('0x26')]);_0xef337c[_0x23bf('0x2e')]=_[_0x23bf('0x2d')](_0x14a2d2[_0x23bf('0x2a')],qs[_0x23bf('0x2f')](_0x28d5b8['query'][_0x23bf('0x2f')]));_0xef337c[_0x23bf('0x2e')]=_0xef337c[_0x23bf('0x2e')][_0x23bf('0x30')]?_0xef337c['attributes']:_0x14a2d2['model'];if(_0x28d5b8['query']['includeAll']){_0xef337c[_0x23bf('0x25')]=[{'all':!![]}];}_0xef337c=_[_0x23bf('0x31')]({},_0xef337c,_0x28d5b8[_0x23bf('0x32')]);return db[_0x23bf('0x20')]['find'](_0xef337c)[_0x23bf('0x1a')](handleEntityNotFound(_0x35feb1,null))[_0x23bf('0x1a')](respondWithResult(_0x35feb1,null))['catch'](handleError(_0x35feb1,null));};exports[_0x23bf('0x33')]=function(_0x412e08,_0x3d23f1){return db[_0x23bf('0x20')][_0x23bf('0x33')](_0x412e08['body'],{})[_0x23bf('0x1a')](function(_0x14bcc7){var _0xbdf21e=_0x412e08[_0x23bf('0x34')][_0x23bf('0x17')]({'plain':!![]});if(!_0xbdf21e)throw new Error(_0x23bf('0x35'));if(_0xbdf21e['role']===_0x23bf('0x34')){var _0x3ea5aa=_0x14bcc7[_0x23bf('0x17')]({'plain':!![]});var _0x4ec991=_0x23bf('0x18');return db[_0x23bf('0x36')][_0x23bf('0x37')]({'where':{'name':_0x4ec991,'userProfileId':_0xbdf21e[_0x23bf('0x38')]},'raw':!![]})['then'](function(_0x1291fc){if(_0x1291fc&&_0x1291fc[_0x23bf('0x39')]===0x0){return db['UserProfileResource']['create']({'name':_0x3ea5aa['name'],'resourceId':_0x3ea5aa['id'],'type':_0x1291fc[_0x23bf('0x1e')],'sectionId':_0x1291fc['id']},{})[_0x23bf('0x1a')](function(){return _0x14bcc7;});}else{return _0x14bcc7;}})['catch'](function(_0x519581){logger[_0x23bf('0x1c')](_0x23bf('0x3a'),_0x519581);throw _0x519581;});}return _0x14bcc7;})[_0x23bf('0x1a')](respondWithResult(_0x3d23f1,0xc9))['catch'](handleError(_0x3d23f1,null));};exports[_0x23bf('0x15')]=function(_0x63dbb7,_0x1596c3){if(_0x63dbb7[_0x23bf('0x3b')]['id']){delete _0x63dbb7[_0x23bf('0x3b')]['id'];}return db[_0x23bf('0x20')][_0x23bf('0x37')]({'where':{'id':_0x63dbb7['params']['id']}})[_0x23bf('0x1a')](handleEntityNotFound(_0x1596c3,null))['then'](saveUpdates(_0x63dbb7[_0x23bf('0x3b')],null))['then'](respondWithResult(_0x1596c3,null))[_0x23bf('0x28')](handleError(_0x1596c3,null));};exports['destroy']=function(_0x2ad3c4,_0x3a08cd){return db[_0x23bf('0x20')][_0x23bf('0x37')]({'where':{'id':_0x2ad3c4['params']['id']}})[_0x23bf('0x1a')](handleEntityNotFound(_0x3a08cd,null))['then'](removeEntity(_0x3a08cd,null))[_0x23bf('0x28')](handleError(_0x3a08cd,null));};exports['describe']=function(_0x3b70fd,_0x1a4f02){return db['MailQueue'][_0x23bf('0x3c')]()['then'](respondWithResult(_0x1a4f02,null))[_0x23bf('0x28')](handleError(_0x1a4f02,null));};exports[_0x23bf('0x3d')]=function(_0x45862a,_0x29bbfe){var _0x315429={'raw':!![],'where':{}},_0x44e9f2={},_0x17e9b;return db[_0x23bf('0x20')][_0x23bf('0x3e')]({'where':{'id':_0x45862a[_0x23bf('0x29')]['id']}})[_0x23bf('0x1a')](handleEntityNotFound(_0x29bbfe,null))[_0x23bf('0x1a')](function(_0x3b3e8){if(_0x3b3e8){_0x17e9b=_0x3b3e8[_0x23bf('0x17')]({'plain':!![]});_0x44e9f2[_0x23bf('0x2a')]=_[_0x23bf('0x2b')](db['UserMailQueue'][_0x23bf('0x21')]);_0x44e9f2[_0x23bf('0x26')]=_['keys'](_0x45862a[_0x23bf('0x26')]);_0x44e9f2[_0x23bf('0x2c')]=_[_0x23bf('0x2d')](_0x44e9f2[_0x23bf('0x2a')],_0x44e9f2[_0x23bf('0x26')]);_0x315429['attributes']=_[_0x23bf('0x2d')](_0x44e9f2['model'],qs[_0x23bf('0x2f')](_0x45862a['query'][_0x23bf('0x2f')]));_0x315429[_0x23bf('0x2e')]=_0x315429['attributes'][_0x23bf('0x30')]?_0x315429[_0x23bf('0x2e')]:_0x44e9f2[_0x23bf('0x2a')];if(!_0x45862a['query'][_0x23bf('0x3f')](_0x23bf('0x40'))){_0x315429[_0x23bf('0x12')]=qs[_0x23bf('0x12')](_0x45862a[_0x23bf('0x26')]['limit']);_0x315429[_0x23bf('0xf')]=qs[_0x23bf('0xf')](_0x45862a['query'][_0x23bf('0xf')]);}_0x315429['order']=qs[_0x23bf('0x41')](_0x45862a[_0x23bf('0x26')][_0x23bf('0x41')]);_0x315429['where']=qs['filters'](_[_0x23bf('0x42')](_0x45862a['query'],_0x44e9f2[_0x23bf('0x2c')]));_0x315429[_0x23bf('0x24')][_0x23bf('0x43')]=_0x3b3e8['id'];if(_0x45862a[_0x23bf('0x26')][_0x23bf('0x44')]){_0x315429[_0x23bf('0x24')]=_[_0x23bf('0x31')](_0x315429[_0x23bf('0x24')],{'$or':_[_0x23bf('0x1f')](_0x315429[_0x23bf('0x2e')],function(_0x3ccfd0){var _0x31c3ed={};_0x31c3ed[_0x3ccfd0]={'$like':'%'+_0x45862a['query'][_0x23bf('0x44')]+'%'};return _0x31c3ed;})});}_0x315429=_[_0x23bf('0x31')]({},_0x315429,_0x45862a['options']);return db[_0x23bf('0x45')][_0x23bf('0x46')](_0x315429);}})[_0x23bf('0x1a')](function(_0x1935cf){if(_0x1935cf){return db['User'][_0x23bf('0x47')]({'where':{'id':_[_0x23bf('0x1f')](_0x1935cf,_0x23bf('0x48')),'role':_0x23bf('0x49')},'attributes':['id',_0x23bf('0x1e'),_0x23bf('0x4a'),_0x23bf('0x4b'),_0x23bf('0x4c')]});}})[_0x23bf('0x1a')](function(_0x5d65ea){if(_0x5d65ea){return{'count':_0x5d65ea[_0x23bf('0x11')],'rows':_[_0x23bf('0x1f')](_0x5d65ea['rows'],function(_0x4cdcf5){return{'membername':_0x4cdcf5[_0x23bf('0x1e')],'UserId':_0x4cdcf5['id'],'queue_name':_0x17e9b[_0x23bf('0x1e')],'MailQueueId':_0x17e9b['id'],'interface':util['format']('%s/%s',_0x23bf('0x4d'),_0x4cdcf5[_0x23bf('0x1e')]),'penalty':0x0,'paused':_0x4cdcf5[_0x23bf('0x4a')],'createdAt':_0x4cdcf5[_0x23bf('0x4c')],'updatedAt':_0x4cdcf5[_0x23bf('0x4b')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x23bf('0x1a')](respondWithFilteredResult(_0x29bbfe,_0x315429))[_0x23bf('0x28')](handleError(_0x29bbfe,null));};exports[_0x23bf('0x4e')]=function(_0x5175ad,_0x3c31a4){var _0x1d8869={};var _0x1d4b31={};var _0x1a5053;var _0x468812;return db['MailQueue'][_0x23bf('0x3e')]({'where':{'id':_0x5175ad['params']['id']}})['then'](handleEntityNotFound(_0x3c31a4,null))['then'](function(_0x29b66a){if(_0x29b66a){_0x1a5053=_0x29b66a;_0x1d4b31[_0x23bf('0x2a')]=_['keys'](db[_0x23bf('0x4f')][_0x23bf('0x21')]);_0x1d4b31[_0x23bf('0x26')]=_['keys'](_0x5175ad['query']);_0x1d4b31['filters']=_[_0x23bf('0x2d')](_0x1d4b31[_0x23bf('0x2a')],_0x1d4b31[_0x23bf('0x26')]);_0x1d8869['attributes']=_['intersection'](_0x1d4b31['model'],qs[_0x23bf('0x2f')](_0x5175ad['query'][_0x23bf('0x2f')]));_0x1d8869[_0x23bf('0x2e')]=_0x1d8869['attributes'][_0x23bf('0x30')]?_0x1d8869['attributes']:_0x1d4b31[_0x23bf('0x2a')];_0x1d8869[_0x23bf('0x50')]=qs[_0x23bf('0x41')](_0x5175ad[_0x23bf('0x26')][_0x23bf('0x41')]);_0x1d8869['where']=qs[_0x23bf('0x2c')](_[_0x23bf('0x42')](_0x5175ad[_0x23bf('0x26')],_0x1d4b31['filters']));if(_0x5175ad[_0x23bf('0x26')][_0x23bf('0x44')]){_0x1d8869[_0x23bf('0x24')]=_[_0x23bf('0x31')](_0x1d8869[_0x23bf('0x24')],{'$or':_[_0x23bf('0x1f')](_0x1d8869[_0x23bf('0x2e')],function(_0x5c6496){var _0x559c4e={};_0x559c4e[_0x5c6496]={'$like':'%'+_0x5175ad[_0x23bf('0x26')][_0x23bf('0x44')]+'%'};return _0x559c4e;})});}_0x1d8869=_[_0x23bf('0x31')]({},_0x1d8869,_0x5175ad[_0x23bf('0x32')]);return _0x1a5053[_0x23bf('0x4e')](_0x1d8869);}})[_0x23bf('0x1a')](function(_0x34a0e9){if(_0x34a0e9){_0x468812=_0x34a0e9[_0x23bf('0x30')];if(!_0x5175ad[_0x23bf('0x26')][_0x23bf('0x3f')](_0x23bf('0x40'))){_0x1d8869[_0x23bf('0x12')]=qs['limit'](_0x5175ad[_0x23bf('0x26')][_0x23bf('0x12')]);_0x1d8869[_0x23bf('0xf')]=qs[_0x23bf('0xf')](_0x5175ad[_0x23bf('0x26')]['offset']);}return _0x1a5053[_0x23bf('0x4e')](_0x1d8869);}})[_0x23bf('0x1a')](function(_0x528c42){if(_0x528c42){return _0x528c42?{'count':_0x468812,'rows':_0x528c42}:null;}})['then'](respondWithResult(_0x3c31a4,null))[_0x23bf('0x28')](handleError(_0x3c31a4,null));};exports[_0x23bf('0x51')]=function(_0x1c0fad,_0x22b6ae){var _0x1173ff=_0x1c0fad['body'][_0x23bf('0x52')];return db['Team'][_0x23bf('0x46')]({'where':{'id':_0x1173ff},'attributes':['id'],'include':[{'model':db[_0x23bf('0x53')],'as':_0x23bf('0x54'),'attributes':['id',_0x23bf('0x1e'),_0x23bf('0x55'),_0x23bf('0x56'),'interface'],'raw':!![]}]})[_0x23bf('0x1a')](function(_0x131468){if(_0x131468){var _0x732992=_['flatMap'](_0x131468,function(_0x4ffdaa){var _0x3153d6=_0x4ffdaa[_0x23bf('0x17')]({'plain':!![]});return _0x3153d6[_0x23bf('0x54')];});return db[_0x23bf('0x20')][_0x23bf('0x37')]({'where':{'id':_0x1c0fad[_0x23bf('0x29')]['id']}})[_0x23bf('0x1a')](function(_0x506ab0){return db[_0x23bf('0x57')][_0x23bf('0x58')](function(_0xaf8ba0){return _0x506ab0[_0x23bf('0x51')](_0x1173ff,{'transaction':_0xaf8ba0})[_0x23bf('0x1a')](function(){return BPromise['each'](_0x732992,function(_0x3368e3){return db[_0x23bf('0x45')]['findOrCreate']({'where':{'UserId':_0x3368e3['id'],'MailQueueId':_0x1c0fad[_0x23bf('0x29')]['id']},'transaction':_0xaf8ba0});});})[_0x23bf('0x1a')](function(){_0x732992[_0x23bf('0x59')](function(_0x5f1510){socket['emit']('userMailQueue:save',{'UserId':_0x5f1510['id'],'MailQueueId':_0x506ab0['id']});});});});});}})[_0x23bf('0x1a')](respondWithStatusCode(_0x22b6ae,null))['catch'](handleError(_0x22b6ae,null));};exports[_0x23bf('0x5a')]=function(_0x35ef83,_0x3947f8){return db['Team'][_0x23bf('0x46')]({'where':{'id':_0x35ef83[_0x23bf('0x26')][_0x23bf('0x52')]},'attributes':['id'],'include':[{'model':db[_0x23bf('0x53')],'as':_0x23bf('0x54'),'attributes':['id'],'raw':!![]}]})[_0x23bf('0x1a')](handleEntityNotFound(_0x3947f8,null))[_0x23bf('0x1a')](function(_0x1d6233){var _0x545450=_['map'](_0x1d6233,'id');var _0x3287dc=[];var _0x3d187f=[];var _0x20c581=squel['select']();_0x20c581[_0x23bf('0x5b')]('tq.TeamId')[_0x23bf('0x5c')]('team_has_mail_queues','tq')[_0x23bf('0x5d')](_0x23bf('0x5e'),'ut',_0x23bf('0x5f'))[_0x23bf('0x24')](_0x23bf('0x60'),_0x35ef83['params']['id']);for(var _0x1cea28=0x0;_0x1cea28<_0x1d6233[_0x23bf('0x30')];_0x1cea28+=0x1){let _0x11a6c4=_0x1d6233[_0x1cea28];for(var _0x1408d8=0x0;_0x1408d8<_0x11a6c4[_0x23bf('0x54')][_0x23bf('0x30')];_0x1408d8+=0x1){let _0x13812a=_0x11a6c4[_0x23bf('0x54')][_0x1408d8];var _0x49b0aa=_0x20c581[_0x23bf('0x61')]();_0x49b0aa[_0x23bf('0x24')](_0x23bf('0x62'),_0x13812a['id']);_0x3d187f[_0x23bf('0x63')](db[_0x23bf('0x57')][_0x23bf('0x26')](_0x49b0aa[_0x23bf('0x64')](),{'type':db[_0x23bf('0x57')][_0x23bf('0x65')][_0x23bf('0x66')]})[_0x23bf('0x1a')](function(_0x5e39d0){if(_0x5e39d0['length']===0x1){return _0x13812a['id'];}else{var _0x8416d4=_['every'](_[_0x23bf('0x1f')](_0x5e39d0,_0x23bf('0x67')),function(_0x388d8d){return _[_0x23bf('0x68')](_0x545450,_0x388d8d);});if(_0x8416d4){return _0x13812a['id'];}}}));}}return BPromise[_0x23bf('0x69')](_0x3d187f)[_0x23bf('0x1a')](function(_0x21af31){_0x3287dc=_(_0x3287dc)['union'](_0x21af31)[_0x23bf('0x6a')]()['value']();return db[_0x23bf('0x20')]['find']({'where':{'id':_0x35ef83[_0x23bf('0x29')]['id']}})[_0x23bf('0x1a')](function(_0x2eca03){return db[_0x23bf('0x57')][_0x23bf('0x58')](function(_0x2883ce){return _0x2eca03[_0x23bf('0x5a')](_0x35ef83[_0x23bf('0x26')][_0x23bf('0x52')],{'transaction':_0x2883ce})['then'](function(){if(!_[_0x23bf('0x6b')](_0x3287dc)){return _0x2eca03[_0x23bf('0x6c')](_0x3287dc,{'transaction':_0x2883ce});}})[_0x23bf('0x1a')](function(){_0x3287dc[_0x23bf('0x59')](function(_0xeb8fc8){socket[_0x23bf('0x6d')](_0x23bf('0x6e'),{'UserId':_0xeb8fc8,'MailQueueId':_0x2eca03['id']});});});});});});})[_0x23bf('0x1a')](respondWithStatusCode(_0x3947f8,null))['catch'](handleError(_0x3947f8,null));};exports['addAgents']=function(_0x207bf9,_0x743ff5){return db[_0x23bf('0x20')][_0x23bf('0x37')]({'where':{'id':_0x207bf9[_0x23bf('0x29')]['id']}})[_0x23bf('0x1a')](handleEntityNotFound(_0x743ff5,null))[_0x23bf('0x1a')](function(_0x519948){if(_0x519948){return _0x519948[_0x23bf('0x6f')](_0x207bf9[_0x23bf('0x3b')][_0x23bf('0x52')],_[_0x23bf('0x70')](_0x207bf9['body'],[_0x23bf('0x52'),'id'])||{})[_0x23bf('0x71')](function(_0x5b6e45){for(var _0x4ac5c3=0x0;_0x4ac5c3<_0x207bf9[_0x23bf('0x3b')][_0x23bf('0x52')][_0x23bf('0x30')];_0x4ac5c3+=0x1){socket[_0x23bf('0x6d')](_0x23bf('0x72'),{'UserId':Number(_0x207bf9[_0x23bf('0x3b')][_0x23bf('0x52')][_0x4ac5c3]),'MailQueueId':Number(_0x207bf9[_0x23bf('0x29')]['id'])});}return _0x5b6e45;});}})[_0x23bf('0x1a')](respondWithResult(_0x743ff5,null))[_0x23bf('0x28')](handleError(_0x743ff5,null));};exports[_0x23bf('0x6c')]=function(_0x30aafb,_0x473b08){return db[_0x23bf('0x20')]['find']({'where':{'id':_0x30aafb[_0x23bf('0x29')]['id']}})[_0x23bf('0x1a')](handleEntityNotFound(_0x473b08,null))[_0x23bf('0x1a')](function(_0x70671e){if(_0x70671e){return _0x70671e['removeAgents'](_0x30aafb[_0x23bf('0x26')]['ids'])['then'](function(){if(_[_0x23bf('0x73')](_0x30aafb[_0x23bf('0x26')]['ids'])){for(var _0x2db36b=0x0;_0x2db36b<_0x30aafb[_0x23bf('0x26')][_0x23bf('0x52')][_0x23bf('0x30')];_0x2db36b+=0x1){socket[_0x23bf('0x6d')]('userMailQueue:remove',{'UserId':Number(_0x30aafb[_0x23bf('0x26')][_0x23bf('0x52')][_0x2db36b]),'MailQueueId':Number(_0x30aafb[_0x23bf('0x29')]['id'])});}}else{socket[_0x23bf('0x6d')](_0x23bf('0x6e'),{'UserId':Number(_0x30aafb[_0x23bf('0x26')]['ids']),'MailQueueId':Number(_0x30aafb[_0x23bf('0x29')]['id'])});}});}})[_0x23bf('0x1a')](respondWithStatusCode(_0x473b08,null))[_0x23bf('0x28')](handleError(_0x473b08,null));};exports[_0x23bf('0x74')]=function(_0x4aad8f,_0x2275c5){var _0x34d799={};var _0x5e899a={};var _0x5641f6;var _0x4d4654;return db[_0x23bf('0x20')]['findOne']({'where':{'id':_0x4aad8f[_0x23bf('0x29')]['id']}})[_0x23bf('0x1a')](handleEntityNotFound(_0x2275c5,null))[_0x23bf('0x1a')](function(_0xf6f227){if(_0xf6f227){_0x5641f6=_0xf6f227;_0x5e899a[_0x23bf('0x2a')]=_['keys'](db[_0x23bf('0x53')][_0x23bf('0x21')]);_0x5e899a[_0x23bf('0x26')]=_[_0x23bf('0x2b')](_0x4aad8f['query']);_0x5e899a[_0x23bf('0x2c')]=_['intersection'](_0x5e899a[_0x23bf('0x2a')],_0x5e899a[_0x23bf('0x26')]);_0x34d799[_0x23bf('0x2e')]=_['intersection'](_0x5e899a[_0x23bf('0x2a')],qs[_0x23bf('0x2f')](_0x4aad8f[_0x23bf('0x26')][_0x23bf('0x2f')]));_0x34d799[_0x23bf('0x2e')]=_0x34d799['attributes'][_0x23bf('0x30')]?_0x34d799['attributes']:_0x5e899a[_0x23bf('0x2a')];_0x34d799[_0x23bf('0x50')]=qs[_0x23bf('0x41')](_0x4aad8f[_0x23bf('0x26')][_0x23bf('0x41')]);_0x34d799['where']=qs[_0x23bf('0x2c')](_['pick'](_0x4aad8f[_0x23bf('0x26')],_0x5e899a[_0x23bf('0x2c')]));if(_0x4aad8f['query']['filter']){_0x34d799[_0x23bf('0x24')]=_['merge'](_0x34d799[_0x23bf('0x24')],{'$or':_['map'](_0x34d799[_0x23bf('0x2e')],function(_0x3a4609){var _0x4c6616={};_0x4c6616[_0x3a4609]={'$like':'%'+_0x4aad8f['query']['filter']+'%'};return _0x4c6616;})});}_0x34d799=_[_0x23bf('0x31')]({},_0x34d799,_0x4aad8f[_0x23bf('0x32')]);return _0x5641f6[_0x23bf('0x74')](_0x34d799);}})[_0x23bf('0x1a')](function(_0x13618f){if(_0x13618f){_0x4d4654=_0x13618f[_0x23bf('0x30')];if(!_0x4aad8f['query']['hasOwnProperty']('nolimit')){_0x34d799[_0x23bf('0x12')]=qs[_0x23bf('0x12')](_0x4aad8f['query'][_0x23bf('0x12')]);_0x34d799[_0x23bf('0xf')]=qs[_0x23bf('0xf')](_0x4aad8f[_0x23bf('0x26')]['offset']);}return _0x5641f6[_0x23bf('0x74')](_0x34d799);}})[_0x23bf('0x1a')](function(_0x556aaf){if(_0x556aaf){return _0x556aaf?{'count':_0x4d4654,'rows':_0x556aaf}:null;}})[_0x23bf('0x1a')](respondWithResult(_0x2275c5,null))[_0x23bf('0x28')](handleError(_0x2275c5,null));};