Built motion from commit d6d69adf.|2.6.33
[motion2.git] / server / api / whatsappQueue / whatsappQueue.controller.js
index c236456..2d0dc72 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x224f=['omit','spread','removeAgents','isArray','getAgents','sort','util','lodash','squel','ioredis','../../components/parsers/qs','api','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./whatsappQueue.socket','register','sendStatus','status','json','undefined','count','offset','limit','set','Content-Range','then','destroy','get','WhatsappQueues','UserProfileResource','error','name','send','index','map','WhatsappQueue','type','key','include','show','params','model','rawAttributes','filters','intersection','attributes','fields','query','length','merge','options','find','catch','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','getMembers','findOne','keys','UserWhatsappQueue','hasOwnProperty','nolimit','order','pick','where','filter','findAll','User','findAndCountAll','UserId','agent','whatsappPause','updatedAt','createdAt','format','%s/%s','getTeams','Team','addTeams','ids','Agents','online','voicePause','interface','sequelize','each','findOrCreate','emit','userWhatsappQueue:save','removeTeams','select','field','tq.TeamId','from','team_has_whatsapp_queues','join','ut.TeamId\x20=\x20tq.TeamId','WhatsappQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','union','compact','value','transaction','isEmpty','forEach','userWhatsappQueue:remove','addAgents'];(function(_0x26eb18,_0x545bf7){var _0x10e4c5=function(_0x162e2d){while(--_0x162e2d){_0x26eb18['push'](_0x26eb18['shift']());}};_0x10e4c5(++_0x545bf7);}(_0x224f,0x180));var _0xf224=function(_0x5216e0,_0x4f8cb9){_0x5216e0=_0x5216e0-0x0;var _0x5b3f40=_0x224f[_0x5216e0];return _0x5b3f40;};'use strict';var BPromise=require('bluebird');var util=require(_0xf224('0x0'));var _=require(_0xf224('0x1'));var squel=require(_0xf224('0x2'));var Redis=require(_0xf224('0x3'));var qs=require(_0xf224('0x4'));var logger=require('../../config/logger')(_0xf224('0x5'));var config=require(_0xf224('0x6'));var db=require(_0xf224('0x7'))['db'];config['redis']=_[_0xf224('0x8')](config[_0xf224('0x9')],{'host':_0xf224('0xa'),'port':0x18eb});var socket=require(_0xf224('0xb'))(new Redis(config[_0xf224('0x9')]));require(_0xf224('0xc'))[_0xf224('0xd')](socket);function respondWithStatusCode(_0x4bf276,_0x51ee2b){_0x51ee2b=_0x51ee2b||0xcc;return function(_0x2de82a){if(_0x2de82a){return _0x4bf276[_0xf224('0xe')](_0x51ee2b);}return _0x4bf276[_0xf224('0xf')](_0x51ee2b)['end']();};}function respondWithResult(_0xcfab84,_0x237612){_0x237612=_0x237612||0xc8;return function(_0x2761d8){if(_0x2761d8){return _0xcfab84[_0xf224('0xf')](_0x237612)[_0xf224('0x10')](_0x2761d8);}};}function respondWithFilteredResult(_0x356584,_0x2ff069){return function(_0x54ebba){if(_0x54ebba){var _0x646f3a=typeof _0x2ff069['offset']===_0xf224('0x11')&&typeof _0x2ff069['limit']===_0xf224('0x11');var _0x51751f=_0x54ebba[_0xf224('0x12')];var _0xbfd8d3=_0x646f3a?0x0:_0x2ff069[_0xf224('0x13')];var _0x11e8e7=_0x646f3a?_0x54ebba[_0xf224('0x12')]:_0x2ff069[_0xf224('0x13')]+_0x2ff069[_0xf224('0x14')];var _0xe910d7;if(_0x11e8e7>=_0x51751f){_0x11e8e7=_0x51751f;_0xe910d7=0xc8;}else{_0xe910d7=0xce;}_0x356584[_0xf224('0xf')](_0xe910d7);return _0x356584[_0xf224('0x15')](_0xf224('0x16'),_0xbfd8d3+'-'+_0x11e8e7+'/'+_0x51751f)[_0xf224('0x10')](_0x54ebba);}return null;};}function saveUpdates(_0x3dfc1d){return function(_0x5da674){if(_0x5da674){return _0x5da674['update'](_0x3dfc1d)[_0xf224('0x17')](function(_0x588703){return _0x588703;});}return null;};}function removeEntity(_0x365916){return function(_0x4f19be){if(_0x4f19be){return _0x4f19be[_0xf224('0x18')]()[_0xf224('0x17')](function(){var _0x2cb6c5=_0x4f19be[_0xf224('0x19')]({'plain':!![]});var _0x29ccc3=_0xf224('0x1a');return db[_0xf224('0x1b')][_0xf224('0x18')]({'where':{'type':_0x29ccc3,'resourceId':_0x2cb6c5['id']}})['then'](function(){return _0x4f19be;});})[_0xf224('0x17')](function(){_0x365916[_0xf224('0xf')](0xcc)['end']();});}};}function handleEntityNotFound(_0x567327){return function(_0x54afa8){if(!_0x54afa8){_0x567327[_0xf224('0xe')](0x194);}return _0x54afa8;};}function handleError(_0x1303b3,_0x40a3b2){_0x40a3b2=_0x40a3b2||0x1f4;return function(_0x5ea026){logger[_0xf224('0x1c')](_0x5ea026['stack']);if(_0x5ea026[_0xf224('0x1d')]){delete _0x5ea026[_0xf224('0x1d')];}_0x1303b3['status'](_0x40a3b2)[_0xf224('0x1e')](_0x5ea026);};}exports[_0xf224('0x1f')]=function(_0x5b69ea,_0x4c04d6){var _0x48605a={};var _0x186854={'count':0x0,'rows':[]};var _0x427993=_[_0xf224('0x20')](db[_0xf224('0x21')]['rawAttributes'],function(_0x5172b3){return{'name':_0x5172b3['fieldName'],'type':_0x5172b3[_0xf224('0x22')][_0xf224('0x23')]};});_0x48605a=qs['getOptions'](_0x427993,_0x5b69ea);var _0x5ae94a={'where':_0x48605a['where']};return db[_0xf224('0x21')][_0xf224('0x12')](_0x5ae94a)[_0xf224('0x17')](function(_0x3aaca0){_0x186854[_0xf224('0x12')]=_0x3aaca0;_0x48605a[_0xf224('0x24')]=qs['include'](_0x5b69ea['query']);return db['WhatsappQueue']['findAll'](_0x48605a);})[_0xf224('0x17')](function(_0x2ead57){_0x186854['rows']=_0x2ead57;return _0x186854;})[_0xf224('0x17')](respondWithFilteredResult(_0x4c04d6,_0x48605a))['catch'](handleError(_0x4c04d6,null));};exports[_0xf224('0x25')]=function(_0x7f283e,_0x527200){var _0x5078f9={'raw':!![],'where':{'id':_0x7f283e[_0xf224('0x26')]['id']}},_0xbaf0e2={};_0xbaf0e2[_0xf224('0x27')]=_['keys'](db[_0xf224('0x21')][_0xf224('0x28')]);_0xbaf0e2['query']=_['keys'](_0x7f283e['query']);_0xbaf0e2[_0xf224('0x29')]=_[_0xf224('0x2a')](_0xbaf0e2[_0xf224('0x27')],_0xbaf0e2['query']);_0x5078f9[_0xf224('0x2b')]=_[_0xf224('0x2a')](_0xbaf0e2[_0xf224('0x27')],qs[_0xf224('0x2c')](_0x7f283e[_0xf224('0x2d')][_0xf224('0x2c')]));_0x5078f9[_0xf224('0x2b')]=_0x5078f9[_0xf224('0x2b')][_0xf224('0x2e')]?_0x5078f9[_0xf224('0x2b')]:_0xbaf0e2['model'];if(_0x7f283e[_0xf224('0x2d')]['includeAll']){_0x5078f9['include']=[{'all':!![]}];}_0x5078f9=_[_0xf224('0x2f')]({},_0x5078f9,_0x7f283e[_0xf224('0x30')]);return db[_0xf224('0x21')][_0xf224('0x31')](_0x5078f9)[_0xf224('0x17')](handleEntityNotFound(_0x527200,null))['then'](respondWithResult(_0x527200,null))[_0xf224('0x32')](handleError(_0x527200,null));};exports['create']=function(_0x3fdd6d,_0x667e30){return db[_0xf224('0x21')]['create'](_0x3fdd6d[_0xf224('0x33')],{})['then'](function(_0x18d335){var _0x153290=_0x3fdd6d[_0xf224('0x34')][_0xf224('0x19')]({'plain':!![]});if(!_0x153290)throw new Error(_0xf224('0x35'));if(_0x153290[_0xf224('0x36')]==='user'){var _0x3c37d5=_0x18d335[_0xf224('0x19')]({'plain':!![]});var _0x495d99='WhatsappQueues';return db[_0xf224('0x37')]['find']({'where':{'name':_0x495d99,'userProfileId':_0x153290[_0xf224('0x38')]},'raw':!![]})['then'](function(_0xc2ef6e){if(_0xc2ef6e&&_0xc2ef6e['autoAssociation']===0x0){return db['UserProfileResource'][_0xf224('0x39')]({'name':_0x3c37d5[_0xf224('0x1d')],'resourceId':_0x3c37d5['id'],'type':_0xc2ef6e[_0xf224('0x1d')],'sectionId':_0xc2ef6e['id']},{})[_0xf224('0x17')](function(){return _0x18d335;});}else{return _0x18d335;}})[_0xf224('0x32')](function(_0x270f46){logger[_0xf224('0x1c')](_0xf224('0x3a'),_0x270f46);throw _0x270f46;});}return _0x18d335;})['then'](respondWithResult(_0x667e30,0xc9))[_0xf224('0x32')](handleError(_0x667e30,null));};exports[_0xf224('0x3b')]=function(_0x3ba3aa,_0x28bf4e){if(_0x3ba3aa[_0xf224('0x33')]['id']){delete _0x3ba3aa[_0xf224('0x33')]['id'];}return db[_0xf224('0x21')][_0xf224('0x31')]({'where':{'id':_0x3ba3aa[_0xf224('0x26')]['id']}})[_0xf224('0x17')](handleEntityNotFound(_0x28bf4e,null))[_0xf224('0x17')](saveUpdates(_0x3ba3aa[_0xf224('0x33')],null))[_0xf224('0x17')](respondWithResult(_0x28bf4e,null))[_0xf224('0x32')](handleError(_0x28bf4e,null));};exports[_0xf224('0x18')]=function(_0xf24f3,_0x245c19){return db[_0xf224('0x21')][_0xf224('0x31')]({'where':{'id':_0xf24f3['params']['id']}})[_0xf224('0x17')](handleEntityNotFound(_0x245c19,null))[_0xf224('0x17')](removeEntity(_0x245c19,null))[_0xf224('0x32')](handleError(_0x245c19,null));};exports[_0xf224('0x3c')]=function(_0x5203fa,_0x1f0601){return db[_0xf224('0x21')]['describe']()[_0xf224('0x17')](respondWithResult(_0x1f0601,null))[_0xf224('0x32')](handleError(_0x1f0601,null));};exports[_0xf224('0x3d')]=function(_0x275495,_0x3c0f33){var _0x98b4a4={'raw':!![],'where':{}},_0x457fcb={},_0x595e4a;return db[_0xf224('0x21')][_0xf224('0x3e')]({'where':{'id':_0x275495['params']['id']}})[_0xf224('0x17')](handleEntityNotFound(_0x3c0f33,null))['then'](function(_0x239105){if(_0x239105){_0x595e4a=_0x239105[_0xf224('0x19')]({'plain':!![]});_0x457fcb[_0xf224('0x27')]=_[_0xf224('0x3f')](db[_0xf224('0x40')][_0xf224('0x28')]);_0x457fcb[_0xf224('0x2d')]=_[_0xf224('0x3f')](_0x275495['query']);_0x457fcb[_0xf224('0x29')]=_[_0xf224('0x2a')](_0x457fcb[_0xf224('0x27')],_0x457fcb['query']);_0x98b4a4[_0xf224('0x2b')]=_[_0xf224('0x2a')](_0x457fcb[_0xf224('0x27')],qs[_0xf224('0x2c')](_0x275495[_0xf224('0x2d')][_0xf224('0x2c')]));_0x98b4a4[_0xf224('0x2b')]=_0x98b4a4[_0xf224('0x2b')]['length']?_0x98b4a4['attributes']:_0x457fcb[_0xf224('0x27')];if(!_0x275495['query'][_0xf224('0x41')](_0xf224('0x42'))){_0x98b4a4[_0xf224('0x14')]=qs[_0xf224('0x14')](_0x275495[_0xf224('0x2d')][_0xf224('0x14')]);_0x98b4a4['offset']=qs[_0xf224('0x13')](_0x275495['query'][_0xf224('0x13')]);}_0x98b4a4[_0xf224('0x43')]=qs['sort'](_0x275495['query']['sort']);_0x98b4a4['where']=qs[_0xf224('0x29')](_[_0xf224('0x44')](_0x275495['query'],_0x457fcb['filters']));_0x98b4a4[_0xf224('0x45')]['WhatsappQueueId']=_0x239105['id'];if(_0x275495[_0xf224('0x2d')][_0xf224('0x46')]){_0x98b4a4[_0xf224('0x45')]=_[_0xf224('0x2f')](_0x98b4a4[_0xf224('0x45')],{'$or':_[_0xf224('0x20')](_0x98b4a4['attributes'],function(_0x2061e6){var _0xcfcd26={};_0xcfcd26[_0x2061e6]={'$like':'%'+_0x275495[_0xf224('0x2d')][_0xf224('0x46')]+'%'};return _0xcfcd26;})});}_0x98b4a4=_[_0xf224('0x2f')]({},_0x98b4a4,_0x275495['options']);return db[_0xf224('0x40')][_0xf224('0x47')](_0x98b4a4);}})['then'](function(_0x4b863d){if(_0x4b863d){return db[_0xf224('0x48')][_0xf224('0x49')]({'where':{'id':_[_0xf224('0x20')](_0x4b863d,_0xf224('0x4a')),'role':_0xf224('0x4b')},'attributes':['id',_0xf224('0x1d'),_0xf224('0x4c'),_0xf224('0x4d'),_0xf224('0x4e')]});}})['then'](function(_0x7723d1){if(_0x7723d1){return{'count':_0x7723d1[_0xf224('0x12')],'rows':_['map'](_0x7723d1['rows'],function(_0x4b9895){return{'membername':_0x4b9895[_0xf224('0x1d')],'UserId':_0x4b9895['id'],'queue_name':_0x595e4a[_0xf224('0x1d')],'WhatsappQueueId':_0x595e4a['id'],'interface':util[_0xf224('0x4f')](_0xf224('0x50'),'SIP',_0x4b9895[_0xf224('0x1d')]),'penalty':0x0,'paused':_0x4b9895['whatsappPause'],'createdAt':_0x4b9895[_0xf224('0x4e')],'updatedAt':_0x4b9895[_0xf224('0x4d')]};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x3c0f33,_0x98b4a4))[_0xf224('0x32')](handleError(_0x3c0f33,null));};exports[_0xf224('0x51')]=function(_0x1ef165,_0x5d010b){var _0x420cbc={};var _0x15f122={};var _0x47c4de;var _0x19fd1b;return db['WhatsappQueue']['findOne']({'where':{'id':_0x1ef165[_0xf224('0x26')]['id']}})['then'](handleEntityNotFound(_0x5d010b,null))['then'](function(_0x1c4185){if(_0x1c4185){_0x47c4de=_0x1c4185;_0x15f122[_0xf224('0x27')]=_[_0xf224('0x3f')](db[_0xf224('0x52')][_0xf224('0x28')]);_0x15f122['query']=_[_0xf224('0x3f')](_0x1ef165[_0xf224('0x2d')]);_0x15f122['filters']=_['intersection'](_0x15f122[_0xf224('0x27')],_0x15f122['query']);_0x420cbc[_0xf224('0x2b')]=_['intersection'](_0x15f122[_0xf224('0x27')],qs[_0xf224('0x2c')](_0x1ef165[_0xf224('0x2d')][_0xf224('0x2c')]));_0x420cbc['attributes']=_0x420cbc[_0xf224('0x2b')]['length']?_0x420cbc[_0xf224('0x2b')]:_0x15f122[_0xf224('0x27')];_0x420cbc['order']=qs['sort'](_0x1ef165['query']['sort']);_0x420cbc[_0xf224('0x45')]=qs[_0xf224('0x29')](_[_0xf224('0x44')](_0x1ef165[_0xf224('0x2d')],_0x15f122[_0xf224('0x29')]));if(_0x1ef165['query']['filter']){_0x420cbc['where']=_[_0xf224('0x2f')](_0x420cbc[_0xf224('0x45')],{'$or':_[_0xf224('0x20')](_0x420cbc[_0xf224('0x2b')],function(_0x1b198f){var _0x2b7e43={};_0x2b7e43[_0x1b198f]={'$like':'%'+_0x1ef165[_0xf224('0x2d')][_0xf224('0x46')]+'%'};return _0x2b7e43;})});}_0x420cbc=_[_0xf224('0x2f')]({},_0x420cbc,_0x1ef165[_0xf224('0x30')]);return _0x47c4de[_0xf224('0x51')](_0x420cbc);}})['then'](function(_0x2c85be){if(_0x2c85be){_0x19fd1b=_0x2c85be[_0xf224('0x2e')];if(!_0x1ef165[_0xf224('0x2d')][_0xf224('0x41')](_0xf224('0x42'))){_0x420cbc[_0xf224('0x14')]=qs[_0xf224('0x14')](_0x1ef165['query'][_0xf224('0x14')]);_0x420cbc[_0xf224('0x13')]=qs[_0xf224('0x13')](_0x1ef165[_0xf224('0x2d')][_0xf224('0x13')]);}return _0x47c4de[_0xf224('0x51')](_0x420cbc);}})[_0xf224('0x17')](function(_0x2465a8){if(_0x2465a8){return _0x2465a8?{'count':_0x19fd1b,'rows':_0x2465a8}:null;}})[_0xf224('0x17')](respondWithResult(_0x5d010b,null))[_0xf224('0x32')](handleError(_0x5d010b,null));};exports[_0xf224('0x53')]=function(_0x5853d8,_0xe52090){var _0x5248ee=_0x5853d8[_0xf224('0x33')][_0xf224('0x54')];return db[_0xf224('0x52')][_0xf224('0x47')]({'where':{'id':_0x5248ee},'attributes':['id'],'include':[{'model':db[_0xf224('0x48')],'as':_0xf224('0x55'),'attributes':['id','name',_0xf224('0x56'),_0xf224('0x57'),_0xf224('0x58')],'raw':!![]}]})[_0xf224('0x17')](function(_0x1ddbb4){if(_0x1ddbb4){var _0x25b402=_['flatMap'](_0x1ddbb4,function(_0x2bfe15){var _0x347281=_0x2bfe15['get']({'plain':!![]});return _0x347281['Agents'];});return db[_0xf224('0x21')]['find']({'where':{'id':_0x5853d8[_0xf224('0x26')]['id']}})[_0xf224('0x17')](function(_0x508387){return db[_0xf224('0x59')]['transaction'](function(_0x19e0f5){return _0x508387[_0xf224('0x53')](_0x5248ee,{'transaction':_0x19e0f5})[_0xf224('0x17')](function(){return BPromise[_0xf224('0x5a')](_0x25b402,function(_0x4fece1){return db[_0xf224('0x40')][_0xf224('0x5b')]({'where':{'UserId':_0x4fece1['id'],'WhatsappQueueId':_0x5853d8[_0xf224('0x26')]['id']},'transaction':_0x19e0f5});});})[_0xf224('0x17')](function(){_0x25b402['forEach'](function(_0x4106ce){socket[_0xf224('0x5c')](_0xf224('0x5d'),{'UserId':_0x4106ce['id'],'WhatsappQueueId':_0x508387['id']});});});});});}})[_0xf224('0x17')](respondWithStatusCode(_0xe52090,null))['catch'](handleError(_0xe52090,null));};exports[_0xf224('0x5e')]=function(_0x4b31e7,_0x415f8f){return db[_0xf224('0x52')][_0xf224('0x47')]({'where':{'id':_0x4b31e7[_0xf224('0x2d')][_0xf224('0x54')]},'attributes':['id'],'include':[{'model':db[_0xf224('0x48')],'as':_0xf224('0x55'),'attributes':['id'],'raw':!![]}]})[_0xf224('0x17')](handleEntityNotFound(_0x415f8f,null))[_0xf224('0x17')](function(_0x265317){var _0xc8c41a=_[_0xf224('0x20')](_0x265317,'id');var _0x5b7cab=[];var _0x4bed90=[];var _0x223506=squel[_0xf224('0x5f')]();_0x223506[_0xf224('0x60')](_0xf224('0x61'))[_0xf224('0x62')](_0xf224('0x63'),'tq')[_0xf224('0x64')]('user_has_teams','ut',_0xf224('0x65'))[_0xf224('0x45')](_0xf224('0x66'),_0x4b31e7[_0xf224('0x26')]['id']);for(var _0x167bcd=0x0;_0x167bcd<_0x265317[_0xf224('0x2e')];_0x167bcd+=0x1){let _0x3dfd45=_0x265317[_0x167bcd];for(var _0x2ba4ef=0x0;_0x2ba4ef<_0x3dfd45[_0xf224('0x55')][_0xf224('0x2e')];_0x2ba4ef+=0x1){let _0x5aefa5=_0x3dfd45[_0xf224('0x55')][_0x2ba4ef];var _0x1aab21=_0x223506[_0xf224('0x67')]();_0x1aab21['where'](_0xf224('0x68'),_0x5aefa5['id']);_0x4bed90[_0xf224('0x69')](db['sequelize'][_0xf224('0x2d')](_0x1aab21[_0xf224('0x6a')](),{'type':db[_0xf224('0x59')][_0xf224('0x6b')][_0xf224('0x6c')]})[_0xf224('0x17')](function(_0x44c931){if(_0x44c931[_0xf224('0x2e')]===0x1){return _0x5aefa5['id'];}else{var _0x2394a4=_[_0xf224('0x6d')](_[_0xf224('0x20')](_0x44c931,_0xf224('0x6e')),function(_0x296c45){return _[_0xf224('0x6f')](_0xc8c41a,_0x296c45);});if(_0x2394a4){return _0x5aefa5['id'];}}}));}}return BPromise['all'](_0x4bed90)[_0xf224('0x17')](function(_0x1f07d4){_0x5b7cab=_(_0x5b7cab)[_0xf224('0x70')](_0x1f07d4)[_0xf224('0x71')]()[_0xf224('0x72')]();return db[_0xf224('0x21')][_0xf224('0x31')]({'where':{'id':_0x4b31e7[_0xf224('0x26')]['id']}})[_0xf224('0x17')](function(_0x5382d6){return db[_0xf224('0x59')][_0xf224('0x73')](function(_0x1ff74e){return _0x5382d6[_0xf224('0x5e')](_0x4b31e7[_0xf224('0x2d')][_0xf224('0x54')],{'transaction':_0x1ff74e})['then'](function(){if(!_[_0xf224('0x74')](_0x5b7cab)){return _0x5382d6['removeAgents'](_0x5b7cab,{'transaction':_0x1ff74e});}})[_0xf224('0x17')](function(){_0x5b7cab[_0xf224('0x75')](function(_0x3026e7){socket[_0xf224('0x5c')](_0xf224('0x76'),{'UserId':_0x3026e7,'WhatsappQueueId':_0x5382d6['id']});});});});});});})[_0xf224('0x17')](respondWithStatusCode(_0x415f8f,null))['catch'](handleError(_0x415f8f,null));};exports[_0xf224('0x77')]=function(_0x54a3ad,_0x1b512e){return db['WhatsappQueue']['find']({'where':{'id':_0x54a3ad[_0xf224('0x26')]['id']}})[_0xf224('0x17')](handleEntityNotFound(_0x1b512e,null))[_0xf224('0x17')](function(_0x20f8b4){if(_0x20f8b4){return _0x20f8b4[_0xf224('0x77')](_0x54a3ad[_0xf224('0x33')][_0xf224('0x54')],_[_0xf224('0x78')](_0x54a3ad['body'],['ids','id'])||{})[_0xf224('0x79')](function(_0x28854f){for(var _0x35c1f6=0x0;_0x35c1f6<_0x54a3ad[_0xf224('0x33')]['ids'][_0xf224('0x2e')];_0x35c1f6+=0x1){socket[_0xf224('0x5c')](_0xf224('0x5d'),{'UserId':Number(_0x54a3ad['body'][_0xf224('0x54')][_0x35c1f6]),'WhatsappQueueId':Number(_0x54a3ad[_0xf224('0x26')]['id'])});}return _0x28854f;});}})[_0xf224('0x17')](respondWithResult(_0x1b512e,null))[_0xf224('0x32')](handleError(_0x1b512e,null));};exports[_0xf224('0x7a')]=function(_0xe49d8b,_0x5edab7){return db['WhatsappQueue']['find']({'where':{'id':_0xe49d8b[_0xf224('0x26')]['id']}})[_0xf224('0x17')](handleEntityNotFound(_0x5edab7,null))[_0xf224('0x17')](function(_0x4d9693){if(_0x4d9693){return _0x4d9693[_0xf224('0x7a')](_0xe49d8b[_0xf224('0x2d')][_0xf224('0x54')])['then'](function(){if(_[_0xf224('0x7b')](_0xe49d8b['query'][_0xf224('0x54')])){for(var _0x5db567=0x0;_0x5db567<_0xe49d8b['query'][_0xf224('0x54')][_0xf224('0x2e')];_0x5db567+=0x1){socket['emit'](_0xf224('0x76'),{'UserId':Number(_0xe49d8b[_0xf224('0x2d')][_0xf224('0x54')][_0x5db567]),'WhatsappQueueId':Number(_0xe49d8b['params']['id'])});}}else{socket['emit']('userWhatsappQueue:remove',{'UserId':Number(_0xe49d8b[_0xf224('0x2d')][_0xf224('0x54')]),'WhatsappQueueId':Number(_0xe49d8b[_0xf224('0x26')]['id'])});}});}})[_0xf224('0x17')](respondWithStatusCode(_0x5edab7,null))[_0xf224('0x32')](handleError(_0x5edab7,null));};exports[_0xf224('0x7c')]=function(_0x4974bc,_0x2aaf5a){var _0xca3ab0={};var _0x34417d={};var _0xaab838;var _0x78f720;return db[_0xf224('0x21')]['findOne']({'where':{'id':_0x4974bc['params']['id']}})[_0xf224('0x17')](handleEntityNotFound(_0x2aaf5a,null))['then'](function(_0x33ee51){if(_0x33ee51){_0xaab838=_0x33ee51;_0x34417d[_0xf224('0x27')]=_[_0xf224('0x3f')](db['User']['rawAttributes']);_0x34417d[_0xf224('0x2d')]=_[_0xf224('0x3f')](_0x4974bc[_0xf224('0x2d')]);_0x34417d[_0xf224('0x29')]=_[_0xf224('0x2a')](_0x34417d['model'],_0x34417d['query']);_0xca3ab0['attributes']=_[_0xf224('0x2a')](_0x34417d['model'],qs[_0xf224('0x2c')](_0x4974bc[_0xf224('0x2d')][_0xf224('0x2c')]));_0xca3ab0[_0xf224('0x2b')]=_0xca3ab0[_0xf224('0x2b')]['length']?_0xca3ab0[_0xf224('0x2b')]:_0x34417d[_0xf224('0x27')];_0xca3ab0['order']=qs[_0xf224('0x7d')](_0x4974bc[_0xf224('0x2d')][_0xf224('0x7d')]);_0xca3ab0[_0xf224('0x45')]=qs['filters'](_['pick'](_0x4974bc[_0xf224('0x2d')],_0x34417d['filters']));if(_0x4974bc['query']['filter']){_0xca3ab0[_0xf224('0x45')]=_['merge'](_0xca3ab0[_0xf224('0x45')],{'$or':_[_0xf224('0x20')](_0xca3ab0['attributes'],function(_0x8c8d29){var _0x57dedf={};_0x57dedf[_0x8c8d29]={'$like':'%'+_0x4974bc[_0xf224('0x2d')][_0xf224('0x46')]+'%'};return _0x57dedf;})});}_0xca3ab0=_[_0xf224('0x2f')]({},_0xca3ab0,_0x4974bc[_0xf224('0x30')]);return _0xaab838[_0xf224('0x7c')](_0xca3ab0);}})[_0xf224('0x17')](function(_0x4b0b07){if(_0x4b0b07){_0x78f720=_0x4b0b07['length'];if(!_0x4974bc[_0xf224('0x2d')]['hasOwnProperty'](_0xf224('0x42'))){_0xca3ab0[_0xf224('0x14')]=qs[_0xf224('0x14')](_0x4974bc['query'][_0xf224('0x14')]);_0xca3ab0['offset']=qs[_0xf224('0x13')](_0x4974bc[_0xf224('0x2d')]['offset']);}return _0xaab838[_0xf224('0x7c')](_0xca3ab0);}})[_0xf224('0x17')](function(_0x4d20df){if(_0x4d20df){return _0x4d20df?{'count':_0x78f720,'rows':_0x4d20df}:null;}})[_0xf224('0x17')](respondWithResult(_0x2aaf5a,null))[_0xf224('0x32')](handleError(_0x2aaf5a,null));};
\ No newline at end of file
+var _0xad4c=['redis','defaults','socket.io-emitter','register','sendStatus','status','json','offset','limit','set','Content-Range','then','destroy','UserProfileResource','end','error','name','send','index','rawAttributes','fieldName','type','key','getOptions','where','count','include','WhatsappQueue','findAll','show','keys','query','filters','intersection','model','attributes','fields','length','includeAll','merge','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','WhatsappQueues','UserProfileSection','userProfileId','autoAssociation','catch','update','params','describe','getMembers','UserWhatsappQueue','hasOwnProperty','nolimit','order','sort','filter','options','findAndCountAll','map','UserId','agent','updatedAt','createdAt','rows','format','%s/%s','whatsappPause','findOne','Team','pick','getTeams','ids','User','Agents','online','sequelize','transaction','each','findOrCreate','userWhatsappQueue:save','removeTeams','select','tq.TeamId','from','team_has_whatsapp_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','WhatsappQueueId\x20=\x20?','clone','QueryTypes','SELECT','TeamId','all','union','compact','isEmpty','forEach','emit','userWhatsappQueue:remove','addAgents','omit','removeAgents','isArray','getAgents','bluebird','util','lodash','squel','ioredis','../../components/parsers/qs','../../config/logger','api','../../mysqldb'];(function(_0x20494e,_0x274e71){var _0x28f4ae=function(_0x357f33){while(--_0x357f33){_0x20494e['push'](_0x20494e['shift']());}};_0x28f4ae(++_0x274e71);}(_0xad4c,0x15f));var _0xcad4=function(_0x47e8b4,_0x29cb6d){_0x47e8b4=_0x47e8b4-0x0;var _0x87a99f=_0xad4c[_0x47e8b4];return _0x87a99f;};'use strict';var BPromise=require(_0xcad4('0x0'));var util=require(_0xcad4('0x1'));var _=require(_0xcad4('0x2'));var squel=require(_0xcad4('0x3'));var Redis=require(_0xcad4('0x4'));var qs=require(_0xcad4('0x5'));var logger=require(_0xcad4('0x6'))(_0xcad4('0x7'));var config=require('../../config/environment');var db=require(_0xcad4('0x8'))['db'];config[_0xcad4('0x9')]=_[_0xcad4('0xa')](config[_0xcad4('0x9')],{'host':'localhost','port':0x18eb});var socket=require(_0xcad4('0xb'))(new Redis(config[_0xcad4('0x9')]));require('./whatsappQueue.socket')[_0xcad4('0xc')](socket);function respondWithStatusCode(_0x44c319,_0x2e10bd){_0x2e10bd=_0x2e10bd||0xcc;return function(_0x2ae015){if(_0x2ae015){return _0x44c319[_0xcad4('0xd')](_0x2e10bd);}return _0x44c319[_0xcad4('0xe')](_0x2e10bd)['end']();};}function respondWithResult(_0x479c5f,_0x14220e){_0x14220e=_0x14220e||0xc8;return function(_0x231eb2){if(_0x231eb2){return _0x479c5f['status'](_0x14220e)[_0xcad4('0xf')](_0x231eb2);}};}function respondWithFilteredResult(_0x337956,_0x47941b){return function(_0x713edc){if(_0x713edc){var _0x4df6a8=typeof _0x47941b[_0xcad4('0x10')]==='undefined'&&typeof _0x47941b['limit']==='undefined';var _0x31d91a=_0x713edc['count'];var _0xcfa937=_0x4df6a8?0x0:_0x47941b['offset'];var _0x2f4c50=_0x4df6a8?_0x713edc['count']:_0x47941b[_0xcad4('0x10')]+_0x47941b[_0xcad4('0x11')];var _0x5ec4f4;if(_0x2f4c50>=_0x31d91a){_0x2f4c50=_0x31d91a;_0x5ec4f4=0xc8;}else{_0x5ec4f4=0xce;}_0x337956[_0xcad4('0xe')](_0x5ec4f4);return _0x337956[_0xcad4('0x12')](_0xcad4('0x13'),_0xcfa937+'-'+_0x2f4c50+'/'+_0x31d91a)['json'](_0x713edc);}return null;};}function saveUpdates(_0x2116de){return function(_0x50783b){if(_0x50783b){return _0x50783b['update'](_0x2116de)[_0xcad4('0x14')](function(_0x18609d){return _0x18609d;});}return null;};}function removeEntity(_0x4f4f2e){return function(_0xe294ca){if(_0xe294ca){return _0xe294ca[_0xcad4('0x15')]()[_0xcad4('0x14')](function(){var _0x5246e0=_0xe294ca['get']({'plain':!![]});var _0x112c1f='WhatsappQueues';return db[_0xcad4('0x16')][_0xcad4('0x15')]({'where':{'type':_0x112c1f,'resourceId':_0x5246e0['id']}})['then'](function(){return _0xe294ca;});})['then'](function(){_0x4f4f2e[_0xcad4('0xe')](0xcc)[_0xcad4('0x17')]();});}};}function handleEntityNotFound(_0x1d6cda){return function(_0x39b455){if(!_0x39b455){_0x1d6cda[_0xcad4('0xd')](0x194);}return _0x39b455;};}function handleError(_0x126e74,_0x388c93){_0x388c93=_0x388c93||0x1f4;return function(_0xc9c85e){logger[_0xcad4('0x18')](_0xc9c85e['stack']);if(_0xc9c85e[_0xcad4('0x19')]){delete _0xc9c85e['name'];}_0x126e74[_0xcad4('0xe')](_0x388c93)[_0xcad4('0x1a')](_0xc9c85e);};}exports[_0xcad4('0x1b')]=function(_0x11f9bc,_0x3872eb){var _0x2ad512={};var _0x3ed465={'count':0x0,'rows':[]};var _0x39a3a0=_['map'](db['WhatsappQueue'][_0xcad4('0x1c')],function(_0x50653e){return{'name':_0x50653e[_0xcad4('0x1d')],'type':_0x50653e[_0xcad4('0x1e')][_0xcad4('0x1f')]};});_0x2ad512=qs[_0xcad4('0x20')](_0x39a3a0,_0x11f9bc);var _0x45bc47={'where':_0x2ad512[_0xcad4('0x21')]};return db['WhatsappQueue'][_0xcad4('0x22')](_0x45bc47)[_0xcad4('0x14')](function(_0x5a0eef){_0x3ed465[_0xcad4('0x22')]=_0x5a0eef;_0x2ad512[_0xcad4('0x23')]=qs[_0xcad4('0x23')](_0x11f9bc['query']);return db[_0xcad4('0x24')][_0xcad4('0x25')](_0x2ad512);})[_0xcad4('0x14')](function(_0xf54775){_0x3ed465['rows']=_0xf54775;return _0x3ed465;})[_0xcad4('0x14')](respondWithFilteredResult(_0x3872eb,_0x2ad512))['catch'](handleError(_0x3872eb,null));};exports[_0xcad4('0x26')]=function(_0x16767c,_0x5ac4e0){var _0x13d4a3={'raw':!![],'where':{'id':_0x16767c['params']['id']}},_0x7c0e6e={};_0x7c0e6e['model']=_[_0xcad4('0x27')](db['WhatsappQueue'][_0xcad4('0x1c')]);_0x7c0e6e[_0xcad4('0x28')]=_[_0xcad4('0x27')](_0x16767c[_0xcad4('0x28')]);_0x7c0e6e[_0xcad4('0x29')]=_[_0xcad4('0x2a')](_0x7c0e6e[_0xcad4('0x2b')],_0x7c0e6e[_0xcad4('0x28')]);_0x13d4a3[_0xcad4('0x2c')]=_[_0xcad4('0x2a')](_0x7c0e6e[_0xcad4('0x2b')],qs['fields'](_0x16767c['query'][_0xcad4('0x2d')]));_0x13d4a3[_0xcad4('0x2c')]=_0x13d4a3[_0xcad4('0x2c')][_0xcad4('0x2e')]?_0x13d4a3[_0xcad4('0x2c')]:_0x7c0e6e[_0xcad4('0x2b')];if(_0x16767c[_0xcad4('0x28')][_0xcad4('0x2f')]){_0x13d4a3[_0xcad4('0x23')]=[{'all':!![]}];}_0x13d4a3=_[_0xcad4('0x30')]({},_0x13d4a3,_0x16767c['options']);return db[_0xcad4('0x24')][_0xcad4('0x31')](_0x13d4a3)['then'](handleEntityNotFound(_0x5ac4e0,null))[_0xcad4('0x14')](respondWithResult(_0x5ac4e0,null))['catch'](handleError(_0x5ac4e0,null));};exports[_0xcad4('0x32')]=function(_0x21454c,_0x1b063e){return db['WhatsappQueue'][_0xcad4('0x32')](_0x21454c[_0xcad4('0x33')],{})[_0xcad4('0x14')](function(_0x57eacf){var _0x20514d=_0x21454c[_0xcad4('0x34')][_0xcad4('0x35')]({'plain':!![]});if(!_0x20514d)throw new Error(_0xcad4('0x36'));if(_0x20514d[_0xcad4('0x37')]===_0xcad4('0x34')){var _0x1bdb62=_0x57eacf[_0xcad4('0x35')]({'plain':!![]});var _0x1b4db9=_0xcad4('0x38');return db[_0xcad4('0x39')][_0xcad4('0x31')]({'where':{'name':_0x1b4db9,'userProfileId':_0x20514d[_0xcad4('0x3a')]},'raw':!![]})[_0xcad4('0x14')](function(_0x32fefc){if(_0x32fefc&&_0x32fefc[_0xcad4('0x3b')]===0x0){return db[_0xcad4('0x16')]['create']({'name':_0x1bdb62[_0xcad4('0x19')],'resourceId':_0x1bdb62['id'],'type':_0x32fefc[_0xcad4('0x19')],'sectionId':_0x32fefc['id']},{})[_0xcad4('0x14')](function(){return _0x57eacf;});}else{return _0x57eacf;}})[_0xcad4('0x3c')](function(_0x317c01){logger[_0xcad4('0x18')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x317c01);throw _0x317c01;});}return _0x57eacf;})[_0xcad4('0x14')](respondWithResult(_0x1b063e,0xc9))['catch'](handleError(_0x1b063e,null));};exports[_0xcad4('0x3d')]=function(_0x1e6540,_0x293e31){if(_0x1e6540['body']['id']){delete _0x1e6540[_0xcad4('0x33')]['id'];}return db['WhatsappQueue']['find']({'where':{'id':_0x1e6540[_0xcad4('0x3e')]['id']}})[_0xcad4('0x14')](handleEntityNotFound(_0x293e31,null))[_0xcad4('0x14')](saveUpdates(_0x1e6540[_0xcad4('0x33')],null))[_0xcad4('0x14')](respondWithResult(_0x293e31,null))[_0xcad4('0x3c')](handleError(_0x293e31,null));};exports['destroy']=function(_0x5b2978,_0x2015b8){return db[_0xcad4('0x24')][_0xcad4('0x31')]({'where':{'id':_0x5b2978['params']['id']}})[_0xcad4('0x14')](handleEntityNotFound(_0x2015b8,null))['then'](removeEntity(_0x2015b8,null))[_0xcad4('0x3c')](handleError(_0x2015b8,null));};exports[_0xcad4('0x3f')]=function(_0x329ae2,_0xd7616d){return db['WhatsappQueue'][_0xcad4('0x3f')]()[_0xcad4('0x14')](respondWithResult(_0xd7616d,null))[_0xcad4('0x3c')](handleError(_0xd7616d,null));};exports[_0xcad4('0x40')]=function(_0x4f4a1f,_0x51a98d){var _0x18c2d8={'raw':!![],'where':{}},_0x41efc3={},_0x25d9ff;return db[_0xcad4('0x24')]['findOne']({'where':{'id':_0x4f4a1f[_0xcad4('0x3e')]['id']}})['then'](handleEntityNotFound(_0x51a98d,null))[_0xcad4('0x14')](function(_0x5e8759){if(_0x5e8759){_0x25d9ff=_0x5e8759[_0xcad4('0x35')]({'plain':!![]});_0x41efc3[_0xcad4('0x2b')]=_[_0xcad4('0x27')](db[_0xcad4('0x41')]['rawAttributes']);_0x41efc3[_0xcad4('0x28')]=_['keys'](_0x4f4a1f['query']);_0x41efc3[_0xcad4('0x29')]=_[_0xcad4('0x2a')](_0x41efc3[_0xcad4('0x2b')],_0x41efc3[_0xcad4('0x28')]);_0x18c2d8[_0xcad4('0x2c')]=_[_0xcad4('0x2a')](_0x41efc3[_0xcad4('0x2b')],qs[_0xcad4('0x2d')](_0x4f4a1f[_0xcad4('0x28')]['fields']));_0x18c2d8[_0xcad4('0x2c')]=_0x18c2d8['attributes'][_0xcad4('0x2e')]?_0x18c2d8[_0xcad4('0x2c')]:_0x41efc3['model'];if(!_0x4f4a1f[_0xcad4('0x28')][_0xcad4('0x42')](_0xcad4('0x43'))){_0x18c2d8[_0xcad4('0x11')]=qs['limit'](_0x4f4a1f[_0xcad4('0x28')][_0xcad4('0x11')]);_0x18c2d8[_0xcad4('0x10')]=qs[_0xcad4('0x10')](_0x4f4a1f[_0xcad4('0x28')][_0xcad4('0x10')]);}_0x18c2d8[_0xcad4('0x44')]=qs[_0xcad4('0x45')](_0x4f4a1f[_0xcad4('0x28')][_0xcad4('0x45')]);_0x18c2d8[_0xcad4('0x21')]=qs[_0xcad4('0x29')](_['pick'](_0x4f4a1f[_0xcad4('0x28')],_0x41efc3[_0xcad4('0x29')]));_0x18c2d8[_0xcad4('0x21')]['WhatsappQueueId']=_0x5e8759['id'];if(_0x4f4a1f[_0xcad4('0x28')][_0xcad4('0x46')]){_0x18c2d8['where']=_[_0xcad4('0x30')](_0x18c2d8[_0xcad4('0x21')],{'$or':_['map'](_0x18c2d8[_0xcad4('0x2c')],function(_0x4ee33f){var _0x2e98db={};_0x2e98db[_0x4ee33f]={'$like':'%'+_0x4f4a1f[_0xcad4('0x28')][_0xcad4('0x46')]+'%'};return _0x2e98db;})});}_0x18c2d8=_[_0xcad4('0x30')]({},_0x18c2d8,_0x4f4a1f[_0xcad4('0x47')]);return db[_0xcad4('0x41')][_0xcad4('0x25')](_0x18c2d8);}})[_0xcad4('0x14')](function(_0x4c07cd){if(_0x4c07cd){return db['User'][_0xcad4('0x48')]({'where':{'id':_[_0xcad4('0x49')](_0x4c07cd,_0xcad4('0x4a')),'role':_0xcad4('0x4b')},'attributes':['id','name','whatsappPause',_0xcad4('0x4c'),_0xcad4('0x4d')]});}})[_0xcad4('0x14')](function(_0x1fc244){if(_0x1fc244){return{'count':_0x1fc244['count'],'rows':_[_0xcad4('0x49')](_0x1fc244[_0xcad4('0x4e')],function(_0xb5dd50){return{'membername':_0xb5dd50[_0xcad4('0x19')],'UserId':_0xb5dd50['id'],'queue_name':_0x25d9ff[_0xcad4('0x19')],'WhatsappQueueId':_0x25d9ff['id'],'interface':util[_0xcad4('0x4f')](_0xcad4('0x50'),'SIP',_0xb5dd50['name']),'penalty':0x0,'paused':_0xb5dd50[_0xcad4('0x51')],'createdAt':_0xb5dd50['createdAt'],'updatedAt':_0xb5dd50[_0xcad4('0x4c')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xcad4('0x14')](respondWithFilteredResult(_0x51a98d,_0x18c2d8))['catch'](handleError(_0x51a98d,null));};exports['getTeams']=function(_0x11c884,_0x371345){var _0x3e7b9d={};var _0x5e79cf={};var _0x2345d9;var _0x2d9e91;return db[_0xcad4('0x24')][_0xcad4('0x52')]({'where':{'id':_0x11c884['params']['id']}})['then'](handleEntityNotFound(_0x371345,null))['then'](function(_0x53a2bd){if(_0x53a2bd){_0x2345d9=_0x53a2bd;_0x5e79cf[_0xcad4('0x2b')]=_[_0xcad4('0x27')](db[_0xcad4('0x53')][_0xcad4('0x1c')]);_0x5e79cf[_0xcad4('0x28')]=_['keys'](_0x11c884[_0xcad4('0x28')]);_0x5e79cf['filters']=_[_0xcad4('0x2a')](_0x5e79cf[_0xcad4('0x2b')],_0x5e79cf['query']);_0x3e7b9d[_0xcad4('0x2c')]=_[_0xcad4('0x2a')](_0x5e79cf[_0xcad4('0x2b')],qs[_0xcad4('0x2d')](_0x11c884['query'][_0xcad4('0x2d')]));_0x3e7b9d['attributes']=_0x3e7b9d[_0xcad4('0x2c')]['length']?_0x3e7b9d[_0xcad4('0x2c')]:_0x5e79cf[_0xcad4('0x2b')];_0x3e7b9d['order']=qs[_0xcad4('0x45')](_0x11c884[_0xcad4('0x28')][_0xcad4('0x45')]);_0x3e7b9d[_0xcad4('0x21')]=qs[_0xcad4('0x29')](_[_0xcad4('0x54')](_0x11c884[_0xcad4('0x28')],_0x5e79cf[_0xcad4('0x29')]));if(_0x11c884[_0xcad4('0x28')][_0xcad4('0x46')]){_0x3e7b9d[_0xcad4('0x21')]=_[_0xcad4('0x30')](_0x3e7b9d[_0xcad4('0x21')],{'$or':_[_0xcad4('0x49')](_0x3e7b9d[_0xcad4('0x2c')],function(_0x567b36){var _0x243183={};_0x243183[_0x567b36]={'$like':'%'+_0x11c884[_0xcad4('0x28')][_0xcad4('0x46')]+'%'};return _0x243183;})});}_0x3e7b9d=_[_0xcad4('0x30')]({},_0x3e7b9d,_0x11c884['options']);return _0x2345d9[_0xcad4('0x55')](_0x3e7b9d);}})[_0xcad4('0x14')](function(_0x56e69d){if(_0x56e69d){_0x2d9e91=_0x56e69d[_0xcad4('0x2e')];if(!_0x11c884[_0xcad4('0x28')][_0xcad4('0x42')]('nolimit')){_0x3e7b9d[_0xcad4('0x11')]=qs['limit'](_0x11c884[_0xcad4('0x28')]['limit']);_0x3e7b9d[_0xcad4('0x10')]=qs[_0xcad4('0x10')](_0x11c884[_0xcad4('0x28')]['offset']);}return _0x2345d9[_0xcad4('0x55')](_0x3e7b9d);}})[_0xcad4('0x14')](function(_0x5912a9){if(_0x5912a9){return _0x5912a9?{'count':_0x2d9e91,'rows':_0x5912a9}:null;}})[_0xcad4('0x14')](respondWithResult(_0x371345,null))[_0xcad4('0x3c')](handleError(_0x371345,null));};exports['addTeams']=function(_0x47828f,_0x11d47f){var _0x344cd6=_0x47828f[_0xcad4('0x33')][_0xcad4('0x56')];return db[_0xcad4('0x53')][_0xcad4('0x25')]({'where':{'id':_0x344cd6},'attributes':['id'],'include':[{'model':db[_0xcad4('0x57')],'as':_0xcad4('0x58'),'attributes':['id',_0xcad4('0x19'),_0xcad4('0x59'),'voicePause','interface'],'raw':!![]}]})[_0xcad4('0x14')](function(_0x376c45){if(_0x376c45){var _0x3938fc=_['flatMap'](_0x376c45,function(_0x5bcb54){var _0x570def=_0x5bcb54[_0xcad4('0x35')]({'plain':!![]});return _0x570def['Agents'];});return db[_0xcad4('0x24')][_0xcad4('0x31')]({'where':{'id':_0x47828f['params']['id']}})[_0xcad4('0x14')](function(_0x97b33d){return db[_0xcad4('0x5a')][_0xcad4('0x5b')](function(_0x4f442b){return _0x97b33d['addTeams'](_0x344cd6,{'transaction':_0x4f442b})[_0xcad4('0x14')](function(){return BPromise[_0xcad4('0x5c')](_0x3938fc,function(_0x1a7ea0){return db['UserWhatsappQueue'][_0xcad4('0x5d')]({'where':{'UserId':_0x1a7ea0['id'],'WhatsappQueueId':_0x47828f[_0xcad4('0x3e')]['id']},'transaction':_0x4f442b});});})['then'](function(){_0x3938fc['forEach'](function(_0xcba9f9){socket['emit'](_0xcad4('0x5e'),{'UserId':_0xcba9f9['id'],'WhatsappQueueId':_0x97b33d['id']});});});});});}})['then'](respondWithStatusCode(_0x11d47f,null))['catch'](handleError(_0x11d47f,null));};exports[_0xcad4('0x5f')]=function(_0x4fce10,_0x68bf2){return db[_0xcad4('0x53')][_0xcad4('0x25')]({'where':{'id':_0x4fce10['query'][_0xcad4('0x56')]},'attributes':['id'],'include':[{'model':db[_0xcad4('0x57')],'as':_0xcad4('0x58'),'attributes':['id'],'raw':!![]}]})[_0xcad4('0x14')](handleEntityNotFound(_0x68bf2,null))[_0xcad4('0x14')](function(_0x10196b){var _0x4e2a0b=_[_0xcad4('0x49')](_0x10196b,'id');var _0x462d61=[];var _0x37936c=[];var _0x398585=squel[_0xcad4('0x60')]();_0x398585['field'](_0xcad4('0x61'))[_0xcad4('0x62')](_0xcad4('0x63'),'tq')[_0xcad4('0x64')](_0xcad4('0x65'),'ut',_0xcad4('0x66'))[_0xcad4('0x21')](_0xcad4('0x67'),_0x4fce10[_0xcad4('0x3e')]['id']);for(var _0x446183=0x0;_0x446183<_0x10196b[_0xcad4('0x2e')];_0x446183+=0x1){let _0x28da9b=_0x10196b[_0x446183];for(var _0x2a2139=0x0;_0x2a2139<_0x28da9b[_0xcad4('0x58')][_0xcad4('0x2e')];_0x2a2139+=0x1){let _0x49d164=_0x28da9b[_0xcad4('0x58')][_0x2a2139];var _0x5b2323=_0x398585[_0xcad4('0x68')]();_0x5b2323['where']('ut.UserId\x20=\x20?',_0x49d164['id']);_0x37936c['push'](db[_0xcad4('0x5a')][_0xcad4('0x28')](_0x5b2323['toString'](),{'type':db['sequelize'][_0xcad4('0x69')][_0xcad4('0x6a')]})['then'](function(_0xd03d7){if(_0xd03d7[_0xcad4('0x2e')]===0x1){return _0x49d164['id'];}else{var _0x133210=_['every'](_[_0xcad4('0x49')](_0xd03d7,_0xcad4('0x6b')),function(_0x2aae66){return _['includes'](_0x4e2a0b,_0x2aae66);});if(_0x133210){return _0x49d164['id'];}}}));}}return BPromise[_0xcad4('0x6c')](_0x37936c)[_0xcad4('0x14')](function(_0x449ce0){_0x462d61=_(_0x462d61)[_0xcad4('0x6d')](_0x449ce0)[_0xcad4('0x6e')]()['value']();return db[_0xcad4('0x24')]['find']({'where':{'id':_0x4fce10[_0xcad4('0x3e')]['id']}})[_0xcad4('0x14')](function(_0x5b9a14){return db[_0xcad4('0x5a')][_0xcad4('0x5b')](function(_0xa4fce7){return _0x5b9a14[_0xcad4('0x5f')](_0x4fce10[_0xcad4('0x28')][_0xcad4('0x56')],{'transaction':_0xa4fce7})[_0xcad4('0x14')](function(){if(!_[_0xcad4('0x6f')](_0x462d61)){return _0x5b9a14['removeAgents'](_0x462d61,{'transaction':_0xa4fce7});}})['then'](function(){_0x462d61[_0xcad4('0x70')](function(_0xaddf7c){socket[_0xcad4('0x71')](_0xcad4('0x72'),{'UserId':_0xaddf7c,'WhatsappQueueId':_0x5b9a14['id']});});});});});});})[_0xcad4('0x14')](respondWithStatusCode(_0x68bf2,null))[_0xcad4('0x3c')](handleError(_0x68bf2,null));};exports[_0xcad4('0x73')]=function(_0xa68e4c,_0x522be8){return db['WhatsappQueue'][_0xcad4('0x31')]({'where':{'id':_0xa68e4c[_0xcad4('0x3e')]['id']}})['then'](handleEntityNotFound(_0x522be8,null))['then'](function(_0x207fd9){if(_0x207fd9){return _0x207fd9[_0xcad4('0x73')](_0xa68e4c['body'][_0xcad4('0x56')],_[_0xcad4('0x74')](_0xa68e4c['body'],['ids','id'])||{})['spread'](function(_0x55798a){for(var _0x2c111f=0x0;_0x2c111f<_0xa68e4c['body'][_0xcad4('0x56')][_0xcad4('0x2e')];_0x2c111f+=0x1){socket[_0xcad4('0x71')](_0xcad4('0x5e'),{'UserId':Number(_0xa68e4c[_0xcad4('0x33')][_0xcad4('0x56')][_0x2c111f]),'WhatsappQueueId':Number(_0xa68e4c[_0xcad4('0x3e')]['id'])});}return _0x55798a;});}})[_0xcad4('0x14')](respondWithResult(_0x522be8,null))[_0xcad4('0x3c')](handleError(_0x522be8,null));};exports[_0xcad4('0x75')]=function(_0x30b853,_0x552859){return db['WhatsappQueue'][_0xcad4('0x31')]({'where':{'id':_0x30b853[_0xcad4('0x3e')]['id']}})['then'](handleEntityNotFound(_0x552859,null))['then'](function(_0x102915){if(_0x102915){return _0x102915['removeAgents'](_0x30b853[_0xcad4('0x28')][_0xcad4('0x56')])[_0xcad4('0x14')](function(){if(_[_0xcad4('0x76')](_0x30b853[_0xcad4('0x28')][_0xcad4('0x56')])){for(var _0x1b251a=0x0;_0x1b251a<_0x30b853[_0xcad4('0x28')]['ids'][_0xcad4('0x2e')];_0x1b251a+=0x1){socket[_0xcad4('0x71')]('userWhatsappQueue:remove',{'UserId':Number(_0x30b853['query']['ids'][_0x1b251a]),'WhatsappQueueId':Number(_0x30b853[_0xcad4('0x3e')]['id'])});}}else{socket[_0xcad4('0x71')]('userWhatsappQueue:remove',{'UserId':Number(_0x30b853['query'][_0xcad4('0x56')]),'WhatsappQueueId':Number(_0x30b853[_0xcad4('0x3e')]['id'])});}});}})[_0xcad4('0x14')](respondWithStatusCode(_0x552859,null))[_0xcad4('0x3c')](handleError(_0x552859,null));};exports[_0xcad4('0x77')]=function(_0x30b342,_0x2daafa){var _0x2f0718={};var _0x110058={};var _0x591dc8;var _0x5d659b;return db['WhatsappQueue']['findOne']({'where':{'id':_0x30b342[_0xcad4('0x3e')]['id']}})[_0xcad4('0x14')](handleEntityNotFound(_0x2daafa,null))['then'](function(_0x3d096e){if(_0x3d096e){_0x591dc8=_0x3d096e;_0x110058['model']=_[_0xcad4('0x27')](db['User'][_0xcad4('0x1c')]);_0x110058[_0xcad4('0x28')]=_[_0xcad4('0x27')](_0x30b342[_0xcad4('0x28')]);_0x110058['filters']=_[_0xcad4('0x2a')](_0x110058[_0xcad4('0x2b')],_0x110058[_0xcad4('0x28')]);_0x2f0718[_0xcad4('0x2c')]=_[_0xcad4('0x2a')](_0x110058[_0xcad4('0x2b')],qs[_0xcad4('0x2d')](_0x30b342[_0xcad4('0x28')]['fields']));_0x2f0718[_0xcad4('0x2c')]=_0x2f0718[_0xcad4('0x2c')]['length']?_0x2f0718[_0xcad4('0x2c')]:_0x110058[_0xcad4('0x2b')];_0x2f0718[_0xcad4('0x44')]=qs['sort'](_0x30b342['query'][_0xcad4('0x45')]);_0x2f0718[_0xcad4('0x21')]=qs[_0xcad4('0x29')](_[_0xcad4('0x54')](_0x30b342[_0xcad4('0x28')],_0x110058['filters']));if(_0x30b342[_0xcad4('0x28')][_0xcad4('0x46')]){_0x2f0718['where']=_[_0xcad4('0x30')](_0x2f0718[_0xcad4('0x21')],{'$or':_[_0xcad4('0x49')](_0x2f0718['attributes'],function(_0xdd9499){var _0x33a471={};_0x33a471[_0xdd9499]={'$like':'%'+_0x30b342[_0xcad4('0x28')][_0xcad4('0x46')]+'%'};return _0x33a471;})});}_0x2f0718=_[_0xcad4('0x30')]({},_0x2f0718,_0x30b342[_0xcad4('0x47')]);return _0x591dc8[_0xcad4('0x77')](_0x2f0718);}})[_0xcad4('0x14')](function(_0x1d4e01){if(_0x1d4e01){_0x5d659b=_0x1d4e01[_0xcad4('0x2e')];if(!_0x30b342['query'][_0xcad4('0x42')]('nolimit')){_0x2f0718[_0xcad4('0x11')]=qs[_0xcad4('0x11')](_0x30b342['query'][_0xcad4('0x11')]);_0x2f0718[_0xcad4('0x10')]=qs[_0xcad4('0x10')](_0x30b342[_0xcad4('0x28')][_0xcad4('0x10')]);}return _0x591dc8[_0xcad4('0x77')](_0x2f0718);}})[_0xcad4('0x14')](function(_0xf6c85e){if(_0xf6c85e){return _0xf6c85e?{'count':_0x5d659b,'rows':_0xf6c85e}:null;}})[_0xcad4('0x14')](respondWithResult(_0x2daafa,null))['catch'](handleError(_0x2daafa,null));};
\ No newline at end of file