Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / smsQueue / smsQueue.controller.js
index a2556b7..c998908 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x171b=['get','SmsQueues','UserProfileResource','destroy','sendStatus','stack','name','send','index','map','SmsQueue','rawAttributes','fieldName','type','key','model','query','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','include','rows','catch','show','keys','length','includeAll','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','getMembers','findOne','SmsQueueId','findAll','User','UserId','agent','updatedAt','format','%s/%s','SIP','smsPause','Team','getTeams','addTeams','ids','Agents','online','interface','sequelize','each','UserSmsQueue','findOrCreate','userSmsQueue:save','removeTeams','select','field','tq.TeamId','from','team_has_sms_queues','join','ut.TeamId\x20=\x20tq.TeamId','SmsQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','includes','all','union','compact','value','isEmpty','forEach','userSmsQueue:remove','omit','spread','removeAgents','isArray','emit','getAgents','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','path','to-csv','lodash','squel','crypto','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','./smsQueue.socket','register','status','end','json','offset','undefined','count','limit','Content-Range','apply','reject','save','update','then'];(function(_0x5be745,_0x190739){var _0x39eac8=function(_0x4ff4bb){while(--_0x4ff4bb){_0x5be745['push'](_0x5be745['shift']());}};_0x39eac8(++_0x190739);}(_0x171b,0xf8));var _0xb171=function(_0x2ddca0,_0x5903da){_0x2ddca0=_0x2ddca0-0x0;var _0x2178e1=_0x171b[_0x2ddca0];return _0x2178e1;};'use strict';var emlformat=require(_0xb171('0x0'));var rimraf=require(_0xb171('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb171('0x2'));var rp=require(_0xb171('0x3'));var moment=require(_0xb171('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xb171('0x5'));var util=require('util');var path=require(_0xb171('0x6'));var sox=require('sox');var csv=require(_0xb171('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xb171('0x8'));var squel=require(_0xb171('0x9'));var crypto=require(_0xb171('0xa'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xb171('0x7'));var querystring=require(_0xb171('0xb'));var Papa=require('papaparse');var Redis=require(_0xb171('0xc'));var authService=require(_0xb171('0xd'));var qs=require(_0xb171('0xe'));var as=require(_0xb171('0xf'));var hardwareService=require(_0xb171('0x10'));var logger=require(_0xb171('0x11'))(_0xb171('0x12'));var utils=require(_0xb171('0x13'));var config=require(_0xb171('0x14'));var licenseUtil=require(_0xb171('0x15'));var db=require(_0xb171('0x16'))['db'];config[_0xb171('0x17')]=_[_0xb171('0x18')](config[_0xb171('0x17')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb171('0x17')]));require(_0xb171('0x19'))[_0xb171('0x1a')](socket);function respondWithStatusCode(_0x2f425d,_0x32593b){_0x32593b=_0x32593b||0xcc;return function(_0x3262a4){if(_0x3262a4){return _0x2f425d['sendStatus'](_0x32593b);}return _0x2f425d[_0xb171('0x1b')](_0x32593b)[_0xb171('0x1c')]();};}function respondWithResult(_0x178662,_0x1ba00f){_0x1ba00f=_0x1ba00f||0xc8;return function(_0x34a26b){if(_0x34a26b){return _0x178662[_0xb171('0x1b')](_0x1ba00f)[_0xb171('0x1d')](_0x34a26b);}};}function respondWithFilteredResult(_0x4e5f11,_0x80a94c){return function(_0x2b9c73){if(_0x2b9c73){var _0xd0ceb=typeof _0x80a94c[_0xb171('0x1e')]===_0xb171('0x1f')&&typeof _0x80a94c['limit']==='undefined';var _0x12c86b=_0x2b9c73['count'];var _0x36e2cf=_0xd0ceb?0x0:_0x80a94c[_0xb171('0x1e')];var _0x4ca843=_0xd0ceb?_0x2b9c73[_0xb171('0x20')]:_0x80a94c[_0xb171('0x1e')]+_0x80a94c[_0xb171('0x21')];var _0x20dfcb;if(_0x4ca843>=_0x12c86b){_0x4ca843=_0x12c86b;_0x20dfcb=0xc8;}else{_0x20dfcb=0xce;}_0x4e5f11['status'](_0x20dfcb);return _0x4e5f11['set'](_0xb171('0x22'),_0x36e2cf+'-'+_0x4ca843+'/'+_0x12c86b)[_0xb171('0x1d')](_0x2b9c73);}return null;};}function patchUpdates(_0x40d599){return function(_0x295677){try{jsonpatch[_0xb171('0x23')](_0x295677,_0x40d599,!![]);}catch(_0x3e0aee){return BPromise[_0xb171('0x24')](_0x3e0aee);}return _0x295677[_0xb171('0x25')]();};}function saveUpdates(_0xb026f8,_0x5d571e){return function(_0x57f7b8){if(_0x57f7b8){return _0x57f7b8[_0xb171('0x26')](_0xb026f8)[_0xb171('0x27')](function(_0x3bb529){return _0x3bb529;});}return null;};}function removeEntity(_0x31d65a,_0x3dd24b){return function(_0x2e66a5){if(_0x2e66a5){return _0x2e66a5['destroy']()[_0xb171('0x27')](function(){var _0x5a59a2=_0x2e66a5[_0xb171('0x28')]({'plain':!![]});var _0x51f109=_0xb171('0x29');return db[_0xb171('0x2a')][_0xb171('0x2b')]({'where':{'type':_0x51f109,'resourceId':_0x5a59a2['id']}})['then'](function(){return _0x2e66a5;});})[_0xb171('0x27')](function(){_0x31d65a['status'](0xcc)[_0xb171('0x1c')]();});}};}function handleEntityNotFound(_0x1c60dd,_0x39ea32){return function(_0x2631d9){if(!_0x2631d9){_0x1c60dd[_0xb171('0x2c')](0x194);}return _0x2631d9;};}function handleError(_0xa11c53,_0x310c97){_0x310c97=_0x310c97||0x1f4;return function(_0x584ec1){logger['error'](_0x584ec1[_0xb171('0x2d')]);if(_0x584ec1[_0xb171('0x2e')]){delete _0x584ec1[_0xb171('0x2e')];}_0xa11c53[_0xb171('0x1b')](_0x310c97)[_0xb171('0x2f')](_0x584ec1);};}exports[_0xb171('0x30')]=function(_0x4ab36a,_0x308b39){var _0x2c1f04={},_0x14b8e4={},_0x4a4b02={'count':0x0,'rows':[]};var _0x2d3ae7=_[_0xb171('0x31')](db[_0xb171('0x32')][_0xb171('0x33')],function(_0x22d137){return{'name':_0x22d137[_0xb171('0x34')],'type':_0x22d137[_0xb171('0x35')][_0xb171('0x36')]};});_0x14b8e4[_0xb171('0x37')]=_[_0xb171('0x31')](_0x2d3ae7,_0xb171('0x2e'));_0x14b8e4[_0xb171('0x38')]=_['keys'](_0x4ab36a[_0xb171('0x38')]);_0x14b8e4['filters']=_[_0xb171('0x39')](_0x14b8e4['model'],_0x14b8e4[_0xb171('0x38')]);_0x2c1f04[_0xb171('0x3a')]=_[_0xb171('0x39')](_0x14b8e4[_0xb171('0x37')],qs['fields'](_0x4ab36a[_0xb171('0x38')][_0xb171('0x3b')]));_0x2c1f04[_0xb171('0x3a')]=_0x2c1f04[_0xb171('0x3a')]['length']?_0x2c1f04['attributes']:_0x14b8e4['model'];if(!_0x4ab36a[_0xb171('0x38')][_0xb171('0x3c')](_0xb171('0x3d'))){_0x2c1f04[_0xb171('0x21')]=qs[_0xb171('0x21')](_0x4ab36a[_0xb171('0x38')][_0xb171('0x21')]);_0x2c1f04[_0xb171('0x1e')]=qs[_0xb171('0x1e')](_0x4ab36a['query']['offset']);}_0x2c1f04[_0xb171('0x3e')]=qs[_0xb171('0x3f')](_0x4ab36a[_0xb171('0x38')][_0xb171('0x3f')]);_0x2c1f04[_0xb171('0x40')]=qs['filters'](_[_0xb171('0x41')](_0x4ab36a['query'],_0x14b8e4[_0xb171('0x42')]),_0x2d3ae7);if(_0x4ab36a['query'][_0xb171('0x43')]){_0x2c1f04[_0xb171('0x40')]=_[_0xb171('0x44')](_0x2c1f04[_0xb171('0x40')],{'$or':_[_0xb171('0x31')](_0x2d3ae7,function(_0x277a89){if(_0x277a89[_0xb171('0x35')]!==_0xb171('0x45')){var _0x464580={};_0x464580[_0x277a89['name']]={'$like':'%'+_0x4ab36a[_0xb171('0x38')][_0xb171('0x43')]+'%'};return _0x464580;}})});}_0x2c1f04=_[_0xb171('0x44')]({},_0x2c1f04,_0x4ab36a[_0xb171('0x46')]);var _0x3b8905={'where':_0x2c1f04[_0xb171('0x40')]};return db['SmsQueue'][_0xb171('0x20')](_0x3b8905)[_0xb171('0x27')](function(_0x45f28e){_0x4a4b02[_0xb171('0x20')]=_0x45f28e;if(_0x4ab36a[_0xb171('0x38')]['includeAll']){_0x2c1f04[_0xb171('0x47')]=[{'all':!![]}];}return db[_0xb171('0x32')]['findAll'](_0x2c1f04);})['then'](function(_0x28e08d){_0x4a4b02[_0xb171('0x48')]=_0x28e08d;return _0x4a4b02;})['then'](respondWithFilteredResult(_0x308b39,_0x2c1f04))[_0xb171('0x49')](handleError(_0x308b39,null));};exports[_0xb171('0x4a')]=function(_0x540c1d,_0x564097){var _0x1f59d0={'raw':!![],'where':{'id':_0x540c1d['params']['id']}},_0x282e45={};_0x282e45[_0xb171('0x37')]=_[_0xb171('0x4b')](db[_0xb171('0x32')][_0xb171('0x33')]);_0x282e45[_0xb171('0x38')]=_[_0xb171('0x4b')](_0x540c1d['query']);_0x282e45[_0xb171('0x42')]=_['intersection'](_0x282e45[_0xb171('0x37')],_0x282e45[_0xb171('0x38')]);_0x1f59d0['attributes']=_[_0xb171('0x39')](_0x282e45[_0xb171('0x37')],qs['fields'](_0x540c1d[_0xb171('0x38')]['fields']));_0x1f59d0[_0xb171('0x3a')]=_0x1f59d0[_0xb171('0x3a')][_0xb171('0x4c')]?_0x1f59d0[_0xb171('0x3a')]:_0x282e45[_0xb171('0x37')];if(_0x540c1d[_0xb171('0x38')][_0xb171('0x4d')]){_0x1f59d0[_0xb171('0x47')]=[{'all':!![]}];}_0x1f59d0=_[_0xb171('0x44')]({},_0x1f59d0,_0x540c1d[_0xb171('0x46')]);return db[_0xb171('0x32')][_0xb171('0x4e')](_0x1f59d0)['then'](handleEntityNotFound(_0x564097,null))[_0xb171('0x27')](respondWithResult(_0x564097,null))[_0xb171('0x49')](handleError(_0x564097,null));};exports[_0xb171('0x4f')]=function(_0xd3ecd,_0x864992){return db[_0xb171('0x32')][_0xb171('0x4f')](_0xd3ecd[_0xb171('0x50')],{})['then'](function(_0x608cb1){var _0x414d7b=_0xd3ecd[_0xb171('0x51')]['get']({'plain':!![]});if(!_0x414d7b)throw new Error(_0xb171('0x52'));if(_0x414d7b[_0xb171('0x53')]===_0xb171('0x51')){var _0x623516=_0x608cb1[_0xb171('0x28')]({'plain':!![]});var _0x335cc5='SmsQueues';return db[_0xb171('0x54')][_0xb171('0x4e')]({'where':{'name':_0x335cc5,'userProfileId':_0x414d7b[_0xb171('0x55')]},'raw':!![]})[_0xb171('0x27')](function(_0x1b107f){if(_0x1b107f&&_0x1b107f['autoAssociation']===0x0){return db[_0xb171('0x2a')][_0xb171('0x4f')]({'name':_0x623516[_0xb171('0x2e')],'resourceId':_0x623516['id'],'type':_0x1b107f[_0xb171('0x2e')],'sectionId':_0x1b107f['id']},{})[_0xb171('0x27')](function(){return _0x608cb1;});}else{return _0x608cb1;}})['catch'](function(_0x1b3d19){logger[_0xb171('0x56')](_0xb171('0x57'),_0x1b3d19);throw _0x1b3d19;});}return _0x608cb1;})['then'](respondWithResult(_0x864992,0xc9))['catch'](handleError(_0x864992,null));};exports[_0xb171('0x26')]=function(_0xc59acc,_0x396889){if(_0xc59acc[_0xb171('0x50')]['id']){delete _0xc59acc[_0xb171('0x50')]['id'];}return db[_0xb171('0x32')]['find']({'where':{'id':_0xc59acc['params']['id']}})[_0xb171('0x27')](handleEntityNotFound(_0x396889,null))['then'](saveUpdates(_0xc59acc[_0xb171('0x50')],null))[_0xb171('0x27')](respondWithResult(_0x396889,null))['catch'](handleError(_0x396889,null));};exports[_0xb171('0x2b')]=function(_0x30a7e7,_0x2a2862){return db['SmsQueue'][_0xb171('0x4e')]({'where':{'id':_0x30a7e7[_0xb171('0x58')]['id']}})[_0xb171('0x27')](handleEntityNotFound(_0x2a2862,null))[_0xb171('0x27')](removeEntity(_0x2a2862,null))[_0xb171('0x49')](handleError(_0x2a2862,null));};exports[_0xb171('0x59')]=function(_0x2b6a41,_0x2437ae){return db[_0xb171('0x32')][_0xb171('0x59')]()[_0xb171('0x27')](respondWithResult(_0x2437ae,null))[_0xb171('0x49')](handleError(_0x2437ae,null));};exports[_0xb171('0x5a')]=function(_0x4e38eb,_0xb06d1e,_0x4c6997){var _0x37adb5={'raw':!![],'where':{}},_0x1eb076={},_0x200168;return db[_0xb171('0x32')][_0xb171('0x5b')]({'where':{'id':_0x4e38eb[_0xb171('0x58')]['id']}})[_0xb171('0x27')](handleEntityNotFound(_0xb06d1e,null))[_0xb171('0x27')](function(_0x36026e){if(_0x36026e){_0x200168=_0x36026e[_0xb171('0x28')]({'plain':!![]});_0x1eb076[_0xb171('0x37')]=_[_0xb171('0x4b')](db['UserSmsQueue']['rawAttributes']);_0x1eb076[_0xb171('0x38')]=_['keys'](_0x4e38eb[_0xb171('0x38')]);_0x1eb076[_0xb171('0x42')]=_[_0xb171('0x39')](_0x1eb076['model'],_0x1eb076[_0xb171('0x38')]);_0x37adb5['attributes']=_[_0xb171('0x39')](_0x1eb076[_0xb171('0x37')],qs[_0xb171('0x3b')](_0x4e38eb[_0xb171('0x38')][_0xb171('0x3b')]));_0x37adb5[_0xb171('0x3a')]=_0x37adb5[_0xb171('0x3a')][_0xb171('0x4c')]?_0x37adb5[_0xb171('0x3a')]:_0x1eb076[_0xb171('0x37')];if(!_0x4e38eb[_0xb171('0x38')][_0xb171('0x3c')](_0xb171('0x3d'))){_0x37adb5[_0xb171('0x21')]=qs[_0xb171('0x21')](_0x4e38eb[_0xb171('0x38')][_0xb171('0x21')]);_0x37adb5['offset']=qs[_0xb171('0x1e')](_0x4e38eb[_0xb171('0x38')][_0xb171('0x1e')]);}_0x37adb5['order']=qs[_0xb171('0x3f')](_0x4e38eb[_0xb171('0x38')][_0xb171('0x3f')]);_0x37adb5['where']=qs[_0xb171('0x42')](_[_0xb171('0x41')](_0x4e38eb[_0xb171('0x38')],_0x1eb076['filters']));_0x37adb5[_0xb171('0x40')][_0xb171('0x5c')]=_0x36026e['id'];if(_0x4e38eb['query']['filter']){_0x37adb5[_0xb171('0x40')]=_[_0xb171('0x44')](_0x37adb5['where'],{'$or':_[_0xb171('0x31')](_0x37adb5[_0xb171('0x3a')],function(_0x3e1c27){var _0x874efc={};_0x874efc[_0x3e1c27]={'$like':'%'+_0x4e38eb[_0xb171('0x38')][_0xb171('0x43')]+'%'};return _0x874efc;})});}_0x37adb5=_[_0xb171('0x44')]({},_0x37adb5,_0x4e38eb[_0xb171('0x46')]);return db['UserSmsQueue'][_0xb171('0x5d')](_0x37adb5);}})[_0xb171('0x27')](function(_0x117a37){if(_0x117a37){return db[_0xb171('0x5e')]['findAndCountAll']({'where':{'id':_['map'](_0x117a37,_0xb171('0x5f')),'role':_0xb171('0x60')},'attributes':['id',_0xb171('0x2e'),'smsPause',_0xb171('0x61'),'createdAt']});}})['then'](function(_0x53940c){if(_0x53940c){return{'count':_0x53940c['count'],'rows':_['map'](_0x53940c[_0xb171('0x48')],function(_0x57b137){return{'membername':_0x57b137[_0xb171('0x2e')],'UserId':_0x57b137['id'],'queue_name':_0x200168['name'],'SmsQueueId':_0x200168['id'],'interface':util[_0xb171('0x62')](_0xb171('0x63'),_0xb171('0x64'),_0x57b137['name']),'penalty':0x0,'paused':_0x57b137[_0xb171('0x65')],'createdAt':_0x57b137['createdAt'],'updatedAt':_0x57b137['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0xb171('0x27')](respondWithFilteredResult(_0xb06d1e,_0x37adb5))[_0xb171('0x49')](handleError(_0xb06d1e,null));};exports['getTeams']=function(_0x22fdb0,_0x3bb5f7,_0x13faf6){var _0x3ff622={};var _0xa37f29={};var _0x532f65;var _0x5281f1;return db['SmsQueue']['findOne']({'where':{'id':_0x22fdb0['params']['id']}})['then'](handleEntityNotFound(_0x3bb5f7,null))['then'](function(_0x4b6d1f){if(_0x4b6d1f){_0x532f65=_0x4b6d1f;_0xa37f29[_0xb171('0x37')]=_['keys'](db[_0xb171('0x66')][_0xb171('0x33')]);_0xa37f29[_0xb171('0x38')]=_[_0xb171('0x4b')](_0x22fdb0[_0xb171('0x38')]);_0xa37f29[_0xb171('0x42')]=_[_0xb171('0x39')](_0xa37f29['model'],_0xa37f29[_0xb171('0x38')]);_0x3ff622['attributes']=_[_0xb171('0x39')](_0xa37f29[_0xb171('0x37')],qs[_0xb171('0x3b')](_0x22fdb0['query'][_0xb171('0x3b')]));_0x3ff622['attributes']=_0x3ff622[_0xb171('0x3a')][_0xb171('0x4c')]?_0x3ff622[_0xb171('0x3a')]:_0xa37f29['model'];_0x3ff622[_0xb171('0x3e')]=qs['sort'](_0x22fdb0[_0xb171('0x38')][_0xb171('0x3f')]);_0x3ff622[_0xb171('0x40')]=qs[_0xb171('0x42')](_[_0xb171('0x41')](_0x22fdb0[_0xb171('0x38')],_0xa37f29[_0xb171('0x42')]));if(_0x22fdb0[_0xb171('0x38')][_0xb171('0x43')]){_0x3ff622[_0xb171('0x40')]=_[_0xb171('0x44')](_0x3ff622[_0xb171('0x40')],{'$or':_[_0xb171('0x31')](_0x3ff622[_0xb171('0x3a')],function(_0x241701){var _0x44e8ca={};_0x44e8ca[_0x241701]={'$like':'%'+_0x22fdb0[_0xb171('0x38')][_0xb171('0x43')]+'%'};return _0x44e8ca;})});}_0x3ff622=_[_0xb171('0x44')]({},_0x3ff622,_0x22fdb0[_0xb171('0x46')]);return _0x532f65[_0xb171('0x67')](_0x3ff622);}})[_0xb171('0x27')](function(_0x197f2d){if(_0x197f2d){_0x5281f1=_0x197f2d[_0xb171('0x4c')];if(!_0x22fdb0[_0xb171('0x38')][_0xb171('0x3c')]('nolimit')){_0x3ff622['limit']=qs[_0xb171('0x21')](_0x22fdb0[_0xb171('0x38')][_0xb171('0x21')]);_0x3ff622['offset']=qs[_0xb171('0x1e')](_0x22fdb0['query'][_0xb171('0x1e')]);}return _0x532f65[_0xb171('0x67')](_0x3ff622);}})[_0xb171('0x27')](function(_0x3c8466){if(_0x3c8466){return _0x3c8466?{'count':_0x5281f1,'rows':_0x3c8466}:null;}})[_0xb171('0x27')](respondWithResult(_0x3bb5f7,null))[_0xb171('0x49')](handleError(_0x3bb5f7,null));};exports[_0xb171('0x68')]=function(_0x157d1d,_0x4bab41,_0x15dfb4){var _0x28b2e9=_0x157d1d[_0xb171('0x50')][_0xb171('0x69')];return db[_0xb171('0x66')]['findAll']({'where':{'id':_0x28b2e9},'attributes':['id'],'include':[{'model':db['User'],'as':_0xb171('0x6a'),'attributes':['id','name',_0xb171('0x6b'),'voicePause',_0xb171('0x6c')],'raw':!![]}]})['then'](function(_0x55c03a){if(_0x55c03a){var _0x367218=_['flatMap'](_0x55c03a,function(_0x399ad4){var _0x209927=_0x399ad4['get']({'plain':!![]});return _0x209927['Agents'];});return db[_0xb171('0x32')][_0xb171('0x4e')]({'where':{'id':_0x157d1d[_0xb171('0x58')]['id']}})['then'](function(_0x4360d8){return db[_0xb171('0x6d')]['transaction'](function(_0x4c1cfa){return _0x4360d8[_0xb171('0x68')](_0x28b2e9,{'transaction':_0x4c1cfa})['then'](function(){return BPromise[_0xb171('0x6e')](_0x367218,function(_0x5a74f1){return db[_0xb171('0x6f')][_0xb171('0x70')]({'where':{'UserId':_0x5a74f1['id'],'SmsQueueId':_0x157d1d['params']['id']},'transaction':_0x4c1cfa});});})[_0xb171('0x27')](function(){_0x367218['forEach'](function(_0x2c2a9b){socket['emit'](_0xb171('0x71'),{'UserId':_0x2c2a9b['id'],'SmsQueueId':_0x4360d8['id']});});});});});}})[_0xb171('0x27')](respondWithStatusCode(_0x4bab41,null))[_0xb171('0x49')](handleError(_0x4bab41,null));};exports[_0xb171('0x72')]=function(_0x2b1a59,_0x12123b,_0x107f07){return db[_0xb171('0x66')][_0xb171('0x5d')]({'where':{'id':_0x2b1a59[_0xb171('0x38')]['ids']},'attributes':['id'],'include':[{'model':db[_0xb171('0x5e')],'as':_0xb171('0x6a'),'attributes':['id'],'raw':!![]}]})[_0xb171('0x27')](handleEntityNotFound(_0x12123b,null))[_0xb171('0x27')](function(_0x291332){var _0x3eb2a6=_[_0xb171('0x31')](_0x291332,'id');var _0x2bc16e=[];var _0x1fe2f2=[];var _0x135693=squel[_0xb171('0x73')]();_0x135693[_0xb171('0x74')](_0xb171('0x75'))[_0xb171('0x76')](_0xb171('0x77'),'tq')[_0xb171('0x78')]('user_has_teams','ut',_0xb171('0x79'))['where'](_0xb171('0x7a'),_0x2b1a59['params']['id']);for(var _0x34edfc=0x0;_0x34edfc<_0x291332[_0xb171('0x4c')];_0x34edfc+=0x1){let _0x5b0cef=_0x291332[_0x34edfc];for(var _0x392c88=0x0;_0x392c88<_0x5b0cef[_0xb171('0x6a')][_0xb171('0x4c')];_0x392c88+=0x1){let _0x5ea475=_0x5b0cef['Agents'][_0x392c88];var _0x528a06=_0x135693[_0xb171('0x7b')]();_0x528a06['where'](_0xb171('0x7c'),_0x5ea475['id']);_0x1fe2f2[_0xb171('0x7d')](db[_0xb171('0x6d')][_0xb171('0x38')](_0x528a06[_0xb171('0x7e')](),{'type':db[_0xb171('0x6d')][_0xb171('0x7f')][_0xb171('0x80')]})[_0xb171('0x27')](function(_0x5e2f08){if(_0x5e2f08[_0xb171('0x4c')]===0x1){return _0x5ea475['id'];}else{var _0x41fd39=_[_0xb171('0x81')](_['map'](_0x5e2f08,'TeamId'),function(_0x200020){return _[_0xb171('0x82')](_0x3eb2a6,_0x200020);});if(_0x41fd39){return _0x5ea475['id'];}}}));}}return BPromise[_0xb171('0x83')](_0x1fe2f2)[_0xb171('0x27')](function(_0x12a69c){_0x2bc16e=_(_0x2bc16e)[_0xb171('0x84')](_0x12a69c)[_0xb171('0x85')]()[_0xb171('0x86')]();return db['SmsQueue']['find']({'where':{'id':_0x2b1a59[_0xb171('0x58')]['id']}})[_0xb171('0x27')](function(_0x75f960){return db[_0xb171('0x6d')]['transaction'](function(_0x142358){return _0x75f960[_0xb171('0x72')](_0x2b1a59['query'][_0xb171('0x69')],{'transaction':_0x142358})[_0xb171('0x27')](function(){if(!_[_0xb171('0x87')](_0x2bc16e)){return _0x75f960['removeAgents'](_0x2bc16e,{'transaction':_0x142358});}})[_0xb171('0x27')](function(){_0x2bc16e[_0xb171('0x88')](function(_0x16c243){socket['emit'](_0xb171('0x89'),{'UserId':_0x16c243,'SmsQueueId':_0x75f960['id']});});});});});});})[_0xb171('0x27')](respondWithStatusCode(_0x12123b,null))['catch'](handleError(_0x12123b,null));};exports['addAgents']=function(_0x450999,_0x5e0a01,_0x421fa4){return db[_0xb171('0x32')][_0xb171('0x4e')]({'where':{'id':_0x450999[_0xb171('0x58')]['id']}})[_0xb171('0x27')](handleEntityNotFound(_0x5e0a01,null))['then'](function(_0x55d54b){if(_0x55d54b){return _0x55d54b['addAgents'](_0x450999[_0xb171('0x50')]['ids'],_[_0xb171('0x8a')](_0x450999[_0xb171('0x50')],[_0xb171('0x69'),'id'])||{})[_0xb171('0x8b')](function(_0x32f0dd){for(var _0x56a5a5=0x0;_0x56a5a5<_0x450999[_0xb171('0x50')]['ids'][_0xb171('0x4c')];_0x56a5a5+=0x1){socket['emit'](_0xb171('0x71'),{'UserId':Number(_0x450999[_0xb171('0x50')][_0xb171('0x69')][_0x56a5a5]),'SmsQueueId':Number(_0x450999['params']['id'])});}return _0x32f0dd;});}})[_0xb171('0x27')](respondWithResult(_0x5e0a01,null))['catch'](handleError(_0x5e0a01,null));};exports[_0xb171('0x8c')]=function(_0x5d627a,_0x3bbc82,_0x2fcade){return db[_0xb171('0x32')]['find']({'where':{'id':_0x5d627a[_0xb171('0x58')]['id']}})['then'](handleEntityNotFound(_0x3bbc82,null))['then'](function(_0x3b0f28){if(_0x3b0f28){return _0x3b0f28[_0xb171('0x8c')](_0x5d627a['query'][_0xb171('0x69')])[_0xb171('0x27')](function(){if(_[_0xb171('0x8d')](_0x5d627a[_0xb171('0x38')]['ids'])){for(var _0x2ebaef=0x0;_0x2ebaef<_0x5d627a[_0xb171('0x38')][_0xb171('0x69')][_0xb171('0x4c')];_0x2ebaef+=0x1){socket[_0xb171('0x8e')](_0xb171('0x89'),{'UserId':Number(_0x5d627a[_0xb171('0x38')][_0xb171('0x69')][_0x2ebaef]),'SmsQueueId':Number(_0x5d627a['params']['id'])});}}else{socket['emit']('userSmsQueue:remove',{'UserId':Number(_0x5d627a['query'][_0xb171('0x69')]),'SmsQueueId':Number(_0x5d627a[_0xb171('0x58')]['id'])});}});}})['then'](respondWithStatusCode(_0x3bbc82,null))[_0xb171('0x49')](handleError(_0x3bbc82,null));};exports[_0xb171('0x8f')]=function(_0x2ae512,_0x12a50d,_0x4df9a5){var _0x42f2d5={};var _0x1d0a2f={};var _0x17f559;var _0x1c84f4;return db[_0xb171('0x32')]['findOne']({'where':{'id':_0x2ae512[_0xb171('0x58')]['id']}})['then'](handleEntityNotFound(_0x12a50d,null))[_0xb171('0x27')](function(_0x1a7fd3){if(_0x1a7fd3){_0x17f559=_0x1a7fd3;_0x1d0a2f[_0xb171('0x37')]=_[_0xb171('0x4b')](db[_0xb171('0x5e')][_0xb171('0x33')]);_0x1d0a2f[_0xb171('0x38')]=_[_0xb171('0x4b')](_0x2ae512['query']);_0x1d0a2f[_0xb171('0x42')]=_[_0xb171('0x39')](_0x1d0a2f['model'],_0x1d0a2f[_0xb171('0x38')]);_0x42f2d5[_0xb171('0x3a')]=_[_0xb171('0x39')](_0x1d0a2f['model'],qs[_0xb171('0x3b')](_0x2ae512[_0xb171('0x38')]['fields']));_0x42f2d5[_0xb171('0x3a')]=_0x42f2d5[_0xb171('0x3a')][_0xb171('0x4c')]?_0x42f2d5['attributes']:_0x1d0a2f[_0xb171('0x37')];_0x42f2d5['order']=qs[_0xb171('0x3f')](_0x2ae512[_0xb171('0x38')]['sort']);_0x42f2d5['where']=qs[_0xb171('0x42')](_[_0xb171('0x41')](_0x2ae512[_0xb171('0x38')],_0x1d0a2f[_0xb171('0x42')]));if(_0x2ae512['query']['filter']){_0x42f2d5[_0xb171('0x40')]=_['merge'](_0x42f2d5[_0xb171('0x40')],{'$or':_[_0xb171('0x31')](_0x42f2d5[_0xb171('0x3a')],function(_0x4d72a9){var _0x553e5e={};_0x553e5e[_0x4d72a9]={'$like':'%'+_0x2ae512[_0xb171('0x38')][_0xb171('0x43')]+'%'};return _0x553e5e;})});}_0x42f2d5=_['merge']({},_0x42f2d5,_0x2ae512[_0xb171('0x46')]);return _0x17f559[_0xb171('0x8f')](_0x42f2d5);}})[_0xb171('0x27')](function(_0x256993){if(_0x256993){_0x1c84f4=_0x256993[_0xb171('0x4c')];if(!_0x2ae512[_0xb171('0x38')][_0xb171('0x3c')](_0xb171('0x3d'))){_0x42f2d5[_0xb171('0x21')]=qs['limit'](_0x2ae512['query'][_0xb171('0x21')]);_0x42f2d5['offset']=qs['offset'](_0x2ae512[_0xb171('0x38')][_0xb171('0x1e')]);}return _0x17f559[_0xb171('0x8f')](_0x42f2d5);}})[_0xb171('0x27')](function(_0x43516f){if(_0x43516f){return _0x43516f?{'count':_0x1c84f4,'rows':_0x43516f}:null;}})[_0xb171('0x27')](respondWithResult(_0x12a50d,null))[_0xb171('0x49')](handleError(_0x12a50d,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(_0x4d62ae,_0x1509f5){var _0x54d4b7=function(_0x492d51){while(--_0x492d51){_0x4d62ae['push'](_0x4d62ae['shift']());}};_0x54d4b7(++_0x1509f5);}(_0x5f66,0x1a0));var _0x65f6=function(_0x3947c9,_0x4d6c97){_0x3947c9=_0x3947c9-0x0;var _0x2e7871=_0x5f66[_0x3947c9];return _0x2e7871;};'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