Built motion from commit 994c64e1.|2.6.1
[motion2.git] / server / api / whatsappQueue / whatsappQueue.controller.js
index 6d824f6..666ed67 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xba0e=['attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','show','params','keys','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','findOne','UserWhatsappQueue','WhatsappQueueId','map','findAll','User','findAndCountAll','updatedAt','createdAt','%s/%s','SIP','whatsappPause','getTeams','Team','ids','voicePause','interface','flatMap','Agents','transaction','emit','removeTeams','select','field','tq.TeamId','from','team_has_whatsapp_queues','ut.TeamId\x20=\x20tq.TeamId','WhatsappQueueId\x20=\x20?','push','toString','SELECT','includes','all','union','compact','isEmpty','removeAgents','forEach','userWhatsappQueue:remove','addAgents','spread','isArray','getAgents','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','to-csv','lodash','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','./whatsappQueue.socket','register','sendStatus','status','end','undefined','count','offset','limit','set','Content-Range','json','reject','save','update','then','destroy','get','WhatsappQueues','UserProfileResource','error','stack','name','send','WhatsappQueue','rawAttributes','fieldName','type','key','model','query','filters','intersection'];(function(_0x2a6809,_0x44edde){var _0x11c371=function(_0x1a4888){while(--_0x1a4888){_0x2a6809['push'](_0x2a6809['shift']());}};_0x11c371(++_0x44edde);}(_0xba0e,0xd1));var _0xeba0=function(_0x4c45d9,_0x4be8de){_0x4c45d9=_0x4c45d9-0x0;var _0x40436b=_0xba0e[_0x4c45d9];return _0x40436b;};'use strict';var emlformat=require(_0xeba0('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xeba0('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xeba0('0x2'));var moment=require(_0xeba0('0x3'));var BPromise=require(_0xeba0('0x4'));var Mustache=require(_0xeba0('0x5'));var util=require(_0xeba0('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0xeba0('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xeba0('0x8'));var squel=require('squel');var crypto=require(_0xeba0('0x9'));var jsforce=require('jsforce');var deskjs=require(_0xeba0('0xa'));var toCsv=require(_0xeba0('0x7'));var querystring=require(_0xeba0('0xb'));var Papa=require(_0xeba0('0xc'));var Redis=require('ioredis');var authService=require(_0xeba0('0xd'));var qs=require(_0xeba0('0xe'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xeba0('0xf'));var logger=require(_0xeba0('0x10'))(_0xeba0('0x11'));var utils=require(_0xeba0('0x12'));var config=require(_0xeba0('0x13'));var licenseUtil=require(_0xeba0('0x14'));var db=require(_0xeba0('0x15'))['db'];config[_0xeba0('0x16')]=_[_0xeba0('0x17')](config[_0xeba0('0x16')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xeba0('0x16')]));require(_0xeba0('0x18'))[_0xeba0('0x19')](socket);function respondWithStatusCode(_0x1322c5,_0x346e8f){_0x346e8f=_0x346e8f||0xcc;return function(_0x23efd0){if(_0x23efd0){return _0x1322c5[_0xeba0('0x1a')](_0x346e8f);}return _0x1322c5[_0xeba0('0x1b')](_0x346e8f)[_0xeba0('0x1c')]();};}function respondWithResult(_0x3cebc3,_0x107714){_0x107714=_0x107714||0xc8;return function(_0x1eb685){if(_0x1eb685){return _0x3cebc3[_0xeba0('0x1b')](_0x107714)['json'](_0x1eb685);}};}function respondWithFilteredResult(_0x45ed71,_0x2af16c){return function(_0x3a5a5c){if(_0x3a5a5c){var _0x5b81f5=typeof _0x2af16c['offset']===_0xeba0('0x1d')&&typeof _0x2af16c['limit']==='undefined';var _0x3e6169=_0x3a5a5c[_0xeba0('0x1e')];var _0x19217c=_0x5b81f5?0x0:_0x2af16c[_0xeba0('0x1f')];var _0x2b3e94=_0x5b81f5?_0x3a5a5c[_0xeba0('0x1e')]:_0x2af16c[_0xeba0('0x1f')]+_0x2af16c[_0xeba0('0x20')];var _0x9fdfeb;if(_0x2b3e94>=_0x3e6169){_0x2b3e94=_0x3e6169;_0x9fdfeb=0xc8;}else{_0x9fdfeb=0xce;}_0x45ed71['status'](_0x9fdfeb);return _0x45ed71[_0xeba0('0x21')](_0xeba0('0x22'),_0x19217c+'-'+_0x2b3e94+'/'+_0x3e6169)[_0xeba0('0x23')](_0x3a5a5c);}return null;};}function patchUpdates(_0x1f25e7){return function(_0x50dda0){try{jsonpatch['apply'](_0x50dda0,_0x1f25e7,!![]);}catch(_0x2a209d){return BPromise[_0xeba0('0x24')](_0x2a209d);}return _0x50dda0[_0xeba0('0x25')]();};}function saveUpdates(_0x3efb81,_0x4950d5){return function(_0x26aec4){if(_0x26aec4){return _0x26aec4[_0xeba0('0x26')](_0x3efb81)[_0xeba0('0x27')](function(_0x4a3d77){return _0x4a3d77;});}return null;};}function removeEntity(_0x84ff51,_0x59af79){return function(_0x15e4c7){if(_0x15e4c7){return _0x15e4c7[_0xeba0('0x28')]()[_0xeba0('0x27')](function(){var _0x27b8b5=_0x15e4c7[_0xeba0('0x29')]({'plain':!![]});var _0x1303b4=_0xeba0('0x2a');return db[_0xeba0('0x2b')]['destroy']({'where':{'type':_0x1303b4,'resourceId':_0x27b8b5['id']}})['then'](function(){return _0x15e4c7;});})['then'](function(){_0x84ff51['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4422ad,_0x52325b){return function(_0x24e08d){if(!_0x24e08d){_0x4422ad['sendStatus'](0x194);}return _0x24e08d;};}function handleError(_0x515c54,_0x1ab874){_0x1ab874=_0x1ab874||0x1f4;return function(_0x2842c8){logger[_0xeba0('0x2c')](_0x2842c8[_0xeba0('0x2d')]);if(_0x2842c8[_0xeba0('0x2e')]){delete _0x2842c8['name'];}_0x515c54[_0xeba0('0x1b')](_0x1ab874)[_0xeba0('0x2f')](_0x2842c8);};}exports['index']=function(_0x27758b,_0x559291){var _0x57fa1f={},_0x4b6d76={},_0x14e189={'count':0x0,'rows':[]};var _0x3a724a=_['map'](db[_0xeba0('0x30')][_0xeba0('0x31')],function(_0x172154){return{'name':_0x172154[_0xeba0('0x32')],'type':_0x172154[_0xeba0('0x33')][_0xeba0('0x34')]};});_0x4b6d76[_0xeba0('0x35')]=_['map'](_0x3a724a,_0xeba0('0x2e'));_0x4b6d76['query']=_['keys'](_0x27758b[_0xeba0('0x36')]);_0x4b6d76[_0xeba0('0x37')]=_[_0xeba0('0x38')](_0x4b6d76[_0xeba0('0x35')],_0x4b6d76[_0xeba0('0x36')]);_0x57fa1f[_0xeba0('0x39')]=_['intersection'](_0x4b6d76[_0xeba0('0x35')],qs['fields'](_0x27758b[_0xeba0('0x36')][_0xeba0('0x3a')]));_0x57fa1f[_0xeba0('0x39')]=_0x57fa1f[_0xeba0('0x39')][_0xeba0('0x3b')]?_0x57fa1f[_0xeba0('0x39')]:_0x4b6d76[_0xeba0('0x35')];if(!_0x27758b[_0xeba0('0x36')][_0xeba0('0x3c')](_0xeba0('0x3d'))){_0x57fa1f[_0xeba0('0x20')]=qs['limit'](_0x27758b['query']['limit']);_0x57fa1f[_0xeba0('0x1f')]=qs[_0xeba0('0x1f')](_0x27758b[_0xeba0('0x36')][_0xeba0('0x1f')]);}_0x57fa1f[_0xeba0('0x3e')]=qs[_0xeba0('0x3f')](_0x27758b['query']['sort']);_0x57fa1f[_0xeba0('0x40')]=qs[_0xeba0('0x37')](_[_0xeba0('0x41')](_0x27758b[_0xeba0('0x36')],_0x4b6d76[_0xeba0('0x37')]),_0x3a724a);if(_0x27758b[_0xeba0('0x36')][_0xeba0('0x42')]){_0x57fa1f['where']=_[_0xeba0('0x43')](_0x57fa1f[_0xeba0('0x40')],{'$or':_['map'](_0x3a724a,function(_0x43fca5){if(_0x43fca5['type']!==_0xeba0('0x44')){var _0x546e38={};_0x546e38[_0x43fca5[_0xeba0('0x2e')]]={'$like':'%'+_0x27758b['query'][_0xeba0('0x42')]+'%'};return _0x546e38;}})});}_0x57fa1f=_[_0xeba0('0x43')]({},_0x57fa1f,_0x27758b[_0xeba0('0x45')]);var _0x49c3cd={'where':_0x57fa1f[_0xeba0('0x40')]};return db[_0xeba0('0x30')][_0xeba0('0x1e')](_0x49c3cd)[_0xeba0('0x27')](function(_0x3c4172){_0x14e189['count']=_0x3c4172;if(_0x27758b[_0xeba0('0x36')][_0xeba0('0x46')]){_0x57fa1f[_0xeba0('0x47')]=[{'all':!![]}];}return db[_0xeba0('0x30')]['findAll'](_0x57fa1f);})['then'](function(_0x58d2cd){_0x14e189[_0xeba0('0x48')]=_0x58d2cd;return _0x14e189;})['then'](respondWithFilteredResult(_0x559291,_0x57fa1f))[_0xeba0('0x49')](handleError(_0x559291,null));};exports[_0xeba0('0x4a')]=function(_0x1fcba4,_0x3da83e){var _0x544504={'raw':!![],'where':{'id':_0x1fcba4[_0xeba0('0x4b')]['id']}},_0x1afde9={};_0x1afde9[_0xeba0('0x35')]=_[_0xeba0('0x4c')](db[_0xeba0('0x30')][_0xeba0('0x31')]);_0x1afde9[_0xeba0('0x36')]=_[_0xeba0('0x4c')](_0x1fcba4[_0xeba0('0x36')]);_0x1afde9[_0xeba0('0x37')]=_[_0xeba0('0x38')](_0x1afde9[_0xeba0('0x35')],_0x1afde9[_0xeba0('0x36')]);_0x544504['attributes']=_[_0xeba0('0x38')](_0x1afde9[_0xeba0('0x35')],qs[_0xeba0('0x3a')](_0x1fcba4['query'][_0xeba0('0x3a')]));_0x544504[_0xeba0('0x39')]=_0x544504[_0xeba0('0x39')][_0xeba0('0x3b')]?_0x544504[_0xeba0('0x39')]:_0x1afde9[_0xeba0('0x35')];if(_0x1fcba4['query'][_0xeba0('0x46')]){_0x544504[_0xeba0('0x47')]=[{'all':!![]}];}_0x544504=_[_0xeba0('0x43')]({},_0x544504,_0x1fcba4[_0xeba0('0x45')]);return db[_0xeba0('0x30')][_0xeba0('0x4d')](_0x544504)[_0xeba0('0x27')](handleEntityNotFound(_0x3da83e,null))[_0xeba0('0x27')](respondWithResult(_0x3da83e,null))[_0xeba0('0x49')](handleError(_0x3da83e,null));};exports[_0xeba0('0x4e')]=function(_0x128937,_0x6a1253){return db[_0xeba0('0x30')][_0xeba0('0x4e')](_0x128937[_0xeba0('0x4f')],{})[_0xeba0('0x27')](function(_0xf42a8f){var _0x5dbca7=_0x128937[_0xeba0('0x50')][_0xeba0('0x29')]({'plain':!![]});if(!_0x5dbca7)throw new Error(_0xeba0('0x51'));if(_0x5dbca7[_0xeba0('0x52')]===_0xeba0('0x50')){var _0x1f981d=_0xf42a8f[_0xeba0('0x29')]({'plain':!![]});var _0x4d8d64=_0xeba0('0x2a');return db[_0xeba0('0x53')][_0xeba0('0x4d')]({'where':{'name':_0x4d8d64,'userProfileId':_0x5dbca7[_0xeba0('0x54')]},'raw':!![]})[_0xeba0('0x27')](function(_0x41f0ad){if(_0x41f0ad&&_0x41f0ad[_0xeba0('0x55')]===0x0){return db[_0xeba0('0x2b')]['create']({'name':_0x1f981d[_0xeba0('0x2e')],'resourceId':_0x1f981d['id'],'type':_0x41f0ad[_0xeba0('0x2e')],'sectionId':_0x41f0ad['id']},{})[_0xeba0('0x27')](function(){return _0xf42a8f;});}else{return _0xf42a8f;}})['catch'](function(_0x53062e){logger[_0xeba0('0x2c')](_0xeba0('0x56'),_0x53062e);throw _0x53062e;});}return _0xf42a8f;})[_0xeba0('0x27')](respondWithResult(_0x6a1253,0xc9))['catch'](handleError(_0x6a1253,null));};exports[_0xeba0('0x26')]=function(_0x311ba1,_0x5a7b1a){if(_0x311ba1[_0xeba0('0x4f')]['id']){delete _0x311ba1[_0xeba0('0x4f')]['id'];}return db[_0xeba0('0x30')]['find']({'where':{'id':_0x311ba1['params']['id']}})[_0xeba0('0x27')](handleEntityNotFound(_0x5a7b1a,null))[_0xeba0('0x27')](saveUpdates(_0x311ba1[_0xeba0('0x4f')],null))[_0xeba0('0x27')](respondWithResult(_0x5a7b1a,null))['catch'](handleError(_0x5a7b1a,null));};exports[_0xeba0('0x28')]=function(_0xb9acdb,_0x14cd44){return db[_0xeba0('0x30')][_0xeba0('0x4d')]({'where':{'id':_0xb9acdb['params']['id']}})[_0xeba0('0x27')](handleEntityNotFound(_0x14cd44,null))[_0xeba0('0x27')](removeEntity(_0x14cd44,null))[_0xeba0('0x49')](handleError(_0x14cd44,null));};exports[_0xeba0('0x57')]=function(_0x34e1ff,_0x3bff86){return db['WhatsappQueue'][_0xeba0('0x57')]()[_0xeba0('0x27')](respondWithResult(_0x3bff86,null))[_0xeba0('0x49')](handleError(_0x3bff86,null));};exports[_0xeba0('0x58')]=function(_0x50b87e,_0x2f55b0,_0x1245c1){var _0x26cce7={'raw':!![],'where':{}},_0x223e90={},_0x29ab80;return db[_0xeba0('0x30')][_0xeba0('0x59')]({'where':{'id':_0x50b87e['params']['id']}})[_0xeba0('0x27')](handleEntityNotFound(_0x2f55b0,null))[_0xeba0('0x27')](function(_0x48962e){if(_0x48962e){_0x29ab80=_0x48962e[_0xeba0('0x29')]({'plain':!![]});_0x223e90[_0xeba0('0x35')]=_[_0xeba0('0x4c')](db[_0xeba0('0x5a')][_0xeba0('0x31')]);_0x223e90[_0xeba0('0x36')]=_[_0xeba0('0x4c')](_0x50b87e[_0xeba0('0x36')]);_0x223e90[_0xeba0('0x37')]=_[_0xeba0('0x38')](_0x223e90[_0xeba0('0x35')],_0x223e90['query']);_0x26cce7[_0xeba0('0x39')]=_[_0xeba0('0x38')](_0x223e90[_0xeba0('0x35')],qs[_0xeba0('0x3a')](_0x50b87e[_0xeba0('0x36')][_0xeba0('0x3a')]));_0x26cce7['attributes']=_0x26cce7[_0xeba0('0x39')]['length']?_0x26cce7['attributes']:_0x223e90[_0xeba0('0x35')];if(!_0x50b87e[_0xeba0('0x36')]['hasOwnProperty'](_0xeba0('0x3d'))){_0x26cce7['limit']=qs[_0xeba0('0x20')](_0x50b87e[_0xeba0('0x36')][_0xeba0('0x20')]);_0x26cce7[_0xeba0('0x1f')]=qs[_0xeba0('0x1f')](_0x50b87e['query'][_0xeba0('0x1f')]);}_0x26cce7['order']=qs[_0xeba0('0x3f')](_0x50b87e[_0xeba0('0x36')]['sort']);_0x26cce7['where']=qs[_0xeba0('0x37')](_[_0xeba0('0x41')](_0x50b87e[_0xeba0('0x36')],_0x223e90['filters']));_0x26cce7[_0xeba0('0x40')][_0xeba0('0x5b')]=_0x48962e['id'];if(_0x50b87e['query'][_0xeba0('0x42')]){_0x26cce7[_0xeba0('0x40')]=_[_0xeba0('0x43')](_0x26cce7[_0xeba0('0x40')],{'$or':_[_0xeba0('0x5c')](_0x26cce7[_0xeba0('0x39')],function(_0x40aa18){var _0x46ddcb={};_0x46ddcb[_0x40aa18]={'$like':'%'+_0x50b87e[_0xeba0('0x36')][_0xeba0('0x42')]+'%'};return _0x46ddcb;})});}_0x26cce7=_['merge']({},_0x26cce7,_0x50b87e[_0xeba0('0x45')]);return db[_0xeba0('0x5a')][_0xeba0('0x5d')](_0x26cce7);}})[_0xeba0('0x27')](function(_0x1e224c){if(_0x1e224c){return db[_0xeba0('0x5e')][_0xeba0('0x5f')]({'where':{'id':_[_0xeba0('0x5c')](_0x1e224c,'UserId'),'role':'agent'},'attributes':['id',_0xeba0('0x2e'),'whatsappPause',_0xeba0('0x60'),_0xeba0('0x61')]});}})[_0xeba0('0x27')](function(_0x28010d){if(_0x28010d){return{'count':_0x28010d[_0xeba0('0x1e')],'rows':_[_0xeba0('0x5c')](_0x28010d[_0xeba0('0x48')],function(_0x570803){return{'membername':_0x570803[_0xeba0('0x2e')],'UserId':_0x570803['id'],'queue_name':_0x29ab80[_0xeba0('0x2e')],'WhatsappQueueId':_0x29ab80['id'],'interface':util['format'](_0xeba0('0x62'),_0xeba0('0x63'),_0x570803[_0xeba0('0x2e')]),'penalty':0x0,'paused':_0x570803[_0xeba0('0x64')],'createdAt':_0x570803[_0xeba0('0x61')],'updatedAt':_0x570803['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0xeba0('0x27')](respondWithFilteredResult(_0x2f55b0,_0x26cce7))['catch'](handleError(_0x2f55b0,null));};exports[_0xeba0('0x65')]=function(_0x4f817b,_0x366360,_0x260156){var _0x3d7fec={};var _0x297a6c={};var _0x17893f;var _0x5e78c3;return db[_0xeba0('0x30')][_0xeba0('0x59')]({'where':{'id':_0x4f817b['params']['id']}})[_0xeba0('0x27')](handleEntityNotFound(_0x366360,null))[_0xeba0('0x27')](function(_0x4dd16f){if(_0x4dd16f){_0x17893f=_0x4dd16f;_0x297a6c[_0xeba0('0x35')]=_[_0xeba0('0x4c')](db[_0xeba0('0x66')][_0xeba0('0x31')]);_0x297a6c['query']=_[_0xeba0('0x4c')](_0x4f817b[_0xeba0('0x36')]);_0x297a6c[_0xeba0('0x37')]=_[_0xeba0('0x38')](_0x297a6c[_0xeba0('0x35')],_0x297a6c[_0xeba0('0x36')]);_0x3d7fec['attributes']=_[_0xeba0('0x38')](_0x297a6c[_0xeba0('0x35')],qs[_0xeba0('0x3a')](_0x4f817b[_0xeba0('0x36')]['fields']));_0x3d7fec[_0xeba0('0x39')]=_0x3d7fec[_0xeba0('0x39')]['length']?_0x3d7fec[_0xeba0('0x39')]:_0x297a6c[_0xeba0('0x35')];_0x3d7fec[_0xeba0('0x3e')]=qs['sort'](_0x4f817b[_0xeba0('0x36')][_0xeba0('0x3f')]);_0x3d7fec[_0xeba0('0x40')]=qs['filters'](_['pick'](_0x4f817b['query'],_0x297a6c[_0xeba0('0x37')]));if(_0x4f817b[_0xeba0('0x36')][_0xeba0('0x42')]){_0x3d7fec[_0xeba0('0x40')]=_[_0xeba0('0x43')](_0x3d7fec['where'],{'$or':_[_0xeba0('0x5c')](_0x3d7fec[_0xeba0('0x39')],function(_0x353682){var _0xf4975d={};_0xf4975d[_0x353682]={'$like':'%'+_0x4f817b[_0xeba0('0x36')]['filter']+'%'};return _0xf4975d;})});}_0x3d7fec=_[_0xeba0('0x43')]({},_0x3d7fec,_0x4f817b[_0xeba0('0x45')]);return _0x17893f['getTeams'](_0x3d7fec);}})[_0xeba0('0x27')](function(_0x3e58ad){if(_0x3e58ad){_0x5e78c3=_0x3e58ad[_0xeba0('0x3b')];if(!_0x4f817b[_0xeba0('0x36')]['hasOwnProperty'](_0xeba0('0x3d'))){_0x3d7fec[_0xeba0('0x20')]=qs[_0xeba0('0x20')](_0x4f817b[_0xeba0('0x36')][_0xeba0('0x20')]);_0x3d7fec['offset']=qs[_0xeba0('0x1f')](_0x4f817b[_0xeba0('0x36')]['offset']);}return _0x17893f[_0xeba0('0x65')](_0x3d7fec);}})[_0xeba0('0x27')](function(_0x310450){if(_0x310450){return _0x310450?{'count':_0x5e78c3,'rows':_0x310450}:null;}})['then'](respondWithResult(_0x366360,null))[_0xeba0('0x49')](handleError(_0x366360,null));};exports['addTeams']=function(_0x33d8ea,_0x1dd61e,_0x3b7338){var _0x750a63=_0x33d8ea[_0xeba0('0x4f')][_0xeba0('0x67')];return db['Team'][_0xeba0('0x5d')]({'where':{'id':_0x750a63},'attributes':['id'],'include':[{'model':db[_0xeba0('0x5e')],'as':'Agents','attributes':['id',_0xeba0('0x2e'),'online',_0xeba0('0x68'),_0xeba0('0x69')],'raw':!![]}]})[_0xeba0('0x27')](function(_0x63c892){if(_0x63c892){var _0x2e8ef2=_[_0xeba0('0x6a')](_0x63c892,function(_0xca04b3){var _0x35b7d8=_0xca04b3[_0xeba0('0x29')]({'plain':!![]});return _0x35b7d8[_0xeba0('0x6b')];});return db['WhatsappQueue'][_0xeba0('0x4d')]({'where':{'id':_0x33d8ea['params']['id']}})['then'](function(_0x908f43){return db['sequelize'][_0xeba0('0x6c')](function(_0x393a00){return _0x908f43['addTeams'](_0x750a63,{'transaction':_0x393a00})[_0xeba0('0x27')](function(){return BPromise['each'](_0x2e8ef2,function(_0x100baf){return db['UserWhatsappQueue']['findOrCreate']({'where':{'UserId':_0x100baf['id'],'WhatsappQueueId':_0x33d8ea[_0xeba0('0x4b')]['id']},'transaction':_0x393a00});});})[_0xeba0('0x27')](function(){_0x2e8ef2['forEach'](function(_0x2ee0c3){socket[_0xeba0('0x6d')]('userWhatsappQueue:save',{'UserId':_0x2ee0c3['id'],'WhatsappQueueId':_0x908f43['id']});});});});});}})['then'](respondWithStatusCode(_0x1dd61e,null))[_0xeba0('0x49')](handleError(_0x1dd61e,null));};exports[_0xeba0('0x6e')]=function(_0x3636b9,_0x2a1b87,_0x3665cf){return db['Team'][_0xeba0('0x5d')]({'where':{'id':_0x3636b9['query'][_0xeba0('0x67')]},'attributes':['id'],'include':[{'model':db[_0xeba0('0x5e')],'as':_0xeba0('0x6b'),'attributes':['id'],'raw':!![]}]})[_0xeba0('0x27')](handleEntityNotFound(_0x2a1b87,null))[_0xeba0('0x27')](function(_0x56b8ea){var _0x2acf12=_[_0xeba0('0x5c')](_0x56b8ea,'id');var _0xb1129a=[];var _0x25175e=[];var _0x4e9fed=squel[_0xeba0('0x6f')]();_0x4e9fed[_0xeba0('0x70')](_0xeba0('0x71'))[_0xeba0('0x72')](_0xeba0('0x73'),'tq')['join']('user_has_teams','ut',_0xeba0('0x74'))[_0xeba0('0x40')](_0xeba0('0x75'),_0x3636b9[_0xeba0('0x4b')]['id']);for(var _0x56ecf2=0x0;_0x56ecf2<_0x56b8ea[_0xeba0('0x3b')];_0x56ecf2+=0x1){let _0x1c74b1=_0x56b8ea[_0x56ecf2];for(var _0x2a8e2e=0x0;_0x2a8e2e<_0x1c74b1[_0xeba0('0x6b')][_0xeba0('0x3b')];_0x2a8e2e+=0x1){let _0x159fce=_0x1c74b1[_0xeba0('0x6b')][_0x2a8e2e];var _0x163a95=_0x4e9fed['clone']();_0x163a95[_0xeba0('0x40')]('ut.UserId\x20=\x20?',_0x159fce['id']);_0x25175e[_0xeba0('0x76')](db['sequelize'][_0xeba0('0x36')](_0x163a95[_0xeba0('0x77')](),{'type':db['sequelize']['QueryTypes'][_0xeba0('0x78')]})['then'](function(_0x49efd6){if(_0x49efd6['length']===0x1){return _0x159fce['id'];}else{var _0xf01df0=_['every'](_['map'](_0x49efd6,'TeamId'),function(_0x235f67){return _[_0xeba0('0x79')](_0x2acf12,_0x235f67);});if(_0xf01df0){return _0x159fce['id'];}}}));}}return BPromise[_0xeba0('0x7a')](_0x25175e)[_0xeba0('0x27')](function(_0x3efbb2){_0xb1129a=_(_0xb1129a)[_0xeba0('0x7b')](_0x3efbb2)[_0xeba0('0x7c')]()['value']();return db[_0xeba0('0x30')][_0xeba0('0x4d')]({'where':{'id':_0x3636b9[_0xeba0('0x4b')]['id']}})[_0xeba0('0x27')](function(_0x53ce02){return db['sequelize']['transaction'](function(_0x4e6be7){return _0x53ce02['removeTeams'](_0x3636b9[_0xeba0('0x36')]['ids'],{'transaction':_0x4e6be7})[_0xeba0('0x27')](function(){if(!_[_0xeba0('0x7d')](_0xb1129a)){return _0x53ce02[_0xeba0('0x7e')](_0xb1129a,{'transaction':_0x4e6be7});}})[_0xeba0('0x27')](function(){_0xb1129a[_0xeba0('0x7f')](function(_0x476674){socket[_0xeba0('0x6d')](_0xeba0('0x80'),{'UserId':_0x476674,'WhatsappQueueId':_0x53ce02['id']});});});});});});})['then'](respondWithStatusCode(_0x2a1b87,null))[_0xeba0('0x49')](handleError(_0x2a1b87,null));};exports['addAgents']=function(_0x152e0e,_0x5eb8b4,_0x4fe5e0){return db['WhatsappQueue'][_0xeba0('0x4d')]({'where':{'id':_0x152e0e[_0xeba0('0x4b')]['id']}})[_0xeba0('0x27')](handleEntityNotFound(_0x5eb8b4,null))[_0xeba0('0x27')](function(_0x10e2e3){if(_0x10e2e3){return _0x10e2e3[_0xeba0('0x81')](_0x152e0e[_0xeba0('0x4f')]['ids'],_['omit'](_0x152e0e[_0xeba0('0x4f')],['ids','id'])||{})[_0xeba0('0x82')](function(_0x358b65){for(var _0x1ce689=0x0;_0x1ce689<_0x152e0e[_0xeba0('0x4f')][_0xeba0('0x67')][_0xeba0('0x3b')];_0x1ce689+=0x1){socket[_0xeba0('0x6d')]('userWhatsappQueue:save',{'UserId':Number(_0x152e0e['body']['ids'][_0x1ce689]),'WhatsappQueueId':Number(_0x152e0e['params']['id'])});}return _0x358b65;});}})[_0xeba0('0x27')](respondWithResult(_0x5eb8b4,null))[_0xeba0('0x49')](handleError(_0x5eb8b4,null));};exports[_0xeba0('0x7e')]=function(_0x372577,_0x320918,_0x3dc4e6){return db['WhatsappQueue'][_0xeba0('0x4d')]({'where':{'id':_0x372577[_0xeba0('0x4b')]['id']}})[_0xeba0('0x27')](handleEntityNotFound(_0x320918,null))['then'](function(_0x43ad65){if(_0x43ad65){return _0x43ad65['removeAgents'](_0x372577[_0xeba0('0x36')]['ids'])['then'](function(){if(_[_0xeba0('0x83')](_0x372577[_0xeba0('0x36')][_0xeba0('0x67')])){for(var _0x4f16a1=0x0;_0x4f16a1<_0x372577[_0xeba0('0x36')]['ids'][_0xeba0('0x3b')];_0x4f16a1+=0x1){socket[_0xeba0('0x6d')](_0xeba0('0x80'),{'UserId':Number(_0x372577['query'][_0xeba0('0x67')][_0x4f16a1]),'WhatsappQueueId':Number(_0x372577[_0xeba0('0x4b')]['id'])});}}else{socket['emit'](_0xeba0('0x80'),{'UserId':Number(_0x372577[_0xeba0('0x36')][_0xeba0('0x67')]),'WhatsappQueueId':Number(_0x372577[_0xeba0('0x4b')]['id'])});}});}})[_0xeba0('0x27')](respondWithStatusCode(_0x320918,null))[_0xeba0('0x49')](handleError(_0x320918,null));};exports[_0xeba0('0x84')]=function(_0x4dcec7,_0x15652e,_0x4a6c7f){var _0x449246={};var _0x2e8625={};var _0x32f32b;var _0x68f7b3;return db[_0xeba0('0x30')][_0xeba0('0x59')]({'where':{'id':_0x4dcec7['params']['id']}})[_0xeba0('0x27')](handleEntityNotFound(_0x15652e,null))[_0xeba0('0x27')](function(_0x34aa0d){if(_0x34aa0d){_0x32f32b=_0x34aa0d;_0x2e8625[_0xeba0('0x35')]=_['keys'](db[_0xeba0('0x5e')][_0xeba0('0x31')]);_0x2e8625['query']=_['keys'](_0x4dcec7[_0xeba0('0x36')]);_0x2e8625[_0xeba0('0x37')]=_[_0xeba0('0x38')](_0x2e8625[_0xeba0('0x35')],_0x2e8625[_0xeba0('0x36')]);_0x449246['attributes']=_['intersection'](_0x2e8625['model'],qs[_0xeba0('0x3a')](_0x4dcec7[_0xeba0('0x36')]['fields']));_0x449246[_0xeba0('0x39')]=_0x449246[_0xeba0('0x39')][_0xeba0('0x3b')]?_0x449246[_0xeba0('0x39')]:_0x2e8625[_0xeba0('0x35')];_0x449246[_0xeba0('0x3e')]=qs[_0xeba0('0x3f')](_0x4dcec7[_0xeba0('0x36')][_0xeba0('0x3f')]);_0x449246[_0xeba0('0x40')]=qs[_0xeba0('0x37')](_[_0xeba0('0x41')](_0x4dcec7['query'],_0x2e8625['filters']));if(_0x4dcec7[_0xeba0('0x36')][_0xeba0('0x42')]){_0x449246[_0xeba0('0x40')]=_['merge'](_0x449246['where'],{'$or':_[_0xeba0('0x5c')](_0x449246['attributes'],function(_0x1583bb){var _0x141b36={};_0x141b36[_0x1583bb]={'$like':'%'+_0x4dcec7[_0xeba0('0x36')][_0xeba0('0x42')]+'%'};return _0x141b36;})});}_0x449246=_[_0xeba0('0x43')]({},_0x449246,_0x4dcec7[_0xeba0('0x45')]);return _0x32f32b['getAgents'](_0x449246);}})[_0xeba0('0x27')](function(_0x226257){if(_0x226257){_0x68f7b3=_0x226257['length'];if(!_0x4dcec7[_0xeba0('0x36')][_0xeba0('0x3c')](_0xeba0('0x3d'))){_0x449246[_0xeba0('0x20')]=qs['limit'](_0x4dcec7[_0xeba0('0x36')][_0xeba0('0x20')]);_0x449246[_0xeba0('0x1f')]=qs['offset'](_0x4dcec7[_0xeba0('0x36')][_0xeba0('0x1f')]);}return _0x32f32b[_0xeba0('0x84')](_0x449246);}})[_0xeba0('0x27')](function(_0xb11ee7){if(_0xb11ee7){return _0xb11ee7?{'count':_0x68f7b3,'rows':_0xb11ee7}:null;}})['then'](respondWithResult(_0x15652e,null))['catch'](handleError(_0x15652e,null));};
\ No newline at end of file
+var _0xc765=['Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','getMembers','findOne','hasOwnProperty','order','WhatsappQueueId','UserWhatsappQueue','User','findAndCountAll','UserId','agent','whatsappPause','updatedAt','%s/%s','SIP','createdAt','getTeams','Team','nolimit','addTeams','ids','online','voicePause','interface','flatMap','Agents','transaction','each','findOrCreate','emit','removeTeams','select','tq.TeamId','from','team_has_whatsapp_queues','join','user_has_teams','WhatsappQueueId\x20=\x20?','ut.UserId\x20=\x20?','sequelize','toString','QueryTypes','SELECT','all','union','compact','value','removeAgents','addAgents','spread','userWhatsappQueue:save','isArray','userWhatsappQueue:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','fs-extra','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','./whatsappQueue.socket','register','sendStatus','status','end','offset','undefined','count','limit','set','save','update','then','destroy','get','WhatsappQueues','UserProfileResource','error','stack','name','index','map','WhatsappQueue','rawAttributes','type','key','model','query','keys','filters','intersection','fields','attributes','length','sort','where','pick','filter','merge','options','includeAll','findAll','rows','catch','show','include','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','find','userProfileId','autoAssociation'];(function(_0x330c91,_0xefc1d6){var _0x4e2f78=function(_0x387744){while(--_0x387744){_0x330c91['push'](_0x330c91['shift']());}};_0x4e2f78(++_0xefc1d6);}(_0xc765,0x14c));var _0x5c76=function(_0x32d28c,_0x586074){_0x32d28c=_0x32d28c-0x0;var _0x2eeda0=_0xc765[_0x32d28c];return _0x2eeda0;};'use strict';var emlformat=require(_0x5c76('0x0'));var rimraf=require(_0x5c76('0x1'));var zipdir=require(_0x5c76('0x2'));var jsonpatch=require(_0x5c76('0x3'));var rp=require(_0x5c76('0x4'));var moment=require(_0x5c76('0x5'));var BPromise=require(_0x5c76('0x6'));var Mustache=require(_0x5c76('0x7'));var util=require(_0x5c76('0x8'));var path=require('path');var sox=require(_0x5c76('0x9'));var csv=require(_0x5c76('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x5c76('0xb'));var _=require('lodash');var squel=require(_0x5c76('0xc'));var crypto=require(_0x5c76('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x5c76('0xe'));var toCsv=require(_0x5c76('0xa'));var querystring=require(_0x5c76('0xf'));var Papa=require('papaparse');var Redis=require(_0x5c76('0x10'));var authService=require(_0x5c76('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x5c76('0x12'));var hardwareService=require(_0x5c76('0x13'));var logger=require(_0x5c76('0x14'))('api');var utils=require(_0x5c76('0x15'));var config=require(_0x5c76('0x16'));var licenseUtil=require(_0x5c76('0x17'));var db=require('../../mysqldb')['db'];config[_0x5c76('0x18')]=_[_0x5c76('0x19')](config[_0x5c76('0x18')],{'host':_0x5c76('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x5c76('0x18')]));require(_0x5c76('0x1b'))[_0x5c76('0x1c')](socket);function respondWithStatusCode(_0x2cf832,_0x5ed697){_0x5ed697=_0x5ed697||0xcc;return function(_0x47bdba){if(_0x47bdba){return _0x2cf832[_0x5c76('0x1d')](_0x5ed697);}return _0x2cf832[_0x5c76('0x1e')](_0x5ed697)[_0x5c76('0x1f')]();};}function respondWithResult(_0x1b1c64,_0x28a9ef){_0x28a9ef=_0x28a9ef||0xc8;return function(_0x30bc42){if(_0x30bc42){return _0x1b1c64['status'](_0x28a9ef)['json'](_0x30bc42);}};}function respondWithFilteredResult(_0x421952,_0x2f2743){return function(_0x1a36b8){if(_0x1a36b8){var _0x3511ed=typeof _0x2f2743[_0x5c76('0x20')]===_0x5c76('0x21')&&typeof _0x2f2743['limit']===_0x5c76('0x21');var _0x45495c=_0x1a36b8[_0x5c76('0x22')];var _0x5ecb54=_0x3511ed?0x0:_0x2f2743[_0x5c76('0x20')];var _0x5da44f=_0x3511ed?_0x1a36b8[_0x5c76('0x22')]:_0x2f2743[_0x5c76('0x20')]+_0x2f2743[_0x5c76('0x23')];var _0x275a6c;if(_0x5da44f>=_0x45495c){_0x5da44f=_0x45495c;_0x275a6c=0xc8;}else{_0x275a6c=0xce;}_0x421952[_0x5c76('0x1e')](_0x275a6c);return _0x421952[_0x5c76('0x24')]('Content-Range',_0x5ecb54+'-'+_0x5da44f+'/'+_0x45495c)['json'](_0x1a36b8);}return null;};}function patchUpdates(_0x288b13){return function(_0x25ff1f){try{jsonpatch['apply'](_0x25ff1f,_0x288b13,!![]);}catch(_0x53b296){return BPromise['reject'](_0x53b296);}return _0x25ff1f[_0x5c76('0x25')]();};}function saveUpdates(_0x17998c,_0x368f0a){return function(_0x5256b6){if(_0x5256b6){return _0x5256b6[_0x5c76('0x26')](_0x17998c)[_0x5c76('0x27')](function(_0x906c45){return _0x906c45;});}return null;};}function removeEntity(_0x20db28,_0x41e7ab){return function(_0x3ef6ae){if(_0x3ef6ae){return _0x3ef6ae[_0x5c76('0x28')]()['then'](function(){var _0x531fcc=_0x3ef6ae[_0x5c76('0x29')]({'plain':!![]});var _0x4b99e1=_0x5c76('0x2a');return db[_0x5c76('0x2b')]['destroy']({'where':{'type':_0x4b99e1,'resourceId':_0x531fcc['id']}})['then'](function(){return _0x3ef6ae;});})['then'](function(){_0x20db28[_0x5c76('0x1e')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3f6c4b,_0x4a2626){return function(_0x223fe3){if(!_0x223fe3){_0x3f6c4b[_0x5c76('0x1d')](0x194);}return _0x223fe3;};}function handleError(_0x4b333c,_0x46d7f3){_0x46d7f3=_0x46d7f3||0x1f4;return function(_0x4e13b9){logger[_0x5c76('0x2c')](_0x4e13b9[_0x5c76('0x2d')]);if(_0x4e13b9['name']){delete _0x4e13b9[_0x5c76('0x2e')];}_0x4b333c[_0x5c76('0x1e')](_0x46d7f3)['send'](_0x4e13b9);};}exports[_0x5c76('0x2f')]=function(_0x1fbbf9,_0x3abe53){var _0x731ed4={},_0x4a15bd={},_0x5e74e0={'count':0x0,'rows':[]};var _0x28ccad=_[_0x5c76('0x30')](db[_0x5c76('0x31')][_0x5c76('0x32')],function(_0x3a2dca){return{'name':_0x3a2dca['fieldName'],'type':_0x3a2dca[_0x5c76('0x33')][_0x5c76('0x34')]};});_0x4a15bd[_0x5c76('0x35')]=_[_0x5c76('0x30')](_0x28ccad,_0x5c76('0x2e'));_0x4a15bd[_0x5c76('0x36')]=_[_0x5c76('0x37')](_0x1fbbf9['query']);_0x4a15bd[_0x5c76('0x38')]=_[_0x5c76('0x39')](_0x4a15bd[_0x5c76('0x35')],_0x4a15bd['query']);_0x731ed4['attributes']=_[_0x5c76('0x39')](_0x4a15bd[_0x5c76('0x35')],qs[_0x5c76('0x3a')](_0x1fbbf9[_0x5c76('0x36')][_0x5c76('0x3a')]));_0x731ed4[_0x5c76('0x3b')]=_0x731ed4[_0x5c76('0x3b')][_0x5c76('0x3c')]?_0x731ed4[_0x5c76('0x3b')]:_0x4a15bd[_0x5c76('0x35')];if(!_0x1fbbf9[_0x5c76('0x36')]['hasOwnProperty']('nolimit')){_0x731ed4['limit']=qs[_0x5c76('0x23')](_0x1fbbf9[_0x5c76('0x36')][_0x5c76('0x23')]);_0x731ed4[_0x5c76('0x20')]=qs[_0x5c76('0x20')](_0x1fbbf9[_0x5c76('0x36')][_0x5c76('0x20')]);}_0x731ed4['order']=qs['sort'](_0x1fbbf9[_0x5c76('0x36')][_0x5c76('0x3d')]);_0x731ed4[_0x5c76('0x3e')]=qs[_0x5c76('0x38')](_[_0x5c76('0x3f')](_0x1fbbf9[_0x5c76('0x36')],_0x4a15bd[_0x5c76('0x38')]),_0x28ccad);if(_0x1fbbf9[_0x5c76('0x36')][_0x5c76('0x40')]){_0x731ed4[_0x5c76('0x3e')]=_[_0x5c76('0x41')](_0x731ed4[_0x5c76('0x3e')],{'$or':_[_0x5c76('0x30')](_0x28ccad,function(_0x3aac18){if(_0x3aac18[_0x5c76('0x33')]!=='VIRTUAL'){var _0x762893={};_0x762893[_0x3aac18['name']]={'$like':'%'+_0x1fbbf9[_0x5c76('0x36')][_0x5c76('0x40')]+'%'};return _0x762893;}})});}_0x731ed4=_[_0x5c76('0x41')]({},_0x731ed4,_0x1fbbf9[_0x5c76('0x42')]);var _0x1d9e1b={'where':_0x731ed4[_0x5c76('0x3e')]};return db[_0x5c76('0x31')][_0x5c76('0x22')](_0x1d9e1b)['then'](function(_0x385aaf){_0x5e74e0[_0x5c76('0x22')]=_0x385aaf;if(_0x1fbbf9['query'][_0x5c76('0x43')]){_0x731ed4['include']=[{'all':!![]}];}return db[_0x5c76('0x31')][_0x5c76('0x44')](_0x731ed4);})[_0x5c76('0x27')](function(_0x5af410){_0x5e74e0[_0x5c76('0x45')]=_0x5af410;return _0x5e74e0;})[_0x5c76('0x27')](respondWithFilteredResult(_0x3abe53,_0x731ed4))[_0x5c76('0x46')](handleError(_0x3abe53,null));};exports[_0x5c76('0x47')]=function(_0x29a995,_0x5f37ac){var _0x245333={'raw':!![],'where':{'id':_0x29a995['params']['id']}},_0x5afb90={};_0x5afb90[_0x5c76('0x35')]=_[_0x5c76('0x37')](db[_0x5c76('0x31')][_0x5c76('0x32')]);_0x5afb90['query']=_[_0x5c76('0x37')](_0x29a995[_0x5c76('0x36')]);_0x5afb90[_0x5c76('0x38')]=_['intersection'](_0x5afb90[_0x5c76('0x35')],_0x5afb90[_0x5c76('0x36')]);_0x245333[_0x5c76('0x3b')]=_['intersection'](_0x5afb90[_0x5c76('0x35')],qs[_0x5c76('0x3a')](_0x29a995['query'][_0x5c76('0x3a')]));_0x245333['attributes']=_0x245333[_0x5c76('0x3b')][_0x5c76('0x3c')]?_0x245333[_0x5c76('0x3b')]:_0x5afb90['model'];if(_0x29a995['query'][_0x5c76('0x43')]){_0x245333[_0x5c76('0x48')]=[{'all':!![]}];}_0x245333=_[_0x5c76('0x41')]({},_0x245333,_0x29a995[_0x5c76('0x42')]);return db[_0x5c76('0x31')]['find'](_0x245333)[_0x5c76('0x27')](handleEntityNotFound(_0x5f37ac,null))[_0x5c76('0x27')](respondWithResult(_0x5f37ac,null))[_0x5c76('0x46')](handleError(_0x5f37ac,null));};exports[_0x5c76('0x49')]=function(_0x302762,_0x23ccaf){return db[_0x5c76('0x31')][_0x5c76('0x49')](_0x302762[_0x5c76('0x4a')],{})['then'](function(_0x2d85cd){var _0xbab8bc=_0x302762['user'][_0x5c76('0x29')]({'plain':!![]});if(!_0xbab8bc)throw new Error(_0x5c76('0x4b'));if(_0xbab8bc[_0x5c76('0x4c')]===_0x5c76('0x4d')){var _0x4e4816=_0x2d85cd[_0x5c76('0x29')]({'plain':!![]});var _0x40c491=_0x5c76('0x2a');return db[_0x5c76('0x4e')][_0x5c76('0x4f')]({'where':{'name':_0x40c491,'userProfileId':_0xbab8bc[_0x5c76('0x50')]},'raw':!![]})[_0x5c76('0x27')](function(_0xbcde40){if(_0xbcde40&&_0xbcde40[_0x5c76('0x51')]===0x0){return db[_0x5c76('0x2b')][_0x5c76('0x49')]({'name':_0x4e4816['name'],'resourceId':_0x4e4816['id'],'type':_0xbcde40[_0x5c76('0x2e')],'sectionId':_0xbcde40['id']},{})[_0x5c76('0x27')](function(){return _0x2d85cd;});}else{return _0x2d85cd;}})[_0x5c76('0x46')](function(_0x2e7f5a){logger[_0x5c76('0x2c')](_0x5c76('0x52'),_0x2e7f5a);throw _0x2e7f5a;});}return _0x2d85cd;})['then'](respondWithResult(_0x23ccaf,0xc9))[_0x5c76('0x46')](handleError(_0x23ccaf,null));};exports[_0x5c76('0x26')]=function(_0x493da7,_0x54e716){if(_0x493da7[_0x5c76('0x4a')]['id']){delete _0x493da7[_0x5c76('0x4a')]['id'];}return db['WhatsappQueue']['find']({'where':{'id':_0x493da7[_0x5c76('0x53')]['id']}})[_0x5c76('0x27')](handleEntityNotFound(_0x54e716,null))[_0x5c76('0x27')](saveUpdates(_0x493da7[_0x5c76('0x4a')],null))[_0x5c76('0x27')](respondWithResult(_0x54e716,null))[_0x5c76('0x46')](handleError(_0x54e716,null));};exports[_0x5c76('0x28')]=function(_0x1fdea6,_0x42d4eb){return db[_0x5c76('0x31')]['find']({'where':{'id':_0x1fdea6[_0x5c76('0x53')]['id']}})[_0x5c76('0x27')](handleEntityNotFound(_0x42d4eb,null))[_0x5c76('0x27')](removeEntity(_0x42d4eb,null))[_0x5c76('0x46')](handleError(_0x42d4eb,null));};exports[_0x5c76('0x54')]=function(_0x2d0816,_0x28cb1e){return db[_0x5c76('0x31')][_0x5c76('0x54')]()['then'](respondWithResult(_0x28cb1e,null))[_0x5c76('0x46')](handleError(_0x28cb1e,null));};exports[_0x5c76('0x55')]=function(_0x44e299,_0x255d4b,_0x5ce89d){var _0xcb5ef1={'raw':!![],'where':{}},_0x4aceb6={},_0x2f6753;return db[_0x5c76('0x31')][_0x5c76('0x56')]({'where':{'id':_0x44e299['params']['id']}})['then'](handleEntityNotFound(_0x255d4b,null))[_0x5c76('0x27')](function(_0x454735){if(_0x454735){_0x2f6753=_0x454735[_0x5c76('0x29')]({'plain':!![]});_0x4aceb6[_0x5c76('0x35')]=_[_0x5c76('0x37')](db['UserWhatsappQueue'][_0x5c76('0x32')]);_0x4aceb6[_0x5c76('0x36')]=_[_0x5c76('0x37')](_0x44e299['query']);_0x4aceb6[_0x5c76('0x38')]=_[_0x5c76('0x39')](_0x4aceb6[_0x5c76('0x35')],_0x4aceb6[_0x5c76('0x36')]);_0xcb5ef1[_0x5c76('0x3b')]=_[_0x5c76('0x39')](_0x4aceb6['model'],qs['fields'](_0x44e299[_0x5c76('0x36')]['fields']));_0xcb5ef1[_0x5c76('0x3b')]=_0xcb5ef1[_0x5c76('0x3b')][_0x5c76('0x3c')]?_0xcb5ef1[_0x5c76('0x3b')]:_0x4aceb6[_0x5c76('0x35')];if(!_0x44e299[_0x5c76('0x36')][_0x5c76('0x57')]('nolimit')){_0xcb5ef1[_0x5c76('0x23')]=qs[_0x5c76('0x23')](_0x44e299[_0x5c76('0x36')][_0x5c76('0x23')]);_0xcb5ef1[_0x5c76('0x20')]=qs[_0x5c76('0x20')](_0x44e299[_0x5c76('0x36')][_0x5c76('0x20')]);}_0xcb5ef1[_0x5c76('0x58')]=qs[_0x5c76('0x3d')](_0x44e299[_0x5c76('0x36')]['sort']);_0xcb5ef1[_0x5c76('0x3e')]=qs[_0x5c76('0x38')](_[_0x5c76('0x3f')](_0x44e299[_0x5c76('0x36')],_0x4aceb6['filters']));_0xcb5ef1[_0x5c76('0x3e')][_0x5c76('0x59')]=_0x454735['id'];if(_0x44e299[_0x5c76('0x36')][_0x5c76('0x40')]){_0xcb5ef1[_0x5c76('0x3e')]=_[_0x5c76('0x41')](_0xcb5ef1[_0x5c76('0x3e')],{'$or':_[_0x5c76('0x30')](_0xcb5ef1[_0x5c76('0x3b')],function(_0x14e4fa){var _0x150804={};_0x150804[_0x14e4fa]={'$like':'%'+_0x44e299[_0x5c76('0x36')]['filter']+'%'};return _0x150804;})});}_0xcb5ef1=_[_0x5c76('0x41')]({},_0xcb5ef1,_0x44e299['options']);return db[_0x5c76('0x5a')][_0x5c76('0x44')](_0xcb5ef1);}})[_0x5c76('0x27')](function(_0x252f43){if(_0x252f43){return db[_0x5c76('0x5b')][_0x5c76('0x5c')]({'where':{'id':_['map'](_0x252f43,_0x5c76('0x5d')),'role':_0x5c76('0x5e')},'attributes':['id',_0x5c76('0x2e'),_0x5c76('0x5f'),_0x5c76('0x60'),'createdAt']});}})[_0x5c76('0x27')](function(_0xcb4606){if(_0xcb4606){return{'count':_0xcb4606[_0x5c76('0x22')],'rows':_[_0x5c76('0x30')](_0xcb4606[_0x5c76('0x45')],function(_0x3d9c48){return{'membername':_0x3d9c48[_0x5c76('0x2e')],'UserId':_0x3d9c48['id'],'queue_name':_0x2f6753[_0x5c76('0x2e')],'WhatsappQueueId':_0x2f6753['id'],'interface':util['format'](_0x5c76('0x61'),_0x5c76('0x62'),_0x3d9c48[_0x5c76('0x2e')]),'penalty':0x0,'paused':_0x3d9c48['whatsappPause'],'createdAt':_0x3d9c48[_0x5c76('0x63')],'updatedAt':_0x3d9c48[_0x5c76('0x60')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x5c76('0x27')](respondWithFilteredResult(_0x255d4b,_0xcb5ef1))[_0x5c76('0x46')](handleError(_0x255d4b,null));};exports[_0x5c76('0x64')]=function(_0x4d210b,_0x589f8a,_0x241816){var _0x56829e={};var _0xf931d3={};var _0x3e0efa;var _0x4fe961;return db['WhatsappQueue'][_0x5c76('0x56')]({'where':{'id':_0x4d210b['params']['id']}})[_0x5c76('0x27')](handleEntityNotFound(_0x589f8a,null))[_0x5c76('0x27')](function(_0x705f25){if(_0x705f25){_0x3e0efa=_0x705f25;_0xf931d3['model']=_[_0x5c76('0x37')](db[_0x5c76('0x65')]['rawAttributes']);_0xf931d3['query']=_[_0x5c76('0x37')](_0x4d210b['query']);_0xf931d3[_0x5c76('0x38')]=_[_0x5c76('0x39')](_0xf931d3[_0x5c76('0x35')],_0xf931d3[_0x5c76('0x36')]);_0x56829e[_0x5c76('0x3b')]=_[_0x5c76('0x39')](_0xf931d3[_0x5c76('0x35')],qs[_0x5c76('0x3a')](_0x4d210b[_0x5c76('0x36')][_0x5c76('0x3a')]));_0x56829e['attributes']=_0x56829e[_0x5c76('0x3b')][_0x5c76('0x3c')]?_0x56829e[_0x5c76('0x3b')]:_0xf931d3[_0x5c76('0x35')];_0x56829e['order']=qs[_0x5c76('0x3d')](_0x4d210b[_0x5c76('0x36')][_0x5c76('0x3d')]);_0x56829e[_0x5c76('0x3e')]=qs[_0x5c76('0x38')](_[_0x5c76('0x3f')](_0x4d210b[_0x5c76('0x36')],_0xf931d3[_0x5c76('0x38')]));if(_0x4d210b['query'][_0x5c76('0x40')]){_0x56829e[_0x5c76('0x3e')]=_[_0x5c76('0x41')](_0x56829e[_0x5c76('0x3e')],{'$or':_[_0x5c76('0x30')](_0x56829e['attributes'],function(_0x1ed7a2){var _0x2fd64d={};_0x2fd64d[_0x1ed7a2]={'$like':'%'+_0x4d210b[_0x5c76('0x36')][_0x5c76('0x40')]+'%'};return _0x2fd64d;})});}_0x56829e=_[_0x5c76('0x41')]({},_0x56829e,_0x4d210b[_0x5c76('0x42')]);return _0x3e0efa[_0x5c76('0x64')](_0x56829e);}})[_0x5c76('0x27')](function(_0x512635){if(_0x512635){_0x4fe961=_0x512635[_0x5c76('0x3c')];if(!_0x4d210b['query']['hasOwnProperty'](_0x5c76('0x66'))){_0x56829e[_0x5c76('0x23')]=qs['limit'](_0x4d210b[_0x5c76('0x36')]['limit']);_0x56829e['offset']=qs['offset'](_0x4d210b[_0x5c76('0x36')]['offset']);}return _0x3e0efa['getTeams'](_0x56829e);}})[_0x5c76('0x27')](function(_0x147db0){if(_0x147db0){return _0x147db0?{'count':_0x4fe961,'rows':_0x147db0}:null;}})['then'](respondWithResult(_0x589f8a,null))[_0x5c76('0x46')](handleError(_0x589f8a,null));};exports[_0x5c76('0x67')]=function(_0xd23475,_0x2cd5e4,_0x86e306){var _0x4bcd32=_0xd23475[_0x5c76('0x4a')][_0x5c76('0x68')];return db[_0x5c76('0x65')]['findAll']({'where':{'id':_0x4bcd32},'attributes':['id'],'include':[{'model':db[_0x5c76('0x5b')],'as':'Agents','attributes':['id',_0x5c76('0x2e'),_0x5c76('0x69'),_0x5c76('0x6a'),_0x5c76('0x6b')],'raw':!![]}]})['then'](function(_0x1b435d){if(_0x1b435d){var _0x200a05=_[_0x5c76('0x6c')](_0x1b435d,function(_0x541ff4){var _0x382e51=_0x541ff4[_0x5c76('0x29')]({'plain':!![]});return _0x382e51[_0x5c76('0x6d')];});return db['WhatsappQueue'][_0x5c76('0x4f')]({'where':{'id':_0xd23475[_0x5c76('0x53')]['id']}})[_0x5c76('0x27')](function(_0x49a481){return db['sequelize'][_0x5c76('0x6e')](function(_0x9cec15){return _0x49a481[_0x5c76('0x67')](_0x4bcd32,{'transaction':_0x9cec15})[_0x5c76('0x27')](function(){return BPromise[_0x5c76('0x6f')](_0x200a05,function(_0x54823c){return db[_0x5c76('0x5a')][_0x5c76('0x70')]({'where':{'UserId':_0x54823c['id'],'WhatsappQueueId':_0xd23475[_0x5c76('0x53')]['id']},'transaction':_0x9cec15});});})[_0x5c76('0x27')](function(){_0x200a05['forEach'](function(_0xb84f82){socket[_0x5c76('0x71')]('userWhatsappQueue:save',{'UserId':_0xb84f82['id'],'WhatsappQueueId':_0x49a481['id']});});});});});}})[_0x5c76('0x27')](respondWithStatusCode(_0x2cd5e4,null))[_0x5c76('0x46')](handleError(_0x2cd5e4,null));};exports[_0x5c76('0x72')]=function(_0x5460e8,_0x5da017,_0x2d0955){return db[_0x5c76('0x65')]['findAll']({'where':{'id':_0x5460e8[_0x5c76('0x36')][_0x5c76('0x68')]},'attributes':['id'],'include':[{'model':db['User'],'as':_0x5c76('0x6d'),'attributes':['id'],'raw':!![]}]})[_0x5c76('0x27')](handleEntityNotFound(_0x5da017,null))[_0x5c76('0x27')](function(_0x4bac22){var _0x4ccb3e=_[_0x5c76('0x30')](_0x4bac22,'id');var _0x24f201=[];var _0x222010=[];var _0x567bde=squel[_0x5c76('0x73')]();_0x567bde['field'](_0x5c76('0x74'))[_0x5c76('0x75')](_0x5c76('0x76'),'tq')[_0x5c76('0x77')](_0x5c76('0x78'),'ut','ut.TeamId\x20=\x20tq.TeamId')[_0x5c76('0x3e')](_0x5c76('0x79'),_0x5460e8[_0x5c76('0x53')]['id']);for(var _0x57fe82=0x0;_0x57fe82<_0x4bac22['length'];_0x57fe82+=0x1){let _0x517b57=_0x4bac22[_0x57fe82];for(var _0x54af76=0x0;_0x54af76<_0x517b57[_0x5c76('0x6d')][_0x5c76('0x3c')];_0x54af76+=0x1){let _0x3c835c=_0x517b57[_0x5c76('0x6d')][_0x54af76];var _0x530d01=_0x567bde['clone']();_0x530d01[_0x5c76('0x3e')](_0x5c76('0x7a'),_0x3c835c['id']);_0x222010['push'](db[_0x5c76('0x7b')][_0x5c76('0x36')](_0x530d01[_0x5c76('0x7c')](),{'type':db[_0x5c76('0x7b')][_0x5c76('0x7d')][_0x5c76('0x7e')]})['then'](function(_0x2edf63){if(_0x2edf63[_0x5c76('0x3c')]===0x1){return _0x3c835c['id'];}else{var _0x9fb24c=_['every'](_[_0x5c76('0x30')](_0x2edf63,'TeamId'),function(_0x4609eb){return _['includes'](_0x4ccb3e,_0x4609eb);});if(_0x9fb24c){return _0x3c835c['id'];}}}));}}return BPromise[_0x5c76('0x7f')](_0x222010)[_0x5c76('0x27')](function(_0x1bc6ae){_0x24f201=_(_0x24f201)[_0x5c76('0x80')](_0x1bc6ae)[_0x5c76('0x81')]()[_0x5c76('0x82')]();return db[_0x5c76('0x31')]['find']({'where':{'id':_0x5460e8[_0x5c76('0x53')]['id']}})[_0x5c76('0x27')](function(_0x203de5){return db['sequelize']['transaction'](function(_0x50d8e4){return _0x203de5[_0x5c76('0x72')](_0x5460e8[_0x5c76('0x36')][_0x5c76('0x68')],{'transaction':_0x50d8e4})[_0x5c76('0x27')](function(){if(!_['isEmpty'](_0x24f201)){return _0x203de5[_0x5c76('0x83')](_0x24f201,{'transaction':_0x50d8e4});}})[_0x5c76('0x27')](function(){_0x24f201['forEach'](function(_0x2325a7){socket[_0x5c76('0x71')]('userWhatsappQueue:remove',{'UserId':_0x2325a7,'WhatsappQueueId':_0x203de5['id']});});});});});});})[_0x5c76('0x27')](respondWithStatusCode(_0x5da017,null))[_0x5c76('0x46')](handleError(_0x5da017,null));};exports[_0x5c76('0x84')]=function(_0x442477,_0x5d368a,_0x553977){return db[_0x5c76('0x31')][_0x5c76('0x4f')]({'where':{'id':_0x442477['params']['id']}})[_0x5c76('0x27')](handleEntityNotFound(_0x5d368a,null))['then'](function(_0x3df208){if(_0x3df208){return _0x3df208[_0x5c76('0x84')](_0x442477[_0x5c76('0x4a')]['ids'],_['omit'](_0x442477['body'],[_0x5c76('0x68'),'id'])||{})[_0x5c76('0x85')](function(_0x368ea8){for(var _0x376d56=0x0;_0x376d56<_0x442477[_0x5c76('0x4a')][_0x5c76('0x68')][_0x5c76('0x3c')];_0x376d56+=0x1){socket['emit'](_0x5c76('0x86'),{'UserId':Number(_0x442477[_0x5c76('0x4a')][_0x5c76('0x68')][_0x376d56]),'WhatsappQueueId':Number(_0x442477['params']['id'])});}return _0x368ea8;});}})[_0x5c76('0x27')](respondWithResult(_0x5d368a,null))[_0x5c76('0x46')](handleError(_0x5d368a,null));};exports[_0x5c76('0x83')]=function(_0x2afb0a,_0xe2e6f1,_0x28bc90){return db[_0x5c76('0x31')][_0x5c76('0x4f')]({'where':{'id':_0x2afb0a[_0x5c76('0x53')]['id']}})[_0x5c76('0x27')](handleEntityNotFound(_0xe2e6f1,null))[_0x5c76('0x27')](function(_0x55eabb){if(_0x55eabb){return _0x55eabb['removeAgents'](_0x2afb0a[_0x5c76('0x36')][_0x5c76('0x68')])[_0x5c76('0x27')](function(){if(_[_0x5c76('0x87')](_0x2afb0a[_0x5c76('0x36')][_0x5c76('0x68')])){for(var _0x458503=0x0;_0x458503<_0x2afb0a[_0x5c76('0x36')][_0x5c76('0x68')][_0x5c76('0x3c')];_0x458503+=0x1){socket[_0x5c76('0x71')](_0x5c76('0x88'),{'UserId':Number(_0x2afb0a[_0x5c76('0x36')][_0x5c76('0x68')][_0x458503]),'WhatsappQueueId':Number(_0x2afb0a[_0x5c76('0x53')]['id'])});}}else{socket[_0x5c76('0x71')](_0x5c76('0x88'),{'UserId':Number(_0x2afb0a['query']['ids']),'WhatsappQueueId':Number(_0x2afb0a[_0x5c76('0x53')]['id'])});}});}})['then'](respondWithStatusCode(_0xe2e6f1,null))['catch'](handleError(_0xe2e6f1,null));};exports['getAgents']=function(_0x5460ad,_0x9e86a5,_0x430c18){var _0x45e4e4={};var _0x428e74={};var _0x3d6c00;var _0xab623c;return db[_0x5c76('0x31')]['findOne']({'where':{'id':_0x5460ad['params']['id']}})['then'](handleEntityNotFound(_0x9e86a5,null))['then'](function(_0x464c74){if(_0x464c74){_0x3d6c00=_0x464c74;_0x428e74[_0x5c76('0x35')]=_[_0x5c76('0x37')](db[_0x5c76('0x5b')][_0x5c76('0x32')]);_0x428e74[_0x5c76('0x36')]=_[_0x5c76('0x37')](_0x5460ad[_0x5c76('0x36')]);_0x428e74[_0x5c76('0x38')]=_[_0x5c76('0x39')](_0x428e74['model'],_0x428e74['query']);_0x45e4e4[_0x5c76('0x3b')]=_[_0x5c76('0x39')](_0x428e74[_0x5c76('0x35')],qs[_0x5c76('0x3a')](_0x5460ad[_0x5c76('0x36')][_0x5c76('0x3a')]));_0x45e4e4[_0x5c76('0x3b')]=_0x45e4e4[_0x5c76('0x3b')][_0x5c76('0x3c')]?_0x45e4e4['attributes']:_0x428e74[_0x5c76('0x35')];_0x45e4e4[_0x5c76('0x58')]=qs[_0x5c76('0x3d')](_0x5460ad[_0x5c76('0x36')][_0x5c76('0x3d')]);_0x45e4e4['where']=qs[_0x5c76('0x38')](_['pick'](_0x5460ad['query'],_0x428e74[_0x5c76('0x38')]));if(_0x5460ad['query'][_0x5c76('0x40')]){_0x45e4e4[_0x5c76('0x3e')]=_[_0x5c76('0x41')](_0x45e4e4[_0x5c76('0x3e')],{'$or':_[_0x5c76('0x30')](_0x45e4e4[_0x5c76('0x3b')],function(_0x2cfabb){var _0x455614={};_0x455614[_0x2cfabb]={'$like':'%'+_0x5460ad[_0x5c76('0x36')][_0x5c76('0x40')]+'%'};return _0x455614;})});}_0x45e4e4=_[_0x5c76('0x41')]({},_0x45e4e4,_0x5460ad[_0x5c76('0x42')]);return _0x3d6c00[_0x5c76('0x89')](_0x45e4e4);}})[_0x5c76('0x27')](function(_0x5a9297){if(_0x5a9297){_0xab623c=_0x5a9297[_0x5c76('0x3c')];if(!_0x5460ad[_0x5c76('0x36')][_0x5c76('0x57')](_0x5c76('0x66'))){_0x45e4e4[_0x5c76('0x23')]=qs['limit'](_0x5460ad[_0x5c76('0x36')][_0x5c76('0x23')]);_0x45e4e4['offset']=qs[_0x5c76('0x20')](_0x5460ad[_0x5c76('0x36')]['offset']);}return _0x3d6c00['getAgents'](_0x45e4e4);}})[_0x5c76('0x27')](function(_0x225e2d){if(_0x225e2d){return _0x225e2d?{'count':_0xab623c,'rows':_0x225e2d}:null;}})[_0x5c76('0x27')](respondWithResult(_0x9e86a5,null))[_0x5c76('0x46')](handleError(_0x9e86a5,null));};
\ No newline at end of file