Built motion from commit (unavailable).|2.5.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 _0x68f1=['sox','to-csv','ejs','fs-extra','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./mailQueue.socket','register','status','json','offset','undefined','count','limit','set','Content-Range','apply','reject','update','then','destroy','get','UserProfileResource','end','sendStatus','name','send','index','MailQueue','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','order','sort','where','merge','map','VIRTUAL','filter','includeAll','include','findAll','params','rawAttributes','options','catch','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','MailQueues','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','getMembers','UserMailQueue','hasOwnProperty','MailQueueId','User','agent','mailPause','createdAt','format','SIP','findOne','Team','pick','getTeams','addTeams','ids','Agents','online','voicePause','interface','sequelize','transaction','findOrCreate','emit','userMailQueue:save','removeTeams','select','field','tq.TeamId','team_has_mail_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','push','SELECT','every','includes','all','compact','forEach','addAgents','omit','spread','removeAgents','isArray','userMailQueue:remove','getAgents','nolimit','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path'];(function(_0x5f02d6,_0x533f9c){var _0x4d336a=function(_0x5907fa){while(--_0x5907fa){_0x5f02d6['push'](_0x5f02d6['shift']());}};_0x4d336a(++_0x533f9c);}(_0x68f1,0x109));var _0x168f=function(_0x50e2f6,_0x211ef3){_0x50e2f6=_0x50e2f6-0x0;var _0x1c6a5b=_0x68f1[_0x50e2f6];return _0x1c6a5b;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x168f('0x0'));var zipdir=require(_0x168f('0x1'));var jsonpatch=require(_0x168f('0x2'));var rp=require(_0x168f('0x3'));var moment=require('moment');var BPromise=require(_0x168f('0x4'));var Mustache=require('mustache');var util=require(_0x168f('0x5'));var path=require(_0x168f('0x6'));var sox=require(_0x168f('0x7'));var csv=require(_0x168f('0x8'));var ejs=require(_0x168f('0x9'));var fs=require('fs');var fs_extra=require(_0x168f('0xa'));var _=require('lodash');var squel=require(_0x168f('0xb'));var crypto=require(_0x168f('0xc'));var jsforce=require(_0x168f('0xd'));var deskjs=require(_0x168f('0xe'));var toCsv=require(_0x168f('0x8'));var querystring=require(_0x168f('0xf'));var Papa=require(_0x168f('0x10'));var Redis=require(_0x168f('0x11'));var authService=require(_0x168f('0x12'));var qs=require(_0x168f('0x13'));var as=require(_0x168f('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x168f('0x15'));var config=require(_0x168f('0x16'));var licenseUtil=require(_0x168f('0x17'));var db=require(_0x168f('0x18'))['db'];config[_0x168f('0x19')]=_[_0x168f('0x1a')](config['redis'],{'host':_0x168f('0x1b'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x168f('0x1c'))[_0x168f('0x1d')](socket);function respondWithStatusCode(_0x44cb05,_0x2bb494){_0x2bb494=_0x2bb494||0xcc;return function(_0xef30a8){if(_0xef30a8){return _0x44cb05['sendStatus'](_0x2bb494);}return _0x44cb05[_0x168f('0x1e')](_0x2bb494)['end']();};}function respondWithResult(_0x299850,_0x2e76ff){_0x2e76ff=_0x2e76ff||0xc8;return function(_0x2d22b0){if(_0x2d22b0){return _0x299850[_0x168f('0x1e')](_0x2e76ff)[_0x168f('0x1f')](_0x2d22b0);}};}function respondWithFilteredResult(_0xc958c0,_0x529100){return function(_0x255c59){if(_0x255c59){var _0x5b00b7=typeof _0x529100[_0x168f('0x20')]===_0x168f('0x21')&&typeof _0x529100['limit']===_0x168f('0x21');var _0x473b19=_0x255c59[_0x168f('0x22')];var _0x3c6c47=_0x5b00b7?0x0:_0x529100[_0x168f('0x20')];var _0x2edf87=_0x5b00b7?_0x255c59[_0x168f('0x22')]:_0x529100[_0x168f('0x20')]+_0x529100[_0x168f('0x23')];var _0x3e2374;if(_0x2edf87>=_0x473b19){_0x2edf87=_0x473b19;_0x3e2374=0xc8;}else{_0x3e2374=0xce;}_0xc958c0[_0x168f('0x1e')](_0x3e2374);return _0xc958c0[_0x168f('0x24')](_0x168f('0x25'),_0x3c6c47+'-'+_0x2edf87+'/'+_0x473b19)['json'](_0x255c59);}return null;};}function patchUpdates(_0x363e1f){return function(_0x195941){try{jsonpatch[_0x168f('0x26')](_0x195941,_0x363e1f,!![]);}catch(_0x3e09f7){return BPromise[_0x168f('0x27')](_0x3e09f7);}return _0x195941['save']();};}function saveUpdates(_0x301feb,_0x3caf6d){return function(_0x1a447a){if(_0x1a447a){return _0x1a447a[_0x168f('0x28')](_0x301feb)[_0x168f('0x29')](function(_0x3786e1){return _0x3786e1;});}return null;};}function removeEntity(_0x54dbd8,_0x34526c){return function(_0x475fd6){if(_0x475fd6){return _0x475fd6[_0x168f('0x2a')]()['then'](function(){var _0x16cfd2=_0x475fd6[_0x168f('0x2b')]({'plain':!![]});var _0xedb5c8='MailQueues';return db[_0x168f('0x2c')][_0x168f('0x2a')]({'where':{'type':_0xedb5c8,'resourceId':_0x16cfd2['id']}})[_0x168f('0x29')](function(){return _0x475fd6;});})[_0x168f('0x29')](function(){_0x54dbd8[_0x168f('0x1e')](0xcc)[_0x168f('0x2d')]();});}};}function handleEntityNotFound(_0x5cc608,_0xac2ec2){return function(_0x25aba1){if(!_0x25aba1){_0x5cc608[_0x168f('0x2e')](0x194);}return _0x25aba1;};}function handleError(_0x2b8566,_0x59e3a4){_0x59e3a4=_0x59e3a4||0x1f4;return function(_0x46e322){logger['error'](_0x46e322['stack']);if(_0x46e322[_0x168f('0x2f')]){delete _0x46e322[_0x168f('0x2f')];}_0x2b8566[_0x168f('0x1e')](_0x59e3a4)[_0x168f('0x30')](_0x46e322);};}exports[_0x168f('0x31')]=function(_0x28420c,_0x34b6d5){var _0x44c45c={},_0x5b2b09={},_0x5eba73={'count':0x0,'rows':[]};var _0x7c5e3b=_['map'](db[_0x168f('0x32')]['rawAttributes'],function(_0x145019){return{'name':_0x145019[_0x168f('0x33')],'type':_0x145019[_0x168f('0x34')][_0x168f('0x35')]};});_0x5b2b09[_0x168f('0x36')]=_['map'](_0x7c5e3b,'name');_0x5b2b09[_0x168f('0x37')]=_[_0x168f('0x38')](_0x28420c[_0x168f('0x37')]);_0x5b2b09[_0x168f('0x39')]=_[_0x168f('0x3a')](_0x5b2b09[_0x168f('0x36')],_0x5b2b09[_0x168f('0x37')]);_0x44c45c['attributes']=_[_0x168f('0x3a')](_0x5b2b09[_0x168f('0x36')],qs[_0x168f('0x3b')](_0x28420c['query'][_0x168f('0x3b')]));_0x44c45c[_0x168f('0x3c')]=_0x44c45c[_0x168f('0x3c')][_0x168f('0x3d')]?_0x44c45c[_0x168f('0x3c')]:_0x5b2b09[_0x168f('0x36')];if(!_0x28420c[_0x168f('0x37')]['hasOwnProperty']('nolimit')){_0x44c45c['limit']=qs[_0x168f('0x23')](_0x28420c['query'][_0x168f('0x23')]);_0x44c45c[_0x168f('0x20')]=qs['offset'](_0x28420c['query']['offset']);}_0x44c45c[_0x168f('0x3e')]=qs[_0x168f('0x3f')](_0x28420c[_0x168f('0x37')][_0x168f('0x3f')]);_0x44c45c[_0x168f('0x40')]=qs[_0x168f('0x39')](_['pick'](_0x28420c[_0x168f('0x37')],_0x5b2b09['filters']),_0x7c5e3b);if(_0x28420c[_0x168f('0x37')]['filter']){_0x44c45c[_0x168f('0x40')]=_[_0x168f('0x41')](_0x44c45c[_0x168f('0x40')],{'$or':_[_0x168f('0x42')](_0x7c5e3b,function(_0xb325a){if(_0xb325a[_0x168f('0x34')]!==_0x168f('0x43')){var _0x179062={};_0x179062[_0xb325a[_0x168f('0x2f')]]={'$like':'%'+_0x28420c[_0x168f('0x37')][_0x168f('0x44')]+'%'};return _0x179062;}})});}_0x44c45c=_['merge']({},_0x44c45c,_0x28420c['options']);var _0x5ed79b={'where':_0x44c45c[_0x168f('0x40')]};return db[_0x168f('0x32')][_0x168f('0x22')](_0x5ed79b)[_0x168f('0x29')](function(_0x27abb3){_0x5eba73[_0x168f('0x22')]=_0x27abb3;if(_0x28420c[_0x168f('0x37')][_0x168f('0x45')]){_0x44c45c[_0x168f('0x46')]=[{'all':!![]}];}return db['MailQueue'][_0x168f('0x47')](_0x44c45c);})[_0x168f('0x29')](function(_0x2170c4){_0x5eba73['rows']=_0x2170c4;return _0x5eba73;})[_0x168f('0x29')](respondWithFilteredResult(_0x34b6d5,_0x44c45c))['catch'](handleError(_0x34b6d5,null));};exports['show']=function(_0x56747d,_0x342383){var _0xb1b069={'raw':!![],'where':{'id':_0x56747d[_0x168f('0x48')]['id']}},_0x1a9222={};_0x1a9222[_0x168f('0x36')]=_[_0x168f('0x38')](db[_0x168f('0x32')][_0x168f('0x49')]);_0x1a9222['query']=_[_0x168f('0x38')](_0x56747d[_0x168f('0x37')]);_0x1a9222['filters']=_[_0x168f('0x3a')](_0x1a9222[_0x168f('0x36')],_0x1a9222[_0x168f('0x37')]);_0xb1b069['attributes']=_[_0x168f('0x3a')](_0x1a9222[_0x168f('0x36')],qs['fields'](_0x56747d[_0x168f('0x37')][_0x168f('0x3b')]));_0xb1b069[_0x168f('0x3c')]=_0xb1b069[_0x168f('0x3c')]['length']?_0xb1b069[_0x168f('0x3c')]:_0x1a9222[_0x168f('0x36')];if(_0x56747d['query'][_0x168f('0x45')]){_0xb1b069['include']=[{'all':!![]}];}_0xb1b069=_['merge']({},_0xb1b069,_0x56747d[_0x168f('0x4a')]);return db[_0x168f('0x32')]['find'](_0xb1b069)[_0x168f('0x29')](handleEntityNotFound(_0x342383,null))['then'](respondWithResult(_0x342383,null))[_0x168f('0x4b')](handleError(_0x342383,null));};exports[_0x168f('0x4c')]=function(_0x25505b,_0x12f567){return db[_0x168f('0x32')][_0x168f('0x4c')](_0x25505b['body'],{})['then'](function(_0x1b4815){var _0x5049e2=_0x25505b[_0x168f('0x4d')][_0x168f('0x2b')]({'plain':!![]});if(!_0x5049e2)throw new Error(_0x168f('0x4e'));if(_0x5049e2['role']===_0x168f('0x4d')){var _0x2fea5b=_0x1b4815[_0x168f('0x2b')]({'plain':!![]});var _0x301275=_0x168f('0x4f');return db[_0x168f('0x50')][_0x168f('0x51')]({'where':{'name':_0x301275,'userProfileId':_0x5049e2[_0x168f('0x52')]},'raw':!![]})[_0x168f('0x29')](function(_0x1e1e4f){if(_0x1e1e4f&&_0x1e1e4f[_0x168f('0x53')]===0x0){return db['UserProfileResource'][_0x168f('0x4c')]({'name':_0x2fea5b[_0x168f('0x2f')],'resourceId':_0x2fea5b['id'],'type':_0x1e1e4f[_0x168f('0x2f')],'sectionId':_0x1e1e4f['id']},{})['then'](function(){return _0x1b4815;});}else{return _0x1b4815;}})[_0x168f('0x4b')](function(_0x4609cb){logger['error'](_0x168f('0x54'),_0x4609cb);throw _0x4609cb;});}return _0x1b4815;})[_0x168f('0x29')](respondWithResult(_0x12f567,0xc9))[_0x168f('0x4b')](handleError(_0x12f567,null));};exports[_0x168f('0x28')]=function(_0x53142e,_0x11be3e){if(_0x53142e[_0x168f('0x55')]['id']){delete _0x53142e[_0x168f('0x55')]['id'];}return db[_0x168f('0x32')][_0x168f('0x51')]({'where':{'id':_0x53142e[_0x168f('0x48')]['id']}})[_0x168f('0x29')](handleEntityNotFound(_0x11be3e,null))['then'](saveUpdates(_0x53142e[_0x168f('0x55')],null))[_0x168f('0x29')](respondWithResult(_0x11be3e,null))[_0x168f('0x4b')](handleError(_0x11be3e,null));};exports[_0x168f('0x2a')]=function(_0x43d372,_0x1a9688){return db['MailQueue']['find']({'where':{'id':_0x43d372[_0x168f('0x48')]['id']}})[_0x168f('0x29')](handleEntityNotFound(_0x1a9688,null))[_0x168f('0x29')](removeEntity(_0x1a9688,null))['catch'](handleError(_0x1a9688,null));};exports['describe']=function(_0xb129f8,_0x269903){return db[_0x168f('0x32')]['describe']()[_0x168f('0x29')](respondWithResult(_0x269903,null))[_0x168f('0x4b')](handleError(_0x269903,null));};exports[_0x168f('0x56')]=function(_0x57e6d3,_0xea48a8,_0x485ecd){var _0x14a744={'raw':!![],'where':{}},_0x76c269={},_0x20be8f;return db[_0x168f('0x32')]['findOne']({'where':{'id':_0x57e6d3['params']['id']}})[_0x168f('0x29')](handleEntityNotFound(_0xea48a8,null))['then'](function(_0x185249){if(_0x185249){_0x20be8f=_0x185249['get']({'plain':!![]});_0x76c269[_0x168f('0x36')]=_[_0x168f('0x38')](db[_0x168f('0x57')][_0x168f('0x49')]);_0x76c269[_0x168f('0x37')]=_[_0x168f('0x38')](_0x57e6d3[_0x168f('0x37')]);_0x76c269[_0x168f('0x39')]=_['intersection'](_0x76c269[_0x168f('0x36')],_0x76c269[_0x168f('0x37')]);_0x14a744[_0x168f('0x3c')]=_[_0x168f('0x3a')](_0x76c269[_0x168f('0x36')],qs[_0x168f('0x3b')](_0x57e6d3[_0x168f('0x37')][_0x168f('0x3b')]));_0x14a744['attributes']=_0x14a744[_0x168f('0x3c')][_0x168f('0x3d')]?_0x14a744[_0x168f('0x3c')]:_0x76c269[_0x168f('0x36')];if(!_0x57e6d3[_0x168f('0x37')][_0x168f('0x58')]('nolimit')){_0x14a744['limit']=qs['limit'](_0x57e6d3[_0x168f('0x37')]['limit']);_0x14a744['offset']=qs[_0x168f('0x20')](_0x57e6d3[_0x168f('0x37')][_0x168f('0x20')]);}_0x14a744['order']=qs[_0x168f('0x3f')](_0x57e6d3[_0x168f('0x37')][_0x168f('0x3f')]);_0x14a744[_0x168f('0x40')]=qs[_0x168f('0x39')](_['pick'](_0x57e6d3[_0x168f('0x37')],_0x76c269[_0x168f('0x39')]));_0x14a744[_0x168f('0x40')][_0x168f('0x59')]=_0x185249['id'];if(_0x57e6d3[_0x168f('0x37')][_0x168f('0x44')]){_0x14a744[_0x168f('0x40')]=_['merge'](_0x14a744['where'],{'$or':_[_0x168f('0x42')](_0x14a744[_0x168f('0x3c')],function(_0x2aa382){var _0x2bc6dd={};_0x2bc6dd[_0x2aa382]={'$like':'%'+_0x57e6d3[_0x168f('0x37')][_0x168f('0x44')]+'%'};return _0x2bc6dd;})});}_0x14a744=_[_0x168f('0x41')]({},_0x14a744,_0x57e6d3[_0x168f('0x4a')]);return db[_0x168f('0x57')][_0x168f('0x47')](_0x14a744);}})[_0x168f('0x29')](function(_0x43012b){if(_0x43012b){return db[_0x168f('0x5a')]['findAndCountAll']({'where':{'id':_[_0x168f('0x42')](_0x43012b,'UserId'),'role':_0x168f('0x5b')},'attributes':['id',_0x168f('0x2f'),_0x168f('0x5c'),'updatedAt',_0x168f('0x5d')]});}})['then'](function(_0x556522){if(_0x556522){return{'count':_0x556522[_0x168f('0x22')],'rows':_[_0x168f('0x42')](_0x556522['rows'],function(_0x3630e3){return{'membername':_0x3630e3[_0x168f('0x2f')],'UserId':_0x3630e3['id'],'queue_name':_0x20be8f[_0x168f('0x2f')],'MailQueueId':_0x20be8f['id'],'interface':util[_0x168f('0x5e')]('%s/%s',_0x168f('0x5f'),_0x3630e3[_0x168f('0x2f')]),'penalty':0x0,'paused':_0x3630e3[_0x168f('0x5c')],'createdAt':_0x3630e3[_0x168f('0x5d')],'updatedAt':_0x3630e3['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0x168f('0x29')](respondWithFilteredResult(_0xea48a8,_0x14a744))[_0x168f('0x4b')](handleError(_0xea48a8,null));};exports['getTeams']=function(_0x4a3b3e,_0x805f59,_0x19e1db){var _0x15a52d={};var _0x169644={};var _0x55f51a;var _0x3cdc33;return db[_0x168f('0x32')][_0x168f('0x60')]({'where':{'id':_0x4a3b3e['params']['id']}})[_0x168f('0x29')](handleEntityNotFound(_0x805f59,null))[_0x168f('0x29')](function(_0x14f643){if(_0x14f643){_0x55f51a=_0x14f643;_0x169644[_0x168f('0x36')]=_[_0x168f('0x38')](db[_0x168f('0x61')][_0x168f('0x49')]);_0x169644[_0x168f('0x37')]=_['keys'](_0x4a3b3e[_0x168f('0x37')]);_0x169644[_0x168f('0x39')]=_[_0x168f('0x3a')](_0x169644[_0x168f('0x36')],_0x169644['query']);_0x15a52d[_0x168f('0x3c')]=_[_0x168f('0x3a')](_0x169644[_0x168f('0x36')],qs[_0x168f('0x3b')](_0x4a3b3e[_0x168f('0x37')][_0x168f('0x3b')]));_0x15a52d[_0x168f('0x3c')]=_0x15a52d[_0x168f('0x3c')][_0x168f('0x3d')]?_0x15a52d['attributes']:_0x169644[_0x168f('0x36')];_0x15a52d[_0x168f('0x3e')]=qs[_0x168f('0x3f')](_0x4a3b3e[_0x168f('0x37')][_0x168f('0x3f')]);_0x15a52d['where']=qs[_0x168f('0x39')](_[_0x168f('0x62')](_0x4a3b3e['query'],_0x169644['filters']));if(_0x4a3b3e[_0x168f('0x37')]['filter']){_0x15a52d['where']=_[_0x168f('0x41')](_0x15a52d[_0x168f('0x40')],{'$or':_['map'](_0x15a52d['attributes'],function(_0x4b23bf){var _0x2f4c04={};_0x2f4c04[_0x4b23bf]={'$like':'%'+_0x4a3b3e[_0x168f('0x37')][_0x168f('0x44')]+'%'};return _0x2f4c04;})});}_0x15a52d=_[_0x168f('0x41')]({},_0x15a52d,_0x4a3b3e[_0x168f('0x4a')]);return _0x55f51a[_0x168f('0x63')](_0x15a52d);}})['then'](function(_0x14076e){if(_0x14076e){_0x3cdc33=_0x14076e[_0x168f('0x3d')];if(!_0x4a3b3e[_0x168f('0x37')][_0x168f('0x58')]('nolimit')){_0x15a52d[_0x168f('0x23')]=qs[_0x168f('0x23')](_0x4a3b3e[_0x168f('0x37')][_0x168f('0x23')]);_0x15a52d[_0x168f('0x20')]=qs['offset'](_0x4a3b3e[_0x168f('0x37')]['offset']);}return _0x55f51a[_0x168f('0x63')](_0x15a52d);}})['then'](function(_0x123eee){if(_0x123eee){return _0x123eee?{'count':_0x3cdc33,'rows':_0x123eee}:null;}})['then'](respondWithResult(_0x805f59,null))[_0x168f('0x4b')](handleError(_0x805f59,null));};exports[_0x168f('0x64')]=function(_0x51777e,_0x1ff398,_0x13e9d4){var _0x2030ce=_0x51777e[_0x168f('0x55')][_0x168f('0x65')];return db['Team'][_0x168f('0x47')]({'where':{'id':_0x2030ce},'attributes':['id'],'include':[{'model':db['User'],'as':_0x168f('0x66'),'attributes':['id','name',_0x168f('0x67'),_0x168f('0x68'),_0x168f('0x69')],'raw':!![]}]})[_0x168f('0x29')](function(_0x2def92){if(_0x2def92){var _0x33b121=_['flatMap'](_0x2def92,function(_0x38ae91){var _0x2e7f2e=_0x38ae91['get']({'plain':!![]});return _0x2e7f2e[_0x168f('0x66')];});return db[_0x168f('0x32')]['find']({'where':{'id':_0x51777e[_0x168f('0x48')]['id']}})[_0x168f('0x29')](function(_0x9bd216){return db[_0x168f('0x6a')][_0x168f('0x6b')](function(_0x2c344){return _0x9bd216[_0x168f('0x64')](_0x2030ce,{'transaction':_0x2c344})[_0x168f('0x29')](function(){return BPromise['each'](_0x33b121,function(_0x3878d4){return db['UserMailQueue'][_0x168f('0x6c')]({'where':{'UserId':_0x3878d4['id'],'MailQueueId':_0x51777e['params']['id']},'transaction':_0x2c344});});})[_0x168f('0x29')](function(){_0x33b121['forEach'](function(_0x5eeabc){socket[_0x168f('0x6d')](_0x168f('0x6e'),{'UserId':_0x5eeabc['id'],'MailQueueId':_0x9bd216['id']});});});});});}})['then'](respondWithStatusCode(_0x1ff398,null))[_0x168f('0x4b')](handleError(_0x1ff398,null));};exports[_0x168f('0x6f')]=function(_0x1f388a,_0x59641b,_0x940f5f){return db[_0x168f('0x61')][_0x168f('0x47')]({'where':{'id':_0x1f388a[_0x168f('0x37')][_0x168f('0x65')]},'attributes':['id'],'include':[{'model':db[_0x168f('0x5a')],'as':_0x168f('0x66'),'attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x59641b,null))[_0x168f('0x29')](function(_0x1d04b1){var _0x274c1f=_['map'](_0x1d04b1,'id');var _0x545fc5=[];var _0x43f72a=[];var _0x295b8e=squel[_0x168f('0x70')]();_0x295b8e[_0x168f('0x71')](_0x168f('0x72'))['from'](_0x168f('0x73'),'tq')[_0x168f('0x74')](_0x168f('0x75'),'ut',_0x168f('0x76'))[_0x168f('0x40')]('MailQueueId\x20=\x20?',_0x1f388a[_0x168f('0x48')]['id']);for(var _0x41962b=0x0;_0x41962b<_0x1d04b1[_0x168f('0x3d')];_0x41962b+=0x1){let _0x4028a8=_0x1d04b1[_0x41962b];for(var _0x5048ac=0x0;_0x5048ac<_0x4028a8['Agents']['length'];_0x5048ac+=0x1){let _0x165fcd=_0x4028a8['Agents'][_0x5048ac];var _0x1372b7=_0x295b8e[_0x168f('0x77')]();_0x1372b7[_0x168f('0x40')](_0x168f('0x78'),_0x165fcd['id']);_0x43f72a[_0x168f('0x79')](db['sequelize'][_0x168f('0x37')](_0x1372b7['toString'](),{'type':db[_0x168f('0x6a')]['QueryTypes'][_0x168f('0x7a')]})[_0x168f('0x29')](function(_0xccb5f7){if(_0xccb5f7[_0x168f('0x3d')]===0x1){return _0x165fcd['id'];}else{var _0xdcf133=_[_0x168f('0x7b')](_[_0x168f('0x42')](_0xccb5f7,'TeamId'),function(_0x59a6d2){return _[_0x168f('0x7c')](_0x274c1f,_0x59a6d2);});if(_0xdcf133){return _0x165fcd['id'];}}}));}}return BPromise[_0x168f('0x7d')](_0x43f72a)['then'](function(_0x39cf34){_0x545fc5=_(_0x545fc5)['union'](_0x39cf34)[_0x168f('0x7e')]()['value']();return db[_0x168f('0x32')][_0x168f('0x51')]({'where':{'id':_0x1f388a[_0x168f('0x48')]['id']}})[_0x168f('0x29')](function(_0x559b32){return db['sequelize'][_0x168f('0x6b')](function(_0x1f8c3f){return _0x559b32['removeTeams'](_0x1f388a['query'][_0x168f('0x65')],{'transaction':_0x1f8c3f})[_0x168f('0x29')](function(){if(!_['isEmpty'](_0x545fc5)){return _0x559b32['removeAgents'](_0x545fc5,{'transaction':_0x1f8c3f});}})[_0x168f('0x29')](function(){_0x545fc5[_0x168f('0x7f')](function(_0x4b2ffb){socket[_0x168f('0x6d')]('userMailQueue:remove',{'UserId':_0x4b2ffb,'MailQueueId':_0x559b32['id']});});});});});});})[_0x168f('0x29')](respondWithStatusCode(_0x59641b,null))[_0x168f('0x4b')](handleError(_0x59641b,null));};exports[_0x168f('0x80')]=function(_0x1b2715,_0xd20c04,_0x2a320a){return db[_0x168f('0x32')][_0x168f('0x51')]({'where':{'id':_0x1b2715[_0x168f('0x48')]['id']}})[_0x168f('0x29')](handleEntityNotFound(_0xd20c04,null))[_0x168f('0x29')](function(_0x25abf9){if(_0x25abf9){return _0x25abf9[_0x168f('0x80')](_0x1b2715[_0x168f('0x55')][_0x168f('0x65')],_[_0x168f('0x81')](_0x1b2715['body'],[_0x168f('0x65'),'id'])||{})[_0x168f('0x82')](function(_0x4fe8d5){for(var _0x95fefc=0x0;_0x95fefc<_0x1b2715[_0x168f('0x55')][_0x168f('0x65')][_0x168f('0x3d')];_0x95fefc+=0x1){socket['emit'](_0x168f('0x6e'),{'UserId':_0x1b2715[_0x168f('0x55')][_0x168f('0x65')][_0x95fefc],'MailQueueId':_0x1b2715[_0x168f('0x48')]['id']});}return _0x4fe8d5;});}})[_0x168f('0x29')](respondWithResult(_0xd20c04,null))[_0x168f('0x4b')](handleError(_0xd20c04,null));};exports[_0x168f('0x83')]=function(_0x45d500,_0x256fc4,_0x57e557){return db[_0x168f('0x32')][_0x168f('0x51')]({'where':{'id':_0x45d500[_0x168f('0x48')]['id']}})[_0x168f('0x29')](handleEntityNotFound(_0x256fc4,null))['then'](function(_0x11c38a){if(_0x11c38a){return _0x11c38a['removeAgents'](_0x45d500[_0x168f('0x37')]['ids'])[_0x168f('0x29')](function(){if(_[_0x168f('0x84')](_0x45d500[_0x168f('0x37')][_0x168f('0x65')])){for(var _0x140a0b=0x0;_0x140a0b<_0x45d500[_0x168f('0x37')][_0x168f('0x65')][_0x168f('0x3d')];_0x140a0b+=0x1){socket[_0x168f('0x6d')](_0x168f('0x85'),{'UserId':Number(_0x45d500[_0x168f('0x37')][_0x168f('0x65')][_0x140a0b]),'MailQueueId':Number(_0x45d500[_0x168f('0x48')]['id'])});}}else{socket[_0x168f('0x6d')](_0x168f('0x85'),{'UserId':Number(_0x45d500[_0x168f('0x37')][_0x168f('0x65')]),'MailQueueId':Number(_0x45d500[_0x168f('0x48')]['id'])});}});}})['then'](respondWithStatusCode(_0x256fc4,null))[_0x168f('0x4b')](handleError(_0x256fc4,null));};exports[_0x168f('0x86')]=function(_0x4aebbb,_0x5c2d2d,_0x467e84){var _0x56a621={};var _0xf6c86a={};var _0x15f6cd;var _0xaf471;return db[_0x168f('0x32')][_0x168f('0x60')]({'where':{'id':_0x4aebbb[_0x168f('0x48')]['id']}})['then'](handleEntityNotFound(_0x5c2d2d,null))[_0x168f('0x29')](function(_0x4d65a9){if(_0x4d65a9){_0x15f6cd=_0x4d65a9;_0xf6c86a[_0x168f('0x36')]=_[_0x168f('0x38')](db[_0x168f('0x5a')][_0x168f('0x49')]);_0xf6c86a[_0x168f('0x37')]=_[_0x168f('0x38')](_0x4aebbb[_0x168f('0x37')]);_0xf6c86a['filters']=_[_0x168f('0x3a')](_0xf6c86a['model'],_0xf6c86a[_0x168f('0x37')]);_0x56a621[_0x168f('0x3c')]=_['intersection'](_0xf6c86a['model'],qs['fields'](_0x4aebbb['query'][_0x168f('0x3b')]));_0x56a621[_0x168f('0x3c')]=_0x56a621[_0x168f('0x3c')][_0x168f('0x3d')]?_0x56a621['attributes']:_0xf6c86a[_0x168f('0x36')];_0x56a621['order']=qs[_0x168f('0x3f')](_0x4aebbb[_0x168f('0x37')][_0x168f('0x3f')]);_0x56a621[_0x168f('0x40')]=qs[_0x168f('0x39')](_[_0x168f('0x62')](_0x4aebbb['query'],_0xf6c86a[_0x168f('0x39')]));if(_0x4aebbb['query'][_0x168f('0x44')]){_0x56a621['where']=_[_0x168f('0x41')](_0x56a621[_0x168f('0x40')],{'$or':_[_0x168f('0x42')](_0x56a621[_0x168f('0x3c')],function(_0x11a7f6){var _0x1095ba={};_0x1095ba[_0x11a7f6]={'$like':'%'+_0x4aebbb[_0x168f('0x37')][_0x168f('0x44')]+'%'};return _0x1095ba;})});}_0x56a621=_[_0x168f('0x41')]({},_0x56a621,_0x4aebbb['options']);return _0x15f6cd[_0x168f('0x86')](_0x56a621);}})[_0x168f('0x29')](function(_0x3debb3){if(_0x3debb3){_0xaf471=_0x3debb3[_0x168f('0x3d')];if(!_0x4aebbb[_0x168f('0x37')][_0x168f('0x58')](_0x168f('0x87'))){_0x56a621[_0x168f('0x23')]=qs[_0x168f('0x23')](_0x4aebbb[_0x168f('0x37')]['limit']);_0x56a621[_0x168f('0x20')]=qs[_0x168f('0x20')](_0x4aebbb[_0x168f('0x37')][_0x168f('0x20')]);}return _0x15f6cd['getAgents'](_0x56a621);}})['then'](function(_0x3f43e9){if(_0x3f43e9){return _0x3f43e9?{'count':_0xaf471,'rows':_0x3f43e9}:null;}})[_0x168f('0x29')](respondWithResult(_0x5c2d2d,null))['catch'](handleError(_0x5c2d2d,null));};