Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / smsQueue / smsQueue.controller.js
index ac640f9..5124850 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xde6b=['./smsQueue.socket','sendStatus','status','end','json','undefined','offset','count','limit','set','Content-Range','save','update','then','SmsQueues','UserProfileResource','destroy','stack','name','send','index','map','rawAttributes','type','model','keys','query','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','pick','filters','filter','VIRTUAL','merge','options','SmsQueue','includeAll','include','findAll','catch','show','params','length','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','UserSmsQueue','order','SmsQueueId','findAndCountAll','agent','smsPause','createdAt','format','%s/%s','SIP','updatedAt','getTeams','Team','addTeams','ids','User','Agents','voicePause','interface','flatMap','transaction','each','findOrCreate','forEach','emit','userSmsQueue:save','removeTeams','field','from','join','ut.TeamId\x20=\x20tq.TeamId','SmsQueueId\x20=\x20?','ut.UserId\x20=\x20?','push','sequelize','toString','QueryTypes','SELECT','every','TeamId','includes','all','union','compact','value','isEmpty','removeAgents','userSmsQueue:remove','addAgents','spread','isArray','getAgents','zip-dir','request-promise','mustache','util','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','redis','defaults','socket.io-emitter'];(function(_0x3f1861,_0x7b4285){var _0x7ca70a=function(_0x119b09){while(--_0x119b09){_0x3f1861['push'](_0x3f1861['shift']());}};_0x7ca70a(++_0x7b4285);}(_0xde6b,0xf7));var _0xbde6=function(_0x4243a3,_0x447337){_0x4243a3=_0x4243a3-0x0;var _0x1b2a33=_0xde6b[_0x4243a3];return _0x1b2a33;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xbde6('0x0'));var jsonpatch=require('fast-json-patch');var rp=require(_0xbde6('0x1'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xbde6('0x2'));var util=require(_0xbde6('0x3'));var path=require(_0xbde6('0x4'));var sox=require(_0xbde6('0x5'));var csv=require('to-csv');var ejs=require(_0xbde6('0x6'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xbde6('0x7'));var squel=require(_0xbde6('0x8'));var crypto=require(_0xbde6('0x9'));var jsforce=require(_0xbde6('0xa'));var deskjs=require(_0xbde6('0xb'));var toCsv=require(_0xbde6('0xc'));var querystring=require(_0xbde6('0xd'));var Papa=require(_0xbde6('0xe'));var Redis=require(_0xbde6('0xf'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xbde6('0x10'));var hardwareService=require(_0xbde6('0x11'));var logger=require('../../config/logger')(_0xbde6('0x12'));var utils=require('../../config/utils');var config=require(_0xbde6('0x13'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0xbde6('0x14')]=_[_0xbde6('0x15')](config[_0xbde6('0x14')],{'host':'localhost','port':0x18eb});var socket=require(_0xbde6('0x16'))(new Redis(config[_0xbde6('0x14')]));require(_0xbde6('0x17'))['register'](socket);function respondWithStatusCode(_0x4c3071,_0x5511d5){_0x5511d5=_0x5511d5||0xcc;return function(_0x21543c){if(_0x21543c){return _0x4c3071[_0xbde6('0x18')](_0x5511d5);}return _0x4c3071[_0xbde6('0x19')](_0x5511d5)[_0xbde6('0x1a')]();};}function respondWithResult(_0x2d3f0b,_0x406597){_0x406597=_0x406597||0xc8;return function(_0xe7b109){if(_0xe7b109){return _0x2d3f0b['status'](_0x406597)[_0xbde6('0x1b')](_0xe7b109);}};}function respondWithFilteredResult(_0x5ec804,_0x386c54){return function(_0xd94e4b){if(_0xd94e4b){var _0x2b891f=typeof _0x386c54['offset']==='undefined'&&typeof _0x386c54['limit']===_0xbde6('0x1c');var _0x1595dd=_0xd94e4b['count'];var _0x561509=_0x2b891f?0x0:_0x386c54[_0xbde6('0x1d')];var _0x2853de=_0x2b891f?_0xd94e4b[_0xbde6('0x1e')]:_0x386c54[_0xbde6('0x1d')]+_0x386c54[_0xbde6('0x1f')];var _0x27a294;if(_0x2853de>=_0x1595dd){_0x2853de=_0x1595dd;_0x27a294=0xc8;}else{_0x27a294=0xce;}_0x5ec804[_0xbde6('0x19')](_0x27a294);return _0x5ec804[_0xbde6('0x20')](_0xbde6('0x21'),_0x561509+'-'+_0x2853de+'/'+_0x1595dd)[_0xbde6('0x1b')](_0xd94e4b);}return null;};}function patchUpdates(_0x4c73b6){return function(_0x238353){try{jsonpatch['apply'](_0x238353,_0x4c73b6,!![]);}catch(_0x4b8426){return BPromise['reject'](_0x4b8426);}return _0x238353[_0xbde6('0x22')]();};}function saveUpdates(_0x11c403,_0x4fe6a8){return function(_0x1abbb4){if(_0x1abbb4){return _0x1abbb4[_0xbde6('0x23')](_0x11c403)[_0xbde6('0x24')](function(_0x21ae4c){return _0x21ae4c;});}return null;};}function removeEntity(_0x5d54bf,_0x2e9c1d){return function(_0x182d77){if(_0x182d77){return _0x182d77['destroy']()[_0xbde6('0x24')](function(){var _0x595f4e=_0x182d77['get']({'plain':!![]});var _0x53c0db=_0xbde6('0x25');return db[_0xbde6('0x26')][_0xbde6('0x27')]({'where':{'type':_0x53c0db,'resourceId':_0x595f4e['id']}})['then'](function(){return _0x182d77;});})[_0xbde6('0x24')](function(){_0x5d54bf[_0xbde6('0x19')](0xcc)[_0xbde6('0x1a')]();});}};}function handleEntityNotFound(_0x54c91b,_0x23e5d5){return function(_0x421ac7){if(!_0x421ac7){_0x54c91b[_0xbde6('0x18')](0x194);}return _0x421ac7;};}function handleError(_0x3476cb,_0x541f71){_0x541f71=_0x541f71||0x1f4;return function(_0x4761b2){logger['error'](_0x4761b2[_0xbde6('0x28')]);if(_0x4761b2[_0xbde6('0x29')]){delete _0x4761b2[_0xbde6('0x29')];}_0x3476cb[_0xbde6('0x19')](_0x541f71)[_0xbde6('0x2a')](_0x4761b2);};}exports[_0xbde6('0x2b')]=function(_0x163345,_0x381ba7){var _0x715420={},_0x55f9a8={},_0x246e86={'count':0x0,'rows':[]};var _0x9360bc=_[_0xbde6('0x2c')](db['SmsQueue'][_0xbde6('0x2d')],function(_0x862690){return{'name':_0x862690['fieldName'],'type':_0x862690[_0xbde6('0x2e')]['key']};});_0x55f9a8[_0xbde6('0x2f')]=_[_0xbde6('0x2c')](_0x9360bc,_0xbde6('0x29'));_0x55f9a8['query']=_[_0xbde6('0x30')](_0x163345[_0xbde6('0x31')]);_0x55f9a8['filters']=_[_0xbde6('0x32')](_0x55f9a8[_0xbde6('0x2f')],_0x55f9a8[_0xbde6('0x31')]);_0x715420[_0xbde6('0x33')]=_[_0xbde6('0x32')](_0x55f9a8[_0xbde6('0x2f')],qs[_0xbde6('0x34')](_0x163345[_0xbde6('0x31')][_0xbde6('0x34')]));_0x715420[_0xbde6('0x33')]=_0x715420[_0xbde6('0x33')]['length']?_0x715420[_0xbde6('0x33')]:_0x55f9a8[_0xbde6('0x2f')];if(!_0x163345[_0xbde6('0x31')][_0xbde6('0x35')](_0xbde6('0x36'))){_0x715420[_0xbde6('0x1f')]=qs[_0xbde6('0x1f')](_0x163345['query']['limit']);_0x715420['offset']=qs[_0xbde6('0x1d')](_0x163345[_0xbde6('0x31')]['offset']);}_0x715420['order']=qs[_0xbde6('0x37')](_0x163345[_0xbde6('0x31')][_0xbde6('0x37')]);_0x715420[_0xbde6('0x38')]=qs['filters'](_[_0xbde6('0x39')](_0x163345[_0xbde6('0x31')],_0x55f9a8[_0xbde6('0x3a')]),_0x9360bc);if(_0x163345[_0xbde6('0x31')][_0xbde6('0x3b')]){_0x715420[_0xbde6('0x38')]=_['merge'](_0x715420[_0xbde6('0x38')],{'$or':_[_0xbde6('0x2c')](_0x9360bc,function(_0x293548){if(_0x293548[_0xbde6('0x2e')]!==_0xbde6('0x3c')){var _0x2735bb={};_0x2735bb[_0x293548['name']]={'$like':'%'+_0x163345['query'][_0xbde6('0x3b')]+'%'};return _0x2735bb;}})});}_0x715420=_[_0xbde6('0x3d')]({},_0x715420,_0x163345[_0xbde6('0x3e')]);var _0xb1f7e5={'where':_0x715420['where']};return db[_0xbde6('0x3f')][_0xbde6('0x1e')](_0xb1f7e5)[_0xbde6('0x24')](function(_0x2ce969){_0x246e86[_0xbde6('0x1e')]=_0x2ce969;if(_0x163345[_0xbde6('0x31')][_0xbde6('0x40')]){_0x715420[_0xbde6('0x41')]=[{'all':!![]}];}return db[_0xbde6('0x3f')][_0xbde6('0x42')](_0x715420);})[_0xbde6('0x24')](function(_0x2dd52e){_0x246e86['rows']=_0x2dd52e;return _0x246e86;})[_0xbde6('0x24')](respondWithFilteredResult(_0x381ba7,_0x715420))[_0xbde6('0x43')](handleError(_0x381ba7,null));};exports[_0xbde6('0x44')]=function(_0x3e1139,_0x574be8){var _0x4e040b={'raw':!![],'where':{'id':_0x3e1139[_0xbde6('0x45')]['id']}},_0x3195da={};_0x3195da[_0xbde6('0x2f')]=_['keys'](db[_0xbde6('0x3f')][_0xbde6('0x2d')]);_0x3195da[_0xbde6('0x31')]=_['keys'](_0x3e1139['query']);_0x3195da['filters']=_['intersection'](_0x3195da['model'],_0x3195da[_0xbde6('0x31')]);_0x4e040b[_0xbde6('0x33')]=_[_0xbde6('0x32')](_0x3195da['model'],qs[_0xbde6('0x34')](_0x3e1139[_0xbde6('0x31')][_0xbde6('0x34')]));_0x4e040b[_0xbde6('0x33')]=_0x4e040b[_0xbde6('0x33')][_0xbde6('0x46')]?_0x4e040b[_0xbde6('0x33')]:_0x3195da[_0xbde6('0x2f')];if(_0x3e1139[_0xbde6('0x31')]['includeAll']){_0x4e040b['include']=[{'all':!![]}];}_0x4e040b=_[_0xbde6('0x3d')]({},_0x4e040b,_0x3e1139['options']);return db['SmsQueue'][_0xbde6('0x47')](_0x4e040b)['then'](handleEntityNotFound(_0x574be8,null))[_0xbde6('0x24')](respondWithResult(_0x574be8,null))[_0xbde6('0x43')](handleError(_0x574be8,null));};exports[_0xbde6('0x48')]=function(_0x470b33,_0x13229b){return db['SmsQueue'][_0xbde6('0x48')](_0x470b33[_0xbde6('0x49')],{})[_0xbde6('0x24')](function(_0x1be552){var _0x5c1072=_0x470b33['user']['get']({'plain':!![]});if(!_0x5c1072)throw new Error(_0xbde6('0x4a'));if(_0x5c1072['role']===_0xbde6('0x4b')){var _0x3b9edc=_0x1be552['get']({'plain':!![]});var _0x160364=_0xbde6('0x25');return db[_0xbde6('0x4c')]['find']({'where':{'name':_0x160364,'userProfileId':_0x5c1072[_0xbde6('0x4d')]},'raw':!![]})[_0xbde6('0x24')](function(_0x45b75f){if(_0x45b75f&&_0x45b75f[_0xbde6('0x4e')]===0x0){return db[_0xbde6('0x26')][_0xbde6('0x48')]({'name':_0x3b9edc[_0xbde6('0x29')],'resourceId':_0x3b9edc['id'],'type':_0x45b75f[_0xbde6('0x29')],'sectionId':_0x45b75f['id']},{})['then'](function(){return _0x1be552;});}else{return _0x1be552;}})['catch'](function(_0x1cd36f){logger[_0xbde6('0x4f')](_0xbde6('0x50'),_0x1cd36f);throw _0x1cd36f;});}return _0x1be552;})[_0xbde6('0x24')](respondWithResult(_0x13229b,0xc9))[_0xbde6('0x43')](handleError(_0x13229b,null));};exports[_0xbde6('0x23')]=function(_0x27bf31,_0x47201b){if(_0x27bf31[_0xbde6('0x49')]['id']){delete _0x27bf31[_0xbde6('0x49')]['id'];}return db[_0xbde6('0x3f')][_0xbde6('0x47')]({'where':{'id':_0x27bf31['params']['id']}})[_0xbde6('0x24')](handleEntityNotFound(_0x47201b,null))[_0xbde6('0x24')](saveUpdates(_0x27bf31[_0xbde6('0x49')],null))['then'](respondWithResult(_0x47201b,null))['catch'](handleError(_0x47201b,null));};exports['destroy']=function(_0xb2a6d4,_0x32b714){return db['SmsQueue']['find']({'where':{'id':_0xb2a6d4[_0xbde6('0x45')]['id']}})[_0xbde6('0x24')](handleEntityNotFound(_0x32b714,null))[_0xbde6('0x24')](removeEntity(_0x32b714,null))['catch'](handleError(_0x32b714,null));};exports[_0xbde6('0x51')]=function(_0x59fdb8,_0x3225a9){return db[_0xbde6('0x3f')][_0xbde6('0x51')]()[_0xbde6('0x24')](respondWithResult(_0x3225a9,null))[_0xbde6('0x43')](handleError(_0x3225a9,null));};exports[_0xbde6('0x52')]=function(_0x176db5,_0x2464b7,_0x39873a){var _0x102074={'raw':!![],'where':{}},_0x3dfd44={},_0x5de829;return db[_0xbde6('0x3f')]['findOne']({'where':{'id':_0x176db5['params']['id']}})['then'](handleEntityNotFound(_0x2464b7,null))['then'](function(_0x492609){if(_0x492609){_0x5de829=_0x492609['get']({'plain':!![]});_0x3dfd44[_0xbde6('0x2f')]=_[_0xbde6('0x30')](db[_0xbde6('0x53')][_0xbde6('0x2d')]);_0x3dfd44[_0xbde6('0x31')]=_[_0xbde6('0x30')](_0x176db5[_0xbde6('0x31')]);_0x3dfd44[_0xbde6('0x3a')]=_[_0xbde6('0x32')](_0x3dfd44[_0xbde6('0x2f')],_0x3dfd44[_0xbde6('0x31')]);_0x102074['attributes']=_[_0xbde6('0x32')](_0x3dfd44[_0xbde6('0x2f')],qs[_0xbde6('0x34')](_0x176db5[_0xbde6('0x31')][_0xbde6('0x34')]));_0x102074[_0xbde6('0x33')]=_0x102074[_0xbde6('0x33')]['length']?_0x102074[_0xbde6('0x33')]:_0x3dfd44[_0xbde6('0x2f')];if(!_0x176db5[_0xbde6('0x31')]['hasOwnProperty']('nolimit')){_0x102074['limit']=qs[_0xbde6('0x1f')](_0x176db5['query'][_0xbde6('0x1f')]);_0x102074[_0xbde6('0x1d')]=qs['offset'](_0x176db5['query'][_0xbde6('0x1d')]);}_0x102074[_0xbde6('0x54')]=qs[_0xbde6('0x37')](_0x176db5['query']['sort']);_0x102074[_0xbde6('0x38')]=qs[_0xbde6('0x3a')](_[_0xbde6('0x39')](_0x176db5[_0xbde6('0x31')],_0x3dfd44[_0xbde6('0x3a')]));_0x102074['where'][_0xbde6('0x55')]=_0x492609['id'];if(_0x176db5[_0xbde6('0x31')][_0xbde6('0x3b')]){_0x102074['where']=_[_0xbde6('0x3d')](_0x102074['where'],{'$or':_[_0xbde6('0x2c')](_0x102074[_0xbde6('0x33')],function(_0x828f2e){var _0xe7998={};_0xe7998[_0x828f2e]={'$like':'%'+_0x176db5[_0xbde6('0x31')]['filter']+'%'};return _0xe7998;})});}_0x102074=_['merge']({},_0x102074,_0x176db5['options']);return db[_0xbde6('0x53')]['findAll'](_0x102074);}})[_0xbde6('0x24')](function(_0x2e2179){if(_0x2e2179){return db['User'][_0xbde6('0x56')]({'where':{'id':_[_0xbde6('0x2c')](_0x2e2179,'UserId'),'role':_0xbde6('0x57')},'attributes':['id',_0xbde6('0x29'),_0xbde6('0x58'),'updatedAt',_0xbde6('0x59')]});}})[_0xbde6('0x24')](function(_0x4c55f3){if(_0x4c55f3){return{'count':_0x4c55f3[_0xbde6('0x1e')],'rows':_[_0xbde6('0x2c')](_0x4c55f3['rows'],function(_0x18d406){return{'membername':_0x18d406['name'],'UserId':_0x18d406['id'],'queue_name':_0x5de829['name'],'SmsQueueId':_0x5de829['id'],'interface':util[_0xbde6('0x5a')](_0xbde6('0x5b'),_0xbde6('0x5c'),_0x18d406[_0xbde6('0x29')]),'penalty':0x0,'paused':_0x18d406[_0xbde6('0x58')],'createdAt':_0x18d406[_0xbde6('0x59')],'updatedAt':_0x18d406[_0xbde6('0x5d')]};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x2464b7,_0x102074))[_0xbde6('0x43')](handleError(_0x2464b7,null));};exports[_0xbde6('0x5e')]=function(_0x20fa10,_0x3a8b60,_0xf131c2){var _0x13ddff={};var _0x377474={};var _0x27787d;var _0x48a369;return db[_0xbde6('0x3f')]['findOne']({'where':{'id':_0x20fa10[_0xbde6('0x45')]['id']}})[_0xbde6('0x24')](handleEntityNotFound(_0x3a8b60,null))[_0xbde6('0x24')](function(_0x379f23){if(_0x379f23){_0x27787d=_0x379f23;_0x377474[_0xbde6('0x2f')]=_[_0xbde6('0x30')](db[_0xbde6('0x5f')]['rawAttributes']);_0x377474[_0xbde6('0x31')]=_[_0xbde6('0x30')](_0x20fa10[_0xbde6('0x31')]);_0x377474[_0xbde6('0x3a')]=_[_0xbde6('0x32')](_0x377474[_0xbde6('0x2f')],_0x377474['query']);_0x13ddff[_0xbde6('0x33')]=_[_0xbde6('0x32')](_0x377474['model'],qs[_0xbde6('0x34')](_0x20fa10[_0xbde6('0x31')][_0xbde6('0x34')]));_0x13ddff[_0xbde6('0x33')]=_0x13ddff[_0xbde6('0x33')][_0xbde6('0x46')]?_0x13ddff[_0xbde6('0x33')]:_0x377474[_0xbde6('0x2f')];_0x13ddff[_0xbde6('0x54')]=qs[_0xbde6('0x37')](_0x20fa10[_0xbde6('0x31')][_0xbde6('0x37')]);_0x13ddff['where']=qs[_0xbde6('0x3a')](_[_0xbde6('0x39')](_0x20fa10['query'],_0x377474[_0xbde6('0x3a')]));if(_0x20fa10[_0xbde6('0x31')][_0xbde6('0x3b')]){_0x13ddff[_0xbde6('0x38')]=_[_0xbde6('0x3d')](_0x13ddff[_0xbde6('0x38')],{'$or':_[_0xbde6('0x2c')](_0x13ddff[_0xbde6('0x33')],function(_0x3f4b71){var _0x512060={};_0x512060[_0x3f4b71]={'$like':'%'+_0x20fa10['query']['filter']+'%'};return _0x512060;})});}_0x13ddff=_['merge']({},_0x13ddff,_0x20fa10['options']);return _0x27787d[_0xbde6('0x5e')](_0x13ddff);}})[_0xbde6('0x24')](function(_0x2a7d5c){if(_0x2a7d5c){_0x48a369=_0x2a7d5c['length'];if(!_0x20fa10['query'][_0xbde6('0x35')](_0xbde6('0x36'))){_0x13ddff['limit']=qs['limit'](_0x20fa10[_0xbde6('0x31')][_0xbde6('0x1f')]);_0x13ddff[_0xbde6('0x1d')]=qs['offset'](_0x20fa10['query']['offset']);}return _0x27787d[_0xbde6('0x5e')](_0x13ddff);}})[_0xbde6('0x24')](function(_0x342be4){if(_0x342be4){return _0x342be4?{'count':_0x48a369,'rows':_0x342be4}:null;}})['then'](respondWithResult(_0x3a8b60,null))['catch'](handleError(_0x3a8b60,null));};exports[_0xbde6('0x60')]=function(_0x2125fc,_0x34f284,_0x32a135){var _0x4303a7=_0x2125fc[_0xbde6('0x49')][_0xbde6('0x61')];return db[_0xbde6('0x5f')][_0xbde6('0x42')]({'where':{'id':_0x4303a7},'attributes':['id'],'include':[{'model':db[_0xbde6('0x62')],'as':_0xbde6('0x63'),'attributes':['id',_0xbde6('0x29'),'online',_0xbde6('0x64'),_0xbde6('0x65')],'raw':!![]}]})[_0xbde6('0x24')](function(_0x5bca05){if(_0x5bca05){var _0x500c22=_[_0xbde6('0x66')](_0x5bca05,function(_0x3f6ec6){var _0x504f7e=_0x3f6ec6['get']({'plain':!![]});return _0x504f7e['Agents'];});return db[_0xbde6('0x3f')]['find']({'where':{'id':_0x2125fc['params']['id']}})['then'](function(_0x5b1584){return db['sequelize'][_0xbde6('0x67')](function(_0x3c0e69){return _0x5b1584[_0xbde6('0x60')](_0x4303a7,{'transaction':_0x3c0e69})[_0xbde6('0x24')](function(){return BPromise[_0xbde6('0x68')](_0x500c22,function(_0xadfe59){return db[_0xbde6('0x53')][_0xbde6('0x69')]({'where':{'UserId':_0xadfe59['id'],'SmsQueueId':_0x2125fc['params']['id']},'transaction':_0x3c0e69});});})[_0xbde6('0x24')](function(){_0x500c22[_0xbde6('0x6a')](function(_0x5aa8c6){socket[_0xbde6('0x6b')](_0xbde6('0x6c'),{'UserId':_0x5aa8c6['id'],'SmsQueueId':_0x5b1584['id']});});});});});}})['then'](respondWithStatusCode(_0x34f284,null))[_0xbde6('0x43')](handleError(_0x34f284,null));};exports[_0xbde6('0x6d')]=function(_0x228149,_0x1d3481,_0x538d7e){return db[_0xbde6('0x5f')][_0xbde6('0x42')]({'where':{'id':_0x228149[_0xbde6('0x31')][_0xbde6('0x61')]},'attributes':['id'],'include':[{'model':db[_0xbde6('0x62')],'as':'Agents','attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x1d3481,null))['then'](function(_0x1965b5){var _0x388407=_[_0xbde6('0x2c')](_0x1965b5,'id');var _0x479f07=[];var _0x254244=[];var _0xffb91=squel['select']();_0xffb91[_0xbde6('0x6e')]('tq.TeamId')[_0xbde6('0x6f')]('team_has_sms_queues','tq')[_0xbde6('0x70')]('user_has_teams','ut',_0xbde6('0x71'))[_0xbde6('0x38')](_0xbde6('0x72'),_0x228149['params']['id']);for(var _0x129e9c=0x0;_0x129e9c<_0x1965b5[_0xbde6('0x46')];_0x129e9c+=0x1){let _0x46d5fc=_0x1965b5[_0x129e9c];for(var _0x34704f=0x0;_0x34704f<_0x46d5fc['Agents'][_0xbde6('0x46')];_0x34704f+=0x1){let _0x5b23aa=_0x46d5fc['Agents'][_0x34704f];var _0x502aaf=_0xffb91['clone']();_0x502aaf[_0xbde6('0x38')](_0xbde6('0x73'),_0x5b23aa['id']);_0x254244[_0xbde6('0x74')](db[_0xbde6('0x75')][_0xbde6('0x31')](_0x502aaf[_0xbde6('0x76')](),{'type':db[_0xbde6('0x75')][_0xbde6('0x77')][_0xbde6('0x78')]})[_0xbde6('0x24')](function(_0x7745a1){if(_0x7745a1[_0xbde6('0x46')]===0x1){return _0x5b23aa['id'];}else{var _0x2fefdc=_[_0xbde6('0x79')](_[_0xbde6('0x2c')](_0x7745a1,_0xbde6('0x7a')),function(_0x40e8b7){return _[_0xbde6('0x7b')](_0x388407,_0x40e8b7);});if(_0x2fefdc){return _0x5b23aa['id'];}}}));}}return BPromise[_0xbde6('0x7c')](_0x254244)[_0xbde6('0x24')](function(_0xd65a29){_0x479f07=_(_0x479f07)[_0xbde6('0x7d')](_0xd65a29)[_0xbde6('0x7e')]()[_0xbde6('0x7f')]();return db[_0xbde6('0x3f')][_0xbde6('0x47')]({'where':{'id':_0x228149[_0xbde6('0x45')]['id']}})[_0xbde6('0x24')](function(_0x45a235){return db['sequelize'][_0xbde6('0x67')](function(_0x1254f2){return _0x45a235[_0xbde6('0x6d')](_0x228149['query']['ids'],{'transaction':_0x1254f2})['then'](function(){if(!_[_0xbde6('0x80')](_0x479f07)){return _0x45a235[_0xbde6('0x81')](_0x479f07,{'transaction':_0x1254f2});}})['then'](function(){_0x479f07[_0xbde6('0x6a')](function(_0x4747f8){socket[_0xbde6('0x6b')](_0xbde6('0x82'),{'UserId':_0x4747f8,'SmsQueueId':_0x45a235['id']});});});});});});})[_0xbde6('0x24')](respondWithStatusCode(_0x1d3481,null))['catch'](handleError(_0x1d3481,null));};exports[_0xbde6('0x83')]=function(_0x24e690,_0x30ae75,_0x5d4034){return db[_0xbde6('0x3f')]['find']({'where':{'id':_0x24e690[_0xbde6('0x45')]['id']}})[_0xbde6('0x24')](handleEntityNotFound(_0x30ae75,null))['then'](function(_0xba87a8){if(_0xba87a8){return _0xba87a8[_0xbde6('0x83')](_0x24e690[_0xbde6('0x49')][_0xbde6('0x61')],_['omit'](_0x24e690[_0xbde6('0x49')],[_0xbde6('0x61'),'id'])||{})[_0xbde6('0x84')](function(_0x13946e){for(var _0x21faf6=0x0;_0x21faf6<_0x24e690[_0xbde6('0x49')][_0xbde6('0x61')][_0xbde6('0x46')];_0x21faf6+=0x1){socket[_0xbde6('0x6b')](_0xbde6('0x6c'),{'UserId':_0x24e690[_0xbde6('0x49')][_0xbde6('0x61')][_0x21faf6],'SmsQueueId':_0x24e690['params']['id']});}return _0x13946e;});}})[_0xbde6('0x24')](respondWithResult(_0x30ae75,null))[_0xbde6('0x43')](handleError(_0x30ae75,null));};exports[_0xbde6('0x81')]=function(_0x210ecd,_0x788b8f,_0x5b7d17){return db[_0xbde6('0x3f')][_0xbde6('0x47')]({'where':{'id':_0x210ecd[_0xbde6('0x45')]['id']}})['then'](handleEntityNotFound(_0x788b8f,null))[_0xbde6('0x24')](function(_0x451972){if(_0x451972){return _0x451972[_0xbde6('0x81')](_0x210ecd[_0xbde6('0x31')]['ids'])[_0xbde6('0x24')](function(){if(_[_0xbde6('0x85')](_0x210ecd[_0xbde6('0x31')][_0xbde6('0x61')])){for(var _0x29ecda=0x0;_0x29ecda<_0x210ecd['query']['ids'][_0xbde6('0x46')];_0x29ecda+=0x1){socket[_0xbde6('0x6b')]('userSmsQueue:remove',{'UserId':Number(_0x210ecd[_0xbde6('0x31')][_0xbde6('0x61')][_0x29ecda]),'SmsQueueId':Number(_0x210ecd['params']['id'])});}}else{socket[_0xbde6('0x6b')]('userSmsQueue:remove',{'UserId':Number(_0x210ecd[_0xbde6('0x31')][_0xbde6('0x61')]),'SmsQueueId':Number(_0x210ecd[_0xbde6('0x45')]['id'])});}});}})[_0xbde6('0x24')](respondWithStatusCode(_0x788b8f,null))['catch'](handleError(_0x788b8f,null));};exports[_0xbde6('0x86')]=function(_0x4da838,_0x2774bb,_0x33a44b){var _0x5cf214={};var _0x3c2079={};var _0x239dab;var _0x58da3b;return db[_0xbde6('0x3f')]['findOne']({'where':{'id':_0x4da838[_0xbde6('0x45')]['id']}})[_0xbde6('0x24')](handleEntityNotFound(_0x2774bb,null))[_0xbde6('0x24')](function(_0x369627){if(_0x369627){_0x239dab=_0x369627;_0x3c2079[_0xbde6('0x2f')]=_['keys'](db[_0xbde6('0x62')][_0xbde6('0x2d')]);_0x3c2079['query']=_['keys'](_0x4da838[_0xbde6('0x31')]);_0x3c2079[_0xbde6('0x3a')]=_[_0xbde6('0x32')](_0x3c2079[_0xbde6('0x2f')],_0x3c2079[_0xbde6('0x31')]);_0x5cf214[_0xbde6('0x33')]=_[_0xbde6('0x32')](_0x3c2079[_0xbde6('0x2f')],qs['fields'](_0x4da838['query']['fields']));_0x5cf214[_0xbde6('0x33')]=_0x5cf214[_0xbde6('0x33')][_0xbde6('0x46')]?_0x5cf214[_0xbde6('0x33')]:_0x3c2079['model'];_0x5cf214[_0xbde6('0x54')]=qs['sort'](_0x4da838[_0xbde6('0x31')][_0xbde6('0x37')]);_0x5cf214['where']=qs[_0xbde6('0x3a')](_[_0xbde6('0x39')](_0x4da838[_0xbde6('0x31')],_0x3c2079['filters']));if(_0x4da838[_0xbde6('0x31')][_0xbde6('0x3b')]){_0x5cf214['where']=_[_0xbde6('0x3d')](_0x5cf214['where'],{'$or':_[_0xbde6('0x2c')](_0x5cf214[_0xbde6('0x33')],function(_0x4a3cf0){var _0x5ce12e={};_0x5ce12e[_0x4a3cf0]={'$like':'%'+_0x4da838[_0xbde6('0x31')][_0xbde6('0x3b')]+'%'};return _0x5ce12e;})});}_0x5cf214=_[_0xbde6('0x3d')]({},_0x5cf214,_0x4da838[_0xbde6('0x3e')]);return _0x239dab[_0xbde6('0x86')](_0x5cf214);}})[_0xbde6('0x24')](function(_0x313429){if(_0x313429){_0x58da3b=_0x313429[_0xbde6('0x46')];if(!_0x4da838[_0xbde6('0x31')][_0xbde6('0x35')](_0xbde6('0x36'))){_0x5cf214[_0xbde6('0x1f')]=qs[_0xbde6('0x1f')](_0x4da838[_0xbde6('0x31')][_0xbde6('0x1f')]);_0x5cf214[_0xbde6('0x1d')]=qs[_0xbde6('0x1d')](_0x4da838[_0xbde6('0x31')]['offset']);}return _0x239dab[_0xbde6('0x86')](_0x5cf214);}})[_0xbde6('0x24')](function(_0x1fcbca){if(_0x1fcbca){return _0x1fcbca?{'count':_0x58da3b,'rows':_0x1fcbca}:null;}})[_0xbde6('0x24')](respondWithResult(_0x2774bb,null))[_0xbde6('0x43')](handleError(_0x2774bb,null));};
\ No newline at end of file
+var _0xadb5=['%s/%s','pick','filter','getTeams','addTeams','ids','findAll','online','voicePause','interface','flatMap','Agents','sequelize','transaction','each','forEach','userSmsQueue:save','removeTeams','Team','field','tq.TeamId','from','team_has_sms_queues','join','ut.TeamId\x20=\x20tq.TeamId','SmsQueueId\x20=\x20?','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','all','union','compact','value','find','isEmpty','removeAgents','emit','userSmsQueue:remove','addAgents','omit','spread','isArray','getAgents','util','squel','ioredis','../../components/parsers/qs','api','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./smsQueue.socket','register','sendStatus','status','end','json','offset','limit','undefined','set','Content-Range','update','then','destroy','SmsQueues','UserProfileResource','error','stack','name','send','index','SmsQueue','rawAttributes','type','key','getOptions','where','count','include','query','rows','catch','show','model','keys','filters','fields','attributes','length','includeAll','options','create','user','get','role','autoAssociation','body','params','describe','getMembers','findOne','intersection','hasOwnProperty','nolimit','order','sort','SmsQueueId','merge','UserSmsQueue','User','findAndCountAll','map','UserId','agent','smsPause','updatedAt','createdAt','format'];(function(_0x2b55b5,_0x78505e){var _0x103d28=function(_0x5095a2){while(--_0x5095a2){_0x2b55b5['push'](_0x2b55b5['shift']());}};_0x103d28(++_0x78505e);}(_0xadb5,0xad));var _0x5adb=function(_0x1b3e9e,_0x299251){_0x1b3e9e=_0x1b3e9e-0x0;var _0x588359=_0xadb5[_0x1b3e9e];return _0x588359;};'use strict';var BPromise=require('bluebird');var util=require(_0x5adb('0x0'));var _=require('lodash');var squel=require(_0x5adb('0x1'));var Redis=require(_0x5adb('0x2'));var qs=require(_0x5adb('0x3'));var logger=require('../../config/logger')(_0x5adb('0x4'));var config=require(_0x5adb('0x5'));var db=require(_0x5adb('0x6'))['db'];config['redis']=_[_0x5adb('0x7')](config[_0x5adb('0x8')],{'host':_0x5adb('0x9'),'port':0x18eb});var socket=require(_0x5adb('0xa'))(new Redis(config[_0x5adb('0x8')]));require(_0x5adb('0xb'))[_0x5adb('0xc')](socket);function respondWithStatusCode(_0x6d1b45,_0x41261c){_0x41261c=_0x41261c||0xcc;return function(_0x7293ab){if(_0x7293ab){return _0x6d1b45[_0x5adb('0xd')](_0x41261c);}return _0x6d1b45[_0x5adb('0xe')](_0x41261c)[_0x5adb('0xf')]();};}function respondWithResult(_0x275428,_0x563d86){_0x563d86=_0x563d86||0xc8;return function(_0x4c268d){if(_0x4c268d){return _0x275428[_0x5adb('0xe')](_0x563d86)[_0x5adb('0x10')](_0x4c268d);}};}function respondWithFilteredResult(_0x82e67e,_0x53b772){return function(_0x29f0d5){if(_0x29f0d5){var _0x56012f=typeof _0x53b772[_0x5adb('0x11')]==='undefined'&&typeof _0x53b772[_0x5adb('0x12')]===_0x5adb('0x13');var _0x44abe3=_0x29f0d5['count'];var _0x2a545b=_0x56012f?0x0:_0x53b772[_0x5adb('0x11')];var _0xf82f72=_0x56012f?_0x29f0d5['count']:_0x53b772[_0x5adb('0x11')]+_0x53b772['limit'];var _0x367d82;if(_0xf82f72>=_0x44abe3){_0xf82f72=_0x44abe3;_0x367d82=0xc8;}else{_0x367d82=0xce;}_0x82e67e[_0x5adb('0xe')](_0x367d82);return _0x82e67e[_0x5adb('0x14')](_0x5adb('0x15'),_0x2a545b+'-'+_0xf82f72+'/'+_0x44abe3)[_0x5adb('0x10')](_0x29f0d5);}return null;};}function saveUpdates(_0x39d24d){return function(_0xa29dc){if(_0xa29dc){return _0xa29dc[_0x5adb('0x16')](_0x39d24d)[_0x5adb('0x17')](function(_0x529b65){return _0x529b65;});}return null;};}function removeEntity(_0x3fff62){return function(_0x5de028){if(_0x5de028){return _0x5de028[_0x5adb('0x18')]()['then'](function(){var _0x3ef465=_0x5de028['get']({'plain':!![]});var _0x5e218c=_0x5adb('0x19');return db[_0x5adb('0x1a')][_0x5adb('0x18')]({'where':{'type':_0x5e218c,'resourceId':_0x3ef465['id']}})[_0x5adb('0x17')](function(){return _0x5de028;});})[_0x5adb('0x17')](function(){_0x3fff62['status'](0xcc)[_0x5adb('0xf')]();});}};}function handleEntityNotFound(_0x5c296e){return function(_0x4e9f16){if(!_0x4e9f16){_0x5c296e[_0x5adb('0xd')](0x194);}return _0x4e9f16;};}function handleError(_0x379b33,_0x1a38d3){_0x1a38d3=_0x1a38d3||0x1f4;return function(_0x1a8014){logger[_0x5adb('0x1b')](_0x1a8014[_0x5adb('0x1c')]);if(_0x1a8014[_0x5adb('0x1d')]){delete _0x1a8014['name'];}_0x379b33[_0x5adb('0xe')](_0x1a38d3)[_0x5adb('0x1e')](_0x1a8014);};}exports[_0x5adb('0x1f')]=function(_0x3839fb,_0xeb556c){var _0x49f203={};var _0x2fee18={'count':0x0,'rows':[]};var _0x2e1e63=_['map'](db[_0x5adb('0x20')][_0x5adb('0x21')],function(_0x1a0acd){return{'name':_0x1a0acd['fieldName'],'type':_0x1a0acd[_0x5adb('0x22')][_0x5adb('0x23')]};});_0x49f203=qs[_0x5adb('0x24')](_0x2e1e63,_0x3839fb);var _0x2c64a3={'where':_0x49f203[_0x5adb('0x25')]};return db[_0x5adb('0x20')]['count'](_0x2c64a3)['then'](function(_0x5d457e){_0x2fee18[_0x5adb('0x26')]=_0x5d457e;_0x49f203[_0x5adb('0x27')]=qs[_0x5adb('0x27')](_0x3839fb[_0x5adb('0x28')]);return db[_0x5adb('0x20')]['findAll'](_0x49f203);})[_0x5adb('0x17')](function(_0x34b793){_0x2fee18[_0x5adb('0x29')]=_0x34b793;return _0x2fee18;})[_0x5adb('0x17')](respondWithFilteredResult(_0xeb556c,_0x49f203))[_0x5adb('0x2a')](handleError(_0xeb556c,null));};exports[_0x5adb('0x2b')]=function(_0x28190d,_0x28bf1f){var _0x138bf6={'raw':!![],'where':{'id':_0x28190d['params']['id']}},_0x260295={};_0x260295[_0x5adb('0x2c')]=_['keys'](db[_0x5adb('0x20')][_0x5adb('0x21')]);_0x260295['query']=_[_0x5adb('0x2d')](_0x28190d[_0x5adb('0x28')]);_0x260295[_0x5adb('0x2e')]=_['intersection'](_0x260295[_0x5adb('0x2c')],_0x260295[_0x5adb('0x28')]);_0x138bf6['attributes']=_['intersection'](_0x260295[_0x5adb('0x2c')],qs['fields'](_0x28190d[_0x5adb('0x28')][_0x5adb('0x2f')]));_0x138bf6[_0x5adb('0x30')]=_0x138bf6[_0x5adb('0x30')][_0x5adb('0x31')]?_0x138bf6['attributes']:_0x260295[_0x5adb('0x2c')];if(_0x28190d[_0x5adb('0x28')][_0x5adb('0x32')]){_0x138bf6['include']=[{'all':!![]}];}_0x138bf6=_['merge']({},_0x138bf6,_0x28190d[_0x5adb('0x33')]);return db[_0x5adb('0x20')]['find'](_0x138bf6)[_0x5adb('0x17')](handleEntityNotFound(_0x28bf1f,null))['then'](respondWithResult(_0x28bf1f,null))[_0x5adb('0x2a')](handleError(_0x28bf1f,null));};exports['create']=function(_0x11cb37,_0x4d052f){return db[_0x5adb('0x20')][_0x5adb('0x34')](_0x11cb37['body'],{})[_0x5adb('0x17')](function(_0x5a6a79){var _0xadbe37=_0x11cb37[_0x5adb('0x35')][_0x5adb('0x36')]({'plain':!![]});if(!_0xadbe37)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0xadbe37[_0x5adb('0x37')]===_0x5adb('0x35')){var _0xcdaf8e=_0x5a6a79[_0x5adb('0x36')]({'plain':!![]});var _0x22aa95='SmsQueues';return db['UserProfileSection']['find']({'where':{'name':_0x22aa95,'userProfileId':_0xadbe37['userProfileId']},'raw':!![]})[_0x5adb('0x17')](function(_0x2fbe14){if(_0x2fbe14&&_0x2fbe14[_0x5adb('0x38')]===0x0){return db[_0x5adb('0x1a')][_0x5adb('0x34')]({'name':_0xcdaf8e[_0x5adb('0x1d')],'resourceId':_0xcdaf8e['id'],'type':_0x2fbe14[_0x5adb('0x1d')],'sectionId':_0x2fbe14['id']},{})[_0x5adb('0x17')](function(){return _0x5a6a79;});}else{return _0x5a6a79;}})['catch'](function(_0x53f2c6){logger[_0x5adb('0x1b')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x53f2c6);throw _0x53f2c6;});}return _0x5a6a79;})[_0x5adb('0x17')](respondWithResult(_0x4d052f,0xc9))[_0x5adb('0x2a')](handleError(_0x4d052f,null));};exports[_0x5adb('0x16')]=function(_0x121714,_0xdfecfd){if(_0x121714['body']['id']){delete _0x121714[_0x5adb('0x39')]['id'];}return db[_0x5adb('0x20')]['find']({'where':{'id':_0x121714[_0x5adb('0x3a')]['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0xdfecfd,null))['then'](saveUpdates(_0x121714[_0x5adb('0x39')],null))[_0x5adb('0x17')](respondWithResult(_0xdfecfd,null))[_0x5adb('0x2a')](handleError(_0xdfecfd,null));};exports[_0x5adb('0x18')]=function(_0xea3307,_0x4362ec){return db[_0x5adb('0x20')]['find']({'where':{'id':_0xea3307['params']['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0x4362ec,null))[_0x5adb('0x17')](removeEntity(_0x4362ec,null))[_0x5adb('0x2a')](handleError(_0x4362ec,null));};exports[_0x5adb('0x3b')]=function(_0x57b8af,_0x507e48){return db[_0x5adb('0x20')][_0x5adb('0x3b')]()[_0x5adb('0x17')](respondWithResult(_0x507e48,null))[_0x5adb('0x2a')](handleError(_0x507e48,null));};exports[_0x5adb('0x3c')]=function(_0x5358c0,_0x182cbc){var _0x437f52={'raw':!![],'where':{}},_0x5b574c={},_0x7786c4;return db[_0x5adb('0x20')][_0x5adb('0x3d')]({'where':{'id':_0x5358c0[_0x5adb('0x3a')]['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0x182cbc,null))[_0x5adb('0x17')](function(_0x39840e){if(_0x39840e){_0x7786c4=_0x39840e[_0x5adb('0x36')]({'plain':!![]});_0x5b574c['model']=_[_0x5adb('0x2d')](db['UserSmsQueue']['rawAttributes']);_0x5b574c['query']=_[_0x5adb('0x2d')](_0x5358c0[_0x5adb('0x28')]);_0x5b574c[_0x5adb('0x2e')]=_['intersection'](_0x5b574c[_0x5adb('0x2c')],_0x5b574c['query']);_0x437f52[_0x5adb('0x30')]=_[_0x5adb('0x3e')](_0x5b574c[_0x5adb('0x2c')],qs['fields'](_0x5358c0[_0x5adb('0x28')]['fields']));_0x437f52[_0x5adb('0x30')]=_0x437f52[_0x5adb('0x30')]['length']?_0x437f52[_0x5adb('0x30')]:_0x5b574c[_0x5adb('0x2c')];if(!_0x5358c0[_0x5adb('0x28')][_0x5adb('0x3f')](_0x5adb('0x40'))){_0x437f52['limit']=qs[_0x5adb('0x12')](_0x5358c0[_0x5adb('0x28')][_0x5adb('0x12')]);_0x437f52[_0x5adb('0x11')]=qs['offset'](_0x5358c0[_0x5adb('0x28')][_0x5adb('0x11')]);}_0x437f52[_0x5adb('0x41')]=qs['sort'](_0x5358c0[_0x5adb('0x28')][_0x5adb('0x42')]);_0x437f52[_0x5adb('0x25')]=qs[_0x5adb('0x2e')](_['pick'](_0x5358c0[_0x5adb('0x28')],_0x5b574c[_0x5adb('0x2e')]));_0x437f52[_0x5adb('0x25')][_0x5adb('0x43')]=_0x39840e['id'];if(_0x5358c0[_0x5adb('0x28')]['filter']){_0x437f52[_0x5adb('0x25')]=_['merge'](_0x437f52[_0x5adb('0x25')],{'$or':_['map'](_0x437f52[_0x5adb('0x30')],function(_0x35df22){var _0x1a9358={};_0x1a9358[_0x35df22]={'$like':'%'+_0x5358c0[_0x5adb('0x28')]['filter']+'%'};return _0x1a9358;})});}_0x437f52=_[_0x5adb('0x44')]({},_0x437f52,_0x5358c0[_0x5adb('0x33')]);return db[_0x5adb('0x45')]['findAll'](_0x437f52);}})['then'](function(_0x4ddfdf){if(_0x4ddfdf){return db[_0x5adb('0x46')][_0x5adb('0x47')]({'where':{'id':_[_0x5adb('0x48')](_0x4ddfdf,_0x5adb('0x49')),'role':_0x5adb('0x4a')},'attributes':['id',_0x5adb('0x1d'),_0x5adb('0x4b'),_0x5adb('0x4c'),_0x5adb('0x4d')]});}})[_0x5adb('0x17')](function(_0x452767){if(_0x452767){return{'count':_0x452767[_0x5adb('0x26')],'rows':_[_0x5adb('0x48')](_0x452767['rows'],function(_0x49f4c8){return{'membername':_0x49f4c8[_0x5adb('0x1d')],'UserId':_0x49f4c8['id'],'queue_name':_0x7786c4[_0x5adb('0x1d')],'SmsQueueId':_0x7786c4['id'],'interface':util[_0x5adb('0x4e')](_0x5adb('0x4f'),'SIP',_0x49f4c8[_0x5adb('0x1d')]),'penalty':0x0,'paused':_0x49f4c8[_0x5adb('0x4b')],'createdAt':_0x49f4c8['createdAt'],'updatedAt':_0x49f4c8[_0x5adb('0x4c')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x5adb('0x17')](respondWithFilteredResult(_0x182cbc,_0x437f52))[_0x5adb('0x2a')](handleError(_0x182cbc,null));};exports['getTeams']=function(_0x30d185,_0x409357){var _0x19df2f={};var _0x30c92c={};var _0x330290;var _0x428019;return db['SmsQueue'][_0x5adb('0x3d')]({'where':{'id':_0x30d185[_0x5adb('0x3a')]['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0x409357,null))['then'](function(_0xcd71d2){if(_0xcd71d2){_0x330290=_0xcd71d2;_0x30c92c[_0x5adb('0x2c')]=_[_0x5adb('0x2d')](db['Team'][_0x5adb('0x21')]);_0x30c92c['query']=_[_0x5adb('0x2d')](_0x30d185[_0x5adb('0x28')]);_0x30c92c[_0x5adb('0x2e')]=_['intersection'](_0x30c92c[_0x5adb('0x2c')],_0x30c92c[_0x5adb('0x28')]);_0x19df2f['attributes']=_[_0x5adb('0x3e')](_0x30c92c[_0x5adb('0x2c')],qs[_0x5adb('0x2f')](_0x30d185[_0x5adb('0x28')]['fields']));_0x19df2f[_0x5adb('0x30')]=_0x19df2f[_0x5adb('0x30')][_0x5adb('0x31')]?_0x19df2f[_0x5adb('0x30')]:_0x30c92c['model'];_0x19df2f['order']=qs[_0x5adb('0x42')](_0x30d185['query']['sort']);_0x19df2f['where']=qs[_0x5adb('0x2e')](_[_0x5adb('0x50')](_0x30d185['query'],_0x30c92c[_0x5adb('0x2e')]));if(_0x30d185[_0x5adb('0x28')][_0x5adb('0x51')]){_0x19df2f[_0x5adb('0x25')]=_[_0x5adb('0x44')](_0x19df2f[_0x5adb('0x25')],{'$or':_[_0x5adb('0x48')](_0x19df2f[_0x5adb('0x30')],function(_0x5240c1){var _0x4b9e80={};_0x4b9e80[_0x5240c1]={'$like':'%'+_0x30d185['query'][_0x5adb('0x51')]+'%'};return _0x4b9e80;})});}_0x19df2f=_[_0x5adb('0x44')]({},_0x19df2f,_0x30d185[_0x5adb('0x33')]);return _0x330290[_0x5adb('0x52')](_0x19df2f);}})[_0x5adb('0x17')](function(_0x2f6ef7){if(_0x2f6ef7){_0x428019=_0x2f6ef7[_0x5adb('0x31')];if(!_0x30d185[_0x5adb('0x28')]['hasOwnProperty']('nolimit')){_0x19df2f[_0x5adb('0x12')]=qs[_0x5adb('0x12')](_0x30d185[_0x5adb('0x28')][_0x5adb('0x12')]);_0x19df2f[_0x5adb('0x11')]=qs[_0x5adb('0x11')](_0x30d185[_0x5adb('0x28')][_0x5adb('0x11')]);}return _0x330290[_0x5adb('0x52')](_0x19df2f);}})[_0x5adb('0x17')](function(_0x484f3d){if(_0x484f3d){return _0x484f3d?{'count':_0x428019,'rows':_0x484f3d}:null;}})[_0x5adb('0x17')](respondWithResult(_0x409357,null))[_0x5adb('0x2a')](handleError(_0x409357,null));};exports[_0x5adb('0x53')]=function(_0x5d3aa4,_0x31f041){var _0xa1bd33=_0x5d3aa4['body'][_0x5adb('0x54')];return db['Team'][_0x5adb('0x55')]({'where':{'id':_0xa1bd33},'attributes':['id'],'include':[{'model':db[_0x5adb('0x46')],'as':'Agents','attributes':['id',_0x5adb('0x1d'),_0x5adb('0x56'),_0x5adb('0x57'),_0x5adb('0x58')],'raw':!![]}]})[_0x5adb('0x17')](function(_0x10f54a){if(_0x10f54a){var _0x3cee6c=_[_0x5adb('0x59')](_0x10f54a,function(_0x49a8a6){var _0x3786b4=_0x49a8a6[_0x5adb('0x36')]({'plain':!![]});return _0x3786b4[_0x5adb('0x5a')];});return db['SmsQueue']['find']({'where':{'id':_0x5d3aa4[_0x5adb('0x3a')]['id']}})['then'](function(_0x27d3d8){return db[_0x5adb('0x5b')][_0x5adb('0x5c')](function(_0x50600f){return _0x27d3d8[_0x5adb('0x53')](_0xa1bd33,{'transaction':_0x50600f})[_0x5adb('0x17')](function(){return BPromise[_0x5adb('0x5d')](_0x3cee6c,function(_0x3ecc56){return db[_0x5adb('0x45')]['findOrCreate']({'where':{'UserId':_0x3ecc56['id'],'SmsQueueId':_0x5d3aa4[_0x5adb('0x3a')]['id']},'transaction':_0x50600f});});})[_0x5adb('0x17')](function(){_0x3cee6c[_0x5adb('0x5e')](function(_0xe3d12d){socket['emit'](_0x5adb('0x5f'),{'UserId':_0xe3d12d['id'],'SmsQueueId':_0x27d3d8['id']});});});});});}})[_0x5adb('0x17')](respondWithStatusCode(_0x31f041,null))[_0x5adb('0x2a')](handleError(_0x31f041,null));};exports[_0x5adb('0x60')]=function(_0x15d4f1,_0x20faf6){return db[_0x5adb('0x61')]['findAll']({'where':{'id':_0x15d4f1[_0x5adb('0x28')][_0x5adb('0x54')]},'attributes':['id'],'include':[{'model':db['User'],'as':_0x5adb('0x5a'),'attributes':['id'],'raw':!![]}]})[_0x5adb('0x17')](handleEntityNotFound(_0x20faf6,null))['then'](function(_0x462fa0){var _0x50f8ed=_[_0x5adb('0x48')](_0x462fa0,'id');var _0x268df2=[];var _0x4a2ebc=[];var _0x167432=squel['select']();_0x167432[_0x5adb('0x62')](_0x5adb('0x63'))[_0x5adb('0x64')](_0x5adb('0x65'),'tq')[_0x5adb('0x66')]('user_has_teams','ut',_0x5adb('0x67'))[_0x5adb('0x25')](_0x5adb('0x68'),_0x15d4f1[_0x5adb('0x3a')]['id']);for(var _0x47c631=0x0;_0x47c631<_0x462fa0['length'];_0x47c631+=0x1){let _0x3f3db9=_0x462fa0[_0x47c631];for(var _0x461a07=0x0;_0x461a07<_0x3f3db9[_0x5adb('0x5a')][_0x5adb('0x31')];_0x461a07+=0x1){let _0x277668=_0x3f3db9[_0x5adb('0x5a')][_0x461a07];var _0x31f5b2=_0x167432['clone']();_0x31f5b2[_0x5adb('0x25')](_0x5adb('0x69'),_0x277668['id']);_0x4a2ebc[_0x5adb('0x6a')](db[_0x5adb('0x5b')]['query'](_0x31f5b2[_0x5adb('0x6b')](),{'type':db[_0x5adb('0x5b')][_0x5adb('0x6c')][_0x5adb('0x6d')]})[_0x5adb('0x17')](function(_0x188cbd){if(_0x188cbd[_0x5adb('0x31')]===0x1){return _0x277668['id'];}else{var _0x2d1b65=_[_0x5adb('0x6e')](_['map'](_0x188cbd,_0x5adb('0x6f')),function(_0x456799){return _['includes'](_0x50f8ed,_0x456799);});if(_0x2d1b65){return _0x277668['id'];}}}));}}return BPromise[_0x5adb('0x70')](_0x4a2ebc)[_0x5adb('0x17')](function(_0x2b8915){_0x268df2=_(_0x268df2)[_0x5adb('0x71')](_0x2b8915)[_0x5adb('0x72')]()[_0x5adb('0x73')]();return db[_0x5adb('0x20')][_0x5adb('0x74')]({'where':{'id':_0x15d4f1['params']['id']}})[_0x5adb('0x17')](function(_0x2386c0){return db['sequelize'][_0x5adb('0x5c')](function(_0x58a26f){return _0x2386c0[_0x5adb('0x60')](_0x15d4f1['query']['ids'],{'transaction':_0x58a26f})[_0x5adb('0x17')](function(){if(!_[_0x5adb('0x75')](_0x268df2)){return _0x2386c0[_0x5adb('0x76')](_0x268df2,{'transaction':_0x58a26f});}})['then'](function(){_0x268df2[_0x5adb('0x5e')](function(_0x321c3a){socket[_0x5adb('0x77')](_0x5adb('0x78'),{'UserId':_0x321c3a,'SmsQueueId':_0x2386c0['id']});});});});});});})[_0x5adb('0x17')](respondWithStatusCode(_0x20faf6,null))[_0x5adb('0x2a')](handleError(_0x20faf6,null));};exports[_0x5adb('0x79')]=function(_0x463e84,_0x28bd33){return db[_0x5adb('0x20')][_0x5adb('0x74')]({'where':{'id':_0x463e84[_0x5adb('0x3a')]['id']}})['then'](handleEntityNotFound(_0x28bd33,null))['then'](function(_0x312463){if(_0x312463){return _0x312463[_0x5adb('0x79')](_0x463e84['body'][_0x5adb('0x54')],_[_0x5adb('0x7a')](_0x463e84[_0x5adb('0x39')],[_0x5adb('0x54'),'id'])||{})[_0x5adb('0x7b')](function(_0x24cd3b){for(var _0x15626b=0x0;_0x15626b<_0x463e84[_0x5adb('0x39')][_0x5adb('0x54')]['length'];_0x15626b+=0x1){socket[_0x5adb('0x77')](_0x5adb('0x5f'),{'UserId':Number(_0x463e84[_0x5adb('0x39')]['ids'][_0x15626b]),'SmsQueueId':Number(_0x463e84[_0x5adb('0x3a')]['id'])});}return _0x24cd3b;});}})[_0x5adb('0x17')](respondWithResult(_0x28bd33,null))[_0x5adb('0x2a')](handleError(_0x28bd33,null));};exports[_0x5adb('0x76')]=function(_0x64475f,_0x2a78f9){return db['SmsQueue'][_0x5adb('0x74')]({'where':{'id':_0x64475f[_0x5adb('0x3a')]['id']}})[_0x5adb('0x17')](handleEntityNotFound(_0x2a78f9,null))[_0x5adb('0x17')](function(_0x2c3af8){if(_0x2c3af8){return _0x2c3af8[_0x5adb('0x76')](_0x64475f[_0x5adb('0x28')][_0x5adb('0x54')])[_0x5adb('0x17')](function(){if(_[_0x5adb('0x7c')](_0x64475f['query'][_0x5adb('0x54')])){for(var _0x5b9565=0x0;_0x5b9565<_0x64475f[_0x5adb('0x28')][_0x5adb('0x54')][_0x5adb('0x31')];_0x5b9565+=0x1){socket[_0x5adb('0x77')](_0x5adb('0x78'),{'UserId':Number(_0x64475f['query']['ids'][_0x5b9565]),'SmsQueueId':Number(_0x64475f[_0x5adb('0x3a')]['id'])});}}else{socket[_0x5adb('0x77')](_0x5adb('0x78'),{'UserId':Number(_0x64475f[_0x5adb('0x28')][_0x5adb('0x54')]),'SmsQueueId':Number(_0x64475f[_0x5adb('0x3a')]['id'])});}});}})['then'](respondWithStatusCode(_0x2a78f9,null))['catch'](handleError(_0x2a78f9,null));};exports[_0x5adb('0x7d')]=function(_0xd5b95d,_0x9d80fd){var _0x4f5721={};var _0x542626={};var _0x227c17;var _0x5982a5;return db[_0x5adb('0x20')][_0x5adb('0x3d')]({'where':{'id':_0xd5b95d['params']['id']}})['then'](handleEntityNotFound(_0x9d80fd,null))[_0x5adb('0x17')](function(_0x4bb198){if(_0x4bb198){_0x227c17=_0x4bb198;_0x542626['model']=_[_0x5adb('0x2d')](db[_0x5adb('0x46')][_0x5adb('0x21')]);_0x542626[_0x5adb('0x28')]=_[_0x5adb('0x2d')](_0xd5b95d[_0x5adb('0x28')]);_0x542626[_0x5adb('0x2e')]=_[_0x5adb('0x3e')](_0x542626[_0x5adb('0x2c')],_0x542626[_0x5adb('0x28')]);_0x4f5721[_0x5adb('0x30')]=_[_0x5adb('0x3e')](_0x542626[_0x5adb('0x2c')],qs['fields'](_0xd5b95d[_0x5adb('0x28')]['fields']));_0x4f5721[_0x5adb('0x30')]=_0x4f5721[_0x5adb('0x30')][_0x5adb('0x31')]?_0x4f5721[_0x5adb('0x30')]:_0x542626[_0x5adb('0x2c')];_0x4f5721[_0x5adb('0x41')]=qs[_0x5adb('0x42')](_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x42')]);_0x4f5721[_0x5adb('0x25')]=qs[_0x5adb('0x2e')](_[_0x5adb('0x50')](_0xd5b95d['query'],_0x542626[_0x5adb('0x2e')]));if(_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x51')]){_0x4f5721[_0x5adb('0x25')]=_[_0x5adb('0x44')](_0x4f5721[_0x5adb('0x25')],{'$or':_[_0x5adb('0x48')](_0x4f5721[_0x5adb('0x30')],function(_0x57c160){var _0xe7ddc4={};_0xe7ddc4[_0x57c160]={'$like':'%'+_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x51')]+'%'};return _0xe7ddc4;})});}_0x4f5721=_['merge']({},_0x4f5721,_0xd5b95d[_0x5adb('0x33')]);return _0x227c17['getAgents'](_0x4f5721);}})[_0x5adb('0x17')](function(_0x50c3a3){if(_0x50c3a3){_0x5982a5=_0x50c3a3['length'];if(!_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x3f')](_0x5adb('0x40'))){_0x4f5721[_0x5adb('0x12')]=qs[_0x5adb('0x12')](_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x12')]);_0x4f5721[_0x5adb('0x11')]=qs[_0x5adb('0x11')](_0xd5b95d[_0x5adb('0x28')][_0x5adb('0x11')]);}return _0x227c17[_0x5adb('0x7d')](_0x4f5721);}})['then'](function(_0x364da7){if(_0x364da7){return _0x364da7?{'count':_0x5982a5,'rows':_0x364da7}:null;}})['then'](respondWithResult(_0x9d80fd,null))[_0x5adb('0x2a')](handleError(_0x9d80fd,null));};
\ No newline at end of file