Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / whatsappQueue / whatsappQueue.controller.js
index 94724ad..d6f12b5 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4f35=['sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./whatsappQueue.socket','register','end','status','limit','count','offset','set','Content-Range','json','apply','reject','update','then','destroy','get','WhatsappQueues','UserProfileResource','sendStatus','error','name','send','index','map','WhatsappQueue','rawAttributes','fieldName','type','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','options','includeAll','include','findAll','rows','catch','show','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','getMembers','findOne','UserWhatsappQueue','pick','WhatsappQueueId','User','findAndCountAll','whatsappPause','createdAt','format','%s/%s','SIP','updatedAt','Team','getTeams','ids','Agents','online','voicePause','interface','flatMap','sequelize','transaction','addTeams','each','findOrCreate','emit','userWhatsappQueue:save','removeTeams','select','field','tq.TeamId','from','join','user_has_teams','WhatsappQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','TeamId','all','compact','value','removeAgents','forEach','userWhatsappQueue:remove','addAgents','omit','getAgents','eml-format','rimraf','zip-dir','moment','bluebird','mustache','path'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x4f35,0x1a3));var _0x54f3=function(_0x4c123b,_0x5699c7){_0x4c123b=_0x4c123b-0x0;var _0x3d51ac=_0x4f35[_0x4c123b];return _0x3d51ac;};'use strict';var emlformat=require(_0x54f3('0x0'));var rimraf=require(_0x54f3('0x1'));var zipdir=require(_0x54f3('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0x54f3('0x3'));var BPromise=require(_0x54f3('0x4'));var Mustache=require(_0x54f3('0x5'));var util=require('util');var path=require(_0x54f3('0x6'));var sox=require(_0x54f3('0x7'));var csv=require(_0x54f3('0x8'));var ejs=require(_0x54f3('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x54f3('0xa'));var squel=require(_0x54f3('0xb'));var crypto=require(_0x54f3('0xc'));var jsforce=require(_0x54f3('0xd'));var deskjs=require(_0x54f3('0xe'));var toCsv=require('to-csv');var querystring=require(_0x54f3('0xf'));var Papa=require('papaparse');var Redis=require(_0x54f3('0x10'));var authService=require(_0x54f3('0x11'));var qs=require(_0x54f3('0x12'));var as=require(_0x54f3('0x13'));var hardwareService=require(_0x54f3('0x14'));var logger=require(_0x54f3('0x15'))(_0x54f3('0x16'));var utils=require(_0x54f3('0x17'));var config=require(_0x54f3('0x18'));var licenseUtil=require(_0x54f3('0x19'));var db=require(_0x54f3('0x1a'))['db'];config[_0x54f3('0x1b')]=_[_0x54f3('0x1c')](config[_0x54f3('0x1b')],{'host':_0x54f3('0x1d'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x54f3('0x1b')]));require(_0x54f3('0x1e'))[_0x54f3('0x1f')](socket);function respondWithStatusCode(_0x38b04d,_0x368330){_0x368330=_0x368330||0xcc;return function(_0x5e0988){if(_0x5e0988){return _0x38b04d['sendStatus'](_0x368330);}return _0x38b04d['status'](_0x368330)[_0x54f3('0x20')]();};}function respondWithResult(_0x4b7dbb,_0x2901ab){_0x2901ab=_0x2901ab||0xc8;return function(_0x326b1d){if(_0x326b1d){return _0x4b7dbb[_0x54f3('0x21')](_0x2901ab)['json'](_0x326b1d);}};}function respondWithFilteredResult(_0x2037d8,_0x32426a){return function(_0x2c187b){if(_0x2c187b){var _0x16b9ea=typeof _0x32426a['offset']==='undefined'&&typeof _0x32426a[_0x54f3('0x22')]==='undefined';var _0x8319c5=_0x2c187b[_0x54f3('0x23')];var _0xe2d6a0=_0x16b9ea?0x0:_0x32426a[_0x54f3('0x24')];var _0x52fa49=_0x16b9ea?_0x2c187b[_0x54f3('0x23')]:_0x32426a[_0x54f3('0x24')]+_0x32426a[_0x54f3('0x22')];var _0x52f4b9;if(_0x52fa49>=_0x8319c5){_0x52fa49=_0x8319c5;_0x52f4b9=0xc8;}else{_0x52f4b9=0xce;}_0x2037d8['status'](_0x52f4b9);return _0x2037d8[_0x54f3('0x25')](_0x54f3('0x26'),_0xe2d6a0+'-'+_0x52fa49+'/'+_0x8319c5)[_0x54f3('0x27')](_0x2c187b);}return null;};}function patchUpdates(_0x19f306){return function(_0xaab002){try{jsonpatch[_0x54f3('0x28')](_0xaab002,_0x19f306,!![]);}catch(_0x27c71f){return BPromise[_0x54f3('0x29')](_0x27c71f);}return _0xaab002['save']();};}function saveUpdates(_0x55372a,_0x1137a6){return function(_0x12bda5){if(_0x12bda5){return _0x12bda5[_0x54f3('0x2a')](_0x55372a)[_0x54f3('0x2b')](function(_0x1261ae){return _0x1261ae;});}return null;};}function removeEntity(_0x2fe2fb,_0xc25782){return function(_0x24f65b){if(_0x24f65b){return _0x24f65b[_0x54f3('0x2c')]()[_0x54f3('0x2b')](function(){var _0x5646ec=_0x24f65b[_0x54f3('0x2d')]({'plain':!![]});var _0x5184e5=_0x54f3('0x2e');return db[_0x54f3('0x2f')][_0x54f3('0x2c')]({'where':{'type':_0x5184e5,'resourceId':_0x5646ec['id']}})['then'](function(){return _0x24f65b;});})['then'](function(){_0x2fe2fb[_0x54f3('0x21')](0xcc)[_0x54f3('0x20')]();});}};}function handleEntityNotFound(_0x239c9e,_0x4cf0d9){return function(_0x13e4c7){if(!_0x13e4c7){_0x239c9e[_0x54f3('0x30')](0x194);}return _0x13e4c7;};}function handleError(_0x2ebc4e,_0x5435ce){_0x5435ce=_0x5435ce||0x1f4;return function(_0x1f0778){logger[_0x54f3('0x31')](_0x1f0778['stack']);if(_0x1f0778['name']){delete _0x1f0778[_0x54f3('0x32')];}_0x2ebc4e[_0x54f3('0x21')](_0x5435ce)[_0x54f3('0x33')](_0x1f0778);};}exports[_0x54f3('0x34')]=function(_0x57e9fa,_0x24e468){var _0x5eb673={},_0x30c658={},_0x2611be={'count':0x0,'rows':[]};var _0x26e82d=_[_0x54f3('0x35')](db[_0x54f3('0x36')][_0x54f3('0x37')],function(_0x5f41dd){return{'name':_0x5f41dd[_0x54f3('0x38')],'type':_0x5f41dd[_0x54f3('0x39')]['key']};});_0x30c658[_0x54f3('0x3a')]=_[_0x54f3('0x35')](_0x26e82d,_0x54f3('0x32'));_0x30c658[_0x54f3('0x3b')]=_[_0x54f3('0x3c')](_0x57e9fa[_0x54f3('0x3b')]);_0x30c658[_0x54f3('0x3d')]=_['intersection'](_0x30c658[_0x54f3('0x3a')],_0x30c658[_0x54f3('0x3b')]);_0x5eb673['attributes']=_[_0x54f3('0x3e')](_0x30c658['model'],qs[_0x54f3('0x3f')](_0x57e9fa[_0x54f3('0x3b')][_0x54f3('0x3f')]));_0x5eb673[_0x54f3('0x40')]=_0x5eb673[_0x54f3('0x40')][_0x54f3('0x41')]?_0x5eb673[_0x54f3('0x40')]:_0x30c658[_0x54f3('0x3a')];if(!_0x57e9fa[_0x54f3('0x3b')][_0x54f3('0x42')](_0x54f3('0x43'))){_0x5eb673[_0x54f3('0x22')]=qs[_0x54f3('0x22')](_0x57e9fa[_0x54f3('0x3b')][_0x54f3('0x22')]);_0x5eb673['offset']=qs[_0x54f3('0x24')](_0x57e9fa[_0x54f3('0x3b')][_0x54f3('0x24')]);}_0x5eb673[_0x54f3('0x44')]=qs['sort'](_0x57e9fa[_0x54f3('0x3b')][_0x54f3('0x45')]);_0x5eb673[_0x54f3('0x46')]=qs['filters'](_['pick'](_0x57e9fa[_0x54f3('0x3b')],_0x30c658[_0x54f3('0x3d')]),_0x26e82d);if(_0x57e9fa['query']['filter']){_0x5eb673[_0x54f3('0x46')]=_['merge'](_0x5eb673[_0x54f3('0x46')],{'$or':_[_0x54f3('0x35')](_0x26e82d,function(_0x35107c){if(_0x35107c[_0x54f3('0x39')]!=='VIRTUAL'){var _0x43c7c8={};_0x43c7c8[_0x35107c[_0x54f3('0x32')]]={'$like':'%'+_0x57e9fa[_0x54f3('0x3b')][_0x54f3('0x47')]+'%'};return _0x43c7c8;}})});}_0x5eb673=_[_0x54f3('0x48')]({},_0x5eb673,_0x57e9fa[_0x54f3('0x49')]);var _0x3063df={'where':_0x5eb673[_0x54f3('0x46')]};return db[_0x54f3('0x36')][_0x54f3('0x23')](_0x3063df)['then'](function(_0x4f880c){_0x2611be[_0x54f3('0x23')]=_0x4f880c;if(_0x57e9fa[_0x54f3('0x3b')][_0x54f3('0x4a')]){_0x5eb673[_0x54f3('0x4b')]=[{'all':!![]}];}return db[_0x54f3('0x36')][_0x54f3('0x4c')](_0x5eb673);})[_0x54f3('0x2b')](function(_0x3cf026){_0x2611be[_0x54f3('0x4d')]=_0x3cf026;return _0x2611be;})[_0x54f3('0x2b')](respondWithFilteredResult(_0x24e468,_0x5eb673))[_0x54f3('0x4e')](handleError(_0x24e468,null));};exports[_0x54f3('0x4f')]=function(_0x2b6cd6,_0x5af479){var _0xd4ebfc={'raw':!![],'where':{'id':_0x2b6cd6['params']['id']}},_0x591d83={};_0x591d83[_0x54f3('0x3a')]=_[_0x54f3('0x3c')](db[_0x54f3('0x36')][_0x54f3('0x37')]);_0x591d83[_0x54f3('0x3b')]=_['keys'](_0x2b6cd6['query']);_0x591d83['filters']=_[_0x54f3('0x3e')](_0x591d83[_0x54f3('0x3a')],_0x591d83[_0x54f3('0x3b')]);_0xd4ebfc[_0x54f3('0x40')]=_[_0x54f3('0x3e')](_0x591d83[_0x54f3('0x3a')],qs[_0x54f3('0x3f')](_0x2b6cd6[_0x54f3('0x3b')]['fields']));_0xd4ebfc['attributes']=_0xd4ebfc[_0x54f3('0x40')][_0x54f3('0x41')]?_0xd4ebfc[_0x54f3('0x40')]:_0x591d83[_0x54f3('0x3a')];if(_0x2b6cd6[_0x54f3('0x3b')]['includeAll']){_0xd4ebfc[_0x54f3('0x4b')]=[{'all':!![]}];}_0xd4ebfc=_[_0x54f3('0x48')]({},_0xd4ebfc,_0x2b6cd6[_0x54f3('0x49')]);return db[_0x54f3('0x36')][_0x54f3('0x50')](_0xd4ebfc)['then'](handleEntityNotFound(_0x5af479,null))[_0x54f3('0x2b')](respondWithResult(_0x5af479,null))[_0x54f3('0x4e')](handleError(_0x5af479,null));};exports[_0x54f3('0x51')]=function(_0x20e42c,_0x3b67a9){return db[_0x54f3('0x36')][_0x54f3('0x51')](_0x20e42c[_0x54f3('0x52')],{})[_0x54f3('0x2b')](function(_0x5acf32){var _0x3f7607=_0x20e42c['user']['get']({'plain':!![]});if(!_0x3f7607)throw new Error(_0x54f3('0x53'));if(_0x3f7607['role']===_0x54f3('0x54')){var _0x949f58=_0x5acf32[_0x54f3('0x2d')]({'plain':!![]});var _0x54d3e7='WhatsappQueues';return db[_0x54f3('0x55')][_0x54f3('0x50')]({'where':{'name':_0x54d3e7,'userProfileId':_0x3f7607['userProfileId']},'raw':!![]})['then'](function(_0x4dc108){if(_0x4dc108&&_0x4dc108[_0x54f3('0x56')]===0x0){return db['UserProfileResource'][_0x54f3('0x51')]({'name':_0x949f58[_0x54f3('0x32')],'resourceId':_0x949f58['id'],'type':_0x4dc108[_0x54f3('0x32')],'sectionId':_0x4dc108['id']},{})[_0x54f3('0x2b')](function(){return _0x5acf32;});}else{return _0x5acf32;}})[_0x54f3('0x4e')](function(_0x4283a8){logger[_0x54f3('0x31')](_0x54f3('0x57'),_0x4283a8);throw _0x4283a8;});}return _0x5acf32;})['then'](respondWithResult(_0x3b67a9,0xc9))[_0x54f3('0x4e')](handleError(_0x3b67a9,null));};exports[_0x54f3('0x2a')]=function(_0x16f511,_0x3b7acb){if(_0x16f511['body']['id']){delete _0x16f511['body']['id'];}return db[_0x54f3('0x36')]['find']({'where':{'id':_0x16f511[_0x54f3('0x58')]['id']}})[_0x54f3('0x2b')](handleEntityNotFound(_0x3b7acb,null))[_0x54f3('0x2b')](saveUpdates(_0x16f511['body'],null))[_0x54f3('0x2b')](respondWithResult(_0x3b7acb,null))[_0x54f3('0x4e')](handleError(_0x3b7acb,null));};exports['destroy']=function(_0x266694,_0x522320){return db[_0x54f3('0x36')][_0x54f3('0x50')]({'where':{'id':_0x266694[_0x54f3('0x58')]['id']}})[_0x54f3('0x2b')](handleEntityNotFound(_0x522320,null))[_0x54f3('0x2b')](removeEntity(_0x522320,null))['catch'](handleError(_0x522320,null));};exports['describe']=function(_0x2086ae,_0x853416){return db[_0x54f3('0x36')][_0x54f3('0x59')]()[_0x54f3('0x2b')](respondWithResult(_0x853416,null))['catch'](handleError(_0x853416,null));};exports[_0x54f3('0x5a')]=function(_0x1debce,_0x153040,_0x54da67){var _0x4fdf85={'raw':!![],'where':{}},_0x53c3fb={},_0x1a0ed5;return db[_0x54f3('0x36')][_0x54f3('0x5b')]({'where':{'id':_0x1debce[_0x54f3('0x58')]['id']}})['then'](handleEntityNotFound(_0x153040,null))['then'](function(_0x4cbe37){if(_0x4cbe37){_0x1a0ed5=_0x4cbe37['get']({'plain':!![]});_0x53c3fb['model']=_[_0x54f3('0x3c')](db[_0x54f3('0x5c')]['rawAttributes']);_0x53c3fb[_0x54f3('0x3b')]=_[_0x54f3('0x3c')](_0x1debce[_0x54f3('0x3b')]);_0x53c3fb['filters']=_[_0x54f3('0x3e')](_0x53c3fb[_0x54f3('0x3a')],_0x53c3fb[_0x54f3('0x3b')]);_0x4fdf85[_0x54f3('0x40')]=_['intersection'](_0x53c3fb[_0x54f3('0x3a')],qs[_0x54f3('0x3f')](_0x1debce[_0x54f3('0x3b')][_0x54f3('0x3f')]));_0x4fdf85[_0x54f3('0x40')]=_0x4fdf85['attributes'][_0x54f3('0x41')]?_0x4fdf85[_0x54f3('0x40')]:_0x53c3fb[_0x54f3('0x3a')];if(!_0x1debce['query']['hasOwnProperty'](_0x54f3('0x43'))){_0x4fdf85[_0x54f3('0x22')]=qs[_0x54f3('0x22')](_0x1debce['query'][_0x54f3('0x22')]);_0x4fdf85[_0x54f3('0x24')]=qs[_0x54f3('0x24')](_0x1debce[_0x54f3('0x3b')][_0x54f3('0x24')]);}_0x4fdf85['order']=qs[_0x54f3('0x45')](_0x1debce[_0x54f3('0x3b')][_0x54f3('0x45')]);_0x4fdf85[_0x54f3('0x46')]=qs['filters'](_[_0x54f3('0x5d')](_0x1debce[_0x54f3('0x3b')],_0x53c3fb[_0x54f3('0x3d')]));_0x4fdf85['where'][_0x54f3('0x5e')]=_0x4cbe37['id'];if(_0x1debce[_0x54f3('0x3b')][_0x54f3('0x47')]){_0x4fdf85[_0x54f3('0x46')]=_[_0x54f3('0x48')](_0x4fdf85[_0x54f3('0x46')],{'$or':_[_0x54f3('0x35')](_0x4fdf85[_0x54f3('0x40')],function(_0x4bfdb5){var _0x493621={};_0x493621[_0x4bfdb5]={'$like':'%'+_0x1debce[_0x54f3('0x3b')][_0x54f3('0x47')]+'%'};return _0x493621;})});}_0x4fdf85=_[_0x54f3('0x48')]({},_0x4fdf85,_0x1debce[_0x54f3('0x49')]);return db[_0x54f3('0x5c')][_0x54f3('0x4c')](_0x4fdf85);}})['then'](function(_0xc6a0e3){if(_0xc6a0e3){return db[_0x54f3('0x5f')][_0x54f3('0x60')]({'where':{'id':_[_0x54f3('0x35')](_0xc6a0e3,'UserId'),'role':'agent'},'attributes':['id',_0x54f3('0x32'),_0x54f3('0x61'),'updatedAt',_0x54f3('0x62')]});}})[_0x54f3('0x2b')](function(_0x20c70c){if(_0x20c70c){return{'count':_0x20c70c['count'],'rows':_[_0x54f3('0x35')](_0x20c70c[_0x54f3('0x4d')],function(_0x3ff72e){return{'membername':_0x3ff72e[_0x54f3('0x32')],'UserId':_0x3ff72e['id'],'queue_name':_0x1a0ed5[_0x54f3('0x32')],'WhatsappQueueId':_0x1a0ed5['id'],'interface':util[_0x54f3('0x63')](_0x54f3('0x64'),_0x54f3('0x65'),_0x3ff72e['name']),'penalty':0x0,'paused':_0x3ff72e[_0x54f3('0x61')],'createdAt':_0x3ff72e[_0x54f3('0x62')],'updatedAt':_0x3ff72e[_0x54f3('0x66')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x54f3('0x2b')](respondWithFilteredResult(_0x153040,_0x4fdf85))[_0x54f3('0x4e')](handleError(_0x153040,null));};exports['getTeams']=function(_0x3b8319,_0xcb032,_0x12b0e3){var _0x4da35b={};var _0x4bb82b={};var _0x2a180c;var _0x424007;return db[_0x54f3('0x36')][_0x54f3('0x5b')]({'where':{'id':_0x3b8319['params']['id']}})['then'](handleEntityNotFound(_0xcb032,null))[_0x54f3('0x2b')](function(_0x2a90d8){if(_0x2a90d8){_0x2a180c=_0x2a90d8;_0x4bb82b[_0x54f3('0x3a')]=_[_0x54f3('0x3c')](db[_0x54f3('0x67')]['rawAttributes']);_0x4bb82b[_0x54f3('0x3b')]=_['keys'](_0x3b8319['query']);_0x4bb82b[_0x54f3('0x3d')]=_['intersection'](_0x4bb82b['model'],_0x4bb82b[_0x54f3('0x3b')]);_0x4da35b[_0x54f3('0x40')]=_[_0x54f3('0x3e')](_0x4bb82b[_0x54f3('0x3a')],qs['fields'](_0x3b8319[_0x54f3('0x3b')][_0x54f3('0x3f')]));_0x4da35b['attributes']=_0x4da35b['attributes'][_0x54f3('0x41')]?_0x4da35b[_0x54f3('0x40')]:_0x4bb82b[_0x54f3('0x3a')];_0x4da35b[_0x54f3('0x44')]=qs[_0x54f3('0x45')](_0x3b8319['query'][_0x54f3('0x45')]);_0x4da35b['where']=qs['filters'](_['pick'](_0x3b8319['query'],_0x4bb82b[_0x54f3('0x3d')]));if(_0x3b8319[_0x54f3('0x3b')][_0x54f3('0x47')]){_0x4da35b[_0x54f3('0x46')]=_[_0x54f3('0x48')](_0x4da35b[_0x54f3('0x46')],{'$or':_[_0x54f3('0x35')](_0x4da35b['attributes'],function(_0x29ec4e){var _0xc3713f={};_0xc3713f[_0x29ec4e]={'$like':'%'+_0x3b8319['query']['filter']+'%'};return _0xc3713f;})});}_0x4da35b=_[_0x54f3('0x48')]({},_0x4da35b,_0x3b8319[_0x54f3('0x49')]);return _0x2a180c[_0x54f3('0x68')](_0x4da35b);}})[_0x54f3('0x2b')](function(_0x36c6e1){if(_0x36c6e1){_0x424007=_0x36c6e1['length'];if(!_0x3b8319[_0x54f3('0x3b')][_0x54f3('0x42')](_0x54f3('0x43'))){_0x4da35b['limit']=qs[_0x54f3('0x22')](_0x3b8319[_0x54f3('0x3b')][_0x54f3('0x22')]);_0x4da35b['offset']=qs[_0x54f3('0x24')](_0x3b8319[_0x54f3('0x3b')][_0x54f3('0x24')]);}return _0x2a180c[_0x54f3('0x68')](_0x4da35b);}})[_0x54f3('0x2b')](function(_0x12517a){if(_0x12517a){return _0x12517a?{'count':_0x424007,'rows':_0x12517a}:null;}})[_0x54f3('0x2b')](respondWithResult(_0xcb032,null))[_0x54f3('0x4e')](handleError(_0xcb032,null));};exports['addTeams']=function(_0x2c691e,_0x2ee280,_0x47731c){var _0x3742de=_0x2c691e[_0x54f3('0x52')][_0x54f3('0x69')];return db['Team'][_0x54f3('0x4c')]({'where':{'id':_0x3742de},'attributes':['id'],'include':[{'model':db[_0x54f3('0x5f')],'as':_0x54f3('0x6a'),'attributes':['id',_0x54f3('0x32'),_0x54f3('0x6b'),_0x54f3('0x6c'),_0x54f3('0x6d')],'raw':!![]}]})[_0x54f3('0x2b')](function(_0x2f2ad1){if(_0x2f2ad1){var _0x4e608f=_[_0x54f3('0x6e')](_0x2f2ad1,function(_0x177a28){var _0x182888=_0x177a28[_0x54f3('0x2d')]({'plain':!![]});return _0x182888[_0x54f3('0x6a')];});return db[_0x54f3('0x36')]['find']({'where':{'id':_0x2c691e[_0x54f3('0x58')]['id']}})[_0x54f3('0x2b')](function(_0x32b7e0){return db[_0x54f3('0x6f')][_0x54f3('0x70')](function(_0x13bac1){return _0x32b7e0[_0x54f3('0x71')](_0x3742de,{'transaction':_0x13bac1})[_0x54f3('0x2b')](function(){return BPromise[_0x54f3('0x72')](_0x4e608f,function(_0x37862e){return db[_0x54f3('0x5c')][_0x54f3('0x73')]({'where':{'UserId':_0x37862e['id'],'WhatsappQueueId':_0x2c691e[_0x54f3('0x58')]['id']},'transaction':_0x13bac1});});})[_0x54f3('0x2b')](function(){_0x4e608f['forEach'](function(_0x5a879b){socket[_0x54f3('0x74')](_0x54f3('0x75'),{'UserId':_0x5a879b['id'],'WhatsappQueueId':_0x32b7e0['id']});});});});});}})[_0x54f3('0x2b')](respondWithStatusCode(_0x2ee280,null))[_0x54f3('0x4e')](handleError(_0x2ee280,null));};exports[_0x54f3('0x76')]=function(_0x471286,_0x31974f,_0x5bae41){return db[_0x54f3('0x67')]['findAll']({'where':{'id':_0x471286[_0x54f3('0x3b')][_0x54f3('0x69')]},'attributes':['id'],'include':[{'model':db[_0x54f3('0x5f')],'as':'Agents','attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x31974f,null))[_0x54f3('0x2b')](function(_0x406d1a){var _0x70711a=_[_0x54f3('0x35')](_0x406d1a,'id');var _0x5d6fba=[];var _0x429684=[];var _0x367e8c=squel[_0x54f3('0x77')]();_0x367e8c[_0x54f3('0x78')](_0x54f3('0x79'))[_0x54f3('0x7a')]('team_has_whatsapp_queues','tq')[_0x54f3('0x7b')](_0x54f3('0x7c'),'ut','ut.TeamId\x20=\x20tq.TeamId')[_0x54f3('0x46')](_0x54f3('0x7d'),_0x471286[_0x54f3('0x58')]['id']);for(var _0x2e067b=0x0;_0x2e067b<_0x406d1a['length'];_0x2e067b+=0x1){let _0x592238=_0x406d1a[_0x2e067b];for(var _0x883605=0x0;_0x883605<_0x592238[_0x54f3('0x6a')][_0x54f3('0x41')];_0x883605+=0x1){let _0x22f06d=_0x592238[_0x54f3('0x6a')][_0x883605];var _0x10499f=_0x367e8c[_0x54f3('0x7e')]();_0x10499f[_0x54f3('0x46')](_0x54f3('0x7f'),_0x22f06d['id']);_0x429684[_0x54f3('0x80')](db['sequelize']['query'](_0x10499f[_0x54f3('0x81')](),{'type':db['sequelize'][_0x54f3('0x82')][_0x54f3('0x83')]})[_0x54f3('0x2b')](function(_0x368d9f){if(_0x368d9f[_0x54f3('0x41')]===0x1){return _0x22f06d['id'];}else{var _0x39ba65=_['every'](_[_0x54f3('0x35')](_0x368d9f,_0x54f3('0x84')),function(_0x522de1){return _['includes'](_0x70711a,_0x522de1);});if(_0x39ba65){return _0x22f06d['id'];}}}));}}return BPromise[_0x54f3('0x85')](_0x429684)[_0x54f3('0x2b')](function(_0x4cdd64){_0x5d6fba=_(_0x5d6fba)['union'](_0x4cdd64)[_0x54f3('0x86')]()[_0x54f3('0x87')]();return db[_0x54f3('0x36')]['find']({'where':{'id':_0x471286[_0x54f3('0x58')]['id']}})[_0x54f3('0x2b')](function(_0x3ab356){return db[_0x54f3('0x6f')]['transaction'](function(_0xd8debe){return _0x3ab356['removeTeams'](_0x471286[_0x54f3('0x3b')][_0x54f3('0x69')],{'transaction':_0xd8debe})[_0x54f3('0x2b')](function(){if(!_['isEmpty'](_0x5d6fba)){return _0x3ab356[_0x54f3('0x88')](_0x5d6fba,{'transaction':_0xd8debe});}})[_0x54f3('0x2b')](function(){_0x5d6fba[_0x54f3('0x89')](function(_0x35565d){socket[_0x54f3('0x74')](_0x54f3('0x8a'),{'UserId':_0x35565d,'WhatsappQueueId':_0x3ab356['id']});});});});});});})[_0x54f3('0x2b')](respondWithStatusCode(_0x31974f,null))[_0x54f3('0x4e')](handleError(_0x31974f,null));};exports[_0x54f3('0x8b')]=function(_0x2d39f7,_0xdf0967,_0x1a17f9){return db[_0x54f3('0x36')]['find']({'where':{'id':_0x2d39f7[_0x54f3('0x58')]['id']}})['then'](handleEntityNotFound(_0xdf0967,null))[_0x54f3('0x2b')](function(_0x520fe0){if(_0x520fe0){return _0x520fe0[_0x54f3('0x8b')](_0x2d39f7['body'][_0x54f3('0x69')],_[_0x54f3('0x8c')](_0x2d39f7[_0x54f3('0x52')],[_0x54f3('0x69'),'id'])||{})['spread'](function(_0x5b0d74){for(var _0x4705f5=0x0;_0x4705f5<_0x2d39f7[_0x54f3('0x52')][_0x54f3('0x69')][_0x54f3('0x41')];_0x4705f5+=0x1){socket[_0x54f3('0x74')](_0x54f3('0x75'),{'UserId':Number(_0x2d39f7[_0x54f3('0x52')][_0x54f3('0x69')][_0x4705f5]),'WhatsappQueueId':Number(_0x2d39f7[_0x54f3('0x58')]['id'])});}return _0x5b0d74;});}})[_0x54f3('0x2b')](respondWithResult(_0xdf0967,null))[_0x54f3('0x4e')](handleError(_0xdf0967,null));};exports[_0x54f3('0x88')]=function(_0x426618,_0x2d0d41,_0x30793b){return db['WhatsappQueue'][_0x54f3('0x50')]({'where':{'id':_0x426618['params']['id']}})[_0x54f3('0x2b')](handleEntityNotFound(_0x2d0d41,null))[_0x54f3('0x2b')](function(_0x146989){if(_0x146989){return _0x146989[_0x54f3('0x88')](_0x426618[_0x54f3('0x3b')]['ids'])[_0x54f3('0x2b')](function(){if(_['isArray'](_0x426618[_0x54f3('0x3b')]['ids'])){for(var _0x58ff45=0x0;_0x58ff45<_0x426618[_0x54f3('0x3b')]['ids']['length'];_0x58ff45+=0x1){socket[_0x54f3('0x74')](_0x54f3('0x8a'),{'UserId':Number(_0x426618['query']['ids'][_0x58ff45]),'WhatsappQueueId':Number(_0x426618[_0x54f3('0x58')]['id'])});}}else{socket[_0x54f3('0x74')]('userWhatsappQueue:remove',{'UserId':Number(_0x426618[_0x54f3('0x3b')][_0x54f3('0x69')]),'WhatsappQueueId':Number(_0x426618['params']['id'])});}});}})[_0x54f3('0x2b')](respondWithStatusCode(_0x2d0d41,null))['catch'](handleError(_0x2d0d41,null));};exports[_0x54f3('0x8d')]=function(_0x5e3b5e,_0x55c01a,_0x325c9e){var _0x50024e={};var _0x277b02={};var _0x3e8d69;var _0x1f4726;return db[_0x54f3('0x36')][_0x54f3('0x5b')]({'where':{'id':_0x5e3b5e[_0x54f3('0x58')]['id']}})[_0x54f3('0x2b')](handleEntityNotFound(_0x55c01a,null))['then'](function(_0x1a0ceb){if(_0x1a0ceb){_0x3e8d69=_0x1a0ceb;_0x277b02[_0x54f3('0x3a')]=_[_0x54f3('0x3c')](db['User'][_0x54f3('0x37')]);_0x277b02[_0x54f3('0x3b')]=_['keys'](_0x5e3b5e['query']);_0x277b02[_0x54f3('0x3d')]=_['intersection'](_0x277b02[_0x54f3('0x3a')],_0x277b02[_0x54f3('0x3b')]);_0x50024e['attributes']=_['intersection'](_0x277b02[_0x54f3('0x3a')],qs[_0x54f3('0x3f')](_0x5e3b5e[_0x54f3('0x3b')][_0x54f3('0x3f')]));_0x50024e[_0x54f3('0x40')]=_0x50024e[_0x54f3('0x40')][_0x54f3('0x41')]?_0x50024e['attributes']:_0x277b02[_0x54f3('0x3a')];_0x50024e[_0x54f3('0x44')]=qs[_0x54f3('0x45')](_0x5e3b5e[_0x54f3('0x3b')][_0x54f3('0x45')]);_0x50024e[_0x54f3('0x46')]=qs[_0x54f3('0x3d')](_[_0x54f3('0x5d')](_0x5e3b5e[_0x54f3('0x3b')],_0x277b02['filters']));if(_0x5e3b5e[_0x54f3('0x3b')]['filter']){_0x50024e['where']=_['merge'](_0x50024e[_0x54f3('0x46')],{'$or':_[_0x54f3('0x35')](_0x50024e[_0x54f3('0x40')],function(_0x5c51f5){var _0x5620c1={};_0x5620c1[_0x5c51f5]={'$like':'%'+_0x5e3b5e[_0x54f3('0x3b')][_0x54f3('0x47')]+'%'};return _0x5620c1;})});}_0x50024e=_['merge']({},_0x50024e,_0x5e3b5e['options']);return _0x3e8d69[_0x54f3('0x8d')](_0x50024e);}})['then'](function(_0x4c1c9b){if(_0x4c1c9b){_0x1f4726=_0x4c1c9b['length'];if(!_0x5e3b5e[_0x54f3('0x3b')][_0x54f3('0x42')](_0x54f3('0x43'))){_0x50024e['limit']=qs[_0x54f3('0x22')](_0x5e3b5e[_0x54f3('0x3b')][_0x54f3('0x22')]);_0x50024e[_0x54f3('0x24')]=qs[_0x54f3('0x24')](_0x5e3b5e['query'][_0x54f3('0x24')]);}return _0x3e8d69['getAgents'](_0x50024e);}})['then'](function(_0xbfc63f){if(_0xbfc63f){return _0xbfc63f?{'count':_0x1f4726,'rows':_0xbfc63f}:null;}})[_0x54f3('0x2b')](respondWithResult(_0x55c01a,null))[_0x54f3('0x4e')](handleError(_0x55c01a,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