2666afd26f8f26d837b2cb95d66a9677b78ad32a
[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 _0xabf1=['includes','all','union','value','isEmpty','userMailQueue:remove','addAgents','omit','removeAgents','isArray','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','moment','util','path','sox','to-csv','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailQueue.socket','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','update','then','destroy','get','MailQueues','UserProfileResource','error','stack','name','send','render','merge','body','contact','message','agent','account','index','map','MailQueue','fieldName','model','query','keys','filters','intersection','attributes','fields','nolimit','sort','where','pick','filter','type','VIRTUAL','options','includeAll','include','rows','catch','show','params','rawAttributes','length','create','role','user','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','findOne','UserMailQueue','hasOwnProperty','order','MailQueueId','findAll','User','UserId','mailPause','updatedAt','format','%s/%s','SIP','createdAt','getTeams','Team','addTeams','ids','Agents','online','voicePause','interface','flatMap','sequelize','transaction','each','findOrCreate','emit','userMailQueue:save','removeTeams','select','tq.TeamId','from','team_has_mail_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','push','toString','SELECT'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0xabf1,0xa0));var _0x1abf=function(_0x3e3064,_0x3dd6f5){_0x3e3064=_0x3e3064-0x0;var _0x4547e1=_0xabf1[_0x3e3064];return _0x4547e1;};'use strict';var emlformat=require(_0x1abf('0x0'));var rimraf=require(_0x1abf('0x1'));var zipdir=require(_0x1abf('0x2'));var jsonpatch=require(_0x1abf('0x3'));var rp=require('request-promise');var moment=require(_0x1abf('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x1abf('0x5'));var path=require(_0x1abf('0x6'));var sox=require(_0x1abf('0x7'));var csv=require(_0x1abf('0x8'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x1abf('0x9'));var _=require(_0x1abf('0xa'));var squel=require(_0x1abf('0xb'));var crypto=require('crypto');var jsforce=require(_0x1abf('0xc'));var deskjs=require(_0x1abf('0xd'));var toCsv=require(_0x1abf('0x8'));var querystring=require(_0x1abf('0xe'));var Papa=require(_0x1abf('0xf'));var Redis=require('ioredis');var authService=require(_0x1abf('0x10'));var qs=require(_0x1abf('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x1abf('0x12'));var logger=require(_0x1abf('0x13'))(_0x1abf('0x14'));var utils=require(_0x1abf('0x15'));var config=require(_0x1abf('0x16'));var licenseUtil=require(_0x1abf('0x17'));var db=require(_0x1abf('0x18'))['db'];config[_0x1abf('0x19')]=_[_0x1abf('0x1a')](config[_0x1abf('0x19')],{'host':_0x1abf('0x1b'),'port':0x18eb});var socket=require(_0x1abf('0x1c'))(new Redis(config[_0x1abf('0x19')]));require(_0x1abf('0x1d'))['register'](socket);function respondWithStatusCode(_0x337fcb,_0x4ab123){_0x4ab123=_0x4ab123||0xcc;return function(_0x1efef5){if(_0x1efef5){return _0x337fcb[_0x1abf('0x1e')](_0x4ab123);}return _0x337fcb[_0x1abf('0x1f')](_0x4ab123)[_0x1abf('0x20')]();};}function respondWithResult(_0xb1c766,_0x3b09b4){_0x3b09b4=_0x3b09b4||0xc8;return function(_0x13ed29){if(_0x13ed29){return _0xb1c766[_0x1abf('0x1f')](_0x3b09b4)[_0x1abf('0x21')](_0x13ed29);}};}function respondWithFilteredResult(_0x183d91,_0x2eec79){return function(_0x412769){if(_0x412769){var _0x5db2ea=typeof _0x2eec79[_0x1abf('0x22')]==='undefined'&&typeof _0x2eec79[_0x1abf('0x23')]===_0x1abf('0x24');var _0x33dc96=_0x412769['count'];var _0x5b26be=_0x5db2ea?0x0:_0x2eec79['offset'];var _0x125509=_0x5db2ea?_0x412769[_0x1abf('0x25')]:_0x2eec79[_0x1abf('0x22')]+_0x2eec79['limit'];var _0x55fe5d;if(_0x125509>=_0x33dc96){_0x125509=_0x33dc96;_0x55fe5d=0xc8;}else{_0x55fe5d=0xce;}_0x183d91[_0x1abf('0x1f')](_0x55fe5d);return _0x183d91[_0x1abf('0x26')](_0x1abf('0x27'),_0x5b26be+'-'+_0x125509+'/'+_0x33dc96)[_0x1abf('0x21')](_0x412769);}return null;};}function patchUpdates(_0x4b69c3){return function(_0x154e1a){try{jsonpatch[_0x1abf('0x28')](_0x154e1a,_0x4b69c3,!![]);}catch(_0x11e36f){return BPromise[_0x1abf('0x29')](_0x11e36f);}return _0x154e1a['save']();};}function saveUpdates(_0x397346,_0x7e6939){return function(_0x31a752){if(_0x31a752){return _0x31a752[_0x1abf('0x2a')](_0x397346)[_0x1abf('0x2b')](function(_0x45cb6e){return _0x45cb6e;});}return null;};}function removeEntity(_0x1ea6cd,_0x32cbee){return function(_0x5bbc04){if(_0x5bbc04){return _0x5bbc04[_0x1abf('0x2c')]()[_0x1abf('0x2b')](function(){var _0x462835=_0x5bbc04[_0x1abf('0x2d')]({'plain':!![]});var _0xfa91c8=_0x1abf('0x2e');return db[_0x1abf('0x2f')]['destroy']({'where':{'type':_0xfa91c8,'resourceId':_0x462835['id']}})[_0x1abf('0x2b')](function(){return _0x5bbc04;});})[_0x1abf('0x2b')](function(){_0x1ea6cd[_0x1abf('0x1f')](0xcc)[_0x1abf('0x20')]();});}};}function handleEntityNotFound(_0x26f7b3,_0x1f4fc7){return function(_0x8cdb50){if(!_0x8cdb50){_0x26f7b3[_0x1abf('0x1e')](0x194);}return _0x8cdb50;};}function handleError(_0x2923dc,_0x5a6bac){_0x5a6bac=_0x5a6bac||0x1f4;return function(_0x273248){logger[_0x1abf('0x30')](_0x273248[_0x1abf('0x31')]);if(_0x273248[_0x1abf('0x32')]){delete _0x273248[_0x1abf('0x32')];}_0x2923dc[_0x1abf('0x1f')](_0x5a6bac)[_0x1abf('0x33')](_0x273248);};}function getMustacheRender(_0x3d62b9,_0x2c9297){return Mustache[_0x1abf('0x34')](_0x3d62b9,_[_0x1abf('0x35')](_0x2c9297[_0x1abf('0x36')],{'contact':_0x2c9297[_0x1abf('0x37')],'message':_0x2c9297[_0x1abf('0x38')],'agent':_0x2c9297[_0x1abf('0x39')],'interaction':_0x2c9297['interaction'],'account':_0x2c9297[_0x1abf('0x3a')]}))||'';}exports[_0x1abf('0x3b')]=function(_0x201297,_0x36ddb9){var _0x7365ae={},_0x194ca0={},_0x4ece62={'count':0x0,'rows':[]};var _0x656cd9=_[_0x1abf('0x3c')](db[_0x1abf('0x3d')]['rawAttributes'],function(_0x369a92){return{'name':_0x369a92[_0x1abf('0x3e')],'type':_0x369a92['type']['key']};});_0x194ca0[_0x1abf('0x3f')]=_[_0x1abf('0x3c')](_0x656cd9,_0x1abf('0x32'));_0x194ca0[_0x1abf('0x40')]=_[_0x1abf('0x41')](_0x201297['query']);_0x194ca0[_0x1abf('0x42')]=_[_0x1abf('0x43')](_0x194ca0[_0x1abf('0x3f')],_0x194ca0['query']);_0x7365ae[_0x1abf('0x44')]=_[_0x1abf('0x43')](_0x194ca0[_0x1abf('0x3f')],qs[_0x1abf('0x45')](_0x201297[_0x1abf('0x40')][_0x1abf('0x45')]));_0x7365ae['attributes']=_0x7365ae[_0x1abf('0x44')]['length']?_0x7365ae[_0x1abf('0x44')]:_0x194ca0[_0x1abf('0x3f')];if(!_0x201297[_0x1abf('0x40')]['hasOwnProperty'](_0x1abf('0x46'))){_0x7365ae[_0x1abf('0x23')]=qs[_0x1abf('0x23')](_0x201297['query']['limit']);_0x7365ae[_0x1abf('0x22')]=qs[_0x1abf('0x22')](_0x201297[_0x1abf('0x40')][_0x1abf('0x22')]);}_0x7365ae['order']=qs[_0x1abf('0x47')](_0x201297[_0x1abf('0x40')][_0x1abf('0x47')]);_0x7365ae[_0x1abf('0x48')]=qs[_0x1abf('0x42')](_[_0x1abf('0x49')](_0x201297[_0x1abf('0x40')],_0x194ca0[_0x1abf('0x42')]),_0x656cd9);if(_0x201297[_0x1abf('0x40')][_0x1abf('0x4a')]){_0x7365ae[_0x1abf('0x48')]=_[_0x1abf('0x35')](_0x7365ae['where'],{'$or':_[_0x1abf('0x3c')](_0x656cd9,function(_0x5608bd){if(_0x5608bd[_0x1abf('0x4b')]!==_0x1abf('0x4c')){var _0x2fad0b={};_0x2fad0b[_0x5608bd[_0x1abf('0x32')]]={'$like':'%'+_0x201297['query'][_0x1abf('0x4a')]+'%'};return _0x2fad0b;}})});}_0x7365ae=_[_0x1abf('0x35')]({},_0x7365ae,_0x201297[_0x1abf('0x4d')]);var _0xf914c7={'where':_0x7365ae[_0x1abf('0x48')]};return db[_0x1abf('0x3d')][_0x1abf('0x25')](_0xf914c7)[_0x1abf('0x2b')](function(_0x5327d9){_0x4ece62[_0x1abf('0x25')]=_0x5327d9;if(_0x201297[_0x1abf('0x40')][_0x1abf('0x4e')]){_0x7365ae[_0x1abf('0x4f')]=[{'all':!![]}];}return db[_0x1abf('0x3d')]['findAll'](_0x7365ae);})[_0x1abf('0x2b')](function(_0x316e0a){_0x4ece62[_0x1abf('0x50')]=_0x316e0a;return _0x4ece62;})[_0x1abf('0x2b')](respondWithFilteredResult(_0x36ddb9,_0x7365ae))[_0x1abf('0x51')](handleError(_0x36ddb9,null));};exports[_0x1abf('0x52')]=function(_0x1cc1ee,_0x7f25f0){var _0x442588={'raw':!![],'where':{'id':_0x1cc1ee[_0x1abf('0x53')]['id']}},_0x136ae4={};_0x136ae4[_0x1abf('0x3f')]=_[_0x1abf('0x41')](db[_0x1abf('0x3d')][_0x1abf('0x54')]);_0x136ae4['query']=_['keys'](_0x1cc1ee[_0x1abf('0x40')]);_0x136ae4[_0x1abf('0x42')]=_[_0x1abf('0x43')](_0x136ae4[_0x1abf('0x3f')],_0x136ae4[_0x1abf('0x40')]);_0x442588['attributes']=_[_0x1abf('0x43')](_0x136ae4[_0x1abf('0x3f')],qs[_0x1abf('0x45')](_0x1cc1ee['query']['fields']));_0x442588[_0x1abf('0x44')]=_0x442588['attributes'][_0x1abf('0x55')]?_0x442588[_0x1abf('0x44')]:_0x136ae4['model'];if(_0x1cc1ee['query'][_0x1abf('0x4e')]){_0x442588[_0x1abf('0x4f')]=[{'all':!![]}];}_0x442588=_['merge']({},_0x442588,_0x1cc1ee[_0x1abf('0x4d')]);return db[_0x1abf('0x3d')]['find'](_0x442588)[_0x1abf('0x2b')](handleEntityNotFound(_0x7f25f0,null))[_0x1abf('0x2b')](respondWithResult(_0x7f25f0,null))[_0x1abf('0x51')](handleError(_0x7f25f0,null));};exports[_0x1abf('0x56')]=function(_0x1111b4,_0x51472e){return db['MailQueue']['create'](_0x1111b4[_0x1abf('0x36')],{})[_0x1abf('0x2b')](function(_0x5730e5){var _0x453182=_0x1111b4['user']['get']({'plain':!![]});if(!_0x453182)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x453182[_0x1abf('0x57')]===_0x1abf('0x58')){var _0x5ec4ff=_0x5730e5[_0x1abf('0x2d')]({'plain':!![]});var _0x51cbb8=_0x1abf('0x2e');return db[_0x1abf('0x59')][_0x1abf('0x5a')]({'where':{'name':_0x51cbb8,'userProfileId':_0x453182[_0x1abf('0x5b')]},'raw':!![]})[_0x1abf('0x2b')](function(_0x27875b){if(_0x27875b&&_0x27875b[_0x1abf('0x5c')]===0x0){return db[_0x1abf('0x2f')][_0x1abf('0x56')]({'name':_0x5ec4ff[_0x1abf('0x32')],'resourceId':_0x5ec4ff['id'],'type':_0x27875b[_0x1abf('0x32')],'sectionId':_0x27875b['id']},{})[_0x1abf('0x2b')](function(){return _0x5730e5;});}else{return _0x5730e5;}})[_0x1abf('0x51')](function(_0x24c0f8){logger[_0x1abf('0x30')](_0x1abf('0x5d'),_0x24c0f8);throw _0x24c0f8;});}return _0x5730e5;})[_0x1abf('0x2b')](respondWithResult(_0x51472e,0xc9))['catch'](handleError(_0x51472e,null));};exports['update']=function(_0x35a4ef,_0x32fcef){if(_0x35a4ef[_0x1abf('0x36')]['id']){delete _0x35a4ef[_0x1abf('0x36')]['id'];}return db[_0x1abf('0x3d')][_0x1abf('0x5a')]({'where':{'id':_0x35a4ef['params']['id']}})[_0x1abf('0x2b')](handleEntityNotFound(_0x32fcef,null))[_0x1abf('0x2b')](saveUpdates(_0x35a4ef[_0x1abf('0x36')],null))[_0x1abf('0x2b')](respondWithResult(_0x32fcef,null))[_0x1abf('0x51')](handleError(_0x32fcef,null));};exports[_0x1abf('0x2c')]=function(_0xc9a1fb,_0x370b6c){return db[_0x1abf('0x3d')][_0x1abf('0x5a')]({'where':{'id':_0xc9a1fb['params']['id']}})[_0x1abf('0x2b')](handleEntityNotFound(_0x370b6c,null))[_0x1abf('0x2b')](removeEntity(_0x370b6c,null))[_0x1abf('0x51')](handleError(_0x370b6c,null));};exports[_0x1abf('0x5e')]=function(_0x4146ff,_0x2f1305){return db['MailQueue'][_0x1abf('0x5e')]()[_0x1abf('0x2b')](respondWithResult(_0x2f1305,null))[_0x1abf('0x51')](handleError(_0x2f1305,null));};exports[_0x1abf('0x5f')]=function(_0x52d25c,_0x53f138,_0x3e5366){var _0x4f054d={'raw':!![],'where':{}},_0x1c6ce9={},_0x2f9124;return db[_0x1abf('0x3d')][_0x1abf('0x60')]({'where':{'id':_0x52d25c[_0x1abf('0x53')]['id']}})[_0x1abf('0x2b')](handleEntityNotFound(_0x53f138,null))['then'](function(_0x337be8){if(_0x337be8){_0x2f9124=_0x337be8[_0x1abf('0x2d')]({'plain':!![]});_0x1c6ce9[_0x1abf('0x3f')]=_[_0x1abf('0x41')](db[_0x1abf('0x61')][_0x1abf('0x54')]);_0x1c6ce9[_0x1abf('0x40')]=_[_0x1abf('0x41')](_0x52d25c[_0x1abf('0x40')]);_0x1c6ce9[_0x1abf('0x42')]=_['intersection'](_0x1c6ce9[_0x1abf('0x3f')],_0x1c6ce9['query']);_0x4f054d[_0x1abf('0x44')]=_[_0x1abf('0x43')](_0x1c6ce9['model'],qs[_0x1abf('0x45')](_0x52d25c[_0x1abf('0x40')][_0x1abf('0x45')]));_0x4f054d[_0x1abf('0x44')]=_0x4f054d[_0x1abf('0x44')][_0x1abf('0x55')]?_0x4f054d[_0x1abf('0x44')]:_0x1c6ce9[_0x1abf('0x3f')];if(!_0x52d25c[_0x1abf('0x40')][_0x1abf('0x62')](_0x1abf('0x46'))){_0x4f054d[_0x1abf('0x23')]=qs[_0x1abf('0x23')](_0x52d25c['query'][_0x1abf('0x23')]);_0x4f054d[_0x1abf('0x22')]=qs[_0x1abf('0x22')](_0x52d25c[_0x1abf('0x40')][_0x1abf('0x22')]);}_0x4f054d[_0x1abf('0x63')]=qs[_0x1abf('0x47')](_0x52d25c['query'][_0x1abf('0x47')]);_0x4f054d[_0x1abf('0x48')]=qs['filters'](_[_0x1abf('0x49')](_0x52d25c['query'],_0x1c6ce9[_0x1abf('0x42')]));_0x4f054d[_0x1abf('0x48')][_0x1abf('0x64')]=_0x337be8['id'];if(_0x52d25c[_0x1abf('0x40')][_0x1abf('0x4a')]){_0x4f054d[_0x1abf('0x48')]=_[_0x1abf('0x35')](_0x4f054d[_0x1abf('0x48')],{'$or':_[_0x1abf('0x3c')](_0x4f054d['attributes'],function(_0x3a4839){var _0x25fdd1={};_0x25fdd1[_0x3a4839]={'$like':'%'+_0x52d25c['query'][_0x1abf('0x4a')]+'%'};return _0x25fdd1;})});}_0x4f054d=_['merge']({},_0x4f054d,_0x52d25c[_0x1abf('0x4d')]);return db[_0x1abf('0x61')][_0x1abf('0x65')](_0x4f054d);}})[_0x1abf('0x2b')](function(_0x2b2c64){if(_0x2b2c64){return db[_0x1abf('0x66')]['findAndCountAll']({'where':{'id':_[_0x1abf('0x3c')](_0x2b2c64,_0x1abf('0x67')),'role':_0x1abf('0x39')},'attributes':['id',_0x1abf('0x32'),_0x1abf('0x68'),_0x1abf('0x69'),'createdAt']});}})[_0x1abf('0x2b')](function(_0x23960d){if(_0x23960d){return{'count':_0x23960d['count'],'rows':_[_0x1abf('0x3c')](_0x23960d[_0x1abf('0x50')],function(_0x1b37b0){return{'membername':_0x1b37b0[_0x1abf('0x32')],'UserId':_0x1b37b0['id'],'queue_name':_0x2f9124[_0x1abf('0x32')],'MailQueueId':_0x2f9124['id'],'interface':util[_0x1abf('0x6a')](_0x1abf('0x6b'),_0x1abf('0x6c'),_0x1b37b0[_0x1abf('0x32')]),'penalty':0x0,'paused':_0x1b37b0[_0x1abf('0x68')],'createdAt':_0x1b37b0[_0x1abf('0x6d')],'updatedAt':_0x1b37b0[_0x1abf('0x69')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x1abf('0x2b')](respondWithFilteredResult(_0x53f138,_0x4f054d))[_0x1abf('0x51')](handleError(_0x53f138,null));};exports[_0x1abf('0x6e')]=function(_0x440fae,_0x42a444,_0x40af67){var _0x1e66a1={};var _0x276f0f={};var _0x207a29;var _0x175d8c;return db[_0x1abf('0x3d')][_0x1abf('0x60')]({'where':{'id':_0x440fae[_0x1abf('0x53')]['id']}})[_0x1abf('0x2b')](handleEntityNotFound(_0x42a444,null))[_0x1abf('0x2b')](function(_0x133c04){if(_0x133c04){_0x207a29=_0x133c04;_0x276f0f[_0x1abf('0x3f')]=_[_0x1abf('0x41')](db[_0x1abf('0x6f')][_0x1abf('0x54')]);_0x276f0f['query']=_['keys'](_0x440fae[_0x1abf('0x40')]);_0x276f0f['filters']=_[_0x1abf('0x43')](_0x276f0f['model'],_0x276f0f[_0x1abf('0x40')]);_0x1e66a1[_0x1abf('0x44')]=_[_0x1abf('0x43')](_0x276f0f[_0x1abf('0x3f')],qs[_0x1abf('0x45')](_0x440fae[_0x1abf('0x40')]['fields']));_0x1e66a1[_0x1abf('0x44')]=_0x1e66a1[_0x1abf('0x44')]['length']?_0x1e66a1['attributes']:_0x276f0f['model'];_0x1e66a1[_0x1abf('0x63')]=qs['sort'](_0x440fae[_0x1abf('0x40')][_0x1abf('0x47')]);_0x1e66a1[_0x1abf('0x48')]=qs[_0x1abf('0x42')](_[_0x1abf('0x49')](_0x440fae[_0x1abf('0x40')],_0x276f0f[_0x1abf('0x42')]));if(_0x440fae[_0x1abf('0x40')][_0x1abf('0x4a')]){_0x1e66a1[_0x1abf('0x48')]=_['merge'](_0x1e66a1[_0x1abf('0x48')],{'$or':_[_0x1abf('0x3c')](_0x1e66a1['attributes'],function(_0x21cf93){var _0x23ae05={};_0x23ae05[_0x21cf93]={'$like':'%'+_0x440fae[_0x1abf('0x40')]['filter']+'%'};return _0x23ae05;})});}_0x1e66a1=_[_0x1abf('0x35')]({},_0x1e66a1,_0x440fae[_0x1abf('0x4d')]);return _0x207a29[_0x1abf('0x6e')](_0x1e66a1);}})[_0x1abf('0x2b')](function(_0x8228f0){if(_0x8228f0){_0x175d8c=_0x8228f0['length'];if(!_0x440fae[_0x1abf('0x40')][_0x1abf('0x62')](_0x1abf('0x46'))){_0x1e66a1[_0x1abf('0x23')]=qs[_0x1abf('0x23')](_0x440fae['query']['limit']);_0x1e66a1[_0x1abf('0x22')]=qs['offset'](_0x440fae[_0x1abf('0x40')][_0x1abf('0x22')]);}return _0x207a29[_0x1abf('0x6e')](_0x1e66a1);}})['then'](function(_0x2f567e){if(_0x2f567e){return _0x2f567e?{'count':_0x175d8c,'rows':_0x2f567e}:null;}})[_0x1abf('0x2b')](respondWithResult(_0x42a444,null))[_0x1abf('0x51')](handleError(_0x42a444,null));};exports[_0x1abf('0x70')]=function(_0x3bd144,_0xa9288b,_0x27bb96){var _0x5114ea=_0x3bd144[_0x1abf('0x36')][_0x1abf('0x71')];return db['Team'][_0x1abf('0x65')]({'where':{'id':_0x5114ea},'attributes':['id'],'include':[{'model':db[_0x1abf('0x66')],'as':_0x1abf('0x72'),'attributes':['id',_0x1abf('0x32'),_0x1abf('0x73'),_0x1abf('0x74'),_0x1abf('0x75')],'raw':!![]}]})['then'](function(_0x21a7ae){if(_0x21a7ae){var _0x5fc448=_[_0x1abf('0x76')](_0x21a7ae,function(_0x1e4c2d){var _0x1048b8=_0x1e4c2d[_0x1abf('0x2d')]({'plain':!![]});return _0x1048b8[_0x1abf('0x72')];});return db[_0x1abf('0x3d')][_0x1abf('0x5a')]({'where':{'id':_0x3bd144[_0x1abf('0x53')]['id']}})['then'](function(_0x36c092){return db[_0x1abf('0x77')][_0x1abf('0x78')](function(_0x4eb657){return _0x36c092[_0x1abf('0x70')](_0x5114ea,{'transaction':_0x4eb657})[_0x1abf('0x2b')](function(){return BPromise[_0x1abf('0x79')](_0x5fc448,function(_0x1b5891){return db[_0x1abf('0x61')][_0x1abf('0x7a')]({'where':{'UserId':_0x1b5891['id'],'MailQueueId':_0x3bd144[_0x1abf('0x53')]['id']},'transaction':_0x4eb657});});})[_0x1abf('0x2b')](function(){_0x5fc448['forEach'](function(_0xcd2ce1){socket[_0x1abf('0x7b')](_0x1abf('0x7c'),{'UserId':_0xcd2ce1['id'],'MailQueueId':_0x36c092['id']});});});});});}})[_0x1abf('0x2b')](respondWithStatusCode(_0xa9288b,null))['catch'](handleError(_0xa9288b,null));};exports[_0x1abf('0x7d')]=function(_0x3b41aa,_0x43c87c,_0xc10451){return db[_0x1abf('0x6f')][_0x1abf('0x65')]({'where':{'id':_0x3b41aa[_0x1abf('0x40')][_0x1abf('0x71')]},'attributes':['id'],'include':[{'model':db[_0x1abf('0x66')],'as':_0x1abf('0x72'),'attributes':['id'],'raw':!![]}]})[_0x1abf('0x2b')](handleEntityNotFound(_0x43c87c,null))['then'](function(_0x316fe9){var _0x3b00a5=_[_0x1abf('0x3c')](_0x316fe9,'id');var _0x1558bf=[];var _0x581c09=[];var _0x3a91a0=squel[_0x1abf('0x7e')]();_0x3a91a0['field'](_0x1abf('0x7f'))[_0x1abf('0x80')](_0x1abf('0x81'),'tq')[_0x1abf('0x82')](_0x1abf('0x83'),'ut',_0x1abf('0x84'))[_0x1abf('0x48')]('MailQueueId\x20=\x20?',_0x3b41aa['params']['id']);for(var _0x206fcc=0x0;_0x206fcc<_0x316fe9[_0x1abf('0x55')];_0x206fcc+=0x1){let _0x7d3430=_0x316fe9[_0x206fcc];for(var _0x3c5d2c=0x0;_0x3c5d2c<_0x7d3430[_0x1abf('0x72')][_0x1abf('0x55')];_0x3c5d2c+=0x1){let _0x4e45ae=_0x7d3430[_0x1abf('0x72')][_0x3c5d2c];var _0x96293e=_0x3a91a0[_0x1abf('0x85')]();_0x96293e[_0x1abf('0x48')](_0x1abf('0x86'),_0x4e45ae['id']);_0x581c09[_0x1abf('0x87')](db[_0x1abf('0x77')][_0x1abf('0x40')](_0x96293e[_0x1abf('0x88')](),{'type':db[_0x1abf('0x77')]['QueryTypes'][_0x1abf('0x89')]})[_0x1abf('0x2b')](function(_0x399190){if(_0x399190[_0x1abf('0x55')]===0x1){return _0x4e45ae['id'];}else{var _0x5f3076=_['every'](_[_0x1abf('0x3c')](_0x399190,'TeamId'),function(_0x1e81fd){return _[_0x1abf('0x8a')](_0x3b00a5,_0x1e81fd);});if(_0x5f3076){return _0x4e45ae['id'];}}}));}}return BPromise[_0x1abf('0x8b')](_0x581c09)['then'](function(_0x546101){_0x1558bf=_(_0x1558bf)[_0x1abf('0x8c')](_0x546101)['compact']()[_0x1abf('0x8d')]();return db['MailQueue'][_0x1abf('0x5a')]({'where':{'id':_0x3b41aa['params']['id']}})[_0x1abf('0x2b')](function(_0x41a760){return db[_0x1abf('0x77')][_0x1abf('0x78')](function(_0x41ec20){return _0x41a760[_0x1abf('0x7d')](_0x3b41aa[_0x1abf('0x40')][_0x1abf('0x71')],{'transaction':_0x41ec20})[_0x1abf('0x2b')](function(){if(!_[_0x1abf('0x8e')](_0x1558bf)){return _0x41a760['removeAgents'](_0x1558bf,{'transaction':_0x41ec20});}})['then'](function(){_0x1558bf['forEach'](function(_0x1ceaad){socket[_0x1abf('0x7b')](_0x1abf('0x8f'),{'UserId':_0x1ceaad,'MailQueueId':_0x41a760['id']});});});});});});})[_0x1abf('0x2b')](respondWithStatusCode(_0x43c87c,null))['catch'](handleError(_0x43c87c,null));};exports[_0x1abf('0x90')]=function(_0x2bc933,_0x3bf8bc,_0x4b41c3){return db[_0x1abf('0x3d')][_0x1abf('0x5a')]({'where':{'id':_0x2bc933[_0x1abf('0x53')]['id']}})[_0x1abf('0x2b')](handleEntityNotFound(_0x3bf8bc,null))[_0x1abf('0x2b')](function(_0x18b42b){if(_0x18b42b){return _0x18b42b[_0x1abf('0x90')](_0x2bc933[_0x1abf('0x36')][_0x1abf('0x71')],_[_0x1abf('0x91')](_0x2bc933[_0x1abf('0x36')],[_0x1abf('0x71'),'id'])||{})['spread'](function(_0x28504c){for(var _0x449916=0x0;_0x449916<_0x2bc933[_0x1abf('0x36')]['ids'][_0x1abf('0x55')];_0x449916+=0x1){socket[_0x1abf('0x7b')](_0x1abf('0x7c'),{'UserId':_0x2bc933[_0x1abf('0x36')][_0x1abf('0x71')][_0x449916],'MailQueueId':_0x2bc933[_0x1abf('0x53')]['id']});}return _0x28504c;});}})[_0x1abf('0x2b')](respondWithResult(_0x3bf8bc,null))[_0x1abf('0x51')](handleError(_0x3bf8bc,null));};exports[_0x1abf('0x92')]=function(_0x3fe191,_0x463737,_0x295592){return db[_0x1abf('0x3d')][_0x1abf('0x5a')]({'where':{'id':_0x3fe191['params']['id']}})[_0x1abf('0x2b')](handleEntityNotFound(_0x463737,null))['then'](function(_0x3ace8b){if(_0x3ace8b){return _0x3ace8b['removeAgents'](_0x3fe191[_0x1abf('0x40')][_0x1abf('0x71')])[_0x1abf('0x2b')](function(){if(_[_0x1abf('0x93')](_0x3fe191[_0x1abf('0x40')][_0x1abf('0x71')])){for(var _0x457be2=0x0;_0x457be2<_0x3fe191[_0x1abf('0x40')][_0x1abf('0x71')][_0x1abf('0x55')];_0x457be2+=0x1){socket[_0x1abf('0x7b')](_0x1abf('0x8f'),{'UserId':Number(_0x3fe191[_0x1abf('0x40')]['ids'][_0x457be2]),'MailQueueId':Number(_0x3fe191[_0x1abf('0x53')]['id'])});}}else{socket['emit'](_0x1abf('0x8f'),{'UserId':Number(_0x3fe191[_0x1abf('0x40')][_0x1abf('0x71')]),'MailQueueId':Number(_0x3fe191[_0x1abf('0x53')]['id'])});}});}})[_0x1abf('0x2b')](respondWithStatusCode(_0x463737,null))[_0x1abf('0x51')](handleError(_0x463737,null));};exports[_0x1abf('0x94')]=function(_0x3fc5c1,_0x4e7ded,_0x29fa6c){var _0x59edf7={};var _0x3723d0={};var _0x1fe402;var _0x353f21;return db[_0x1abf('0x3d')]['findOne']({'where':{'id':_0x3fc5c1[_0x1abf('0x53')]['id']}})[_0x1abf('0x2b')](handleEntityNotFound(_0x4e7ded,null))[_0x1abf('0x2b')](function(_0x58d0fb){if(_0x58d0fb){_0x1fe402=_0x58d0fb;_0x3723d0[_0x1abf('0x3f')]=_[_0x1abf('0x41')](db['User'][_0x1abf('0x54')]);_0x3723d0[_0x1abf('0x40')]=_[_0x1abf('0x41')](_0x3fc5c1[_0x1abf('0x40')]);_0x3723d0[_0x1abf('0x42')]=_[_0x1abf('0x43')](_0x3723d0[_0x1abf('0x3f')],_0x3723d0[_0x1abf('0x40')]);_0x59edf7[_0x1abf('0x44')]=_['intersection'](_0x3723d0[_0x1abf('0x3f')],qs[_0x1abf('0x45')](_0x3fc5c1[_0x1abf('0x40')][_0x1abf('0x45')]));_0x59edf7['attributes']=_0x59edf7[_0x1abf('0x44')][_0x1abf('0x55')]?_0x59edf7[_0x1abf('0x44')]:_0x3723d0[_0x1abf('0x3f')];_0x59edf7[_0x1abf('0x63')]=qs[_0x1abf('0x47')](_0x3fc5c1[_0x1abf('0x40')][_0x1abf('0x47')]);_0x59edf7[_0x1abf('0x48')]=qs[_0x1abf('0x42')](_[_0x1abf('0x49')](_0x3fc5c1[_0x1abf('0x40')],_0x3723d0[_0x1abf('0x42')]));if(_0x3fc5c1[_0x1abf('0x40')][_0x1abf('0x4a')]){_0x59edf7[_0x1abf('0x48')]=_[_0x1abf('0x35')](_0x59edf7[_0x1abf('0x48')],{'$or':_[_0x1abf('0x3c')](_0x59edf7['attributes'],function(_0x5dc3ad){var _0x29c05e={};_0x29c05e[_0x5dc3ad]={'$like':'%'+_0x3fc5c1[_0x1abf('0x40')][_0x1abf('0x4a')]+'%'};return _0x29c05e;})});}_0x59edf7=_[_0x1abf('0x35')]({},_0x59edf7,_0x3fc5c1[_0x1abf('0x4d')]);return _0x1fe402[_0x1abf('0x94')](_0x59edf7);}})['then'](function(_0x4a8c6c){if(_0x4a8c6c){_0x353f21=_0x4a8c6c[_0x1abf('0x55')];if(!_0x3fc5c1[_0x1abf('0x40')]['hasOwnProperty'](_0x1abf('0x46'))){_0x59edf7[_0x1abf('0x23')]=qs[_0x1abf('0x23')](_0x3fc5c1[_0x1abf('0x40')]['limit']);_0x59edf7[_0x1abf('0x22')]=qs[_0x1abf('0x22')](_0x3fc5c1[_0x1abf('0x40')][_0x1abf('0x22')]);}return _0x1fe402['getAgents'](_0x59edf7);}})[_0x1abf('0x2b')](function(_0x44cc5a){if(_0x44cc5a){return _0x44cc5a?{'count':_0x353f21,'rows':_0x44cc5a}:null;}})['then'](respondWithResult(_0x4e7ded,null))[_0x1abf('0x51')](handleError(_0x4e7ded,null));};