Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / smsQueue / smsQueue.controller.js
index 214b78e..c998908 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x782e=['join','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','push','sequelize','toString','QueryTypes','SELECT','every','includes','all','union','value','isEmpty','removeAgents','emit','addAgents','omit','spread','userSmsQueue:save','isArray','userSmsQueue:remove','getAgents','eml-format','rimraf','zip-dir','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','localhost','register','sendStatus','status','end','json','offset','undefined','limit','set','Content-Range','apply','reject','save','update','then','get','SmsQueues','UserProfileResource','error','stack','name','send','index','map','rawAttributes','fieldName','type','model','keys','query','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','count','rows','catch','show','params','SmsQueue','includeAll','include','options','find','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','destroy','describe','getMembers','findOne','UserSmsQueue','hasOwnProperty','SmsQueueId','findAll','User','findAndCountAll','UserId','agent','format','%s/%s','SIP','smsPause','createdAt','updatedAt','Team','addTeams','ids','Agents','online','voicePause','interface','flatMap','transaction','each','findOrCreate','forEach','removeTeams','select','field','tq.TeamId','team_has_sms_queues'];(function(_0x2d1cf5,_0x8212d4){var _0x3edb6e=function(_0x55854e){while(--_0x55854e){_0x2d1cf5['push'](_0x2d1cf5['shift']());}};_0x3edb6e(++_0x8212d4);}(_0x782e,0x1d4));var _0xe782=function(_0x4cc7db,_0x2047a5){_0x4cc7db=_0x4cc7db-0x0;var _0xde80fb=_0x782e[_0x4cc7db];return _0xde80fb;};'use strict';var emlformat=require(_0xe782('0x0'));var rimraf=require(_0xe782('0x1'));var zipdir=require(_0xe782('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xe782('0x3'));var BPromise=require(_0xe782('0x4'));var Mustache=require(_0xe782('0x5'));var util=require(_0xe782('0x6'));var path=require(_0xe782('0x7'));var sox=require(_0xe782('0x8'));var csv=require(_0xe782('0x9'));var ejs=require(_0xe782('0xa'));var fs=require('fs');var fs_extra=require(_0xe782('0xb'));var _=require(_0xe782('0xc'));var squel=require(_0xe782('0xd'));var crypto=require(_0xe782('0xe'));var jsforce=require(_0xe782('0xf'));var deskjs=require(_0xe782('0x10'));var toCsv=require('to-csv');var querystring=require(_0xe782('0x11'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xe782('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xe782('0x13'));var logger=require(_0xe782('0x14'))(_0xe782('0x15'));var utils=require(_0xe782('0x16'));var config=require(_0xe782('0x17'));var licenseUtil=require(_0xe782('0x18'));var db=require('../../mysqldb')['db'];config[_0xe782('0x19')]=_['defaults'](config[_0xe782('0x19')],{'host':_0xe782('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xe782('0x19')]));require('./smsQueue.socket')[_0xe782('0x1b')](socket);function respondWithStatusCode(_0x3a3fe2,_0x1c6010){_0x1c6010=_0x1c6010||0xcc;return function(_0xa8d8c7){if(_0xa8d8c7){return _0x3a3fe2[_0xe782('0x1c')](_0x1c6010);}return _0x3a3fe2[_0xe782('0x1d')](_0x1c6010)[_0xe782('0x1e')]();};}function respondWithResult(_0x36b0ee,_0xd369ad){_0xd369ad=_0xd369ad||0xc8;return function(_0x30330d){if(_0x30330d){return _0x36b0ee[_0xe782('0x1d')](_0xd369ad)[_0xe782('0x1f')](_0x30330d);}};}function respondWithFilteredResult(_0xb9de4f,_0x508b4d){return function(_0xd0f314){if(_0xd0f314){var _0x3626b6=typeof _0x508b4d[_0xe782('0x20')]==='undefined'&&typeof _0x508b4d['limit']===_0xe782('0x21');var _0xf29563=_0xd0f314['count'];var _0x470423=_0x3626b6?0x0:_0x508b4d[_0xe782('0x20')];var _0x57f1a6=_0x3626b6?_0xd0f314['count']:_0x508b4d[_0xe782('0x20')]+_0x508b4d[_0xe782('0x22')];var _0x99eecf;if(_0x57f1a6>=_0xf29563){_0x57f1a6=_0xf29563;_0x99eecf=0xc8;}else{_0x99eecf=0xce;}_0xb9de4f['status'](_0x99eecf);return _0xb9de4f[_0xe782('0x23')](_0xe782('0x24'),_0x470423+'-'+_0x57f1a6+'/'+_0xf29563)[_0xe782('0x1f')](_0xd0f314);}return null;};}function patchUpdates(_0x9a2005){return function(_0x1f2bf5){try{jsonpatch[_0xe782('0x25')](_0x1f2bf5,_0x9a2005,!![]);}catch(_0x77a98c){return BPromise[_0xe782('0x26')](_0x77a98c);}return _0x1f2bf5[_0xe782('0x27')]();};}function saveUpdates(_0x5f20e4,_0x52b4df){return function(_0x2423be){if(_0x2423be){return _0x2423be[_0xe782('0x28')](_0x5f20e4)[_0xe782('0x29')](function(_0x194030){return _0x194030;});}return null;};}function removeEntity(_0x34d55c,_0x2521da){return function(_0x4deb87){if(_0x4deb87){return _0x4deb87['destroy']()[_0xe782('0x29')](function(){var _0xc58cc3=_0x4deb87[_0xe782('0x2a')]({'plain':!![]});var _0x291384=_0xe782('0x2b');return db[_0xe782('0x2c')]['destroy']({'where':{'type':_0x291384,'resourceId':_0xc58cc3['id']}})['then'](function(){return _0x4deb87;});})[_0xe782('0x29')](function(){_0x34d55c[_0xe782('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4c7157,_0xb392e9){return function(_0xc02bf2){if(!_0xc02bf2){_0x4c7157['sendStatus'](0x194);}return _0xc02bf2;};}function handleError(_0x14076c,_0x3198bc){_0x3198bc=_0x3198bc||0x1f4;return function(_0x51514d){logger[_0xe782('0x2d')](_0x51514d[_0xe782('0x2e')]);if(_0x51514d[_0xe782('0x2f')]){delete _0x51514d[_0xe782('0x2f')];}_0x14076c[_0xe782('0x1d')](_0x3198bc)[_0xe782('0x30')](_0x51514d);};}exports[_0xe782('0x31')]=function(_0x3fcd13,_0x29bfe9){var _0x11a757={},_0x3b92e6={},_0x394701={'count':0x0,'rows':[]};var _0x3910d9=_[_0xe782('0x32')](db['SmsQueue'][_0xe782('0x33')],function(_0x2f0c15){return{'name':_0x2f0c15[_0xe782('0x34')],'type':_0x2f0c15[_0xe782('0x35')]['key']};});_0x3b92e6[_0xe782('0x36')]=_[_0xe782('0x32')](_0x3910d9,_0xe782('0x2f'));_0x3b92e6['query']=_[_0xe782('0x37')](_0x3fcd13[_0xe782('0x38')]);_0x3b92e6[_0xe782('0x39')]=_[_0xe782('0x3a')](_0x3b92e6['model'],_0x3b92e6[_0xe782('0x38')]);_0x11a757[_0xe782('0x3b')]=_[_0xe782('0x3a')](_0x3b92e6['model'],qs[_0xe782('0x3c')](_0x3fcd13[_0xe782('0x38')]['fields']));_0x11a757['attributes']=_0x11a757[_0xe782('0x3b')][_0xe782('0x3d')]?_0x11a757['attributes']:_0x3b92e6[_0xe782('0x36')];if(!_0x3fcd13[_0xe782('0x38')]['hasOwnProperty'](_0xe782('0x3e'))){_0x11a757[_0xe782('0x22')]=qs[_0xe782('0x22')](_0x3fcd13[_0xe782('0x38')]['limit']);_0x11a757[_0xe782('0x20')]=qs[_0xe782('0x20')](_0x3fcd13[_0xe782('0x38')][_0xe782('0x20')]);}_0x11a757[_0xe782('0x3f')]=qs[_0xe782('0x40')](_0x3fcd13['query'][_0xe782('0x40')]);_0x11a757[_0xe782('0x41')]=qs[_0xe782('0x39')](_[_0xe782('0x42')](_0x3fcd13[_0xe782('0x38')],_0x3b92e6[_0xe782('0x39')]),_0x3910d9);if(_0x3fcd13['query'][_0xe782('0x43')]){_0x11a757['where']=_[_0xe782('0x44')](_0x11a757['where'],{'$or':_['map'](_0x3910d9,function(_0x13288f){if(_0x13288f[_0xe782('0x35')]!==_0xe782('0x45')){var _0x2c13c4={};_0x2c13c4[_0x13288f[_0xe782('0x2f')]]={'$like':'%'+_0x3fcd13[_0xe782('0x38')][_0xe782('0x43')]+'%'};return _0x2c13c4;}})});}_0x11a757=_[_0xe782('0x44')]({},_0x11a757,_0x3fcd13['options']);var _0x56019d={'where':_0x11a757[_0xe782('0x41')]};return db['SmsQueue'][_0xe782('0x46')](_0x56019d)[_0xe782('0x29')](function(_0x1bba1a){_0x394701[_0xe782('0x46')]=_0x1bba1a;if(_0x3fcd13[_0xe782('0x38')]['includeAll']){_0x11a757['include']=[{'all':!![]}];}return db['SmsQueue']['findAll'](_0x11a757);})[_0xe782('0x29')](function(_0x33f000){_0x394701[_0xe782('0x47')]=_0x33f000;return _0x394701;})[_0xe782('0x29')](respondWithFilteredResult(_0x29bfe9,_0x11a757))[_0xe782('0x48')](handleError(_0x29bfe9,null));};exports[_0xe782('0x49')]=function(_0x26c9e7,_0x497a3c){var _0x2e44f5={'raw':!![],'where':{'id':_0x26c9e7[_0xe782('0x4a')]['id']}},_0x5cc5fb={};_0x5cc5fb[_0xe782('0x36')]=_[_0xe782('0x37')](db[_0xe782('0x4b')][_0xe782('0x33')]);_0x5cc5fb['query']=_[_0xe782('0x37')](_0x26c9e7[_0xe782('0x38')]);_0x5cc5fb[_0xe782('0x39')]=_[_0xe782('0x3a')](_0x5cc5fb['model'],_0x5cc5fb['query']);_0x2e44f5[_0xe782('0x3b')]=_['intersection'](_0x5cc5fb['model'],qs[_0xe782('0x3c')](_0x26c9e7[_0xe782('0x38')][_0xe782('0x3c')]));_0x2e44f5[_0xe782('0x3b')]=_0x2e44f5['attributes'][_0xe782('0x3d')]?_0x2e44f5['attributes']:_0x5cc5fb[_0xe782('0x36')];if(_0x26c9e7['query'][_0xe782('0x4c')]){_0x2e44f5[_0xe782('0x4d')]=[{'all':!![]}];}_0x2e44f5=_[_0xe782('0x44')]({},_0x2e44f5,_0x26c9e7[_0xe782('0x4e')]);return db['SmsQueue'][_0xe782('0x4f')](_0x2e44f5)[_0xe782('0x29')](handleEntityNotFound(_0x497a3c,null))[_0xe782('0x29')](respondWithResult(_0x497a3c,null))[_0xe782('0x48')](handleError(_0x497a3c,null));};exports['create']=function(_0x1deebb,_0x5d2dcf){return db['SmsQueue']['create'](_0x1deebb['body'],{})[_0xe782('0x29')](function(_0x446969){var _0xa72123=_0x1deebb[_0xe782('0x50')]['get']({'plain':!![]});if(!_0xa72123)throw new Error(_0xe782('0x51'));if(_0xa72123[_0xe782('0x52')]==='user'){var _0x8bd9ac=_0x446969[_0xe782('0x2a')]({'plain':!![]});var _0x1710c8=_0xe782('0x2b');return db[_0xe782('0x53')]['find']({'where':{'name':_0x1710c8,'userProfileId':_0xa72123[_0xe782('0x54')]},'raw':!![]})['then'](function(_0x278f0f){if(_0x278f0f&&_0x278f0f[_0xe782('0x55')]===0x0){return db[_0xe782('0x2c')][_0xe782('0x56')]({'name':_0x8bd9ac[_0xe782('0x2f')],'resourceId':_0x8bd9ac['id'],'type':_0x278f0f['name'],'sectionId':_0x278f0f['id']},{})['then'](function(){return _0x446969;});}else{return _0x446969;}})['catch'](function(_0x1c47a7){logger[_0xe782('0x2d')](_0xe782('0x57'),_0x1c47a7);throw _0x1c47a7;});}return _0x446969;})[_0xe782('0x29')](respondWithResult(_0x5d2dcf,0xc9))[_0xe782('0x48')](handleError(_0x5d2dcf,null));};exports['update']=function(_0x2bc8c0,_0x471d3f){if(_0x2bc8c0[_0xe782('0x58')]['id']){delete _0x2bc8c0[_0xe782('0x58')]['id'];}return db[_0xe782('0x4b')][_0xe782('0x4f')]({'where':{'id':_0x2bc8c0['params']['id']}})['then'](handleEntityNotFound(_0x471d3f,null))[_0xe782('0x29')](saveUpdates(_0x2bc8c0[_0xe782('0x58')],null))[_0xe782('0x29')](respondWithResult(_0x471d3f,null))['catch'](handleError(_0x471d3f,null));};exports[_0xe782('0x59')]=function(_0x3f30a2,_0x2fb288){return db[_0xe782('0x4b')]['find']({'where':{'id':_0x3f30a2['params']['id']}})[_0xe782('0x29')](handleEntityNotFound(_0x2fb288,null))[_0xe782('0x29')](removeEntity(_0x2fb288,null))[_0xe782('0x48')](handleError(_0x2fb288,null));};exports[_0xe782('0x5a')]=function(_0x2937b2,_0x2aa894){return db[_0xe782('0x4b')]['describe']()[_0xe782('0x29')](respondWithResult(_0x2aa894,null))[_0xe782('0x48')](handleError(_0x2aa894,null));};exports[_0xe782('0x5b')]=function(_0x1cff76,_0x26eb45,_0x4e1f2e){var _0x20fa61={'raw':!![],'where':{}},_0x18b8e8={},_0x3dcee2;return db[_0xe782('0x4b')][_0xe782('0x5c')]({'where':{'id':_0x1cff76['params']['id']}})[_0xe782('0x29')](handleEntityNotFound(_0x26eb45,null))[_0xe782('0x29')](function(_0x961164){if(_0x961164){_0x3dcee2=_0x961164[_0xe782('0x2a')]({'plain':!![]});_0x18b8e8[_0xe782('0x36')]=_['keys'](db[_0xe782('0x5d')][_0xe782('0x33')]);_0x18b8e8[_0xe782('0x38')]=_[_0xe782('0x37')](_0x1cff76[_0xe782('0x38')]);_0x18b8e8['filters']=_[_0xe782('0x3a')](_0x18b8e8['model'],_0x18b8e8[_0xe782('0x38')]);_0x20fa61[_0xe782('0x3b')]=_['intersection'](_0x18b8e8[_0xe782('0x36')],qs[_0xe782('0x3c')](_0x1cff76[_0xe782('0x38')]['fields']));_0x20fa61[_0xe782('0x3b')]=_0x20fa61['attributes']['length']?_0x20fa61['attributes']:_0x18b8e8['model'];if(!_0x1cff76['query'][_0xe782('0x5e')](_0xe782('0x3e'))){_0x20fa61[_0xe782('0x22')]=qs[_0xe782('0x22')](_0x1cff76[_0xe782('0x38')][_0xe782('0x22')]);_0x20fa61[_0xe782('0x20')]=qs['offset'](_0x1cff76[_0xe782('0x38')][_0xe782('0x20')]);}_0x20fa61['order']=qs[_0xe782('0x40')](_0x1cff76[_0xe782('0x38')][_0xe782('0x40')]);_0x20fa61[_0xe782('0x41')]=qs[_0xe782('0x39')](_['pick'](_0x1cff76[_0xe782('0x38')],_0x18b8e8[_0xe782('0x39')]));_0x20fa61[_0xe782('0x41')][_0xe782('0x5f')]=_0x961164['id'];if(_0x1cff76[_0xe782('0x38')][_0xe782('0x43')]){_0x20fa61['where']=_[_0xe782('0x44')](_0x20fa61[_0xe782('0x41')],{'$or':_['map'](_0x20fa61[_0xe782('0x3b')],function(_0x514bbb){var _0xee9e1b={};_0xee9e1b[_0x514bbb]={'$like':'%'+_0x1cff76[_0xe782('0x38')][_0xe782('0x43')]+'%'};return _0xee9e1b;})});}_0x20fa61=_['merge']({},_0x20fa61,_0x1cff76['options']);return db[_0xe782('0x5d')][_0xe782('0x60')](_0x20fa61);}})[_0xe782('0x29')](function(_0x393329){if(_0x393329){return db[_0xe782('0x61')][_0xe782('0x62')]({'where':{'id':_[_0xe782('0x32')](_0x393329,_0xe782('0x63')),'role':_0xe782('0x64')},'attributes':['id',_0xe782('0x2f'),'smsPause','updatedAt','createdAt']});}})[_0xe782('0x29')](function(_0x1f8fd8){if(_0x1f8fd8){return{'count':_0x1f8fd8['count'],'rows':_[_0xe782('0x32')](_0x1f8fd8[_0xe782('0x47')],function(_0x5b0d33){return{'membername':_0x5b0d33['name'],'UserId':_0x5b0d33['id'],'queue_name':_0x3dcee2[_0xe782('0x2f')],'SmsQueueId':_0x3dcee2['id'],'interface':util[_0xe782('0x65')](_0xe782('0x66'),_0xe782('0x67'),_0x5b0d33['name']),'penalty':0x0,'paused':_0x5b0d33[_0xe782('0x68')],'createdAt':_0x5b0d33[_0xe782('0x69')],'updatedAt':_0x5b0d33[_0xe782('0x6a')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xe782('0x29')](respondWithFilteredResult(_0x26eb45,_0x20fa61))[_0xe782('0x48')](handleError(_0x26eb45,null));};exports['getTeams']=function(_0x881a4d,_0xf9fcd3,_0x200628){var _0x15067d={};var _0x596b58={};var _0x420e4a;var _0x24864e;return db['SmsQueue'][_0xe782('0x5c')]({'where':{'id':_0x881a4d[_0xe782('0x4a')]['id']}})[_0xe782('0x29')](handleEntityNotFound(_0xf9fcd3,null))[_0xe782('0x29')](function(_0x24cd54){if(_0x24cd54){_0x420e4a=_0x24cd54;_0x596b58[_0xe782('0x36')]=_['keys'](db[_0xe782('0x6b')]['rawAttributes']);_0x596b58[_0xe782('0x38')]=_[_0xe782('0x37')](_0x881a4d[_0xe782('0x38')]);_0x596b58[_0xe782('0x39')]=_['intersection'](_0x596b58['model'],_0x596b58[_0xe782('0x38')]);_0x15067d[_0xe782('0x3b')]=_[_0xe782('0x3a')](_0x596b58[_0xe782('0x36')],qs[_0xe782('0x3c')](_0x881a4d[_0xe782('0x38')][_0xe782('0x3c')]));_0x15067d[_0xe782('0x3b')]=_0x15067d['attributes'][_0xe782('0x3d')]?_0x15067d['attributes']:_0x596b58['model'];_0x15067d['order']=qs[_0xe782('0x40')](_0x881a4d['query'][_0xe782('0x40')]);_0x15067d[_0xe782('0x41')]=qs[_0xe782('0x39')](_[_0xe782('0x42')](_0x881a4d[_0xe782('0x38')],_0x596b58['filters']));if(_0x881a4d[_0xe782('0x38')][_0xe782('0x43')]){_0x15067d[_0xe782('0x41')]=_[_0xe782('0x44')](_0x15067d[_0xe782('0x41')],{'$or':_[_0xe782('0x32')](_0x15067d['attributes'],function(_0x444a66){var _0x521d4b={};_0x521d4b[_0x444a66]={'$like':'%'+_0x881a4d['query'][_0xe782('0x43')]+'%'};return _0x521d4b;})});}_0x15067d=_[_0xe782('0x44')]({},_0x15067d,_0x881a4d['options']);return _0x420e4a['getTeams'](_0x15067d);}})[_0xe782('0x29')](function(_0x3d79e1){if(_0x3d79e1){_0x24864e=_0x3d79e1['length'];if(!_0x881a4d[_0xe782('0x38')][_0xe782('0x5e')](_0xe782('0x3e'))){_0x15067d['limit']=qs[_0xe782('0x22')](_0x881a4d[_0xe782('0x38')][_0xe782('0x22')]);_0x15067d[_0xe782('0x20')]=qs['offset'](_0x881a4d[_0xe782('0x38')][_0xe782('0x20')]);}return _0x420e4a['getTeams'](_0x15067d);}})['then'](function(_0x603b21){if(_0x603b21){return _0x603b21?{'count':_0x24864e,'rows':_0x603b21}:null;}})[_0xe782('0x29')](respondWithResult(_0xf9fcd3,null))[_0xe782('0x48')](handleError(_0xf9fcd3,null));};exports[_0xe782('0x6c')]=function(_0xd84778,_0x2035fa,_0x25666b){var _0x51b6e9=_0xd84778[_0xe782('0x58')][_0xe782('0x6d')];return db[_0xe782('0x6b')][_0xe782('0x60')]({'where':{'id':_0x51b6e9},'attributes':['id'],'include':[{'model':db[_0xe782('0x61')],'as':_0xe782('0x6e'),'attributes':['id',_0xe782('0x2f'),_0xe782('0x6f'),_0xe782('0x70'),_0xe782('0x71')],'raw':!![]}]})[_0xe782('0x29')](function(_0x18a14f){if(_0x18a14f){var _0x801ac7=_[_0xe782('0x72')](_0x18a14f,function(_0x53c890){var _0x45e584=_0x53c890[_0xe782('0x2a')]({'plain':!![]});return _0x45e584['Agents'];});return db['SmsQueue'][_0xe782('0x4f')]({'where':{'id':_0xd84778['params']['id']}})[_0xe782('0x29')](function(_0x1c85d7){return db['sequelize'][_0xe782('0x73')](function(_0x5181c7){return _0x1c85d7[_0xe782('0x6c')](_0x51b6e9,{'transaction':_0x5181c7})['then'](function(){return BPromise[_0xe782('0x74')](_0x801ac7,function(_0x569a98){return db[_0xe782('0x5d')][_0xe782('0x75')]({'where':{'UserId':_0x569a98['id'],'SmsQueueId':_0xd84778[_0xe782('0x4a')]['id']},'transaction':_0x5181c7});});})['then'](function(){_0x801ac7[_0xe782('0x76')](function(_0x313788){socket['emit']('userSmsQueue:save',{'UserId':_0x313788['id'],'SmsQueueId':_0x1c85d7['id']});});});});});}})[_0xe782('0x29')](respondWithStatusCode(_0x2035fa,null))[_0xe782('0x48')](handleError(_0x2035fa,null));};exports[_0xe782('0x77')]=function(_0x181a01,_0xc7226c,_0x1c10e5){return db[_0xe782('0x6b')][_0xe782('0x60')]({'where':{'id':_0x181a01[_0xe782('0x38')][_0xe782('0x6d')]},'attributes':['id'],'include':[{'model':db[_0xe782('0x61')],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0xe782('0x29')](handleEntityNotFound(_0xc7226c,null))['then'](function(_0x355437){var _0x5bfa9b=_[_0xe782('0x32')](_0x355437,'id');var _0x372a17=[];var _0x5d4e61=[];var _0x61d222=squel[_0xe782('0x78')]();_0x61d222[_0xe782('0x79')](_0xe782('0x7a'))['from'](_0xe782('0x7b'),'tq')[_0xe782('0x7c')]('user_has_teams','ut',_0xe782('0x7d'))[_0xe782('0x41')]('SmsQueueId\x20=\x20?',_0x181a01[_0xe782('0x4a')]['id']);for(var _0x183153=0x0;_0x183153<_0x355437[_0xe782('0x3d')];_0x183153+=0x1){let _0x4fbbdb=_0x355437[_0x183153];for(var _0x3efc09=0x0;_0x3efc09<_0x4fbbdb[_0xe782('0x6e')][_0xe782('0x3d')];_0x3efc09+=0x1){let _0x193328=_0x4fbbdb[_0xe782('0x6e')][_0x3efc09];var _0x3c36b4=_0x61d222[_0xe782('0x7e')]();_0x3c36b4['where'](_0xe782('0x7f'),_0x193328['id']);_0x5d4e61[_0xe782('0x80')](db[_0xe782('0x81')][_0xe782('0x38')](_0x3c36b4[_0xe782('0x82')](),{'type':db[_0xe782('0x81')][_0xe782('0x83')][_0xe782('0x84')]})[_0xe782('0x29')](function(_0x3fc6df){if(_0x3fc6df['length']===0x1){return _0x193328['id'];}else{var _0xbf7343=_[_0xe782('0x85')](_[_0xe782('0x32')](_0x3fc6df,'TeamId'),function(_0x48b2d3){return _[_0xe782('0x86')](_0x5bfa9b,_0x48b2d3);});if(_0xbf7343){return _0x193328['id'];}}}));}}return BPromise[_0xe782('0x87')](_0x5d4e61)[_0xe782('0x29')](function(_0x1280fb){_0x372a17=_(_0x372a17)[_0xe782('0x88')](_0x1280fb)['compact']()[_0xe782('0x89')]();return db['SmsQueue']['find']({'where':{'id':_0x181a01[_0xe782('0x4a')]['id']}})['then'](function(_0x21b436){return db[_0xe782('0x81')][_0xe782('0x73')](function(_0x139951){return _0x21b436[_0xe782('0x77')](_0x181a01[_0xe782('0x38')]['ids'],{'transaction':_0x139951})['then'](function(){if(!_[_0xe782('0x8a')](_0x372a17)){return _0x21b436[_0xe782('0x8b')](_0x372a17,{'transaction':_0x139951});}})[_0xe782('0x29')](function(){_0x372a17[_0xe782('0x76')](function(_0x970711){socket[_0xe782('0x8c')]('userSmsQueue:remove',{'UserId':_0x970711,'SmsQueueId':_0x21b436['id']});});});});});});})['then'](respondWithStatusCode(_0xc7226c,null))['catch'](handleError(_0xc7226c,null));};exports[_0xe782('0x8d')]=function(_0x1b9676,_0x5236bc,_0x30cb92){return db[_0xe782('0x4b')][_0xe782('0x4f')]({'where':{'id':_0x1b9676[_0xe782('0x4a')]['id']}})[_0xe782('0x29')](handleEntityNotFound(_0x5236bc,null))[_0xe782('0x29')](function(_0x3100dd){if(_0x3100dd){return _0x3100dd[_0xe782('0x8d')](_0x1b9676[_0xe782('0x58')][_0xe782('0x6d')],_[_0xe782('0x8e')](_0x1b9676['body'],[_0xe782('0x6d'),'id'])||{})[_0xe782('0x8f')](function(_0x3462d2){for(var _0x4115e4=0x0;_0x4115e4<_0x1b9676[_0xe782('0x58')]['ids'][_0xe782('0x3d')];_0x4115e4+=0x1){socket[_0xe782('0x8c')](_0xe782('0x90'),{'UserId':Number(_0x1b9676[_0xe782('0x58')]['ids'][_0x4115e4]),'SmsQueueId':Number(_0x1b9676[_0xe782('0x4a')]['id'])});}return _0x3462d2;});}})[_0xe782('0x29')](respondWithResult(_0x5236bc,null))['catch'](handleError(_0x5236bc,null));};exports['removeAgents']=function(_0x501c1c,_0x4353c2,_0x4b167d){return db[_0xe782('0x4b')][_0xe782('0x4f')]({'where':{'id':_0x501c1c[_0xe782('0x4a')]['id']}})[_0xe782('0x29')](handleEntityNotFound(_0x4353c2,null))[_0xe782('0x29')](function(_0x2b7f88){if(_0x2b7f88){return _0x2b7f88[_0xe782('0x8b')](_0x501c1c[_0xe782('0x38')][_0xe782('0x6d')])['then'](function(){if(_[_0xe782('0x91')](_0x501c1c['query'][_0xe782('0x6d')])){for(var _0x1b2e41=0x0;_0x1b2e41<_0x501c1c[_0xe782('0x38')]['ids'][_0xe782('0x3d')];_0x1b2e41+=0x1){socket[_0xe782('0x8c')](_0xe782('0x92'),{'UserId':Number(_0x501c1c[_0xe782('0x38')][_0xe782('0x6d')][_0x1b2e41]),'SmsQueueId':Number(_0x501c1c[_0xe782('0x4a')]['id'])});}}else{socket[_0xe782('0x8c')](_0xe782('0x92'),{'UserId':Number(_0x501c1c[_0xe782('0x38')]['ids']),'SmsQueueId':Number(_0x501c1c[_0xe782('0x4a')]['id'])});}});}})[_0xe782('0x29')](respondWithStatusCode(_0x4353c2,null))['catch'](handleError(_0x4353c2,null));};exports[_0xe782('0x93')]=function(_0x341fb6,_0x240c03,_0x317767){var _0x5e1b06={};var _0x1a187a={};var _0x35eb78;var _0x7d1cf3;return db[_0xe782('0x4b')][_0xe782('0x5c')]({'where':{'id':_0x341fb6[_0xe782('0x4a')]['id']}})['then'](handleEntityNotFound(_0x240c03,null))[_0xe782('0x29')](function(_0x362a3a){if(_0x362a3a){_0x35eb78=_0x362a3a;_0x1a187a[_0xe782('0x36')]=_[_0xe782('0x37')](db[_0xe782('0x61')]['rawAttributes']);_0x1a187a[_0xe782('0x38')]=_[_0xe782('0x37')](_0x341fb6['query']);_0x1a187a[_0xe782('0x39')]=_[_0xe782('0x3a')](_0x1a187a[_0xe782('0x36')],_0x1a187a['query']);_0x5e1b06['attributes']=_['intersection'](_0x1a187a[_0xe782('0x36')],qs[_0xe782('0x3c')](_0x341fb6[_0xe782('0x38')][_0xe782('0x3c')]));_0x5e1b06[_0xe782('0x3b')]=_0x5e1b06[_0xe782('0x3b')][_0xe782('0x3d')]?_0x5e1b06[_0xe782('0x3b')]:_0x1a187a[_0xe782('0x36')];_0x5e1b06['order']=qs[_0xe782('0x40')](_0x341fb6[_0xe782('0x38')][_0xe782('0x40')]);_0x5e1b06[_0xe782('0x41')]=qs['filters'](_[_0xe782('0x42')](_0x341fb6[_0xe782('0x38')],_0x1a187a[_0xe782('0x39')]));if(_0x341fb6[_0xe782('0x38')][_0xe782('0x43')]){_0x5e1b06[_0xe782('0x41')]=_[_0xe782('0x44')](_0x5e1b06[_0xe782('0x41')],{'$or':_[_0xe782('0x32')](_0x5e1b06['attributes'],function(_0x316634){var _0x4cc4a5={};_0x4cc4a5[_0x316634]={'$like':'%'+_0x341fb6[_0xe782('0x38')][_0xe782('0x43')]+'%'};return _0x4cc4a5;})});}_0x5e1b06=_[_0xe782('0x44')]({},_0x5e1b06,_0x341fb6[_0xe782('0x4e')]);return _0x35eb78[_0xe782('0x93')](_0x5e1b06);}})['then'](function(_0x168d36){if(_0x168d36){_0x7d1cf3=_0x168d36[_0xe782('0x3d')];if(!_0x341fb6[_0xe782('0x38')][_0xe782('0x5e')]('nolimit')){_0x5e1b06[_0xe782('0x22')]=qs['limit'](_0x341fb6[_0xe782('0x38')][_0xe782('0x22')]);_0x5e1b06[_0xe782('0x20')]=qs[_0xe782('0x20')](_0x341fb6[_0xe782('0x38')][_0xe782('0x20')]);}return _0x35eb78['getAgents'](_0x5e1b06);}})[_0xe782('0x29')](function(_0x398221){if(_0x398221){return _0x398221?{'count':_0x7d1cf3,'rows':_0x398221}:null;}})['then'](respondWithResult(_0x240c03,null))[_0xe782('0x48')](handleError(_0x240c03,null));};
\ No newline at end of file
+var _0x5f66=['show','params','model','keys','intersection','attributes','fields','includeAll','merge','options','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','SmsQueues','find','userProfileId','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','rawAttributes','filters','hasOwnProperty','order','sort','pick','map','UserSmsQueue','User','findAndCountAll','UserId','agent','smsPause','updatedAt','createdAt','%s/%s','SIP','getTeams','length','filter','nolimit','ids','Team','Agents','interface','flatMap','sequelize','transaction','addTeams','forEach','emit','userSmsQueue:save','removeTeams','select','tq.TeamId','team_has_sms_queues','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','toString','QueryTypes','SELECT','includes','all','compact','value','isEmpty','removeAgents','userSmsQueue:remove','addAgents','spread','isArray','findOne','getAgents','util','squel','ioredis','../../components/parsers/qs','../../config/logger','api','../../mysqldb','defaults','redis','./smsQueue.socket','register','end','json','offset','limit','undefined','count','status','update','then','UserProfileResource','destroy','sendStatus','stack','name','send','index','fieldName','key','getOptions','where','SmsQueue','include','query','findAll','catch'];(function(_0x4d62ae,_0x1509f5){var _0x54d4b7=function(_0x492d51){while(--_0x492d51){_0x4d62ae['push'](_0x4d62ae['shift']());}};_0x54d4b7(++_0x1509f5);}(_0x5f66,0x1a0));var _0x65f6=function(_0x3947c9,_0x4d6c97){_0x3947c9=_0x3947c9-0x0;var _0x2e7871=_0x5f66[_0x3947c9];return _0x2e7871;};'use strict';var BPromise=require('bluebird');var util=require(_0x65f6('0x0'));var _=require('lodash');var squel=require(_0x65f6('0x1'));var Redis=require(_0x65f6('0x2'));var qs=require(_0x65f6('0x3'));var logger=require(_0x65f6('0x4'))(_0x65f6('0x5'));var config=require('../../config/environment');var db=require(_0x65f6('0x6'))['db'];config['redis']=_[_0x65f6('0x7')](config[_0x65f6('0x8')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x65f6('0x8')]));require(_0x65f6('0x9'))[_0x65f6('0xa')](socket);function respondWithStatusCode(_0x8f6451,_0xc44c70){_0xc44c70=_0xc44c70||0xcc;return function(_0x14f4c7){if(_0x14f4c7){return _0x8f6451['sendStatus'](_0xc44c70);}return _0x8f6451['status'](_0xc44c70)[_0x65f6('0xb')]();};}function respondWithResult(_0x2f6d5b,_0x264647){_0x264647=_0x264647||0xc8;return function(_0x25c416){if(_0x25c416){return _0x2f6d5b['status'](_0x264647)[_0x65f6('0xc')](_0x25c416);}};}function respondWithFilteredResult(_0x571436,_0x497cf3){return function(_0x2d2dfa){if(_0x2d2dfa){var _0x576875=typeof _0x497cf3[_0x65f6('0xd')]==='undefined'&&typeof _0x497cf3[_0x65f6('0xe')]===_0x65f6('0xf');var _0x2c4ee5=_0x2d2dfa[_0x65f6('0x10')];var _0x369f96=_0x576875?0x0:_0x497cf3[_0x65f6('0xd')];var _0x44144b=_0x576875?_0x2d2dfa[_0x65f6('0x10')]:_0x497cf3[_0x65f6('0xd')]+_0x497cf3[_0x65f6('0xe')];var _0x59154e;if(_0x44144b>=_0x2c4ee5){_0x44144b=_0x2c4ee5;_0x59154e=0xc8;}else{_0x59154e=0xce;}_0x571436[_0x65f6('0x11')](_0x59154e);return _0x571436['set']('Content-Range',_0x369f96+'-'+_0x44144b+'/'+_0x2c4ee5)[_0x65f6('0xc')](_0x2d2dfa);}return null;};}function saveUpdates(_0x5c69f8){return function(_0x37330d){if(_0x37330d){return _0x37330d[_0x65f6('0x12')](_0x5c69f8)[_0x65f6('0x13')](function(_0x1f974c){return _0x1f974c;});}return null;};}function removeEntity(_0xc8660c){return function(_0x18380e){if(_0x18380e){return _0x18380e['destroy']()['then'](function(){var _0x2d538c=_0x18380e['get']({'plain':!![]});var _0x4c81f3='SmsQueues';return db[_0x65f6('0x14')][_0x65f6('0x15')]({'where':{'type':_0x4c81f3,'resourceId':_0x2d538c['id']}})['then'](function(){return _0x18380e;});})[_0x65f6('0x13')](function(){_0xc8660c[_0x65f6('0x11')](0xcc)[_0x65f6('0xb')]();});}};}function handleEntityNotFound(_0x3876ed){return function(_0x219ab2){if(!_0x219ab2){_0x3876ed[_0x65f6('0x16')](0x194);}return _0x219ab2;};}function handleError(_0x581374,_0x197a49){_0x197a49=_0x197a49||0x1f4;return function(_0x4bb39e){logger['error'](_0x4bb39e[_0x65f6('0x17')]);if(_0x4bb39e[_0x65f6('0x18')]){delete _0x4bb39e['name'];}_0x581374[_0x65f6('0x11')](_0x197a49)[_0x65f6('0x19')](_0x4bb39e);};}exports[_0x65f6('0x1a')]=function(_0x2774a1,_0x4f5a69){var _0x9d7bb0={};var _0x59ea32={'count':0x0,'rows':[]};var _0x20a161=_['map'](db['SmsQueue']['rawAttributes'],function(_0x29abdb){return{'name':_0x29abdb[_0x65f6('0x1b')],'type':_0x29abdb['type'][_0x65f6('0x1c')]};});_0x9d7bb0=qs[_0x65f6('0x1d')](_0x20a161,_0x2774a1);var _0x52277c={'where':_0x9d7bb0[_0x65f6('0x1e')]};return db[_0x65f6('0x1f')][_0x65f6('0x10')](_0x52277c)['then'](function(_0x4ac04b){_0x59ea32['count']=_0x4ac04b;_0x9d7bb0[_0x65f6('0x20')]=qs[_0x65f6('0x20')](_0x2774a1[_0x65f6('0x21')]);return db[_0x65f6('0x1f')][_0x65f6('0x22')](_0x9d7bb0);})[_0x65f6('0x13')](function(_0x144e55){_0x59ea32['rows']=_0x144e55;return _0x59ea32;})['then'](respondWithFilteredResult(_0x4f5a69,_0x9d7bb0))[_0x65f6('0x23')](handleError(_0x4f5a69,null));};exports[_0x65f6('0x24')]=function(_0x5878bc,_0x4e50c0){var _0x10b368={'raw':!![],'where':{'id':_0x5878bc[_0x65f6('0x25')]['id']}},_0x1ce43c={};_0x1ce43c[_0x65f6('0x26')]=_[_0x65f6('0x27')](db[_0x65f6('0x1f')]['rawAttributes']);_0x1ce43c[_0x65f6('0x21')]=_[_0x65f6('0x27')](_0x5878bc[_0x65f6('0x21')]);_0x1ce43c['filters']=_[_0x65f6('0x28')](_0x1ce43c[_0x65f6('0x26')],_0x1ce43c[_0x65f6('0x21')]);_0x10b368[_0x65f6('0x29')]=_[_0x65f6('0x28')](_0x1ce43c[_0x65f6('0x26')],qs['fields'](_0x5878bc[_0x65f6('0x21')][_0x65f6('0x2a')]));_0x10b368['attributes']=_0x10b368[_0x65f6('0x29')]['length']?_0x10b368[_0x65f6('0x29')]:_0x1ce43c['model'];if(_0x5878bc[_0x65f6('0x21')][_0x65f6('0x2b')]){_0x10b368['include']=[{'all':!![]}];}_0x10b368=_[_0x65f6('0x2c')]({},_0x10b368,_0x5878bc[_0x65f6('0x2d')]);return db[_0x65f6('0x1f')]['find'](_0x10b368)['then'](handleEntityNotFound(_0x4e50c0,null))[_0x65f6('0x13')](respondWithResult(_0x4e50c0,null))['catch'](handleError(_0x4e50c0,null));};exports[_0x65f6('0x2e')]=function(_0x4e6653,_0x22d760){return db[_0x65f6('0x1f')]['create'](_0x4e6653[_0x65f6('0x2f')],{})['then'](function(_0x5edd04){var _0x71b16b=_0x4e6653[_0x65f6('0x30')][_0x65f6('0x31')]({'plain':!![]});if(!_0x71b16b)throw new Error(_0x65f6('0x32'));if(_0x71b16b[_0x65f6('0x33')]===_0x65f6('0x30')){var _0x1a55da=_0x5edd04[_0x65f6('0x31')]({'plain':!![]});var _0x4f933b=_0x65f6('0x34');return db['UserProfileSection'][_0x65f6('0x35')]({'where':{'name':_0x4f933b,'userProfileId':_0x71b16b[_0x65f6('0x36')]},'raw':!![]})[_0x65f6('0x13')](function(_0x2ea7f7){if(_0x2ea7f7&&_0x2ea7f7['autoAssociation']===0x0){return db[_0x65f6('0x14')][_0x65f6('0x2e')]({'name':_0x1a55da[_0x65f6('0x18')],'resourceId':_0x1a55da['id'],'type':_0x2ea7f7[_0x65f6('0x18')],'sectionId':_0x2ea7f7['id']},{})[_0x65f6('0x13')](function(){return _0x5edd04;});}else{return _0x5edd04;}})[_0x65f6('0x23')](function(_0xed4c96){logger[_0x65f6('0x37')](_0x65f6('0x38'),_0xed4c96);throw _0xed4c96;});}return _0x5edd04;})['then'](respondWithResult(_0x22d760,0xc9))[_0x65f6('0x23')](handleError(_0x22d760,null));};exports[_0x65f6('0x12')]=function(_0x377ae5,_0x181798){if(_0x377ae5[_0x65f6('0x2f')]['id']){delete _0x377ae5[_0x65f6('0x2f')]['id'];}return db[_0x65f6('0x1f')][_0x65f6('0x35')]({'where':{'id':_0x377ae5[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x181798,null))[_0x65f6('0x13')](saveUpdates(_0x377ae5[_0x65f6('0x2f')],null))[_0x65f6('0x13')](respondWithResult(_0x181798,null))[_0x65f6('0x23')](handleError(_0x181798,null));};exports[_0x65f6('0x15')]=function(_0x2cb38d,_0x5119ee){return db[_0x65f6('0x1f')][_0x65f6('0x35')]({'where':{'id':_0x2cb38d[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x5119ee,null))['then'](removeEntity(_0x5119ee,null))[_0x65f6('0x23')](handleError(_0x5119ee,null));};exports[_0x65f6('0x39')]=function(_0x2b01eb,_0x5e69b4){return db[_0x65f6('0x1f')][_0x65f6('0x39')]()[_0x65f6('0x13')](respondWithResult(_0x5e69b4,null))[_0x65f6('0x23')](handleError(_0x5e69b4,null));};exports['getMembers']=function(_0x2ec114,_0x512527){var _0x3f1baa={'raw':!![],'where':{}},_0x6968b={},_0x577c93;return db[_0x65f6('0x1f')]['findOne']({'where':{'id':_0x2ec114[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x512527,null))[_0x65f6('0x13')](function(_0xc0db01){if(_0xc0db01){_0x577c93=_0xc0db01[_0x65f6('0x31')]({'plain':!![]});_0x6968b[_0x65f6('0x26')]=_['keys'](db['UserSmsQueue'][_0x65f6('0x3a')]);_0x6968b[_0x65f6('0x21')]=_[_0x65f6('0x27')](_0x2ec114[_0x65f6('0x21')]);_0x6968b[_0x65f6('0x3b')]=_[_0x65f6('0x28')](_0x6968b[_0x65f6('0x26')],_0x6968b[_0x65f6('0x21')]);_0x3f1baa[_0x65f6('0x29')]=_['intersection'](_0x6968b[_0x65f6('0x26')],qs[_0x65f6('0x2a')](_0x2ec114[_0x65f6('0x21')]['fields']));_0x3f1baa[_0x65f6('0x29')]=_0x3f1baa[_0x65f6('0x29')]['length']?_0x3f1baa[_0x65f6('0x29')]:_0x6968b[_0x65f6('0x26')];if(!_0x2ec114['query'][_0x65f6('0x3c')]('nolimit')){_0x3f1baa[_0x65f6('0xe')]=qs[_0x65f6('0xe')](_0x2ec114[_0x65f6('0x21')]['limit']);_0x3f1baa[_0x65f6('0xd')]=qs[_0x65f6('0xd')](_0x2ec114['query'][_0x65f6('0xd')]);}_0x3f1baa[_0x65f6('0x3d')]=qs['sort'](_0x2ec114[_0x65f6('0x21')][_0x65f6('0x3e')]);_0x3f1baa[_0x65f6('0x1e')]=qs[_0x65f6('0x3b')](_[_0x65f6('0x3f')](_0x2ec114[_0x65f6('0x21')],_0x6968b[_0x65f6('0x3b')]));_0x3f1baa[_0x65f6('0x1e')]['SmsQueueId']=_0xc0db01['id'];if(_0x2ec114['query']['filter']){_0x3f1baa[_0x65f6('0x1e')]=_[_0x65f6('0x2c')](_0x3f1baa[_0x65f6('0x1e')],{'$or':_[_0x65f6('0x40')](_0x3f1baa['attributes'],function(_0x183c08){var _0x2032b9={};_0x2032b9[_0x183c08]={'$like':'%'+_0x2ec114[_0x65f6('0x21')]['filter']+'%'};return _0x2032b9;})});}_0x3f1baa=_[_0x65f6('0x2c')]({},_0x3f1baa,_0x2ec114[_0x65f6('0x2d')]);return db[_0x65f6('0x41')]['findAll'](_0x3f1baa);}})['then'](function(_0x1d337d){if(_0x1d337d){return db[_0x65f6('0x42')][_0x65f6('0x43')]({'where':{'id':_[_0x65f6('0x40')](_0x1d337d,_0x65f6('0x44')),'role':_0x65f6('0x45')},'attributes':['id',_0x65f6('0x18'),_0x65f6('0x46'),_0x65f6('0x47'),_0x65f6('0x48')]});}})[_0x65f6('0x13')](function(_0x141fcc){if(_0x141fcc){return{'count':_0x141fcc[_0x65f6('0x10')],'rows':_[_0x65f6('0x40')](_0x141fcc['rows'],function(_0x47610a){return{'membername':_0x47610a[_0x65f6('0x18')],'UserId':_0x47610a['id'],'queue_name':_0x577c93[_0x65f6('0x18')],'SmsQueueId':_0x577c93['id'],'interface':util['format'](_0x65f6('0x49'),_0x65f6('0x4a'),_0x47610a[_0x65f6('0x18')]),'penalty':0x0,'paused':_0x47610a[_0x65f6('0x46')],'createdAt':_0x47610a['createdAt'],'updatedAt':_0x47610a[_0x65f6('0x47')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x65f6('0x13')](respondWithFilteredResult(_0x512527,_0x3f1baa))[_0x65f6('0x23')](handleError(_0x512527,null));};exports[_0x65f6('0x4b')]=function(_0x553ff0,_0x2923ff){var _0x2fc20f={};var _0x5c55e4={};var _0x28682b;var _0x26481e;return db[_0x65f6('0x1f')]['findOne']({'where':{'id':_0x553ff0[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x2923ff,null))[_0x65f6('0x13')](function(_0x3c23e3){if(_0x3c23e3){_0x28682b=_0x3c23e3;_0x5c55e4[_0x65f6('0x26')]=_[_0x65f6('0x27')](db['Team']['rawAttributes']);_0x5c55e4['query']=_[_0x65f6('0x27')](_0x553ff0[_0x65f6('0x21')]);_0x5c55e4[_0x65f6('0x3b')]=_[_0x65f6('0x28')](_0x5c55e4[_0x65f6('0x26')],_0x5c55e4[_0x65f6('0x21')]);_0x2fc20f['attributes']=_[_0x65f6('0x28')](_0x5c55e4[_0x65f6('0x26')],qs['fields'](_0x553ff0[_0x65f6('0x21')][_0x65f6('0x2a')]));_0x2fc20f[_0x65f6('0x29')]=_0x2fc20f['attributes'][_0x65f6('0x4c')]?_0x2fc20f[_0x65f6('0x29')]:_0x5c55e4['model'];_0x2fc20f[_0x65f6('0x3d')]=qs[_0x65f6('0x3e')](_0x553ff0[_0x65f6('0x21')][_0x65f6('0x3e')]);_0x2fc20f[_0x65f6('0x1e')]=qs[_0x65f6('0x3b')](_[_0x65f6('0x3f')](_0x553ff0['query'],_0x5c55e4['filters']));if(_0x553ff0[_0x65f6('0x21')][_0x65f6('0x4d')]){_0x2fc20f['where']=_[_0x65f6('0x2c')](_0x2fc20f['where'],{'$or':_[_0x65f6('0x40')](_0x2fc20f['attributes'],function(_0x440df1){var _0xdc8989={};_0xdc8989[_0x440df1]={'$like':'%'+_0x553ff0[_0x65f6('0x21')][_0x65f6('0x4d')]+'%'};return _0xdc8989;})});}_0x2fc20f=_[_0x65f6('0x2c')]({},_0x2fc20f,_0x553ff0[_0x65f6('0x2d')]);return _0x28682b[_0x65f6('0x4b')](_0x2fc20f);}})[_0x65f6('0x13')](function(_0x2405a7){if(_0x2405a7){_0x26481e=_0x2405a7['length'];if(!_0x553ff0['query'][_0x65f6('0x3c')](_0x65f6('0x4e'))){_0x2fc20f[_0x65f6('0xe')]=qs['limit'](_0x553ff0['query'][_0x65f6('0xe')]);_0x2fc20f[_0x65f6('0xd')]=qs[_0x65f6('0xd')](_0x553ff0[_0x65f6('0x21')][_0x65f6('0xd')]);}return _0x28682b[_0x65f6('0x4b')](_0x2fc20f);}})['then'](function(_0x4f42ae){if(_0x4f42ae){return _0x4f42ae?{'count':_0x26481e,'rows':_0x4f42ae}:null;}})[_0x65f6('0x13')](respondWithResult(_0x2923ff,null))[_0x65f6('0x23')](handleError(_0x2923ff,null));};exports['addTeams']=function(_0x219bf8,_0x4a8b60){var _0x254e9f=_0x219bf8[_0x65f6('0x2f')][_0x65f6('0x4f')];return db[_0x65f6('0x50')]['findAll']({'where':{'id':_0x254e9f},'attributes':['id'],'include':[{'model':db[_0x65f6('0x42')],'as':_0x65f6('0x51'),'attributes':['id',_0x65f6('0x18'),'online','voicePause',_0x65f6('0x52')],'raw':!![]}]})['then'](function(_0x305967){if(_0x305967){var _0xf6de=_[_0x65f6('0x53')](_0x305967,function(_0x354b90){var _0x512776=_0x354b90['get']({'plain':!![]});return _0x512776['Agents'];});return db[_0x65f6('0x1f')][_0x65f6('0x35')]({'where':{'id':_0x219bf8[_0x65f6('0x25')]['id']}})['then'](function(_0x46cbde){return db[_0x65f6('0x54')][_0x65f6('0x55')](function(_0x49cee2){return _0x46cbde[_0x65f6('0x56')](_0x254e9f,{'transaction':_0x49cee2})[_0x65f6('0x13')](function(){return BPromise['each'](_0xf6de,function(_0x758e80){return db[_0x65f6('0x41')]['findOrCreate']({'where':{'UserId':_0x758e80['id'],'SmsQueueId':_0x219bf8[_0x65f6('0x25')]['id']},'transaction':_0x49cee2});});})['then'](function(){_0xf6de[_0x65f6('0x57')](function(_0x55ea91){socket[_0x65f6('0x58')](_0x65f6('0x59'),{'UserId':_0x55ea91['id'],'SmsQueueId':_0x46cbde['id']});});});});});}})['then'](respondWithStatusCode(_0x4a8b60,null))[_0x65f6('0x23')](handleError(_0x4a8b60,null));};exports[_0x65f6('0x5a')]=function(_0x2a700b,_0x299b85){return db[_0x65f6('0x50')][_0x65f6('0x22')]({'where':{'id':_0x2a700b[_0x65f6('0x21')][_0x65f6('0x4f')]},'attributes':['id'],'include':[{'model':db[_0x65f6('0x42')],'as':_0x65f6('0x51'),'attributes':['id'],'raw':!![]}]})[_0x65f6('0x13')](handleEntityNotFound(_0x299b85,null))['then'](function(_0x10a661){var _0x1cf1bd=_[_0x65f6('0x40')](_0x10a661,'id');var _0x219e42=[];var _0x5694f9=[];var _0x453080=squel[_0x65f6('0x5b')]();_0x453080['field'](_0x65f6('0x5c'))['from'](_0x65f6('0x5d'),'tq')['join'](_0x65f6('0x5e'),'ut',_0x65f6('0x5f'))['where']('SmsQueueId\x20=\x20?',_0x2a700b[_0x65f6('0x25')]['id']);for(var _0x413c21=0x0;_0x413c21<_0x10a661['length'];_0x413c21+=0x1){let _0x2d86c8=_0x10a661[_0x413c21];for(var _0x3b3bd5=0x0;_0x3b3bd5<_0x2d86c8[_0x65f6('0x51')]['length'];_0x3b3bd5+=0x1){let _0x1348ec=_0x2d86c8[_0x65f6('0x51')][_0x3b3bd5];var _0x5889dc=_0x453080[_0x65f6('0x60')]();_0x5889dc['where'](_0x65f6('0x61'),_0x1348ec['id']);_0x5694f9['push'](db['sequelize'][_0x65f6('0x21')](_0x5889dc[_0x65f6('0x62')](),{'type':db[_0x65f6('0x54')][_0x65f6('0x63')][_0x65f6('0x64')]})[_0x65f6('0x13')](function(_0x1ac46f){if(_0x1ac46f[_0x65f6('0x4c')]===0x1){return _0x1348ec['id'];}else{var _0x4d66fe=_['every'](_[_0x65f6('0x40')](_0x1ac46f,'TeamId'),function(_0x1ee28a){return _[_0x65f6('0x65')](_0x1cf1bd,_0x1ee28a);});if(_0x4d66fe){return _0x1348ec['id'];}}}));}}return BPromise[_0x65f6('0x66')](_0x5694f9)[_0x65f6('0x13')](function(_0x43127b){_0x219e42=_(_0x219e42)['union'](_0x43127b)[_0x65f6('0x67')]()[_0x65f6('0x68')]();return db[_0x65f6('0x1f')]['find']({'where':{'id':_0x2a700b[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](function(_0x4254c2){return db[_0x65f6('0x54')][_0x65f6('0x55')](function(_0x16bf93){return _0x4254c2['removeTeams'](_0x2a700b['query'][_0x65f6('0x4f')],{'transaction':_0x16bf93})[_0x65f6('0x13')](function(){if(!_[_0x65f6('0x69')](_0x219e42)){return _0x4254c2[_0x65f6('0x6a')](_0x219e42,{'transaction':_0x16bf93});}})['then'](function(){_0x219e42['forEach'](function(_0x336076){socket[_0x65f6('0x58')](_0x65f6('0x6b'),{'UserId':_0x336076,'SmsQueueId':_0x4254c2['id']});});});});});});})[_0x65f6('0x13')](respondWithStatusCode(_0x299b85,null))[_0x65f6('0x23')](handleError(_0x299b85,null));};exports[_0x65f6('0x6c')]=function(_0x5daaf4,_0x4d607a){return db['SmsQueue'][_0x65f6('0x35')]({'where':{'id':_0x5daaf4[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x4d607a,null))[_0x65f6('0x13')](function(_0x53b11c){if(_0x53b11c){return _0x53b11c['addAgents'](_0x5daaf4[_0x65f6('0x2f')][_0x65f6('0x4f')],_['omit'](_0x5daaf4[_0x65f6('0x2f')],['ids','id'])||{})[_0x65f6('0x6d')](function(_0x4f3ef8){for(var _0x3a30ed=0x0;_0x3a30ed<_0x5daaf4[_0x65f6('0x2f')]['ids'][_0x65f6('0x4c')];_0x3a30ed+=0x1){socket[_0x65f6('0x58')](_0x65f6('0x59'),{'UserId':Number(_0x5daaf4[_0x65f6('0x2f')][_0x65f6('0x4f')][_0x3a30ed]),'SmsQueueId':Number(_0x5daaf4[_0x65f6('0x25')]['id'])});}return _0x4f3ef8;});}})['then'](respondWithResult(_0x4d607a,null))[_0x65f6('0x23')](handleError(_0x4d607a,null));};exports['removeAgents']=function(_0x24495c,_0x56336a){return db[_0x65f6('0x1f')][_0x65f6('0x35')]({'where':{'id':_0x24495c[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x56336a,null))['then'](function(_0x2b6f98){if(_0x2b6f98){return _0x2b6f98[_0x65f6('0x6a')](_0x24495c[_0x65f6('0x21')]['ids'])['then'](function(){if(_[_0x65f6('0x6e')](_0x24495c[_0x65f6('0x21')]['ids'])){for(var _0x180cde=0x0;_0x180cde<_0x24495c[_0x65f6('0x21')][_0x65f6('0x4f')]['length'];_0x180cde+=0x1){socket[_0x65f6('0x58')](_0x65f6('0x6b'),{'UserId':Number(_0x24495c['query'][_0x65f6('0x4f')][_0x180cde]),'SmsQueueId':Number(_0x24495c[_0x65f6('0x25')]['id'])});}}else{socket[_0x65f6('0x58')]('userSmsQueue:remove',{'UserId':Number(_0x24495c[_0x65f6('0x21')][_0x65f6('0x4f')]),'SmsQueueId':Number(_0x24495c[_0x65f6('0x25')]['id'])});}});}})['then'](respondWithStatusCode(_0x56336a,null))[_0x65f6('0x23')](handleError(_0x56336a,null));};exports['getAgents']=function(_0x1beaa7,_0x87a9e4){var _0x31ec61={};var _0x22be6e={};var _0x29b2de;var _0x430fb8;return db['SmsQueue'][_0x65f6('0x6f')]({'where':{'id':_0x1beaa7[_0x65f6('0x25')]['id']}})[_0x65f6('0x13')](handleEntityNotFound(_0x87a9e4,null))[_0x65f6('0x13')](function(_0x207d15){if(_0x207d15){_0x29b2de=_0x207d15;_0x22be6e['model']=_['keys'](db['User'][_0x65f6('0x3a')]);_0x22be6e[_0x65f6('0x21')]=_[_0x65f6('0x27')](_0x1beaa7['query']);_0x22be6e[_0x65f6('0x3b')]=_['intersection'](_0x22be6e['model'],_0x22be6e[_0x65f6('0x21')]);_0x31ec61[_0x65f6('0x29')]=_['intersection'](_0x22be6e[_0x65f6('0x26')],qs[_0x65f6('0x2a')](_0x1beaa7[_0x65f6('0x21')][_0x65f6('0x2a')]));_0x31ec61[_0x65f6('0x29')]=_0x31ec61[_0x65f6('0x29')][_0x65f6('0x4c')]?_0x31ec61[_0x65f6('0x29')]:_0x22be6e[_0x65f6('0x26')];_0x31ec61[_0x65f6('0x3d')]=qs[_0x65f6('0x3e')](_0x1beaa7[_0x65f6('0x21')]['sort']);_0x31ec61[_0x65f6('0x1e')]=qs['filters'](_['pick'](_0x1beaa7[_0x65f6('0x21')],_0x22be6e[_0x65f6('0x3b')]));if(_0x1beaa7[_0x65f6('0x21')][_0x65f6('0x4d')]){_0x31ec61['where']=_[_0x65f6('0x2c')](_0x31ec61['where'],{'$or':_['map'](_0x31ec61[_0x65f6('0x29')],function(_0x99fe6e){var _0x1a7e52={};_0x1a7e52[_0x99fe6e]={'$like':'%'+_0x1beaa7[_0x65f6('0x21')][_0x65f6('0x4d')]+'%'};return _0x1a7e52;})});}_0x31ec61=_[_0x65f6('0x2c')]({},_0x31ec61,_0x1beaa7['options']);return _0x29b2de[_0x65f6('0x70')](_0x31ec61);}})['then'](function(_0x1ef2a0){if(_0x1ef2a0){_0x430fb8=_0x1ef2a0[_0x65f6('0x4c')];if(!_0x1beaa7[_0x65f6('0x21')]['hasOwnProperty'](_0x65f6('0x4e'))){_0x31ec61['limit']=qs['limit'](_0x1beaa7[_0x65f6('0x21')][_0x65f6('0xe')]);_0x31ec61[_0x65f6('0xd')]=qs[_0x65f6('0xd')](_0x1beaa7[_0x65f6('0x21')]['offset']);}return _0x29b2de[_0x65f6('0x70')](_0x31ec61);}})[_0x65f6('0x13')](function(_0x3bebe3){if(_0x3bebe3){return _0x3bebe3?{'count':_0x430fb8,'rows':_0x3bebe3}:null;}})[_0x65f6('0x13')](respondWithResult(_0x87a9e4,null))['catch'](handleError(_0x87a9e4,null));};
\ No newline at end of file