Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / api / smsQueue / smsQueue.controller.js
index 5162d65..4007293 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5f2f=['redis','defaults','localhost','socket.io-emitter','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','update','then','destroy','get','SmsQueues','UserProfileResource','error','stack','name','map','SmsQueue','rawAttributes','type','key','getOptions','where','include','findAll','rows','show','params','model','keys','query','filters','intersection','attributes','fields','includeAll','options','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','userProfileId','autoAssociation','catch','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','findOne','UserSmsQueue','length','hasOwnProperty','nolimit','order','sort','pick','filter','merge','findAndCountAll','UserId','agent','smsPause','updatedAt','createdAt','format','%s/%s','SIP','getTeams','Team','addTeams','ids','User','Agents','online','voicePause','interface','flatMap','findOrCreate','forEach','emit','userSmsQueue:save','removeTeams','field','SmsQueueId\x20=\x20?','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','all','union','compact','value','sequelize','transaction','isEmpty','removeAgents','addAgents','omit','spread','isArray','userSmsQueue:remove','getAgents','bluebird','util','lodash','squel','ioredis','../../components/parsers/qs','../../config/logger','api'];(function(_0x25023b,_0x383839){var _0x48b984=function(_0x3d3258){while(--_0x3d3258){_0x25023b['push'](_0x25023b['shift']());}};_0x48b984(++_0x383839);}(_0x5f2f,0x73));var _0xf5f2=function(_0x40d7b6,_0x299c45){_0x40d7b6=_0x40d7b6-0x0;var _0x203f97=_0x5f2f[_0x40d7b6];return _0x203f97;};'use strict';var BPromise=require(_0xf5f2('0x0'));var util=require(_0xf5f2('0x1'));var _=require(_0xf5f2('0x2'));var squel=require(_0xf5f2('0x3'));var Redis=require(_0xf5f2('0x4'));var qs=require(_0xf5f2('0x5'));var logger=require(_0xf5f2('0x6'))(_0xf5f2('0x7'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config[_0xf5f2('0x8')]=_[_0xf5f2('0x9')](config[_0xf5f2('0x8')],{'host':_0xf5f2('0xa'),'port':0x18eb});var socket=require(_0xf5f2('0xb'))(new Redis(config[_0xf5f2('0x8')]));require('./smsQueue.socket')[_0xf5f2('0xc')](socket);function respondWithStatusCode(_0x46cd9c,_0x2ec345){_0x2ec345=_0x2ec345||0xcc;return function(_0x56a69f){if(_0x56a69f){return _0x46cd9c[_0xf5f2('0xd')](_0x2ec345);}return _0x46cd9c[_0xf5f2('0xe')](_0x2ec345)[_0xf5f2('0xf')]();};}function respondWithResult(_0x4e0e6b,_0x977a59){_0x977a59=_0x977a59||0xc8;return function(_0x4ebbbe){if(_0x4ebbbe){return _0x4e0e6b['status'](_0x977a59)[_0xf5f2('0x10')](_0x4ebbbe);}};}function respondWithFilteredResult(_0x151aba,_0x4b78cd){return function(_0x336f6b){if(_0x336f6b){var _0x14b51f=typeof _0x4b78cd[_0xf5f2('0x11')]===_0xf5f2('0x12')&&typeof _0x4b78cd[_0xf5f2('0x13')]===_0xf5f2('0x12');var _0x5c01b8=_0x336f6b[_0xf5f2('0x14')];var _0xea612c=_0x14b51f?0x0:_0x4b78cd[_0xf5f2('0x11')];var _0x1c1a5c=_0x14b51f?_0x336f6b[_0xf5f2('0x14')]:_0x4b78cd['offset']+_0x4b78cd[_0xf5f2('0x13')];var _0x286197;if(_0x1c1a5c>=_0x5c01b8){_0x1c1a5c=_0x5c01b8;_0x286197=0xc8;}else{_0x286197=0xce;}_0x151aba[_0xf5f2('0xe')](_0x286197);return _0x151aba[_0xf5f2('0x15')](_0xf5f2('0x16'),_0xea612c+'-'+_0x1c1a5c+'/'+_0x5c01b8)[_0xf5f2('0x10')](_0x336f6b);}return null;};}function saveUpdates(_0xdb61b3){return function(_0x395a5a){if(_0x395a5a){return _0x395a5a[_0xf5f2('0x17')](_0xdb61b3)[_0xf5f2('0x18')](function(_0x20fccd){return _0x20fccd;});}return null;};}function removeEntity(_0x28e097){return function(_0x4ff59b){if(_0x4ff59b){return _0x4ff59b[_0xf5f2('0x19')]()[_0xf5f2('0x18')](function(){var _0x626999=_0x4ff59b[_0xf5f2('0x1a')]({'plain':!![]});var _0x56acc5=_0xf5f2('0x1b');return db[_0xf5f2('0x1c')]['destroy']({'where':{'type':_0x56acc5,'resourceId':_0x626999['id']}})['then'](function(){return _0x4ff59b;});})[_0xf5f2('0x18')](function(){_0x28e097[_0xf5f2('0xe')](0xcc)['end']();});}};}function handleEntityNotFound(_0x45b74f){return function(_0x170042){if(!_0x170042){_0x45b74f[_0xf5f2('0xd')](0x194);}return _0x170042;};}function handleError(_0x39c024,_0x36f1cb){_0x36f1cb=_0x36f1cb||0x1f4;return function(_0x4c691a){logger[_0xf5f2('0x1d')](_0x4c691a[_0xf5f2('0x1e')]);if(_0x4c691a[_0xf5f2('0x1f')]){delete _0x4c691a[_0xf5f2('0x1f')];}_0x39c024[_0xf5f2('0xe')](_0x36f1cb)['send'](_0x4c691a);};}exports['index']=function(_0x5f1124,_0x3f79d5){var _0x13da6f={};var _0x1a5bb3={'count':0x0,'rows':[]};var _0xf6c58d=_[_0xf5f2('0x20')](db[_0xf5f2('0x21')][_0xf5f2('0x22')],function(_0x294414){return{'name':_0x294414['fieldName'],'type':_0x294414[_0xf5f2('0x23')][_0xf5f2('0x24')]};});_0x13da6f=qs[_0xf5f2('0x25')](_0xf6c58d,_0x5f1124);var _0x31bfcb={'where':_0x13da6f[_0xf5f2('0x26')]};return db[_0xf5f2('0x21')]['count'](_0x31bfcb)['then'](function(_0x22c826){_0x1a5bb3[_0xf5f2('0x14')]=_0x22c826;_0x13da6f[_0xf5f2('0x27')]=qs['include'](_0x5f1124['query']);return db[_0xf5f2('0x21')][_0xf5f2('0x28')](_0x13da6f);})[_0xf5f2('0x18')](function(_0x153924){_0x1a5bb3[_0xf5f2('0x29')]=_0x153924;return _0x1a5bb3;})['then'](respondWithFilteredResult(_0x3f79d5,_0x13da6f))['catch'](handleError(_0x3f79d5,null));};exports[_0xf5f2('0x2a')]=function(_0x4e19cb,_0xb744b9){var _0x58a4df={'raw':!![],'where':{'id':_0x4e19cb[_0xf5f2('0x2b')]['id']}},_0x45b643={};_0x45b643[_0xf5f2('0x2c')]=_[_0xf5f2('0x2d')](db[_0xf5f2('0x21')][_0xf5f2('0x22')]);_0x45b643[_0xf5f2('0x2e')]=_[_0xf5f2('0x2d')](_0x4e19cb['query']);_0x45b643[_0xf5f2('0x2f')]=_[_0xf5f2('0x30')](_0x45b643[_0xf5f2('0x2c')],_0x45b643[_0xf5f2('0x2e')]);_0x58a4df[_0xf5f2('0x31')]=_[_0xf5f2('0x30')](_0x45b643[_0xf5f2('0x2c')],qs['fields'](_0x4e19cb[_0xf5f2('0x2e')][_0xf5f2('0x32')]));_0x58a4df['attributes']=_0x58a4df[_0xf5f2('0x31')]['length']?_0x58a4df[_0xf5f2('0x31')]:_0x45b643[_0xf5f2('0x2c')];if(_0x4e19cb[_0xf5f2('0x2e')][_0xf5f2('0x33')]){_0x58a4df['include']=[{'all':!![]}];}_0x58a4df=_['merge']({},_0x58a4df,_0x4e19cb[_0xf5f2('0x34')]);return db[_0xf5f2('0x21')][_0xf5f2('0x35')](_0x58a4df)['then'](handleEntityNotFound(_0xb744b9,null))[_0xf5f2('0x18')](respondWithResult(_0xb744b9,null))['catch'](handleError(_0xb744b9,null));};exports[_0xf5f2('0x36')]=function(_0x566c47,_0x46f464){return db[_0xf5f2('0x21')]['create'](_0x566c47[_0xf5f2('0x37')],{})[_0xf5f2('0x18')](function(_0x5a4441){var _0x35f738=_0x566c47['user']['get']({'plain':!![]});if(!_0x35f738)throw new Error(_0xf5f2('0x38'));if(_0x35f738[_0xf5f2('0x39')]===_0xf5f2('0x3a')){var _0x2d4400=_0x5a4441[_0xf5f2('0x1a')]({'plain':!![]});var _0xe62b57=_0xf5f2('0x1b');return db['UserProfileSection'][_0xf5f2('0x35')]({'where':{'name':_0xe62b57,'userProfileId':_0x35f738[_0xf5f2('0x3b')]},'raw':!![]})['then'](function(_0xc6a1ae){if(_0xc6a1ae&&_0xc6a1ae[_0xf5f2('0x3c')]===0x0){return db[_0xf5f2('0x1c')][_0xf5f2('0x36')]({'name':_0x2d4400[_0xf5f2('0x1f')],'resourceId':_0x2d4400['id'],'type':_0xc6a1ae[_0xf5f2('0x1f')],'sectionId':_0xc6a1ae['id']},{})[_0xf5f2('0x18')](function(){return _0x5a4441;});}else{return _0x5a4441;}})[_0xf5f2('0x3d')](function(_0x574f24){logger[_0xf5f2('0x1d')](_0xf5f2('0x3e'),_0x574f24);throw _0x574f24;});}return _0x5a4441;})[_0xf5f2('0x18')](respondWithResult(_0x46f464,0xc9))['catch'](handleError(_0x46f464,null));};exports['update']=function(_0x59eb00,_0x76d21b){if(_0x59eb00[_0xf5f2('0x37')]['id']){delete _0x59eb00['body']['id'];}return db[_0xf5f2('0x21')][_0xf5f2('0x35')]({'where':{'id':_0x59eb00[_0xf5f2('0x2b')]['id']}})[_0xf5f2('0x18')](handleEntityNotFound(_0x76d21b,null))[_0xf5f2('0x18')](saveUpdates(_0x59eb00[_0xf5f2('0x37')],null))[_0xf5f2('0x18')](respondWithResult(_0x76d21b,null))[_0xf5f2('0x3d')](handleError(_0x76d21b,null));};exports[_0xf5f2('0x19')]=function(_0x106062,_0x444317){return db[_0xf5f2('0x21')][_0xf5f2('0x35')]({'where':{'id':_0x106062[_0xf5f2('0x2b')]['id']}})['then'](handleEntityNotFound(_0x444317,null))[_0xf5f2('0x18')](removeEntity(_0x444317,null))['catch'](handleError(_0x444317,null));};exports[_0xf5f2('0x3f')]=function(_0xc04f44,_0x218def){return db[_0xf5f2('0x21')][_0xf5f2('0x3f')]()[_0xf5f2('0x18')](respondWithResult(_0x218def,null))['catch'](handleError(_0x218def,null));};exports[_0xf5f2('0x40')]=function(_0x2e7193,_0x1c1497){var _0x29b108={'raw':!![],'where':{}},_0x12124d={},_0x10753a;return db[_0xf5f2('0x21')][_0xf5f2('0x41')]({'where':{'id':_0x2e7193['params']['id']}})[_0xf5f2('0x18')](handleEntityNotFound(_0x1c1497,null))[_0xf5f2('0x18')](function(_0x45db9a){if(_0x45db9a){_0x10753a=_0x45db9a['get']({'plain':!![]});_0x12124d[_0xf5f2('0x2c')]=_[_0xf5f2('0x2d')](db[_0xf5f2('0x42')]['rawAttributes']);_0x12124d['query']=_[_0xf5f2('0x2d')](_0x2e7193[_0xf5f2('0x2e')]);_0x12124d['filters']=_[_0xf5f2('0x30')](_0x12124d['model'],_0x12124d[_0xf5f2('0x2e')]);_0x29b108['attributes']=_[_0xf5f2('0x30')](_0x12124d['model'],qs[_0xf5f2('0x32')](_0x2e7193[_0xf5f2('0x2e')][_0xf5f2('0x32')]));_0x29b108[_0xf5f2('0x31')]=_0x29b108['attributes'][_0xf5f2('0x43')]?_0x29b108[_0xf5f2('0x31')]:_0x12124d['model'];if(!_0x2e7193['query'][_0xf5f2('0x44')](_0xf5f2('0x45'))){_0x29b108['limit']=qs[_0xf5f2('0x13')](_0x2e7193[_0xf5f2('0x2e')][_0xf5f2('0x13')]);_0x29b108[_0xf5f2('0x11')]=qs['offset'](_0x2e7193['query'][_0xf5f2('0x11')]);}_0x29b108[_0xf5f2('0x46')]=qs['sort'](_0x2e7193[_0xf5f2('0x2e')][_0xf5f2('0x47')]);_0x29b108[_0xf5f2('0x26')]=qs[_0xf5f2('0x2f')](_[_0xf5f2('0x48')](_0x2e7193[_0xf5f2('0x2e')],_0x12124d[_0xf5f2('0x2f')]));_0x29b108['where']['SmsQueueId']=_0x45db9a['id'];if(_0x2e7193[_0xf5f2('0x2e')][_0xf5f2('0x49')]){_0x29b108[_0xf5f2('0x26')]=_[_0xf5f2('0x4a')](_0x29b108[_0xf5f2('0x26')],{'$or':_['map'](_0x29b108[_0xf5f2('0x31')],function(_0x20ba91){var _0x18b124={};_0x18b124[_0x20ba91]={'$like':'%'+_0x2e7193['query'][_0xf5f2('0x49')]+'%'};return _0x18b124;})});}_0x29b108=_['merge']({},_0x29b108,_0x2e7193[_0xf5f2('0x34')]);return db[_0xf5f2('0x42')][_0xf5f2('0x28')](_0x29b108);}})[_0xf5f2('0x18')](function(_0x4afa4d){if(_0x4afa4d){return db['User'][_0xf5f2('0x4b')]({'where':{'id':_['map'](_0x4afa4d,_0xf5f2('0x4c')),'role':_0xf5f2('0x4d')},'attributes':['id','name',_0xf5f2('0x4e'),_0xf5f2('0x4f'),_0xf5f2('0x50')]});}})['then'](function(_0x397b99){if(_0x397b99){return{'count':_0x397b99[_0xf5f2('0x14')],'rows':_[_0xf5f2('0x20')](_0x397b99[_0xf5f2('0x29')],function(_0x51fa7e){return{'membername':_0x51fa7e[_0xf5f2('0x1f')],'UserId':_0x51fa7e['id'],'queue_name':_0x10753a['name'],'SmsQueueId':_0x10753a['id'],'interface':util[_0xf5f2('0x51')](_0xf5f2('0x52'),_0xf5f2('0x53'),_0x51fa7e[_0xf5f2('0x1f')]),'penalty':0x0,'paused':_0x51fa7e[_0xf5f2('0x4e')],'createdAt':_0x51fa7e['createdAt'],'updatedAt':_0x51fa7e[_0xf5f2('0x4f')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xf5f2('0x18')](respondWithFilteredResult(_0x1c1497,_0x29b108))[_0xf5f2('0x3d')](handleError(_0x1c1497,null));};exports[_0xf5f2('0x54')]=function(_0x2c5733,_0x5359b5){var _0x31e16b={};var _0x5ee6bc={};var _0x4c96ee;var _0xd4f6ef;return db['SmsQueue'][_0xf5f2('0x41')]({'where':{'id':_0x2c5733[_0xf5f2('0x2b')]['id']}})[_0xf5f2('0x18')](handleEntityNotFound(_0x5359b5,null))[_0xf5f2('0x18')](function(_0x5767fc){if(_0x5767fc){_0x4c96ee=_0x5767fc;_0x5ee6bc[_0xf5f2('0x2c')]=_[_0xf5f2('0x2d')](db[_0xf5f2('0x55')][_0xf5f2('0x22')]);_0x5ee6bc[_0xf5f2('0x2e')]=_[_0xf5f2('0x2d')](_0x2c5733[_0xf5f2('0x2e')]);_0x5ee6bc['filters']=_[_0xf5f2('0x30')](_0x5ee6bc[_0xf5f2('0x2c')],_0x5ee6bc[_0xf5f2('0x2e')]);_0x31e16b[_0xf5f2('0x31')]=_['intersection'](_0x5ee6bc[_0xf5f2('0x2c')],qs['fields'](_0x2c5733[_0xf5f2('0x2e')][_0xf5f2('0x32')]));_0x31e16b['attributes']=_0x31e16b[_0xf5f2('0x31')][_0xf5f2('0x43')]?_0x31e16b[_0xf5f2('0x31')]:_0x5ee6bc[_0xf5f2('0x2c')];_0x31e16b[_0xf5f2('0x46')]=qs['sort'](_0x2c5733[_0xf5f2('0x2e')][_0xf5f2('0x47')]);_0x31e16b[_0xf5f2('0x26')]=qs[_0xf5f2('0x2f')](_[_0xf5f2('0x48')](_0x2c5733[_0xf5f2('0x2e')],_0x5ee6bc['filters']));if(_0x2c5733[_0xf5f2('0x2e')][_0xf5f2('0x49')]){_0x31e16b['where']=_[_0xf5f2('0x4a')](_0x31e16b[_0xf5f2('0x26')],{'$or':_[_0xf5f2('0x20')](_0x31e16b['attributes'],function(_0x551cc9){var _0x4f3df6={};_0x4f3df6[_0x551cc9]={'$like':'%'+_0x2c5733[_0xf5f2('0x2e')][_0xf5f2('0x49')]+'%'};return _0x4f3df6;})});}_0x31e16b=_[_0xf5f2('0x4a')]({},_0x31e16b,_0x2c5733[_0xf5f2('0x34')]);return _0x4c96ee[_0xf5f2('0x54')](_0x31e16b);}})['then'](function(_0x278b76){if(_0x278b76){_0xd4f6ef=_0x278b76[_0xf5f2('0x43')];if(!_0x2c5733[_0xf5f2('0x2e')][_0xf5f2('0x44')](_0xf5f2('0x45'))){_0x31e16b[_0xf5f2('0x13')]=qs[_0xf5f2('0x13')](_0x2c5733[_0xf5f2('0x2e')][_0xf5f2('0x13')]);_0x31e16b[_0xf5f2('0x11')]=qs[_0xf5f2('0x11')](_0x2c5733['query']['offset']);}return _0x4c96ee['getTeams'](_0x31e16b);}})[_0xf5f2('0x18')](function(_0xafba8e){if(_0xafba8e){return _0xafba8e?{'count':_0xd4f6ef,'rows':_0xafba8e}:null;}})[_0xf5f2('0x18')](respondWithResult(_0x5359b5,null))[_0xf5f2('0x3d')](handleError(_0x5359b5,null));};exports[_0xf5f2('0x56')]=function(_0x5c6959,_0x9d943f){var _0x43c732=_0x5c6959[_0xf5f2('0x37')][_0xf5f2('0x57')];return db[_0xf5f2('0x55')]['findAll']({'where':{'id':_0x43c732},'attributes':['id'],'include':[{'model':db[_0xf5f2('0x58')],'as':_0xf5f2('0x59'),'attributes':['id','name',_0xf5f2('0x5a'),_0xf5f2('0x5b'),_0xf5f2('0x5c')],'raw':!![]}]})[_0xf5f2('0x18')](function(_0x588434){if(_0x588434){var _0x40b36e=_[_0xf5f2('0x5d')](_0x588434,function(_0x19602d){var _0x2adeb4=_0x19602d[_0xf5f2('0x1a')]({'plain':!![]});return _0x2adeb4['Agents'];});return db['SmsQueue'][_0xf5f2('0x35')]({'where':{'id':_0x5c6959[_0xf5f2('0x2b')]['id']}})[_0xf5f2('0x18')](function(_0xe3ea1e){return db['sequelize']['transaction'](function(_0x16048e){return _0xe3ea1e['addTeams'](_0x43c732,{'transaction':_0x16048e})['then'](function(){return BPromise['each'](_0x40b36e,function(_0x57cb18){return db[_0xf5f2('0x42')][_0xf5f2('0x5e')]({'where':{'UserId':_0x57cb18['id'],'SmsQueueId':_0x5c6959[_0xf5f2('0x2b')]['id']},'transaction':_0x16048e});});})[_0xf5f2('0x18')](function(){_0x40b36e[_0xf5f2('0x5f')](function(_0x9f941e){socket[_0xf5f2('0x60')](_0xf5f2('0x61'),{'UserId':_0x9f941e['id'],'SmsQueueId':_0xe3ea1e['id']});});});});});}})[_0xf5f2('0x18')](respondWithStatusCode(_0x9d943f,null))[_0xf5f2('0x3d')](handleError(_0x9d943f,null));};exports[_0xf5f2('0x62')]=function(_0x2afeac,_0x1ba503){return db[_0xf5f2('0x55')][_0xf5f2('0x28')]({'where':{'id':_0x2afeac[_0xf5f2('0x2e')][_0xf5f2('0x57')]},'attributes':['id'],'include':[{'model':db[_0xf5f2('0x58')],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0xf5f2('0x18')](handleEntityNotFound(_0x1ba503,null))[_0xf5f2('0x18')](function(_0x21043b){var _0x2811ad=_[_0xf5f2('0x20')](_0x21043b,'id');var _0x308220=[];var _0x16491c=[];var _0xcf48eb=squel['select']();_0xcf48eb[_0xf5f2('0x63')]('tq.TeamId')['from']('team_has_sms_queues','tq')['join']('user_has_teams','ut','ut.TeamId\x20=\x20tq.TeamId')[_0xf5f2('0x26')](_0xf5f2('0x64'),_0x2afeac[_0xf5f2('0x2b')]['id']);for(var _0x375bc9=0x0;_0x375bc9<_0x21043b[_0xf5f2('0x43')];_0x375bc9+=0x1){let _0x3cf857=_0x21043b[_0x375bc9];for(var _0x5dc63f=0x0;_0x5dc63f<_0x3cf857['Agents'][_0xf5f2('0x43')];_0x5dc63f+=0x1){let _0x578a22=_0x3cf857[_0xf5f2('0x59')][_0x5dc63f];var _0x186fdd=_0xcf48eb['clone']();_0x186fdd['where'](_0xf5f2('0x65'),_0x578a22['id']);_0x16491c[_0xf5f2('0x66')](db['sequelize'][_0xf5f2('0x2e')](_0x186fdd[_0xf5f2('0x67')](),{'type':db['sequelize'][_0xf5f2('0x68')][_0xf5f2('0x69')]})[_0xf5f2('0x18')](function(_0x4c1678){if(_0x4c1678[_0xf5f2('0x43')]===0x1){return _0x578a22['id'];}else{var _0xc28adc=_[_0xf5f2('0x6a')](_[_0xf5f2('0x20')](_0x4c1678,_0xf5f2('0x6b')),function(_0x3e0288){return _[_0xf5f2('0x6c')](_0x2811ad,_0x3e0288);});if(_0xc28adc){return _0x578a22['id'];}}}));}}return BPromise[_0xf5f2('0x6d')](_0x16491c)[_0xf5f2('0x18')](function(_0x3a6f60){_0x308220=_(_0x308220)[_0xf5f2('0x6e')](_0x3a6f60)[_0xf5f2('0x6f')]()[_0xf5f2('0x70')]();return db[_0xf5f2('0x21')][_0xf5f2('0x35')]({'where':{'id':_0x2afeac[_0xf5f2('0x2b')]['id']}})[_0xf5f2('0x18')](function(_0x29a9d4){return db[_0xf5f2('0x71')][_0xf5f2('0x72')](function(_0x800f42){return _0x29a9d4['removeTeams'](_0x2afeac[_0xf5f2('0x2e')][_0xf5f2('0x57')],{'transaction':_0x800f42})['then'](function(){if(!_[_0xf5f2('0x73')](_0x308220)){return _0x29a9d4[_0xf5f2('0x74')](_0x308220,{'transaction':_0x800f42});}})['then'](function(){_0x308220[_0xf5f2('0x5f')](function(_0x2f54eb){socket[_0xf5f2('0x60')]('userSmsQueue:remove',{'UserId':_0x2f54eb,'SmsQueueId':_0x29a9d4['id']});});});});});});})['then'](respondWithStatusCode(_0x1ba503,null))[_0xf5f2('0x3d')](handleError(_0x1ba503,null));};exports[_0xf5f2('0x75')]=function(_0x213ade,_0x5ba275){return db['SmsQueue'][_0xf5f2('0x35')]({'where':{'id':_0x213ade[_0xf5f2('0x2b')]['id']}})[_0xf5f2('0x18')](handleEntityNotFound(_0x5ba275,null))['then'](function(_0x4cde64){if(_0x4cde64){return _0x4cde64['addAgents'](_0x213ade['body']['ids'],_[_0xf5f2('0x76')](_0x213ade['body'],[_0xf5f2('0x57'),'id'])||{})[_0xf5f2('0x77')](function(_0xec3c35){for(var _0x43a167=0x0;_0x43a167<_0x213ade[_0xf5f2('0x37')][_0xf5f2('0x57')][_0xf5f2('0x43')];_0x43a167+=0x1){socket[_0xf5f2('0x60')](_0xf5f2('0x61'),{'UserId':Number(_0x213ade[_0xf5f2('0x37')][_0xf5f2('0x57')][_0x43a167]),'SmsQueueId':Number(_0x213ade[_0xf5f2('0x2b')]['id'])});}return _0xec3c35;});}})[_0xf5f2('0x18')](respondWithResult(_0x5ba275,null))['catch'](handleError(_0x5ba275,null));};exports[_0xf5f2('0x74')]=function(_0x2a4fed,_0x5783e2){return db[_0xf5f2('0x21')][_0xf5f2('0x35')]({'where':{'id':_0x2a4fed['params']['id']}})[_0xf5f2('0x18')](handleEntityNotFound(_0x5783e2,null))[_0xf5f2('0x18')](function(_0x281f61){if(_0x281f61){return _0x281f61['removeAgents'](_0x2a4fed[_0xf5f2('0x2e')][_0xf5f2('0x57')])['then'](function(){if(_[_0xf5f2('0x78')](_0x2a4fed[_0xf5f2('0x2e')][_0xf5f2('0x57')])){for(var _0x517aa8=0x0;_0x517aa8<_0x2a4fed[_0xf5f2('0x2e')]['ids'][_0xf5f2('0x43')];_0x517aa8+=0x1){socket['emit'](_0xf5f2('0x79'),{'UserId':Number(_0x2a4fed[_0xf5f2('0x2e')][_0xf5f2('0x57')][_0x517aa8]),'SmsQueueId':Number(_0x2a4fed[_0xf5f2('0x2b')]['id'])});}}else{socket['emit'](_0xf5f2('0x79'),{'UserId':Number(_0x2a4fed['query']['ids']),'SmsQueueId':Number(_0x2a4fed['params']['id'])});}});}})[_0xf5f2('0x18')](respondWithStatusCode(_0x5783e2,null))[_0xf5f2('0x3d')](handleError(_0x5783e2,null));};exports['getAgents']=function(_0x3c8a1b,_0x15025d){var _0x35790b={};var _0x3962b2={};var _0x28873e;var _0x1fc5ae;return db['SmsQueue'][_0xf5f2('0x41')]({'where':{'id':_0x3c8a1b[_0xf5f2('0x2b')]['id']}})['then'](handleEntityNotFound(_0x15025d,null))[_0xf5f2('0x18')](function(_0x19cbff){if(_0x19cbff){_0x28873e=_0x19cbff;_0x3962b2['model']=_[_0xf5f2('0x2d')](db[_0xf5f2('0x58')][_0xf5f2('0x22')]);_0x3962b2[_0xf5f2('0x2e')]=_[_0xf5f2('0x2d')](_0x3c8a1b[_0xf5f2('0x2e')]);_0x3962b2['filters']=_[_0xf5f2('0x30')](_0x3962b2[_0xf5f2('0x2c')],_0x3962b2[_0xf5f2('0x2e')]);_0x35790b[_0xf5f2('0x31')]=_[_0xf5f2('0x30')](_0x3962b2[_0xf5f2('0x2c')],qs[_0xf5f2('0x32')](_0x3c8a1b[_0xf5f2('0x2e')][_0xf5f2('0x32')]));_0x35790b['attributes']=_0x35790b[_0xf5f2('0x31')][_0xf5f2('0x43')]?_0x35790b[_0xf5f2('0x31')]:_0x3962b2[_0xf5f2('0x2c')];_0x35790b[_0xf5f2('0x46')]=qs[_0xf5f2('0x47')](_0x3c8a1b[_0xf5f2('0x2e')][_0xf5f2('0x47')]);_0x35790b[_0xf5f2('0x26')]=qs[_0xf5f2('0x2f')](_['pick'](_0x3c8a1b['query'],_0x3962b2[_0xf5f2('0x2f')]));if(_0x3c8a1b[_0xf5f2('0x2e')][_0xf5f2('0x49')]){_0x35790b[_0xf5f2('0x26')]=_['merge'](_0x35790b[_0xf5f2('0x26')],{'$or':_[_0xf5f2('0x20')](_0x35790b[_0xf5f2('0x31')],function(_0x3d7f53){var _0x456a1e={};_0x456a1e[_0x3d7f53]={'$like':'%'+_0x3c8a1b['query'][_0xf5f2('0x49')]+'%'};return _0x456a1e;})});}_0x35790b=_[_0xf5f2('0x4a')]({},_0x35790b,_0x3c8a1b['options']);return _0x28873e[_0xf5f2('0x7a')](_0x35790b);}})[_0xf5f2('0x18')](function(_0x2563fa){if(_0x2563fa){_0x1fc5ae=_0x2563fa[_0xf5f2('0x43')];if(!_0x3c8a1b['query'][_0xf5f2('0x44')](_0xf5f2('0x45'))){_0x35790b[_0xf5f2('0x13')]=qs['limit'](_0x3c8a1b['query'][_0xf5f2('0x13')]);_0x35790b[_0xf5f2('0x11')]=qs[_0xf5f2('0x11')](_0x3c8a1b[_0xf5f2('0x2e')][_0xf5f2('0x11')]);}return _0x28873e[_0xf5f2('0x7a')](_0x35790b);}})['then'](function(_0x39dee8){if(_0x39dee8){return _0x39dee8?{'count':_0x1fc5ae,'rows':_0x39dee8}:null;}})['then'](respondWithResult(_0x15025d,null))[_0xf5f2('0x3d')](handleError(_0x15025d,null));};
\ No newline at end of file
+var _0x5f66=['show','params','model','keys','intersection','attributes','fields','includeAll','merge','options','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','SmsQueues','find','userProfileId','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','rawAttributes','filters','hasOwnProperty','order','sort','pick','map','UserSmsQueue','User','findAndCountAll','UserId','agent','smsPause','updatedAt','createdAt','%s/%s','SIP','getTeams','length','filter','nolimit','ids','Team','Agents','interface','flatMap','sequelize','transaction','addTeams','forEach','emit','userSmsQueue:save','removeTeams','select','tq.TeamId','team_has_sms_queues','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','toString','QueryTypes','SELECT','includes','all','compact','value','isEmpty','removeAgents','userSmsQueue:remove','addAgents','spread','isArray','findOne','getAgents','util','squel','ioredis','../../components/parsers/qs','../../config/logger','api','../../mysqldb','defaults','redis','./smsQueue.socket','register','end','json','offset','limit','undefined','count','status','update','then','UserProfileResource','destroy','sendStatus','stack','name','send','index','fieldName','key','getOptions','where','SmsQueue','include','query','findAll','catch'];(function(_0x3b2395,_0x1cf2c1){var _0x2e6751=function(_0x4ea274){while(--_0x4ea274){_0x3b2395['push'](_0x3b2395['shift']());}};_0x2e6751(++_0x1cf2c1);}(_0x5f66,0x1a0));var _0x65f6=function(_0x3e5086,_0x48f4a2){_0x3e5086=_0x3e5086-0x0;var _0xfeb102=_0x5f66[_0x3e5086];return _0xfeb102;};'use strict';var BPromise=require('bluebird');var util=require(_0x65f6('0x0'));var _=require('lodash');var squel=require(_0x65f6('0x1'));var Redis=require(_0x65f6('0x2'));var qs=require(_0x65f6('0x3'));var logger=require(_0x65f6('0x4'))(_0x65f6('0x5'));var config=require('../../config/environment');var db=require(_0x65f6('0x6'))['db'];config['redis']=_[_0x65f6('0x7')](config[_0x65f6('0x8')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x65f6('0x8')]));require(_0x65f6('0x9'))[_0x65f6('0xa')](socket);function respondWithStatusCode(_0x8f6451,_0xc44c70){_0xc44c70=_0xc44c70||0xcc;return function(_0x14f4c7){if(_0x14f4c7){return _0x8f6451['sendStatus'](_0xc44c70);}return _0x8f6451['status'](_0xc44c70)[_0x65f6('0xb')]();};}function respondWithResult(_0x2f6d5b,_0x264647){_0x264647=_0x264647||0xc8;return function(_0x25c416){if(_0x25c416){return _0x2f6d5b['status'](_0x264647)[_0x65f6('0xc')](_0x25c416);}};}function respondWithFilteredResult(_0x571436,_0x497cf3){return function(_0x2d2dfa){if(_0x2d2dfa){var _0x576875=typeof _0x497cf3[_0x65f6('0xd')]==='undefined'&&typeof _0x497cf3[_0x65f6('0xe')]===_0x65f6('0xf');var _0x2c4ee5=_0x2d2dfa[_0x65f6('0x10')];var _0x369f96=_0x576875?0x0:_0x497cf3[_0x65f6('0xd')];var _0x44144b=_0x576875?_0x2d2dfa[_0x65f6('0x10')]:_0x497cf3[_0x65f6('0xd')]+_0x497cf3[_0x65f6('0xe')];var _0x59154e;if(_0x44144b>=_0x2c4ee5){_0x44144b=_0x2c4ee5;_0x59154e=0xc8;}else{_0x59154e=0xce;}_0x571436[_0x65f6('0x11')](_0x59154e);return _0x571436['set']('Content-Range',_0x369f96+'-'+_0x44144b+'/'+_0x2c4ee5)[_0x65f6('0xc')](_0x2d2dfa);}return null;};}function saveUpdates(_0x5c69f8){return function(_0x37330d){if(_0x37330d){return _0x37330d[_0x65f6('0x12')](_0x5c69f8)[_0x65f6('0x13')](function(_0x1f974c){return _0x1f974c;});}return null;};}function removeEntity(_0xc8660c){return function(_0x18380e){if(_0x18380e){return _0x18380e['destroy']()['then'](function(){var _0x2d538c=_0x18380e['get']({'plain':!![]});var _0x4c81f3='SmsQueues';return db[_0x65f6('0x14')][_0x65f6('0x15')]({'where':{'type':_0x4c81f3,'resourceId':_0x2d538c['id']}})['then'](function(){return _0x18380e;});})[_0x65f6('0x13')](function(){_0xc8660c[_0x65f6('0x11')](0xcc)[_0x65f6('0xb')]();});}};}function handleEntityNotFound(_0x3876ed){return function(_0x219ab2){if(!_0x219ab2){_0x3876ed[_0x65f6('0x16')](0x194);}return _0x219ab2;};}function handleError(_0x581374,_0x197a49){_0x197a49=_0x197a49||0x1f4;return function(_0x4bb39e){logger['error'](_0x4bb39e[_0x65f6('0x17')]);if(_0x4bb39e[_0x65f6('0x18')]){delete _0x4bb39e['name'];}_0x581374[_0x65f6('0x11')](_0x197a49)[_0x65f6('0x19')](_0x4bb39e);};}exports[_0x65f6('0x1a')]=function(_0x2774a1,_0x4f5a69){var _0x9d7bb0={};var _0x59ea32={'count':0x0,'rows':[]};var _0x20a161=_['map'](db['SmsQueue']['rawAttributes'],function(_0x29abdb){return{'name':_0x29abdb[_0x65f6('0x1b')],'type':_0x29abdb['type'][_0x65f6('0x1c')]};});_0x9d7bb0=qs[_0x65f6('0x1d')](_0x20a161,_0x2774a1);var _0x52277c={'where':_0x9d7bb0[_0x65f6('0x1e')]};return db[_0x65f6('0x1f')][_0x65f6('0x10')](_0x52277c)['then'](function(_0x4ac04b){_0x59ea32['count']=_0x4ac04b;_0x9d7bb0[_0x65f6('0x20')]=qs[_0x65f6('0x20')](_0x2774a1[_0x65f6('0x21')]);return db[_0x65f6('0x1f')][_0x65f6('0x22')](_0x9d7bb0);})[_0x65f6('0x13')](function(_0x144e55){_0x59ea32['rows']=_0x144e55;return _0x59ea32;})['then'](respondWithFilteredResult(_0x4f5a69,_0x9d7bb0))[_0x65f6('0x23')](handleError(_0x4f5a69,null));};exports[_0x65f6('0x24')]=function(_0x5878bc,_0x4e50c0){var _0x10b368={'raw':!![],'where':{'id':_0x5878bc[_0x65f6('0x25')]['id']}},_0x1ce43c={};_0x1ce43c[_0x65f6('0x26')]=_[_0x65f6('0x27')](db[_0x65f6('0x1f')]['rawAttributes']);_0x1ce43c[_0x65f6('0x21')]=_[_0x65f6('0x27')](_0x5878bc[_0x65f6('0x21')]);_0x1ce43c['filters']=_[_0x65f6('0x28')](_0x1ce43c[_0x65f6('0x26')],_0x1ce43c[_0x65f6('0x21')]);_0x10b368[_0x65f6('0x29')]=_[_0x65f6('0x28')](_0x1ce43c[_0x65f6('0x26')],qs['fields'](_0x5878bc[_0x65f6('0x21')][_0x65f6('0x2a')]));_0x10b368['attributes']=_0x10b368[_0x65f6('0x29')]['length']?_0x10b368[_0x65f6('0x29')]:_0x1ce43c['model'];if(_0x5878bc[_0x65f6('0x21')][_0x65f6('0x2b')]){_0x10b368['include']=[{'all':!![]}];}_0x10b368=_[_0x65f6('0x2c')]({},_0x10b368,_0x5878bc[_0x65f6('0x2d')]);return db[_0x65f6('0x1f')]['find'](_0x10b368)['then'](handleEntityNotFound(_0x4e50c0,null))[_0x65f6('0x13')](respondWithResult(_0x4e50c0,null))['catch'](handleError(_0x4e50c0,null));};exports[_0x65f6('0x2e')]=function(_0x4e6653,_0x22d760){return db[_0x65f6('0x1f')]['create'](_0x4e6653[_0x65f6('0x2f')],{})['then'](function(_0x5edd04){var _0x71b16b=_0x4e6653[_0x65f6('0x30')][_0x65f6('0x31')]({'plain':!![]});if(!_0x71b16b)throw new Error(_0x65f6('0x32'));if(_0x71b16b[_0x65f6('0x33')]===_0x65f6('0x30')){var _0x1a55da=_0x5edd04[_0x65f6('0x31')]({'plain':!![]});var _0x4f933b=_0x65f6('0x34');return db['UserProfileSection'][_0x65f6('0x35')]({'where':{'name':_0x4f933b,'userProfileId':_0x71b16b[_0x65f6('0x36')]},'raw':!![]})[_0x65f6('0x13')](function(_0x2ea7f7){if(_0x2ea7f7&&_0x2ea7f7['autoAssociation']===0x0){return db[_0x65f6('0x14')][_0x65f6('0x2e')]({'name':_0x1a55da[_0x65f6('0x18')],'resourceId':_0x1a55da['id'],'type':_0x2ea7f7[_0x65f6('0x18')],'sectionId':_0x2ea7f7['id']},{})[_0x65f6('0x13')](function(){return _0x5edd04;});}else{return _0x5edd04;}})[_0x65f6('0x23')](function(_0xed4c96){logger[_0x65f6('0x37')](_0x65f6('0x38'),_0xed4c96);throw _0xed4c96;});}return _0x5edd04;})['then'](respondWithResult(_0x22d760,0xc9))[_0x65f6('0x23')](handleError(_0x22d760,null));};exports[_0x65f6('0x12')]=function(_0x377ae5,_0x181798){if(_0x377ae5[_0x65f6('0x2f')]['id']){delete _0x377ae5[_0x65f6('0x2f')]['id'];}return db[_0x65f6('0x1f')][_0x65f6('0x35')]({'where':{'id':_0x377ae5[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x181798,null))[_0x65f6('0x13')](saveUpdates(_0x377ae5[_0x65f6('0x2f')],null))[_0x65f6('0x13')](respondWithResult(_0x181798,null))[_0x65f6('0x23')](handleError(_0x181798,null));};exports[_0x65f6('0x15')]=function(_0x2cb38d,_0x5119ee){return db[_0x65f6('0x1f')][_0x65f6('0x35')]({'where':{'id':_0x2cb38d[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x5119ee,null))['then'](removeEntity(_0x5119ee,null))[_0x65f6('0x23')](handleError(_0x5119ee,null));};exports[_0x65f6('0x39')]=function(_0x2b01eb,_0x5e69b4){return db[_0x65f6('0x1f')][_0x65f6('0x39')]()[_0x65f6('0x13')](respondWithResult(_0x5e69b4,null))[_0x65f6('0x23')](handleError(_0x5e69b4,null));};exports['getMembers']=function(_0x2ec114,_0x512527){var _0x3f1baa={'raw':!![],'where':{}},_0x6968b={},_0x577c93;return db[_0x65f6('0x1f')]['findOne']({'where':{'id':_0x2ec114[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x512527,null))[_0x65f6('0x13')](function(_0xc0db01){if(_0xc0db01){_0x577c93=_0xc0db01[_0x65f6('0x31')]({'plain':!![]});_0x6968b[_0x65f6('0x26')]=_['keys'](db['UserSmsQueue'][_0x65f6('0x3a')]);_0x6968b[_0x65f6('0x21')]=_[_0x65f6('0x27')](_0x2ec114[_0x65f6('0x21')]);_0x6968b[_0x65f6('0x3b')]=_[_0x65f6('0x28')](_0x6968b[_0x65f6('0x26')],_0x6968b[_0x65f6('0x21')]);_0x3f1baa[_0x65f6('0x29')]=_['intersection'](_0x6968b[_0x65f6('0x26')],qs[_0x65f6('0x2a')](_0x2ec114[_0x65f6('0x21')]['fields']));_0x3f1baa[_0x65f6('0x29')]=_0x3f1baa[_0x65f6('0x29')]['length']?_0x3f1baa[_0x65f6('0x29')]:_0x6968b[_0x65f6('0x26')];if(!_0x2ec114['query'][_0x65f6('0x3c')]('nolimit')){_0x3f1baa[_0x65f6('0xe')]=qs[_0x65f6('0xe')](_0x2ec114[_0x65f6('0x21')]['limit']);_0x3f1baa[_0x65f6('0xd')]=qs[_0x65f6('0xd')](_0x2ec114['query'][_0x65f6('0xd')]);}_0x3f1baa[_0x65f6('0x3d')]=qs['sort'](_0x2ec114[_0x65f6('0x21')][_0x65f6('0x3e')]);_0x3f1baa[_0x65f6('0x1e')]=qs[_0x65f6('0x3b')](_[_0x65f6('0x3f')](_0x2ec114[_0x65f6('0x21')],_0x6968b[_0x65f6('0x3b')]));_0x3f1baa[_0x65f6('0x1e')]['SmsQueueId']=_0xc0db01['id'];if(_0x2ec114['query']['filter']){_0x3f1baa[_0x65f6('0x1e')]=_[_0x65f6('0x2c')](_0x3f1baa[_0x65f6('0x1e')],{'$or':_[_0x65f6('0x40')](_0x3f1baa['attributes'],function(_0x183c08){var _0x2032b9={};_0x2032b9[_0x183c08]={'$like':'%'+_0x2ec114[_0x65f6('0x21')]['filter']+'%'};return _0x2032b9;})});}_0x3f1baa=_[_0x65f6('0x2c')]({},_0x3f1baa,_0x2ec114[_0x65f6('0x2d')]);return db[_0x65f6('0x41')]['findAll'](_0x3f1baa);}})['then'](function(_0x1d337d){if(_0x1d337d){return db[_0x65f6('0x42')][_0x65f6('0x43')]({'where':{'id':_[_0x65f6('0x40')](_0x1d337d,_0x65f6('0x44')),'role':_0x65f6('0x45')},'attributes':['id',_0x65f6('0x18'),_0x65f6('0x46'),_0x65f6('0x47'),_0x65f6('0x48')]});}})[_0x65f6('0x13')](function(_0x141fcc){if(_0x141fcc){return{'count':_0x141fcc[_0x65f6('0x10')],'rows':_[_0x65f6('0x40')](_0x141fcc['rows'],function(_0x47610a){return{'membername':_0x47610a[_0x65f6('0x18')],'UserId':_0x47610a['id'],'queue_name':_0x577c93[_0x65f6('0x18')],'SmsQueueId':_0x577c93['id'],'interface':util['format'](_0x65f6('0x49'),_0x65f6('0x4a'),_0x47610a[_0x65f6('0x18')]),'penalty':0x0,'paused':_0x47610a[_0x65f6('0x46')],'createdAt':_0x47610a['createdAt'],'updatedAt':_0x47610a[_0x65f6('0x47')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x65f6('0x13')](respondWithFilteredResult(_0x512527,_0x3f1baa))[_0x65f6('0x23')](handleError(_0x512527,null));};exports[_0x65f6('0x4b')]=function(_0x553ff0,_0x2923ff){var _0x2fc20f={};var _0x5c55e4={};var _0x28682b;var _0x26481e;return db[_0x65f6('0x1f')]['findOne']({'where':{'id':_0x553ff0[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x2923ff,null))[_0x65f6('0x13')](function(_0x3c23e3){if(_0x3c23e3){_0x28682b=_0x3c23e3;_0x5c55e4[_0x65f6('0x26')]=_[_0x65f6('0x27')](db['Team']['rawAttributes']);_0x5c55e4['query']=_[_0x65f6('0x27')](_0x553ff0[_0x65f6('0x21')]);_0x5c55e4[_0x65f6('0x3b')]=_[_0x65f6('0x28')](_0x5c55e4[_0x65f6('0x26')],_0x5c55e4[_0x65f6('0x21')]);_0x2fc20f['attributes']=_[_0x65f6('0x28')](_0x5c55e4[_0x65f6('0x26')],qs['fields'](_0x553ff0[_0x65f6('0x21')][_0x65f6('0x2a')]));_0x2fc20f[_0x65f6('0x29')]=_0x2fc20f['attributes'][_0x65f6('0x4c')]?_0x2fc20f[_0x65f6('0x29')]:_0x5c55e4['model'];_0x2fc20f[_0x65f6('0x3d')]=qs[_0x65f6('0x3e')](_0x553ff0[_0x65f6('0x21')][_0x65f6('0x3e')]);_0x2fc20f[_0x65f6('0x1e')]=qs[_0x65f6('0x3b')](_[_0x65f6('0x3f')](_0x553ff0['query'],_0x5c55e4['filters']));if(_0x553ff0[_0x65f6('0x21')][_0x65f6('0x4d')]){_0x2fc20f['where']=_[_0x65f6('0x2c')](_0x2fc20f['where'],{'$or':_[_0x65f6('0x40')](_0x2fc20f['attributes'],function(_0x440df1){var _0xdc8989={};_0xdc8989[_0x440df1]={'$like':'%'+_0x553ff0[_0x65f6('0x21')][_0x65f6('0x4d')]+'%'};return _0xdc8989;})});}_0x2fc20f=_[_0x65f6('0x2c')]({},_0x2fc20f,_0x553ff0[_0x65f6('0x2d')]);return _0x28682b[_0x65f6('0x4b')](_0x2fc20f);}})[_0x65f6('0x13')](function(_0x2405a7){if(_0x2405a7){_0x26481e=_0x2405a7['length'];if(!_0x553ff0['query'][_0x65f6('0x3c')](_0x65f6('0x4e'))){_0x2fc20f[_0x65f6('0xe')]=qs['limit'](_0x553ff0['query'][_0x65f6('0xe')]);_0x2fc20f[_0x65f6('0xd')]=qs[_0x65f6('0xd')](_0x553ff0[_0x65f6('0x21')][_0x65f6('0xd')]);}return _0x28682b[_0x65f6('0x4b')](_0x2fc20f);}})['then'](function(_0x4f42ae){if(_0x4f42ae){return _0x4f42ae?{'count':_0x26481e,'rows':_0x4f42ae}:null;}})[_0x65f6('0x13')](respondWithResult(_0x2923ff,null))[_0x65f6('0x23')](handleError(_0x2923ff,null));};exports['addTeams']=function(_0x219bf8,_0x4a8b60){var _0x254e9f=_0x219bf8[_0x65f6('0x2f')][_0x65f6('0x4f')];return db[_0x65f6('0x50')]['findAll']({'where':{'id':_0x254e9f},'attributes':['id'],'include':[{'model':db[_0x65f6('0x42')],'as':_0x65f6('0x51'),'attributes':['id',_0x65f6('0x18'),'online','voicePause',_0x65f6('0x52')],'raw':!![]}]})['then'](function(_0x305967){if(_0x305967){var _0xf6de=_[_0x65f6('0x53')](_0x305967,function(_0x354b90){var _0x512776=_0x354b90['get']({'plain':!![]});return _0x512776['Agents'];});return db[_0x65f6('0x1f')][_0x65f6('0x35')]({'where':{'id':_0x219bf8[_0x65f6('0x25')]['id']}})['then'](function(_0x46cbde){return db[_0x65f6('0x54')][_0x65f6('0x55')](function(_0x49cee2){return _0x46cbde[_0x65f6('0x56')](_0x254e9f,{'transaction':_0x49cee2})[_0x65f6('0x13')](function(){return BPromise['each'](_0xf6de,function(_0x758e80){return db[_0x65f6('0x41')]['findOrCreate']({'where':{'UserId':_0x758e80['id'],'SmsQueueId':_0x219bf8[_0x65f6('0x25')]['id']},'transaction':_0x49cee2});});})['then'](function(){_0xf6de[_0x65f6('0x57')](function(_0x55ea91){socket[_0x65f6('0x58')](_0x65f6('0x59'),{'UserId':_0x55ea91['id'],'SmsQueueId':_0x46cbde['id']});});});});});}})['then'](respondWithStatusCode(_0x4a8b60,null))[_0x65f6('0x23')](handleError(_0x4a8b60,null));};exports[_0x65f6('0x5a')]=function(_0x2a700b,_0x299b85){return db[_0x65f6('0x50')][_0x65f6('0x22')]({'where':{'id':_0x2a700b[_0x65f6('0x21')][_0x65f6('0x4f')]},'attributes':['id'],'include':[{'model':db[_0x65f6('0x42')],'as':_0x65f6('0x51'),'attributes':['id'],'raw':!![]}]})[_0x65f6('0x13')](handleEntityNotFound(_0x299b85,null))['then'](function(_0x10a661){var _0x1cf1bd=_[_0x65f6('0x40')](_0x10a661,'id');var _0x219e42=[];var _0x5694f9=[];var _0x453080=squel[_0x65f6('0x5b')]();_0x453080['field'](_0x65f6('0x5c'))['from'](_0x65f6('0x5d'),'tq')['join'](_0x65f6('0x5e'),'ut',_0x65f6('0x5f'))['where']('SmsQueueId\x20=\x20?',_0x2a700b[_0x65f6('0x25')]['id']);for(var _0x413c21=0x0;_0x413c21<_0x10a661['length'];_0x413c21+=0x1){let _0x2d86c8=_0x10a661[_0x413c21];for(var _0x3b3bd5=0x0;_0x3b3bd5<_0x2d86c8[_0x65f6('0x51')]['length'];_0x3b3bd5+=0x1){let _0x1348ec=_0x2d86c8[_0x65f6('0x51')][_0x3b3bd5];var _0x5889dc=_0x453080[_0x65f6('0x60')]();_0x5889dc['where'](_0x65f6('0x61'),_0x1348ec['id']);_0x5694f9['push'](db['sequelize'][_0x65f6('0x21')](_0x5889dc[_0x65f6('0x62')](),{'type':db[_0x65f6('0x54')][_0x65f6('0x63')][_0x65f6('0x64')]})[_0x65f6('0x13')](function(_0x1ac46f){if(_0x1ac46f[_0x65f6('0x4c')]===0x1){return _0x1348ec['id'];}else{var _0x4d66fe=_['every'](_[_0x65f6('0x40')](_0x1ac46f,'TeamId'),function(_0x1ee28a){return _[_0x65f6('0x65')](_0x1cf1bd,_0x1ee28a);});if(_0x4d66fe){return _0x1348ec['id'];}}}));}}return BPromise[_0x65f6('0x66')](_0x5694f9)[_0x65f6('0x13')](function(_0x43127b){_0x219e42=_(_0x219e42)['union'](_0x43127b)[_0x65f6('0x67')]()[_0x65f6('0x68')]();return db[_0x65f6('0x1f')]['find']({'where':{'id':_0x2a700b[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](function(_0x4254c2){return db[_0x65f6('0x54')][_0x65f6('0x55')](function(_0x16bf93){return _0x4254c2['removeTeams'](_0x2a700b['query'][_0x65f6('0x4f')],{'transaction':_0x16bf93})[_0x65f6('0x13')](function(){if(!_[_0x65f6('0x69')](_0x219e42)){return _0x4254c2[_0x65f6('0x6a')](_0x219e42,{'transaction':_0x16bf93});}})['then'](function(){_0x219e42['forEach'](function(_0x336076){socket[_0x65f6('0x58')](_0x65f6('0x6b'),{'UserId':_0x336076,'SmsQueueId':_0x4254c2['id']});});});});});});})[_0x65f6('0x13')](respondWithStatusCode(_0x299b85,null))[_0x65f6('0x23')](handleError(_0x299b85,null));};exports[_0x65f6('0x6c')]=function(_0x5daaf4,_0x4d607a){return db['SmsQueue'][_0x65f6('0x35')]({'where':{'id':_0x5daaf4[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x4d607a,null))[_0x65f6('0x13')](function(_0x53b11c){if(_0x53b11c){return _0x53b11c['addAgents'](_0x5daaf4[_0x65f6('0x2f')][_0x65f6('0x4f')],_['omit'](_0x5daaf4[_0x65f6('0x2f')],['ids','id'])||{})[_0x65f6('0x6d')](function(_0x4f3ef8){for(var _0x3a30ed=0x0;_0x3a30ed<_0x5daaf4[_0x65f6('0x2f')]['ids'][_0x65f6('0x4c')];_0x3a30ed+=0x1){socket[_0x65f6('0x58')](_0x65f6('0x59'),{'UserId':Number(_0x5daaf4[_0x65f6('0x2f')][_0x65f6('0x4f')][_0x3a30ed]),'SmsQueueId':Number(_0x5daaf4[_0x65f6('0x25')]['id'])});}return _0x4f3ef8;});}})['then'](respondWithResult(_0x4d607a,null))[_0x65f6('0x23')](handleError(_0x4d607a,null));};exports['removeAgents']=function(_0x24495c,_0x56336a){return db[_0x65f6('0x1f')][_0x65f6('0x35')]({'where':{'id':_0x24495c[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x56336a,null))['then'](function(_0x2b6f98){if(_0x2b6f98){return _0x2b6f98[_0x65f6('0x6a')](_0x24495c[_0x65f6('0x21')]['ids'])['then'](function(){if(_[_0x65f6('0x6e')](_0x24495c[_0x65f6('0x21')]['ids'])){for(var _0x180cde=0x0;_0x180cde<_0x24495c[_0x65f6('0x21')][_0x65f6('0x4f')]['length'];_0x180cde+=0x1){socket[_0x65f6('0x58')](_0x65f6('0x6b'),{'UserId':Number(_0x24495c['query'][_0x65f6('0x4f')][_0x180cde]),'SmsQueueId':Number(_0x24495c[_0x65f6('0x25')]['id'])});}}else{socket[_0x65f6('0x58')]('userSmsQueue:remove',{'UserId':Number(_0x24495c[_0x65f6('0x21')][_0x65f6('0x4f')]),'SmsQueueId':Number(_0x24495c[_0x65f6('0x25')]['id'])});}});}})['then'](respondWithStatusCode(_0x56336a,null))[_0x65f6('0x23')](handleError(_0x56336a,null));};exports['getAgents']=function(_0x1beaa7,_0x87a9e4){var _0x31ec61={};var _0x22be6e={};var _0x29b2de;var _0x430fb8;return db['SmsQueue'][_0x65f6('0x6f')]({'where':{'id':_0x1beaa7[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x87a9e4,null))[_0x65f6('0x13')](function(_0x207d15){if(_0x207d15){_0x29b2de=_0x207d15;_0x22be6e['model']=_['keys'](db['User'][_0x65f6('0x3a')]);_0x22be6e[_0x65f6('0x21')]=_[_0x65f6('0x27')](_0x1beaa7['query']);_0x22be6e[_0x65f6('0x3b')]=_['intersection'](_0x22be6e['model'],_0x22be6e[_0x65f6('0x21')]);_0x31ec61[_0x65f6('0x29')]=_['intersection'](_0x22be6e[_0x65f6('0x26')],qs[_0x65f6('0x2a')](_0x1beaa7[_0x65f6('0x21')][_0x65f6('0x2a')]));_0x31ec61[_0x65f6('0x29')]=_0x31ec61[_0x65f6('0x29')][_0x65f6('0x4c')]?_0x31ec61[_0x65f6('0x29')]:_0x22be6e[_0x65f6('0x26')];_0x31ec61[_0x65f6('0x3d')]=qs[_0x65f6('0x3e')](_0x1beaa7[_0x65f6('0x21')]['sort']);_0x31ec61[_0x65f6('0x1e')]=qs['filters'](_['pick'](_0x1beaa7[_0x65f6('0x21')],_0x22be6e[_0x65f6('0x3b')]));if(_0x1beaa7[_0x65f6('0x21')][_0x65f6('0x4d')]){_0x31ec61['where']=_[_0x65f6('0x2c')](_0x31ec61['where'],{'$or':_['map'](_0x31ec61[_0x65f6('0x29')],function(_0x99fe6e){var _0x1a7e52={};_0x1a7e52[_0x99fe6e]={'$like':'%'+_0x1beaa7[_0x65f6('0x21')][_0x65f6('0x4d')]+'%'};return _0x1a7e52;})});}_0x31ec61=_[_0x65f6('0x2c')]({},_0x31ec61,_0x1beaa7['options']);return _0x29b2de[_0x65f6('0x70')](_0x31ec61);}})['then'](function(_0x1ef2a0){if(_0x1ef2a0){_0x430fb8=_0x1ef2a0[_0x65f6('0x4c')];if(!_0x1beaa7[_0x65f6('0x21')]['hasOwnProperty'](_0x65f6('0x4e'))){_0x31ec61['limit']=qs['limit'](_0x1beaa7[_0x65f6('0x21')][_0x65f6('0xe')]);_0x31ec61[_0x65f6('0xd')]=qs[_0x65f6('0xd')](_0x1beaa7[_0x65f6('0x21')]['offset']);}return _0x29b2de[_0x65f6('0x70')](_0x31ec61);}})[_0x65f6('0x13')](function(_0x3bebe3){if(_0x3bebe3){return _0x3bebe3?{'count':_0x430fb8,'rows':_0x3bebe3}:null;}})[_0x65f6('0x13')](respondWithResult(_0x87a9e4,null))['catch'](handleError(_0x87a9e4,null));};
\ No newline at end of file