Built motion from commit ecb45b58.|2.6.31
[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 _0x6f40=['nolimit','order','sort','where','MailQueueId','filter','options','User','findAndCountAll','UserId','agent','mailPause','updatedAt','createdAt','rows','format','%s/%s','SIP','getTeams','Team','hasOwnProperty','addTeams','Agents','interface','sequelize','transaction','each','UserMailQueue','findOrCreate','removeTeams','ids','select','tq.TeamId','from','team_has_mail_queues','join','ut.TeamId\x20=\x20tq.TeamId','MailQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','TeamId','includes','all','compact','removeAgents','forEach','emit','userMailQueue:remove','addAgents','omit','spread','userMailQueue:save','isArray','getAgents','bluebird','lodash','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailQueue.socket','register','sendStatus','end','status','undefined','limit','count','offset','set','Content-Range','json','update','then','destroy','MailQueues','UserProfileResource','error','stack','name','index','map','MailQueue','rawAttributes','type','key','getOptions','include','query','findAll','show','params','model','keys','filters','intersection','fields','attributes','length','merge','catch','create','body','user','get','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','findOne'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x6f40,0x1ab));var _0x06f4=function(_0x2cfbcf,_0x2cf96f){_0x2cfbcf=_0x2cfbcf-0x0;var _0x41fc13=_0x6f40[_0x2cfbcf];return _0x41fc13;};'use strict';var BPromise=require(_0x06f4('0x0'));var util=require('util');var _=require(_0x06f4('0x1'));var squel=require('squel');var Redis=require(_0x06f4('0x2'));var qs=require(_0x06f4('0x3'));var logger=require(_0x06f4('0x4'))(_0x06f4('0x5'));var config=require(_0x06f4('0x6'));var db=require(_0x06f4('0x7'))['db'];config[_0x06f4('0x8')]=_[_0x06f4('0x9')](config[_0x06f4('0x8')],{'host':_0x06f4('0xa'),'port':0x18eb});var socket=require(_0x06f4('0xb'))(new Redis(config[_0x06f4('0x8')]));require(_0x06f4('0xc'))[_0x06f4('0xd')](socket);function respondWithStatusCode(_0x49bbf2,_0x133735){_0x133735=_0x133735||0xcc;return function(_0x98d6b9){if(_0x98d6b9){return _0x49bbf2[_0x06f4('0xe')](_0x133735);}return _0x49bbf2['status'](_0x133735)[_0x06f4('0xf')]();};}function respondWithResult(_0x4b5be7,_0x5a9120){_0x5a9120=_0x5a9120||0xc8;return function(_0x38ff1b){if(_0x38ff1b){return _0x4b5be7[_0x06f4('0x10')](_0x5a9120)['json'](_0x38ff1b);}};}function respondWithFilteredResult(_0x2d9b27,_0x56aef8){return function(_0x3ee5b6){if(_0x3ee5b6){var _0x551b83=typeof _0x56aef8['offset']===_0x06f4('0x11')&&typeof _0x56aef8[_0x06f4('0x12')]===_0x06f4('0x11');var _0x5dd019=_0x3ee5b6[_0x06f4('0x13')];var _0x4bc7bb=_0x551b83?0x0:_0x56aef8['offset'];var _0x5fa05b=_0x551b83?_0x3ee5b6[_0x06f4('0x13')]:_0x56aef8[_0x06f4('0x14')]+_0x56aef8[_0x06f4('0x12')];var _0x3fede8;if(_0x5fa05b>=_0x5dd019){_0x5fa05b=_0x5dd019;_0x3fede8=0xc8;}else{_0x3fede8=0xce;}_0x2d9b27['status'](_0x3fede8);return _0x2d9b27[_0x06f4('0x15')](_0x06f4('0x16'),_0x4bc7bb+'-'+_0x5fa05b+'/'+_0x5dd019)[_0x06f4('0x17')](_0x3ee5b6);}return null;};}function saveUpdates(_0x1ecd67){return function(_0x5b3005){if(_0x5b3005){return _0x5b3005[_0x06f4('0x18')](_0x1ecd67)[_0x06f4('0x19')](function(_0x189995){return _0x189995;});}return null;};}function removeEntity(_0x1f10a2){return function(_0x1f3354){if(_0x1f3354){return _0x1f3354[_0x06f4('0x1a')]()['then'](function(){var _0xc1d7d=_0x1f3354['get']({'plain':!![]});var _0x1dd897=_0x06f4('0x1b');return db[_0x06f4('0x1c')][_0x06f4('0x1a')]({'where':{'type':_0x1dd897,'resourceId':_0xc1d7d['id']}})['then'](function(){return _0x1f3354;});})[_0x06f4('0x19')](function(){_0x1f10a2[_0x06f4('0x10')](0xcc)[_0x06f4('0xf')]();});}};}function handleEntityNotFound(_0x4a865f){return function(_0xa772b9){if(!_0xa772b9){_0x4a865f[_0x06f4('0xe')](0x194);}return _0xa772b9;};}function handleError(_0x3b32a6,_0x4ae304){_0x4ae304=_0x4ae304||0x1f4;return function(_0x1f0c37){logger[_0x06f4('0x1d')](_0x1f0c37[_0x06f4('0x1e')]);if(_0x1f0c37[_0x06f4('0x1f')]){delete _0x1f0c37[_0x06f4('0x1f')];}_0x3b32a6[_0x06f4('0x10')](_0x4ae304)['send'](_0x1f0c37);};}exports[_0x06f4('0x20')]=function(_0x5d58c8,_0x1456c3){var _0x5362e6={};var _0x1d79d4={'count':0x0,'rows':[]};var _0x5118a0=_[_0x06f4('0x21')](db[_0x06f4('0x22')][_0x06f4('0x23')],function(_0x52428b){return{'name':_0x52428b['fieldName'],'type':_0x52428b[_0x06f4('0x24')][_0x06f4('0x25')]};});_0x5362e6=qs[_0x06f4('0x26')](_0x5118a0,_0x5d58c8);var _0x59af03={'where':_0x5362e6['where']};return db[_0x06f4('0x22')]['count'](_0x59af03)['then'](function(_0x17b9bb){_0x1d79d4[_0x06f4('0x13')]=_0x17b9bb;_0x5362e6[_0x06f4('0x27')]=qs['include'](_0x5d58c8[_0x06f4('0x28')]);return db[_0x06f4('0x22')][_0x06f4('0x29')](_0x5362e6);})[_0x06f4('0x19')](function(_0x538280){_0x1d79d4['rows']=_0x538280;return _0x1d79d4;})[_0x06f4('0x19')](respondWithFilteredResult(_0x1456c3,_0x5362e6))['catch'](handleError(_0x1456c3,null));};exports[_0x06f4('0x2a')]=function(_0x5618ce,_0xfe9e37){var _0x22937a={'raw':!![],'where':{'id':_0x5618ce[_0x06f4('0x2b')]['id']}},_0xcc0aa4={};_0xcc0aa4[_0x06f4('0x2c')]=_[_0x06f4('0x2d')](db['MailQueue'][_0x06f4('0x23')]);_0xcc0aa4['query']=_['keys'](_0x5618ce[_0x06f4('0x28')]);_0xcc0aa4[_0x06f4('0x2e')]=_[_0x06f4('0x2f')](_0xcc0aa4[_0x06f4('0x2c')],_0xcc0aa4[_0x06f4('0x28')]);_0x22937a['attributes']=_[_0x06f4('0x2f')](_0xcc0aa4[_0x06f4('0x2c')],qs[_0x06f4('0x30')](_0x5618ce[_0x06f4('0x28')]['fields']));_0x22937a[_0x06f4('0x31')]=_0x22937a['attributes'][_0x06f4('0x32')]?_0x22937a[_0x06f4('0x31')]:_0xcc0aa4['model'];if(_0x5618ce[_0x06f4('0x28')]['includeAll']){_0x22937a['include']=[{'all':!![]}];}_0x22937a=_[_0x06f4('0x33')]({},_0x22937a,_0x5618ce['options']);return db['MailQueue']['find'](_0x22937a)[_0x06f4('0x19')](handleEntityNotFound(_0xfe9e37,null))[_0x06f4('0x19')](respondWithResult(_0xfe9e37,null))[_0x06f4('0x34')](handleError(_0xfe9e37,null));};exports[_0x06f4('0x35')]=function(_0x12e655,_0x42439f){return db[_0x06f4('0x22')]['create'](_0x12e655[_0x06f4('0x36')],{})[_0x06f4('0x19')](function(_0x3a68c1){var _0x19be5e=_0x12e655[_0x06f4('0x37')][_0x06f4('0x38')]({'plain':!![]});if(!_0x19be5e)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x19be5e['role']===_0x06f4('0x37')){var _0x3b4606=_0x3a68c1['get']({'plain':!![]});var _0x317d3f=_0x06f4('0x1b');return db[_0x06f4('0x39')][_0x06f4('0x3a')]({'where':{'name':_0x317d3f,'userProfileId':_0x19be5e[_0x06f4('0x3b')]},'raw':!![]})[_0x06f4('0x19')](function(_0x1f0828){if(_0x1f0828&&_0x1f0828[_0x06f4('0x3c')]===0x0){return db[_0x06f4('0x1c')]['create']({'name':_0x3b4606[_0x06f4('0x1f')],'resourceId':_0x3b4606['id'],'type':_0x1f0828['name'],'sectionId':_0x1f0828['id']},{})[_0x06f4('0x19')](function(){return _0x3a68c1;});}else{return _0x3a68c1;}})[_0x06f4('0x34')](function(_0x23ac59){logger['error'](_0x06f4('0x3d'),_0x23ac59);throw _0x23ac59;});}return _0x3a68c1;})[_0x06f4('0x19')](respondWithResult(_0x42439f,0xc9))['catch'](handleError(_0x42439f,null));};exports[_0x06f4('0x18')]=function(_0x5d7590,_0x15db99){if(_0x5d7590[_0x06f4('0x36')]['id']){delete _0x5d7590['body']['id'];}return db[_0x06f4('0x22')][_0x06f4('0x3a')]({'where':{'id':_0x5d7590['params']['id']}})['then'](handleEntityNotFound(_0x15db99,null))[_0x06f4('0x19')](saveUpdates(_0x5d7590[_0x06f4('0x36')],null))['then'](respondWithResult(_0x15db99,null))[_0x06f4('0x34')](handleError(_0x15db99,null));};exports[_0x06f4('0x1a')]=function(_0x1fd003,_0x335c98){return db['MailQueue'][_0x06f4('0x3a')]({'where':{'id':_0x1fd003[_0x06f4('0x2b')]['id']}})['then'](handleEntityNotFound(_0x335c98,null))['then'](removeEntity(_0x335c98,null))[_0x06f4('0x34')](handleError(_0x335c98,null));};exports[_0x06f4('0x3e')]=function(_0x16592d,_0x2ee23c){return db[_0x06f4('0x22')][_0x06f4('0x3e')]()['then'](respondWithResult(_0x2ee23c,null))['catch'](handleError(_0x2ee23c,null));};exports[_0x06f4('0x3f')]=function(_0x5d85cb,_0x41ad4a){var _0x197a6f={'raw':!![],'where':{}},_0x243bca={},_0x2a038a;return db[_0x06f4('0x22')][_0x06f4('0x40')]({'where':{'id':_0x5d85cb[_0x06f4('0x2b')]['id']}})[_0x06f4('0x19')](handleEntityNotFound(_0x41ad4a,null))[_0x06f4('0x19')](function(_0x4976c6){if(_0x4976c6){_0x2a038a=_0x4976c6[_0x06f4('0x38')]({'plain':!![]});_0x243bca[_0x06f4('0x2c')]=_['keys'](db['UserMailQueue']['rawAttributes']);_0x243bca['query']=_[_0x06f4('0x2d')](_0x5d85cb[_0x06f4('0x28')]);_0x243bca['filters']=_['intersection'](_0x243bca[_0x06f4('0x2c')],_0x243bca[_0x06f4('0x28')]);_0x197a6f['attributes']=_['intersection'](_0x243bca[_0x06f4('0x2c')],qs['fields'](_0x5d85cb[_0x06f4('0x28')]['fields']));_0x197a6f[_0x06f4('0x31')]=_0x197a6f[_0x06f4('0x31')]['length']?_0x197a6f['attributes']:_0x243bca[_0x06f4('0x2c')];if(!_0x5d85cb[_0x06f4('0x28')]['hasOwnProperty'](_0x06f4('0x41'))){_0x197a6f[_0x06f4('0x12')]=qs[_0x06f4('0x12')](_0x5d85cb[_0x06f4('0x28')][_0x06f4('0x12')]);_0x197a6f[_0x06f4('0x14')]=qs[_0x06f4('0x14')](_0x5d85cb[_0x06f4('0x28')][_0x06f4('0x14')]);}_0x197a6f[_0x06f4('0x42')]=qs['sort'](_0x5d85cb[_0x06f4('0x28')][_0x06f4('0x43')]);_0x197a6f[_0x06f4('0x44')]=qs[_0x06f4('0x2e')](_['pick'](_0x5d85cb[_0x06f4('0x28')],_0x243bca['filters']));_0x197a6f[_0x06f4('0x44')][_0x06f4('0x45')]=_0x4976c6['id'];if(_0x5d85cb[_0x06f4('0x28')][_0x06f4('0x46')]){_0x197a6f[_0x06f4('0x44')]=_[_0x06f4('0x33')](_0x197a6f['where'],{'$or':_['map'](_0x197a6f[_0x06f4('0x31')],function(_0x4c9b20){var _0x3ddfa3={};_0x3ddfa3[_0x4c9b20]={'$like':'%'+_0x5d85cb[_0x06f4('0x28')][_0x06f4('0x46')]+'%'};return _0x3ddfa3;})});}_0x197a6f=_[_0x06f4('0x33')]({},_0x197a6f,_0x5d85cb[_0x06f4('0x47')]);return db['UserMailQueue']['findAll'](_0x197a6f);}})[_0x06f4('0x19')](function(_0xd5778b){if(_0xd5778b){return db[_0x06f4('0x48')][_0x06f4('0x49')]({'where':{'id':_[_0x06f4('0x21')](_0xd5778b,_0x06f4('0x4a')),'role':_0x06f4('0x4b')},'attributes':['id',_0x06f4('0x1f'),_0x06f4('0x4c'),_0x06f4('0x4d'),_0x06f4('0x4e')]});}})[_0x06f4('0x19')](function(_0x36e8ca){if(_0x36e8ca){return{'count':_0x36e8ca[_0x06f4('0x13')],'rows':_['map'](_0x36e8ca[_0x06f4('0x4f')],function(_0xd0e18b){return{'membername':_0xd0e18b[_0x06f4('0x1f')],'UserId':_0xd0e18b['id'],'queue_name':_0x2a038a[_0x06f4('0x1f')],'MailQueueId':_0x2a038a['id'],'interface':util[_0x06f4('0x50')](_0x06f4('0x51'),_0x06f4('0x52'),_0xd0e18b['name']),'penalty':0x0,'paused':_0xd0e18b['mailPause'],'createdAt':_0xd0e18b[_0x06f4('0x4e')],'updatedAt':_0xd0e18b[_0x06f4('0x4d')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x06f4('0x19')](respondWithFilteredResult(_0x41ad4a,_0x197a6f))[_0x06f4('0x34')](handleError(_0x41ad4a,null));};exports[_0x06f4('0x53')]=function(_0x3e3be7,_0x44b9da){var _0x3bf0e5={};var _0x53a6d8={};var _0x5b5206;var _0x13291d;return db['MailQueue'][_0x06f4('0x40')]({'where':{'id':_0x3e3be7[_0x06f4('0x2b')]['id']}})[_0x06f4('0x19')](handleEntityNotFound(_0x44b9da,null))[_0x06f4('0x19')](function(_0x5aa35f){if(_0x5aa35f){_0x5b5206=_0x5aa35f;_0x53a6d8[_0x06f4('0x2c')]=_[_0x06f4('0x2d')](db[_0x06f4('0x54')]['rawAttributes']);_0x53a6d8[_0x06f4('0x28')]=_[_0x06f4('0x2d')](_0x3e3be7[_0x06f4('0x28')]);_0x53a6d8[_0x06f4('0x2e')]=_[_0x06f4('0x2f')](_0x53a6d8[_0x06f4('0x2c')],_0x53a6d8[_0x06f4('0x28')]);_0x3bf0e5['attributes']=_[_0x06f4('0x2f')](_0x53a6d8[_0x06f4('0x2c')],qs[_0x06f4('0x30')](_0x3e3be7[_0x06f4('0x28')]['fields']));_0x3bf0e5[_0x06f4('0x31')]=_0x3bf0e5[_0x06f4('0x31')]['length']?_0x3bf0e5[_0x06f4('0x31')]:_0x53a6d8[_0x06f4('0x2c')];_0x3bf0e5['order']=qs[_0x06f4('0x43')](_0x3e3be7[_0x06f4('0x28')][_0x06f4('0x43')]);_0x3bf0e5['where']=qs[_0x06f4('0x2e')](_['pick'](_0x3e3be7[_0x06f4('0x28')],_0x53a6d8['filters']));if(_0x3e3be7['query'][_0x06f4('0x46')]){_0x3bf0e5[_0x06f4('0x44')]=_[_0x06f4('0x33')](_0x3bf0e5[_0x06f4('0x44')],{'$or':_[_0x06f4('0x21')](_0x3bf0e5['attributes'],function(_0x215c04){var _0x12388b={};_0x12388b[_0x215c04]={'$like':'%'+_0x3e3be7[_0x06f4('0x28')][_0x06f4('0x46')]+'%'};return _0x12388b;})});}_0x3bf0e5=_[_0x06f4('0x33')]({},_0x3bf0e5,_0x3e3be7[_0x06f4('0x47')]);return _0x5b5206[_0x06f4('0x53')](_0x3bf0e5);}})[_0x06f4('0x19')](function(_0x3b2a18){if(_0x3b2a18){_0x13291d=_0x3b2a18[_0x06f4('0x32')];if(!_0x3e3be7[_0x06f4('0x28')][_0x06f4('0x55')](_0x06f4('0x41'))){_0x3bf0e5[_0x06f4('0x12')]=qs[_0x06f4('0x12')](_0x3e3be7['query']['limit']);_0x3bf0e5['offset']=qs[_0x06f4('0x14')](_0x3e3be7['query'][_0x06f4('0x14')]);}return _0x5b5206['getTeams'](_0x3bf0e5);}})[_0x06f4('0x19')](function(_0x89cb90){if(_0x89cb90){return _0x89cb90?{'count':_0x13291d,'rows':_0x89cb90}:null;}})[_0x06f4('0x19')](respondWithResult(_0x44b9da,null))[_0x06f4('0x34')](handleError(_0x44b9da,null));};exports[_0x06f4('0x56')]=function(_0x119677,_0x4d2b68){var _0x2b15f5=_0x119677[_0x06f4('0x36')]['ids'];return db['Team'][_0x06f4('0x29')]({'where':{'id':_0x2b15f5},'attributes':['id'],'include':[{'model':db['User'],'as':_0x06f4('0x57'),'attributes':['id','name','online','voicePause',_0x06f4('0x58')],'raw':!![]}]})[_0x06f4('0x19')](function(_0x4b9523){if(_0x4b9523){var _0x223e26=_['flatMap'](_0x4b9523,function(_0x4bebec){var _0x7df86e=_0x4bebec[_0x06f4('0x38')]({'plain':!![]});return _0x7df86e[_0x06f4('0x57')];});return db['MailQueue'][_0x06f4('0x3a')]({'where':{'id':_0x119677[_0x06f4('0x2b')]['id']}})[_0x06f4('0x19')](function(_0x314b33){return db[_0x06f4('0x59')][_0x06f4('0x5a')](function(_0x5df2ee){return _0x314b33[_0x06f4('0x56')](_0x2b15f5,{'transaction':_0x5df2ee})[_0x06f4('0x19')](function(){return BPromise[_0x06f4('0x5b')](_0x223e26,function(_0x1882d7){return db[_0x06f4('0x5c')][_0x06f4('0x5d')]({'where':{'UserId':_0x1882d7['id'],'MailQueueId':_0x119677[_0x06f4('0x2b')]['id']},'transaction':_0x5df2ee});});})[_0x06f4('0x19')](function(){_0x223e26['forEach'](function(_0x3443c1){socket['emit']('userMailQueue:save',{'UserId':_0x3443c1['id'],'MailQueueId':_0x314b33['id']});});});});});}})[_0x06f4('0x19')](respondWithStatusCode(_0x4d2b68,null))[_0x06f4('0x34')](handleError(_0x4d2b68,null));};exports[_0x06f4('0x5e')]=function(_0x2a8324,_0x28e8cd){return db[_0x06f4('0x54')]['findAll']({'where':{'id':_0x2a8324[_0x06f4('0x28')][_0x06f4('0x5f')]},'attributes':['id'],'include':[{'model':db[_0x06f4('0x48')],'as':_0x06f4('0x57'),'attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x28e8cd,null))[_0x06f4('0x19')](function(_0x1d9170){var _0x2530d2=_[_0x06f4('0x21')](_0x1d9170,'id');var _0x339ea7=[];var _0x166b12=[];var _0x45f5e2=squel[_0x06f4('0x60')]();_0x45f5e2['field'](_0x06f4('0x61'))[_0x06f4('0x62')](_0x06f4('0x63'),'tq')[_0x06f4('0x64')]('user_has_teams','ut',_0x06f4('0x65'))[_0x06f4('0x44')](_0x06f4('0x66'),_0x2a8324['params']['id']);for(var _0x8f4e79=0x0;_0x8f4e79<_0x1d9170['length'];_0x8f4e79+=0x1){let _0x27cad0=_0x1d9170[_0x8f4e79];for(var _0x1b2321=0x0;_0x1b2321<_0x27cad0[_0x06f4('0x57')]['length'];_0x1b2321+=0x1){let _0x18d3f3=_0x27cad0[_0x06f4('0x57')][_0x1b2321];var _0x2be6be=_0x45f5e2[_0x06f4('0x67')]();_0x2be6be[_0x06f4('0x44')](_0x06f4('0x68'),_0x18d3f3['id']);_0x166b12[_0x06f4('0x69')](db[_0x06f4('0x59')]['query'](_0x2be6be[_0x06f4('0x6a')](),{'type':db[_0x06f4('0x59')][_0x06f4('0x6b')][_0x06f4('0x6c')]})[_0x06f4('0x19')](function(_0x27025f){if(_0x27025f['length']===0x1){return _0x18d3f3['id'];}else{var _0x28ec13=_['every'](_[_0x06f4('0x21')](_0x27025f,_0x06f4('0x6d')),function(_0x17aaf3){return _[_0x06f4('0x6e')](_0x2530d2,_0x17aaf3);});if(_0x28ec13){return _0x18d3f3['id'];}}}));}}return BPromise[_0x06f4('0x6f')](_0x166b12)[_0x06f4('0x19')](function(_0x4facca){_0x339ea7=_(_0x339ea7)['union'](_0x4facca)[_0x06f4('0x70')]()['value']();return db[_0x06f4('0x22')][_0x06f4('0x3a')]({'where':{'id':_0x2a8324[_0x06f4('0x2b')]['id']}})[_0x06f4('0x19')](function(_0xb8b57a){return db[_0x06f4('0x59')][_0x06f4('0x5a')](function(_0x5029ba){return _0xb8b57a[_0x06f4('0x5e')](_0x2a8324['query'][_0x06f4('0x5f')],{'transaction':_0x5029ba})[_0x06f4('0x19')](function(){if(!_['isEmpty'](_0x339ea7)){return _0xb8b57a[_0x06f4('0x71')](_0x339ea7,{'transaction':_0x5029ba});}})[_0x06f4('0x19')](function(){_0x339ea7[_0x06f4('0x72')](function(_0x15cebf){socket[_0x06f4('0x73')](_0x06f4('0x74'),{'UserId':_0x15cebf,'MailQueueId':_0xb8b57a['id']});});});});});});})[_0x06f4('0x19')](respondWithStatusCode(_0x28e8cd,null))['catch'](handleError(_0x28e8cd,null));};exports[_0x06f4('0x75')]=function(_0x2b207b,_0x53ea7f){return db[_0x06f4('0x22')][_0x06f4('0x3a')]({'where':{'id':_0x2b207b['params']['id']}})[_0x06f4('0x19')](handleEntityNotFound(_0x53ea7f,null))[_0x06f4('0x19')](function(_0xf45968){if(_0xf45968){return _0xf45968[_0x06f4('0x75')](_0x2b207b[_0x06f4('0x36')][_0x06f4('0x5f')],_[_0x06f4('0x76')](_0x2b207b[_0x06f4('0x36')],['ids','id'])||{})[_0x06f4('0x77')](function(_0x4b7735){for(var _0x419326=0x0;_0x419326<_0x2b207b[_0x06f4('0x36')][_0x06f4('0x5f')][_0x06f4('0x32')];_0x419326+=0x1){socket[_0x06f4('0x73')](_0x06f4('0x78'),{'UserId':Number(_0x2b207b[_0x06f4('0x36')][_0x06f4('0x5f')][_0x419326]),'MailQueueId':Number(_0x2b207b['params']['id'])});}return _0x4b7735;});}})[_0x06f4('0x19')](respondWithResult(_0x53ea7f,null))['catch'](handleError(_0x53ea7f,null));};exports['removeAgents']=function(_0xdee29a,_0x42c507){return db[_0x06f4('0x22')]['find']({'where':{'id':_0xdee29a[_0x06f4('0x2b')]['id']}})[_0x06f4('0x19')](handleEntityNotFound(_0x42c507,null))['then'](function(_0x429206){if(_0x429206){return _0x429206['removeAgents'](_0xdee29a[_0x06f4('0x28')][_0x06f4('0x5f')])[_0x06f4('0x19')](function(){if(_[_0x06f4('0x79')](_0xdee29a[_0x06f4('0x28')][_0x06f4('0x5f')])){for(var _0x18fc22=0x0;_0x18fc22<_0xdee29a[_0x06f4('0x28')][_0x06f4('0x5f')][_0x06f4('0x32')];_0x18fc22+=0x1){socket[_0x06f4('0x73')](_0x06f4('0x74'),{'UserId':Number(_0xdee29a[_0x06f4('0x28')][_0x06f4('0x5f')][_0x18fc22]),'MailQueueId':Number(_0xdee29a['params']['id'])});}}else{socket[_0x06f4('0x73')]('userMailQueue:remove',{'UserId':Number(_0xdee29a[_0x06f4('0x28')]['ids']),'MailQueueId':Number(_0xdee29a['params']['id'])});}});}})['then'](respondWithStatusCode(_0x42c507,null))[_0x06f4('0x34')](handleError(_0x42c507,null));};exports[_0x06f4('0x7a')]=function(_0x43c318,_0xbad584){var _0x253cfb={};var _0xf809f6={};var _0x3eb311;var _0xa021af;return db['MailQueue'][_0x06f4('0x40')]({'where':{'id':_0x43c318[_0x06f4('0x2b')]['id']}})['then'](handleEntityNotFound(_0xbad584,null))['then'](function(_0x36e5be){if(_0x36e5be){_0x3eb311=_0x36e5be;_0xf809f6[_0x06f4('0x2c')]=_[_0x06f4('0x2d')](db[_0x06f4('0x48')][_0x06f4('0x23')]);_0xf809f6[_0x06f4('0x28')]=_[_0x06f4('0x2d')](_0x43c318[_0x06f4('0x28')]);_0xf809f6[_0x06f4('0x2e')]=_[_0x06f4('0x2f')](_0xf809f6[_0x06f4('0x2c')],_0xf809f6[_0x06f4('0x28')]);_0x253cfb[_0x06f4('0x31')]=_['intersection'](_0xf809f6['model'],qs[_0x06f4('0x30')](_0x43c318[_0x06f4('0x28')][_0x06f4('0x30')]));_0x253cfb[_0x06f4('0x31')]=_0x253cfb[_0x06f4('0x31')][_0x06f4('0x32')]?_0x253cfb[_0x06f4('0x31')]:_0xf809f6[_0x06f4('0x2c')];_0x253cfb['order']=qs[_0x06f4('0x43')](_0x43c318[_0x06f4('0x28')][_0x06f4('0x43')]);_0x253cfb[_0x06f4('0x44')]=qs[_0x06f4('0x2e')](_['pick'](_0x43c318[_0x06f4('0x28')],_0xf809f6[_0x06f4('0x2e')]));if(_0x43c318['query'][_0x06f4('0x46')]){_0x253cfb[_0x06f4('0x44')]=_[_0x06f4('0x33')](_0x253cfb['where'],{'$or':_['map'](_0x253cfb['attributes'],function(_0x8dbeb9){var _0x9fba2b={};_0x9fba2b[_0x8dbeb9]={'$like':'%'+_0x43c318[_0x06f4('0x28')]['filter']+'%'};return _0x9fba2b;})});}_0x253cfb=_[_0x06f4('0x33')]({},_0x253cfb,_0x43c318[_0x06f4('0x47')]);return _0x3eb311[_0x06f4('0x7a')](_0x253cfb);}})['then'](function(_0x2603b3){if(_0x2603b3){_0xa021af=_0x2603b3[_0x06f4('0x32')];if(!_0x43c318[_0x06f4('0x28')]['hasOwnProperty'](_0x06f4('0x41'))){_0x253cfb[_0x06f4('0x12')]=qs[_0x06f4('0x12')](_0x43c318[_0x06f4('0x28')][_0x06f4('0x12')]);_0x253cfb[_0x06f4('0x14')]=qs['offset'](_0x43c318[_0x06f4('0x28')][_0x06f4('0x14')]);}return _0x3eb311[_0x06f4('0x7a')](_0x253cfb);}})['then'](function(_0xb00922){if(_0xb00922){return _0xb00922?{'count':_0xa021af,'rows':_0xb00922}:null;}})[_0x06f4('0x19')](respondWithResult(_0xbad584,null))[_0x06f4('0x34')](handleError(_0xbad584,null));};