Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / api / smsQueue / smsQueue.controller.js
index a701ed2..4007293 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x241a=['sendStatus','end','status','json','offset','undefined','count','set','Content-Range','apply','reject','save','update','then','destroy','get','SmsQueues','error','stack','name','send','index','map','SmsQueue','rawAttributes','fieldName','type','key','query','keys','filters','model','attributes','intersection','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','findAll','rows','catch','show','params','includeAll','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','find','describe','UserSmsQueue','SmsQueueId','findAndCountAll','UserId','agent','smsPause','updatedAt','createdAt','format','%s/%s','SIP','Team','getTeams','addTeams','ids','User','Agents','online','voicePause','sequelize','transaction','forEach','userSmsQueue:save','removeTeams','field','tq.TeamId','from','team_has_sms_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','SmsQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','all','union','value','removeAgents','userSmsQueue:remove','addAgents','spread','emit','isArray','getAgents','eml-format','fast-json-patch','request-promise','bluebird','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsQueue.socket','register'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x241a,0x18b));var _0xa241=function(_0x3ab9ee,_0x4a74b8){_0x3ab9ee=_0x3ab9ee-0x0;var _0x82ee88=_0x241a[_0x3ab9ee];return _0x82ee88;};'use strict';var emlformat=require(_0xa241('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xa241('0x1'));var rp=require(_0xa241('0x2'));var moment=require('moment');var BPromise=require(_0xa241('0x3'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0xa241('0x4'));var ejs=require(_0xa241('0x5'));var fs=require('fs');var fs_extra=require(_0xa241('0x6'));var _=require(_0xa241('0x7'));var squel=require(_0xa241('0x8'));var crypto=require('crypto');var jsforce=require(_0xa241('0x9'));var deskjs=require(_0xa241('0xa'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xa241('0xb'));var Redis=require('ioredis');var authService=require(_0xa241('0xc'));var qs=require(_0xa241('0xd'));var as=require(_0xa241('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xa241('0xf'))('api');var utils=require(_0xa241('0x10'));var config=require('../../config/environment');var licenseUtil=require(_0xa241('0x11'));var db=require(_0xa241('0x12'))['db'];config[_0xa241('0x13')]=_[_0xa241('0x14')](config['redis'],{'host':_0xa241('0x15'),'port':0x18eb});var socket=require(_0xa241('0x16'))(new Redis(config[_0xa241('0x13')]));require(_0xa241('0x17'))[_0xa241('0x18')](socket);function respondWithStatusCode(_0x4b75fb,_0x368b60){_0x368b60=_0x368b60||0xcc;return function(_0x217e23){if(_0x217e23){return _0x4b75fb[_0xa241('0x19')](_0x368b60);}return _0x4b75fb['status'](_0x368b60)[_0xa241('0x1a')]();};}function respondWithResult(_0x3e3bcb,_0x25e4aa){_0x25e4aa=_0x25e4aa||0xc8;return function(_0x479c30){if(_0x479c30){return _0x3e3bcb[_0xa241('0x1b')](_0x25e4aa)[_0xa241('0x1c')](_0x479c30);}};}function respondWithFilteredResult(_0x49e6e7,_0x45d9c6){return function(_0x483d25){if(_0x483d25){var _0x4bbfa7=typeof _0x45d9c6[_0xa241('0x1d')]===_0xa241('0x1e')&&typeof _0x45d9c6['limit']===_0xa241('0x1e');var _0x42370f=_0x483d25['count'];var _0x427b1a=_0x4bbfa7?0x0:_0x45d9c6[_0xa241('0x1d')];var _0x144648=_0x4bbfa7?_0x483d25[_0xa241('0x1f')]:_0x45d9c6[_0xa241('0x1d')]+_0x45d9c6['limit'];var _0x3e3715;if(_0x144648>=_0x42370f){_0x144648=_0x42370f;_0x3e3715=0xc8;}else{_0x3e3715=0xce;}_0x49e6e7['status'](_0x3e3715);return _0x49e6e7[_0xa241('0x20')](_0xa241('0x21'),_0x427b1a+'-'+_0x144648+'/'+_0x42370f)[_0xa241('0x1c')](_0x483d25);}return null;};}function patchUpdates(_0x450c72){return function(_0x1b6a7d){try{jsonpatch[_0xa241('0x22')](_0x1b6a7d,_0x450c72,!![]);}catch(_0x92bd74){return BPromise[_0xa241('0x23')](_0x92bd74);}return _0x1b6a7d[_0xa241('0x24')]();};}function saveUpdates(_0x3784c7,_0x4bc96c){return function(_0x1a2cb8){if(_0x1a2cb8){return _0x1a2cb8[_0xa241('0x25')](_0x3784c7)[_0xa241('0x26')](function(_0x9bff73){return _0x9bff73;});}return null;};}function removeEntity(_0x462973,_0x44ab52){return function(_0x4fbd84){if(_0x4fbd84){return _0x4fbd84[_0xa241('0x27')]()['then'](function(){var _0x276830=_0x4fbd84[_0xa241('0x28')]({'plain':!![]});var _0x4ea587=_0xa241('0x29');return db['UserProfileResource'][_0xa241('0x27')]({'where':{'type':_0x4ea587,'resourceId':_0x276830['id']}})[_0xa241('0x26')](function(){return _0x4fbd84;});})['then'](function(){_0x462973[_0xa241('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x16a1bc,_0x17b393){return function(_0xd83c8){if(!_0xd83c8){_0x16a1bc[_0xa241('0x19')](0x194);}return _0xd83c8;};}function handleError(_0x11b96d,_0x408f24){_0x408f24=_0x408f24||0x1f4;return function(_0x7402ed){logger[_0xa241('0x2a')](_0x7402ed[_0xa241('0x2b')]);if(_0x7402ed[_0xa241('0x2c')]){delete _0x7402ed[_0xa241('0x2c')];}_0x11b96d[_0xa241('0x1b')](_0x408f24)[_0xa241('0x2d')](_0x7402ed);};}exports[_0xa241('0x2e')]=function(_0x466cbf,_0x19e5fa){var _0x580d56={},_0x27a4f8={},_0x50b4a1={'count':0x0,'rows':[]};var _0x368ee2=_[_0xa241('0x2f')](db[_0xa241('0x30')][_0xa241('0x31')],function(_0x3eb313){return{'name':_0x3eb313[_0xa241('0x32')],'type':_0x3eb313[_0xa241('0x33')][_0xa241('0x34')]};});_0x27a4f8['model']=_[_0xa241('0x2f')](_0x368ee2,_0xa241('0x2c'));_0x27a4f8[_0xa241('0x35')]=_[_0xa241('0x36')](_0x466cbf['query']);_0x27a4f8[_0xa241('0x37')]=_['intersection'](_0x27a4f8[_0xa241('0x38')],_0x27a4f8[_0xa241('0x35')]);_0x580d56[_0xa241('0x39')]=_[_0xa241('0x3a')](_0x27a4f8['model'],qs[_0xa241('0x3b')](_0x466cbf[_0xa241('0x35')][_0xa241('0x3b')]));_0x580d56['attributes']=_0x580d56[_0xa241('0x39')][_0xa241('0x3c')]?_0x580d56[_0xa241('0x39')]:_0x27a4f8[_0xa241('0x38')];if(!_0x466cbf['query'][_0xa241('0x3d')](_0xa241('0x3e'))){_0x580d56[_0xa241('0x3f')]=qs[_0xa241('0x3f')](_0x466cbf[_0xa241('0x35')][_0xa241('0x3f')]);_0x580d56[_0xa241('0x1d')]=qs[_0xa241('0x1d')](_0x466cbf['query']['offset']);}_0x580d56[_0xa241('0x40')]=qs[_0xa241('0x41')](_0x466cbf[_0xa241('0x35')][_0xa241('0x41')]);_0x580d56[_0xa241('0x42')]=qs[_0xa241('0x37')](_[_0xa241('0x43')](_0x466cbf[_0xa241('0x35')],_0x27a4f8['filters']),_0x368ee2);if(_0x466cbf[_0xa241('0x35')][_0xa241('0x44')]){_0x580d56[_0xa241('0x42')]=_[_0xa241('0x45')](_0x580d56[_0xa241('0x42')],{'$or':_['map'](_0x368ee2,function(_0x5ddade){if(_0x5ddade[_0xa241('0x33')]!==_0xa241('0x46')){var _0x3fa1ba={};_0x3fa1ba[_0x5ddade[_0xa241('0x2c')]]={'$like':'%'+_0x466cbf['query'][_0xa241('0x44')]+'%'};return _0x3fa1ba;}})});}_0x580d56=_[_0xa241('0x45')]({},_0x580d56,_0x466cbf[_0xa241('0x47')]);var _0xe8f239={'where':_0x580d56['where']};return db['SmsQueue'][_0xa241('0x1f')](_0xe8f239)['then'](function(_0x451a27){_0x50b4a1[_0xa241('0x1f')]=_0x451a27;if(_0x466cbf[_0xa241('0x35')]['includeAll']){_0x580d56[_0xa241('0x48')]=[{'all':!![]}];}return db[_0xa241('0x30')][_0xa241('0x49')](_0x580d56);})[_0xa241('0x26')](function(_0x2a19be){_0x50b4a1[_0xa241('0x4a')]=_0x2a19be;return _0x50b4a1;})[_0xa241('0x26')](respondWithFilteredResult(_0x19e5fa,_0x580d56))[_0xa241('0x4b')](handleError(_0x19e5fa,null));};exports[_0xa241('0x4c')]=function(_0x26d541,_0x510f7c){var _0x1c3a91={'raw':!![],'where':{'id':_0x26d541[_0xa241('0x4d')]['id']}},_0x20cfeb={};_0x20cfeb[_0xa241('0x38')]=_[_0xa241('0x36')](db[_0xa241('0x30')][_0xa241('0x31')]);_0x20cfeb['query']=_[_0xa241('0x36')](_0x26d541[_0xa241('0x35')]);_0x20cfeb['filters']=_[_0xa241('0x3a')](_0x20cfeb['model'],_0x20cfeb['query']);_0x1c3a91[_0xa241('0x39')]=_[_0xa241('0x3a')](_0x20cfeb['model'],qs['fields'](_0x26d541['query']['fields']));_0x1c3a91[_0xa241('0x39')]=_0x1c3a91[_0xa241('0x39')][_0xa241('0x3c')]?_0x1c3a91['attributes']:_0x20cfeb[_0xa241('0x38')];if(_0x26d541[_0xa241('0x35')][_0xa241('0x4e')]){_0x1c3a91[_0xa241('0x48')]=[{'all':!![]}];}_0x1c3a91=_[_0xa241('0x45')]({},_0x1c3a91,_0x26d541['options']);return db['SmsQueue']['find'](_0x1c3a91)['then'](handleEntityNotFound(_0x510f7c,null))[_0xa241('0x26')](respondWithResult(_0x510f7c,null))['catch'](handleError(_0x510f7c,null));};exports['create']=function(_0x376c3a,_0x5197d0){return db[_0xa241('0x30')][_0xa241('0x4f')](_0x376c3a[_0xa241('0x50')],{})[_0xa241('0x26')](function(_0xc7c677){var _0x57e8cd=_0x376c3a[_0xa241('0x51')]['get']({'plain':!![]});if(!_0x57e8cd)throw new Error(_0xa241('0x52'));if(_0x57e8cd[_0xa241('0x53')]==='user'){var _0x4c204c=_0xc7c677[_0xa241('0x28')]({'plain':!![]});var _0x329fce=_0xa241('0x29');return db[_0xa241('0x54')]['find']({'where':{'name':_0x329fce,'userProfileId':_0x57e8cd[_0xa241('0x55')]},'raw':!![]})[_0xa241('0x26')](function(_0x44a00d){if(_0x44a00d&&_0x44a00d[_0xa241('0x56')]===0x0){return db[_0xa241('0x57')][_0xa241('0x4f')]({'name':_0x4c204c['name'],'resourceId':_0x4c204c['id'],'type':_0x44a00d['name'],'sectionId':_0x44a00d['id']},{})[_0xa241('0x26')](function(){return _0xc7c677;});}else{return _0xc7c677;}})[_0xa241('0x4b')](function(_0x328c14){logger['error'](_0xa241('0x58'),_0x328c14);throw _0x328c14;});}return _0xc7c677;})[_0xa241('0x26')](respondWithResult(_0x5197d0,0xc9))[_0xa241('0x4b')](handleError(_0x5197d0,null));};exports[_0xa241('0x25')]=function(_0x30ec28,_0x13acac){if(_0x30ec28[_0xa241('0x50')]['id']){delete _0x30ec28[_0xa241('0x50')]['id'];}return db[_0xa241('0x30')]['find']({'where':{'id':_0x30ec28['params']['id']}})[_0xa241('0x26')](handleEntityNotFound(_0x13acac,null))['then'](saveUpdates(_0x30ec28[_0xa241('0x50')],null))['then'](respondWithResult(_0x13acac,null))[_0xa241('0x4b')](handleError(_0x13acac,null));};exports[_0xa241('0x27')]=function(_0x2c1537,_0x466336){return db[_0xa241('0x30')][_0xa241('0x59')]({'where':{'id':_0x2c1537[_0xa241('0x4d')]['id']}})[_0xa241('0x26')](handleEntityNotFound(_0x466336,null))[_0xa241('0x26')](removeEntity(_0x466336,null))[_0xa241('0x4b')](handleError(_0x466336,null));};exports['describe']=function(_0x3067bf,_0x59e139){return db[_0xa241('0x30')][_0xa241('0x5a')]()[_0xa241('0x26')](respondWithResult(_0x59e139,null))['catch'](handleError(_0x59e139,null));};exports['getMembers']=function(_0x399de7,_0x41d3b2,_0x45f173){var _0xff2868={'raw':!![],'where':{}},_0x44fa6e={},_0x52f26;return db[_0xa241('0x30')]['findOne']({'where':{'id':_0x399de7['params']['id']}})[_0xa241('0x26')](handleEntityNotFound(_0x41d3b2,null))['then'](function(_0x28d878){if(_0x28d878){_0x52f26=_0x28d878[_0xa241('0x28')]({'plain':!![]});_0x44fa6e[_0xa241('0x38')]=_[_0xa241('0x36')](db[_0xa241('0x5b')]['rawAttributes']);_0x44fa6e[_0xa241('0x35')]=_['keys'](_0x399de7['query']);_0x44fa6e[_0xa241('0x37')]=_['intersection'](_0x44fa6e[_0xa241('0x38')],_0x44fa6e['query']);_0xff2868[_0xa241('0x39')]=_[_0xa241('0x3a')](_0x44fa6e[_0xa241('0x38')],qs['fields'](_0x399de7[_0xa241('0x35')][_0xa241('0x3b')]));_0xff2868['attributes']=_0xff2868[_0xa241('0x39')][_0xa241('0x3c')]?_0xff2868[_0xa241('0x39')]:_0x44fa6e[_0xa241('0x38')];if(!_0x399de7[_0xa241('0x35')][_0xa241('0x3d')]('nolimit')){_0xff2868[_0xa241('0x3f')]=qs['limit'](_0x399de7[_0xa241('0x35')][_0xa241('0x3f')]);_0xff2868[_0xa241('0x1d')]=qs['offset'](_0x399de7[_0xa241('0x35')][_0xa241('0x1d')]);}_0xff2868[_0xa241('0x40')]=qs[_0xa241('0x41')](_0x399de7['query'][_0xa241('0x41')]);_0xff2868[_0xa241('0x42')]=qs[_0xa241('0x37')](_[_0xa241('0x43')](_0x399de7['query'],_0x44fa6e[_0xa241('0x37')]));_0xff2868[_0xa241('0x42')][_0xa241('0x5c')]=_0x28d878['id'];if(_0x399de7['query'][_0xa241('0x44')]){_0xff2868[_0xa241('0x42')]=_[_0xa241('0x45')](_0xff2868[_0xa241('0x42')],{'$or':_[_0xa241('0x2f')](_0xff2868[_0xa241('0x39')],function(_0x37e1ff){var _0x142d15={};_0x142d15[_0x37e1ff]={'$like':'%'+_0x399de7['query'][_0xa241('0x44')]+'%'};return _0x142d15;})});}_0xff2868=_['merge']({},_0xff2868,_0x399de7[_0xa241('0x47')]);return db[_0xa241('0x5b')][_0xa241('0x49')](_0xff2868);}})['then'](function(_0x1be6fc){if(_0x1be6fc){return db['User'][_0xa241('0x5d')]({'where':{'id':_['map'](_0x1be6fc,_0xa241('0x5e')),'role':_0xa241('0x5f')},'attributes':['id',_0xa241('0x2c'),_0xa241('0x60'),_0xa241('0x61'),_0xa241('0x62')]});}})[_0xa241('0x26')](function(_0x329702){if(_0x329702){return{'count':_0x329702['count'],'rows':_[_0xa241('0x2f')](_0x329702[_0xa241('0x4a')],function(_0x35d09e){return{'membername':_0x35d09e[_0xa241('0x2c')],'UserId':_0x35d09e['id'],'queue_name':_0x52f26[_0xa241('0x2c')],'SmsQueueId':_0x52f26['id'],'interface':util[_0xa241('0x63')](_0xa241('0x64'),_0xa241('0x65'),_0x35d09e[_0xa241('0x2c')]),'penalty':0x0,'paused':_0x35d09e[_0xa241('0x60')],'createdAt':_0x35d09e[_0xa241('0x62')],'updatedAt':_0x35d09e[_0xa241('0x61')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xa241('0x26')](respondWithFilteredResult(_0x41d3b2,_0xff2868))[_0xa241('0x4b')](handleError(_0x41d3b2,null));};exports['getTeams']=function(_0x1afe4b,_0x3436fc,_0x2e684d){var _0x9f5240={};var _0x282517={};var _0x23aa85;var _0x455770;return db[_0xa241('0x30')]['findOne']({'where':{'id':_0x1afe4b[_0xa241('0x4d')]['id']}})[_0xa241('0x26')](handleEntityNotFound(_0x3436fc,null))[_0xa241('0x26')](function(_0x2c13e1){if(_0x2c13e1){_0x23aa85=_0x2c13e1;_0x282517[_0xa241('0x38')]=_[_0xa241('0x36')](db[_0xa241('0x66')][_0xa241('0x31')]);_0x282517['query']=_[_0xa241('0x36')](_0x1afe4b[_0xa241('0x35')]);_0x282517['filters']=_[_0xa241('0x3a')](_0x282517['model'],_0x282517[_0xa241('0x35')]);_0x9f5240['attributes']=_[_0xa241('0x3a')](_0x282517['model'],qs[_0xa241('0x3b')](_0x1afe4b[_0xa241('0x35')][_0xa241('0x3b')]));_0x9f5240[_0xa241('0x39')]=_0x9f5240[_0xa241('0x39')][_0xa241('0x3c')]?_0x9f5240['attributes']:_0x282517[_0xa241('0x38')];_0x9f5240[_0xa241('0x40')]=qs[_0xa241('0x41')](_0x1afe4b['query'][_0xa241('0x41')]);_0x9f5240[_0xa241('0x42')]=qs[_0xa241('0x37')](_['pick'](_0x1afe4b[_0xa241('0x35')],_0x282517['filters']));if(_0x1afe4b[_0xa241('0x35')][_0xa241('0x44')]){_0x9f5240[_0xa241('0x42')]=_[_0xa241('0x45')](_0x9f5240['where'],{'$or':_[_0xa241('0x2f')](_0x9f5240[_0xa241('0x39')],function(_0x1d31a5){var _0x26324e={};_0x26324e[_0x1d31a5]={'$like':'%'+_0x1afe4b[_0xa241('0x35')]['filter']+'%'};return _0x26324e;})});}_0x9f5240=_['merge']({},_0x9f5240,_0x1afe4b[_0xa241('0x47')]);return _0x23aa85[_0xa241('0x67')](_0x9f5240);}})[_0xa241('0x26')](function(_0x394aa8){if(_0x394aa8){_0x455770=_0x394aa8[_0xa241('0x3c')];if(!_0x1afe4b[_0xa241('0x35')][_0xa241('0x3d')]('nolimit')){_0x9f5240[_0xa241('0x3f')]=qs[_0xa241('0x3f')](_0x1afe4b[_0xa241('0x35')][_0xa241('0x3f')]);_0x9f5240[_0xa241('0x1d')]=qs[_0xa241('0x1d')](_0x1afe4b[_0xa241('0x35')][_0xa241('0x1d')]);}return _0x23aa85[_0xa241('0x67')](_0x9f5240);}})['then'](function(_0x22aeb5){if(_0x22aeb5){return _0x22aeb5?{'count':_0x455770,'rows':_0x22aeb5}:null;}})['then'](respondWithResult(_0x3436fc,null))[_0xa241('0x4b')](handleError(_0x3436fc,null));};exports[_0xa241('0x68')]=function(_0x17644f,_0x1332da,_0x36ed66){var _0x5e3062=_0x17644f[_0xa241('0x50')][_0xa241('0x69')];return db[_0xa241('0x66')]['findAll']({'where':{'id':_0x5e3062},'attributes':['id'],'include':[{'model':db[_0xa241('0x6a')],'as':_0xa241('0x6b'),'attributes':['id',_0xa241('0x2c'),_0xa241('0x6c'),_0xa241('0x6d'),'interface'],'raw':!![]}]})[_0xa241('0x26')](function(_0x1d379e){if(_0x1d379e){var _0x474384=_['flatMap'](_0x1d379e,function(_0x50e0ad){var _0x3001e2=_0x50e0ad[_0xa241('0x28')]({'plain':!![]});return _0x3001e2[_0xa241('0x6b')];});return db[_0xa241('0x30')][_0xa241('0x59')]({'where':{'id':_0x17644f[_0xa241('0x4d')]['id']}})[_0xa241('0x26')](function(_0x357fb8){return db[_0xa241('0x6e')][_0xa241('0x6f')](function(_0xa9d23c){return _0x357fb8[_0xa241('0x68')](_0x5e3062,{'transaction':_0xa9d23c})['then'](function(){return BPromise['each'](_0x474384,function(_0x450150){return db[_0xa241('0x5b')]['findOrCreate']({'where':{'UserId':_0x450150['id'],'SmsQueueId':_0x17644f[_0xa241('0x4d')]['id']},'transaction':_0xa9d23c});});})[_0xa241('0x26')](function(){_0x474384[_0xa241('0x70')](function(_0x29b706){socket['emit'](_0xa241('0x71'),{'UserId':_0x29b706['id'],'SmsQueueId':_0x357fb8['id']});});});});});}})[_0xa241('0x26')](respondWithStatusCode(_0x1332da,null))[_0xa241('0x4b')](handleError(_0x1332da,null));};exports[_0xa241('0x72')]=function(_0x4b4b15,_0x31cc67,_0x375ac1){return db[_0xa241('0x66')][_0xa241('0x49')]({'where':{'id':_0x4b4b15['query'][_0xa241('0x69')]},'attributes':['id'],'include':[{'model':db[_0xa241('0x6a')],'as':_0xa241('0x6b'),'attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x31cc67,null))['then'](function(_0x356cde){var _0x14b29f=_[_0xa241('0x2f')](_0x356cde,'id');var _0x4e63ac=[];var _0x1e2244=[];var _0x81de3a=squel['select']();_0x81de3a[_0xa241('0x73')](_0xa241('0x74'))[_0xa241('0x75')](_0xa241('0x76'),'tq')[_0xa241('0x77')](_0xa241('0x78'),'ut',_0xa241('0x79'))[_0xa241('0x42')](_0xa241('0x7a'),_0x4b4b15[_0xa241('0x4d')]['id']);for(var _0x51d8fa=0x0;_0x51d8fa<_0x356cde[_0xa241('0x3c')];_0x51d8fa+=0x1){let _0x423c21=_0x356cde[_0x51d8fa];for(var _0x322e88=0x0;_0x322e88<_0x423c21['Agents'][_0xa241('0x3c')];_0x322e88+=0x1){let _0x17308a=_0x423c21[_0xa241('0x6b')][_0x322e88];var _0x3c9db1=_0x81de3a[_0xa241('0x7b')]();_0x3c9db1['where'](_0xa241('0x7c'),_0x17308a['id']);_0x1e2244[_0xa241('0x7d')](db[_0xa241('0x6e')][_0xa241('0x35')](_0x3c9db1[_0xa241('0x7e')](),{'type':db[_0xa241('0x6e')][_0xa241('0x7f')][_0xa241('0x80')]})[_0xa241('0x26')](function(_0x54e59b){if(_0x54e59b[_0xa241('0x3c')]===0x1){return _0x17308a['id'];}else{var _0x368806=_[_0xa241('0x81')](_[_0xa241('0x2f')](_0x54e59b,'TeamId'),function(_0x291523){return _['includes'](_0x14b29f,_0x291523);});if(_0x368806){return _0x17308a['id'];}}}));}}return BPromise[_0xa241('0x82')](_0x1e2244)[_0xa241('0x26')](function(_0x4278ea){_0x4e63ac=_(_0x4e63ac)[_0xa241('0x83')](_0x4278ea)['compact']()[_0xa241('0x84')]();return db[_0xa241('0x30')][_0xa241('0x59')]({'where':{'id':_0x4b4b15[_0xa241('0x4d')]['id']}})[_0xa241('0x26')](function(_0x2b61c7){return db[_0xa241('0x6e')]['transaction'](function(_0x3951d7){return _0x2b61c7['removeTeams'](_0x4b4b15[_0xa241('0x35')][_0xa241('0x69')],{'transaction':_0x3951d7})['then'](function(){if(!_['isEmpty'](_0x4e63ac)){return _0x2b61c7[_0xa241('0x85')](_0x4e63ac,{'transaction':_0x3951d7});}})['then'](function(){_0x4e63ac[_0xa241('0x70')](function(_0x347ee4){socket['emit'](_0xa241('0x86'),{'UserId':_0x347ee4,'SmsQueueId':_0x2b61c7['id']});});});});});});})[_0xa241('0x26')](respondWithStatusCode(_0x31cc67,null))[_0xa241('0x4b')](handleError(_0x31cc67,null));};exports[_0xa241('0x87')]=function(_0xd1bb09,_0x193801,_0xe2051){return db[_0xa241('0x30')][_0xa241('0x59')]({'where':{'id':_0xd1bb09[_0xa241('0x4d')]['id']}})[_0xa241('0x26')](handleEntityNotFound(_0x193801,null))['then'](function(_0x5921a5){if(_0x5921a5){return _0x5921a5[_0xa241('0x87')](_0xd1bb09[_0xa241('0x50')][_0xa241('0x69')],_['omit'](_0xd1bb09[_0xa241('0x50')],[_0xa241('0x69'),'id'])||{})[_0xa241('0x88')](function(_0x57eb4d){for(var _0x4910cc=0x0;_0x4910cc<_0xd1bb09[_0xa241('0x50')][_0xa241('0x69')][_0xa241('0x3c')];_0x4910cc+=0x1){socket[_0xa241('0x89')](_0xa241('0x71'),{'UserId':Number(_0xd1bb09[_0xa241('0x50')][_0xa241('0x69')][_0x4910cc]),'SmsQueueId':Number(_0xd1bb09[_0xa241('0x4d')]['id'])});}return _0x57eb4d;});}})[_0xa241('0x26')](respondWithResult(_0x193801,null))[_0xa241('0x4b')](handleError(_0x193801,null));};exports[_0xa241('0x85')]=function(_0x47766b,_0x272342,_0x4fe5d6){return db[_0xa241('0x30')][_0xa241('0x59')]({'where':{'id':_0x47766b[_0xa241('0x4d')]['id']}})[_0xa241('0x26')](handleEntityNotFound(_0x272342,null))[_0xa241('0x26')](function(_0x401221){if(_0x401221){return _0x401221['removeAgents'](_0x47766b[_0xa241('0x35')][_0xa241('0x69')])['then'](function(){if(_[_0xa241('0x8a')](_0x47766b[_0xa241('0x35')][_0xa241('0x69')])){for(var _0x152cd9=0x0;_0x152cd9<_0x47766b[_0xa241('0x35')]['ids'][_0xa241('0x3c')];_0x152cd9+=0x1){socket[_0xa241('0x89')](_0xa241('0x86'),{'UserId':Number(_0x47766b[_0xa241('0x35')]['ids'][_0x152cd9]),'SmsQueueId':Number(_0x47766b[_0xa241('0x4d')]['id'])});}}else{socket[_0xa241('0x89')](_0xa241('0x86'),{'UserId':Number(_0x47766b[_0xa241('0x35')][_0xa241('0x69')]),'SmsQueueId':Number(_0x47766b[_0xa241('0x4d')]['id'])});}});}})['then'](respondWithStatusCode(_0x272342,null))['catch'](handleError(_0x272342,null));};exports['getAgents']=function(_0x5ae16b,_0x106f3e,_0x38398d){var _0x2e4eed={};var _0x3636f7={};var _0x37c3b5;var _0xccdc15;return db[_0xa241('0x30')]['findOne']({'where':{'id':_0x5ae16b[_0xa241('0x4d')]['id']}})[_0xa241('0x26')](handleEntityNotFound(_0x106f3e,null))[_0xa241('0x26')](function(_0x2364f3){if(_0x2364f3){_0x37c3b5=_0x2364f3;_0x3636f7['model']=_[_0xa241('0x36')](db[_0xa241('0x6a')][_0xa241('0x31')]);_0x3636f7[_0xa241('0x35')]=_[_0xa241('0x36')](_0x5ae16b['query']);_0x3636f7[_0xa241('0x37')]=_[_0xa241('0x3a')](_0x3636f7[_0xa241('0x38')],_0x3636f7[_0xa241('0x35')]);_0x2e4eed['attributes']=_[_0xa241('0x3a')](_0x3636f7['model'],qs[_0xa241('0x3b')](_0x5ae16b[_0xa241('0x35')][_0xa241('0x3b')]));_0x2e4eed[_0xa241('0x39')]=_0x2e4eed['attributes'][_0xa241('0x3c')]?_0x2e4eed[_0xa241('0x39')]:_0x3636f7[_0xa241('0x38')];_0x2e4eed['order']=qs[_0xa241('0x41')](_0x5ae16b[_0xa241('0x35')][_0xa241('0x41')]);_0x2e4eed['where']=qs['filters'](_[_0xa241('0x43')](_0x5ae16b['query'],_0x3636f7[_0xa241('0x37')]));if(_0x5ae16b['query']['filter']){_0x2e4eed[_0xa241('0x42')]=_['merge'](_0x2e4eed[_0xa241('0x42')],{'$or':_[_0xa241('0x2f')](_0x2e4eed['attributes'],function(_0x3375c3){var _0x2d5479={};_0x2d5479[_0x3375c3]={'$like':'%'+_0x5ae16b[_0xa241('0x35')][_0xa241('0x44')]+'%'};return _0x2d5479;})});}_0x2e4eed=_['merge']({},_0x2e4eed,_0x5ae16b['options']);return _0x37c3b5[_0xa241('0x8b')](_0x2e4eed);}})['then'](function(_0x391f95){if(_0x391f95){_0xccdc15=_0x391f95[_0xa241('0x3c')];if(!_0x5ae16b[_0xa241('0x35')]['hasOwnProperty'](_0xa241('0x3e'))){_0x2e4eed[_0xa241('0x3f')]=qs[_0xa241('0x3f')](_0x5ae16b[_0xa241('0x35')][_0xa241('0x3f')]);_0x2e4eed[_0xa241('0x1d')]=qs[_0xa241('0x1d')](_0x5ae16b[_0xa241('0x35')]['offset']);}return _0x37c3b5[_0xa241('0x8b')](_0x2e4eed);}})[_0xa241('0x26')](function(_0x1435c5){if(_0x1435c5){return _0x1435c5?{'count':_0xccdc15,'rows':_0x1435c5}:null;}})['then'](respondWithResult(_0x106f3e,null))['catch'](handleError(_0x106f3e,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