Built motion from commit 97153652.|2.6.26
[motion2.git] / server / api / whatsappQueue / whatsappQueue.controller.js
index 89fb87f..2cc0b6d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5bde=['voicePause','interface','flatMap','sequelize','transaction','addTeams','userWhatsappQueue:save','ids','select','field','tq.TeamId','from','team_has_whatsapp_queues','join','ut.TeamId\x20=\x20tq.TeamId','WhatsappQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','toString','QueryTypes','SELECT','every','TeamId','all','compact','value','removeTeams','isEmpty','removeAgents','forEach','emit','userWhatsappQueue:remove','addAgents','omit','spread','isArray','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../config/license/util','redis','defaults','socket.io-emitter','register','sendStatus','status','json','offset','limit','undefined','count','set','Content-Range','reject','save','update','then','destroy','get','WhatsappQueues','UserProfileResource','end','stack','name','index','map','WhatsappQueue','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','where','merge','VIRTUAL','filter','includeAll','include','findAll','rows','catch','show','params','options','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','getMembers','findOne','UserWhatsappQueue','User','UserId','agent','whatsappPause','updatedAt','createdAt','%s/%s','getTeams','Team','Agents','online'];(function(_0x438283,_0x4961ae){var _0x62b5ab=function(_0x289958){while(--_0x289958){_0x438283['push'](_0x438283['shift']());}};_0x62b5ab(++_0x4961ae);}(_0x5bde,0x1c6));var _0xe5bd=function(_0x172dc4,_0xef717){_0x172dc4=_0x172dc4-0x0;var _0xb8e080=_0x5bde[_0x172dc4];return _0xb8e080;};'use strict';var emlformat=require(_0xe5bd('0x0'));var rimraf=require(_0xe5bd('0x1'));var zipdir=require(_0xe5bd('0x2'));var jsonpatch=require(_0xe5bd('0x3'));var rp=require('request-promise');var moment=require(_0xe5bd('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xe5bd('0x5'));var util=require(_0xe5bd('0x6'));var path=require(_0xe5bd('0x7'));var sox=require(_0xe5bd('0x8'));var csv=require(_0xe5bd('0x9'));var ejs=require(_0xe5bd('0xa'));var fs=require('fs');var fs_extra=require(_0xe5bd('0xb'));var _=require(_0xe5bd('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xe5bd('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xe5bd('0x9'));var querystring=require(_0xe5bd('0xe'));var Papa=require('papaparse');var Redis=require(_0xe5bd('0xf'));var authService=require(_0xe5bd('0x10'));var qs=require(_0xe5bd('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xe5bd('0x12'))(_0xe5bd('0x13'));var utils=require('../../config/utils');var config=require(_0xe5bd('0x14'));var licenseUtil=require(_0xe5bd('0x15'));var db=require('../../mysqldb')['db'];config[_0xe5bd('0x16')]=_[_0xe5bd('0x17')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xe5bd('0x18'))(new Redis(config['redis']));require('./whatsappQueue.socket')[_0xe5bd('0x19')](socket);function respondWithStatusCode(_0x226827,_0x57adb1){_0x57adb1=_0x57adb1||0xcc;return function(_0x2cd7bf){if(_0x2cd7bf){return _0x226827[_0xe5bd('0x1a')](_0x57adb1);}return _0x226827[_0xe5bd('0x1b')](_0x57adb1)['end']();};}function respondWithResult(_0x155d4d,_0x2825aa){_0x2825aa=_0x2825aa||0xc8;return function(_0x3662b8){if(_0x3662b8){return _0x155d4d[_0xe5bd('0x1b')](_0x2825aa)[_0xe5bd('0x1c')](_0x3662b8);}};}function respondWithFilteredResult(_0x3179d9,_0x1e7047){return function(_0x25e3a0){if(_0x25e3a0){var _0x4304a2=typeof _0x1e7047[_0xe5bd('0x1d')]==='undefined'&&typeof _0x1e7047[_0xe5bd('0x1e')]===_0xe5bd('0x1f');var _0x5db591=_0x25e3a0[_0xe5bd('0x20')];var _0x40b904=_0x4304a2?0x0:_0x1e7047[_0xe5bd('0x1d')];var _0x12824a=_0x4304a2?_0x25e3a0[_0xe5bd('0x20')]:_0x1e7047[_0xe5bd('0x1d')]+_0x1e7047[_0xe5bd('0x1e')];var _0x20573b;if(_0x12824a>=_0x5db591){_0x12824a=_0x5db591;_0x20573b=0xc8;}else{_0x20573b=0xce;}_0x3179d9[_0xe5bd('0x1b')](_0x20573b);return _0x3179d9[_0xe5bd('0x21')](_0xe5bd('0x22'),_0x40b904+'-'+_0x12824a+'/'+_0x5db591)[_0xe5bd('0x1c')](_0x25e3a0);}return null;};}function patchUpdates(_0x34d885){return function(_0x43932c){try{jsonpatch['apply'](_0x43932c,_0x34d885,!![]);}catch(_0x42609f){return BPromise[_0xe5bd('0x23')](_0x42609f);}return _0x43932c[_0xe5bd('0x24')]();};}function saveUpdates(_0x4fc6c3,_0x548da3){return function(_0x5c50d8){if(_0x5c50d8){return _0x5c50d8[_0xe5bd('0x25')](_0x4fc6c3)[_0xe5bd('0x26')](function(_0x211f8a){return _0x211f8a;});}return null;};}function removeEntity(_0xe9233e,_0x111808){return function(_0x8c0bd1){if(_0x8c0bd1){return _0x8c0bd1[_0xe5bd('0x27')]()['then'](function(){var _0x7f620d=_0x8c0bd1[_0xe5bd('0x28')]({'plain':!![]});var _0x386032=_0xe5bd('0x29');return db[_0xe5bd('0x2a')][_0xe5bd('0x27')]({'where':{'type':_0x386032,'resourceId':_0x7f620d['id']}})[_0xe5bd('0x26')](function(){return _0x8c0bd1;});})[_0xe5bd('0x26')](function(){_0xe9233e[_0xe5bd('0x1b')](0xcc)[_0xe5bd('0x2b')]();});}};}function handleEntityNotFound(_0x45f4e0,_0x51abd3){return function(_0x24602c){if(!_0x24602c){_0x45f4e0[_0xe5bd('0x1a')](0x194);}return _0x24602c;};}function handleError(_0x8a7394,_0x4e7ac8){_0x4e7ac8=_0x4e7ac8||0x1f4;return function(_0x1bef8c){logger['error'](_0x1bef8c[_0xe5bd('0x2c')]);if(_0x1bef8c[_0xe5bd('0x2d')]){delete _0x1bef8c['name'];}_0x8a7394[_0xe5bd('0x1b')](_0x4e7ac8)['send'](_0x1bef8c);};}exports[_0xe5bd('0x2e')]=function(_0x539e54,_0x43f1f7){var _0x2dbbb2={},_0x495739={},_0x496a32={'count':0x0,'rows':[]};var _0x3c60a=_[_0xe5bd('0x2f')](db[_0xe5bd('0x30')][_0xe5bd('0x31')],function(_0x5f040e){return{'name':_0x5f040e[_0xe5bd('0x32')],'type':_0x5f040e[_0xe5bd('0x33')][_0xe5bd('0x34')]};});_0x495739['model']=_[_0xe5bd('0x2f')](_0x3c60a,'name');_0x495739[_0xe5bd('0x35')]=_[_0xe5bd('0x36')](_0x539e54[_0xe5bd('0x35')]);_0x495739[_0xe5bd('0x37')]=_[_0xe5bd('0x38')](_0x495739[_0xe5bd('0x39')],_0x495739['query']);_0x2dbbb2[_0xe5bd('0x3a')]=_['intersection'](_0x495739['model'],qs[_0xe5bd('0x3b')](_0x539e54[_0xe5bd('0x35')][_0xe5bd('0x3b')]));_0x2dbbb2[_0xe5bd('0x3a')]=_0x2dbbb2[_0xe5bd('0x3a')][_0xe5bd('0x3c')]?_0x2dbbb2[_0xe5bd('0x3a')]:_0x495739['model'];if(!_0x539e54['query'][_0xe5bd('0x3d')](_0xe5bd('0x3e'))){_0x2dbbb2[_0xe5bd('0x1e')]=qs[_0xe5bd('0x1e')](_0x539e54[_0xe5bd('0x35')][_0xe5bd('0x1e')]);_0x2dbbb2[_0xe5bd('0x1d')]=qs['offset'](_0x539e54[_0xe5bd('0x35')][_0xe5bd('0x1d')]);}_0x2dbbb2[_0xe5bd('0x3f')]=qs[_0xe5bd('0x40')](_0x539e54[_0xe5bd('0x35')][_0xe5bd('0x40')]);_0x2dbbb2['where']=qs[_0xe5bd('0x37')](_[_0xe5bd('0x41')](_0x539e54['query'],_0x495739[_0xe5bd('0x37')]),_0x3c60a);if(_0x539e54['query']['filter']){_0x2dbbb2[_0xe5bd('0x42')]=_[_0xe5bd('0x43')](_0x2dbbb2[_0xe5bd('0x42')],{'$or':_[_0xe5bd('0x2f')](_0x3c60a,function(_0x2c395a){if(_0x2c395a['type']!==_0xe5bd('0x44')){var _0xf2238c={};_0xf2238c[_0x2c395a['name']]={'$like':'%'+_0x539e54['query'][_0xe5bd('0x45')]+'%'};return _0xf2238c;}})});}_0x2dbbb2=_[_0xe5bd('0x43')]({},_0x2dbbb2,_0x539e54['options']);var _0x2495e4={'where':_0x2dbbb2[_0xe5bd('0x42')]};return db[_0xe5bd('0x30')][_0xe5bd('0x20')](_0x2495e4)['then'](function(_0xa9ada6){_0x496a32[_0xe5bd('0x20')]=_0xa9ada6;if(_0x539e54[_0xe5bd('0x35')][_0xe5bd('0x46')]){_0x2dbbb2[_0xe5bd('0x47')]=[{'all':!![]}];}return db[_0xe5bd('0x30')][_0xe5bd('0x48')](_0x2dbbb2);})['then'](function(_0x1392a3){_0x496a32[_0xe5bd('0x49')]=_0x1392a3;return _0x496a32;})[_0xe5bd('0x26')](respondWithFilteredResult(_0x43f1f7,_0x2dbbb2))[_0xe5bd('0x4a')](handleError(_0x43f1f7,null));};exports[_0xe5bd('0x4b')]=function(_0x3af418,_0x5f5233){var _0x3e0edd={'raw':!![],'where':{'id':_0x3af418[_0xe5bd('0x4c')]['id']}},_0x430264={};_0x430264['model']=_['keys'](db['WhatsappQueue']['rawAttributes']);_0x430264[_0xe5bd('0x35')]=_['keys'](_0x3af418['query']);_0x430264['filters']=_['intersection'](_0x430264['model'],_0x430264[_0xe5bd('0x35')]);_0x3e0edd['attributes']=_['intersection'](_0x430264['model'],qs['fields'](_0x3af418['query']['fields']));_0x3e0edd[_0xe5bd('0x3a')]=_0x3e0edd[_0xe5bd('0x3a')][_0xe5bd('0x3c')]?_0x3e0edd[_0xe5bd('0x3a')]:_0x430264[_0xe5bd('0x39')];if(_0x3af418[_0xe5bd('0x35')][_0xe5bd('0x46')]){_0x3e0edd[_0xe5bd('0x47')]=[{'all':!![]}];}_0x3e0edd=_['merge']({},_0x3e0edd,_0x3af418[_0xe5bd('0x4d')]);return db[_0xe5bd('0x30')][_0xe5bd('0x4e')](_0x3e0edd)[_0xe5bd('0x26')](handleEntityNotFound(_0x5f5233,null))[_0xe5bd('0x26')](respondWithResult(_0x5f5233,null))[_0xe5bd('0x4a')](handleError(_0x5f5233,null));};exports[_0xe5bd('0x4f')]=function(_0xcf0e7c,_0x305f0b){return db[_0xe5bd('0x30')]['create'](_0xcf0e7c['body'],{})['then'](function(_0x4119ec){var _0x449e08=_0xcf0e7c[_0xe5bd('0x50')][_0xe5bd('0x28')]({'plain':!![]});if(!_0x449e08)throw new Error(_0xe5bd('0x51'));if(_0x449e08['role']===_0xe5bd('0x50')){var _0x4f74f7=_0x4119ec[_0xe5bd('0x28')]({'plain':!![]});var _0x24b143=_0xe5bd('0x29');return db['UserProfileSection']['find']({'where':{'name':_0x24b143,'userProfileId':_0x449e08[_0xe5bd('0x52')]},'raw':!![]})[_0xe5bd('0x26')](function(_0x5190c4){if(_0x5190c4&&_0x5190c4[_0xe5bd('0x53')]===0x0){return db[_0xe5bd('0x2a')][_0xe5bd('0x4f')]({'name':_0x4f74f7['name'],'resourceId':_0x4f74f7['id'],'type':_0x5190c4[_0xe5bd('0x2d')],'sectionId':_0x5190c4['id']},{})[_0xe5bd('0x26')](function(){return _0x4119ec;});}else{return _0x4119ec;}})[_0xe5bd('0x4a')](function(_0x3832c5){logger[_0xe5bd('0x54')](_0xe5bd('0x55'),_0x3832c5);throw _0x3832c5;});}return _0x4119ec;})[_0xe5bd('0x26')](respondWithResult(_0x305f0b,0xc9))['catch'](handleError(_0x305f0b,null));};exports['update']=function(_0x368894,_0x38fc12){if(_0x368894['body']['id']){delete _0x368894[_0xe5bd('0x56')]['id'];}return db['WhatsappQueue'][_0xe5bd('0x4e')]({'where':{'id':_0x368894[_0xe5bd('0x4c')]['id']}})[_0xe5bd('0x26')](handleEntityNotFound(_0x38fc12,null))[_0xe5bd('0x26')](saveUpdates(_0x368894['body'],null))[_0xe5bd('0x26')](respondWithResult(_0x38fc12,null))['catch'](handleError(_0x38fc12,null));};exports[_0xe5bd('0x27')]=function(_0x536c6a,_0x2c2c65){return db['WhatsappQueue']['find']({'where':{'id':_0x536c6a[_0xe5bd('0x4c')]['id']}})[_0xe5bd('0x26')](handleEntityNotFound(_0x2c2c65,null))[_0xe5bd('0x26')](removeEntity(_0x2c2c65,null))[_0xe5bd('0x4a')](handleError(_0x2c2c65,null));};exports['describe']=function(_0x1c8b9d,_0x2971f4){return db[_0xe5bd('0x30')][_0xe5bd('0x57')]()['then'](respondWithResult(_0x2971f4,null))[_0xe5bd('0x4a')](handleError(_0x2971f4,null));};exports[_0xe5bd('0x58')]=function(_0x55e7d6,_0x5c4de8,_0x3be123){var _0x4bc99e={'raw':!![],'where':{}},_0x556ca2={},_0x381664;return db[_0xe5bd('0x30')][_0xe5bd('0x59')]({'where':{'id':_0x55e7d6['params']['id']}})['then'](handleEntityNotFound(_0x5c4de8,null))[_0xe5bd('0x26')](function(_0x50d0bf){if(_0x50d0bf){_0x381664=_0x50d0bf[_0xe5bd('0x28')]({'plain':!![]});_0x556ca2[_0xe5bd('0x39')]=_[_0xe5bd('0x36')](db[_0xe5bd('0x5a')]['rawAttributes']);_0x556ca2[_0xe5bd('0x35')]=_[_0xe5bd('0x36')](_0x55e7d6['query']);_0x556ca2[_0xe5bd('0x37')]=_[_0xe5bd('0x38')](_0x556ca2[_0xe5bd('0x39')],_0x556ca2['query']);_0x4bc99e['attributes']=_[_0xe5bd('0x38')](_0x556ca2['model'],qs[_0xe5bd('0x3b')](_0x55e7d6[_0xe5bd('0x35')][_0xe5bd('0x3b')]));_0x4bc99e[_0xe5bd('0x3a')]=_0x4bc99e[_0xe5bd('0x3a')][_0xe5bd('0x3c')]?_0x4bc99e[_0xe5bd('0x3a')]:_0x556ca2[_0xe5bd('0x39')];if(!_0x55e7d6[_0xe5bd('0x35')][_0xe5bd('0x3d')](_0xe5bd('0x3e'))){_0x4bc99e[_0xe5bd('0x1e')]=qs['limit'](_0x55e7d6[_0xe5bd('0x35')][_0xe5bd('0x1e')]);_0x4bc99e[_0xe5bd('0x1d')]=qs[_0xe5bd('0x1d')](_0x55e7d6['query'][_0xe5bd('0x1d')]);}_0x4bc99e[_0xe5bd('0x3f')]=qs[_0xe5bd('0x40')](_0x55e7d6[_0xe5bd('0x35')][_0xe5bd('0x40')]);_0x4bc99e[_0xe5bd('0x42')]=qs[_0xe5bd('0x37')](_[_0xe5bd('0x41')](_0x55e7d6[_0xe5bd('0x35')],_0x556ca2[_0xe5bd('0x37')]));_0x4bc99e[_0xe5bd('0x42')]['WhatsappQueueId']=_0x50d0bf['id'];if(_0x55e7d6['query'][_0xe5bd('0x45')]){_0x4bc99e['where']=_[_0xe5bd('0x43')](_0x4bc99e['where'],{'$or':_[_0xe5bd('0x2f')](_0x4bc99e[_0xe5bd('0x3a')],function(_0x382615){var _0x2ebe73={};_0x2ebe73[_0x382615]={'$like':'%'+_0x55e7d6[_0xe5bd('0x35')]['filter']+'%'};return _0x2ebe73;})});}_0x4bc99e=_[_0xe5bd('0x43')]({},_0x4bc99e,_0x55e7d6[_0xe5bd('0x4d')]);return db[_0xe5bd('0x5a')][_0xe5bd('0x48')](_0x4bc99e);}})['then'](function(_0x367af6){if(_0x367af6){return db[_0xe5bd('0x5b')]['findAndCountAll']({'where':{'id':_[_0xe5bd('0x2f')](_0x367af6,_0xe5bd('0x5c')),'role':_0xe5bd('0x5d')},'attributes':['id','name',_0xe5bd('0x5e'),_0xe5bd('0x5f'),_0xe5bd('0x60')]});}})[_0xe5bd('0x26')](function(_0x1cc0ce){if(_0x1cc0ce){return{'count':_0x1cc0ce[_0xe5bd('0x20')],'rows':_[_0xe5bd('0x2f')](_0x1cc0ce[_0xe5bd('0x49')],function(_0x3107eb){return{'membername':_0x3107eb[_0xe5bd('0x2d')],'UserId':_0x3107eb['id'],'queue_name':_0x381664[_0xe5bd('0x2d')],'WhatsappQueueId':_0x381664['id'],'interface':util['format'](_0xe5bd('0x61'),'SIP',_0x3107eb[_0xe5bd('0x2d')]),'penalty':0x0,'paused':_0x3107eb['whatsappPause'],'createdAt':_0x3107eb[_0xe5bd('0x60')],'updatedAt':_0x3107eb[_0xe5bd('0x5f')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xe5bd('0x26')](respondWithFilteredResult(_0x5c4de8,_0x4bc99e))[_0xe5bd('0x4a')](handleError(_0x5c4de8,null));};exports[_0xe5bd('0x62')]=function(_0x58c0e3,_0x59e2b7,_0x99fdda){var _0x166277={};var _0x4a81bd={};var _0x278b82;var _0x3550ec;return db[_0xe5bd('0x30')][_0xe5bd('0x59')]({'where':{'id':_0x58c0e3['params']['id']}})[_0xe5bd('0x26')](handleEntityNotFound(_0x59e2b7,null))[_0xe5bd('0x26')](function(_0x4358e6){if(_0x4358e6){_0x278b82=_0x4358e6;_0x4a81bd['model']=_[_0xe5bd('0x36')](db[_0xe5bd('0x63')][_0xe5bd('0x31')]);_0x4a81bd[_0xe5bd('0x35')]=_['keys'](_0x58c0e3[_0xe5bd('0x35')]);_0x4a81bd[_0xe5bd('0x37')]=_['intersection'](_0x4a81bd[_0xe5bd('0x39')],_0x4a81bd[_0xe5bd('0x35')]);_0x166277['attributes']=_['intersection'](_0x4a81bd[_0xe5bd('0x39')],qs[_0xe5bd('0x3b')](_0x58c0e3['query']['fields']));_0x166277['attributes']=_0x166277['attributes']['length']?_0x166277[_0xe5bd('0x3a')]:_0x4a81bd[_0xe5bd('0x39')];_0x166277[_0xe5bd('0x3f')]=qs[_0xe5bd('0x40')](_0x58c0e3['query'][_0xe5bd('0x40')]);_0x166277[_0xe5bd('0x42')]=qs[_0xe5bd('0x37')](_['pick'](_0x58c0e3[_0xe5bd('0x35')],_0x4a81bd['filters']));if(_0x58c0e3[_0xe5bd('0x35')][_0xe5bd('0x45')]){_0x166277['where']=_[_0xe5bd('0x43')](_0x166277[_0xe5bd('0x42')],{'$or':_['map'](_0x166277['attributes'],function(_0x4cea05){var _0x17f579={};_0x17f579[_0x4cea05]={'$like':'%'+_0x58c0e3[_0xe5bd('0x35')][_0xe5bd('0x45')]+'%'};return _0x17f579;})});}_0x166277=_[_0xe5bd('0x43')]({},_0x166277,_0x58c0e3[_0xe5bd('0x4d')]);return _0x278b82[_0xe5bd('0x62')](_0x166277);}})['then'](function(_0x53e441){if(_0x53e441){_0x3550ec=_0x53e441[_0xe5bd('0x3c')];if(!_0x58c0e3['query'][_0xe5bd('0x3d')]('nolimit')){_0x166277['limit']=qs[_0xe5bd('0x1e')](_0x58c0e3[_0xe5bd('0x35')][_0xe5bd('0x1e')]);_0x166277[_0xe5bd('0x1d')]=qs[_0xe5bd('0x1d')](_0x58c0e3[_0xe5bd('0x35')]['offset']);}return _0x278b82[_0xe5bd('0x62')](_0x166277);}})[_0xe5bd('0x26')](function(_0x40c676){if(_0x40c676){return _0x40c676?{'count':_0x3550ec,'rows':_0x40c676}:null;}})[_0xe5bd('0x26')](respondWithResult(_0x59e2b7,null))[_0xe5bd('0x4a')](handleError(_0x59e2b7,null));};exports['addTeams']=function(_0x8e7438,_0x2c5173,_0x199afc){var _0x511df1=_0x8e7438['body']['ids'];return db[_0xe5bd('0x63')]['findAll']({'where':{'id':_0x511df1},'attributes':['id'],'include':[{'model':db['User'],'as':_0xe5bd('0x64'),'attributes':['id',_0xe5bd('0x2d'),_0xe5bd('0x65'),_0xe5bd('0x66'),_0xe5bd('0x67')],'raw':!![]}]})[_0xe5bd('0x26')](function(_0x33e90e){if(_0x33e90e){var _0x457f91=_[_0xe5bd('0x68')](_0x33e90e,function(_0x2292f1){var _0x368724=_0x2292f1['get']({'plain':!![]});return _0x368724[_0xe5bd('0x64')];});return db['WhatsappQueue']['find']({'where':{'id':_0x8e7438[_0xe5bd('0x4c')]['id']}})[_0xe5bd('0x26')](function(_0x5243d8){return db[_0xe5bd('0x69')][_0xe5bd('0x6a')](function(_0x2b7a08){return _0x5243d8[_0xe5bd('0x6b')](_0x511df1,{'transaction':_0x2b7a08})['then'](function(){return BPromise['each'](_0x457f91,function(_0x504a7f){return db['UserWhatsappQueue']['findOrCreate']({'where':{'UserId':_0x504a7f['id'],'WhatsappQueueId':_0x8e7438[_0xe5bd('0x4c')]['id']},'transaction':_0x2b7a08});});})['then'](function(){_0x457f91['forEach'](function(_0x56c0cc){socket['emit'](_0xe5bd('0x6c'),{'UserId':_0x56c0cc['id'],'WhatsappQueueId':_0x5243d8['id']});});});});});}})['then'](respondWithStatusCode(_0x2c5173,null))['catch'](handleError(_0x2c5173,null));};exports['removeTeams']=function(_0x25a538,_0x3652c3,_0x51a57e){return db[_0xe5bd('0x63')][_0xe5bd('0x48')]({'where':{'id':_0x25a538[_0xe5bd('0x35')][_0xe5bd('0x6d')]},'attributes':['id'],'include':[{'model':db[_0xe5bd('0x5b')],'as':_0xe5bd('0x64'),'attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x3652c3,null))[_0xe5bd('0x26')](function(_0x1bee94){var _0x190712=_[_0xe5bd('0x2f')](_0x1bee94,'id');var _0x1a536=[];var _0x1e5192=[];var _0x40c2d5=squel[_0xe5bd('0x6e')]();_0x40c2d5[_0xe5bd('0x6f')](_0xe5bd('0x70'))[_0xe5bd('0x71')](_0xe5bd('0x72'),'tq')[_0xe5bd('0x73')]('user_has_teams','ut',_0xe5bd('0x74'))[_0xe5bd('0x42')](_0xe5bd('0x75'),_0x25a538[_0xe5bd('0x4c')]['id']);for(var _0x1ca0a3=0x0;_0x1ca0a3<_0x1bee94[_0xe5bd('0x3c')];_0x1ca0a3+=0x1){let _0x35a749=_0x1bee94[_0x1ca0a3];for(var _0x46df88=0x0;_0x46df88<_0x35a749[_0xe5bd('0x64')][_0xe5bd('0x3c')];_0x46df88+=0x1){let _0x3dcb44=_0x35a749['Agents'][_0x46df88];var _0x55b561=_0x40c2d5[_0xe5bd('0x76')]();_0x55b561[_0xe5bd('0x42')](_0xe5bd('0x77'),_0x3dcb44['id']);_0x1e5192['push'](db['sequelize'][_0xe5bd('0x35')](_0x55b561[_0xe5bd('0x78')](),{'type':db[_0xe5bd('0x69')][_0xe5bd('0x79')][_0xe5bd('0x7a')]})[_0xe5bd('0x26')](function(_0x456fce){if(_0x456fce[_0xe5bd('0x3c')]===0x1){return _0x3dcb44['id'];}else{var _0x43adf3=_[_0xe5bd('0x7b')](_[_0xe5bd('0x2f')](_0x456fce,_0xe5bd('0x7c')),function(_0x4c62c2){return _['includes'](_0x190712,_0x4c62c2);});if(_0x43adf3){return _0x3dcb44['id'];}}}));}}return BPromise[_0xe5bd('0x7d')](_0x1e5192)[_0xe5bd('0x26')](function(_0x513c01){_0x1a536=_(_0x1a536)['union'](_0x513c01)[_0xe5bd('0x7e')]()[_0xe5bd('0x7f')]();return db[_0xe5bd('0x30')]['find']({'where':{'id':_0x25a538['params']['id']}})['then'](function(_0x1ee92b){return db['sequelize'][_0xe5bd('0x6a')](function(_0x3a3b2e){return _0x1ee92b[_0xe5bd('0x80')](_0x25a538[_0xe5bd('0x35')][_0xe5bd('0x6d')],{'transaction':_0x3a3b2e})[_0xe5bd('0x26')](function(){if(!_[_0xe5bd('0x81')](_0x1a536)){return _0x1ee92b[_0xe5bd('0x82')](_0x1a536,{'transaction':_0x3a3b2e});}})[_0xe5bd('0x26')](function(){_0x1a536[_0xe5bd('0x83')](function(_0x190ecb){socket[_0xe5bd('0x84')](_0xe5bd('0x85'),{'UserId':_0x190ecb,'WhatsappQueueId':_0x1ee92b['id']});});});});});});})[_0xe5bd('0x26')](respondWithStatusCode(_0x3652c3,null))[_0xe5bd('0x4a')](handleError(_0x3652c3,null));};exports['addAgents']=function(_0x1bd31c,_0x5e4a6f,_0x22a188){return db[_0xe5bd('0x30')][_0xe5bd('0x4e')]({'where':{'id':_0x1bd31c[_0xe5bd('0x4c')]['id']}})[_0xe5bd('0x26')](handleEntityNotFound(_0x5e4a6f,null))['then'](function(_0x168695){if(_0x168695){return _0x168695[_0xe5bd('0x86')](_0x1bd31c[_0xe5bd('0x56')][_0xe5bd('0x6d')],_[_0xe5bd('0x87')](_0x1bd31c[_0xe5bd('0x56')],['ids','id'])||{})[_0xe5bd('0x88')](function(_0x34782c){for(var _0x1686c5=0x0;_0x1686c5<_0x1bd31c[_0xe5bd('0x56')]['ids']['length'];_0x1686c5+=0x1){socket[_0xe5bd('0x84')]('userWhatsappQueue:save',{'UserId':Number(_0x1bd31c[_0xe5bd('0x56')]['ids'][_0x1686c5]),'WhatsappQueueId':Number(_0x1bd31c[_0xe5bd('0x4c')]['id'])});}return _0x34782c;});}})[_0xe5bd('0x26')](respondWithResult(_0x5e4a6f,null))[_0xe5bd('0x4a')](handleError(_0x5e4a6f,null));};exports['removeAgents']=function(_0x4c166e,_0x253cd3,_0x4289b9){return db[_0xe5bd('0x30')]['find']({'where':{'id':_0x4c166e['params']['id']}})[_0xe5bd('0x26')](handleEntityNotFound(_0x253cd3,null))[_0xe5bd('0x26')](function(_0x2406d7){if(_0x2406d7){return _0x2406d7['removeAgents'](_0x4c166e[_0xe5bd('0x35')]['ids'])[_0xe5bd('0x26')](function(){if(_[_0xe5bd('0x89')](_0x4c166e[_0xe5bd('0x35')][_0xe5bd('0x6d')])){for(var _0x341e82=0x0;_0x341e82<_0x4c166e[_0xe5bd('0x35')]['ids']['length'];_0x341e82+=0x1){socket[_0xe5bd('0x84')](_0xe5bd('0x85'),{'UserId':Number(_0x4c166e[_0xe5bd('0x35')]['ids'][_0x341e82]),'WhatsappQueueId':Number(_0x4c166e['params']['id'])});}}else{socket[_0xe5bd('0x84')](_0xe5bd('0x85'),{'UserId':Number(_0x4c166e[_0xe5bd('0x35')][_0xe5bd('0x6d')]),'WhatsappQueueId':Number(_0x4c166e[_0xe5bd('0x4c')]['id'])});}});}})[_0xe5bd('0x26')](respondWithStatusCode(_0x253cd3,null))['catch'](handleError(_0x253cd3,null));};exports['getAgents']=function(_0x475435,_0x54b627,_0x5e9100){var _0x40f80c={};var _0x17e3fb={};var _0x5b0e1e;var _0x44dcee;return db[_0xe5bd('0x30')][_0xe5bd('0x59')]({'where':{'id':_0x475435['params']['id']}})[_0xe5bd('0x26')](handleEntityNotFound(_0x54b627,null))['then'](function(_0x1fb3be){if(_0x1fb3be){_0x5b0e1e=_0x1fb3be;_0x17e3fb[_0xe5bd('0x39')]=_['keys'](db['User']['rawAttributes']);_0x17e3fb[_0xe5bd('0x35')]=_[_0xe5bd('0x36')](_0x475435[_0xe5bd('0x35')]);_0x17e3fb[_0xe5bd('0x37')]=_['intersection'](_0x17e3fb['model'],_0x17e3fb[_0xe5bd('0x35')]);_0x40f80c[_0xe5bd('0x3a')]=_[_0xe5bd('0x38')](_0x17e3fb['model'],qs[_0xe5bd('0x3b')](_0x475435[_0xe5bd('0x35')][_0xe5bd('0x3b')]));_0x40f80c[_0xe5bd('0x3a')]=_0x40f80c[_0xe5bd('0x3a')][_0xe5bd('0x3c')]?_0x40f80c[_0xe5bd('0x3a')]:_0x17e3fb[_0xe5bd('0x39')];_0x40f80c['order']=qs[_0xe5bd('0x40')](_0x475435[_0xe5bd('0x35')]['sort']);_0x40f80c[_0xe5bd('0x42')]=qs[_0xe5bd('0x37')](_[_0xe5bd('0x41')](_0x475435[_0xe5bd('0x35')],_0x17e3fb['filters']));if(_0x475435[_0xe5bd('0x35')][_0xe5bd('0x45')]){_0x40f80c[_0xe5bd('0x42')]=_['merge'](_0x40f80c[_0xe5bd('0x42')],{'$or':_[_0xe5bd('0x2f')](_0x40f80c[_0xe5bd('0x3a')],function(_0x2a0300){var _0x548e9d={};_0x548e9d[_0x2a0300]={'$like':'%'+_0x475435[_0xe5bd('0x35')][_0xe5bd('0x45')]+'%'};return _0x548e9d;})});}_0x40f80c=_['merge']({},_0x40f80c,_0x475435[_0xe5bd('0x4d')]);return _0x5b0e1e[_0xe5bd('0x8a')](_0x40f80c);}})[_0xe5bd('0x26')](function(_0x2aad8b){if(_0x2aad8b){_0x44dcee=_0x2aad8b[_0xe5bd('0x3c')];if(!_0x475435[_0xe5bd('0x35')][_0xe5bd('0x3d')](_0xe5bd('0x3e'))){_0x40f80c[_0xe5bd('0x1e')]=qs[_0xe5bd('0x1e')](_0x475435[_0xe5bd('0x35')][_0xe5bd('0x1e')]);_0x40f80c[_0xe5bd('0x1d')]=qs[_0xe5bd('0x1d')](_0x475435['query'][_0xe5bd('0x1d')]);}return _0x5b0e1e[_0xe5bd('0x8a')](_0x40f80c);}})[_0xe5bd('0x26')](function(_0x5aae7a){if(_0x5aae7a){return _0x5aae7a?{'count':_0x44dcee,'rows':_0x5aae7a}:null;}})[_0xe5bd('0x26')](respondWithResult(_0x54b627,null))['catch'](handleError(_0x54b627,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