Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / whatsappQueue / whatsappQueue.controller.js
index 8cafb7d..5ff3fb2 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x204e=['WhatsappQueueId','UserWhatsappQueue','User','findAndCountAll','UserId','agent','whatsappPause','updatedAt','%s/%s','SIP','createdAt','getTeams','Team','addTeams','ids','Agents','online','interface','flatMap','sequelize','transaction','each','findOrCreate','userWhatsappQueue:save','removeTeams','field','from','team_has_whatsapp_queues','join','user_has_teams','WhatsappQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','all','union','value','isEmpty','removeAgents','emit','userWhatsappQueue:remove','addAgents','omit','spread','isArray','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../mysqldb','redis','socket.io-emitter','./whatsappQueue.socket','sendStatus','status','end','json','offset','undefined','count','set','Content-Range','apply','reject','save','update','then','destroy','get','WhatsappQueues','UserProfileResource','error','stack','name','send','map','WhatsappQueue','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','findAll','rows','catch','show','params','keys','rawAttributes','includeAll','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','findOne'];(function(_0x7e918f,_0x48cf10){var _0x5b35ab=function(_0x1455be){while(--_0x1455be){_0x7e918f['push'](_0x7e918f['shift']());}};_0x5b35ab(++_0x48cf10);}(_0x204e,0xc8));var _0xe204=function(_0x1f2186,_0x5eb77f){_0x1f2186=_0x1f2186-0x0;var _0x3b6279=_0x204e[_0x1f2186];return _0x3b6279;};'use strict';var emlformat=require(_0xe204('0x0'));var rimraf=require(_0xe204('0x1'));var zipdir=require(_0xe204('0x2'));var jsonpatch=require(_0xe204('0x3'));var rp=require(_0xe204('0x4'));var moment=require(_0xe204('0x5'));var BPromise=require(_0xe204('0x6'));var Mustache=require(_0xe204('0x7'));var util=require(_0xe204('0x8'));var path=require(_0xe204('0x9'));var sox=require(_0xe204('0xa'));var csv=require(_0xe204('0xb'));var ejs=require(_0xe204('0xc'));var fs=require('fs');var fs_extra=require(_0xe204('0xd'));var _=require(_0xe204('0xe'));var squel=require(_0xe204('0xf'));var crypto=require(_0xe204('0x10'));var jsforce=require(_0xe204('0x11'));var deskjs=require(_0xe204('0x12'));var toCsv=require(_0xe204('0xb'));var querystring=require(_0xe204('0x13'));var Papa=require(_0xe204('0x14'));var Redis=require(_0xe204('0x15'));var authService=require('../../components/auth/service');var qs=require(_0xe204('0x16'));var as=require(_0xe204('0x17'));var hardwareService=require(_0xe204('0x18'));var logger=require('../../config/logger')(_0xe204('0x19'));var utils=require('../../config/utils');var config=require(_0xe204('0x1a'));var licenseUtil=require('../../config/license/util');var db=require(_0xe204('0x1b'))['db'];config[_0xe204('0x1c')]=_['defaults'](config[_0xe204('0x1c')],{'host':'localhost','port':0x18eb});var socket=require(_0xe204('0x1d'))(new Redis(config[_0xe204('0x1c')]));require(_0xe204('0x1e'))['register'](socket);function respondWithStatusCode(_0x56d7a2,_0x44aa32){_0x44aa32=_0x44aa32||0xcc;return function(_0x2ab01a){if(_0x2ab01a){return _0x56d7a2[_0xe204('0x1f')](_0x44aa32);}return _0x56d7a2[_0xe204('0x20')](_0x44aa32)[_0xe204('0x21')]();};}function respondWithResult(_0x321718,_0x35137f){_0x35137f=_0x35137f||0xc8;return function(_0x4ef01a){if(_0x4ef01a){return _0x321718['status'](_0x35137f)[_0xe204('0x22')](_0x4ef01a);}};}function respondWithFilteredResult(_0xbc4d0,_0x2974c0){return function(_0x5b2da1){if(_0x5b2da1){var _0x1a9ce3=typeof _0x2974c0[_0xe204('0x23')]===_0xe204('0x24')&&typeof _0x2974c0['limit']===_0xe204('0x24');var _0x166d2a=_0x5b2da1[_0xe204('0x25')];var _0x2eaa95=_0x1a9ce3?0x0:_0x2974c0[_0xe204('0x23')];var _0x294b59=_0x1a9ce3?_0x5b2da1[_0xe204('0x25')]:_0x2974c0[_0xe204('0x23')]+_0x2974c0['limit'];var _0x3be5ab;if(_0x294b59>=_0x166d2a){_0x294b59=_0x166d2a;_0x3be5ab=0xc8;}else{_0x3be5ab=0xce;}_0xbc4d0[_0xe204('0x20')](_0x3be5ab);return _0xbc4d0[_0xe204('0x26')](_0xe204('0x27'),_0x2eaa95+'-'+_0x294b59+'/'+_0x166d2a)['json'](_0x5b2da1);}return null;};}function patchUpdates(_0x1d9dac){return function(_0xcbbc3a){try{jsonpatch[_0xe204('0x28')](_0xcbbc3a,_0x1d9dac,!![]);}catch(_0x3d8524){return BPromise[_0xe204('0x29')](_0x3d8524);}return _0xcbbc3a[_0xe204('0x2a')]();};}function saveUpdates(_0x45709c,_0x3302c3){return function(_0x375d95){if(_0x375d95){return _0x375d95[_0xe204('0x2b')](_0x45709c)[_0xe204('0x2c')](function(_0xab1163){return _0xab1163;});}return null;};}function removeEntity(_0x2199ae,_0x18e5c4){return function(_0x255228){if(_0x255228){return _0x255228[_0xe204('0x2d')]()['then'](function(){var _0x478031=_0x255228[_0xe204('0x2e')]({'plain':!![]});var _0x383abb=_0xe204('0x2f');return db[_0xe204('0x30')][_0xe204('0x2d')]({'where':{'type':_0x383abb,'resourceId':_0x478031['id']}})[_0xe204('0x2c')](function(){return _0x255228;});})[_0xe204('0x2c')](function(){_0x2199ae[_0xe204('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x35e0c0,_0x483d73){return function(_0xee9952){if(!_0xee9952){_0x35e0c0['sendStatus'](0x194);}return _0xee9952;};}function handleError(_0x68f602,_0x1ce6eb){_0x1ce6eb=_0x1ce6eb||0x1f4;return function(_0x43f5f0){logger[_0xe204('0x31')](_0x43f5f0[_0xe204('0x32')]);if(_0x43f5f0[_0xe204('0x33')]){delete _0x43f5f0[_0xe204('0x33')];}_0x68f602['status'](_0x1ce6eb)[_0xe204('0x34')](_0x43f5f0);};}exports['index']=function(_0x58dc65,_0x239b91){var _0x2502ed={},_0x227a0b={},_0x5db06b={'count':0x0,'rows':[]};var _0x4a80b2=_[_0xe204('0x35')](db[_0xe204('0x36')]['rawAttributes'],function(_0xff602a){return{'name':_0xff602a[_0xe204('0x37')],'type':_0xff602a[_0xe204('0x38')][_0xe204('0x39')]};});_0x227a0b[_0xe204('0x3a')]=_[_0xe204('0x35')](_0x4a80b2,_0xe204('0x33'));_0x227a0b['query']=_['keys'](_0x58dc65[_0xe204('0x3b')]);_0x227a0b[_0xe204('0x3c')]=_[_0xe204('0x3d')](_0x227a0b['model'],_0x227a0b[_0xe204('0x3b')]);_0x2502ed[_0xe204('0x3e')]=_[_0xe204('0x3d')](_0x227a0b['model'],qs[_0xe204('0x3f')](_0x58dc65[_0xe204('0x3b')]['fields']));_0x2502ed[_0xe204('0x3e')]=_0x2502ed[_0xe204('0x3e')][_0xe204('0x40')]?_0x2502ed['attributes']:_0x227a0b['model'];if(!_0x58dc65[_0xe204('0x3b')][_0xe204('0x41')](_0xe204('0x42'))){_0x2502ed[_0xe204('0x43')]=qs[_0xe204('0x43')](_0x58dc65[_0xe204('0x3b')][_0xe204('0x43')]);_0x2502ed[_0xe204('0x23')]=qs[_0xe204('0x23')](_0x58dc65[_0xe204('0x3b')][_0xe204('0x23')]);}_0x2502ed[_0xe204('0x44')]=qs['sort'](_0x58dc65[_0xe204('0x3b')][_0xe204('0x45')]);_0x2502ed[_0xe204('0x46')]=qs[_0xe204('0x3c')](_[_0xe204('0x47')](_0x58dc65[_0xe204('0x3b')],_0x227a0b[_0xe204('0x3c')]),_0x4a80b2);if(_0x58dc65[_0xe204('0x3b')][_0xe204('0x48')]){_0x2502ed[_0xe204('0x46')]=_[_0xe204('0x49')](_0x2502ed[_0xe204('0x46')],{'$or':_['map'](_0x4a80b2,function(_0x11b52d){if(_0x11b52d[_0xe204('0x38')]!==_0xe204('0x4a')){var _0x2b504f={};_0x2b504f[_0x11b52d[_0xe204('0x33')]]={'$like':'%'+_0x58dc65[_0xe204('0x3b')][_0xe204('0x48')]+'%'};return _0x2b504f;}})});}_0x2502ed=_[_0xe204('0x49')]({},_0x2502ed,_0x58dc65['options']);var _0x811810={'where':_0x2502ed['where']};return db[_0xe204('0x36')][_0xe204('0x25')](_0x811810)[_0xe204('0x2c')](function(_0x5b9812){_0x5db06b[_0xe204('0x25')]=_0x5b9812;if(_0x58dc65[_0xe204('0x3b')]['includeAll']){_0x2502ed['include']=[{'all':!![]}];}return db['WhatsappQueue'][_0xe204('0x4b')](_0x2502ed);})[_0xe204('0x2c')](function(_0x568b25){_0x5db06b[_0xe204('0x4c')]=_0x568b25;return _0x5db06b;})[_0xe204('0x2c')](respondWithFilteredResult(_0x239b91,_0x2502ed))[_0xe204('0x4d')](handleError(_0x239b91,null));};exports[_0xe204('0x4e')]=function(_0x21334d,_0x28f908){var _0x54bd3f={'raw':!![],'where':{'id':_0x21334d[_0xe204('0x4f')]['id']}},_0x1d6b68={};_0x1d6b68[_0xe204('0x3a')]=_[_0xe204('0x50')](db['WhatsappQueue'][_0xe204('0x51')]);_0x1d6b68[_0xe204('0x3b')]=_[_0xe204('0x50')](_0x21334d[_0xe204('0x3b')]);_0x1d6b68[_0xe204('0x3c')]=_['intersection'](_0x1d6b68[_0xe204('0x3a')],_0x1d6b68[_0xe204('0x3b')]);_0x54bd3f['attributes']=_['intersection'](_0x1d6b68[_0xe204('0x3a')],qs['fields'](_0x21334d[_0xe204('0x3b')][_0xe204('0x3f')]));_0x54bd3f[_0xe204('0x3e')]=_0x54bd3f['attributes'][_0xe204('0x40')]?_0x54bd3f[_0xe204('0x3e')]:_0x1d6b68[_0xe204('0x3a')];if(_0x21334d[_0xe204('0x3b')][_0xe204('0x52')]){_0x54bd3f['include']=[{'all':!![]}];}_0x54bd3f=_[_0xe204('0x49')]({},_0x54bd3f,_0x21334d[_0xe204('0x53')]);return db['WhatsappQueue'][_0xe204('0x54')](_0x54bd3f)[_0xe204('0x2c')](handleEntityNotFound(_0x28f908,null))[_0xe204('0x2c')](respondWithResult(_0x28f908,null))[_0xe204('0x4d')](handleError(_0x28f908,null));};exports[_0xe204('0x55')]=function(_0x2dde55,_0x392545){return db[_0xe204('0x36')]['create'](_0x2dde55[_0xe204('0x56')],{})[_0xe204('0x2c')](function(_0x1a5fae){var _0x3d5e8b=_0x2dde55[_0xe204('0x57')][_0xe204('0x2e')]({'plain':!![]});if(!_0x3d5e8b)throw new Error(_0xe204('0x58'));if(_0x3d5e8b[_0xe204('0x59')]===_0xe204('0x57')){var _0x12a8ef=_0x1a5fae[_0xe204('0x2e')]({'plain':!![]});var _0x31b86a=_0xe204('0x2f');return db['UserProfileSection']['find']({'where':{'name':_0x31b86a,'userProfileId':_0x3d5e8b[_0xe204('0x5a')]},'raw':!![]})[_0xe204('0x2c')](function(_0x17826d){if(_0x17826d&&_0x17826d[_0xe204('0x5b')]===0x0){return db[_0xe204('0x30')]['create']({'name':_0x12a8ef[_0xe204('0x33')],'resourceId':_0x12a8ef['id'],'type':_0x17826d[_0xe204('0x33')],'sectionId':_0x17826d['id']},{})[_0xe204('0x2c')](function(){return _0x1a5fae;});}else{return _0x1a5fae;}})[_0xe204('0x4d')](function(_0xfd0368){logger[_0xe204('0x31')](_0xe204('0x5c'),_0xfd0368);throw _0xfd0368;});}return _0x1a5fae;})[_0xe204('0x2c')](respondWithResult(_0x392545,0xc9))[_0xe204('0x4d')](handleError(_0x392545,null));};exports['update']=function(_0x365e50,_0xea4a34){if(_0x365e50['body']['id']){delete _0x365e50[_0xe204('0x56')]['id'];}return db[_0xe204('0x36')]['find']({'where':{'id':_0x365e50[_0xe204('0x4f')]['id']}})[_0xe204('0x2c')](handleEntityNotFound(_0xea4a34,null))['then'](saveUpdates(_0x365e50[_0xe204('0x56')],null))[_0xe204('0x2c')](respondWithResult(_0xea4a34,null))[_0xe204('0x4d')](handleError(_0xea4a34,null));};exports['destroy']=function(_0x38c5db,_0x40f41e){return db[_0xe204('0x36')][_0xe204('0x54')]({'where':{'id':_0x38c5db[_0xe204('0x4f')]['id']}})[_0xe204('0x2c')](handleEntityNotFound(_0x40f41e,null))[_0xe204('0x2c')](removeEntity(_0x40f41e,null))[_0xe204('0x4d')](handleError(_0x40f41e,null));};exports[_0xe204('0x5d')]=function(_0x595d33,_0x58dcef){return db[_0xe204('0x36')][_0xe204('0x5d')]()['then'](respondWithResult(_0x58dcef,null))[_0xe204('0x4d')](handleError(_0x58dcef,null));};exports[_0xe204('0x5e')]=function(_0x3a29d6,_0x19be24,_0x3d81d1){var _0x114dde={'raw':!![],'where':{}},_0x2fcd7e={},_0x429a2d;return db['WhatsappQueue'][_0xe204('0x5f')]({'where':{'id':_0x3a29d6[_0xe204('0x4f')]['id']}})[_0xe204('0x2c')](handleEntityNotFound(_0x19be24,null))[_0xe204('0x2c')](function(_0xbeda12){if(_0xbeda12){_0x429a2d=_0xbeda12[_0xe204('0x2e')]({'plain':!![]});_0x2fcd7e['model']=_['keys'](db['UserWhatsappQueue']['rawAttributes']);_0x2fcd7e[_0xe204('0x3b')]=_[_0xe204('0x50')](_0x3a29d6[_0xe204('0x3b')]);_0x2fcd7e['filters']=_[_0xe204('0x3d')](_0x2fcd7e['model'],_0x2fcd7e[_0xe204('0x3b')]);_0x114dde[_0xe204('0x3e')]=_[_0xe204('0x3d')](_0x2fcd7e[_0xe204('0x3a')],qs['fields'](_0x3a29d6[_0xe204('0x3b')][_0xe204('0x3f')]));_0x114dde['attributes']=_0x114dde['attributes'][_0xe204('0x40')]?_0x114dde[_0xe204('0x3e')]:_0x2fcd7e[_0xe204('0x3a')];if(!_0x3a29d6[_0xe204('0x3b')][_0xe204('0x41')](_0xe204('0x42'))){_0x114dde[_0xe204('0x43')]=qs['limit'](_0x3a29d6[_0xe204('0x3b')]['limit']);_0x114dde[_0xe204('0x23')]=qs[_0xe204('0x23')](_0x3a29d6[_0xe204('0x3b')][_0xe204('0x23')]);}_0x114dde['order']=qs['sort'](_0x3a29d6['query'][_0xe204('0x45')]);_0x114dde[_0xe204('0x46')]=qs[_0xe204('0x3c')](_['pick'](_0x3a29d6[_0xe204('0x3b')],_0x2fcd7e[_0xe204('0x3c')]));_0x114dde[_0xe204('0x46')][_0xe204('0x60')]=_0xbeda12['id'];if(_0x3a29d6[_0xe204('0x3b')][_0xe204('0x48')]){_0x114dde[_0xe204('0x46')]=_['merge'](_0x114dde[_0xe204('0x46')],{'$or':_[_0xe204('0x35')](_0x114dde['attributes'],function(_0x4f945f){var _0xa5e529={};_0xa5e529[_0x4f945f]={'$like':'%'+_0x3a29d6[_0xe204('0x3b')]['filter']+'%'};return _0xa5e529;})});}_0x114dde=_['merge']({},_0x114dde,_0x3a29d6['options']);return db[_0xe204('0x61')][_0xe204('0x4b')](_0x114dde);}})['then'](function(_0x24634f){if(_0x24634f){return db[_0xe204('0x62')][_0xe204('0x63')]({'where':{'id':_['map'](_0x24634f,_0xe204('0x64')),'role':_0xe204('0x65')},'attributes':['id',_0xe204('0x33'),_0xe204('0x66'),_0xe204('0x67'),'createdAt']});}})[_0xe204('0x2c')](function(_0x3a1833){if(_0x3a1833){return{'count':_0x3a1833[_0xe204('0x25')],'rows':_[_0xe204('0x35')](_0x3a1833[_0xe204('0x4c')],function(_0x31d0fc){return{'membername':_0x31d0fc['name'],'UserId':_0x31d0fc['id'],'queue_name':_0x429a2d[_0xe204('0x33')],'WhatsappQueueId':_0x429a2d['id'],'interface':util['format'](_0xe204('0x68'),_0xe204('0x69'),_0x31d0fc['name']),'penalty':0x0,'paused':_0x31d0fc[_0xe204('0x66')],'createdAt':_0x31d0fc[_0xe204('0x6a')],'updatedAt':_0x31d0fc['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0xe204('0x2c')](respondWithFilteredResult(_0x19be24,_0x114dde))[_0xe204('0x4d')](handleError(_0x19be24,null));};exports[_0xe204('0x6b')]=function(_0x2717f7,_0xdee01b,_0x5cdc5e){var _0x4c1a89={};var _0x2665fa={};var _0x2b63a7;var _0x1a42be;return db[_0xe204('0x36')][_0xe204('0x5f')]({'where':{'id':_0x2717f7[_0xe204('0x4f')]['id']}})[_0xe204('0x2c')](handleEntityNotFound(_0xdee01b,null))['then'](function(_0x47fd15){if(_0x47fd15){_0x2b63a7=_0x47fd15;_0x2665fa['model']=_['keys'](db[_0xe204('0x6c')][_0xe204('0x51')]);_0x2665fa[_0xe204('0x3b')]=_[_0xe204('0x50')](_0x2717f7['query']);_0x2665fa[_0xe204('0x3c')]=_[_0xe204('0x3d')](_0x2665fa[_0xe204('0x3a')],_0x2665fa[_0xe204('0x3b')]);_0x4c1a89['attributes']=_[_0xe204('0x3d')](_0x2665fa[_0xe204('0x3a')],qs[_0xe204('0x3f')](_0x2717f7[_0xe204('0x3b')]['fields']));_0x4c1a89[_0xe204('0x3e')]=_0x4c1a89[_0xe204('0x3e')][_0xe204('0x40')]?_0x4c1a89[_0xe204('0x3e')]:_0x2665fa['model'];_0x4c1a89[_0xe204('0x44')]=qs[_0xe204('0x45')](_0x2717f7['query'][_0xe204('0x45')]);_0x4c1a89[_0xe204('0x46')]=qs[_0xe204('0x3c')](_[_0xe204('0x47')](_0x2717f7['query'],_0x2665fa[_0xe204('0x3c')]));if(_0x2717f7[_0xe204('0x3b')][_0xe204('0x48')]){_0x4c1a89[_0xe204('0x46')]=_['merge'](_0x4c1a89[_0xe204('0x46')],{'$or':_[_0xe204('0x35')](_0x4c1a89['attributes'],function(_0x34ec92){var _0x1ff7ca={};_0x1ff7ca[_0x34ec92]={'$like':'%'+_0x2717f7[_0xe204('0x3b')][_0xe204('0x48')]+'%'};return _0x1ff7ca;})});}_0x4c1a89=_[_0xe204('0x49')]({},_0x4c1a89,_0x2717f7[_0xe204('0x53')]);return _0x2b63a7[_0xe204('0x6b')](_0x4c1a89);}})['then'](function(_0x2c9381){if(_0x2c9381){_0x1a42be=_0x2c9381[_0xe204('0x40')];if(!_0x2717f7[_0xe204('0x3b')][_0xe204('0x41')]('nolimit')){_0x4c1a89[_0xe204('0x43')]=qs[_0xe204('0x43')](_0x2717f7[_0xe204('0x3b')][_0xe204('0x43')]);_0x4c1a89[_0xe204('0x23')]=qs['offset'](_0x2717f7[_0xe204('0x3b')][_0xe204('0x23')]);}return _0x2b63a7[_0xe204('0x6b')](_0x4c1a89);}})[_0xe204('0x2c')](function(_0x262b88){if(_0x262b88){return _0x262b88?{'count':_0x1a42be,'rows':_0x262b88}:null;}})[_0xe204('0x2c')](respondWithResult(_0xdee01b,null))['catch'](handleError(_0xdee01b,null));};exports[_0xe204('0x6d')]=function(_0x22d77c,_0x554a26,_0x35d19d){var _0x215a04=_0x22d77c[_0xe204('0x56')][_0xe204('0x6e')];return db[_0xe204('0x6c')][_0xe204('0x4b')]({'where':{'id':_0x215a04},'attributes':['id'],'include':[{'model':db[_0xe204('0x62')],'as':_0xe204('0x6f'),'attributes':['id','name',_0xe204('0x70'),'voicePause',_0xe204('0x71')],'raw':!![]}]})['then'](function(_0x64dd7b){if(_0x64dd7b){var _0x511927=_[_0xe204('0x72')](_0x64dd7b,function(_0x41479b){var _0x2c421e=_0x41479b[_0xe204('0x2e')]({'plain':!![]});return _0x2c421e['Agents'];});return db[_0xe204('0x36')]['find']({'where':{'id':_0x22d77c[_0xe204('0x4f')]['id']}})['then'](function(_0x368279){return db[_0xe204('0x73')][_0xe204('0x74')](function(_0x58b63c){return _0x368279['addTeams'](_0x215a04,{'transaction':_0x58b63c})[_0xe204('0x2c')](function(){return BPromise[_0xe204('0x75')](_0x511927,function(_0x4f13f8){return db[_0xe204('0x61')][_0xe204('0x76')]({'where':{'UserId':_0x4f13f8['id'],'WhatsappQueueId':_0x22d77c[_0xe204('0x4f')]['id']},'transaction':_0x58b63c});});})[_0xe204('0x2c')](function(){_0x511927['forEach'](function(_0x49aae9){socket['emit'](_0xe204('0x77'),{'UserId':_0x49aae9['id'],'WhatsappQueueId':_0x368279['id']});});});});});}})[_0xe204('0x2c')](respondWithStatusCode(_0x554a26,null))[_0xe204('0x4d')](handleError(_0x554a26,null));};exports[_0xe204('0x78')]=function(_0x2a2bc9,_0x5169e3,_0x1f3b7b){return db[_0xe204('0x6c')][_0xe204('0x4b')]({'where':{'id':_0x2a2bc9[_0xe204('0x3b')][_0xe204('0x6e')]},'attributes':['id'],'include':[{'model':db[_0xe204('0x62')],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0xe204('0x2c')](handleEntityNotFound(_0x5169e3,null))[_0xe204('0x2c')](function(_0x1fe39c){var _0x2035fe=_['map'](_0x1fe39c,'id');var _0x3cde75=[];var _0x1ce545=[];var _0x2ab392=squel['select']();_0x2ab392[_0xe204('0x79')]('tq.TeamId')[_0xe204('0x7a')](_0xe204('0x7b'),'tq')[_0xe204('0x7c')](_0xe204('0x7d'),'ut','ut.TeamId\x20=\x20tq.TeamId')[_0xe204('0x46')](_0xe204('0x7e'),_0x2a2bc9[_0xe204('0x4f')]['id']);for(var _0x341c68=0x0;_0x341c68<_0x1fe39c['length'];_0x341c68+=0x1){let _0x5e5e82=_0x1fe39c[_0x341c68];for(var _0x24218d=0x0;_0x24218d<_0x5e5e82[_0xe204('0x6f')][_0xe204('0x40')];_0x24218d+=0x1){let _0x342cab=_0x5e5e82['Agents'][_0x24218d];var _0xfb3d23=_0x2ab392[_0xe204('0x7f')]();_0xfb3d23['where'](_0xe204('0x80'),_0x342cab['id']);_0x1ce545[_0xe204('0x81')](db[_0xe204('0x73')]['query'](_0xfb3d23[_0xe204('0x82')](),{'type':db['sequelize'][_0xe204('0x83')][_0xe204('0x84')]})['then'](function(_0x25ff78){if(_0x25ff78[_0xe204('0x40')]===0x1){return _0x342cab['id'];}else{var _0x245258=_[_0xe204('0x85')](_[_0xe204('0x35')](_0x25ff78,_0xe204('0x86')),function(_0x1a3824){return _[_0xe204('0x87')](_0x2035fe,_0x1a3824);});if(_0x245258){return _0x342cab['id'];}}}));}}return BPromise[_0xe204('0x88')](_0x1ce545)[_0xe204('0x2c')](function(_0x45f8c8){_0x3cde75=_(_0x3cde75)[_0xe204('0x89')](_0x45f8c8)['compact']()[_0xe204('0x8a')]();return db[_0xe204('0x36')][_0xe204('0x54')]({'where':{'id':_0x2a2bc9[_0xe204('0x4f')]['id']}})['then'](function(_0x23137d){return db['sequelize'][_0xe204('0x74')](function(_0x258b96){return _0x23137d[_0xe204('0x78')](_0x2a2bc9['query'][_0xe204('0x6e')],{'transaction':_0x258b96})['then'](function(){if(!_[_0xe204('0x8b')](_0x3cde75)){return _0x23137d[_0xe204('0x8c')](_0x3cde75,{'transaction':_0x258b96});}})['then'](function(){_0x3cde75['forEach'](function(_0x930c49){socket[_0xe204('0x8d')](_0xe204('0x8e'),{'UserId':_0x930c49,'WhatsappQueueId':_0x23137d['id']});});});});});});})[_0xe204('0x2c')](respondWithStatusCode(_0x5169e3,null))[_0xe204('0x4d')](handleError(_0x5169e3,null));};exports[_0xe204('0x8f')]=function(_0x19f7b7,_0xe4e5e5,_0xc527c2){return db[_0xe204('0x36')][_0xe204('0x54')]({'where':{'id':_0x19f7b7[_0xe204('0x4f')]['id']}})[_0xe204('0x2c')](handleEntityNotFound(_0xe4e5e5,null))[_0xe204('0x2c')](function(_0x15d676){if(_0x15d676){return _0x15d676['addAgents'](_0x19f7b7[_0xe204('0x56')][_0xe204('0x6e')],_[_0xe204('0x90')](_0x19f7b7['body'],[_0xe204('0x6e'),'id'])||{})[_0xe204('0x91')](function(_0x28efd5){for(var _0x3d2f8b=0x0;_0x3d2f8b<_0x19f7b7['body'][_0xe204('0x6e')][_0xe204('0x40')];_0x3d2f8b+=0x1){socket[_0xe204('0x8d')](_0xe204('0x77'),{'UserId':Number(_0x19f7b7[_0xe204('0x56')][_0xe204('0x6e')][_0x3d2f8b]),'WhatsappQueueId':Number(_0x19f7b7[_0xe204('0x4f')]['id'])});}return _0x28efd5;});}})[_0xe204('0x2c')](respondWithResult(_0xe4e5e5,null))[_0xe204('0x4d')](handleError(_0xe4e5e5,null));};exports[_0xe204('0x8c')]=function(_0x5e8586,_0x625335,_0x399edd){return db[_0xe204('0x36')][_0xe204('0x54')]({'where':{'id':_0x5e8586['params']['id']}})['then'](handleEntityNotFound(_0x625335,null))[_0xe204('0x2c')](function(_0x5af442){if(_0x5af442){return _0x5af442[_0xe204('0x8c')](_0x5e8586[_0xe204('0x3b')][_0xe204('0x6e')])[_0xe204('0x2c')](function(){if(_[_0xe204('0x92')](_0x5e8586[_0xe204('0x3b')][_0xe204('0x6e')])){for(var _0x56629c=0x0;_0x56629c<_0x5e8586[_0xe204('0x3b')][_0xe204('0x6e')][_0xe204('0x40')];_0x56629c+=0x1){socket['emit'](_0xe204('0x8e'),{'UserId':Number(_0x5e8586[_0xe204('0x3b')][_0xe204('0x6e')][_0x56629c]),'WhatsappQueueId':Number(_0x5e8586[_0xe204('0x4f')]['id'])});}}else{socket[_0xe204('0x8d')](_0xe204('0x8e'),{'UserId':Number(_0x5e8586['query'][_0xe204('0x6e')]),'WhatsappQueueId':Number(_0x5e8586[_0xe204('0x4f')]['id'])});}});}})[_0xe204('0x2c')](respondWithStatusCode(_0x625335,null))[_0xe204('0x4d')](handleError(_0x625335,null));};exports[_0xe204('0x93')]=function(_0x2ec7af,_0x2cf12b,_0x1f492e){var _0x50ba26={};var _0x46c9a2={};var _0x5ec7ec;var _0x40b1d7;return db[_0xe204('0x36')][_0xe204('0x5f')]({'where':{'id':_0x2ec7af[_0xe204('0x4f')]['id']}})['then'](handleEntityNotFound(_0x2cf12b,null))[_0xe204('0x2c')](function(_0x527ab3){if(_0x527ab3){_0x5ec7ec=_0x527ab3;_0x46c9a2[_0xe204('0x3a')]=_['keys'](db[_0xe204('0x62')][_0xe204('0x51')]);_0x46c9a2[_0xe204('0x3b')]=_[_0xe204('0x50')](_0x2ec7af[_0xe204('0x3b')]);_0x46c9a2[_0xe204('0x3c')]=_[_0xe204('0x3d')](_0x46c9a2[_0xe204('0x3a')],_0x46c9a2[_0xe204('0x3b')]);_0x50ba26['attributes']=_[_0xe204('0x3d')](_0x46c9a2[_0xe204('0x3a')],qs['fields'](_0x2ec7af['query'][_0xe204('0x3f')]));_0x50ba26[_0xe204('0x3e')]=_0x50ba26[_0xe204('0x3e')][_0xe204('0x40')]?_0x50ba26['attributes']:_0x46c9a2['model'];_0x50ba26['order']=qs[_0xe204('0x45')](_0x2ec7af[_0xe204('0x3b')]['sort']);_0x50ba26[_0xe204('0x46')]=qs['filters'](_[_0xe204('0x47')](_0x2ec7af[_0xe204('0x3b')],_0x46c9a2[_0xe204('0x3c')]));if(_0x2ec7af[_0xe204('0x3b')][_0xe204('0x48')]){_0x50ba26['where']=_[_0xe204('0x49')](_0x50ba26[_0xe204('0x46')],{'$or':_[_0xe204('0x35')](_0x50ba26['attributes'],function(_0x2a1580){var _0x31d7a5={};_0x31d7a5[_0x2a1580]={'$like':'%'+_0x2ec7af['query']['filter']+'%'};return _0x31d7a5;})});}_0x50ba26=_[_0xe204('0x49')]({},_0x50ba26,_0x2ec7af[_0xe204('0x53')]);return _0x5ec7ec[_0xe204('0x93')](_0x50ba26);}})[_0xe204('0x2c')](function(_0xadd2cf){if(_0xadd2cf){_0x40b1d7=_0xadd2cf[_0xe204('0x40')];if(!_0x2ec7af[_0xe204('0x3b')]['hasOwnProperty']('nolimit')){_0x50ba26[_0xe204('0x43')]=qs['limit'](_0x2ec7af[_0xe204('0x3b')][_0xe204('0x43')]);_0x50ba26[_0xe204('0x23')]=qs[_0xe204('0x23')](_0x2ec7af[_0xe204('0x3b')]['offset']);}return _0x5ec7ec[_0xe204('0x93')](_0x50ba26);}})[_0xe204('0x2c')](function(_0x36991e){if(_0x36991e){return _0x36991e?{'count':_0x40b1d7,'rows':_0x36991e}:null;}})['then'](respondWithResult(_0x2cf12b,null))[_0xe204('0x4d')](handleError(_0x2cf12b,null));};
\ No newline at end of file
+var _0x6a2d=['flatMap','Agents','sequelize','transaction','each','findOrCreate','forEach','emit','userWhatsappQueue:save','removeTeams','Team','select','field','from','team_has_whatsapp_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','all','compact','value','isEmpty','userWhatsappQueue:remove','addAgents','omit','spread','removeAgents','isArray','getAgents','lodash','ioredis','../../components/parsers/qs','../../config/logger','api','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','then','destroy','get','WhatsappQueues','UserProfileResource','stack','name','send','map','WhatsappQueue','rawAttributes','fieldName','type','key','getOptions','where','include','findAll','rows','catch','show','params','model','keys','query','filters','intersection','fields','attributes','length','includeAll','merge','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','error','update','describe','getMembers','findOne','UserWhatsappQueue','hasOwnProperty','nolimit','sort','pick','WhatsappQueueId','User','findAndCountAll','UserId','whatsappPause','updatedAt','createdAt','format','SIP','getTeams','filter','addTeams','ids','voicePause'];(function(_0x37c07d,_0xdbdb5f){var _0x10dadc=function(_0x2bafb7){while(--_0x2bafb7){_0x37c07d['push'](_0x37c07d['shift']());}};_0x10dadc(++_0xdbdb5f);}(_0x6a2d,0x197));var _0xd6a2=function(_0x3bf83f,_0x181cac){_0x3bf83f=_0x3bf83f-0x0;var _0x22c4a9=_0x6a2d[_0x3bf83f];return _0x22c4a9;};'use strict';var BPromise=require('bluebird');var util=require('util');var _=require(_0xd6a2('0x0'));var squel=require('squel');var Redis=require(_0xd6a2('0x1'));var qs=require(_0xd6a2('0x2'));var logger=require(_0xd6a2('0x3'))(_0xd6a2('0x4'));var config=require('../../config/environment');var db=require(_0xd6a2('0x5'))['db'];config['redis']=_[_0xd6a2('0x6')](config[_0xd6a2('0x7')],{'host':_0xd6a2('0x8'),'port':0x18eb});var socket=require(_0xd6a2('0x9'))(new Redis(config['redis']));require('./whatsappQueue.socket')[_0xd6a2('0xa')](socket);function respondWithStatusCode(_0x560686,_0x53cd2a){_0x53cd2a=_0x53cd2a||0xcc;return function(_0x290d78){if(_0x290d78){return _0x560686[_0xd6a2('0xb')](_0x53cd2a);}return _0x560686[_0xd6a2('0xc')](_0x53cd2a)[_0xd6a2('0xd')]();};}function respondWithResult(_0x262459,_0x31b63f){_0x31b63f=_0x31b63f||0xc8;return function(_0x14a38f){if(_0x14a38f){return _0x262459[_0xd6a2('0xc')](_0x31b63f)['json'](_0x14a38f);}};}function respondWithFilteredResult(_0x2b3289,_0x16e283){return function(_0xc5d101){if(_0xc5d101){var _0x46a4e4=typeof _0x16e283[_0xd6a2('0xe')]===_0xd6a2('0xf')&&typeof _0x16e283[_0xd6a2('0x10')]===_0xd6a2('0xf');var _0x5f69dd=_0xc5d101[_0xd6a2('0x11')];var _0x56b6e9=_0x46a4e4?0x0:_0x16e283[_0xd6a2('0xe')];var _0x3842a4=_0x46a4e4?_0xc5d101[_0xd6a2('0x11')]:_0x16e283[_0xd6a2('0xe')]+_0x16e283['limit'];var _0x53dbc3;if(_0x3842a4>=_0x5f69dd){_0x3842a4=_0x5f69dd;_0x53dbc3=0xc8;}else{_0x53dbc3=0xce;}_0x2b3289['status'](_0x53dbc3);return _0x2b3289[_0xd6a2('0x12')](_0xd6a2('0x13'),_0x56b6e9+'-'+_0x3842a4+'/'+_0x5f69dd)['json'](_0xc5d101);}return null;};}function saveUpdates(_0x4e1c37){return function(_0x2a4a0f){if(_0x2a4a0f){return _0x2a4a0f['update'](_0x4e1c37)[_0xd6a2('0x14')](function(_0xcdbc15){return _0xcdbc15;});}return null;};}function removeEntity(_0x559d67){return function(_0x47c72f){if(_0x47c72f){return _0x47c72f[_0xd6a2('0x15')]()[_0xd6a2('0x14')](function(){var _0x1b6540=_0x47c72f[_0xd6a2('0x16')]({'plain':!![]});var _0x52bc2b=_0xd6a2('0x17');return db[_0xd6a2('0x18')][_0xd6a2('0x15')]({'where':{'type':_0x52bc2b,'resourceId':_0x1b6540['id']}})[_0xd6a2('0x14')](function(){return _0x47c72f;});})[_0xd6a2('0x14')](function(){_0x559d67[_0xd6a2('0xc')](0xcc)[_0xd6a2('0xd')]();});}};}function handleEntityNotFound(_0x1af467){return function(_0x586a19){if(!_0x586a19){_0x1af467['sendStatus'](0x194);}return _0x586a19;};}function handleError(_0x22540c,_0xed93f0){_0xed93f0=_0xed93f0||0x1f4;return function(_0x566857){logger['error'](_0x566857[_0xd6a2('0x19')]);if(_0x566857[_0xd6a2('0x1a')]){delete _0x566857[_0xd6a2('0x1a')];}_0x22540c[_0xd6a2('0xc')](_0xed93f0)[_0xd6a2('0x1b')](_0x566857);};}exports['index']=function(_0x4b85eb,_0x5788e3){var _0x5ed4f9={};var _0x970e33={'count':0x0,'rows':[]};var _0x4058c4=_[_0xd6a2('0x1c')](db[_0xd6a2('0x1d')][_0xd6a2('0x1e')],function(_0x5ef07d){return{'name':_0x5ef07d[_0xd6a2('0x1f')],'type':_0x5ef07d[_0xd6a2('0x20')][_0xd6a2('0x21')]};});_0x5ed4f9=qs[_0xd6a2('0x22')](_0x4058c4,_0x4b85eb);var _0x3aaf85={'where':_0x5ed4f9[_0xd6a2('0x23')]};return db[_0xd6a2('0x1d')][_0xd6a2('0x11')](_0x3aaf85)[_0xd6a2('0x14')](function(_0x4915b8){_0x970e33[_0xd6a2('0x11')]=_0x4915b8;_0x5ed4f9[_0xd6a2('0x24')]=qs[_0xd6a2('0x24')](_0x4b85eb['query']);return db['WhatsappQueue'][_0xd6a2('0x25')](_0x5ed4f9);})[_0xd6a2('0x14')](function(_0xea1cb2){_0x970e33[_0xd6a2('0x26')]=_0xea1cb2;return _0x970e33;})[_0xd6a2('0x14')](respondWithFilteredResult(_0x5788e3,_0x5ed4f9))[_0xd6a2('0x27')](handleError(_0x5788e3,null));};exports[_0xd6a2('0x28')]=function(_0x19a125,_0x5b5cf0){var _0x3db39d={'raw':!![],'where':{'id':_0x19a125[_0xd6a2('0x29')]['id']}},_0x10be98={};_0x10be98[_0xd6a2('0x2a')]=_[_0xd6a2('0x2b')](db[_0xd6a2('0x1d')][_0xd6a2('0x1e')]);_0x10be98[_0xd6a2('0x2c')]=_[_0xd6a2('0x2b')](_0x19a125[_0xd6a2('0x2c')]);_0x10be98[_0xd6a2('0x2d')]=_['intersection'](_0x10be98[_0xd6a2('0x2a')],_0x10be98[_0xd6a2('0x2c')]);_0x3db39d['attributes']=_[_0xd6a2('0x2e')](_0x10be98[_0xd6a2('0x2a')],qs[_0xd6a2('0x2f')](_0x19a125[_0xd6a2('0x2c')][_0xd6a2('0x2f')]));_0x3db39d[_0xd6a2('0x30')]=_0x3db39d[_0xd6a2('0x30')][_0xd6a2('0x31')]?_0x3db39d[_0xd6a2('0x30')]:_0x10be98['model'];if(_0x19a125[_0xd6a2('0x2c')][_0xd6a2('0x32')]){_0x3db39d['include']=[{'all':!![]}];}_0x3db39d=_[_0xd6a2('0x33')]({},_0x3db39d,_0x19a125[_0xd6a2('0x34')]);return db[_0xd6a2('0x1d')][_0xd6a2('0x35')](_0x3db39d)[_0xd6a2('0x14')](handleEntityNotFound(_0x5b5cf0,null))['then'](respondWithResult(_0x5b5cf0,null))[_0xd6a2('0x27')](handleError(_0x5b5cf0,null));};exports['create']=function(_0x1c66bd,_0x29b9a3){return db['WhatsappQueue'][_0xd6a2('0x36')](_0x1c66bd[_0xd6a2('0x37')],{})[_0xd6a2('0x14')](function(_0x530bea){var _0x1f48b8=_0x1c66bd[_0xd6a2('0x38')]['get']({'plain':!![]});if(!_0x1f48b8)throw new Error(_0xd6a2('0x39'));if(_0x1f48b8[_0xd6a2('0x3a')]===_0xd6a2('0x38')){var _0x2a9f49=_0x530bea[_0xd6a2('0x16')]({'plain':!![]});var _0x1aa8c6=_0xd6a2('0x17');return db[_0xd6a2('0x3b')]['find']({'where':{'name':_0x1aa8c6,'userProfileId':_0x1f48b8[_0xd6a2('0x3c')]},'raw':!![]})['then'](function(_0x5d0d16){if(_0x5d0d16&&_0x5d0d16['autoAssociation']===0x0){return db['UserProfileResource'][_0xd6a2('0x36')]({'name':_0x2a9f49[_0xd6a2('0x1a')],'resourceId':_0x2a9f49['id'],'type':_0x5d0d16[_0xd6a2('0x1a')],'sectionId':_0x5d0d16['id']},{})[_0xd6a2('0x14')](function(){return _0x530bea;});}else{return _0x530bea;}})[_0xd6a2('0x27')](function(_0x2c46f3){logger[_0xd6a2('0x3d')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x2c46f3);throw _0x2c46f3;});}return _0x530bea;})[_0xd6a2('0x14')](respondWithResult(_0x29b9a3,0xc9))[_0xd6a2('0x27')](handleError(_0x29b9a3,null));};exports[_0xd6a2('0x3e')]=function(_0x236a92,_0x48cb71){if(_0x236a92[_0xd6a2('0x37')]['id']){delete _0x236a92[_0xd6a2('0x37')]['id'];}return db[_0xd6a2('0x1d')]['find']({'where':{'id':_0x236a92[_0xd6a2('0x29')]['id']}})[_0xd6a2('0x14')](handleEntityNotFound(_0x48cb71,null))[_0xd6a2('0x14')](saveUpdates(_0x236a92[_0xd6a2('0x37')],null))['then'](respondWithResult(_0x48cb71,null))['catch'](handleError(_0x48cb71,null));};exports[_0xd6a2('0x15')]=function(_0x38e91e,_0x2a99fa){return db['WhatsappQueue'][_0xd6a2('0x35')]({'where':{'id':_0x38e91e[_0xd6a2('0x29')]['id']}})[_0xd6a2('0x14')](handleEntityNotFound(_0x2a99fa,null))[_0xd6a2('0x14')](removeEntity(_0x2a99fa,null))[_0xd6a2('0x27')](handleError(_0x2a99fa,null));};exports[_0xd6a2('0x3f')]=function(_0x56f73c,_0xd0a8ce){return db[_0xd6a2('0x1d')][_0xd6a2('0x3f')]()['then'](respondWithResult(_0xd0a8ce,null))['catch'](handleError(_0xd0a8ce,null));};exports[_0xd6a2('0x40')]=function(_0x3edabe,_0x2f6183){var _0x22be26={'raw':!![],'where':{}},_0x261e18={},_0x48d43e;return db[_0xd6a2('0x1d')][_0xd6a2('0x41')]({'where':{'id':_0x3edabe[_0xd6a2('0x29')]['id']}})[_0xd6a2('0x14')](handleEntityNotFound(_0x2f6183,null))[_0xd6a2('0x14')](function(_0xd707b6){if(_0xd707b6){_0x48d43e=_0xd707b6[_0xd6a2('0x16')]({'plain':!![]});_0x261e18['model']=_[_0xd6a2('0x2b')](db[_0xd6a2('0x42')][_0xd6a2('0x1e')]);_0x261e18[_0xd6a2('0x2c')]=_[_0xd6a2('0x2b')](_0x3edabe[_0xd6a2('0x2c')]);_0x261e18[_0xd6a2('0x2d')]=_[_0xd6a2('0x2e')](_0x261e18['model'],_0x261e18[_0xd6a2('0x2c')]);_0x22be26[_0xd6a2('0x30')]=_[_0xd6a2('0x2e')](_0x261e18['model'],qs['fields'](_0x3edabe['query'][_0xd6a2('0x2f')]));_0x22be26[_0xd6a2('0x30')]=_0x22be26['attributes'][_0xd6a2('0x31')]?_0x22be26['attributes']:_0x261e18['model'];if(!_0x3edabe[_0xd6a2('0x2c')][_0xd6a2('0x43')](_0xd6a2('0x44'))){_0x22be26[_0xd6a2('0x10')]=qs[_0xd6a2('0x10')](_0x3edabe['query'][_0xd6a2('0x10')]);_0x22be26[_0xd6a2('0xe')]=qs[_0xd6a2('0xe')](_0x3edabe[_0xd6a2('0x2c')][_0xd6a2('0xe')]);}_0x22be26['order']=qs[_0xd6a2('0x45')](_0x3edabe['query']['sort']);_0x22be26[_0xd6a2('0x23')]=qs[_0xd6a2('0x2d')](_[_0xd6a2('0x46')](_0x3edabe['query'],_0x261e18[_0xd6a2('0x2d')]));_0x22be26['where'][_0xd6a2('0x47')]=_0xd707b6['id'];if(_0x3edabe[_0xd6a2('0x2c')]['filter']){_0x22be26['where']=_[_0xd6a2('0x33')](_0x22be26['where'],{'$or':_[_0xd6a2('0x1c')](_0x22be26[_0xd6a2('0x30')],function(_0x34cab0){var _0x48386a={};_0x48386a[_0x34cab0]={'$like':'%'+_0x3edabe[_0xd6a2('0x2c')]['filter']+'%'};return _0x48386a;})});}_0x22be26=_['merge']({},_0x22be26,_0x3edabe[_0xd6a2('0x34')]);return db['UserWhatsappQueue']['findAll'](_0x22be26);}})[_0xd6a2('0x14')](function(_0xdd0a96){if(_0xdd0a96){return db[_0xd6a2('0x48')][_0xd6a2('0x49')]({'where':{'id':_[_0xd6a2('0x1c')](_0xdd0a96,_0xd6a2('0x4a')),'role':'agent'},'attributes':['id',_0xd6a2('0x1a'),_0xd6a2('0x4b'),_0xd6a2('0x4c'),_0xd6a2('0x4d')]});}})['then'](function(_0x550301){if(_0x550301){return{'count':_0x550301[_0xd6a2('0x11')],'rows':_[_0xd6a2('0x1c')](_0x550301[_0xd6a2('0x26')],function(_0x14eb3c){return{'membername':_0x14eb3c[_0xd6a2('0x1a')],'UserId':_0x14eb3c['id'],'queue_name':_0x48d43e[_0xd6a2('0x1a')],'WhatsappQueueId':_0x48d43e['id'],'interface':util[_0xd6a2('0x4e')]('%s/%s',_0xd6a2('0x4f'),_0x14eb3c[_0xd6a2('0x1a')]),'penalty':0x0,'paused':_0x14eb3c['whatsappPause'],'createdAt':_0x14eb3c[_0xd6a2('0x4d')],'updatedAt':_0x14eb3c['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0xd6a2('0x14')](respondWithFilteredResult(_0x2f6183,_0x22be26))[_0xd6a2('0x27')](handleError(_0x2f6183,null));};exports[_0xd6a2('0x50')]=function(_0x15769c,_0x5a3455){var _0x557f2c={};var _0x1d137c={};var _0x2b4a77;var _0xba5865;return db['WhatsappQueue'][_0xd6a2('0x41')]({'where':{'id':_0x15769c[_0xd6a2('0x29')]['id']}})[_0xd6a2('0x14')](handleEntityNotFound(_0x5a3455,null))[_0xd6a2('0x14')](function(_0x110cbb){if(_0x110cbb){_0x2b4a77=_0x110cbb;_0x1d137c[_0xd6a2('0x2a')]=_[_0xd6a2('0x2b')](db['Team'][_0xd6a2('0x1e')]);_0x1d137c[_0xd6a2('0x2c')]=_['keys'](_0x15769c[_0xd6a2('0x2c')]);_0x1d137c[_0xd6a2('0x2d')]=_['intersection'](_0x1d137c[_0xd6a2('0x2a')],_0x1d137c[_0xd6a2('0x2c')]);_0x557f2c['attributes']=_[_0xd6a2('0x2e')](_0x1d137c[_0xd6a2('0x2a')],qs[_0xd6a2('0x2f')](_0x15769c[_0xd6a2('0x2c')][_0xd6a2('0x2f')]));_0x557f2c[_0xd6a2('0x30')]=_0x557f2c['attributes'][_0xd6a2('0x31')]?_0x557f2c[_0xd6a2('0x30')]:_0x1d137c[_0xd6a2('0x2a')];_0x557f2c['order']=qs[_0xd6a2('0x45')](_0x15769c[_0xd6a2('0x2c')]['sort']);_0x557f2c['where']=qs[_0xd6a2('0x2d')](_[_0xd6a2('0x46')](_0x15769c[_0xd6a2('0x2c')],_0x1d137c[_0xd6a2('0x2d')]));if(_0x15769c[_0xd6a2('0x2c')][_0xd6a2('0x51')]){_0x557f2c[_0xd6a2('0x23')]=_['merge'](_0x557f2c[_0xd6a2('0x23')],{'$or':_[_0xd6a2('0x1c')](_0x557f2c['attributes'],function(_0x308a3c){var _0x59f379={};_0x59f379[_0x308a3c]={'$like':'%'+_0x15769c[_0xd6a2('0x2c')][_0xd6a2('0x51')]+'%'};return _0x59f379;})});}_0x557f2c=_[_0xd6a2('0x33')]({},_0x557f2c,_0x15769c[_0xd6a2('0x34')]);return _0x2b4a77[_0xd6a2('0x50')](_0x557f2c);}})[_0xd6a2('0x14')](function(_0x56d477){if(_0x56d477){_0xba5865=_0x56d477[_0xd6a2('0x31')];if(!_0x15769c[_0xd6a2('0x2c')][_0xd6a2('0x43')]('nolimit')){_0x557f2c[_0xd6a2('0x10')]=qs['limit'](_0x15769c[_0xd6a2('0x2c')]['limit']);_0x557f2c[_0xd6a2('0xe')]=qs['offset'](_0x15769c[_0xd6a2('0x2c')][_0xd6a2('0xe')]);}return _0x2b4a77[_0xd6a2('0x50')](_0x557f2c);}})[_0xd6a2('0x14')](function(_0x1ceeda){if(_0x1ceeda){return _0x1ceeda?{'count':_0xba5865,'rows':_0x1ceeda}:null;}})[_0xd6a2('0x14')](respondWithResult(_0x5a3455,null))[_0xd6a2('0x27')](handleError(_0x5a3455,null));};exports[_0xd6a2('0x52')]=function(_0x4ab2b3,_0x2fd62b){var _0xdcbcb6=_0x4ab2b3[_0xd6a2('0x37')][_0xd6a2('0x53')];return db['Team'][_0xd6a2('0x25')]({'where':{'id':_0xdcbcb6},'attributes':['id'],'include':[{'model':db[_0xd6a2('0x48')],'as':'Agents','attributes':['id',_0xd6a2('0x1a'),'online',_0xd6a2('0x54'),'interface'],'raw':!![]}]})[_0xd6a2('0x14')](function(_0x55f1ad){if(_0x55f1ad){var _0x4c77a5=_[_0xd6a2('0x55')](_0x55f1ad,function(_0x328f36){var _0x1d811b=_0x328f36[_0xd6a2('0x16')]({'plain':!![]});return _0x1d811b[_0xd6a2('0x56')];});return db[_0xd6a2('0x1d')][_0xd6a2('0x35')]({'where':{'id':_0x4ab2b3['params']['id']}})[_0xd6a2('0x14')](function(_0x556593){return db[_0xd6a2('0x57')][_0xd6a2('0x58')](function(_0x2a18db){return _0x556593['addTeams'](_0xdcbcb6,{'transaction':_0x2a18db})[_0xd6a2('0x14')](function(){return BPromise[_0xd6a2('0x59')](_0x4c77a5,function(_0xbf4542){return db[_0xd6a2('0x42')][_0xd6a2('0x5a')]({'where':{'UserId':_0xbf4542['id'],'WhatsappQueueId':_0x4ab2b3['params']['id']},'transaction':_0x2a18db});});})[_0xd6a2('0x14')](function(){_0x4c77a5[_0xd6a2('0x5b')](function(_0xf40937){socket[_0xd6a2('0x5c')](_0xd6a2('0x5d'),{'UserId':_0xf40937['id'],'WhatsappQueueId':_0x556593['id']});});});});});}})[_0xd6a2('0x14')](respondWithStatusCode(_0x2fd62b,null))['catch'](handleError(_0x2fd62b,null));};exports[_0xd6a2('0x5e')]=function(_0x8c24b0,_0x1dbc30){return db[_0xd6a2('0x5f')][_0xd6a2('0x25')]({'where':{'id':_0x8c24b0[_0xd6a2('0x2c')]['ids']},'attributes':['id'],'include':[{'model':db[_0xd6a2('0x48')],'as':_0xd6a2('0x56'),'attributes':['id'],'raw':!![]}]})[_0xd6a2('0x14')](handleEntityNotFound(_0x1dbc30,null))[_0xd6a2('0x14')](function(_0xee54db){var _0x3c9f12=_['map'](_0xee54db,'id');var _0x78ad42=[];var _0x1d344a=[];var _0x5b336b=squel[_0xd6a2('0x60')]();_0x5b336b[_0xd6a2('0x61')]('tq.TeamId')[_0xd6a2('0x62')](_0xd6a2('0x63'),'tq')[_0xd6a2('0x64')](_0xd6a2('0x65'),'ut',_0xd6a2('0x66'))['where']('WhatsappQueueId\x20=\x20?',_0x8c24b0[_0xd6a2('0x29')]['id']);for(var _0x1ffd2b=0x0;_0x1ffd2b<_0xee54db[_0xd6a2('0x31')];_0x1ffd2b+=0x1){let _0x47e9e7=_0xee54db[_0x1ffd2b];for(var _0x16f5d2=0x0;_0x16f5d2<_0x47e9e7['Agents']['length'];_0x16f5d2+=0x1){let _0x3f6f4e=_0x47e9e7['Agents'][_0x16f5d2];var _0x1afdb1=_0x5b336b[_0xd6a2('0x67')]();_0x1afdb1['where'](_0xd6a2('0x68'),_0x3f6f4e['id']);_0x1d344a[_0xd6a2('0x69')](db['sequelize']['query'](_0x1afdb1[_0xd6a2('0x6a')](),{'type':db['sequelize'][_0xd6a2('0x6b')][_0xd6a2('0x6c')]})[_0xd6a2('0x14')](function(_0x5e9d76){if(_0x5e9d76[_0xd6a2('0x31')]===0x1){return _0x3f6f4e['id'];}else{var _0x59e45b=_[_0xd6a2('0x6d')](_['map'](_0x5e9d76,_0xd6a2('0x6e')),function(_0x172bc2){return _[_0xd6a2('0x6f')](_0x3c9f12,_0x172bc2);});if(_0x59e45b){return _0x3f6f4e['id'];}}}));}}return BPromise[_0xd6a2('0x70')](_0x1d344a)[_0xd6a2('0x14')](function(_0x506282){_0x78ad42=_(_0x78ad42)['union'](_0x506282)[_0xd6a2('0x71')]()[_0xd6a2('0x72')]();return db[_0xd6a2('0x1d')][_0xd6a2('0x35')]({'where':{'id':_0x8c24b0['params']['id']}})['then'](function(_0x4cd37f){return db[_0xd6a2('0x57')]['transaction'](function(_0x5c0e03){return _0x4cd37f[_0xd6a2('0x5e')](_0x8c24b0[_0xd6a2('0x2c')][_0xd6a2('0x53')],{'transaction':_0x5c0e03})[_0xd6a2('0x14')](function(){if(!_[_0xd6a2('0x73')](_0x78ad42)){return _0x4cd37f['removeAgents'](_0x78ad42,{'transaction':_0x5c0e03});}})['then'](function(){_0x78ad42[_0xd6a2('0x5b')](function(_0x3efc85){socket[_0xd6a2('0x5c')](_0xd6a2('0x74'),{'UserId':_0x3efc85,'WhatsappQueueId':_0x4cd37f['id']});});});});});});})['then'](respondWithStatusCode(_0x1dbc30,null))[_0xd6a2('0x27')](handleError(_0x1dbc30,null));};exports[_0xd6a2('0x75')]=function(_0xca5ea2,_0x20b284){return db[_0xd6a2('0x1d')][_0xd6a2('0x35')]({'where':{'id':_0xca5ea2['params']['id']}})[_0xd6a2('0x14')](handleEntityNotFound(_0x20b284,null))[_0xd6a2('0x14')](function(_0x271d70){if(_0x271d70){return _0x271d70['addAgents'](_0xca5ea2['body'][_0xd6a2('0x53')],_[_0xd6a2('0x76')](_0xca5ea2['body'],['ids','id'])||{})[_0xd6a2('0x77')](function(_0x171044){for(var _0x4743e0=0x0;_0x4743e0<_0xca5ea2['body'][_0xd6a2('0x53')][_0xd6a2('0x31')];_0x4743e0+=0x1){socket[_0xd6a2('0x5c')](_0xd6a2('0x5d'),{'UserId':Number(_0xca5ea2[_0xd6a2('0x37')][_0xd6a2('0x53')][_0x4743e0]),'WhatsappQueueId':Number(_0xca5ea2[_0xd6a2('0x29')]['id'])});}return _0x171044;});}})[_0xd6a2('0x14')](respondWithResult(_0x20b284,null))[_0xd6a2('0x27')](handleError(_0x20b284,null));};exports[_0xd6a2('0x78')]=function(_0x33c8e3,_0x5756dc){return db[_0xd6a2('0x1d')][_0xd6a2('0x35')]({'where':{'id':_0x33c8e3[_0xd6a2('0x29')]['id']}})[_0xd6a2('0x14')](handleEntityNotFound(_0x5756dc,null))[_0xd6a2('0x14')](function(_0x1a0c78){if(_0x1a0c78){return _0x1a0c78['removeAgents'](_0x33c8e3[_0xd6a2('0x2c')][_0xd6a2('0x53')])[_0xd6a2('0x14')](function(){if(_[_0xd6a2('0x79')](_0x33c8e3[_0xd6a2('0x2c')]['ids'])){for(var _0x37ecca=0x0;_0x37ecca<_0x33c8e3[_0xd6a2('0x2c')][_0xd6a2('0x53')][_0xd6a2('0x31')];_0x37ecca+=0x1){socket['emit'](_0xd6a2('0x74'),{'UserId':Number(_0x33c8e3[_0xd6a2('0x2c')]['ids'][_0x37ecca]),'WhatsappQueueId':Number(_0x33c8e3['params']['id'])});}}else{socket[_0xd6a2('0x5c')](_0xd6a2('0x74'),{'UserId':Number(_0x33c8e3[_0xd6a2('0x2c')][_0xd6a2('0x53')]),'WhatsappQueueId':Number(_0x33c8e3[_0xd6a2('0x29')]['id'])});}});}})[_0xd6a2('0x14')](respondWithStatusCode(_0x5756dc,null))[_0xd6a2('0x27')](handleError(_0x5756dc,null));};exports[_0xd6a2('0x7a')]=function(_0x130f01,_0x126724){var _0x276cae={};var _0x53585d={};var _0x5d1241;var _0x1bf288;return db[_0xd6a2('0x1d')][_0xd6a2('0x41')]({'where':{'id':_0x130f01[_0xd6a2('0x29')]['id']}})[_0xd6a2('0x14')](handleEntityNotFound(_0x126724,null))[_0xd6a2('0x14')](function(_0x196fe7){if(_0x196fe7){_0x5d1241=_0x196fe7;_0x53585d[_0xd6a2('0x2a')]=_[_0xd6a2('0x2b')](db[_0xd6a2('0x48')][_0xd6a2('0x1e')]);_0x53585d['query']=_['keys'](_0x130f01[_0xd6a2('0x2c')]);_0x53585d[_0xd6a2('0x2d')]=_[_0xd6a2('0x2e')](_0x53585d[_0xd6a2('0x2a')],_0x53585d[_0xd6a2('0x2c')]);_0x276cae[_0xd6a2('0x30')]=_['intersection'](_0x53585d[_0xd6a2('0x2a')],qs[_0xd6a2('0x2f')](_0x130f01[_0xd6a2('0x2c')][_0xd6a2('0x2f')]));_0x276cae['attributes']=_0x276cae[_0xd6a2('0x30')]['length']?_0x276cae[_0xd6a2('0x30')]:_0x53585d[_0xd6a2('0x2a')];_0x276cae['order']=qs[_0xd6a2('0x45')](_0x130f01[_0xd6a2('0x2c')][_0xd6a2('0x45')]);_0x276cae['where']=qs[_0xd6a2('0x2d')](_[_0xd6a2('0x46')](_0x130f01[_0xd6a2('0x2c')],_0x53585d[_0xd6a2('0x2d')]));if(_0x130f01['query'][_0xd6a2('0x51')]){_0x276cae[_0xd6a2('0x23')]=_['merge'](_0x276cae[_0xd6a2('0x23')],{'$or':_[_0xd6a2('0x1c')](_0x276cae[_0xd6a2('0x30')],function(_0x19df25){var _0x4bbb9b={};_0x4bbb9b[_0x19df25]={'$like':'%'+_0x130f01[_0xd6a2('0x2c')]['filter']+'%'};return _0x4bbb9b;})});}_0x276cae=_['merge']({},_0x276cae,_0x130f01[_0xd6a2('0x34')]);return _0x5d1241[_0xd6a2('0x7a')](_0x276cae);}})[_0xd6a2('0x14')](function(_0x34a3b8){if(_0x34a3b8){_0x1bf288=_0x34a3b8[_0xd6a2('0x31')];if(!_0x130f01[_0xd6a2('0x2c')][_0xd6a2('0x43')](_0xd6a2('0x44'))){_0x276cae[_0xd6a2('0x10')]=qs[_0xd6a2('0x10')](_0x130f01[_0xd6a2('0x2c')][_0xd6a2('0x10')]);_0x276cae[_0xd6a2('0xe')]=qs[_0xd6a2('0xe')](_0x130f01[_0xd6a2('0x2c')][_0xd6a2('0xe')]);}return _0x5d1241[_0xd6a2('0x7a')](_0x276cae);}})[_0xd6a2('0x14')](function(_0xb62ece){if(_0xb62ece){return _0xb62ece?{'count':_0x1bf288,'rows':_0xb62ece}:null;}})[_0xd6a2('0x14')](respondWithResult(_0x126724,null))['catch'](handleError(_0x126724,null));};
\ No newline at end of file