Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / whatsappQueue / whatsappQueue.controller.js
index f6bb4bb..d6f12b5 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2d22=['Team','findAll','User','Agents','online','voicePause','interface','flatMap','sequelize','transaction','each','findOrCreate','forEach','emit','ids','select','field','from','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','all','removeTeams','isEmpty','removeAgents','userWhatsappQueue:remove','addAgents','omit','userWhatsappQueue:save','isArray','getAgents','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','sendStatus','status','end','count','offset','set','Content-Range','json','reject','save','update','then','destroy','WhatsappQueues','UserProfileResource','error','stack','name','send','map','WhatsappQueue','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','nolimit','limit','sort','where','pick','filter','VIRTUAL','merge','options','includeAll','include','rows','catch','show','params','rawAttributes','find','create','body','user','role','UserProfileSection','autoAssociation','describe','getMembers','findOne','get','UserWhatsappQueue','order','WhatsappQueueId','findAndCountAll','UserId','updatedAt','createdAt','format','SIP','getTeams','hasOwnProperty','addTeams'];(function(_0x580cea,_0x41fab5){var _0x5311c8=function(_0x3c654f){while(--_0x3c654f){_0x580cea['push'](_0x580cea['shift']());}};_0x5311c8(++_0x41fab5);}(_0x2d22,0x139));var _0x22d2=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x2d22[_0x3dd15e];return _0x231fd0;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x22d2('0x0'));var zipdir=require(_0x22d2('0x1'));var jsonpatch=require(_0x22d2('0x2'));var rp=require(_0x22d2('0x3'));var moment=require(_0x22d2('0x4'));var BPromise=require(_0x22d2('0x5'));var Mustache=require('mustache');var util=require(_0x22d2('0x6'));var path=require('path');var sox=require(_0x22d2('0x7'));var csv=require(_0x22d2('0x8'));var ejs=require(_0x22d2('0x9'));var fs=require('fs');var _=require(_0x22d2('0xa'));var squel=require('squel');var crypto=require(_0x22d2('0xb'));var jsforce=require(_0x22d2('0xc'));var deskjs=require(_0x22d2('0xd'));var toCsv=require(_0x22d2('0x8'));var querystring=require(_0x22d2('0xe'));var Papa=require(_0x22d2('0xf'));var Redis=require(_0x22d2('0x10'));var authService=require(_0x22d2('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x22d2('0x12'));var hardwareService=require(_0x22d2('0x13'));var logger=require('../../config/logger')(_0x22d2('0x14'));var utils=require('../../config/utils');var config=require(_0x22d2('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x22d2('0x16'))['db'];config[_0x22d2('0x17')]=_[_0x22d2('0x18')](config[_0x22d2('0x17')],{'host':_0x22d2('0x19'),'port':0x18eb});var socket=require(_0x22d2('0x1a'))(new Redis(config['redis']));require('./whatsappQueue.socket')[_0x22d2('0x1b')](socket);function respondWithStatusCode(_0x2d75e6,_0x12a1c5){_0x12a1c5=_0x12a1c5||0xcc;return function(_0x570a61){if(_0x570a61){return _0x2d75e6[_0x22d2('0x1c')](_0x12a1c5);}return _0x2d75e6[_0x22d2('0x1d')](_0x12a1c5)[_0x22d2('0x1e')]();};}function respondWithResult(_0x30fda1,_0x5d1383){_0x5d1383=_0x5d1383||0xc8;return function(_0x48002b){if(_0x48002b){return _0x30fda1[_0x22d2('0x1d')](_0x5d1383)['json'](_0x48002b);}};}function respondWithFilteredResult(_0x343fcf,_0x35eb54){return function(_0x230d4d){if(_0x230d4d){var _0x18e9f9=_0x230d4d[_0x22d2('0x1f')],_0x36a027=_0x35eb54[_0x22d2('0x20')],_0x159a63=_0x35eb54[_0x22d2('0x20')]+_0x35eb54['limit'],_0x82eb16;if(_0x159a63>=_0x18e9f9){_0x159a63=_0x18e9f9;_0x82eb16=0xc8;}else{_0x82eb16=0xce;}_0x343fcf[_0x22d2('0x1d')](_0x82eb16);return _0x343fcf[_0x22d2('0x21')](_0x22d2('0x22'),_0x36a027+'-'+_0x159a63+'/'+_0x18e9f9)[_0x22d2('0x23')](_0x230d4d);}return null;};}function patchUpdates(_0x44f426){return function(_0x35de8d){try{jsonpatch['apply'](_0x35de8d,_0x44f426,!![]);}catch(_0x31355d){return BPromise[_0x22d2('0x24')](_0x31355d);}return _0x35de8d[_0x22d2('0x25')]();};}function saveUpdates(_0x5ca8f0,_0x550efb){return function(_0x1eafd){if(_0x1eafd){return _0x1eafd[_0x22d2('0x26')](_0x5ca8f0)[_0x22d2('0x27')](function(_0x2bcdcf){return _0x2bcdcf;});}return null;};}function removeEntity(_0xea614a,_0x341e7d){return function(_0x30044d){if(_0x30044d){return _0x30044d[_0x22d2('0x28')]()[_0x22d2('0x27')](function(){var _0x1e671e=_0x30044d['get']({'plain':!![]});var _0x5e2ee9=_0x22d2('0x29');return db[_0x22d2('0x2a')]['destroy']({'where':{'type':_0x5e2ee9,'resourceId':_0x1e671e['id']}})[_0x22d2('0x27')](function(){return _0x30044d;});})[_0x22d2('0x27')](function(){_0xea614a[_0x22d2('0x1d')](0xcc)[_0x22d2('0x1e')]();});}};}function handleEntityNotFound(_0x415a2f,_0x21b176){return function(_0x47c1cf){if(!_0x47c1cf){_0x415a2f[_0x22d2('0x1c')](0x194);}return _0x47c1cf;};}function handleError(_0x36d94b,_0x5afaad){_0x5afaad=_0x5afaad||0x1f4;return function(_0x3cb8ca){logger[_0x22d2('0x2b')](_0x3cb8ca[_0x22d2('0x2c')]);if(_0x3cb8ca[_0x22d2('0x2d')]){delete _0x3cb8ca[_0x22d2('0x2d')];}_0x36d94b['status'](_0x5afaad)[_0x22d2('0x2e')](_0x3cb8ca);};}exports['index']=function(_0x219ed5,_0x200d5b){var _0x3d95e0={},_0x18ea3d={},_0x2317c0={'count':0x0,'rows':[]};var _0x463e08=_[_0x22d2('0x2f')](db[_0x22d2('0x30')]['rawAttributes'],function(_0x3fe469){return{'name':_0x3fe469[_0x22d2('0x31')],'type':_0x3fe469[_0x22d2('0x32')]['key']};});_0x18ea3d[_0x22d2('0x33')]=_[_0x22d2('0x2f')](_0x463e08,_0x22d2('0x2d'));_0x18ea3d[_0x22d2('0x34')]=_[_0x22d2('0x35')](_0x219ed5['query']);_0x18ea3d[_0x22d2('0x36')]=_[_0x22d2('0x37')](_0x18ea3d[_0x22d2('0x33')],_0x18ea3d[_0x22d2('0x34')]);_0x3d95e0[_0x22d2('0x38')]=_[_0x22d2('0x37')](_0x18ea3d['model'],qs[_0x22d2('0x39')](_0x219ed5[_0x22d2('0x34')][_0x22d2('0x39')]));_0x3d95e0[_0x22d2('0x38')]=_0x3d95e0['attributes'][_0x22d2('0x3a')]?_0x3d95e0['attributes']:_0x18ea3d[_0x22d2('0x33')];if(!_0x219ed5['query']['hasOwnProperty'](_0x22d2('0x3b'))){_0x3d95e0[_0x22d2('0x3c')]=qs[_0x22d2('0x3c')](_0x219ed5['query'][_0x22d2('0x3c')]);_0x3d95e0[_0x22d2('0x20')]=qs[_0x22d2('0x20')](_0x219ed5[_0x22d2('0x34')]['offset']);}_0x3d95e0['order']=qs['sort'](_0x219ed5[_0x22d2('0x34')][_0x22d2('0x3d')]);_0x3d95e0[_0x22d2('0x3e')]=qs[_0x22d2('0x36')](_[_0x22d2('0x3f')](_0x219ed5[_0x22d2('0x34')],_0x18ea3d[_0x22d2('0x36')]),_0x463e08);if(_0x219ed5[_0x22d2('0x34')][_0x22d2('0x40')]){_0x3d95e0['where']=_['merge'](_0x3d95e0[_0x22d2('0x3e')],{'$or':_[_0x22d2('0x2f')](_0x463e08,function(_0x4b8aad){if(_0x4b8aad[_0x22d2('0x32')]!==_0x22d2('0x41')){var _0x48a44f={};_0x48a44f[_0x4b8aad['name']]={'$like':'%'+_0x219ed5['query']['filter']+'%'};return _0x48a44f;}})});}_0x3d95e0=_[_0x22d2('0x42')]({},_0x3d95e0,_0x219ed5[_0x22d2('0x43')]);var _0x503866={'where':_0x3d95e0[_0x22d2('0x3e')]};return db[_0x22d2('0x30')][_0x22d2('0x1f')](_0x503866)[_0x22d2('0x27')](function(_0x368f99){_0x2317c0[_0x22d2('0x1f')]=_0x368f99;if(_0x219ed5[_0x22d2('0x34')][_0x22d2('0x44')]){_0x3d95e0[_0x22d2('0x45')]=[{'all':!![]}];}return db[_0x22d2('0x30')]['findAll'](_0x3d95e0);})[_0x22d2('0x27')](function(_0x4724e5){_0x2317c0[_0x22d2('0x46')]=_0x4724e5;return _0x2317c0;})['then'](respondWithFilteredResult(_0x200d5b,_0x3d95e0))[_0x22d2('0x47')](handleError(_0x200d5b,null));};exports[_0x22d2('0x48')]=function(_0x509630,_0x208c14){var _0x1b23f7={'raw':!![],'where':{'id':_0x509630[_0x22d2('0x49')]['id']}},_0x7fb1cb={};_0x7fb1cb['model']=_[_0x22d2('0x35')](db[_0x22d2('0x30')][_0x22d2('0x4a')]);_0x7fb1cb['query']=_[_0x22d2('0x35')](_0x509630[_0x22d2('0x34')]);_0x7fb1cb[_0x22d2('0x36')]=_[_0x22d2('0x37')](_0x7fb1cb[_0x22d2('0x33')],_0x7fb1cb[_0x22d2('0x34')]);_0x1b23f7[_0x22d2('0x38')]=_[_0x22d2('0x37')](_0x7fb1cb[_0x22d2('0x33')],qs[_0x22d2('0x39')](_0x509630['query'][_0x22d2('0x39')]));_0x1b23f7[_0x22d2('0x38')]=_0x1b23f7['attributes'][_0x22d2('0x3a')]?_0x1b23f7[_0x22d2('0x38')]:_0x7fb1cb['model'];if(_0x509630[_0x22d2('0x34')]['includeAll']){_0x1b23f7['include']=[{'all':!![]}];}_0x1b23f7=_[_0x22d2('0x42')]({},_0x1b23f7,_0x509630[_0x22d2('0x43')]);return db['WhatsappQueue'][_0x22d2('0x4b')](_0x1b23f7)[_0x22d2('0x27')](handleEntityNotFound(_0x208c14,null))[_0x22d2('0x27')](respondWithResult(_0x208c14,null))[_0x22d2('0x47')](handleError(_0x208c14,null));};exports[_0x22d2('0x4c')]=function(_0x8c6811,_0x378833){return db[_0x22d2('0x30')][_0x22d2('0x4c')](_0x8c6811[_0x22d2('0x4d')],{})['then'](function(_0x229e23){var _0x2dca27=_0x8c6811[_0x22d2('0x4e')]['get']({'plain':!![]});if(!_0x2dca27)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2dca27[_0x22d2('0x4f')]===_0x22d2('0x4e')){var _0x4b57b1=_0x229e23['get']({'plain':!![]});var _0x2fc48f='WhatsappQueues';return db[_0x22d2('0x50')][_0x22d2('0x4b')]({'where':{'name':_0x2fc48f,'userProfileId':_0x2dca27['userProfileId']},'raw':!![]})[_0x22d2('0x27')](function(_0x31eeb6){if(_0x31eeb6&&_0x31eeb6[_0x22d2('0x51')]===0x0){return db[_0x22d2('0x2a')][_0x22d2('0x4c')]({'name':_0x4b57b1[_0x22d2('0x2d')],'resourceId':_0x4b57b1['id'],'type':_0x31eeb6[_0x22d2('0x2d')],'sectionId':_0x31eeb6['id']},{})[_0x22d2('0x27')](function(){return _0x229e23;});}else{return _0x229e23;}})[_0x22d2('0x47')](function(_0x494b5e){logger[_0x22d2('0x2b')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x494b5e);throw _0x494b5e;});}return _0x229e23;})[_0x22d2('0x27')](respondWithResult(_0x378833,0xc9))[_0x22d2('0x47')](handleError(_0x378833,null));};exports[_0x22d2('0x26')]=function(_0x273b1,_0x3f45e6){if(_0x273b1['body']['id']){delete _0x273b1['body']['id'];}return db[_0x22d2('0x30')][_0x22d2('0x4b')]({'where':{'id':_0x273b1['params']['id']}})['then'](handleEntityNotFound(_0x3f45e6,null))[_0x22d2('0x27')](saveUpdates(_0x273b1[_0x22d2('0x4d')],null))[_0x22d2('0x27')](respondWithResult(_0x3f45e6,null))[_0x22d2('0x47')](handleError(_0x3f45e6,null));};exports[_0x22d2('0x28')]=function(_0x428c2c,_0x2561da){return db['WhatsappQueue'][_0x22d2('0x4b')]({'where':{'id':_0x428c2c[_0x22d2('0x49')]['id']}})['then'](handleEntityNotFound(_0x2561da,null))[_0x22d2('0x27')](removeEntity(_0x2561da,null))[_0x22d2('0x47')](handleError(_0x2561da,null));};exports[_0x22d2('0x52')]=function(_0x114196,_0x3e7bb8){return db[_0x22d2('0x30')][_0x22d2('0x52')]()[_0x22d2('0x27')](respondWithResult(_0x3e7bb8,null))['catch'](handleError(_0x3e7bb8,null));};exports[_0x22d2('0x53')]=function(_0xab6ab1,_0x457d29,_0x4449c0){var _0x35b4c0={'raw':!![],'where':{}},_0x53d3a1={},_0x3838e9;return db[_0x22d2('0x30')][_0x22d2('0x54')]({'where':{'id':_0xab6ab1[_0x22d2('0x49')]['id']}})[_0x22d2('0x27')](handleEntityNotFound(_0x457d29,null))[_0x22d2('0x27')](function(_0x2756ba){if(_0x2756ba){_0x3838e9=_0x2756ba[_0x22d2('0x55')]({'plain':!![]});_0x53d3a1['model']=_[_0x22d2('0x35')](db[_0x22d2('0x56')][_0x22d2('0x4a')]);_0x53d3a1[_0x22d2('0x34')]=_[_0x22d2('0x35')](_0xab6ab1['query']);_0x53d3a1[_0x22d2('0x36')]=_[_0x22d2('0x37')](_0x53d3a1['model'],_0x53d3a1[_0x22d2('0x34')]);_0x35b4c0[_0x22d2('0x38')]=_[_0x22d2('0x37')](_0x53d3a1[_0x22d2('0x33')],qs[_0x22d2('0x39')](_0xab6ab1['query'][_0x22d2('0x39')]));_0x35b4c0[_0x22d2('0x38')]=_0x35b4c0['attributes']['length']?_0x35b4c0[_0x22d2('0x38')]:_0x53d3a1[_0x22d2('0x33')];if(!_0xab6ab1[_0x22d2('0x34')]['hasOwnProperty']('nolimit')){_0x35b4c0[_0x22d2('0x3c')]=qs[_0x22d2('0x3c')](_0xab6ab1[_0x22d2('0x34')][_0x22d2('0x3c')]);_0x35b4c0[_0x22d2('0x20')]=qs[_0x22d2('0x20')](_0xab6ab1[_0x22d2('0x34')][_0x22d2('0x20')]);}_0x35b4c0[_0x22d2('0x57')]=qs[_0x22d2('0x3d')](_0xab6ab1['query'][_0x22d2('0x3d')]);_0x35b4c0['where']=qs['filters'](_['pick'](_0xab6ab1[_0x22d2('0x34')],_0x53d3a1[_0x22d2('0x36')]));_0x35b4c0[_0x22d2('0x3e')][_0x22d2('0x58')]=_0x2756ba['id'];if(_0xab6ab1[_0x22d2('0x34')]['filter']){_0x35b4c0['where']=_[_0x22d2('0x42')](_0x35b4c0[_0x22d2('0x3e')],{'$or':_['map'](_0x35b4c0[_0x22d2('0x38')],function(_0x103af4){var _0x476cce={};_0x476cce[_0x103af4]={'$like':'%'+_0xab6ab1['query'][_0x22d2('0x40')]+'%'};return _0x476cce;})});}_0x35b4c0=_[_0x22d2('0x42')]({},_0x35b4c0,_0xab6ab1[_0x22d2('0x43')]);return db['UserWhatsappQueue']['findAll'](_0x35b4c0);}})[_0x22d2('0x27')](function(_0x25774a){if(_0x25774a){return db['User'][_0x22d2('0x59')]({'where':{'id':_[_0x22d2('0x2f')](_0x25774a,_0x22d2('0x5a')),'role':'agent'},'attributes':['id',_0x22d2('0x2d'),'whatsappPause',_0x22d2('0x5b'),_0x22d2('0x5c')]});}})[_0x22d2('0x27')](function(_0x32137f){if(_0x32137f){return{'count':_0x32137f['count'],'rows':_[_0x22d2('0x2f')](_0x32137f[_0x22d2('0x46')],function(_0x53b948){return{'membername':_0x53b948[_0x22d2('0x2d')],'UserId':_0x53b948['id'],'queue_name':_0x3838e9[_0x22d2('0x2d')],'WhatsappQueueId':_0x3838e9['id'],'interface':util[_0x22d2('0x5d')]('%s/%s',_0x22d2('0x5e'),_0x53b948[_0x22d2('0x2d')]),'penalty':0x0,'paused':_0x53b948['whatsappPause'],'createdAt':_0x53b948[_0x22d2('0x5c')],'updatedAt':_0x53b948['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0x22d2('0x27')](respondWithFilteredResult(_0x457d29,_0x35b4c0))[_0x22d2('0x47')](handleError(_0x457d29,null));};exports['getTeams']=function(_0x4350d4,_0x55bf56,_0x363a82){var _0x12d83a={};var _0x3ecdd8={};var _0x4f0158;var _0x53829a;return db['WhatsappQueue'][_0x22d2('0x54')]({'where':{'id':_0x4350d4[_0x22d2('0x49')]['id']}})[_0x22d2('0x27')](handleEntityNotFound(_0x55bf56,null))['then'](function(_0x278eeb){if(_0x278eeb){_0x4f0158=_0x278eeb;_0x3ecdd8['model']=_[_0x22d2('0x35')](db['Team'][_0x22d2('0x4a')]);_0x3ecdd8[_0x22d2('0x34')]=_[_0x22d2('0x35')](_0x4350d4[_0x22d2('0x34')]);_0x3ecdd8[_0x22d2('0x36')]=_['intersection'](_0x3ecdd8[_0x22d2('0x33')],_0x3ecdd8[_0x22d2('0x34')]);_0x12d83a['attributes']=_[_0x22d2('0x37')](_0x3ecdd8[_0x22d2('0x33')],qs[_0x22d2('0x39')](_0x4350d4[_0x22d2('0x34')][_0x22d2('0x39')]));_0x12d83a[_0x22d2('0x38')]=_0x12d83a[_0x22d2('0x38')][_0x22d2('0x3a')]?_0x12d83a[_0x22d2('0x38')]:_0x3ecdd8[_0x22d2('0x33')];_0x12d83a[_0x22d2('0x57')]=qs[_0x22d2('0x3d')](_0x4350d4['query']['sort']);_0x12d83a[_0x22d2('0x3e')]=qs[_0x22d2('0x36')](_[_0x22d2('0x3f')](_0x4350d4[_0x22d2('0x34')],_0x3ecdd8[_0x22d2('0x36')]));if(_0x4350d4['query'][_0x22d2('0x40')]){_0x12d83a[_0x22d2('0x3e')]=_['merge'](_0x12d83a[_0x22d2('0x3e')],{'$or':_['map'](_0x12d83a[_0x22d2('0x38')],function(_0x1aa68f){var _0x3484f={};_0x3484f[_0x1aa68f]={'$like':'%'+_0x4350d4[_0x22d2('0x34')][_0x22d2('0x40')]+'%'};return _0x3484f;})});}_0x12d83a=_[_0x22d2('0x42')]({},_0x12d83a,_0x4350d4[_0x22d2('0x43')]);return _0x4f0158[_0x22d2('0x5f')](_0x12d83a);}})['then'](function(_0x57ecc0){if(_0x57ecc0){_0x53829a=_0x57ecc0[_0x22d2('0x3a')];if(!_0x4350d4[_0x22d2('0x34')][_0x22d2('0x60')](_0x22d2('0x3b'))){_0x12d83a['limit']=qs[_0x22d2('0x3c')](_0x4350d4[_0x22d2('0x34')][_0x22d2('0x3c')]);_0x12d83a[_0x22d2('0x20')]=qs['offset'](_0x4350d4[_0x22d2('0x34')]['offset']);}return _0x4f0158['getTeams'](_0x12d83a);}})['then'](function(_0x1b5342){if(_0x1b5342){return _0x1b5342?{'count':_0x53829a,'rows':_0x1b5342}:null;}})[_0x22d2('0x27')](respondWithResult(_0x55bf56,null))[_0x22d2('0x47')](handleError(_0x55bf56,null));};exports[_0x22d2('0x61')]=function(_0x3dd759,_0x81866a,_0x1d5b0c){var _0x3c2223=_0x3dd759[_0x22d2('0x4d')]['ids'];return db[_0x22d2('0x62')][_0x22d2('0x63')]({'where':{'id':_0x3c2223},'attributes':['id'],'include':[{'model':db[_0x22d2('0x64')],'as':_0x22d2('0x65'),'attributes':['id',_0x22d2('0x2d'),_0x22d2('0x66'),_0x22d2('0x67'),_0x22d2('0x68')],'raw':!![]}]})[_0x22d2('0x27')](function(_0x4e1f8a){if(_0x4e1f8a){var _0x338ed1=_[_0x22d2('0x69')](_0x4e1f8a,function(_0x22d5ec){var _0x176457=_0x22d5ec['get']({'plain':!![]});return _0x176457[_0x22d2('0x65')];});return db[_0x22d2('0x30')][_0x22d2('0x4b')]({'where':{'id':_0x3dd759[_0x22d2('0x49')]['id']}})[_0x22d2('0x27')](function(_0x952064){return db[_0x22d2('0x6a')][_0x22d2('0x6b')](function(_0x1bede6){return _0x952064[_0x22d2('0x61')](_0x3c2223,{'transaction':_0x1bede6})[_0x22d2('0x27')](function(){return BPromise[_0x22d2('0x6c')](_0x338ed1,function(_0x4f2ba4){return db[_0x22d2('0x56')][_0x22d2('0x6d')]({'where':{'UserId':_0x4f2ba4['id'],'WhatsappQueueId':_0x3dd759['params']['id']},'transaction':_0x1bede6});});})[_0x22d2('0x27')](function(){_0x338ed1[_0x22d2('0x6e')](function(_0x4613f9){socket[_0x22d2('0x6f')]('userWhatsappQueue:save',{'UserId':_0x4613f9['id'],'WhatsappQueueId':_0x952064['id']});});});});});}})[_0x22d2('0x27')](respondWithStatusCode(_0x81866a,null))[_0x22d2('0x47')](handleError(_0x81866a,null));};exports['removeTeams']=function(_0x5502f1,_0x38a605,_0x3de207){return db[_0x22d2('0x62')][_0x22d2('0x63')]({'where':{'id':_0x5502f1[_0x22d2('0x34')][_0x22d2('0x70')]},'attributes':['id'],'include':[{'model':db[_0x22d2('0x64')],'as':_0x22d2('0x65'),'attributes':['id'],'raw':!![]}]})[_0x22d2('0x27')](handleEntityNotFound(_0x38a605,null))[_0x22d2('0x27')](function(_0x4ec50f){var _0x530c90=_[_0x22d2('0x2f')](_0x4ec50f,'id');var _0x3be5cd=[];var _0x163a36=[];var _0x3c5262=squel[_0x22d2('0x71')]();_0x3c5262[_0x22d2('0x72')]('tq.TeamId')[_0x22d2('0x73')]('team_has_whatsapp_queues','tq')[_0x22d2('0x74')](_0x22d2('0x75'),'ut',_0x22d2('0x76'))['where']('WhatsappQueueId\x20=\x20?',_0x5502f1[_0x22d2('0x49')]['id']);for(var _0x22b96a=0x0;_0x22b96a<_0x4ec50f[_0x22d2('0x3a')];_0x22b96a+=0x1){let _0x22c1d4=_0x4ec50f[_0x22b96a];for(var _0x408e58=0x0;_0x408e58<_0x22c1d4[_0x22d2('0x65')][_0x22d2('0x3a')];_0x408e58+=0x1){let _0xa032cd=_0x22c1d4[_0x22d2('0x65')][_0x408e58];var _0x23304d=_0x3c5262['clone']();_0x23304d[_0x22d2('0x3e')](_0x22d2('0x77'),_0xa032cd['id']);_0x163a36[_0x22d2('0x78')](db[_0x22d2('0x6a')]['query'](_0x23304d[_0x22d2('0x79')](),{'type':db[_0x22d2('0x6a')][_0x22d2('0x7a')][_0x22d2('0x7b')]})[_0x22d2('0x27')](function(_0x534fce){if(_0x534fce[_0x22d2('0x3a')]===0x1){return _0xa032cd['id'];}else{var _0x24c82c=_[_0x22d2('0x7c')](_[_0x22d2('0x2f')](_0x534fce,_0x22d2('0x7d')),function(_0x51c81a){return _[_0x22d2('0x7e')](_0x530c90,_0x51c81a);});if(_0x24c82c){return _0xa032cd['id'];}}}));}}return BPromise[_0x22d2('0x7f')](_0x163a36)[_0x22d2('0x27')](function(_0x14e86a){_0x3be5cd=_(_0x3be5cd)['union'](_0x14e86a)['compact']()['value']();return db['WhatsappQueue'][_0x22d2('0x4b')]({'where':{'id':_0x5502f1[_0x22d2('0x49')]['id']}})[_0x22d2('0x27')](function(_0x47145f){return db[_0x22d2('0x6a')][_0x22d2('0x6b')](function(_0x249f3e){return _0x47145f[_0x22d2('0x80')](_0x5502f1[_0x22d2('0x34')][_0x22d2('0x70')],{'transaction':_0x249f3e})[_0x22d2('0x27')](function(){if(!_[_0x22d2('0x81')](_0x3be5cd)){return _0x47145f[_0x22d2('0x82')](_0x3be5cd,{'transaction':_0x249f3e});}})[_0x22d2('0x27')](function(){_0x3be5cd[_0x22d2('0x6e')](function(_0x155cd3){socket[_0x22d2('0x6f')](_0x22d2('0x83'),{'UserId':_0x155cd3,'WhatsappQueueId':_0x47145f['id']});});});});});});})['then'](respondWithStatusCode(_0x38a605,null))['catch'](handleError(_0x38a605,null));};exports['addAgents']=function(_0x2da8c9,_0xb32e58,_0x221ada){return db[_0x22d2('0x30')]['find']({'where':{'id':_0x2da8c9[_0x22d2('0x49')]['id']}})[_0x22d2('0x27')](handleEntityNotFound(_0xb32e58,null))[_0x22d2('0x27')](function(_0x4b91ab){if(_0x4b91ab){return _0x4b91ab[_0x22d2('0x84')](_0x2da8c9[_0x22d2('0x4d')]['ids'],_[_0x22d2('0x85')](_0x2da8c9[_0x22d2('0x4d')],[_0x22d2('0x70'),'id'])||{})['spread'](function(_0x58de44){for(var _0x2f2c55=0x0;_0x2f2c55<_0x2da8c9[_0x22d2('0x4d')][_0x22d2('0x70')][_0x22d2('0x3a')];_0x2f2c55+=0x1){socket[_0x22d2('0x6f')](_0x22d2('0x86'),{'UserId':_0x2da8c9[_0x22d2('0x4d')]['ids'][_0x2f2c55],'WhatsappQueueId':_0x2da8c9[_0x22d2('0x49')]['id']});}return _0x58de44;});}})[_0x22d2('0x27')](respondWithResult(_0xb32e58,null))['catch'](handleError(_0xb32e58,null));};exports[_0x22d2('0x82')]=function(_0x5d9bb3,_0x42bdcf,_0x122288){return db[_0x22d2('0x30')][_0x22d2('0x4b')]({'where':{'id':_0x5d9bb3['params']['id']}})[_0x22d2('0x27')](handleEntityNotFound(_0x42bdcf,null))[_0x22d2('0x27')](function(_0x339e2d){if(_0x339e2d){return _0x339e2d[_0x22d2('0x82')](_0x5d9bb3[_0x22d2('0x34')]['ids'])['then'](function(){if(_[_0x22d2('0x87')](_0x5d9bb3[_0x22d2('0x34')][_0x22d2('0x70')])){for(var _0x46c707=0x0;_0x46c707<_0x5d9bb3[_0x22d2('0x34')]['ids'][_0x22d2('0x3a')];_0x46c707+=0x1){socket[_0x22d2('0x6f')](_0x22d2('0x83'),{'UserId':Number(_0x5d9bb3[_0x22d2('0x34')][_0x22d2('0x70')][_0x46c707]),'WhatsappQueueId':Number(_0x5d9bb3[_0x22d2('0x49')]['id'])});}}else{socket[_0x22d2('0x6f')]('userWhatsappQueue:remove',{'UserId':Number(_0x5d9bb3['query']['ids']),'WhatsappQueueId':Number(_0x5d9bb3[_0x22d2('0x49')]['id'])});}});}})[_0x22d2('0x27')](respondWithStatusCode(_0x42bdcf,null))['catch'](handleError(_0x42bdcf,null));};exports[_0x22d2('0x88')]=function(_0x158b34,_0x32eea6,_0x5ed392){var _0x45f451={};var _0x4bb373={};var _0x40e905;var _0x1a1939;return db[_0x22d2('0x30')]['findOne']({'where':{'id':_0x158b34[_0x22d2('0x49')]['id']}})['then'](handleEntityNotFound(_0x32eea6,null))[_0x22d2('0x27')](function(_0x38af2b){if(_0x38af2b){_0x40e905=_0x38af2b;_0x4bb373[_0x22d2('0x33')]=_[_0x22d2('0x35')](db['User'][_0x22d2('0x4a')]);_0x4bb373['query']=_[_0x22d2('0x35')](_0x158b34[_0x22d2('0x34')]);_0x4bb373[_0x22d2('0x36')]=_[_0x22d2('0x37')](_0x4bb373[_0x22d2('0x33')],_0x4bb373[_0x22d2('0x34')]);_0x45f451[_0x22d2('0x38')]=_[_0x22d2('0x37')](_0x4bb373[_0x22d2('0x33')],qs[_0x22d2('0x39')](_0x158b34[_0x22d2('0x34')][_0x22d2('0x39')]));_0x45f451['attributes']=_0x45f451['attributes'][_0x22d2('0x3a')]?_0x45f451[_0x22d2('0x38')]:_0x4bb373[_0x22d2('0x33')];_0x45f451[_0x22d2('0x57')]=qs['sort'](_0x158b34['query'][_0x22d2('0x3d')]);_0x45f451['where']=qs[_0x22d2('0x36')](_[_0x22d2('0x3f')](_0x158b34[_0x22d2('0x34')],_0x4bb373[_0x22d2('0x36')]));if(_0x158b34[_0x22d2('0x34')][_0x22d2('0x40')]){_0x45f451[_0x22d2('0x3e')]=_[_0x22d2('0x42')](_0x45f451[_0x22d2('0x3e')],{'$or':_[_0x22d2('0x2f')](_0x45f451[_0x22d2('0x38')],function(_0x2ada47){var _0x5126db={};_0x5126db[_0x2ada47]={'$like':'%'+_0x158b34[_0x22d2('0x34')][_0x22d2('0x40')]+'%'};return _0x5126db;})});}_0x45f451=_[_0x22d2('0x42')]({},_0x45f451,_0x158b34[_0x22d2('0x43')]);return _0x40e905[_0x22d2('0x88')](_0x45f451);}})['then'](function(_0x14408d){if(_0x14408d){_0x1a1939=_0x14408d[_0x22d2('0x3a')];if(!_0x158b34[_0x22d2('0x34')][_0x22d2('0x60')](_0x22d2('0x3b'))){_0x45f451[_0x22d2('0x3c')]=qs[_0x22d2('0x3c')](_0x158b34[_0x22d2('0x34')][_0x22d2('0x3c')]);_0x45f451[_0x22d2('0x20')]=qs[_0x22d2('0x20')](_0x158b34['query'][_0x22d2('0x20')]);}return _0x40e905[_0x22d2('0x88')](_0x45f451);}})[_0x22d2('0x27')](function(_0x56307e){if(_0x56307e){return _0x56307e?{'count':_0x1a1939,'rows':_0x56307e}:null;}})[_0x22d2('0x27')](respondWithResult(_0x32eea6,null))[_0x22d2('0x47')](handleError(_0x32eea6,null));};
\ No newline at end of file
+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