Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / api / smsQueue / smsQueue.controller.js
index 1ed6fa6..4007293 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x814b=['union','value','removeAgents','addAgents','omit','spread','userSmsQueue:save','isArray','userSmsQueue:remove','getAgents','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsQueue.socket','register','sendStatus','status','end','json','offset','set','Content-Range','apply','reject','save','then','destroy','get','SmsQueues','UserProfileResource','error','name','send','map','SmsQueue','fieldName','type','model','query','keys','filters','attributes','intersection','length','nolimit','limit','order','where','filter','merge','options','count','includeAll','findAll','catch','show','params','rawAttributes','fields','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','describe','UserSmsQueue','hasOwnProperty','sort','pick','SmsQueueId','User','findAndCountAll','agent','smsPause','createdAt','format','%s/%s','SIP','updatedAt','getTeams','findOne','Team','addTeams','ids','Agents','online','voicePause','flatMap','sequelize','transaction','forEach','emit','removeTeams','select','field','tq.TeamId','from','team_has_sms_queues','join','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','all'];(function(_0x19bd5b,_0x439291){var _0x2ee998=function(_0x5df139){while(--_0x5df139){_0x19bd5b['push'](_0x19bd5b['shift']());}};_0x2ee998(++_0x439291);}(_0x814b,0x1a2));var _0xb814=function(_0x31bab3,_0x44554f){_0x31bab3=_0x31bab3-0x0;var _0x4fd382=_0x814b[_0x31bab3];return _0x4fd382;};'use strict';var pdf=require(_0xb814('0x0'));var emlformat=require(_0xb814('0x1'));var rimraf=require(_0xb814('0x2'));var zipdir=require(_0xb814('0x3'));var jsonpatch=require(_0xb814('0x4'));var rp=require(_0xb814('0x5'));var moment=require('moment');var BPromise=require(_0xb814('0x6'));var Mustache=require(_0xb814('0x7'));var util=require(_0xb814('0x8'));var path=require(_0xb814('0x9'));var sox=require(_0xb814('0xa'));var csv=require(_0xb814('0xb'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xb814('0xc'));var squel=require(_0xb814('0xd'));var crypto=require('crypto');var jsforce=require(_0xb814('0xe'));var deskjs=require(_0xb814('0xf'));var toCsv=require(_0xb814('0xb'));var querystring=require(_0xb814('0x10'));var Papa=require(_0xb814('0x11'));var Redis=require(_0xb814('0x12'));var authService=require(_0xb814('0x13'));var qs=require(_0xb814('0x14'));var as=require(_0xb814('0x15'));var hardwareService=require(_0xb814('0x16'));var logger=require(_0xb814('0x17'))('api');var utils=require(_0xb814('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0xb814('0x19'));var db=require(_0xb814('0x1a'))['db'];config[_0xb814('0x1b')]=_[_0xb814('0x1c')](config[_0xb814('0x1b')],{'host':_0xb814('0x1d'),'port':0x18eb});var socket=require(_0xb814('0x1e'))(new Redis(config[_0xb814('0x1b')]));require(_0xb814('0x1f'))[_0xb814('0x20')](socket);function respondWithStatusCode(_0x3f4881,_0x44fb96){_0x44fb96=_0x44fb96||0xcc;return function(_0x17f5bd){if(_0x17f5bd){return _0x3f4881[_0xb814('0x21')](_0x44fb96);}return _0x3f4881[_0xb814('0x22')](_0x44fb96)[_0xb814('0x23')]();};}function respondWithResult(_0x45e0d0,_0x265a83){_0x265a83=_0x265a83||0xc8;return function(_0x125ce2){if(_0x125ce2){return _0x45e0d0[_0xb814('0x22')](_0x265a83)[_0xb814('0x24')](_0x125ce2);}};}function respondWithFilteredResult(_0x48c9df,_0x168a48){return function(_0x55ba16){if(_0x55ba16){var _0x270598=_0x55ba16['count'],_0xfac75b=_0x168a48[_0xb814('0x25')],_0x4c3007=_0x168a48['offset']+_0x168a48['limit'],_0x4b55a7;if(_0x4c3007>=_0x270598){_0x4c3007=_0x270598;_0x4b55a7=0xc8;}else{_0x4b55a7=0xce;}_0x48c9df[_0xb814('0x22')](_0x4b55a7);return _0x48c9df[_0xb814('0x26')](_0xb814('0x27'),_0xfac75b+'-'+_0x4c3007+'/'+_0x270598)['json'](_0x55ba16);}return null;};}function patchUpdates(_0xf5b8aa){return function(_0x531032){try{jsonpatch[_0xb814('0x28')](_0x531032,_0xf5b8aa,!![]);}catch(_0x1808a3){return BPromise[_0xb814('0x29')](_0x1808a3);}return _0x531032[_0xb814('0x2a')]();};}function saveUpdates(_0x27352e,_0x2bd039){return function(_0x1f5d40){if(_0x1f5d40){return _0x1f5d40['update'](_0x27352e)[_0xb814('0x2b')](function(_0x52b7a3){return _0x52b7a3;});}return null;};}function removeEntity(_0x3f81d0,_0x457dac){return function(_0x31c7ec){if(_0x31c7ec){return _0x31c7ec[_0xb814('0x2c')]()[_0xb814('0x2b')](function(){var _0xb9e57d=_0x31c7ec[_0xb814('0x2d')]({'plain':!![]});var _0x5755ea=_0xb814('0x2e');return db[_0xb814('0x2f')][_0xb814('0x2c')]({'where':{'type':_0x5755ea,'resourceId':_0xb9e57d['id']}})[_0xb814('0x2b')](function(){return _0x31c7ec;});})[_0xb814('0x2b')](function(){_0x3f81d0[_0xb814('0x22')](0xcc)[_0xb814('0x23')]();});}};}function handleEntityNotFound(_0x1e4e89,_0x5a6291){return function(_0x271aa8){if(!_0x271aa8){_0x1e4e89[_0xb814('0x21')](0x194);}return _0x271aa8;};}function handleError(_0x52ed64,_0x9008b2){_0x9008b2=_0x9008b2||0x1f4;return function(_0x37d24d){logger[_0xb814('0x30')](_0x37d24d['stack']);if(_0x37d24d[_0xb814('0x31')]){delete _0x37d24d[_0xb814('0x31')];}_0x52ed64['status'](_0x9008b2)[_0xb814('0x32')](_0x37d24d);};}exports['index']=function(_0x6efe9a,_0x5f3e9b){var _0x4cfc58={},_0x419cd9={},_0x4a4f27={'count':0x0,'rows':[]};var _0x2431e2=_[_0xb814('0x33')](db[_0xb814('0x34')]['rawAttributes'],function(_0x51d5ae){return{'name':_0x51d5ae[_0xb814('0x35')],'type':_0x51d5ae[_0xb814('0x36')]['key']};});_0x419cd9[_0xb814('0x37')]=_[_0xb814('0x33')](_0x2431e2,_0xb814('0x31'));_0x419cd9[_0xb814('0x38')]=_[_0xb814('0x39')](_0x6efe9a[_0xb814('0x38')]);_0x419cd9[_0xb814('0x3a')]=_['intersection'](_0x419cd9[_0xb814('0x37')],_0x419cd9[_0xb814('0x38')]);_0x4cfc58[_0xb814('0x3b')]=_[_0xb814('0x3c')](_0x419cd9[_0xb814('0x37')],qs['fields'](_0x6efe9a[_0xb814('0x38')]['fields']));_0x4cfc58[_0xb814('0x3b')]=_0x4cfc58[_0xb814('0x3b')][_0xb814('0x3d')]?_0x4cfc58['attributes']:_0x419cd9[_0xb814('0x37')];if(!_0x6efe9a[_0xb814('0x38')]['hasOwnProperty'](_0xb814('0x3e'))){_0x4cfc58[_0xb814('0x3f')]=qs[_0xb814('0x3f')](_0x6efe9a[_0xb814('0x38')][_0xb814('0x3f')]);_0x4cfc58[_0xb814('0x25')]=qs['offset'](_0x6efe9a[_0xb814('0x38')]['offset']);}_0x4cfc58[_0xb814('0x40')]=qs['sort'](_0x6efe9a[_0xb814('0x38')]['sort']);_0x4cfc58[_0xb814('0x41')]=qs[_0xb814('0x3a')](_['pick'](_0x6efe9a['query'],_0x419cd9['filters']),_0x2431e2);if(_0x6efe9a['query'][_0xb814('0x42')]){_0x4cfc58[_0xb814('0x41')]=_[_0xb814('0x43')](_0x4cfc58[_0xb814('0x41')],{'$or':_['map'](_0x2431e2,function(_0x47d782){if(_0x47d782[_0xb814('0x36')]!=='VIRTUAL'){var _0x2a93da={};_0x2a93da[_0x47d782[_0xb814('0x31')]]={'$like':'%'+_0x6efe9a[_0xb814('0x38')][_0xb814('0x42')]+'%'};return _0x2a93da;}})});}_0x4cfc58=_[_0xb814('0x43')]({},_0x4cfc58,_0x6efe9a[_0xb814('0x44')]);var _0x3b7f5a={'where':_0x4cfc58[_0xb814('0x41')]};return db[_0xb814('0x34')]['count'](_0x3b7f5a)['then'](function(_0x5d26be){_0x4a4f27[_0xb814('0x45')]=_0x5d26be;if(_0x6efe9a['query'][_0xb814('0x46')]){_0x4cfc58['include']=[{'all':!![]}];}return db[_0xb814('0x34')][_0xb814('0x47')](_0x4cfc58);})[_0xb814('0x2b')](function(_0x2e97cc){_0x4a4f27['rows']=_0x2e97cc;return _0x4a4f27;})[_0xb814('0x2b')](respondWithFilteredResult(_0x5f3e9b,_0x4cfc58))[_0xb814('0x48')](handleError(_0x5f3e9b,null));};exports[_0xb814('0x49')]=function(_0x22cf27,_0x7d92aa){var _0x450a08={'raw':!![],'where':{'id':_0x22cf27[_0xb814('0x4a')]['id']}},_0x534eb8={};_0x534eb8[_0xb814('0x37')]=_[_0xb814('0x39')](db[_0xb814('0x34')][_0xb814('0x4b')]);_0x534eb8[_0xb814('0x38')]=_[_0xb814('0x39')](_0x22cf27['query']);_0x534eb8['filters']=_[_0xb814('0x3c')](_0x534eb8[_0xb814('0x37')],_0x534eb8[_0xb814('0x38')]);_0x450a08[_0xb814('0x3b')]=_[_0xb814('0x3c')](_0x534eb8[_0xb814('0x37')],qs[_0xb814('0x4c')](_0x22cf27[_0xb814('0x38')][_0xb814('0x4c')]));_0x450a08[_0xb814('0x3b')]=_0x450a08[_0xb814('0x3b')]['length']?_0x450a08[_0xb814('0x3b')]:_0x534eb8[_0xb814('0x37')];if(_0x22cf27['query'][_0xb814('0x46')]){_0x450a08['include']=[{'all':!![]}];}_0x450a08=_[_0xb814('0x43')]({},_0x450a08,_0x22cf27[_0xb814('0x44')]);return db[_0xb814('0x34')][_0xb814('0x4d')](_0x450a08)[_0xb814('0x2b')](handleEntityNotFound(_0x7d92aa,null))[_0xb814('0x2b')](respondWithResult(_0x7d92aa,null))[_0xb814('0x48')](handleError(_0x7d92aa,null));};exports[_0xb814('0x4e')]=function(_0x32a397,_0x2a422a){return db['SmsQueue']['create'](_0x32a397[_0xb814('0x4f')],{})[_0xb814('0x2b')](function(_0x4156d8){var _0x3f8e29=_0x32a397[_0xb814('0x50')][_0xb814('0x2d')]({'plain':!![]});if(!_0x3f8e29)throw new Error(_0xb814('0x51'));if(_0x3f8e29['role']===_0xb814('0x50')){var _0x388324=_0x4156d8[_0xb814('0x2d')]({'plain':!![]});var _0x5a916d=_0xb814('0x2e');return db['UserProfileSection'][_0xb814('0x4d')]({'where':{'name':_0x5a916d,'userProfileId':_0x3f8e29['userProfileId']},'raw':!![]})[_0xb814('0x2b')](function(_0x3cf8f8){if(_0x3cf8f8&&_0x3cf8f8['autoAssociation']===0x0){return db[_0xb814('0x2f')][_0xb814('0x4e')]({'name':_0x388324[_0xb814('0x31')],'resourceId':_0x388324['id'],'type':_0x3cf8f8['name'],'sectionId':_0x3cf8f8['id']},{})[_0xb814('0x2b')](function(){return _0x4156d8;});}else{return _0x4156d8;}})['catch'](function(_0x13bdcf){logger[_0xb814('0x30')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x13bdcf);throw _0x13bdcf;});}return _0x4156d8;})[_0xb814('0x2b')](respondWithResult(_0x2a422a,0xc9))['catch'](handleError(_0x2a422a,null));};exports['update']=function(_0x3b9709,_0x35f59a){if(_0x3b9709[_0xb814('0x4f')]['id']){delete _0x3b9709['body']['id'];}return db[_0xb814('0x34')]['find']({'where':{'id':_0x3b9709[_0xb814('0x4a')]['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0x35f59a,null))['then'](saveUpdates(_0x3b9709[_0xb814('0x4f')],null))['then'](respondWithResult(_0x35f59a,null))[_0xb814('0x48')](handleError(_0x35f59a,null));};exports[_0xb814('0x2c')]=function(_0xb2bd82,_0x113fe5){return db[_0xb814('0x34')][_0xb814('0x4d')]({'where':{'id':_0xb2bd82[_0xb814('0x4a')]['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0x113fe5,null))['then'](removeEntity(_0x113fe5,null))[_0xb814('0x48')](handleError(_0x113fe5,null));};exports[_0xb814('0x52')]=function(_0x5d71d5,_0x29a127){return db[_0xb814('0x34')]['describe']()[_0xb814('0x2b')](respondWithResult(_0x29a127,null))['catch'](handleError(_0x29a127,null));};exports['getMembers']=function(_0x2114ca,_0x5257be,_0x3ff213){var _0xd1cd8b={'raw':!![],'where':{}},_0x2dec52={},_0x586957;return db[_0xb814('0x34')]['findOne']({'where':{'id':_0x2114ca[_0xb814('0x4a')]['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0x5257be,null))[_0xb814('0x2b')](function(_0x176585){if(_0x176585){_0x586957=_0x176585[_0xb814('0x2d')]({'plain':!![]});_0x2dec52[_0xb814('0x37')]=_[_0xb814('0x39')](db[_0xb814('0x53')][_0xb814('0x4b')]);_0x2dec52['query']=_[_0xb814('0x39')](_0x2114ca[_0xb814('0x38')]);_0x2dec52[_0xb814('0x3a')]=_[_0xb814('0x3c')](_0x2dec52[_0xb814('0x37')],_0x2dec52[_0xb814('0x38')]);_0xd1cd8b['attributes']=_[_0xb814('0x3c')](_0x2dec52['model'],qs[_0xb814('0x4c')](_0x2114ca[_0xb814('0x38')][_0xb814('0x4c')]));_0xd1cd8b['attributes']=_0xd1cd8b[_0xb814('0x3b')]['length']?_0xd1cd8b[_0xb814('0x3b')]:_0x2dec52['model'];if(!_0x2114ca[_0xb814('0x38')][_0xb814('0x54')](_0xb814('0x3e'))){_0xd1cd8b[_0xb814('0x3f')]=qs[_0xb814('0x3f')](_0x2114ca[_0xb814('0x38')][_0xb814('0x3f')]);_0xd1cd8b['offset']=qs[_0xb814('0x25')](_0x2114ca['query'][_0xb814('0x25')]);}_0xd1cd8b[_0xb814('0x40')]=qs[_0xb814('0x55')](_0x2114ca[_0xb814('0x38')][_0xb814('0x55')]);_0xd1cd8b[_0xb814('0x41')]=qs['filters'](_[_0xb814('0x56')](_0x2114ca[_0xb814('0x38')],_0x2dec52['filters']));_0xd1cd8b[_0xb814('0x41')][_0xb814('0x57')]=_0x176585['id'];if(_0x2114ca[_0xb814('0x38')][_0xb814('0x42')]){_0xd1cd8b[_0xb814('0x41')]=_['merge'](_0xd1cd8b[_0xb814('0x41')],{'$or':_['map'](_0xd1cd8b[_0xb814('0x3b')],function(_0x16f8f2){var _0x2645f6={};_0x2645f6[_0x16f8f2]={'$like':'%'+_0x2114ca[_0xb814('0x38')][_0xb814('0x42')]+'%'};return _0x2645f6;})});}_0xd1cd8b=_[_0xb814('0x43')]({},_0xd1cd8b,_0x2114ca['options']);return db['UserSmsQueue']['findAll'](_0xd1cd8b);}})[_0xb814('0x2b')](function(_0x490e5c){if(_0x490e5c){return db[_0xb814('0x58')][_0xb814('0x59')]({'where':{'id':_[_0xb814('0x33')](_0x490e5c,'UserId'),'role':_0xb814('0x5a')},'attributes':['id',_0xb814('0x31'),_0xb814('0x5b'),'updatedAt',_0xb814('0x5c')]});}})[_0xb814('0x2b')](function(_0x1f39c0){if(_0x1f39c0){return{'count':_0x1f39c0[_0xb814('0x45')],'rows':_['map'](_0x1f39c0['rows'],function(_0x28eaf8){return{'membername':_0x28eaf8[_0xb814('0x31')],'UserId':_0x28eaf8['id'],'queue_name':_0x586957[_0xb814('0x31')],'SmsQueueId':_0x586957['id'],'interface':util[_0xb814('0x5d')](_0xb814('0x5e'),_0xb814('0x5f'),_0x28eaf8[_0xb814('0x31')]),'penalty':0x0,'paused':_0x28eaf8[_0xb814('0x5b')],'createdAt':_0x28eaf8[_0xb814('0x5c')],'updatedAt':_0x28eaf8[_0xb814('0x60')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xb814('0x2b')](respondWithFilteredResult(_0x5257be,_0xd1cd8b))[_0xb814('0x48')](handleError(_0x5257be,null));};exports[_0xb814('0x61')]=function(_0x21fc41,_0xc94e99,_0x55a9c4){var _0x2332dc={};var _0x33cfc4={};var _0xfc9a65;var _0x357b90;return db[_0xb814('0x34')][_0xb814('0x62')]({'where':{'id':_0x21fc41['params']['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0xc94e99,null))['then'](function(_0x872d43){if(_0x872d43){_0xfc9a65=_0x872d43;_0x33cfc4[_0xb814('0x37')]=_[_0xb814('0x39')](db[_0xb814('0x63')][_0xb814('0x4b')]);_0x33cfc4['query']=_['keys'](_0x21fc41[_0xb814('0x38')]);_0x33cfc4[_0xb814('0x3a')]=_[_0xb814('0x3c')](_0x33cfc4[_0xb814('0x37')],_0x33cfc4['query']);_0x2332dc[_0xb814('0x3b')]=_['intersection'](_0x33cfc4[_0xb814('0x37')],qs[_0xb814('0x4c')](_0x21fc41['query']['fields']));_0x2332dc[_0xb814('0x3b')]=_0x2332dc['attributes'][_0xb814('0x3d')]?_0x2332dc[_0xb814('0x3b')]:_0x33cfc4[_0xb814('0x37')];_0x2332dc[_0xb814('0x40')]=qs[_0xb814('0x55')](_0x21fc41[_0xb814('0x38')][_0xb814('0x55')]);_0x2332dc['where']=qs[_0xb814('0x3a')](_['pick'](_0x21fc41[_0xb814('0x38')],_0x33cfc4['filters']));if(_0x21fc41[_0xb814('0x38')][_0xb814('0x42')]){_0x2332dc['where']=_[_0xb814('0x43')](_0x2332dc['where'],{'$or':_[_0xb814('0x33')](_0x2332dc[_0xb814('0x3b')],function(_0x4e15c2){var _0x5a0c4a={};_0x5a0c4a[_0x4e15c2]={'$like':'%'+_0x21fc41[_0xb814('0x38')][_0xb814('0x42')]+'%'};return _0x5a0c4a;})});}_0x2332dc=_[_0xb814('0x43')]({},_0x2332dc,_0x21fc41[_0xb814('0x44')]);return _0xfc9a65[_0xb814('0x61')](_0x2332dc);}})[_0xb814('0x2b')](function(_0x2b12a9){if(_0x2b12a9){_0x357b90=_0x2b12a9[_0xb814('0x3d')];if(!_0x21fc41[_0xb814('0x38')][_0xb814('0x54')]('nolimit')){_0x2332dc['limit']=qs['limit'](_0x21fc41['query']['limit']);_0x2332dc[_0xb814('0x25')]=qs[_0xb814('0x25')](_0x21fc41[_0xb814('0x38')]['offset']);}return _0xfc9a65[_0xb814('0x61')](_0x2332dc);}})[_0xb814('0x2b')](function(_0x31c072){if(_0x31c072){return _0x31c072?{'count':_0x357b90,'rows':_0x31c072}:null;}})[_0xb814('0x2b')](respondWithResult(_0xc94e99,null))[_0xb814('0x48')](handleError(_0xc94e99,null));};exports[_0xb814('0x64')]=function(_0x3367b8,_0x1d9f13,_0x5cf5ad){var _0x20efc3=_0x3367b8[_0xb814('0x4f')][_0xb814('0x65')];return db[_0xb814('0x63')]['findAll']({'where':{'id':_0x20efc3},'attributes':['id'],'include':[{'model':db[_0xb814('0x58')],'as':_0xb814('0x66'),'attributes':['id',_0xb814('0x31'),_0xb814('0x67'),_0xb814('0x68'),'interface'],'raw':!![]}]})['then'](function(_0x252f9c){if(_0x252f9c){var _0x57b3f2=_[_0xb814('0x69')](_0x252f9c,function(_0x3882f8){var _0x592aae=_0x3882f8[_0xb814('0x2d')]({'plain':!![]});return _0x592aae['Agents'];});return db[_0xb814('0x34')]['find']({'where':{'id':_0x3367b8[_0xb814('0x4a')]['id']}})[_0xb814('0x2b')](function(_0x41867b){return db[_0xb814('0x6a')][_0xb814('0x6b')](function(_0x1ae812){return _0x41867b[_0xb814('0x64')](_0x20efc3,{'transaction':_0x1ae812})['then'](function(){return BPromise['each'](_0x57b3f2,function(_0x21aa36){return db['UserSmsQueue']['findOrCreate']({'where':{'UserId':_0x21aa36['id'],'SmsQueueId':_0x3367b8[_0xb814('0x4a')]['id']},'transaction':_0x1ae812});});})[_0xb814('0x2b')](function(){_0x57b3f2[_0xb814('0x6c')](function(_0x57bf1b){socket[_0xb814('0x6d')]('userSmsQueue:save',{'UserId':_0x57bf1b['id'],'SmsQueueId':_0x41867b['id']});});});});});}})[_0xb814('0x2b')](respondWithStatusCode(_0x1d9f13,null))[_0xb814('0x48')](handleError(_0x1d9f13,null));};exports[_0xb814('0x6e')]=function(_0x2d2b6c,_0x4c8a00,_0x1454b3){return db[_0xb814('0x63')][_0xb814('0x47')]({'where':{'id':_0x2d2b6c['query'][_0xb814('0x65')]},'attributes':['id'],'include':[{'model':db[_0xb814('0x58')],'as':_0xb814('0x66'),'attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x4c8a00,null))[_0xb814('0x2b')](function(_0x2d0651){var _0x9dc06b=_[_0xb814('0x33')](_0x2d0651,'id');var _0x40b3c5=[];var _0x1ae8e8=[];var _0x37a7ab=squel[_0xb814('0x6f')]();_0x37a7ab[_0xb814('0x70')](_0xb814('0x71'))[_0xb814('0x72')](_0xb814('0x73'),'tq')[_0xb814('0x74')]('user_has_teams','ut','ut.TeamId\x20=\x20tq.TeamId')[_0xb814('0x41')]('SmsQueueId\x20=\x20?',_0x2d2b6c[_0xb814('0x4a')]['id']);for(var _0x3949fd=0x0;_0x3949fd<_0x2d0651[_0xb814('0x3d')];_0x3949fd+=0x1){let _0x2bc95b=_0x2d0651[_0x3949fd];for(var _0x405db7=0x0;_0x405db7<_0x2bc95b[_0xb814('0x66')][_0xb814('0x3d')];_0x405db7+=0x1){let _0x5db5d0=_0x2bc95b['Agents'][_0x405db7];var _0x3f6df9=_0x37a7ab['clone']();_0x3f6df9[_0xb814('0x41')](_0xb814('0x75'),_0x5db5d0['id']);_0x1ae8e8[_0xb814('0x76')](db['sequelize'][_0xb814('0x38')](_0x3f6df9[_0xb814('0x77')](),{'type':db[_0xb814('0x6a')][_0xb814('0x78')][_0xb814('0x79')]})['then'](function(_0x59425f){if(_0x59425f[_0xb814('0x3d')]===0x1){return _0x5db5d0['id'];}else{var _0x4ac8c5=_[_0xb814('0x7a')](_[_0xb814('0x33')](_0x59425f,_0xb814('0x7b')),function(_0x4b96a6){return _[_0xb814('0x7c')](_0x9dc06b,_0x4b96a6);});if(_0x4ac8c5){return _0x5db5d0['id'];}}}));}}return BPromise[_0xb814('0x7d')](_0x1ae8e8)['then'](function(_0x32562d){_0x40b3c5=_(_0x40b3c5)[_0xb814('0x7e')](_0x32562d)['compact']()[_0xb814('0x7f')]();return db[_0xb814('0x34')][_0xb814('0x4d')]({'where':{'id':_0x2d2b6c[_0xb814('0x4a')]['id']}})[_0xb814('0x2b')](function(_0x2ee22e){return db[_0xb814('0x6a')][_0xb814('0x6b')](function(_0xb115ba){return _0x2ee22e[_0xb814('0x6e')](_0x2d2b6c[_0xb814('0x38')][_0xb814('0x65')],{'transaction':_0xb115ba})['then'](function(){if(!_['isEmpty'](_0x40b3c5)){return _0x2ee22e[_0xb814('0x80')](_0x40b3c5,{'transaction':_0xb115ba});}})['then'](function(){_0x40b3c5['forEach'](function(_0x3f2ff9){socket['emit']('userSmsQueue:remove',{'UserId':_0x3f2ff9,'SmsQueueId':_0x2ee22e['id']});});});});});});})['then'](respondWithStatusCode(_0x4c8a00,null))[_0xb814('0x48')](handleError(_0x4c8a00,null));};exports[_0xb814('0x81')]=function(_0x3341f5,_0x5eb4b1,_0xa721d3){return db['SmsQueue'][_0xb814('0x4d')]({'where':{'id':_0x3341f5[_0xb814('0x4a')]['id']}})['then'](handleEntityNotFound(_0x5eb4b1,null))[_0xb814('0x2b')](function(_0x53467f){if(_0x53467f){return _0x53467f[_0xb814('0x81')](_0x3341f5[_0xb814('0x4f')][_0xb814('0x65')],_[_0xb814('0x82')](_0x3341f5[_0xb814('0x4f')],[_0xb814('0x65'),'id'])||{})[_0xb814('0x83')](function(_0x2b7abf){for(var _0x3a3b35=0x0;_0x3a3b35<_0x3341f5[_0xb814('0x4f')][_0xb814('0x65')][_0xb814('0x3d')];_0x3a3b35+=0x1){socket[_0xb814('0x6d')](_0xb814('0x84'),{'UserId':_0x3341f5[_0xb814('0x4f')]['ids'][_0x3a3b35],'SmsQueueId':_0x3341f5[_0xb814('0x4a')]['id']});}return _0x2b7abf;});}})[_0xb814('0x2b')](respondWithResult(_0x5eb4b1,null))['catch'](handleError(_0x5eb4b1,null));};exports[_0xb814('0x80')]=function(_0x552aae,_0x1868d9,_0x570191){return db['SmsQueue'][_0xb814('0x4d')]({'where':{'id':_0x552aae['params']['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0x1868d9,null))['then'](function(_0xdf3e07){if(_0xdf3e07){return _0xdf3e07['removeAgents'](_0x552aae['query'][_0xb814('0x65')])[_0xb814('0x2b')](function(){if(_[_0xb814('0x85')](_0x552aae[_0xb814('0x38')][_0xb814('0x65')])){for(var _0x4339a2=0x0;_0x4339a2<_0x552aae[_0xb814('0x38')][_0xb814('0x65')][_0xb814('0x3d')];_0x4339a2+=0x1){socket[_0xb814('0x6d')](_0xb814('0x86'),{'UserId':Number(_0x552aae['query'][_0xb814('0x65')][_0x4339a2]),'SmsQueueId':Number(_0x552aae['params']['id'])});}}else{socket[_0xb814('0x6d')](_0xb814('0x86'),{'UserId':Number(_0x552aae[_0xb814('0x38')]['ids']),'SmsQueueId':Number(_0x552aae[_0xb814('0x4a')]['id'])});}});}})[_0xb814('0x2b')](respondWithStatusCode(_0x1868d9,null))[_0xb814('0x48')](handleError(_0x1868d9,null));};exports[_0xb814('0x87')]=function(_0x290718,_0x2972b9,_0x26ce1a){var _0x44588a={};var _0x1462fb={};var _0x11d14f;var _0x3b65c0;return db[_0xb814('0x34')][_0xb814('0x62')]({'where':{'id':_0x290718[_0xb814('0x4a')]['id']}})[_0xb814('0x2b')](handleEntityNotFound(_0x2972b9,null))['then'](function(_0x37dec4){if(_0x37dec4){_0x11d14f=_0x37dec4;_0x1462fb[_0xb814('0x37')]=_[_0xb814('0x39')](db['User']['rawAttributes']);_0x1462fb[_0xb814('0x38')]=_['keys'](_0x290718['query']);_0x1462fb['filters']=_['intersection'](_0x1462fb[_0xb814('0x37')],_0x1462fb[_0xb814('0x38')]);_0x44588a['attributes']=_[_0xb814('0x3c')](_0x1462fb[_0xb814('0x37')],qs[_0xb814('0x4c')](_0x290718[_0xb814('0x38')][_0xb814('0x4c')]));_0x44588a[_0xb814('0x3b')]=_0x44588a[_0xb814('0x3b')][_0xb814('0x3d')]?_0x44588a[_0xb814('0x3b')]:_0x1462fb[_0xb814('0x37')];_0x44588a[_0xb814('0x40')]=qs['sort'](_0x290718[_0xb814('0x38')]['sort']);_0x44588a[_0xb814('0x41')]=qs[_0xb814('0x3a')](_[_0xb814('0x56')](_0x290718[_0xb814('0x38')],_0x1462fb[_0xb814('0x3a')]));if(_0x290718[_0xb814('0x38')][_0xb814('0x42')]){_0x44588a[_0xb814('0x41')]=_['merge'](_0x44588a['where'],{'$or':_['map'](_0x44588a[_0xb814('0x3b')],function(_0x4a2e90){var _0x1f49eb={};_0x1f49eb[_0x4a2e90]={'$like':'%'+_0x290718[_0xb814('0x38')][_0xb814('0x42')]+'%'};return _0x1f49eb;})});}_0x44588a=_[_0xb814('0x43')]({},_0x44588a,_0x290718[_0xb814('0x44')]);return _0x11d14f[_0xb814('0x87')](_0x44588a);}})[_0xb814('0x2b')](function(_0x1a5685){if(_0x1a5685){_0x3b65c0=_0x1a5685['length'];if(!_0x290718['query'][_0xb814('0x54')](_0xb814('0x3e'))){_0x44588a[_0xb814('0x3f')]=qs[_0xb814('0x3f')](_0x290718[_0xb814('0x38')][_0xb814('0x3f')]);_0x44588a['offset']=qs[_0xb814('0x25')](_0x290718['query'][_0xb814('0x25')]);}return _0x11d14f[_0xb814('0x87')](_0x44588a);}})[_0xb814('0x2b')](function(_0x94aa05){if(_0x94aa05){return _0x94aa05?{'count':_0x3b65c0,'rows':_0x94aa05}:null;}})[_0xb814('0x2b')](respondWithResult(_0x2972b9,null))[_0xb814('0x48')](handleError(_0x2972b9,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