Built motion from commit (unavailable).|2.5.21
[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 _0x315f=['then','error','stack','name','send','map','MailQueue','type','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','findAll','catch','params','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','getMembers','findOne','UserMailQueue','rawAttributes','MailQueueId','User','agent','mailPause','rows','format','%s/%s','SIP','createdAt','updatedAt','getTeams','Team','hasOwnProperty','ids','Agents','online','voicePause','flatMap','sequelize','transaction','each','findOrCreate','emit','userMailQueue:save','select','field','tq.TeamId','from','team_has_mail_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','MailQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','compact','value','isEmpty','removeAgents','forEach','userMailQueue:remove','addAgents','omit','isArray','getAgents','html-pdf','rimraf','request-promise','path','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./mailQueue.socket','register','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','get','MailQueues','destroy'];(function(_0x4c8484,_0x38abb7){var _0x16377d=function(_0x443e2b){while(--_0x443e2b){_0x4c8484['push'](_0x4c8484['shift']());}};_0x16377d(++_0x38abb7);}(_0x315f,0x174));var _0xf315=function(_0x483ab9,_0x419148){_0x483ab9=_0x483ab9-0x0;var _0x35043b=_0x315f[_0x483ab9];return _0x35043b;};'use strict';var pdf=require(_0xf315('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xf315('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xf315('0x2'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require('util');var path=require(_0xf315('0x3'));var sox=require('sox');var csv=require(_0xf315('0x4'));var ejs=require(_0xf315('0x5'));var fs=require('fs');var _=require(_0xf315('0x6'));var squel=require(_0xf315('0x7'));var crypto=require(_0xf315('0x8'));var jsforce=require(_0xf315('0x9'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xf315('0xa'));var Papa=require('papaparse');var Redis=require(_0xf315('0xb'));var authService=require(_0xf315('0xc'));var qs=require(_0xf315('0xd'));var as=require(_0xf315('0xe'));var hardwareService=require(_0xf315('0xf'));var logger=require('../../config/logger')('api');var utils=require(_0xf315('0x10'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xf315('0x11'))['db'];config['redis']=_[_0xf315('0x12')](config[_0xf315('0x13')],{'host':_0xf315('0x14'),'port':0x18eb});var socket=require(_0xf315('0x15'))(new Redis(config['redis']));require(_0xf315('0x16'))[_0xf315('0x17')](socket);function respondWithStatusCode(_0x56deea,_0x19bb1a){_0x19bb1a=_0x19bb1a||0xcc;return function(_0x5cbe32){if(_0x5cbe32){return _0x56deea[_0xf315('0x18')](_0x19bb1a);}return _0x56deea[_0xf315('0x19')](_0x19bb1a)[_0xf315('0x1a')]();};}function respondWithResult(_0x22c049,_0x45fc6d){_0x45fc6d=_0x45fc6d||0xc8;return function(_0x3c2e05){if(_0x3c2e05){return _0x22c049[_0xf315('0x19')](_0x45fc6d)[_0xf315('0x1b')](_0x3c2e05);}};}function respondWithFilteredResult(_0x3d0630,_0x294933){return function(_0x3cc17b){if(_0x3cc17b){var _0x252d9c=_0x3cc17b[_0xf315('0x1c')],_0x24ae41=_0x294933[_0xf315('0x1d')],_0xb5fcb6=_0x294933[_0xf315('0x1d')]+_0x294933[_0xf315('0x1e')],_0x59bd76;if(_0xb5fcb6>=_0x252d9c){_0xb5fcb6=_0x252d9c;_0x59bd76=0xc8;}else{_0x59bd76=0xce;}_0x3d0630[_0xf315('0x19')](_0x59bd76);return _0x3d0630[_0xf315('0x1f')](_0xf315('0x20'),_0x24ae41+'-'+_0xb5fcb6+'/'+_0x252d9c)[_0xf315('0x1b')](_0x3cc17b);}return null;};}function patchUpdates(_0x558377){return function(_0x3a4f4c){try{jsonpatch[_0xf315('0x21')](_0x3a4f4c,_0x558377,!![]);}catch(_0x9159ca){return BPromise[_0xf315('0x22')](_0x9159ca);}return _0x3a4f4c[_0xf315('0x23')]();};}function saveUpdates(_0x56f6e3,_0x120158){return function(_0x5d1ac5){if(_0x5d1ac5){return _0x5d1ac5['update'](_0x56f6e3)['then'](function(_0x25d707){return _0x25d707;});}return null;};}function removeEntity(_0x219bf2,_0x14021d){return function(_0x3dd922){if(_0x3dd922){return _0x3dd922['destroy']()['then'](function(){var _0x6d0615=_0x3dd922[_0xf315('0x24')]({'plain':!![]});var _0x4b730d=_0xf315('0x25');return db['UserProfileResource'][_0xf315('0x26')]({'where':{'type':_0x4b730d,'resourceId':_0x6d0615['id']}})['then'](function(){return _0x3dd922;});})[_0xf315('0x27')](function(){_0x219bf2[_0xf315('0x19')](0xcc)[_0xf315('0x1a')]();});}};}function handleEntityNotFound(_0x22f7b8,_0x42d78d){return function(_0x478cca){if(!_0x478cca){_0x22f7b8['sendStatus'](0x194);}return _0x478cca;};}function handleError(_0x456325,_0x2072db){_0x2072db=_0x2072db||0x1f4;return function(_0x8866ef){logger[_0xf315('0x28')](_0x8866ef[_0xf315('0x29')]);if(_0x8866ef[_0xf315('0x2a')]){delete _0x8866ef[_0xf315('0x2a')];}_0x456325[_0xf315('0x19')](_0x2072db)[_0xf315('0x2b')](_0x8866ef);};}exports['index']=function(_0x373c9e,_0x42ffd3){var _0x41bfdc={},_0x2c21cd={},_0x3b3ef4={'count':0x0,'rows':[]};var _0xe971ba=_[_0xf315('0x2c')](db[_0xf315('0x2d')]['rawAttributes'],function(_0x2f0a1b){return{'name':_0x2f0a1b['fieldName'],'type':_0x2f0a1b[_0xf315('0x2e')][_0xf315('0x2f')]};});_0x2c21cd[_0xf315('0x30')]=_[_0xf315('0x2c')](_0xe971ba,_0xf315('0x2a'));_0x2c21cd[_0xf315('0x31')]=_[_0xf315('0x32')](_0x373c9e['query']);_0x2c21cd[_0xf315('0x33')]=_[_0xf315('0x34')](_0x2c21cd[_0xf315('0x30')],_0x2c21cd['query']);_0x41bfdc[_0xf315('0x35')]=_[_0xf315('0x34')](_0x2c21cd[_0xf315('0x30')],qs[_0xf315('0x36')](_0x373c9e[_0xf315('0x31')][_0xf315('0x36')]));_0x41bfdc['attributes']=_0x41bfdc['attributes'][_0xf315('0x37')]?_0x41bfdc['attributes']:_0x2c21cd[_0xf315('0x30')];if(!_0x373c9e['query']['hasOwnProperty'](_0xf315('0x38'))){_0x41bfdc['limit']=qs[_0xf315('0x1e')](_0x373c9e[_0xf315('0x31')][_0xf315('0x1e')]);_0x41bfdc[_0xf315('0x1d')]=qs[_0xf315('0x1d')](_0x373c9e[_0xf315('0x31')]['offset']);}_0x41bfdc[_0xf315('0x39')]=qs[_0xf315('0x3a')](_0x373c9e[_0xf315('0x31')][_0xf315('0x3a')]);_0x41bfdc[_0xf315('0x3b')]=qs[_0xf315('0x33')](_[_0xf315('0x3c')](_0x373c9e[_0xf315('0x31')],_0x2c21cd['filters']),_0xe971ba);if(_0x373c9e[_0xf315('0x31')][_0xf315('0x3d')]){_0x41bfdc['where']=_[_0xf315('0x3e')](_0x41bfdc[_0xf315('0x3b')],{'$or':_[_0xf315('0x2c')](_0xe971ba,function(_0x36181f){if(_0x36181f[_0xf315('0x2e')]!=='VIRTUAL'){var _0x5cbca0={};_0x5cbca0[_0x36181f[_0xf315('0x2a')]]={'$like':'%'+_0x373c9e[_0xf315('0x31')][_0xf315('0x3d')]+'%'};return _0x5cbca0;}})});}_0x41bfdc=_[_0xf315('0x3e')]({},_0x41bfdc,_0x373c9e[_0xf315('0x3f')]);var _0x580632={'where':_0x41bfdc[_0xf315('0x3b')]};return db[_0xf315('0x2d')][_0xf315('0x1c')](_0x580632)['then'](function(_0xc01924){_0x3b3ef4[_0xf315('0x1c')]=_0xc01924;if(_0x373c9e[_0xf315('0x31')][_0xf315('0x40')]){_0x41bfdc[_0xf315('0x41')]=[{'all':!![]}];}return db['MailQueue'][_0xf315('0x42')](_0x41bfdc);})[_0xf315('0x27')](function(_0x4f04c7){_0x3b3ef4['rows']=_0x4f04c7;return _0x3b3ef4;})[_0xf315('0x27')](respondWithFilteredResult(_0x42ffd3,_0x41bfdc))[_0xf315('0x43')](handleError(_0x42ffd3,null));};exports['show']=function(_0xf865dd,_0x417b8c){var _0x370382={'raw':!![],'where':{'id':_0xf865dd[_0xf315('0x44')]['id']}},_0x5a0c43={};_0x5a0c43[_0xf315('0x30')]=_[_0xf315('0x32')](db[_0xf315('0x2d')]['rawAttributes']);_0x5a0c43[_0xf315('0x31')]=_[_0xf315('0x32')](_0xf865dd['query']);_0x5a0c43['filters']=_[_0xf315('0x34')](_0x5a0c43[_0xf315('0x30')],_0x5a0c43['query']);_0x370382[_0xf315('0x35')]=_[_0xf315('0x34')](_0x5a0c43['model'],qs[_0xf315('0x36')](_0xf865dd['query']['fields']));_0x370382[_0xf315('0x35')]=_0x370382['attributes'][_0xf315('0x37')]?_0x370382[_0xf315('0x35')]:_0x5a0c43[_0xf315('0x30')];if(_0xf865dd[_0xf315('0x31')]['includeAll']){_0x370382[_0xf315('0x41')]=[{'all':!![]}];}_0x370382=_[_0xf315('0x3e')]({},_0x370382,_0xf865dd[_0xf315('0x3f')]);return db[_0xf315('0x2d')][_0xf315('0x45')](_0x370382)['then'](handleEntityNotFound(_0x417b8c,null))[_0xf315('0x27')](respondWithResult(_0x417b8c,null))['catch'](handleError(_0x417b8c,null));};exports[_0xf315('0x46')]=function(_0x5e7335,_0x59f371){return db[_0xf315('0x2d')]['create'](_0x5e7335[_0xf315('0x47')],{})[_0xf315('0x27')](function(_0x281de8){var _0x9df4ee=_0x5e7335[_0xf315('0x48')][_0xf315('0x24')]({'plain':!![]});if(!_0x9df4ee)throw new Error(_0xf315('0x49'));if(_0x9df4ee[_0xf315('0x4a')]===_0xf315('0x48')){var _0x2e469f=_0x281de8[_0xf315('0x24')]({'plain':!![]});var _0x153fea=_0xf315('0x25');return db[_0xf315('0x4b')][_0xf315('0x45')]({'where':{'name':_0x153fea,'userProfileId':_0x9df4ee['userProfileId']},'raw':!![]})['then'](function(_0x2ea72d){if(_0x2ea72d&&_0x2ea72d[_0xf315('0x4c')]===0x0){return db[_0xf315('0x4d')][_0xf315('0x46')]({'name':_0x2e469f['name'],'resourceId':_0x2e469f['id'],'type':_0x2ea72d[_0xf315('0x2a')],'sectionId':_0x2ea72d['id']},{})[_0xf315('0x27')](function(){return _0x281de8;});}else{return _0x281de8;}})[_0xf315('0x43')](function(_0x2bc208){logger['error'](_0xf315('0x4e'),_0x2bc208);throw _0x2bc208;});}return _0x281de8;})[_0xf315('0x27')](respondWithResult(_0x59f371,0xc9))[_0xf315('0x43')](handleError(_0x59f371,null));};exports[_0xf315('0x4f')]=function(_0x53f603,_0xb6ef08){if(_0x53f603[_0xf315('0x47')]['id']){delete _0x53f603[_0xf315('0x47')]['id'];}return db[_0xf315('0x2d')][_0xf315('0x45')]({'where':{'id':_0x53f603[_0xf315('0x44')]['id']}})[_0xf315('0x27')](handleEntityNotFound(_0xb6ef08,null))[_0xf315('0x27')](saveUpdates(_0x53f603[_0xf315('0x47')],null))[_0xf315('0x27')](respondWithResult(_0xb6ef08,null))[_0xf315('0x43')](handleError(_0xb6ef08,null));};exports[_0xf315('0x26')]=function(_0x536154,_0x477c0b){return db[_0xf315('0x2d')][_0xf315('0x45')]({'where':{'id':_0x536154[_0xf315('0x44')]['id']}})[_0xf315('0x27')](handleEntityNotFound(_0x477c0b,null))[_0xf315('0x27')](removeEntity(_0x477c0b,null))[_0xf315('0x43')](handleError(_0x477c0b,null));};exports[_0xf315('0x50')]=function(_0x5ecb47,_0x86a957){return db[_0xf315('0x2d')][_0xf315('0x50')]()['then'](respondWithResult(_0x86a957,null))['catch'](handleError(_0x86a957,null));};exports[_0xf315('0x51')]=function(_0xd1597,_0x43fb3a,_0x29033e){var _0x4d7ab3={'raw':!![],'where':{}},_0x986700={},_0x13981b;return db['MailQueue'][_0xf315('0x52')]({'where':{'id':_0xd1597[_0xf315('0x44')]['id']}})['then'](handleEntityNotFound(_0x43fb3a,null))[_0xf315('0x27')](function(_0x112ac7){if(_0x112ac7){_0x13981b=_0x112ac7[_0xf315('0x24')]({'plain':!![]});_0x986700[_0xf315('0x30')]=_[_0xf315('0x32')](db[_0xf315('0x53')][_0xf315('0x54')]);_0x986700[_0xf315('0x31')]=_['keys'](_0xd1597[_0xf315('0x31')]);_0x986700[_0xf315('0x33')]=_[_0xf315('0x34')](_0x986700[_0xf315('0x30')],_0x986700['query']);_0x4d7ab3[_0xf315('0x35')]=_[_0xf315('0x34')](_0x986700[_0xf315('0x30')],qs[_0xf315('0x36')](_0xd1597[_0xf315('0x31')][_0xf315('0x36')]));_0x4d7ab3[_0xf315('0x35')]=_0x4d7ab3[_0xf315('0x35')]['length']?_0x4d7ab3[_0xf315('0x35')]:_0x986700[_0xf315('0x30')];if(!_0xd1597[_0xf315('0x31')]['hasOwnProperty'](_0xf315('0x38'))){_0x4d7ab3[_0xf315('0x1e')]=qs[_0xf315('0x1e')](_0xd1597[_0xf315('0x31')]['limit']);_0x4d7ab3[_0xf315('0x1d')]=qs[_0xf315('0x1d')](_0xd1597[_0xf315('0x31')][_0xf315('0x1d')]);}_0x4d7ab3[_0xf315('0x39')]=qs[_0xf315('0x3a')](_0xd1597[_0xf315('0x31')][_0xf315('0x3a')]);_0x4d7ab3[_0xf315('0x3b')]=qs['filters'](_['pick'](_0xd1597[_0xf315('0x31')],_0x986700[_0xf315('0x33')]));_0x4d7ab3['where'][_0xf315('0x55')]=_0x112ac7['id'];if(_0xd1597[_0xf315('0x31')][_0xf315('0x3d')]){_0x4d7ab3[_0xf315('0x3b')]=_[_0xf315('0x3e')](_0x4d7ab3['where'],{'$or':_[_0xf315('0x2c')](_0x4d7ab3[_0xf315('0x35')],function(_0x4e8012){var _0x7875f8={};_0x7875f8[_0x4e8012]={'$like':'%'+_0xd1597[_0xf315('0x31')]['filter']+'%'};return _0x7875f8;})});}_0x4d7ab3=_[_0xf315('0x3e')]({},_0x4d7ab3,_0xd1597[_0xf315('0x3f')]);return db[_0xf315('0x53')]['findAll'](_0x4d7ab3);}})[_0xf315('0x27')](function(_0x32f2ff){if(_0x32f2ff){return db[_0xf315('0x56')]['findAndCountAll']({'where':{'id':_[_0xf315('0x2c')](_0x32f2ff,'UserId'),'role':_0xf315('0x57')},'attributes':['id',_0xf315('0x2a'),_0xf315('0x58'),'updatedAt','createdAt']});}})['then'](function(_0x22c8f6){if(_0x22c8f6){return{'count':_0x22c8f6[_0xf315('0x1c')],'rows':_['map'](_0x22c8f6[_0xf315('0x59')],function(_0x21813e){return{'membername':_0x21813e['name'],'UserId':_0x21813e['id'],'queue_name':_0x13981b[_0xf315('0x2a')],'MailQueueId':_0x13981b['id'],'interface':util[_0xf315('0x5a')](_0xf315('0x5b'),_0xf315('0x5c'),_0x21813e[_0xf315('0x2a')]),'penalty':0x0,'paused':_0x21813e[_0xf315('0x58')],'createdAt':_0x21813e[_0xf315('0x5d')],'updatedAt':_0x21813e[_0xf315('0x5e')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xf315('0x27')](respondWithFilteredResult(_0x43fb3a,_0x4d7ab3))[_0xf315('0x43')](handleError(_0x43fb3a,null));};exports[_0xf315('0x5f')]=function(_0x4d92c2,_0x3069d0,_0x598651){var _0x2d986d={};var _0x390f6b={};var _0x46982a;var _0x108295;return db[_0xf315('0x2d')][_0xf315('0x52')]({'where':{'id':_0x4d92c2[_0xf315('0x44')]['id']}})['then'](handleEntityNotFound(_0x3069d0,null))['then'](function(_0x165f81){if(_0x165f81){_0x46982a=_0x165f81;_0x390f6b[_0xf315('0x30')]=_[_0xf315('0x32')](db[_0xf315('0x60')][_0xf315('0x54')]);_0x390f6b['query']=_[_0xf315('0x32')](_0x4d92c2[_0xf315('0x31')]);_0x390f6b[_0xf315('0x33')]=_['intersection'](_0x390f6b[_0xf315('0x30')],_0x390f6b[_0xf315('0x31')]);_0x2d986d[_0xf315('0x35')]=_['intersection'](_0x390f6b['model'],qs[_0xf315('0x36')](_0x4d92c2[_0xf315('0x31')][_0xf315('0x36')]));_0x2d986d['attributes']=_0x2d986d['attributes'][_0xf315('0x37')]?_0x2d986d['attributes']:_0x390f6b[_0xf315('0x30')];_0x2d986d[_0xf315('0x39')]=qs['sort'](_0x4d92c2[_0xf315('0x31')]['sort']);_0x2d986d[_0xf315('0x3b')]=qs[_0xf315('0x33')](_[_0xf315('0x3c')](_0x4d92c2[_0xf315('0x31')],_0x390f6b[_0xf315('0x33')]));if(_0x4d92c2['query'][_0xf315('0x3d')]){_0x2d986d[_0xf315('0x3b')]=_['merge'](_0x2d986d[_0xf315('0x3b')],{'$or':_[_0xf315('0x2c')](_0x2d986d[_0xf315('0x35')],function(_0x2a1899){var _0x27b636={};_0x27b636[_0x2a1899]={'$like':'%'+_0x4d92c2[_0xf315('0x31')][_0xf315('0x3d')]+'%'};return _0x27b636;})});}_0x2d986d=_[_0xf315('0x3e')]({},_0x2d986d,_0x4d92c2['options']);return _0x46982a[_0xf315('0x5f')](_0x2d986d);}})['then'](function(_0x49514d){if(_0x49514d){_0x108295=_0x49514d[_0xf315('0x37')];if(!_0x4d92c2[_0xf315('0x31')][_0xf315('0x61')](_0xf315('0x38'))){_0x2d986d[_0xf315('0x1e')]=qs[_0xf315('0x1e')](_0x4d92c2['query'][_0xf315('0x1e')]);_0x2d986d[_0xf315('0x1d')]=qs['offset'](_0x4d92c2[_0xf315('0x31')]['offset']);}return _0x46982a[_0xf315('0x5f')](_0x2d986d);}})[_0xf315('0x27')](function(_0x20050b){if(_0x20050b){return _0x20050b?{'count':_0x108295,'rows':_0x20050b}:null;}})[_0xf315('0x27')](respondWithResult(_0x3069d0,null))[_0xf315('0x43')](handleError(_0x3069d0,null));};exports['addTeams']=function(_0x3f1f87,_0x21f777,_0x1e06e1){var _0x26d95e=_0x3f1f87['body'][_0xf315('0x62')];return db[_0xf315('0x60')][_0xf315('0x42')]({'where':{'id':_0x26d95e},'attributes':['id'],'include':[{'model':db[_0xf315('0x56')],'as':_0xf315('0x63'),'attributes':['id','name',_0xf315('0x64'),_0xf315('0x65'),'interface'],'raw':!![]}]})['then'](function(_0x5ba999){if(_0x5ba999){var _0x32d7d9=_[_0xf315('0x66')](_0x5ba999,function(_0xbe3477){var _0x30de71=_0xbe3477[_0xf315('0x24')]({'plain':!![]});return _0x30de71['Agents'];});return db['MailQueue'][_0xf315('0x45')]({'where':{'id':_0x3f1f87[_0xf315('0x44')]['id']}})[_0xf315('0x27')](function(_0x3e04a3){return db[_0xf315('0x67')][_0xf315('0x68')](function(_0x66727a){return _0x3e04a3['addTeams'](_0x26d95e,{'transaction':_0x66727a})[_0xf315('0x27')](function(){return BPromise[_0xf315('0x69')](_0x32d7d9,function(_0x4b6fc0){return db[_0xf315('0x53')][_0xf315('0x6a')]({'where':{'UserId':_0x4b6fc0['id'],'MailQueueId':_0x3f1f87[_0xf315('0x44')]['id']},'transaction':_0x66727a});});})['then'](function(){_0x32d7d9['forEach'](function(_0x2a5bba){socket[_0xf315('0x6b')](_0xf315('0x6c'),{'UserId':_0x2a5bba['id'],'MailQueueId':_0x3e04a3['id']});});});});});}})['then'](respondWithStatusCode(_0x21f777,null))[_0xf315('0x43')](handleError(_0x21f777,null));};exports['removeTeams']=function(_0x4e7191,_0x4ba590,_0x20469a){return db[_0xf315('0x60')][_0xf315('0x42')]({'where':{'id':_0x4e7191['query'][_0xf315('0x62')]},'attributes':['id'],'include':[{'model':db[_0xf315('0x56')],'as':'Agents','attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x4ba590,null))[_0xf315('0x27')](function(_0x4bc266){var _0x510f72=_[_0xf315('0x2c')](_0x4bc266,'id');var _0x2c7550=[];var _0x4ba9d3=[];var _0x1ccbd2=squel[_0xf315('0x6d')]();_0x1ccbd2[_0xf315('0x6e')](_0xf315('0x6f'))[_0xf315('0x70')](_0xf315('0x71'),'tq')[_0xf315('0x72')](_0xf315('0x73'),'ut',_0xf315('0x74'))[_0xf315('0x3b')](_0xf315('0x75'),_0x4e7191[_0xf315('0x44')]['id']);for(var _0x38c42a=0x0;_0x38c42a<_0x4bc266[_0xf315('0x37')];_0x38c42a+=0x1){let _0xae8ede=_0x4bc266[_0x38c42a];for(var _0x51302b=0x0;_0x51302b<_0xae8ede['Agents'][_0xf315('0x37')];_0x51302b+=0x1){let _0x539753=_0xae8ede[_0xf315('0x63')][_0x51302b];var _0x18c9ac=_0x1ccbd2[_0xf315('0x76')]();_0x18c9ac[_0xf315('0x3b')](_0xf315('0x77'),_0x539753['id']);_0x4ba9d3[_0xf315('0x78')](db[_0xf315('0x67')][_0xf315('0x31')](_0x18c9ac[_0xf315('0x79')](),{'type':db[_0xf315('0x67')][_0xf315('0x7a')][_0xf315('0x7b')]})['then'](function(_0x13d801){if(_0x13d801['length']===0x1){return _0x539753['id'];}else{var _0x35f97b=_[_0xf315('0x7c')](_[_0xf315('0x2c')](_0x13d801,_0xf315('0x7d')),function(_0x24bd2c){return _[_0xf315('0x7e')](_0x510f72,_0x24bd2c);});if(_0x35f97b){return _0x539753['id'];}}}));}}return BPromise['all'](_0x4ba9d3)[_0xf315('0x27')](function(_0x4afe86){_0x2c7550=_(_0x2c7550)['union'](_0x4afe86)[_0xf315('0x7f')]()[_0xf315('0x80')]();return db[_0xf315('0x2d')][_0xf315('0x45')]({'where':{'id':_0x4e7191[_0xf315('0x44')]['id']}})[_0xf315('0x27')](function(_0x2ec3b5){return db[_0xf315('0x67')]['transaction'](function(_0x59e661){return _0x2ec3b5['removeTeams'](_0x4e7191[_0xf315('0x31')]['ids'],{'transaction':_0x59e661})[_0xf315('0x27')](function(){if(!_[_0xf315('0x81')](_0x2c7550)){return _0x2ec3b5[_0xf315('0x82')](_0x2c7550,{'transaction':_0x59e661});}})[_0xf315('0x27')](function(){_0x2c7550[_0xf315('0x83')](function(_0x4158b0){socket[_0xf315('0x6b')](_0xf315('0x84'),{'UserId':_0x4158b0,'MailQueueId':_0x2ec3b5['id']});});});});});});})[_0xf315('0x27')](respondWithStatusCode(_0x4ba590,null))[_0xf315('0x43')](handleError(_0x4ba590,null));};exports[_0xf315('0x85')]=function(_0xd7f42c,_0x378908,_0xcfeb1d){return db[_0xf315('0x2d')][_0xf315('0x45')]({'where':{'id':_0xd7f42c[_0xf315('0x44')]['id']}})[_0xf315('0x27')](handleEntityNotFound(_0x378908,null))[_0xf315('0x27')](function(_0x483b06){if(_0x483b06){return _0x483b06['addAgents'](_0xd7f42c[_0xf315('0x47')][_0xf315('0x62')],_[_0xf315('0x86')](_0xd7f42c[_0xf315('0x47')],[_0xf315('0x62'),'id'])||{})['spread'](function(_0x5acc7d){for(var _0x30e5fb=0x0;_0x30e5fb<_0xd7f42c[_0xf315('0x47')]['ids']['length'];_0x30e5fb+=0x1){socket['emit'](_0xf315('0x6c'),{'UserId':_0xd7f42c[_0xf315('0x47')][_0xf315('0x62')][_0x30e5fb],'MailQueueId':_0xd7f42c[_0xf315('0x44')]['id']});}return _0x5acc7d;});}})[_0xf315('0x27')](respondWithResult(_0x378908,null))[_0xf315('0x43')](handleError(_0x378908,null));};exports[_0xf315('0x82')]=function(_0x466451,_0x463f2d,_0x20440b){return db[_0xf315('0x2d')][_0xf315('0x45')]({'where':{'id':_0x466451[_0xf315('0x44')]['id']}})[_0xf315('0x27')](handleEntityNotFound(_0x463f2d,null))[_0xf315('0x27')](function(_0x24a3db){if(_0x24a3db){return _0x24a3db[_0xf315('0x82')](_0x466451['query'][_0xf315('0x62')])[_0xf315('0x27')](function(){if(_[_0xf315('0x87')](_0x466451[_0xf315('0x31')][_0xf315('0x62')])){for(var _0x1f5c95=0x0;_0x1f5c95<_0x466451[_0xf315('0x31')][_0xf315('0x62')][_0xf315('0x37')];_0x1f5c95+=0x1){socket['emit']('userMailQueue:remove',{'UserId':Number(_0x466451['query']['ids'][_0x1f5c95]),'MailQueueId':Number(_0x466451['params']['id'])});}}else{socket[_0xf315('0x6b')]('userMailQueue:remove',{'UserId':Number(_0x466451[_0xf315('0x31')][_0xf315('0x62')]),'MailQueueId':Number(_0x466451[_0xf315('0x44')]['id'])});}});}})[_0xf315('0x27')](respondWithStatusCode(_0x463f2d,null))['catch'](handleError(_0x463f2d,null));};exports['getAgents']=function(_0x513b79,_0x2529c4,_0x2aab22){var _0x2482f1={};var _0x5d54cf={};var _0x49e8ce;var _0x3bc51c;return db[_0xf315('0x2d')][_0xf315('0x52')]({'where':{'id':_0x513b79[_0xf315('0x44')]['id']}})['then'](handleEntityNotFound(_0x2529c4,null))['then'](function(_0x6c1822){if(_0x6c1822){_0x49e8ce=_0x6c1822;_0x5d54cf[_0xf315('0x30')]=_[_0xf315('0x32')](db[_0xf315('0x56')]['rawAttributes']);_0x5d54cf['query']=_[_0xf315('0x32')](_0x513b79['query']);_0x5d54cf[_0xf315('0x33')]=_[_0xf315('0x34')](_0x5d54cf['model'],_0x5d54cf[_0xf315('0x31')]);_0x2482f1[_0xf315('0x35')]=_[_0xf315('0x34')](_0x5d54cf[_0xf315('0x30')],qs[_0xf315('0x36')](_0x513b79[_0xf315('0x31')][_0xf315('0x36')]));_0x2482f1[_0xf315('0x35')]=_0x2482f1[_0xf315('0x35')][_0xf315('0x37')]?_0x2482f1[_0xf315('0x35')]:_0x5d54cf['model'];_0x2482f1['order']=qs[_0xf315('0x3a')](_0x513b79[_0xf315('0x31')][_0xf315('0x3a')]);_0x2482f1[_0xf315('0x3b')]=qs[_0xf315('0x33')](_[_0xf315('0x3c')](_0x513b79[_0xf315('0x31')],_0x5d54cf[_0xf315('0x33')]));if(_0x513b79[_0xf315('0x31')][_0xf315('0x3d')]){_0x2482f1[_0xf315('0x3b')]=_[_0xf315('0x3e')](_0x2482f1[_0xf315('0x3b')],{'$or':_[_0xf315('0x2c')](_0x2482f1[_0xf315('0x35')],function(_0x1f65d2){var _0x13926b={};_0x13926b[_0x1f65d2]={'$like':'%'+_0x513b79[_0xf315('0x31')]['filter']+'%'};return _0x13926b;})});}_0x2482f1=_[_0xf315('0x3e')]({},_0x2482f1,_0x513b79[_0xf315('0x3f')]);return _0x49e8ce[_0xf315('0x88')](_0x2482f1);}})[_0xf315('0x27')](function(_0x2db115){if(_0x2db115){_0x3bc51c=_0x2db115[_0xf315('0x37')];if(!_0x513b79[_0xf315('0x31')]['hasOwnProperty'](_0xf315('0x38'))){_0x2482f1[_0xf315('0x1e')]=qs[_0xf315('0x1e')](_0x513b79[_0xf315('0x31')][_0xf315('0x1e')]);_0x2482f1[_0xf315('0x1d')]=qs['offset'](_0x513b79[_0xf315('0x31')]['offset']);}return _0x49e8ce[_0xf315('0x88')](_0x2482f1);}})[_0xf315('0x27')](function(_0x31a457){if(_0x31a457){return _0x31a457?{'count':_0x3bc51c,'rows':_0x31a457}:null;}})[_0xf315('0x27')](respondWithResult(_0x2529c4,null))['catch'](handleError(_0x2529c4,null));};