Built motion from commit 97153652.|2.6.26
[motion2.git] / server / api / whatsappQueue / whatsappQueue.controller.js
index d6f12b5..2cc0b6d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf1c9=['show','params','model','keys','filters','intersection','attributes','fields','length','includeAll','merge','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','describe','getMembers','findOne','hasOwnProperty','order','sort','WhatsappQueueId','filter','UserWhatsappQueue','findAll','findAndCountAll','UserId','agent','whatsappPause','updatedAt','format','SIP','createdAt','Team','pick','options','getTeams','nolimit','addTeams','User','Agents','online','voicePause','flatMap','sequelize','each','forEach','emit','removeTeams','ids','select','tq.TeamId','from','team_has_whatsapp_queues','join','ut.TeamId\x20=\x20tq.TeamId','WhatsappQueueId\x20=\x20?','toString','QueryTypes','SELECT','every','TeamId','includes','all','union','compact','value','transaction','isEmpty','removeAgents','userWhatsappQueue:remove','addAgents','omit','spread','userWhatsappQueue:save','isArray','bluebird','util','lodash','squel','ioredis','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./whatsappQueue.socket','register','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','update','then','get','WhatsappQueues','UserProfileResource','destroy','error','stack','name','send','index','map','WhatsappQueue','rawAttributes','fieldName','type','key','where','include','query','rows','catch'];(function(_0x3db453,_0x18a04f){var _0x25e68e=function(_0x559f48){while(--_0x559f48){_0x3db453['push'](_0x3db453['shift']());}};_0x25e68e(++_0x18a04f);}(_0xf1c9,0x1c9));var _0x9f1c=function(_0x44ec36,_0x296ad2){_0x44ec36=_0x44ec36-0x0;var _0x22976e=_0xf1c9[_0x44ec36];return _0x22976e;};'use strict';var BPromise=require(_0x9f1c('0x0'));var util=require(_0x9f1c('0x1'));var _=require(_0x9f1c('0x2'));var squel=require(_0x9f1c('0x3'));var Redis=require(_0x9f1c('0x4'));var qs=require('../../components/parsers/qs');var logger=require(_0x9f1c('0x5'))(_0x9f1c('0x6'));var config=require(_0x9f1c('0x7'));var db=require(_0x9f1c('0x8'))['db'];config[_0x9f1c('0x9')]=_[_0x9f1c('0xa')](config[_0x9f1c('0x9')],{'host':_0x9f1c('0xb'),'port':0x18eb});var socket=require(_0x9f1c('0xc'))(new Redis(config[_0x9f1c('0x9')]));require(_0x9f1c('0xd'))[_0x9f1c('0xe')](socket);function respondWithStatusCode(_0x388848,_0x155a00){_0x155a00=_0x155a00||0xcc;return function(_0x3af1b1){if(_0x3af1b1){return _0x388848[_0x9f1c('0xf')](_0x155a00);}return _0x388848[_0x9f1c('0x10')](_0x155a00)[_0x9f1c('0x11')]();};}function respondWithResult(_0xf9dc3d,_0x4f24fc){_0x4f24fc=_0x4f24fc||0xc8;return function(_0x126a43){if(_0x126a43){return _0xf9dc3d[_0x9f1c('0x10')](_0x4f24fc)[_0x9f1c('0x12')](_0x126a43);}};}function respondWithFilteredResult(_0x2daf78,_0x2a9669){return function(_0x2a3ad0){if(_0x2a3ad0){var _0x5653a1=typeof _0x2a9669[_0x9f1c('0x13')]===_0x9f1c('0x14')&&typeof _0x2a9669['limit']===_0x9f1c('0x14');var _0x47aab9=_0x2a3ad0[_0x9f1c('0x15')];var _0x556662=_0x5653a1?0x0:_0x2a9669['offset'];var _0x17357b=_0x5653a1?_0x2a3ad0[_0x9f1c('0x15')]:_0x2a9669[_0x9f1c('0x13')]+_0x2a9669[_0x9f1c('0x16')];var _0x618160;if(_0x17357b>=_0x47aab9){_0x17357b=_0x47aab9;_0x618160=0xc8;}else{_0x618160=0xce;}_0x2daf78[_0x9f1c('0x10')](_0x618160);return _0x2daf78[_0x9f1c('0x17')](_0x9f1c('0x18'),_0x556662+'-'+_0x17357b+'/'+_0x47aab9)[_0x9f1c('0x12')](_0x2a3ad0);}return null;};}function saveUpdates(_0x24af19){return function(_0x4528a9){if(_0x4528a9){return _0x4528a9[_0x9f1c('0x19')](_0x24af19)[_0x9f1c('0x1a')](function(_0x383be8){return _0x383be8;});}return null;};}function removeEntity(_0x3dfc53){return function(_0x1f367c){if(_0x1f367c){return _0x1f367c['destroy']()[_0x9f1c('0x1a')](function(){var _0x695c7d=_0x1f367c[_0x9f1c('0x1b')]({'plain':!![]});var _0x2ce630=_0x9f1c('0x1c');return db[_0x9f1c('0x1d')][_0x9f1c('0x1e')]({'where':{'type':_0x2ce630,'resourceId':_0x695c7d['id']}})[_0x9f1c('0x1a')](function(){return _0x1f367c;});})[_0x9f1c('0x1a')](function(){_0x3dfc53[_0x9f1c('0x10')](0xcc)[_0x9f1c('0x11')]();});}};}function handleEntityNotFound(_0x26b871){return function(_0x74e786){if(!_0x74e786){_0x26b871[_0x9f1c('0xf')](0x194);}return _0x74e786;};}function handleError(_0x54bc51,_0x53ccf2){_0x53ccf2=_0x53ccf2||0x1f4;return function(_0x4d6759){logger[_0x9f1c('0x1f')](_0x4d6759[_0x9f1c('0x20')]);if(_0x4d6759[_0x9f1c('0x21')]){delete _0x4d6759[_0x9f1c('0x21')];}_0x54bc51[_0x9f1c('0x10')](_0x53ccf2)[_0x9f1c('0x22')](_0x4d6759);};}exports[_0x9f1c('0x23')]=function(_0x375b28,_0x46c3b2){var _0xa13bdf={};var _0xbc341b={'count':0x0,'rows':[]};var _0x49197d=_[_0x9f1c('0x24')](db[_0x9f1c('0x25')][_0x9f1c('0x26')],function(_0x3a4592){return{'name':_0x3a4592[_0x9f1c('0x27')],'type':_0x3a4592[_0x9f1c('0x28')][_0x9f1c('0x29')]};});_0xa13bdf=qs['getOptions'](_0x49197d,_0x375b28);var _0x358fe9={'where':_0xa13bdf[_0x9f1c('0x2a')]};return db['WhatsappQueue'][_0x9f1c('0x15')](_0x358fe9)[_0x9f1c('0x1a')](function(_0x2f96f5){_0xbc341b[_0x9f1c('0x15')]=_0x2f96f5;_0xa13bdf[_0x9f1c('0x2b')]=qs[_0x9f1c('0x2b')](_0x375b28[_0x9f1c('0x2c')]);return db['WhatsappQueue']['findAll'](_0xa13bdf);})[_0x9f1c('0x1a')](function(_0x194383){_0xbc341b[_0x9f1c('0x2d')]=_0x194383;return _0xbc341b;})[_0x9f1c('0x1a')](respondWithFilteredResult(_0x46c3b2,_0xa13bdf))[_0x9f1c('0x2e')](handleError(_0x46c3b2,null));};exports[_0x9f1c('0x2f')]=function(_0x51e47b,_0x299de0){var _0x525816={'raw':!![],'where':{'id':_0x51e47b[_0x9f1c('0x30')]['id']}},_0x4dec34={};_0x4dec34[_0x9f1c('0x31')]=_[_0x9f1c('0x32')](db['WhatsappQueue'][_0x9f1c('0x26')]);_0x4dec34[_0x9f1c('0x2c')]=_[_0x9f1c('0x32')](_0x51e47b[_0x9f1c('0x2c')]);_0x4dec34[_0x9f1c('0x33')]=_[_0x9f1c('0x34')](_0x4dec34[_0x9f1c('0x31')],_0x4dec34['query']);_0x525816[_0x9f1c('0x35')]=_['intersection'](_0x4dec34['model'],qs['fields'](_0x51e47b['query'][_0x9f1c('0x36')]));_0x525816['attributes']=_0x525816[_0x9f1c('0x35')][_0x9f1c('0x37')]?_0x525816['attributes']:_0x4dec34[_0x9f1c('0x31')];if(_0x51e47b['query'][_0x9f1c('0x38')]){_0x525816['include']=[{'all':!![]}];}_0x525816=_[_0x9f1c('0x39')]({},_0x525816,_0x51e47b['options']);return db[_0x9f1c('0x25')][_0x9f1c('0x3a')](_0x525816)[_0x9f1c('0x1a')](handleEntityNotFound(_0x299de0,null))[_0x9f1c('0x1a')](respondWithResult(_0x299de0,null))[_0x9f1c('0x2e')](handleError(_0x299de0,null));};exports['create']=function(_0x292dfb,_0xda3056){return db[_0x9f1c('0x25')][_0x9f1c('0x3b')](_0x292dfb[_0x9f1c('0x3c')],{})[_0x9f1c('0x1a')](function(_0x4fc81b){var _0x50ec1f=_0x292dfb[_0x9f1c('0x3d')]['get']({'plain':!![]});if(!_0x50ec1f)throw new Error(_0x9f1c('0x3e'));if(_0x50ec1f['role']===_0x9f1c('0x3d')){var _0x229eed=_0x4fc81b['get']({'plain':!![]});var _0x2b2a67=_0x9f1c('0x1c');return db[_0x9f1c('0x3f')][_0x9f1c('0x3a')]({'where':{'name':_0x2b2a67,'userProfileId':_0x50ec1f[_0x9f1c('0x40')]},'raw':!![]})[_0x9f1c('0x1a')](function(_0x181270){if(_0x181270&&_0x181270['autoAssociation']===0x0){return db['UserProfileResource'][_0x9f1c('0x3b')]({'name':_0x229eed[_0x9f1c('0x21')],'resourceId':_0x229eed['id'],'type':_0x181270[_0x9f1c('0x21')],'sectionId':_0x181270['id']},{})[_0x9f1c('0x1a')](function(){return _0x4fc81b;});}else{return _0x4fc81b;}})[_0x9f1c('0x2e')](function(_0x14b3be){logger[_0x9f1c('0x1f')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x14b3be);throw _0x14b3be;});}return _0x4fc81b;})[_0x9f1c('0x1a')](respondWithResult(_0xda3056,0xc9))['catch'](handleError(_0xda3056,null));};exports[_0x9f1c('0x19')]=function(_0x20636e,_0x4c6bf6){if(_0x20636e[_0x9f1c('0x3c')]['id']){delete _0x20636e['body']['id'];}return db[_0x9f1c('0x25')][_0x9f1c('0x3a')]({'where':{'id':_0x20636e['params']['id']}})['then'](handleEntityNotFound(_0x4c6bf6,null))['then'](saveUpdates(_0x20636e['body'],null))['then'](respondWithResult(_0x4c6bf6,null))[_0x9f1c('0x2e')](handleError(_0x4c6bf6,null));};exports['destroy']=function(_0x45260f,_0x590e0e){return db[_0x9f1c('0x25')][_0x9f1c('0x3a')]({'where':{'id':_0x45260f[_0x9f1c('0x30')]['id']}})['then'](handleEntityNotFound(_0x590e0e,null))[_0x9f1c('0x1a')](removeEntity(_0x590e0e,null))[_0x9f1c('0x2e')](handleError(_0x590e0e,null));};exports[_0x9f1c('0x41')]=function(_0x3c1b44,_0x2dafa4){return db['WhatsappQueue']['describe']()[_0x9f1c('0x1a')](respondWithResult(_0x2dafa4,null))[_0x9f1c('0x2e')](handleError(_0x2dafa4,null));};exports[_0x9f1c('0x42')]=function(_0x18bfde,_0x2354e2){var _0x473065={'raw':!![],'where':{}},_0x39b0aa={},_0x8ac4ae;return db['WhatsappQueue'][_0x9f1c('0x43')]({'where':{'id':_0x18bfde[_0x9f1c('0x30')]['id']}})[_0x9f1c('0x1a')](handleEntityNotFound(_0x2354e2,null))[_0x9f1c('0x1a')](function(_0x309bf9){if(_0x309bf9){_0x8ac4ae=_0x309bf9[_0x9f1c('0x1b')]({'plain':!![]});_0x39b0aa[_0x9f1c('0x31')]=_[_0x9f1c('0x32')](db['UserWhatsappQueue'][_0x9f1c('0x26')]);_0x39b0aa['query']=_['keys'](_0x18bfde[_0x9f1c('0x2c')]);_0x39b0aa[_0x9f1c('0x33')]=_[_0x9f1c('0x34')](_0x39b0aa[_0x9f1c('0x31')],_0x39b0aa[_0x9f1c('0x2c')]);_0x473065['attributes']=_['intersection'](_0x39b0aa[_0x9f1c('0x31')],qs['fields'](_0x18bfde['query'][_0x9f1c('0x36')]));_0x473065[_0x9f1c('0x35')]=_0x473065[_0x9f1c('0x35')][_0x9f1c('0x37')]?_0x473065[_0x9f1c('0x35')]:_0x39b0aa[_0x9f1c('0x31')];if(!_0x18bfde[_0x9f1c('0x2c')][_0x9f1c('0x44')]('nolimit')){_0x473065[_0x9f1c('0x16')]=qs[_0x9f1c('0x16')](_0x18bfde[_0x9f1c('0x2c')]['limit']);_0x473065[_0x9f1c('0x13')]=qs[_0x9f1c('0x13')](_0x18bfde[_0x9f1c('0x2c')][_0x9f1c('0x13')]);}_0x473065[_0x9f1c('0x45')]=qs['sort'](_0x18bfde[_0x9f1c('0x2c')][_0x9f1c('0x46')]);_0x473065[_0x9f1c('0x2a')]=qs['filters'](_['pick'](_0x18bfde[_0x9f1c('0x2c')],_0x39b0aa[_0x9f1c('0x33')]));_0x473065[_0x9f1c('0x2a')][_0x9f1c('0x47')]=_0x309bf9['id'];if(_0x18bfde[_0x9f1c('0x2c')]['filter']){_0x473065['where']=_[_0x9f1c('0x39')](_0x473065[_0x9f1c('0x2a')],{'$or':_[_0x9f1c('0x24')](_0x473065[_0x9f1c('0x35')],function(_0x175ec9){var _0xf9587={};_0xf9587[_0x175ec9]={'$like':'%'+_0x18bfde[_0x9f1c('0x2c')][_0x9f1c('0x48')]+'%'};return _0xf9587;})});}_0x473065=_['merge']({},_0x473065,_0x18bfde['options']);return db[_0x9f1c('0x49')][_0x9f1c('0x4a')](_0x473065);}})[_0x9f1c('0x1a')](function(_0x1d7e7e){if(_0x1d7e7e){return db['User'][_0x9f1c('0x4b')]({'where':{'id':_[_0x9f1c('0x24')](_0x1d7e7e,_0x9f1c('0x4c')),'role':_0x9f1c('0x4d')},'attributes':['id','name',_0x9f1c('0x4e'),_0x9f1c('0x4f'),'createdAt']});}})[_0x9f1c('0x1a')](function(_0x32dbc2){if(_0x32dbc2){return{'count':_0x32dbc2[_0x9f1c('0x15')],'rows':_[_0x9f1c('0x24')](_0x32dbc2[_0x9f1c('0x2d')],function(_0x3d82cf){return{'membername':_0x3d82cf[_0x9f1c('0x21')],'UserId':_0x3d82cf['id'],'queue_name':_0x8ac4ae[_0x9f1c('0x21')],'WhatsappQueueId':_0x8ac4ae['id'],'interface':util[_0x9f1c('0x50')]('%s/%s',_0x9f1c('0x51'),_0x3d82cf[_0x9f1c('0x21')]),'penalty':0x0,'paused':_0x3d82cf[_0x9f1c('0x4e')],'createdAt':_0x3d82cf[_0x9f1c('0x52')],'updatedAt':_0x3d82cf[_0x9f1c('0x4f')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x9f1c('0x1a')](respondWithFilteredResult(_0x2354e2,_0x473065))[_0x9f1c('0x2e')](handleError(_0x2354e2,null));};exports['getTeams']=function(_0x4eecca,_0x2a7ed5){var _0x51ba88={};var _0xb92ad4={};var _0x18b2f7;var _0x3d34d7;return db[_0x9f1c('0x25')][_0x9f1c('0x43')]({'where':{'id':_0x4eecca[_0x9f1c('0x30')]['id']}})[_0x9f1c('0x1a')](handleEntityNotFound(_0x2a7ed5,null))[_0x9f1c('0x1a')](function(_0x312615){if(_0x312615){_0x18b2f7=_0x312615;_0xb92ad4['model']=_['keys'](db[_0x9f1c('0x53')][_0x9f1c('0x26')]);_0xb92ad4['query']=_['keys'](_0x4eecca['query']);_0xb92ad4[_0x9f1c('0x33')]=_[_0x9f1c('0x34')](_0xb92ad4['model'],_0xb92ad4['query']);_0x51ba88[_0x9f1c('0x35')]=_[_0x9f1c('0x34')](_0xb92ad4['model'],qs['fields'](_0x4eecca[_0x9f1c('0x2c')][_0x9f1c('0x36')]));_0x51ba88['attributes']=_0x51ba88[_0x9f1c('0x35')][_0x9f1c('0x37')]?_0x51ba88[_0x9f1c('0x35')]:_0xb92ad4[_0x9f1c('0x31')];_0x51ba88[_0x9f1c('0x45')]=qs[_0x9f1c('0x46')](_0x4eecca['query'][_0x9f1c('0x46')]);_0x51ba88[_0x9f1c('0x2a')]=qs[_0x9f1c('0x33')](_[_0x9f1c('0x54')](_0x4eecca[_0x9f1c('0x2c')],_0xb92ad4['filters']));if(_0x4eecca[_0x9f1c('0x2c')][_0x9f1c('0x48')]){_0x51ba88[_0x9f1c('0x2a')]=_['merge'](_0x51ba88[_0x9f1c('0x2a')],{'$or':_[_0x9f1c('0x24')](_0x51ba88[_0x9f1c('0x35')],function(_0x25cdc0){var _0xeef153={};_0xeef153[_0x25cdc0]={'$like':'%'+_0x4eecca[_0x9f1c('0x2c')]['filter']+'%'};return _0xeef153;})});}_0x51ba88=_[_0x9f1c('0x39')]({},_0x51ba88,_0x4eecca[_0x9f1c('0x55')]);return _0x18b2f7[_0x9f1c('0x56')](_0x51ba88);}})[_0x9f1c('0x1a')](function(_0xe5b409){if(_0xe5b409){_0x3d34d7=_0xe5b409[_0x9f1c('0x37')];if(!_0x4eecca[_0x9f1c('0x2c')]['hasOwnProperty'](_0x9f1c('0x57'))){_0x51ba88[_0x9f1c('0x16')]=qs[_0x9f1c('0x16')](_0x4eecca[_0x9f1c('0x2c')][_0x9f1c('0x16')]);_0x51ba88[_0x9f1c('0x13')]=qs[_0x9f1c('0x13')](_0x4eecca['query'][_0x9f1c('0x13')]);}return _0x18b2f7[_0x9f1c('0x56')](_0x51ba88);}})[_0x9f1c('0x1a')](function(_0x4cb04a){if(_0x4cb04a){return _0x4cb04a?{'count':_0x3d34d7,'rows':_0x4cb04a}:null;}})['then'](respondWithResult(_0x2a7ed5,null))[_0x9f1c('0x2e')](handleError(_0x2a7ed5,null));};exports[_0x9f1c('0x58')]=function(_0x4f6fca,_0x35a0bd){var _0x3062d3=_0x4f6fca[_0x9f1c('0x3c')]['ids'];return db[_0x9f1c('0x53')]['findAll']({'where':{'id':_0x3062d3},'attributes':['id'],'include':[{'model':db[_0x9f1c('0x59')],'as':_0x9f1c('0x5a'),'attributes':['id',_0x9f1c('0x21'),_0x9f1c('0x5b'),_0x9f1c('0x5c'),'interface'],'raw':!![]}]})[_0x9f1c('0x1a')](function(_0x35a1f8){if(_0x35a1f8){var _0x4d2855=_[_0x9f1c('0x5d')](_0x35a1f8,function(_0xbf8e1a){var _0x28abf5=_0xbf8e1a[_0x9f1c('0x1b')]({'plain':!![]});return _0x28abf5[_0x9f1c('0x5a')];});return db[_0x9f1c('0x25')][_0x9f1c('0x3a')]({'where':{'id':_0x4f6fca[_0x9f1c('0x30')]['id']}})[_0x9f1c('0x1a')](function(_0x207692){return db[_0x9f1c('0x5e')]['transaction'](function(_0x3d3ac5){return _0x207692[_0x9f1c('0x58')](_0x3062d3,{'transaction':_0x3d3ac5})[_0x9f1c('0x1a')](function(){return BPromise[_0x9f1c('0x5f')](_0x4d2855,function(_0x44fcff){return db[_0x9f1c('0x49')]['findOrCreate']({'where':{'UserId':_0x44fcff['id'],'WhatsappQueueId':_0x4f6fca[_0x9f1c('0x30')]['id']},'transaction':_0x3d3ac5});});})[_0x9f1c('0x1a')](function(){_0x4d2855[_0x9f1c('0x60')](function(_0x59a6b8){socket[_0x9f1c('0x61')]('userWhatsappQueue:save',{'UserId':_0x59a6b8['id'],'WhatsappQueueId':_0x207692['id']});});});});});}})['then'](respondWithStatusCode(_0x35a0bd,null))['catch'](handleError(_0x35a0bd,null));};exports[_0x9f1c('0x62')]=function(_0x21885c,_0x3f75bd){return db['Team'][_0x9f1c('0x4a')]({'where':{'id':_0x21885c[_0x9f1c('0x2c')][_0x9f1c('0x63')]},'attributes':['id'],'include':[{'model':db['User'],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0x9f1c('0x1a')](handleEntityNotFound(_0x3f75bd,null))[_0x9f1c('0x1a')](function(_0x5a98e2){var _0x4185a4=_[_0x9f1c('0x24')](_0x5a98e2,'id');var _0x37be96=[];var _0x26e75f=[];var _0x99d8f2=squel[_0x9f1c('0x64')]();_0x99d8f2['field'](_0x9f1c('0x65'))[_0x9f1c('0x66')](_0x9f1c('0x67'),'tq')[_0x9f1c('0x68')]('user_has_teams','ut',_0x9f1c('0x69'))[_0x9f1c('0x2a')](_0x9f1c('0x6a'),_0x21885c[_0x9f1c('0x30')]['id']);for(var _0x1d7a1b=0x0;_0x1d7a1b<_0x5a98e2[_0x9f1c('0x37')];_0x1d7a1b+=0x1){let _0x2403c4=_0x5a98e2[_0x1d7a1b];for(var _0x443734=0x0;_0x443734<_0x2403c4['Agents'][_0x9f1c('0x37')];_0x443734+=0x1){let _0x517859=_0x2403c4['Agents'][_0x443734];var _0x3739db=_0x99d8f2['clone']();_0x3739db[_0x9f1c('0x2a')]('ut.UserId\x20=\x20?',_0x517859['id']);_0x26e75f['push'](db[_0x9f1c('0x5e')][_0x9f1c('0x2c')](_0x3739db[_0x9f1c('0x6b')](),{'type':db['sequelize'][_0x9f1c('0x6c')][_0x9f1c('0x6d')]})[_0x9f1c('0x1a')](function(_0x111107){if(_0x111107[_0x9f1c('0x37')]===0x1){return _0x517859['id'];}else{var _0x113cda=_[_0x9f1c('0x6e')](_['map'](_0x111107,_0x9f1c('0x6f')),function(_0x18dcac){return _[_0x9f1c('0x70')](_0x4185a4,_0x18dcac);});if(_0x113cda){return _0x517859['id'];}}}));}}return BPromise[_0x9f1c('0x71')](_0x26e75f)['then'](function(_0x374394){_0x37be96=_(_0x37be96)[_0x9f1c('0x72')](_0x374394)[_0x9f1c('0x73')]()[_0x9f1c('0x74')]();return db[_0x9f1c('0x25')][_0x9f1c('0x3a')]({'where':{'id':_0x21885c[_0x9f1c('0x30')]['id']}})[_0x9f1c('0x1a')](function(_0x5a9e53){return db[_0x9f1c('0x5e')][_0x9f1c('0x75')](function(_0x14ce39){return _0x5a9e53[_0x9f1c('0x62')](_0x21885c[_0x9f1c('0x2c')][_0x9f1c('0x63')],{'transaction':_0x14ce39})[_0x9f1c('0x1a')](function(){if(!_[_0x9f1c('0x76')](_0x37be96)){return _0x5a9e53[_0x9f1c('0x77')](_0x37be96,{'transaction':_0x14ce39});}})[_0x9f1c('0x1a')](function(){_0x37be96[_0x9f1c('0x60')](function(_0x3063d1){socket[_0x9f1c('0x61')](_0x9f1c('0x78'),{'UserId':_0x3063d1,'WhatsappQueueId':_0x5a9e53['id']});});});});});});})['then'](respondWithStatusCode(_0x3f75bd,null))[_0x9f1c('0x2e')](handleError(_0x3f75bd,null));};exports[_0x9f1c('0x79')]=function(_0x2d0ca7,_0x527211){return db[_0x9f1c('0x25')][_0x9f1c('0x3a')]({'where':{'id':_0x2d0ca7[_0x9f1c('0x30')]['id']}})['then'](handleEntityNotFound(_0x527211,null))[_0x9f1c('0x1a')](function(_0x52563c){if(_0x52563c){return _0x52563c[_0x9f1c('0x79')](_0x2d0ca7[_0x9f1c('0x3c')][_0x9f1c('0x63')],_[_0x9f1c('0x7a')](_0x2d0ca7['body'],[_0x9f1c('0x63'),'id'])||{})[_0x9f1c('0x7b')](function(_0x2e25da){for(var _0x22b6ad=0x0;_0x22b6ad<_0x2d0ca7[_0x9f1c('0x3c')][_0x9f1c('0x63')][_0x9f1c('0x37')];_0x22b6ad+=0x1){socket[_0x9f1c('0x61')](_0x9f1c('0x7c'),{'UserId':Number(_0x2d0ca7[_0x9f1c('0x3c')][_0x9f1c('0x63')][_0x22b6ad]),'WhatsappQueueId':Number(_0x2d0ca7[_0x9f1c('0x30')]['id'])});}return _0x2e25da;});}})[_0x9f1c('0x1a')](respondWithResult(_0x527211,null))[_0x9f1c('0x2e')](handleError(_0x527211,null));};exports[_0x9f1c('0x77')]=function(_0x15aa3b,_0x50a9a1){return db[_0x9f1c('0x25')][_0x9f1c('0x3a')]({'where':{'id':_0x15aa3b[_0x9f1c('0x30')]['id']}})[_0x9f1c('0x1a')](handleEntityNotFound(_0x50a9a1,null))[_0x9f1c('0x1a')](function(_0x1ce741){if(_0x1ce741){return _0x1ce741[_0x9f1c('0x77')](_0x15aa3b[_0x9f1c('0x2c')][_0x9f1c('0x63')])['then'](function(){if(_[_0x9f1c('0x7d')](_0x15aa3b['query']['ids'])){for(var _0x43f24a=0x0;_0x43f24a<_0x15aa3b[_0x9f1c('0x2c')]['ids'][_0x9f1c('0x37')];_0x43f24a+=0x1){socket[_0x9f1c('0x61')](_0x9f1c('0x78'),{'UserId':Number(_0x15aa3b['query']['ids'][_0x43f24a]),'WhatsappQueueId':Number(_0x15aa3b[_0x9f1c('0x30')]['id'])});}}else{socket['emit']('userWhatsappQueue:remove',{'UserId':Number(_0x15aa3b[_0x9f1c('0x2c')][_0x9f1c('0x63')]),'WhatsappQueueId':Number(_0x15aa3b[_0x9f1c('0x30')]['id'])});}});}})['then'](respondWithStatusCode(_0x50a9a1,null))[_0x9f1c('0x2e')](handleError(_0x50a9a1,null));};exports['getAgents']=function(_0x2d5d69,_0x1acffb){var _0x5d29dc={};var _0x57ea09={};var _0x12e0c6;var _0x206691;return db[_0x9f1c('0x25')][_0x9f1c('0x43')]({'where':{'id':_0x2d5d69[_0x9f1c('0x30')]['id']}})[_0x9f1c('0x1a')](handleEntityNotFound(_0x1acffb,null))[_0x9f1c('0x1a')](function(_0x45b694){if(_0x45b694){_0x12e0c6=_0x45b694;_0x57ea09[_0x9f1c('0x31')]=_[_0x9f1c('0x32')](db[_0x9f1c('0x59')][_0x9f1c('0x26')]);_0x57ea09[_0x9f1c('0x2c')]=_[_0x9f1c('0x32')](_0x2d5d69[_0x9f1c('0x2c')]);_0x57ea09[_0x9f1c('0x33')]=_[_0x9f1c('0x34')](_0x57ea09[_0x9f1c('0x31')],_0x57ea09[_0x9f1c('0x2c')]);_0x5d29dc[_0x9f1c('0x35')]=_[_0x9f1c('0x34')](_0x57ea09['model'],qs[_0x9f1c('0x36')](_0x2d5d69[_0x9f1c('0x2c')][_0x9f1c('0x36')]));_0x5d29dc[_0x9f1c('0x35')]=_0x5d29dc[_0x9f1c('0x35')][_0x9f1c('0x37')]?_0x5d29dc[_0x9f1c('0x35')]:_0x57ea09[_0x9f1c('0x31')];_0x5d29dc[_0x9f1c('0x45')]=qs['sort'](_0x2d5d69[_0x9f1c('0x2c')][_0x9f1c('0x46')]);_0x5d29dc['where']=qs['filters'](_['pick'](_0x2d5d69[_0x9f1c('0x2c')],_0x57ea09[_0x9f1c('0x33')]));if(_0x2d5d69[_0x9f1c('0x2c')]['filter']){_0x5d29dc[_0x9f1c('0x2a')]=_[_0x9f1c('0x39')](_0x5d29dc[_0x9f1c('0x2a')],{'$or':_[_0x9f1c('0x24')](_0x5d29dc['attributes'],function(_0x158b19){var _0x514d5e={};_0x514d5e[_0x158b19]={'$like':'%'+_0x2d5d69[_0x9f1c('0x2c')][_0x9f1c('0x48')]+'%'};return _0x514d5e;})});}_0x5d29dc=_['merge']({},_0x5d29dc,_0x2d5d69[_0x9f1c('0x55')]);return _0x12e0c6['getAgents'](_0x5d29dc);}})[_0x9f1c('0x1a')](function(_0x4ae993){if(_0x4ae993){_0x206691=_0x4ae993[_0x9f1c('0x37')];if(!_0x2d5d69[_0x9f1c('0x2c')]['hasOwnProperty'](_0x9f1c('0x57'))){_0x5d29dc[_0x9f1c('0x16')]=qs['limit'](_0x2d5d69[_0x9f1c('0x2c')]['limit']);_0x5d29dc['offset']=qs['offset'](_0x2d5d69['query'][_0x9f1c('0x13')]);}return _0x12e0c6['getAgents'](_0x5d29dc);}})[_0x9f1c('0x1a')](function(_0x5c08af){if(_0x5c08af){return _0x5c08af?{'count':_0x206691,'rows':_0x5c08af}:null;}})['then'](respondWithResult(_0x1acffb,null))['catch'](handleError(_0x1acffb,null));};
\ No newline at end of file
+var _0xd410=['spread','isArray','getAgents','util','squel','ioredis','../../components/parsers/qs','api','../../mysqldb','defaults','redis','./whatsappQueue.socket','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','then','get','WhatsappQueues','destroy','error','map','rawAttributes','fieldName','type','key','getOptions','where','include','query','WhatsappQueue','rows','catch','show','model','keys','intersection','attributes','fields','includeAll','merge','options','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','find','userProfileId','autoAssociation','UserProfileResource','name','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','params','describe','getMembers','findOne','UserWhatsappQueue','length','hasOwnProperty','nolimit','order','sort','filters','pick','WhatsappQueueId','filter','findAll','User','findAndCountAll','UserId','agent','whatsappPause','updatedAt','createdAt','%s/%s','SIP','getTeams','Team','addTeams','ids','online','voicePause','interface','transaction','forEach','emit','userWhatsappQueue:save','Agents','select','field','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','WhatsappQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','sequelize','TeamId','includes','all','value','removeTeams','isEmpty','removeAgents','userWhatsappQueue:remove','addAgents','omit'];(function(_0x41c124,_0x938abf){var _0x1b8248=function(_0x5c8aef){while(--_0x5c8aef){_0x41c124['push'](_0x41c124['shift']());}};_0x1b8248(++_0x938abf);}(_0xd410,0x1cf));var _0x0d41=function(_0x2bf141,_0x31eac7){_0x2bf141=_0x2bf141-0x0;var _0x48277b=_0xd410[_0x2bf141];return _0x48277b;};'use strict';var BPromise=require('bluebird');var util=require(_0x0d41('0x0'));var _=require('lodash');var squel=require(_0x0d41('0x1'));var Redis=require(_0x0d41('0x2'));var qs=require(_0x0d41('0x3'));var logger=require('../../config/logger')(_0x0d41('0x4'));var config=require('../../config/environment');var db=require(_0x0d41('0x5'))['db'];config['redis']=_[_0x0d41('0x6')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x0d41('0x7')]));require(_0x0d41('0x8'))['register'](socket);function respondWithStatusCode(_0x2cde70,_0x45e2c2){_0x45e2c2=_0x45e2c2||0xcc;return function(_0x2645bb){if(_0x2645bb){return _0x2cde70[_0x0d41('0x9')](_0x45e2c2);}return _0x2cde70[_0x0d41('0xa')](_0x45e2c2)['end']();};}function respondWithResult(_0x1f3edf,_0x1d781e){_0x1d781e=_0x1d781e||0xc8;return function(_0x2b08f8){if(_0x2b08f8){return _0x1f3edf['status'](_0x1d781e)[_0x0d41('0xb')](_0x2b08f8);}};}function respondWithFilteredResult(_0x2ac236,_0x5f14c2){return function(_0x4e6bac){if(_0x4e6bac){var _0x4e4f7e=typeof _0x5f14c2[_0x0d41('0xc')]===_0x0d41('0xd')&&typeof _0x5f14c2[_0x0d41('0xe')]===_0x0d41('0xd');var _0xe7d9b8=_0x4e6bac[_0x0d41('0xf')];var _0x189da1=_0x4e4f7e?0x0:_0x5f14c2[_0x0d41('0xc')];var _0x15bf2f=_0x4e4f7e?_0x4e6bac[_0x0d41('0xf')]:_0x5f14c2[_0x0d41('0xc')]+_0x5f14c2[_0x0d41('0xe')];var _0x18e35e;if(_0x15bf2f>=_0xe7d9b8){_0x15bf2f=_0xe7d9b8;_0x18e35e=0xc8;}else{_0x18e35e=0xce;}_0x2ac236[_0x0d41('0xa')](_0x18e35e);return _0x2ac236[_0x0d41('0x10')](_0x0d41('0x11'),_0x189da1+'-'+_0x15bf2f+'/'+_0xe7d9b8)[_0x0d41('0xb')](_0x4e6bac);}return null;};}function saveUpdates(_0x31c25c){return function(_0xd659ad){if(_0xd659ad){return _0xd659ad['update'](_0x31c25c)[_0x0d41('0x12')](function(_0x5c2fcb){return _0x5c2fcb;});}return null;};}function removeEntity(_0xb8c900){return function(_0x207410){if(_0x207410){return _0x207410['destroy']()[_0x0d41('0x12')](function(){var _0x1e1c70=_0x207410[_0x0d41('0x13')]({'plain':!![]});var _0x2c550f=_0x0d41('0x14');return db['UserProfileResource'][_0x0d41('0x15')]({'where':{'type':_0x2c550f,'resourceId':_0x1e1c70['id']}})[_0x0d41('0x12')](function(){return _0x207410;});})[_0x0d41('0x12')](function(){_0xb8c900[_0x0d41('0xa')](0xcc)['end']();});}};}function handleEntityNotFound(_0x58f332){return function(_0x13efef){if(!_0x13efef){_0x58f332[_0x0d41('0x9')](0x194);}return _0x13efef;};}function handleError(_0x22ba30,_0x516262){_0x516262=_0x516262||0x1f4;return function(_0x1bcfe1){logger[_0x0d41('0x16')](_0x1bcfe1['stack']);if(_0x1bcfe1['name']){delete _0x1bcfe1['name'];}_0x22ba30[_0x0d41('0xa')](_0x516262)['send'](_0x1bcfe1);};}exports['index']=function(_0x1cac7f,_0x39475f){var _0x49e960={};var _0x13147e={'count':0x0,'rows':[]};var _0x3a216c=_[_0x0d41('0x17')](db['WhatsappQueue'][_0x0d41('0x18')],function(_0x238cc1){return{'name':_0x238cc1[_0x0d41('0x19')],'type':_0x238cc1[_0x0d41('0x1a')][_0x0d41('0x1b')]};});_0x49e960=qs[_0x0d41('0x1c')](_0x3a216c,_0x1cac7f);var _0x5af429={'where':_0x49e960[_0x0d41('0x1d')]};return db['WhatsappQueue'][_0x0d41('0xf')](_0x5af429)[_0x0d41('0x12')](function(_0x267f48){_0x13147e[_0x0d41('0xf')]=_0x267f48;_0x49e960[_0x0d41('0x1e')]=qs[_0x0d41('0x1e')](_0x1cac7f[_0x0d41('0x1f')]);return db[_0x0d41('0x20')]['findAll'](_0x49e960);})[_0x0d41('0x12')](function(_0x541469){_0x13147e[_0x0d41('0x21')]=_0x541469;return _0x13147e;})[_0x0d41('0x12')](respondWithFilteredResult(_0x39475f,_0x49e960))[_0x0d41('0x22')](handleError(_0x39475f,null));};exports[_0x0d41('0x23')]=function(_0x1d816c,_0x3dd8fb){var _0x42682b={'raw':!![],'where':{'id':_0x1d816c['params']['id']}},_0x399327={};_0x399327[_0x0d41('0x24')]=_[_0x0d41('0x25')](db[_0x0d41('0x20')][_0x0d41('0x18')]);_0x399327[_0x0d41('0x1f')]=_['keys'](_0x1d816c[_0x0d41('0x1f')]);_0x399327['filters']=_[_0x0d41('0x26')](_0x399327['model'],_0x399327[_0x0d41('0x1f')]);_0x42682b[_0x0d41('0x27')]=_[_0x0d41('0x26')](_0x399327[_0x0d41('0x24')],qs[_0x0d41('0x28')](_0x1d816c[_0x0d41('0x1f')][_0x0d41('0x28')]));_0x42682b[_0x0d41('0x27')]=_0x42682b[_0x0d41('0x27')]['length']?_0x42682b[_0x0d41('0x27')]:_0x399327[_0x0d41('0x24')];if(_0x1d816c[_0x0d41('0x1f')][_0x0d41('0x29')]){_0x42682b[_0x0d41('0x1e')]=[{'all':!![]}];}_0x42682b=_[_0x0d41('0x2a')]({},_0x42682b,_0x1d816c[_0x0d41('0x2b')]);return db[_0x0d41('0x20')]['find'](_0x42682b)[_0x0d41('0x12')](handleEntityNotFound(_0x3dd8fb,null))['then'](respondWithResult(_0x3dd8fb,null))['catch'](handleError(_0x3dd8fb,null));};exports[_0x0d41('0x2c')]=function(_0x4d70ec,_0x52ea66){return db[_0x0d41('0x20')]['create'](_0x4d70ec[_0x0d41('0x2d')],{})[_0x0d41('0x12')](function(_0x205cda){var _0x20cd3b=_0x4d70ec['user'][_0x0d41('0x13')]({'plain':!![]});if(!_0x20cd3b)throw new Error(_0x0d41('0x2e'));if(_0x20cd3b['role']==='user'){var _0x58fdfa=_0x205cda[_0x0d41('0x13')]({'plain':!![]});var _0xefac87=_0x0d41('0x14');return db[_0x0d41('0x2f')][_0x0d41('0x30')]({'where':{'name':_0xefac87,'userProfileId':_0x20cd3b[_0x0d41('0x31')]},'raw':!![]})['then'](function(_0x55146b){if(_0x55146b&&_0x55146b[_0x0d41('0x32')]===0x0){return db[_0x0d41('0x33')][_0x0d41('0x2c')]({'name':_0x58fdfa[_0x0d41('0x34')],'resourceId':_0x58fdfa['id'],'type':_0x55146b[_0x0d41('0x34')],'sectionId':_0x55146b['id']},{})[_0x0d41('0x12')](function(){return _0x205cda;});}else{return _0x205cda;}})['catch'](function(_0xd8e727){logger[_0x0d41('0x16')](_0x0d41('0x35'),_0xd8e727);throw _0xd8e727;});}return _0x205cda;})['then'](respondWithResult(_0x52ea66,0xc9))[_0x0d41('0x22')](handleError(_0x52ea66,null));};exports[_0x0d41('0x36')]=function(_0x501afc,_0x3ca358){if(_0x501afc[_0x0d41('0x2d')]['id']){delete _0x501afc['body']['id'];}return db[_0x0d41('0x20')]['find']({'where':{'id':_0x501afc['params']['id']}})[_0x0d41('0x12')](handleEntityNotFound(_0x3ca358,null))['then'](saveUpdates(_0x501afc[_0x0d41('0x2d')],null))['then'](respondWithResult(_0x3ca358,null))[_0x0d41('0x22')](handleError(_0x3ca358,null));};exports['destroy']=function(_0x36bc7d,_0x4b1371){return db[_0x0d41('0x20')][_0x0d41('0x30')]({'where':{'id':_0x36bc7d[_0x0d41('0x37')]['id']}})[_0x0d41('0x12')](handleEntityNotFound(_0x4b1371,null))[_0x0d41('0x12')](removeEntity(_0x4b1371,null))[_0x0d41('0x22')](handleError(_0x4b1371,null));};exports[_0x0d41('0x38')]=function(_0x5d80e0,_0x1efbd9){return db[_0x0d41('0x20')]['describe']()[_0x0d41('0x12')](respondWithResult(_0x1efbd9,null))[_0x0d41('0x22')](handleError(_0x1efbd9,null));};exports[_0x0d41('0x39')]=function(_0x537635,_0x56eea7){var _0x49b73a={'raw':!![],'where':{}},_0x73486={},_0xdbd497;return db[_0x0d41('0x20')][_0x0d41('0x3a')]({'where':{'id':_0x537635[_0x0d41('0x37')]['id']}})[_0x0d41('0x12')](handleEntityNotFound(_0x56eea7,null))[_0x0d41('0x12')](function(_0x5de101){if(_0x5de101){_0xdbd497=_0x5de101['get']({'plain':!![]});_0x73486[_0x0d41('0x24')]=_['keys'](db[_0x0d41('0x3b')][_0x0d41('0x18')]);_0x73486[_0x0d41('0x1f')]=_[_0x0d41('0x25')](_0x537635[_0x0d41('0x1f')]);_0x73486['filters']=_[_0x0d41('0x26')](_0x73486[_0x0d41('0x24')],_0x73486[_0x0d41('0x1f')]);_0x49b73a[_0x0d41('0x27')]=_[_0x0d41('0x26')](_0x73486['model'],qs[_0x0d41('0x28')](_0x537635['query'][_0x0d41('0x28')]));_0x49b73a[_0x0d41('0x27')]=_0x49b73a['attributes'][_0x0d41('0x3c')]?_0x49b73a['attributes']:_0x73486[_0x0d41('0x24')];if(!_0x537635['query'][_0x0d41('0x3d')](_0x0d41('0x3e'))){_0x49b73a[_0x0d41('0xe')]=qs[_0x0d41('0xe')](_0x537635['query'][_0x0d41('0xe')]);_0x49b73a[_0x0d41('0xc')]=qs[_0x0d41('0xc')](_0x537635[_0x0d41('0x1f')][_0x0d41('0xc')]);}_0x49b73a[_0x0d41('0x3f')]=qs[_0x0d41('0x40')](_0x537635[_0x0d41('0x1f')][_0x0d41('0x40')]);_0x49b73a['where']=qs[_0x0d41('0x41')](_[_0x0d41('0x42')](_0x537635[_0x0d41('0x1f')],_0x73486[_0x0d41('0x41')]));_0x49b73a[_0x0d41('0x1d')][_0x0d41('0x43')]=_0x5de101['id'];if(_0x537635[_0x0d41('0x1f')]['filter']){_0x49b73a[_0x0d41('0x1d')]=_[_0x0d41('0x2a')](_0x49b73a[_0x0d41('0x1d')],{'$or':_[_0x0d41('0x17')](_0x49b73a[_0x0d41('0x27')],function(_0x4e1b0f){var _0x54b35e={};_0x54b35e[_0x4e1b0f]={'$like':'%'+_0x537635[_0x0d41('0x1f')][_0x0d41('0x44')]+'%'};return _0x54b35e;})});}_0x49b73a=_[_0x0d41('0x2a')]({},_0x49b73a,_0x537635[_0x0d41('0x2b')]);return db['UserWhatsappQueue'][_0x0d41('0x45')](_0x49b73a);}})[_0x0d41('0x12')](function(_0x3c3e07){if(_0x3c3e07){return db[_0x0d41('0x46')][_0x0d41('0x47')]({'where':{'id':_[_0x0d41('0x17')](_0x3c3e07,_0x0d41('0x48')),'role':_0x0d41('0x49')},'attributes':['id',_0x0d41('0x34'),_0x0d41('0x4a'),_0x0d41('0x4b'),_0x0d41('0x4c')]});}})[_0x0d41('0x12')](function(_0x4e6c01){if(_0x4e6c01){return{'count':_0x4e6c01[_0x0d41('0xf')],'rows':_[_0x0d41('0x17')](_0x4e6c01['rows'],function(_0x2bcfe4){return{'membername':_0x2bcfe4['name'],'UserId':_0x2bcfe4['id'],'queue_name':_0xdbd497[_0x0d41('0x34')],'WhatsappQueueId':_0xdbd497['id'],'interface':util['format'](_0x0d41('0x4d'),_0x0d41('0x4e'),_0x2bcfe4['name']),'penalty':0x0,'paused':_0x2bcfe4[_0x0d41('0x4a')],'createdAt':_0x2bcfe4[_0x0d41('0x4c')],'updatedAt':_0x2bcfe4[_0x0d41('0x4b')]};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x56eea7,_0x49b73a))[_0x0d41('0x22')](handleError(_0x56eea7,null));};exports[_0x0d41('0x4f')]=function(_0x514d4b,_0x2c1693){var _0x47bc72={};var _0x1b5806={};var _0x26c782;var _0x52e7e7;return db[_0x0d41('0x20')]['findOne']({'where':{'id':_0x514d4b[_0x0d41('0x37')]['id']}})[_0x0d41('0x12')](handleEntityNotFound(_0x2c1693,null))[_0x0d41('0x12')](function(_0x275572){if(_0x275572){_0x26c782=_0x275572;_0x1b5806[_0x0d41('0x24')]=_[_0x0d41('0x25')](db[_0x0d41('0x50')][_0x0d41('0x18')]);_0x1b5806[_0x0d41('0x1f')]=_[_0x0d41('0x25')](_0x514d4b[_0x0d41('0x1f')]);_0x1b5806['filters']=_['intersection'](_0x1b5806[_0x0d41('0x24')],_0x1b5806['query']);_0x47bc72[_0x0d41('0x27')]=_[_0x0d41('0x26')](_0x1b5806['model'],qs[_0x0d41('0x28')](_0x514d4b[_0x0d41('0x1f')]['fields']));_0x47bc72[_0x0d41('0x27')]=_0x47bc72[_0x0d41('0x27')][_0x0d41('0x3c')]?_0x47bc72[_0x0d41('0x27')]:_0x1b5806[_0x0d41('0x24')];_0x47bc72['order']=qs[_0x0d41('0x40')](_0x514d4b[_0x0d41('0x1f')][_0x0d41('0x40')]);_0x47bc72[_0x0d41('0x1d')]=qs[_0x0d41('0x41')](_['pick'](_0x514d4b['query'],_0x1b5806[_0x0d41('0x41')]));if(_0x514d4b[_0x0d41('0x1f')][_0x0d41('0x44')]){_0x47bc72['where']=_[_0x0d41('0x2a')](_0x47bc72[_0x0d41('0x1d')],{'$or':_[_0x0d41('0x17')](_0x47bc72['attributes'],function(_0x3e024e){var _0x55d985={};_0x55d985[_0x3e024e]={'$like':'%'+_0x514d4b[_0x0d41('0x1f')][_0x0d41('0x44')]+'%'};return _0x55d985;})});}_0x47bc72=_['merge']({},_0x47bc72,_0x514d4b[_0x0d41('0x2b')]);return _0x26c782[_0x0d41('0x4f')](_0x47bc72);}})[_0x0d41('0x12')](function(_0x474ca7){if(_0x474ca7){_0x52e7e7=_0x474ca7['length'];if(!_0x514d4b[_0x0d41('0x1f')][_0x0d41('0x3d')](_0x0d41('0x3e'))){_0x47bc72[_0x0d41('0xe')]=qs['limit'](_0x514d4b[_0x0d41('0x1f')][_0x0d41('0xe')]);_0x47bc72[_0x0d41('0xc')]=qs['offset'](_0x514d4b[_0x0d41('0x1f')][_0x0d41('0xc')]);}return _0x26c782[_0x0d41('0x4f')](_0x47bc72);}})['then'](function(_0x2d5cf3){if(_0x2d5cf3){return _0x2d5cf3?{'count':_0x52e7e7,'rows':_0x2d5cf3}:null;}})[_0x0d41('0x12')](respondWithResult(_0x2c1693,null))[_0x0d41('0x22')](handleError(_0x2c1693,null));};exports[_0x0d41('0x51')]=function(_0xf17a9b,_0xe6a44e){var _0x1cc067=_0xf17a9b[_0x0d41('0x2d')][_0x0d41('0x52')];return db[_0x0d41('0x50')][_0x0d41('0x45')]({'where':{'id':_0x1cc067},'attributes':['id'],'include':[{'model':db[_0x0d41('0x46')],'as':'Agents','attributes':['id',_0x0d41('0x34'),_0x0d41('0x53'),_0x0d41('0x54'),_0x0d41('0x55')],'raw':!![]}]})[_0x0d41('0x12')](function(_0x2d7ab4){if(_0x2d7ab4){var _0x262b36=_['flatMap'](_0x2d7ab4,function(_0x5c6a5e){var _0x22c1a7=_0x5c6a5e[_0x0d41('0x13')]({'plain':!![]});return _0x22c1a7['Agents'];});return db[_0x0d41('0x20')]['find']({'where':{'id':_0xf17a9b['params']['id']}})[_0x0d41('0x12')](function(_0x3aafca){return db['sequelize'][_0x0d41('0x56')](function(_0x24d57c){return _0x3aafca[_0x0d41('0x51')](_0x1cc067,{'transaction':_0x24d57c})[_0x0d41('0x12')](function(){return BPromise['each'](_0x262b36,function(_0x52049b){return db[_0x0d41('0x3b')]['findOrCreate']({'where':{'UserId':_0x52049b['id'],'WhatsappQueueId':_0xf17a9b['params']['id']},'transaction':_0x24d57c});});})['then'](function(){_0x262b36[_0x0d41('0x57')](function(_0x1f1caa){socket[_0x0d41('0x58')](_0x0d41('0x59'),{'UserId':_0x1f1caa['id'],'WhatsappQueueId':_0x3aafca['id']});});});});});}})['then'](respondWithStatusCode(_0xe6a44e,null))['catch'](handleError(_0xe6a44e,null));};exports['removeTeams']=function(_0x1d2377,_0x4ce93a){return db[_0x0d41('0x50')][_0x0d41('0x45')]({'where':{'id':_0x1d2377[_0x0d41('0x1f')][_0x0d41('0x52')]},'attributes':['id'],'include':[{'model':db[_0x0d41('0x46')],'as':_0x0d41('0x5a'),'attributes':['id'],'raw':!![]}]})[_0x0d41('0x12')](handleEntityNotFound(_0x4ce93a,null))['then'](function(_0x3bf78b){var _0x324ecb=_[_0x0d41('0x17')](_0x3bf78b,'id');var _0x2a18a7=[];var _0x536040=[];var _0x2c81a8=squel[_0x0d41('0x5b')]();_0x2c81a8[_0x0d41('0x5c')]('tq.TeamId')['from']('team_has_whatsapp_queues','tq')[_0x0d41('0x5d')](_0x0d41('0x5e'),'ut',_0x0d41('0x5f'))[_0x0d41('0x1d')](_0x0d41('0x60'),_0x1d2377['params']['id']);for(var _0x4c8702=0x0;_0x4c8702<_0x3bf78b['length'];_0x4c8702+=0x1){let _0x1666b1=_0x3bf78b[_0x4c8702];for(var _0x5265d0=0x0;_0x5265d0<_0x1666b1['Agents']['length'];_0x5265d0+=0x1){let _0x596181=_0x1666b1[_0x0d41('0x5a')][_0x5265d0];var _0x7d02ac=_0x2c81a8[_0x0d41('0x61')]();_0x7d02ac['where'](_0x0d41('0x62'),_0x596181['id']);_0x536040[_0x0d41('0x63')](db['sequelize'][_0x0d41('0x1f')](_0x7d02ac[_0x0d41('0x64')](),{'type':db[_0x0d41('0x65')]['QueryTypes']['SELECT']})[_0x0d41('0x12')](function(_0x52f90d){if(_0x52f90d['length']===0x1){return _0x596181['id'];}else{var _0xff8874=_['every'](_[_0x0d41('0x17')](_0x52f90d,_0x0d41('0x66')),function(_0x5b00f8){return _[_0x0d41('0x67')](_0x324ecb,_0x5b00f8);});if(_0xff8874){return _0x596181['id'];}}}));}}return BPromise[_0x0d41('0x68')](_0x536040)['then'](function(_0x54a93e){_0x2a18a7=_(_0x2a18a7)['union'](_0x54a93e)['compact']()[_0x0d41('0x69')]();return db[_0x0d41('0x20')][_0x0d41('0x30')]({'where':{'id':_0x1d2377[_0x0d41('0x37')]['id']}})['then'](function(_0xd90fcf){return db[_0x0d41('0x65')][_0x0d41('0x56')](function(_0x936e78){return _0xd90fcf[_0x0d41('0x6a')](_0x1d2377['query'][_0x0d41('0x52')],{'transaction':_0x936e78})[_0x0d41('0x12')](function(){if(!_[_0x0d41('0x6b')](_0x2a18a7)){return _0xd90fcf[_0x0d41('0x6c')](_0x2a18a7,{'transaction':_0x936e78});}})[_0x0d41('0x12')](function(){_0x2a18a7[_0x0d41('0x57')](function(_0x41b5b3){socket[_0x0d41('0x58')](_0x0d41('0x6d'),{'UserId':_0x41b5b3,'WhatsappQueueId':_0xd90fcf['id']});});});});});});})[_0x0d41('0x12')](respondWithStatusCode(_0x4ce93a,null))[_0x0d41('0x22')](handleError(_0x4ce93a,null));};exports[_0x0d41('0x6e')]=function(_0x1fd35c,_0x29f366){return db[_0x0d41('0x20')][_0x0d41('0x30')]({'where':{'id':_0x1fd35c[_0x0d41('0x37')]['id']}})['then'](handleEntityNotFound(_0x29f366,null))[_0x0d41('0x12')](function(_0x33d190){if(_0x33d190){return _0x33d190['addAgents'](_0x1fd35c[_0x0d41('0x2d')][_0x0d41('0x52')],_[_0x0d41('0x6f')](_0x1fd35c['body'],[_0x0d41('0x52'),'id'])||{})[_0x0d41('0x70')](function(_0x18cd27){for(var _0x64df80=0x0;_0x64df80<_0x1fd35c[_0x0d41('0x2d')][_0x0d41('0x52')][_0x0d41('0x3c')];_0x64df80+=0x1){socket['emit'](_0x0d41('0x59'),{'UserId':Number(_0x1fd35c[_0x0d41('0x2d')]['ids'][_0x64df80]),'WhatsappQueueId':Number(_0x1fd35c[_0x0d41('0x37')]['id'])});}return _0x18cd27;});}})[_0x0d41('0x12')](respondWithResult(_0x29f366,null))[_0x0d41('0x22')](handleError(_0x29f366,null));};exports[_0x0d41('0x6c')]=function(_0x3645be,_0x5821f1){return db[_0x0d41('0x20')][_0x0d41('0x30')]({'where':{'id':_0x3645be['params']['id']}})[_0x0d41('0x12')](handleEntityNotFound(_0x5821f1,null))[_0x0d41('0x12')](function(_0x226214){if(_0x226214){return _0x226214[_0x0d41('0x6c')](_0x3645be[_0x0d41('0x1f')]['ids'])[_0x0d41('0x12')](function(){if(_[_0x0d41('0x71')](_0x3645be[_0x0d41('0x1f')][_0x0d41('0x52')])){for(var _0x2e8954=0x0;_0x2e8954<_0x3645be[_0x0d41('0x1f')][_0x0d41('0x52')][_0x0d41('0x3c')];_0x2e8954+=0x1){socket[_0x0d41('0x58')](_0x0d41('0x6d'),{'UserId':Number(_0x3645be[_0x0d41('0x1f')][_0x0d41('0x52')][_0x2e8954]),'WhatsappQueueId':Number(_0x3645be[_0x0d41('0x37')]['id'])});}}else{socket[_0x0d41('0x58')]('userWhatsappQueue:remove',{'UserId':Number(_0x3645be[_0x0d41('0x1f')]['ids']),'WhatsappQueueId':Number(_0x3645be[_0x0d41('0x37')]['id'])});}});}})['then'](respondWithStatusCode(_0x5821f1,null))[_0x0d41('0x22')](handleError(_0x5821f1,null));};exports[_0x0d41('0x72')]=function(_0x5bdb17,_0x450e7e){var _0x54b60d={};var _0x599e9e={};var _0x203ae3;var _0x42bab4;return db[_0x0d41('0x20')][_0x0d41('0x3a')]({'where':{'id':_0x5bdb17[_0x0d41('0x37')]['id']}})[_0x0d41('0x12')](handleEntityNotFound(_0x450e7e,null))[_0x0d41('0x12')](function(_0x258bcb){if(_0x258bcb){_0x203ae3=_0x258bcb;_0x599e9e[_0x0d41('0x24')]=_['keys'](db['User'][_0x0d41('0x18')]);_0x599e9e[_0x0d41('0x1f')]=_[_0x0d41('0x25')](_0x5bdb17[_0x0d41('0x1f')]);_0x599e9e[_0x0d41('0x41')]=_['intersection'](_0x599e9e['model'],_0x599e9e[_0x0d41('0x1f')]);_0x54b60d['attributes']=_[_0x0d41('0x26')](_0x599e9e[_0x0d41('0x24')],qs[_0x0d41('0x28')](_0x5bdb17[_0x0d41('0x1f')][_0x0d41('0x28')]));_0x54b60d[_0x0d41('0x27')]=_0x54b60d['attributes']['length']?_0x54b60d[_0x0d41('0x27')]:_0x599e9e[_0x0d41('0x24')];_0x54b60d['order']=qs[_0x0d41('0x40')](_0x5bdb17[_0x0d41('0x1f')]['sort']);_0x54b60d[_0x0d41('0x1d')]=qs[_0x0d41('0x41')](_[_0x0d41('0x42')](_0x5bdb17[_0x0d41('0x1f')],_0x599e9e['filters']));if(_0x5bdb17[_0x0d41('0x1f')][_0x0d41('0x44')]){_0x54b60d[_0x0d41('0x1d')]=_['merge'](_0x54b60d['where'],{'$or':_[_0x0d41('0x17')](_0x54b60d[_0x0d41('0x27')],function(_0x38fd1e){var _0x14cad8={};_0x14cad8[_0x38fd1e]={'$like':'%'+_0x5bdb17[_0x0d41('0x1f')][_0x0d41('0x44')]+'%'};return _0x14cad8;})});}_0x54b60d=_[_0x0d41('0x2a')]({},_0x54b60d,_0x5bdb17[_0x0d41('0x2b')]);return _0x203ae3['getAgents'](_0x54b60d);}})[_0x0d41('0x12')](function(_0x39470a){if(_0x39470a){_0x42bab4=_0x39470a[_0x0d41('0x3c')];if(!_0x5bdb17[_0x0d41('0x1f')][_0x0d41('0x3d')](_0x0d41('0x3e'))){_0x54b60d[_0x0d41('0xe')]=qs[_0x0d41('0xe')](_0x5bdb17[_0x0d41('0x1f')][_0x0d41('0xe')]);_0x54b60d[_0x0d41('0xc')]=qs[_0x0d41('0xc')](_0x5bdb17[_0x0d41('0x1f')][_0x0d41('0xc')]);}return _0x203ae3['getAgents'](_0x54b60d);}})[_0x0d41('0x12')](function(_0xf193e6){if(_0xf193e6){return _0xf193e6?{'count':_0x42bab4,'rows':_0xf193e6}:null;}})[_0x0d41('0x12')](respondWithResult(_0x450e7e,null))[_0x0d41('0x22')](handleError(_0x450e7e,null));};
\ No newline at end of file