67bae3e21471b115a0048943049cf121b06f8028
[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 _0xb140=['filter','options','User','findAndCountAll','UserId','format','%s/%s','SIP','mailPause','createdAt','updatedAt','getTeams','Team','hasOwnProperty','nolimit','addTeams','ids','Agents','online','voicePause','findOrCreate','forEach','emit','userMailQueue:save','removeTeams','select','field','from','team_has_mail_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','MailQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','sequelize','toString','QueryTypes','SELECT','every','TeamId','all','union','compact','value','transaction','isEmpty','removeAgents','userMailQueue:remove','addAgents','omit','spread','isArray','getAgents','bluebird','util','lodash','squel','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','redis','./mailQueue.socket','end','json','offset','undefined','count','limit','status','set','Content-Range','update','then','destroy','get','UserProfileResource','stack','name','send','index','map','MailQueue','rawAttributes','fieldName','type','key','where','include','query','findAll','rows','catch','params','keys','filters','intersection','model','fields','attributes','includeAll','merge','find','create','body','user','role','UserProfileSection','userProfileId','autoAssociation','error','describe','getMembers','findOne','UserMailQueue','length','order','sort','pick','MailQueueId'];(function(_0x3511d3,_0x4107ae){var _0x5d6321=function(_0x1a23da){while(--_0x1a23da){_0x3511d3['push'](_0x3511d3['shift']());}};_0x5d6321(++_0x4107ae);}(_0xb140,0xb3));var _0x0b14=function(_0x7f1086,_0x434356){_0x7f1086=_0x7f1086-0x0;var _0x358a47=_0xb140[_0x7f1086];return _0x358a47;};'use strict';var BPromise=require(_0x0b14('0x0'));var util=require(_0x0b14('0x1'));var _=require(_0x0b14('0x2'));var squel=require(_0x0b14('0x3'));var Redis=require(_0x0b14('0x4'));var qs=require(_0x0b14('0x5'));var logger=require(_0x0b14('0x6'))(_0x0b14('0x7'));var config=require(_0x0b14('0x8'));var db=require(_0x0b14('0x9'))['db'];config[_0x0b14('0xa')]=_['defaults'](config[_0x0b14('0xa')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x0b14('0xa')]));require(_0x0b14('0xb'))['register'](socket);function respondWithStatusCode(_0x1b19e3,_0x35504d){_0x35504d=_0x35504d||0xcc;return function(_0x5bcd32){if(_0x5bcd32){return _0x1b19e3['sendStatus'](_0x35504d);}return _0x1b19e3['status'](_0x35504d)[_0x0b14('0xc')]();};}function respondWithResult(_0x1a9f24,_0x34d816){_0x34d816=_0x34d816||0xc8;return function(_0x3c3a98){if(_0x3c3a98){return _0x1a9f24['status'](_0x34d816)[_0x0b14('0xd')](_0x3c3a98);}};}function respondWithFilteredResult(_0x13792b,_0x1bf11f){return function(_0x364fcb){if(_0x364fcb){var _0x2db6b3=typeof _0x1bf11f[_0x0b14('0xe')]===_0x0b14('0xf')&&typeof _0x1bf11f['limit']===_0x0b14('0xf');var _0x231855=_0x364fcb[_0x0b14('0x10')];var _0x3bf7db=_0x2db6b3?0x0:_0x1bf11f[_0x0b14('0xe')];var _0x12b97b=_0x2db6b3?_0x364fcb[_0x0b14('0x10')]:_0x1bf11f[_0x0b14('0xe')]+_0x1bf11f[_0x0b14('0x11')];var _0x2e3554;if(_0x12b97b>=_0x231855){_0x12b97b=_0x231855;_0x2e3554=0xc8;}else{_0x2e3554=0xce;}_0x13792b[_0x0b14('0x12')](_0x2e3554);return _0x13792b[_0x0b14('0x13')](_0x0b14('0x14'),_0x3bf7db+'-'+_0x12b97b+'/'+_0x231855)[_0x0b14('0xd')](_0x364fcb);}return null;};}function saveUpdates(_0x2e38b0){return function(_0x2c5269){if(_0x2c5269){return _0x2c5269[_0x0b14('0x15')](_0x2e38b0)[_0x0b14('0x16')](function(_0xeffa6b){return _0xeffa6b;});}return null;};}function removeEntity(_0x3e3d76){return function(_0x216534){if(_0x216534){return _0x216534[_0x0b14('0x17')]()[_0x0b14('0x16')](function(){var _0x47d4ad=_0x216534[_0x0b14('0x18')]({'plain':!![]});var _0x25a77c='MailQueues';return db[_0x0b14('0x19')][_0x0b14('0x17')]({'where':{'type':_0x25a77c,'resourceId':_0x47d4ad['id']}})[_0x0b14('0x16')](function(){return _0x216534;});})[_0x0b14('0x16')](function(){_0x3e3d76[_0x0b14('0x12')](0xcc)[_0x0b14('0xc')]();});}};}function handleEntityNotFound(_0x189d12){return function(_0x35e7a2){if(!_0x35e7a2){_0x189d12['sendStatus'](0x194);}return _0x35e7a2;};}function handleError(_0x2099b5,_0x5894ec){_0x5894ec=_0x5894ec||0x1f4;return function(_0x28ed33){logger['error'](_0x28ed33[_0x0b14('0x1a')]);if(_0x28ed33[_0x0b14('0x1b')]){delete _0x28ed33['name'];}_0x2099b5[_0x0b14('0x12')](_0x5894ec)[_0x0b14('0x1c')](_0x28ed33);};}exports[_0x0b14('0x1d')]=function(_0x49bb96,_0x14e211){var _0x4bb4fa={};var _0x573b29={'count':0x0,'rows':[]};var _0x1c14c8=_[_0x0b14('0x1e')](db[_0x0b14('0x1f')][_0x0b14('0x20')],function(_0x5ad8c6){return{'name':_0x5ad8c6[_0x0b14('0x21')],'type':_0x5ad8c6[_0x0b14('0x22')][_0x0b14('0x23')]};});_0x4bb4fa=qs['getOptions'](_0x1c14c8,_0x49bb96);var _0x2753ae={'where':_0x4bb4fa[_0x0b14('0x24')]};return db['MailQueue'][_0x0b14('0x10')](_0x2753ae)[_0x0b14('0x16')](function(_0x491542){_0x573b29[_0x0b14('0x10')]=_0x491542;_0x4bb4fa[_0x0b14('0x25')]=qs[_0x0b14('0x25')](_0x49bb96[_0x0b14('0x26')]);return db[_0x0b14('0x1f')][_0x0b14('0x27')](_0x4bb4fa);})[_0x0b14('0x16')](function(_0x409eb0){_0x573b29[_0x0b14('0x28')]=_0x409eb0;return _0x573b29;})['then'](respondWithFilteredResult(_0x14e211,_0x4bb4fa))[_0x0b14('0x29')](handleError(_0x14e211,null));};exports['show']=function(_0x212a4d,_0x14cdb6){var _0x298339={'raw':!![],'where':{'id':_0x212a4d[_0x0b14('0x2a')]['id']}},_0x3107c4={};_0x3107c4['model']=_['keys'](db[_0x0b14('0x1f')]['rawAttributes']);_0x3107c4[_0x0b14('0x26')]=_[_0x0b14('0x2b')](_0x212a4d[_0x0b14('0x26')]);_0x3107c4[_0x0b14('0x2c')]=_[_0x0b14('0x2d')](_0x3107c4[_0x0b14('0x2e')],_0x3107c4['query']);_0x298339['attributes']=_[_0x0b14('0x2d')](_0x3107c4['model'],qs['fields'](_0x212a4d[_0x0b14('0x26')][_0x0b14('0x2f')]));_0x298339[_0x0b14('0x30')]=_0x298339[_0x0b14('0x30')]['length']?_0x298339[_0x0b14('0x30')]:_0x3107c4['model'];if(_0x212a4d[_0x0b14('0x26')][_0x0b14('0x31')]){_0x298339[_0x0b14('0x25')]=[{'all':!![]}];}_0x298339=_[_0x0b14('0x32')]({},_0x298339,_0x212a4d['options']);return db[_0x0b14('0x1f')][_0x0b14('0x33')](_0x298339)[_0x0b14('0x16')](handleEntityNotFound(_0x14cdb6,null))[_0x0b14('0x16')](respondWithResult(_0x14cdb6,null))[_0x0b14('0x29')](handleError(_0x14cdb6,null));};exports[_0x0b14('0x34')]=function(_0x5e107f,_0x1487fa){return db[_0x0b14('0x1f')][_0x0b14('0x34')](_0x5e107f[_0x0b14('0x35')],{})[_0x0b14('0x16')](function(_0x9b1dd5){var _0x3059fe=_0x5e107f[_0x0b14('0x36')][_0x0b14('0x18')]({'plain':!![]});if(!_0x3059fe)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3059fe[_0x0b14('0x37')]===_0x0b14('0x36')){var _0x3acf13=_0x9b1dd5[_0x0b14('0x18')]({'plain':!![]});var _0x400e8a='MailQueues';return db[_0x0b14('0x38')][_0x0b14('0x33')]({'where':{'name':_0x400e8a,'userProfileId':_0x3059fe[_0x0b14('0x39')]},'raw':!![]})[_0x0b14('0x16')](function(_0x3c0263){if(_0x3c0263&&_0x3c0263[_0x0b14('0x3a')]===0x0){return db[_0x0b14('0x19')][_0x0b14('0x34')]({'name':_0x3acf13['name'],'resourceId':_0x3acf13['id'],'type':_0x3c0263[_0x0b14('0x1b')],'sectionId':_0x3c0263['id']},{})[_0x0b14('0x16')](function(){return _0x9b1dd5;});}else{return _0x9b1dd5;}})[_0x0b14('0x29')](function(_0x474836){logger[_0x0b14('0x3b')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x474836);throw _0x474836;});}return _0x9b1dd5;})[_0x0b14('0x16')](respondWithResult(_0x1487fa,0xc9))[_0x0b14('0x29')](handleError(_0x1487fa,null));};exports[_0x0b14('0x15')]=function(_0x111b66,_0x2a6412){if(_0x111b66['body']['id']){delete _0x111b66[_0x0b14('0x35')]['id'];}return db[_0x0b14('0x1f')]['find']({'where':{'id':_0x111b66[_0x0b14('0x2a')]['id']}})['then'](handleEntityNotFound(_0x2a6412,null))[_0x0b14('0x16')](saveUpdates(_0x111b66[_0x0b14('0x35')],null))[_0x0b14('0x16')](respondWithResult(_0x2a6412,null))[_0x0b14('0x29')](handleError(_0x2a6412,null));};exports[_0x0b14('0x17')]=function(_0x32a7a3,_0x4663e7){return db[_0x0b14('0x1f')][_0x0b14('0x33')]({'where':{'id':_0x32a7a3[_0x0b14('0x2a')]['id']}})['then'](handleEntityNotFound(_0x4663e7,null))[_0x0b14('0x16')](removeEntity(_0x4663e7,null))[_0x0b14('0x29')](handleError(_0x4663e7,null));};exports[_0x0b14('0x3c')]=function(_0x113a15,_0x28fde8){return db[_0x0b14('0x1f')][_0x0b14('0x3c')]()['then'](respondWithResult(_0x28fde8,null))[_0x0b14('0x29')](handleError(_0x28fde8,null));};exports[_0x0b14('0x3d')]=function(_0x56c5ec,_0x35c197){var _0x33e4e0={'raw':!![],'where':{}},_0x4b3929={},_0x5a986d;return db[_0x0b14('0x1f')][_0x0b14('0x3e')]({'where':{'id':_0x56c5ec[_0x0b14('0x2a')]['id']}})[_0x0b14('0x16')](handleEntityNotFound(_0x35c197,null))[_0x0b14('0x16')](function(_0x537aa5){if(_0x537aa5){_0x5a986d=_0x537aa5['get']({'plain':!![]});_0x4b3929[_0x0b14('0x2e')]=_['keys'](db[_0x0b14('0x3f')]['rawAttributes']);_0x4b3929['query']=_[_0x0b14('0x2b')](_0x56c5ec[_0x0b14('0x26')]);_0x4b3929[_0x0b14('0x2c')]=_['intersection'](_0x4b3929[_0x0b14('0x2e')],_0x4b3929[_0x0b14('0x26')]);_0x33e4e0['attributes']=_[_0x0b14('0x2d')](_0x4b3929['model'],qs[_0x0b14('0x2f')](_0x56c5ec[_0x0b14('0x26')]['fields']));_0x33e4e0[_0x0b14('0x30')]=_0x33e4e0[_0x0b14('0x30')][_0x0b14('0x40')]?_0x33e4e0['attributes']:_0x4b3929[_0x0b14('0x2e')];if(!_0x56c5ec[_0x0b14('0x26')]['hasOwnProperty']('nolimit')){_0x33e4e0['limit']=qs['limit'](_0x56c5ec['query']['limit']);_0x33e4e0[_0x0b14('0xe')]=qs[_0x0b14('0xe')](_0x56c5ec[_0x0b14('0x26')][_0x0b14('0xe')]);}_0x33e4e0[_0x0b14('0x41')]=qs[_0x0b14('0x42')](_0x56c5ec[_0x0b14('0x26')]['sort']);_0x33e4e0[_0x0b14('0x24')]=qs['filters'](_[_0x0b14('0x43')](_0x56c5ec[_0x0b14('0x26')],_0x4b3929['filters']));_0x33e4e0['where'][_0x0b14('0x44')]=_0x537aa5['id'];if(_0x56c5ec['query'][_0x0b14('0x45')]){_0x33e4e0[_0x0b14('0x24')]=_[_0x0b14('0x32')](_0x33e4e0['where'],{'$or':_['map'](_0x33e4e0['attributes'],function(_0x2b3203){var _0xd25c26={};_0xd25c26[_0x2b3203]={'$like':'%'+_0x56c5ec[_0x0b14('0x26')]['filter']+'%'};return _0xd25c26;})});}_0x33e4e0=_[_0x0b14('0x32')]({},_0x33e4e0,_0x56c5ec[_0x0b14('0x46')]);return db[_0x0b14('0x3f')]['findAll'](_0x33e4e0);}})[_0x0b14('0x16')](function(_0x32c7c1){if(_0x32c7c1){return db[_0x0b14('0x47')][_0x0b14('0x48')]({'where':{'id':_['map'](_0x32c7c1,_0x0b14('0x49')),'role':'agent'},'attributes':['id',_0x0b14('0x1b'),'mailPause','updatedAt','createdAt']});}})[_0x0b14('0x16')](function(_0x211899){if(_0x211899){return{'count':_0x211899[_0x0b14('0x10')],'rows':_[_0x0b14('0x1e')](_0x211899[_0x0b14('0x28')],function(_0x346757){return{'membername':_0x346757['name'],'UserId':_0x346757['id'],'queue_name':_0x5a986d[_0x0b14('0x1b')],'MailQueueId':_0x5a986d['id'],'interface':util[_0x0b14('0x4a')](_0x0b14('0x4b'),_0x0b14('0x4c'),_0x346757['name']),'penalty':0x0,'paused':_0x346757[_0x0b14('0x4d')],'createdAt':_0x346757[_0x0b14('0x4e')],'updatedAt':_0x346757[_0x0b14('0x4f')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x0b14('0x16')](respondWithFilteredResult(_0x35c197,_0x33e4e0))['catch'](handleError(_0x35c197,null));};exports[_0x0b14('0x50')]=function(_0xdf76c5,_0x1d87eb){var _0x32c391={};var _0x3acabd={};var _0x26c7ab;var _0x11884f;return db[_0x0b14('0x1f')]['findOne']({'where':{'id':_0xdf76c5[_0x0b14('0x2a')]['id']}})[_0x0b14('0x16')](handleEntityNotFound(_0x1d87eb,null))[_0x0b14('0x16')](function(_0x32be9c){if(_0x32be9c){_0x26c7ab=_0x32be9c;_0x3acabd[_0x0b14('0x2e')]=_[_0x0b14('0x2b')](db[_0x0b14('0x51')]['rawAttributes']);_0x3acabd[_0x0b14('0x26')]=_[_0x0b14('0x2b')](_0xdf76c5[_0x0b14('0x26')]);_0x3acabd[_0x0b14('0x2c')]=_[_0x0b14('0x2d')](_0x3acabd[_0x0b14('0x2e')],_0x3acabd[_0x0b14('0x26')]);_0x32c391[_0x0b14('0x30')]=_['intersection'](_0x3acabd[_0x0b14('0x2e')],qs['fields'](_0xdf76c5[_0x0b14('0x26')][_0x0b14('0x2f')]));_0x32c391['attributes']=_0x32c391[_0x0b14('0x30')]['length']?_0x32c391['attributes']:_0x3acabd['model'];_0x32c391[_0x0b14('0x41')]=qs['sort'](_0xdf76c5[_0x0b14('0x26')][_0x0b14('0x42')]);_0x32c391['where']=qs[_0x0b14('0x2c')](_[_0x0b14('0x43')](_0xdf76c5[_0x0b14('0x26')],_0x3acabd[_0x0b14('0x2c')]));if(_0xdf76c5[_0x0b14('0x26')][_0x0b14('0x45')]){_0x32c391['where']=_[_0x0b14('0x32')](_0x32c391[_0x0b14('0x24')],{'$or':_[_0x0b14('0x1e')](_0x32c391[_0x0b14('0x30')],function(_0x20dfb6){var _0x43c53c={};_0x43c53c[_0x20dfb6]={'$like':'%'+_0xdf76c5[_0x0b14('0x26')][_0x0b14('0x45')]+'%'};return _0x43c53c;})});}_0x32c391=_[_0x0b14('0x32')]({},_0x32c391,_0xdf76c5[_0x0b14('0x46')]);return _0x26c7ab[_0x0b14('0x50')](_0x32c391);}})[_0x0b14('0x16')](function(_0x3b1f11){if(_0x3b1f11){_0x11884f=_0x3b1f11['length'];if(!_0xdf76c5[_0x0b14('0x26')][_0x0b14('0x52')](_0x0b14('0x53'))){_0x32c391['limit']=qs['limit'](_0xdf76c5[_0x0b14('0x26')][_0x0b14('0x11')]);_0x32c391['offset']=qs[_0x0b14('0xe')](_0xdf76c5['query'][_0x0b14('0xe')]);}return _0x26c7ab[_0x0b14('0x50')](_0x32c391);}})[_0x0b14('0x16')](function(_0x434cee){if(_0x434cee){return _0x434cee?{'count':_0x11884f,'rows':_0x434cee}:null;}})[_0x0b14('0x16')](respondWithResult(_0x1d87eb,null))[_0x0b14('0x29')](handleError(_0x1d87eb,null));};exports[_0x0b14('0x54')]=function(_0x228283,_0x11d9ca){var _0x1ce2ee=_0x228283[_0x0b14('0x35')][_0x0b14('0x55')];return db[_0x0b14('0x51')][_0x0b14('0x27')]({'where':{'id':_0x1ce2ee},'attributes':['id'],'include':[{'model':db[_0x0b14('0x47')],'as':_0x0b14('0x56'),'attributes':['id',_0x0b14('0x1b'),_0x0b14('0x57'),_0x0b14('0x58'),'interface'],'raw':!![]}]})[_0x0b14('0x16')](function(_0x35ac40){if(_0x35ac40){var _0x42fe74=_['flatMap'](_0x35ac40,function(_0x58ee2e){var _0x174773=_0x58ee2e['get']({'plain':!![]});return _0x174773[_0x0b14('0x56')];});return db[_0x0b14('0x1f')][_0x0b14('0x33')]({'where':{'id':_0x228283[_0x0b14('0x2a')]['id']}})['then'](function(_0xa1aea9){return db['sequelize']['transaction'](function(_0x4aa7f4){return _0xa1aea9[_0x0b14('0x54')](_0x1ce2ee,{'transaction':_0x4aa7f4})[_0x0b14('0x16')](function(){return BPromise['each'](_0x42fe74,function(_0x39b05e){return db[_0x0b14('0x3f')][_0x0b14('0x59')]({'where':{'UserId':_0x39b05e['id'],'MailQueueId':_0x228283[_0x0b14('0x2a')]['id']},'transaction':_0x4aa7f4});});})[_0x0b14('0x16')](function(){_0x42fe74[_0x0b14('0x5a')](function(_0x3a285d){socket[_0x0b14('0x5b')](_0x0b14('0x5c'),{'UserId':_0x3a285d['id'],'MailQueueId':_0xa1aea9['id']});});});});});}})[_0x0b14('0x16')](respondWithStatusCode(_0x11d9ca,null))[_0x0b14('0x29')](handleError(_0x11d9ca,null));};exports[_0x0b14('0x5d')]=function(_0x420f03,_0x4535d2){return db['Team'][_0x0b14('0x27')]({'where':{'id':_0x420f03['query'][_0x0b14('0x55')]},'attributes':['id'],'include':[{'model':db[_0x0b14('0x47')],'as':_0x0b14('0x56'),'attributes':['id'],'raw':!![]}]})[_0x0b14('0x16')](handleEntityNotFound(_0x4535d2,null))[_0x0b14('0x16')](function(_0x36f29c){var _0x5617c0=_[_0x0b14('0x1e')](_0x36f29c,'id');var _0x142019=[];var _0x4bffd4=[];var _0x3e06a7=squel[_0x0b14('0x5e')]();_0x3e06a7[_0x0b14('0x5f')]('tq.TeamId')[_0x0b14('0x60')](_0x0b14('0x61'),'tq')[_0x0b14('0x62')](_0x0b14('0x63'),'ut',_0x0b14('0x64'))['where'](_0x0b14('0x65'),_0x420f03['params']['id']);for(var _0x3f45ec=0x0;_0x3f45ec<_0x36f29c[_0x0b14('0x40')];_0x3f45ec+=0x1){let _0x475cf1=_0x36f29c[_0x3f45ec];for(var _0x58a61c=0x0;_0x58a61c<_0x475cf1[_0x0b14('0x56')][_0x0b14('0x40')];_0x58a61c+=0x1){let _0x1b7e31=_0x475cf1['Agents'][_0x58a61c];var _0x172621=_0x3e06a7[_0x0b14('0x66')]();_0x172621['where'](_0x0b14('0x67'),_0x1b7e31['id']);_0x4bffd4[_0x0b14('0x68')](db[_0x0b14('0x69')][_0x0b14('0x26')](_0x172621[_0x0b14('0x6a')](),{'type':db[_0x0b14('0x69')][_0x0b14('0x6b')][_0x0b14('0x6c')]})['then'](function(_0x57520f){if(_0x57520f[_0x0b14('0x40')]===0x1){return _0x1b7e31['id'];}else{var _0x505149=_[_0x0b14('0x6d')](_[_0x0b14('0x1e')](_0x57520f,_0x0b14('0x6e')),function(_0xe8d4c7){return _['includes'](_0x5617c0,_0xe8d4c7);});if(_0x505149){return _0x1b7e31['id'];}}}));}}return BPromise[_0x0b14('0x6f')](_0x4bffd4)[_0x0b14('0x16')](function(_0x103125){_0x142019=_(_0x142019)[_0x0b14('0x70')](_0x103125)[_0x0b14('0x71')]()[_0x0b14('0x72')]();return db[_0x0b14('0x1f')][_0x0b14('0x33')]({'where':{'id':_0x420f03[_0x0b14('0x2a')]['id']}})[_0x0b14('0x16')](function(_0x44a134){return db[_0x0b14('0x69')][_0x0b14('0x73')](function(_0xa4cd33){return _0x44a134[_0x0b14('0x5d')](_0x420f03[_0x0b14('0x26')][_0x0b14('0x55')],{'transaction':_0xa4cd33})[_0x0b14('0x16')](function(){if(!_[_0x0b14('0x74')](_0x142019)){return _0x44a134[_0x0b14('0x75')](_0x142019,{'transaction':_0xa4cd33});}})['then'](function(){_0x142019['forEach'](function(_0x386792){socket[_0x0b14('0x5b')](_0x0b14('0x76'),{'UserId':_0x386792,'MailQueueId':_0x44a134['id']});});});});});});})[_0x0b14('0x16')](respondWithStatusCode(_0x4535d2,null))[_0x0b14('0x29')](handleError(_0x4535d2,null));};exports[_0x0b14('0x77')]=function(_0xb2ef7b,_0x2e453b){return db[_0x0b14('0x1f')][_0x0b14('0x33')]({'where':{'id':_0xb2ef7b[_0x0b14('0x2a')]['id']}})[_0x0b14('0x16')](handleEntityNotFound(_0x2e453b,null))['then'](function(_0x4fc54b){if(_0x4fc54b){return _0x4fc54b[_0x0b14('0x77')](_0xb2ef7b[_0x0b14('0x35')]['ids'],_[_0x0b14('0x78')](_0xb2ef7b[_0x0b14('0x35')],[_0x0b14('0x55'),'id'])||{})[_0x0b14('0x79')](function(_0x71144e){for(var _0x2cd97b=0x0;_0x2cd97b<_0xb2ef7b[_0x0b14('0x35')][_0x0b14('0x55')][_0x0b14('0x40')];_0x2cd97b+=0x1){socket[_0x0b14('0x5b')](_0x0b14('0x5c'),{'UserId':Number(_0xb2ef7b['body'][_0x0b14('0x55')][_0x2cd97b]),'MailQueueId':Number(_0xb2ef7b['params']['id'])});}return _0x71144e;});}})[_0x0b14('0x16')](respondWithResult(_0x2e453b,null))['catch'](handleError(_0x2e453b,null));};exports[_0x0b14('0x75')]=function(_0x5260fe,_0x301d4b){return db[_0x0b14('0x1f')][_0x0b14('0x33')]({'where':{'id':_0x5260fe[_0x0b14('0x2a')]['id']}})[_0x0b14('0x16')](handleEntityNotFound(_0x301d4b,null))[_0x0b14('0x16')](function(_0x188b69){if(_0x188b69){return _0x188b69[_0x0b14('0x75')](_0x5260fe[_0x0b14('0x26')]['ids'])['then'](function(){if(_[_0x0b14('0x7a')](_0x5260fe[_0x0b14('0x26')][_0x0b14('0x55')])){for(var _0x82c529=0x0;_0x82c529<_0x5260fe[_0x0b14('0x26')]['ids']['length'];_0x82c529+=0x1){socket[_0x0b14('0x5b')]('userMailQueue:remove',{'UserId':Number(_0x5260fe[_0x0b14('0x26')][_0x0b14('0x55')][_0x82c529]),'MailQueueId':Number(_0x5260fe[_0x0b14('0x2a')]['id'])});}}else{socket['emit'](_0x0b14('0x76'),{'UserId':Number(_0x5260fe[_0x0b14('0x26')]['ids']),'MailQueueId':Number(_0x5260fe[_0x0b14('0x2a')]['id'])});}});}})[_0x0b14('0x16')](respondWithStatusCode(_0x301d4b,null))['catch'](handleError(_0x301d4b,null));};exports['getAgents']=function(_0x211190,_0xf947db){var _0x476f75={};var _0x15eec2={};var _0x2f9f8d;var _0x552dc6;return db[_0x0b14('0x1f')][_0x0b14('0x3e')]({'where':{'id':_0x211190[_0x0b14('0x2a')]['id']}})[_0x0b14('0x16')](handleEntityNotFound(_0xf947db,null))[_0x0b14('0x16')](function(_0x2ce263){if(_0x2ce263){_0x2f9f8d=_0x2ce263;_0x15eec2[_0x0b14('0x2e')]=_[_0x0b14('0x2b')](db[_0x0b14('0x47')][_0x0b14('0x20')]);_0x15eec2['query']=_[_0x0b14('0x2b')](_0x211190[_0x0b14('0x26')]);_0x15eec2[_0x0b14('0x2c')]=_[_0x0b14('0x2d')](_0x15eec2[_0x0b14('0x2e')],_0x15eec2['query']);_0x476f75[_0x0b14('0x30')]=_[_0x0b14('0x2d')](_0x15eec2[_0x0b14('0x2e')],qs[_0x0b14('0x2f')](_0x211190['query'][_0x0b14('0x2f')]));_0x476f75['attributes']=_0x476f75[_0x0b14('0x30')]['length']?_0x476f75[_0x0b14('0x30')]:_0x15eec2['model'];_0x476f75[_0x0b14('0x41')]=qs[_0x0b14('0x42')](_0x211190[_0x0b14('0x26')][_0x0b14('0x42')]);_0x476f75['where']=qs[_0x0b14('0x2c')](_[_0x0b14('0x43')](_0x211190['query'],_0x15eec2[_0x0b14('0x2c')]));if(_0x211190[_0x0b14('0x26')][_0x0b14('0x45')]){_0x476f75[_0x0b14('0x24')]=_[_0x0b14('0x32')](_0x476f75['where'],{'$or':_[_0x0b14('0x1e')](_0x476f75[_0x0b14('0x30')],function(_0x196940){var _0x125d9e={};_0x125d9e[_0x196940]={'$like':'%'+_0x211190['query'][_0x0b14('0x45')]+'%'};return _0x125d9e;})});}_0x476f75=_['merge']({},_0x476f75,_0x211190[_0x0b14('0x46')]);return _0x2f9f8d['getAgents'](_0x476f75);}})[_0x0b14('0x16')](function(_0x46e50b){if(_0x46e50b){_0x552dc6=_0x46e50b[_0x0b14('0x40')];if(!_0x211190[_0x0b14('0x26')]['hasOwnProperty'](_0x0b14('0x53'))){_0x476f75['limit']=qs[_0x0b14('0x11')](_0x211190['query'][_0x0b14('0x11')]);_0x476f75['offset']=qs[_0x0b14('0xe')](_0x211190[_0x0b14('0x26')][_0x0b14('0xe')]);}return _0x2f9f8d[_0x0b14('0x7b')](_0x476f75);}})[_0x0b14('0x16')](function(_0x1509ff){if(_0x1509ff){return _0x1509ff?{'count':_0x552dc6,'rows':_0x1509ff}:null;}})[_0x0b14('0x16')](respondWithResult(_0xf947db,null))[_0x0b14('0x29')](handleError(_0xf947db,null));};