5aa750926b6b0c23c4cc14492a8d87ced53e5b53
[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 _0x4f11=['mailPause','format','%s/%s','SIP','createdAt','updatedAt','getTeams','Team','hasOwnProperty','addTeams','ids','Agents','online','interface','flatMap','sequelize','transaction','findOrCreate','forEach','emit','removeTeams','User','select','field','tq.TeamId','from','team_has_mail_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','all','union','removeAgents','addAgents','omit','userMailQueue:save','isArray','userMailQueue:remove','getAgents','bluebird','util','lodash','squel','../../components/parsers/qs','../../config/logger','../../config/environment','redis','defaults','socket.io-emitter','./mailQueue.socket','register','sendStatus','status','end','json','offset','undefined','count','Content-Range','then','destroy','get','UserProfileResource','error','stack','name','send','index','map','MailQueue','rawAttributes','type','key','getOptions','where','include','findAll','rows','catch','show','params','model','query','keys','attributes','intersection','fields','length','options','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','MailQueues','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','body','describe','getMembers','findOne','filters','nolimit','limit','order','sort','pick','MailQueueId','filter','merge','UserMailQueue','findAndCountAll','UserId','agent'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x4f11,0x1a7));var _0x14f1=function(_0x4c5279,_0x21aeb8){_0x4c5279=_0x4c5279-0x0;var _0x455832=_0x4f11[_0x4c5279];return _0x455832;};'use strict';var BPromise=require(_0x14f1('0x0'));var util=require(_0x14f1('0x1'));var _=require(_0x14f1('0x2'));var squel=require(_0x14f1('0x3'));var Redis=require('ioredis');var qs=require(_0x14f1('0x4'));var logger=require(_0x14f1('0x5'))('api');var config=require(_0x14f1('0x6'));var db=require('../../mysqldb')['db'];config[_0x14f1('0x7')]=_[_0x14f1('0x8')](config[_0x14f1('0x7')],{'host':'localhost','port':0x18eb});var socket=require(_0x14f1('0x9'))(new Redis(config[_0x14f1('0x7')]));require(_0x14f1('0xa'))[_0x14f1('0xb')](socket);function respondWithStatusCode(_0x39a31b,_0x2768a0){_0x2768a0=_0x2768a0||0xcc;return function(_0xf19e5d){if(_0xf19e5d){return _0x39a31b[_0x14f1('0xc')](_0x2768a0);}return _0x39a31b[_0x14f1('0xd')](_0x2768a0)[_0x14f1('0xe')]();};}function respondWithResult(_0x116bc3,_0x4b0055){_0x4b0055=_0x4b0055||0xc8;return function(_0x335776){if(_0x335776){return _0x116bc3['status'](_0x4b0055)[_0x14f1('0xf')](_0x335776);}};}function respondWithFilteredResult(_0x3131d0,_0x313b83){return function(_0x98651d){if(_0x98651d){var _0x22eddf=typeof _0x313b83[_0x14f1('0x10')]===_0x14f1('0x11')&&typeof _0x313b83['limit']===_0x14f1('0x11');var _0x53e6e0=_0x98651d[_0x14f1('0x12')];var _0x322fd1=_0x22eddf?0x0:_0x313b83['offset'];var _0x183597=_0x22eddf?_0x98651d[_0x14f1('0x12')]:_0x313b83['offset']+_0x313b83['limit'];var _0x531042;if(_0x183597>=_0x53e6e0){_0x183597=_0x53e6e0;_0x531042=0xc8;}else{_0x531042=0xce;}_0x3131d0[_0x14f1('0xd')](_0x531042);return _0x3131d0['set'](_0x14f1('0x13'),_0x322fd1+'-'+_0x183597+'/'+_0x53e6e0)[_0x14f1('0xf')](_0x98651d);}return null;};}function saveUpdates(_0x2c9b81){return function(_0x27ff18){if(_0x27ff18){return _0x27ff18['update'](_0x2c9b81)[_0x14f1('0x14')](function(_0x38f018){return _0x38f018;});}return null;};}function removeEntity(_0x164325){return function(_0x30e371){if(_0x30e371){return _0x30e371[_0x14f1('0x15')]()['then'](function(){var _0x1a667e=_0x30e371[_0x14f1('0x16')]({'plain':!![]});var _0x1f5df7='MailQueues';return db[_0x14f1('0x17')][_0x14f1('0x15')]({'where':{'type':_0x1f5df7,'resourceId':_0x1a667e['id']}})['then'](function(){return _0x30e371;});})[_0x14f1('0x14')](function(){_0x164325['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x3f838d){return function(_0x238543){if(!_0x238543){_0x3f838d['sendStatus'](0x194);}return _0x238543;};}function handleError(_0x1f54a2,_0x134237){_0x134237=_0x134237||0x1f4;return function(_0x582c86){logger[_0x14f1('0x18')](_0x582c86[_0x14f1('0x19')]);if(_0x582c86[_0x14f1('0x1a')]){delete _0x582c86[_0x14f1('0x1a')];}_0x1f54a2[_0x14f1('0xd')](_0x134237)[_0x14f1('0x1b')](_0x582c86);};}exports[_0x14f1('0x1c')]=function(_0x1f45b0,_0x56992d){var _0x2cbba7={};var _0x321c64={'count':0x0,'rows':[]};var _0x3021ed=_[_0x14f1('0x1d')](db[_0x14f1('0x1e')][_0x14f1('0x1f')],function(_0x1898c4){return{'name':_0x1898c4['fieldName'],'type':_0x1898c4[_0x14f1('0x20')][_0x14f1('0x21')]};});_0x2cbba7=qs[_0x14f1('0x22')](_0x3021ed,_0x1f45b0);var _0x524829={'where':_0x2cbba7[_0x14f1('0x23')]};return db[_0x14f1('0x1e')][_0x14f1('0x12')](_0x524829)[_0x14f1('0x14')](function(_0x4520ae){_0x321c64[_0x14f1('0x12')]=_0x4520ae;_0x2cbba7[_0x14f1('0x24')]=qs['include'](_0x1f45b0['query']);return db['MailQueue'][_0x14f1('0x25')](_0x2cbba7);})['then'](function(_0x704b1){_0x321c64[_0x14f1('0x26')]=_0x704b1;return _0x321c64;})[_0x14f1('0x14')](respondWithFilteredResult(_0x56992d,_0x2cbba7))[_0x14f1('0x27')](handleError(_0x56992d,null));};exports[_0x14f1('0x28')]=function(_0x21ab42,_0x3510d5){var _0x21a4a3={'raw':!![],'where':{'id':_0x21ab42[_0x14f1('0x29')]['id']}},_0x40a829={};_0x40a829[_0x14f1('0x2a')]=_['keys'](db[_0x14f1('0x1e')][_0x14f1('0x1f')]);_0x40a829[_0x14f1('0x2b')]=_[_0x14f1('0x2c')](_0x21ab42[_0x14f1('0x2b')]);_0x40a829['filters']=_['intersection'](_0x40a829[_0x14f1('0x2a')],_0x40a829[_0x14f1('0x2b')]);_0x21a4a3[_0x14f1('0x2d')]=_[_0x14f1('0x2e')](_0x40a829['model'],qs[_0x14f1('0x2f')](_0x21ab42['query'][_0x14f1('0x2f')]));_0x21a4a3[_0x14f1('0x2d')]=_0x21a4a3[_0x14f1('0x2d')][_0x14f1('0x30')]?_0x21a4a3[_0x14f1('0x2d')]:_0x40a829[_0x14f1('0x2a')];if(_0x21ab42[_0x14f1('0x2b')]['includeAll']){_0x21a4a3['include']=[{'all':!![]}];}_0x21a4a3=_['merge']({},_0x21a4a3,_0x21ab42[_0x14f1('0x31')]);return db[_0x14f1('0x1e')][_0x14f1('0x32')](_0x21a4a3)[_0x14f1('0x14')](handleEntityNotFound(_0x3510d5,null))['then'](respondWithResult(_0x3510d5,null))[_0x14f1('0x27')](handleError(_0x3510d5,null));};exports['create']=function(_0x294165,_0x1b28b9){return db[_0x14f1('0x1e')][_0x14f1('0x33')](_0x294165['body'],{})[_0x14f1('0x14')](function(_0x407980){var _0x4b6fc6=_0x294165[_0x14f1('0x34')][_0x14f1('0x16')]({'plain':!![]});if(!_0x4b6fc6)throw new Error(_0x14f1('0x35'));if(_0x4b6fc6[_0x14f1('0x36')]===_0x14f1('0x34')){var _0x5a5bad=_0x407980[_0x14f1('0x16')]({'plain':!![]});var _0x5ddda1=_0x14f1('0x37');return db[_0x14f1('0x38')][_0x14f1('0x32')]({'where':{'name':_0x5ddda1,'userProfileId':_0x4b6fc6['userProfileId']},'raw':!![]})[_0x14f1('0x14')](function(_0x338a14){if(_0x338a14&&_0x338a14[_0x14f1('0x39')]===0x0){return db[_0x14f1('0x17')]['create']({'name':_0x5a5bad[_0x14f1('0x1a')],'resourceId':_0x5a5bad['id'],'type':_0x338a14[_0x14f1('0x1a')],'sectionId':_0x338a14['id']},{})[_0x14f1('0x14')](function(){return _0x407980;});}else{return _0x407980;}})[_0x14f1('0x27')](function(_0x2221d6){logger[_0x14f1('0x18')](_0x14f1('0x3a'),_0x2221d6);throw _0x2221d6;});}return _0x407980;})[_0x14f1('0x14')](respondWithResult(_0x1b28b9,0xc9))['catch'](handleError(_0x1b28b9,null));};exports[_0x14f1('0x3b')]=function(_0x276053,_0x58e42e){if(_0x276053['body']['id']){delete _0x276053[_0x14f1('0x3c')]['id'];}return db[_0x14f1('0x1e')][_0x14f1('0x32')]({'where':{'id':_0x276053['params']['id']}})[_0x14f1('0x14')](handleEntityNotFound(_0x58e42e,null))[_0x14f1('0x14')](saveUpdates(_0x276053[_0x14f1('0x3c')],null))[_0x14f1('0x14')](respondWithResult(_0x58e42e,null))[_0x14f1('0x27')](handleError(_0x58e42e,null));};exports[_0x14f1('0x15')]=function(_0x3b1ae9,_0x5fa62f){return db[_0x14f1('0x1e')][_0x14f1('0x32')]({'where':{'id':_0x3b1ae9['params']['id']}})[_0x14f1('0x14')](handleEntityNotFound(_0x5fa62f,null))['then'](removeEntity(_0x5fa62f,null))[_0x14f1('0x27')](handleError(_0x5fa62f,null));};exports[_0x14f1('0x3d')]=function(_0x32d842,_0x5a7894){return db[_0x14f1('0x1e')][_0x14f1('0x3d')]()[_0x14f1('0x14')](respondWithResult(_0x5a7894,null))[_0x14f1('0x27')](handleError(_0x5a7894,null));};exports[_0x14f1('0x3e')]=function(_0x1400f8,_0x14ba3d){var _0x5d7fe2={'raw':!![],'where':{}},_0x358af5={},_0x2f4f0b;return db[_0x14f1('0x1e')][_0x14f1('0x3f')]({'where':{'id':_0x1400f8['params']['id']}})[_0x14f1('0x14')](handleEntityNotFound(_0x14ba3d,null))[_0x14f1('0x14')](function(_0x28d023){if(_0x28d023){_0x2f4f0b=_0x28d023[_0x14f1('0x16')]({'plain':!![]});_0x358af5[_0x14f1('0x2a')]=_[_0x14f1('0x2c')](db['UserMailQueue']['rawAttributes']);_0x358af5[_0x14f1('0x2b')]=_[_0x14f1('0x2c')](_0x1400f8['query']);_0x358af5[_0x14f1('0x40')]=_[_0x14f1('0x2e')](_0x358af5[_0x14f1('0x2a')],_0x358af5[_0x14f1('0x2b')]);_0x5d7fe2[_0x14f1('0x2d')]=_[_0x14f1('0x2e')](_0x358af5['model'],qs[_0x14f1('0x2f')](_0x1400f8[_0x14f1('0x2b')]['fields']));_0x5d7fe2[_0x14f1('0x2d')]=_0x5d7fe2[_0x14f1('0x2d')][_0x14f1('0x30')]?_0x5d7fe2['attributes']:_0x358af5['model'];if(!_0x1400f8[_0x14f1('0x2b')]['hasOwnProperty'](_0x14f1('0x41'))){_0x5d7fe2[_0x14f1('0x42')]=qs[_0x14f1('0x42')](_0x1400f8[_0x14f1('0x2b')][_0x14f1('0x42')]);_0x5d7fe2[_0x14f1('0x10')]=qs['offset'](_0x1400f8[_0x14f1('0x2b')][_0x14f1('0x10')]);}_0x5d7fe2[_0x14f1('0x43')]=qs[_0x14f1('0x44')](_0x1400f8[_0x14f1('0x2b')][_0x14f1('0x44')]);_0x5d7fe2[_0x14f1('0x23')]=qs[_0x14f1('0x40')](_[_0x14f1('0x45')](_0x1400f8[_0x14f1('0x2b')],_0x358af5[_0x14f1('0x40')]));_0x5d7fe2[_0x14f1('0x23')][_0x14f1('0x46')]=_0x28d023['id'];if(_0x1400f8[_0x14f1('0x2b')][_0x14f1('0x47')]){_0x5d7fe2[_0x14f1('0x23')]=_['merge'](_0x5d7fe2['where'],{'$or':_[_0x14f1('0x1d')](_0x5d7fe2['attributes'],function(_0x337822){var _0x2b05ca={};_0x2b05ca[_0x337822]={'$like':'%'+_0x1400f8[_0x14f1('0x2b')]['filter']+'%'};return _0x2b05ca;})});}_0x5d7fe2=_[_0x14f1('0x48')]({},_0x5d7fe2,_0x1400f8[_0x14f1('0x31')]);return db[_0x14f1('0x49')][_0x14f1('0x25')](_0x5d7fe2);}})[_0x14f1('0x14')](function(_0x3a7d72){if(_0x3a7d72){return db['User'][_0x14f1('0x4a')]({'where':{'id':_[_0x14f1('0x1d')](_0x3a7d72,_0x14f1('0x4b')),'role':_0x14f1('0x4c')},'attributes':['id',_0x14f1('0x1a'),_0x14f1('0x4d'),'updatedAt','createdAt']});}})[_0x14f1('0x14')](function(_0x2adfc2){if(_0x2adfc2){return{'count':_0x2adfc2[_0x14f1('0x12')],'rows':_[_0x14f1('0x1d')](_0x2adfc2[_0x14f1('0x26')],function(_0x3196a9){return{'membername':_0x3196a9[_0x14f1('0x1a')],'UserId':_0x3196a9['id'],'queue_name':_0x2f4f0b[_0x14f1('0x1a')],'MailQueueId':_0x2f4f0b['id'],'interface':util[_0x14f1('0x4e')](_0x14f1('0x4f'),_0x14f1('0x50'),_0x3196a9['name']),'penalty':0x0,'paused':_0x3196a9[_0x14f1('0x4d')],'createdAt':_0x3196a9[_0x14f1('0x51')],'updatedAt':_0x3196a9[_0x14f1('0x52')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x14f1('0x14')](respondWithFilteredResult(_0x14ba3d,_0x5d7fe2))[_0x14f1('0x27')](handleError(_0x14ba3d,null));};exports[_0x14f1('0x53')]=function(_0x302d28,_0xb3dfcb){var _0x2e88a0={};var _0x4d3159={};var _0x13dc70;var _0x4aa762;return db['MailQueue'][_0x14f1('0x3f')]({'where':{'id':_0x302d28[_0x14f1('0x29')]['id']}})[_0x14f1('0x14')](handleEntityNotFound(_0xb3dfcb,null))[_0x14f1('0x14')](function(_0x2a7a60){if(_0x2a7a60){_0x13dc70=_0x2a7a60;_0x4d3159[_0x14f1('0x2a')]=_['keys'](db[_0x14f1('0x54')][_0x14f1('0x1f')]);_0x4d3159['query']=_['keys'](_0x302d28[_0x14f1('0x2b')]);_0x4d3159[_0x14f1('0x40')]=_[_0x14f1('0x2e')](_0x4d3159['model'],_0x4d3159[_0x14f1('0x2b')]);_0x2e88a0[_0x14f1('0x2d')]=_[_0x14f1('0x2e')](_0x4d3159[_0x14f1('0x2a')],qs[_0x14f1('0x2f')](_0x302d28[_0x14f1('0x2b')][_0x14f1('0x2f')]));_0x2e88a0[_0x14f1('0x2d')]=_0x2e88a0[_0x14f1('0x2d')][_0x14f1('0x30')]?_0x2e88a0[_0x14f1('0x2d')]:_0x4d3159[_0x14f1('0x2a')];_0x2e88a0[_0x14f1('0x43')]=qs[_0x14f1('0x44')](_0x302d28[_0x14f1('0x2b')][_0x14f1('0x44')]);_0x2e88a0[_0x14f1('0x23')]=qs[_0x14f1('0x40')](_['pick'](_0x302d28['query'],_0x4d3159[_0x14f1('0x40')]));if(_0x302d28[_0x14f1('0x2b')]['filter']){_0x2e88a0['where']=_[_0x14f1('0x48')](_0x2e88a0[_0x14f1('0x23')],{'$or':_[_0x14f1('0x1d')](_0x2e88a0['attributes'],function(_0x1b88ea){var _0x4d1b4d={};_0x4d1b4d[_0x1b88ea]={'$like':'%'+_0x302d28['query'][_0x14f1('0x47')]+'%'};return _0x4d1b4d;})});}_0x2e88a0=_[_0x14f1('0x48')]({},_0x2e88a0,_0x302d28[_0x14f1('0x31')]);return _0x13dc70['getTeams'](_0x2e88a0);}})['then'](function(_0x239fa1){if(_0x239fa1){_0x4aa762=_0x239fa1[_0x14f1('0x30')];if(!_0x302d28[_0x14f1('0x2b')][_0x14f1('0x55')]('nolimit')){_0x2e88a0[_0x14f1('0x42')]=qs['limit'](_0x302d28[_0x14f1('0x2b')]['limit']);_0x2e88a0[_0x14f1('0x10')]=qs[_0x14f1('0x10')](_0x302d28[_0x14f1('0x2b')][_0x14f1('0x10')]);}return _0x13dc70[_0x14f1('0x53')](_0x2e88a0);}})[_0x14f1('0x14')](function(_0x2fd510){if(_0x2fd510){return _0x2fd510?{'count':_0x4aa762,'rows':_0x2fd510}:null;}})[_0x14f1('0x14')](respondWithResult(_0xb3dfcb,null))['catch'](handleError(_0xb3dfcb,null));};exports[_0x14f1('0x56')]=function(_0x4c6f6a,_0x3eec03){var _0x53bdd4=_0x4c6f6a[_0x14f1('0x3c')][_0x14f1('0x57')];return db[_0x14f1('0x54')]['findAll']({'where':{'id':_0x53bdd4},'attributes':['id'],'include':[{'model':db['User'],'as':_0x14f1('0x58'),'attributes':['id',_0x14f1('0x1a'),_0x14f1('0x59'),'voicePause',_0x14f1('0x5a')],'raw':!![]}]})[_0x14f1('0x14')](function(_0x3e07e0){if(_0x3e07e0){var _0x4e52f7=_[_0x14f1('0x5b')](_0x3e07e0,function(_0x29ab26){var _0x2518f9=_0x29ab26[_0x14f1('0x16')]({'plain':!![]});return _0x2518f9['Agents'];});return db[_0x14f1('0x1e')]['find']({'where':{'id':_0x4c6f6a['params']['id']}})['then'](function(_0x5288f6){return db[_0x14f1('0x5c')][_0x14f1('0x5d')](function(_0x5e2799){return _0x5288f6[_0x14f1('0x56')](_0x53bdd4,{'transaction':_0x5e2799})[_0x14f1('0x14')](function(){return BPromise['each'](_0x4e52f7,function(_0x1fcc67){return db['UserMailQueue'][_0x14f1('0x5e')]({'where':{'UserId':_0x1fcc67['id'],'MailQueueId':_0x4c6f6a[_0x14f1('0x29')]['id']},'transaction':_0x5e2799});});})[_0x14f1('0x14')](function(){_0x4e52f7[_0x14f1('0x5f')](function(_0x451e1a){socket[_0x14f1('0x60')]('userMailQueue:save',{'UserId':_0x451e1a['id'],'MailQueueId':_0x5288f6['id']});});});});});}})[_0x14f1('0x14')](respondWithStatusCode(_0x3eec03,null))[_0x14f1('0x27')](handleError(_0x3eec03,null));};exports[_0x14f1('0x61')]=function(_0x1e82d2,_0x43ca8){return db[_0x14f1('0x54')][_0x14f1('0x25')]({'where':{'id':_0x1e82d2[_0x14f1('0x2b')]['ids']},'attributes':['id'],'include':[{'model':db[_0x14f1('0x62')],'as':_0x14f1('0x58'),'attributes':['id'],'raw':!![]}]})[_0x14f1('0x14')](handleEntityNotFound(_0x43ca8,null))[_0x14f1('0x14')](function(_0x3ccc14){var _0x4e34ba=_['map'](_0x3ccc14,'id');var _0x445d57=[];var _0x5c7930=[];var _0x279fb2=squel[_0x14f1('0x63')]();_0x279fb2[_0x14f1('0x64')](_0x14f1('0x65'))[_0x14f1('0x66')](_0x14f1('0x67'),'tq')[_0x14f1('0x68')](_0x14f1('0x69'),'ut',_0x14f1('0x6a'))['where']('MailQueueId\x20=\x20?',_0x1e82d2[_0x14f1('0x29')]['id']);for(var _0x211055=0x0;_0x211055<_0x3ccc14[_0x14f1('0x30')];_0x211055+=0x1){let _0xe92124=_0x3ccc14[_0x211055];for(var _0x1c1999=0x0;_0x1c1999<_0xe92124['Agents'][_0x14f1('0x30')];_0x1c1999+=0x1){let _0xa7dcc7=_0xe92124[_0x14f1('0x58')][_0x1c1999];var _0x5c67bb=_0x279fb2[_0x14f1('0x6b')]();_0x5c67bb[_0x14f1('0x23')](_0x14f1('0x6c'),_0xa7dcc7['id']);_0x5c7930[_0x14f1('0x6d')](db[_0x14f1('0x5c')]['query'](_0x5c67bb[_0x14f1('0x6e')](),{'type':db['sequelize'][_0x14f1('0x6f')][_0x14f1('0x70')]})[_0x14f1('0x14')](function(_0x4efeda){if(_0x4efeda['length']===0x1){return _0xa7dcc7['id'];}else{var _0x2b1730=_[_0x14f1('0x71')](_[_0x14f1('0x1d')](_0x4efeda,_0x14f1('0x72')),function(_0x2ffee1){return _[_0x14f1('0x73')](_0x4e34ba,_0x2ffee1);});if(_0x2b1730){return _0xa7dcc7['id'];}}}));}}return BPromise[_0x14f1('0x74')](_0x5c7930)[_0x14f1('0x14')](function(_0xa04450){_0x445d57=_(_0x445d57)[_0x14f1('0x75')](_0xa04450)['compact']()['value']();return db[_0x14f1('0x1e')][_0x14f1('0x32')]({'where':{'id':_0x1e82d2['params']['id']}})[_0x14f1('0x14')](function(_0x45717f){return db[_0x14f1('0x5c')][_0x14f1('0x5d')](function(_0x4a5520){return _0x45717f[_0x14f1('0x61')](_0x1e82d2[_0x14f1('0x2b')]['ids'],{'transaction':_0x4a5520})[_0x14f1('0x14')](function(){if(!_['isEmpty'](_0x445d57)){return _0x45717f[_0x14f1('0x76')](_0x445d57,{'transaction':_0x4a5520});}})[_0x14f1('0x14')](function(){_0x445d57[_0x14f1('0x5f')](function(_0x2b95cf){socket[_0x14f1('0x60')]('userMailQueue:remove',{'UserId':_0x2b95cf,'MailQueueId':_0x45717f['id']});});});});});});})['then'](respondWithStatusCode(_0x43ca8,null))[_0x14f1('0x27')](handleError(_0x43ca8,null));};exports[_0x14f1('0x77')]=function(_0xeb48b2,_0x2e395e){return db[_0x14f1('0x1e')][_0x14f1('0x32')]({'where':{'id':_0xeb48b2['params']['id']}})[_0x14f1('0x14')](handleEntityNotFound(_0x2e395e,null))[_0x14f1('0x14')](function(_0x5d74a1){if(_0x5d74a1){return _0x5d74a1[_0x14f1('0x77')](_0xeb48b2[_0x14f1('0x3c')][_0x14f1('0x57')],_[_0x14f1('0x78')](_0xeb48b2[_0x14f1('0x3c')],[_0x14f1('0x57'),'id'])||{})['spread'](function(_0x29f479){for(var _0x539ae2=0x0;_0x539ae2<_0xeb48b2[_0x14f1('0x3c')][_0x14f1('0x57')][_0x14f1('0x30')];_0x539ae2+=0x1){socket[_0x14f1('0x60')](_0x14f1('0x79'),{'UserId':Number(_0xeb48b2[_0x14f1('0x3c')][_0x14f1('0x57')][_0x539ae2]),'MailQueueId':Number(_0xeb48b2['params']['id'])});}return _0x29f479;});}})['then'](respondWithResult(_0x2e395e,null))[_0x14f1('0x27')](handleError(_0x2e395e,null));};exports[_0x14f1('0x76')]=function(_0x131e7d,_0x562e0c){return db['MailQueue'][_0x14f1('0x32')]({'where':{'id':_0x131e7d[_0x14f1('0x29')]['id']}})[_0x14f1('0x14')](handleEntityNotFound(_0x562e0c,null))['then'](function(_0x11f865){if(_0x11f865){return _0x11f865[_0x14f1('0x76')](_0x131e7d[_0x14f1('0x2b')][_0x14f1('0x57')])[_0x14f1('0x14')](function(){if(_[_0x14f1('0x7a')](_0x131e7d[_0x14f1('0x2b')]['ids'])){for(var _0x5ab809=0x0;_0x5ab809<_0x131e7d[_0x14f1('0x2b')][_0x14f1('0x57')]['length'];_0x5ab809+=0x1){socket[_0x14f1('0x60')](_0x14f1('0x7b'),{'UserId':Number(_0x131e7d[_0x14f1('0x2b')][_0x14f1('0x57')][_0x5ab809]),'MailQueueId':Number(_0x131e7d[_0x14f1('0x29')]['id'])});}}else{socket[_0x14f1('0x60')](_0x14f1('0x7b'),{'UserId':Number(_0x131e7d[_0x14f1('0x2b')][_0x14f1('0x57')]),'MailQueueId':Number(_0x131e7d[_0x14f1('0x29')]['id'])});}});}})[_0x14f1('0x14')](respondWithStatusCode(_0x562e0c,null))[_0x14f1('0x27')](handleError(_0x562e0c,null));};exports['getAgents']=function(_0x266f96,_0x10273c){var _0x321ac5={};var _0x4b9041={};var _0x3c9002;var _0x33de7d;return db['MailQueue'][_0x14f1('0x3f')]({'where':{'id':_0x266f96[_0x14f1('0x29')]['id']}})[_0x14f1('0x14')](handleEntityNotFound(_0x10273c,null))[_0x14f1('0x14')](function(_0x5c159b){if(_0x5c159b){_0x3c9002=_0x5c159b;_0x4b9041[_0x14f1('0x2a')]=_[_0x14f1('0x2c')](db[_0x14f1('0x62')][_0x14f1('0x1f')]);_0x4b9041[_0x14f1('0x2b')]=_[_0x14f1('0x2c')](_0x266f96[_0x14f1('0x2b')]);_0x4b9041['filters']=_['intersection'](_0x4b9041[_0x14f1('0x2a')],_0x4b9041[_0x14f1('0x2b')]);_0x321ac5['attributes']=_[_0x14f1('0x2e')](_0x4b9041[_0x14f1('0x2a')],qs[_0x14f1('0x2f')](_0x266f96['query'][_0x14f1('0x2f')]));_0x321ac5[_0x14f1('0x2d')]=_0x321ac5[_0x14f1('0x2d')][_0x14f1('0x30')]?_0x321ac5[_0x14f1('0x2d')]:_0x4b9041['model'];_0x321ac5[_0x14f1('0x43')]=qs[_0x14f1('0x44')](_0x266f96[_0x14f1('0x2b')][_0x14f1('0x44')]);_0x321ac5[_0x14f1('0x23')]=qs['filters'](_[_0x14f1('0x45')](_0x266f96['query'],_0x4b9041[_0x14f1('0x40')]));if(_0x266f96[_0x14f1('0x2b')][_0x14f1('0x47')]){_0x321ac5[_0x14f1('0x23')]=_[_0x14f1('0x48')](_0x321ac5['where'],{'$or':_[_0x14f1('0x1d')](_0x321ac5[_0x14f1('0x2d')],function(_0x4ed7f0){var _0x49fa35={};_0x49fa35[_0x4ed7f0]={'$like':'%'+_0x266f96[_0x14f1('0x2b')][_0x14f1('0x47')]+'%'};return _0x49fa35;})});}_0x321ac5=_[_0x14f1('0x48')]({},_0x321ac5,_0x266f96[_0x14f1('0x31')]);return _0x3c9002[_0x14f1('0x7c')](_0x321ac5);}})['then'](function(_0x5629a2){if(_0x5629a2){_0x33de7d=_0x5629a2[_0x14f1('0x30')];if(!_0x266f96['query'][_0x14f1('0x55')](_0x14f1('0x41'))){_0x321ac5['limit']=qs[_0x14f1('0x42')](_0x266f96['query'][_0x14f1('0x42')]);_0x321ac5[_0x14f1('0x10')]=qs[_0x14f1('0x10')](_0x266f96[_0x14f1('0x2b')][_0x14f1('0x10')]);}return _0x3c9002[_0x14f1('0x7c')](_0x321ac5);}})['then'](function(_0x272cc7){if(_0x272cc7){return _0x272cc7?{'count':_0x33de7d,'rows':_0x272cc7}:null;}})['then'](respondWithResult(_0x10273c,null))[_0x14f1('0x27')](handleError(_0x10273c,null));};