Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / faxQueue / faxQueue.controller.js
index 6332a67..09d0cb3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0879=['filter','VIRTUAL','options','includeAll','include','findAll','rows','show','params','keys','rawAttributes','merge','find','create','body','user','role','UserProfileSection','userProfileId','autoAssociation','catch','describe','getMembers','findOne','UserFaxQueue','nolimit','FaxQueueId','User','findAndCountAll','UserId','faxPause','updatedAt','createdAt','format','%s/%s','getTeams','Team','addTeams','ids','Agents','online','voicePause','interface','flatMap','sequelize','transaction','each','findOrCreate','forEach','emit','userFaxQueue:save','removeTeams','tq.TeamId','from','team_has_fax_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','FaxQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','SELECT','TeamId','includes','union','compact','value','removeAgents','userFaxQueue:remove','addAgents','omit','spread','getAgents','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','socket.io-emitter','./faxQueue.socket','sendStatus','end','status','count','offset','limit','Content-Range','json','apply','save','update','then','destroy','get','FaxQueues','UserProfileResource','error','stack','name','send','FaxQueue','type','map','query','model','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','filters','pick'];(function(_0x31ca49,_0x5e6186){var _0x59548b=function(_0x58b04c){while(--_0x58b04c){_0x31ca49['push'](_0x31ca49['shift']());}};_0x59548b(++_0x5e6186);}(_0x0879,0x1e9));var _0x9087=function(_0x5e2e6e,_0x119816){_0x5e2e6e=_0x5e2e6e-0x0;var _0x4e4637=_0x0879[_0x5e2e6e];return _0x4e4637;};'use strict';var pdf=require(_0x9087('0x0'));var emlformat=require(_0x9087('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x9087('0x2'));var jsonpatch=require(_0x9087('0x3'));var rp=require(_0x9087('0x4'));var moment=require('moment');var BPromise=require(_0x9087('0x5'));var Mustache=require(_0x9087('0x6'));var util=require(_0x9087('0x7'));var path=require(_0x9087('0x8'));var sox=require('sox');var csv=require(_0x9087('0x9'));var ejs=require(_0x9087('0xa'));var fs=require('fs');var _=require(_0x9087('0xb'));var squel=require(_0x9087('0xc'));var crypto=require(_0x9087('0xd'));var jsforce=require(_0x9087('0xe'));var deskjs=require(_0x9087('0xf'));var toCsv=require('to-csv');var querystring=require(_0x9087('0x10'));var Papa=require('papaparse');var Redis=require(_0x9087('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x9087('0x12'));var hardwareService=require(_0x9087('0x13'));var logger=require('../../config/logger')(_0x9087('0x14'));var utils=require(_0x9087('0x15'));var config=require(_0x9087('0x16'));var licenseUtil=require(_0x9087('0x17'));var db=require('../../mysqldb')['db'];config[_0x9087('0x18')]=_[_0x9087('0x19')](config[_0x9087('0x18')],{'host':'localhost','port':0x18eb});var socket=require(_0x9087('0x1a'))(new Redis(config[_0x9087('0x18')]));require(_0x9087('0x1b'))['register'](socket);function respondWithStatusCode(_0x43e290,_0x377e9a){_0x377e9a=_0x377e9a||0xcc;return function(_0x250fb0){if(_0x250fb0){return _0x43e290[_0x9087('0x1c')](_0x377e9a);}return _0x43e290['status'](_0x377e9a)[_0x9087('0x1d')]();};}function respondWithResult(_0x144521,_0x51fc87){_0x51fc87=_0x51fc87||0xc8;return function(_0x47d3e3){if(_0x47d3e3){return _0x144521[_0x9087('0x1e')](_0x51fc87)['json'](_0x47d3e3);}};}function respondWithFilteredResult(_0x5590f9,_0xd9b1b){return function(_0x569a46){if(_0x569a46){var _0x45e93e=_0x569a46[_0x9087('0x1f')],_0x392fd3=_0xd9b1b[_0x9087('0x20')],_0x4721d6=_0xd9b1b[_0x9087('0x20')]+_0xd9b1b[_0x9087('0x21')],_0x4d3030;if(_0x4721d6>=_0x45e93e){_0x4721d6=_0x45e93e;_0x4d3030=0xc8;}else{_0x4d3030=0xce;}_0x5590f9['status'](_0x4d3030);return _0x5590f9['set'](_0x9087('0x22'),_0x392fd3+'-'+_0x4721d6+'/'+_0x45e93e)[_0x9087('0x23')](_0x569a46);}return null;};}function patchUpdates(_0x25d7c1){return function(_0x209f95){try{jsonpatch[_0x9087('0x24')](_0x209f95,_0x25d7c1,!![]);}catch(_0x597c31){return BPromise['reject'](_0x597c31);}return _0x209f95[_0x9087('0x25')]();};}function saveUpdates(_0x585c86,_0x346707){return function(_0x281e65){if(_0x281e65){return _0x281e65[_0x9087('0x26')](_0x585c86)[_0x9087('0x27')](function(_0x66c3bf){return _0x66c3bf;});}return null;};}function removeEntity(_0x52713b,_0x45c711){return function(_0x17b43a){if(_0x17b43a){return _0x17b43a[_0x9087('0x28')]()[_0x9087('0x27')](function(){var _0x4f3e97=_0x17b43a[_0x9087('0x29')]({'plain':!![]});var _0x4ca6b7=_0x9087('0x2a');return db[_0x9087('0x2b')][_0x9087('0x28')]({'where':{'type':_0x4ca6b7,'resourceId':_0x4f3e97['id']}})[_0x9087('0x27')](function(){return _0x17b43a;});})[_0x9087('0x27')](function(){_0x52713b['status'](0xcc)[_0x9087('0x1d')]();});}};}function handleEntityNotFound(_0x3c957c,_0x4a0fc7){return function(_0x6675f7){if(!_0x6675f7){_0x3c957c[_0x9087('0x1c')](0x194);}return _0x6675f7;};}function handleError(_0x46c9ce,_0x38d7dc){_0x38d7dc=_0x38d7dc||0x1f4;return function(_0x189929){logger[_0x9087('0x2c')](_0x189929[_0x9087('0x2d')]);if(_0x189929[_0x9087('0x2e')]){delete _0x189929['name'];}_0x46c9ce[_0x9087('0x1e')](_0x38d7dc)[_0x9087('0x2f')](_0x189929);};}exports['index']=function(_0x3c877d,_0x44fc65){var _0x486b47={},_0x283e32={},_0x48e146={'count':0x0,'rows':[]};var _0x37d8a2=_['map'](db[_0x9087('0x30')]['rawAttributes'],function(_0x18a83b){return{'name':_0x18a83b['fieldName'],'type':_0x18a83b[_0x9087('0x31')]['key']};});_0x283e32['model']=_[_0x9087('0x32')](_0x37d8a2,'name');_0x283e32[_0x9087('0x33')]=_['keys'](_0x3c877d[_0x9087('0x33')]);_0x283e32['filters']=_['intersection'](_0x283e32[_0x9087('0x34')],_0x283e32[_0x9087('0x33')]);_0x486b47[_0x9087('0x35')]=_[_0x9087('0x36')](_0x283e32[_0x9087('0x34')],qs['fields'](_0x3c877d['query'][_0x9087('0x37')]));_0x486b47[_0x9087('0x35')]=_0x486b47[_0x9087('0x35')][_0x9087('0x38')]?_0x486b47[_0x9087('0x35')]:_0x283e32[_0x9087('0x34')];if(!_0x3c877d[_0x9087('0x33')][_0x9087('0x39')]('nolimit')){_0x486b47[_0x9087('0x21')]=qs['limit'](_0x3c877d[_0x9087('0x33')][_0x9087('0x21')]);_0x486b47['offset']=qs[_0x9087('0x20')](_0x3c877d[_0x9087('0x33')][_0x9087('0x20')]);}_0x486b47[_0x9087('0x3a')]=qs[_0x9087('0x3b')](_0x3c877d[_0x9087('0x33')]['sort']);_0x486b47[_0x9087('0x3c')]=qs[_0x9087('0x3d')](_[_0x9087('0x3e')](_0x3c877d[_0x9087('0x33')],_0x283e32[_0x9087('0x3d')]),_0x37d8a2);if(_0x3c877d['query'][_0x9087('0x3f')]){_0x486b47['where']=_['merge'](_0x486b47['where'],{'$or':_[_0x9087('0x32')](_0x37d8a2,function(_0x2cfd9a){if(_0x2cfd9a[_0x9087('0x31')]!==_0x9087('0x40')){var _0x2f6501={};_0x2f6501[_0x2cfd9a[_0x9087('0x2e')]]={'$like':'%'+_0x3c877d[_0x9087('0x33')]['filter']+'%'};return _0x2f6501;}})});}_0x486b47=_['merge']({},_0x486b47,_0x3c877d[_0x9087('0x41')]);var _0x1e4f14={'where':_0x486b47[_0x9087('0x3c')]};return db[_0x9087('0x30')][_0x9087('0x1f')](_0x1e4f14)[_0x9087('0x27')](function(_0x27c0d3){_0x48e146[_0x9087('0x1f')]=_0x27c0d3;if(_0x3c877d['query'][_0x9087('0x42')]){_0x486b47[_0x9087('0x43')]=[{'all':!![]}];}return db['FaxQueue'][_0x9087('0x44')](_0x486b47);})[_0x9087('0x27')](function(_0x4f6ded){_0x48e146[_0x9087('0x45')]=_0x4f6ded;return _0x48e146;})[_0x9087('0x27')](respondWithFilteredResult(_0x44fc65,_0x486b47))['catch'](handleError(_0x44fc65,null));};exports[_0x9087('0x46')]=function(_0x5a0741,_0x39fecb){var _0x39564f={'raw':!![],'where':{'id':_0x5a0741[_0x9087('0x47')]['id']}},_0x4f031f={};_0x4f031f[_0x9087('0x34')]=_[_0x9087('0x48')](db[_0x9087('0x30')][_0x9087('0x49')]);_0x4f031f['query']=_[_0x9087('0x48')](_0x5a0741[_0x9087('0x33')]);_0x4f031f[_0x9087('0x3d')]=_['intersection'](_0x4f031f[_0x9087('0x34')],_0x4f031f[_0x9087('0x33')]);_0x39564f[_0x9087('0x35')]=_[_0x9087('0x36')](_0x4f031f[_0x9087('0x34')],qs[_0x9087('0x37')](_0x5a0741['query'][_0x9087('0x37')]));_0x39564f[_0x9087('0x35')]=_0x39564f[_0x9087('0x35')][_0x9087('0x38')]?_0x39564f[_0x9087('0x35')]:_0x4f031f[_0x9087('0x34')];if(_0x5a0741[_0x9087('0x33')][_0x9087('0x42')]){_0x39564f[_0x9087('0x43')]=[{'all':!![]}];}_0x39564f=_[_0x9087('0x4a')]({},_0x39564f,_0x5a0741[_0x9087('0x41')]);return db[_0x9087('0x30')][_0x9087('0x4b')](_0x39564f)[_0x9087('0x27')](handleEntityNotFound(_0x39fecb,null))['then'](respondWithResult(_0x39fecb,null))['catch'](handleError(_0x39fecb,null));};exports[_0x9087('0x4c')]=function(_0x39db9b,_0x4c8466){return db['FaxQueue']['create'](_0x39db9b[_0x9087('0x4d')],{})['then'](function(_0x9f10a1){var _0x257fbb=_0x39db9b[_0x9087('0x4e')]['get']({'plain':!![]});if(!_0x257fbb)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x257fbb[_0x9087('0x4f')]===_0x9087('0x4e')){var _0x18274=_0x9f10a1[_0x9087('0x29')]({'plain':!![]});var _0x4a3df2='FaxQueues';return db[_0x9087('0x50')][_0x9087('0x4b')]({'where':{'name':_0x4a3df2,'userProfileId':_0x257fbb[_0x9087('0x51')]},'raw':!![]})['then'](function(_0x52346a){if(_0x52346a&&_0x52346a[_0x9087('0x52')]===0x0){return db[_0x9087('0x2b')][_0x9087('0x4c')]({'name':_0x18274[_0x9087('0x2e')],'resourceId':_0x18274['id'],'type':_0x52346a[_0x9087('0x2e')],'sectionId':_0x52346a['id']},{})[_0x9087('0x27')](function(){return _0x9f10a1;});}else{return _0x9f10a1;}})[_0x9087('0x53')](function(_0x3ff22b){logger[_0x9087('0x2c')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3ff22b);throw _0x3ff22b;});}return _0x9f10a1;})['then'](respondWithResult(_0x4c8466,0xc9))[_0x9087('0x53')](handleError(_0x4c8466,null));};exports[_0x9087('0x26')]=function(_0x2a7837,_0x33afb0){if(_0x2a7837[_0x9087('0x4d')]['id']){delete _0x2a7837['body']['id'];}return db[_0x9087('0x30')][_0x9087('0x4b')]({'where':{'id':_0x2a7837[_0x9087('0x47')]['id']}})[_0x9087('0x27')](handleEntityNotFound(_0x33afb0,null))['then'](saveUpdates(_0x2a7837[_0x9087('0x4d')],null))[_0x9087('0x27')](respondWithResult(_0x33afb0,null))[_0x9087('0x53')](handleError(_0x33afb0,null));};exports[_0x9087('0x28')]=function(_0x40c855,_0x3a9515){return db[_0x9087('0x30')]['find']({'where':{'id':_0x40c855[_0x9087('0x47')]['id']}})[_0x9087('0x27')](handleEntityNotFound(_0x3a9515,null))[_0x9087('0x27')](removeEntity(_0x3a9515,null))[_0x9087('0x53')](handleError(_0x3a9515,null));};exports[_0x9087('0x54')]=function(_0xb9ca2a,_0x1e4916){return db[_0x9087('0x30')][_0x9087('0x54')]()[_0x9087('0x27')](respondWithResult(_0x1e4916,null))[_0x9087('0x53')](handleError(_0x1e4916,null));};exports[_0x9087('0x55')]=function(_0x7da4fb,_0x572fd3,_0x4e8c52){var _0x8542a8={'raw':!![],'where':{}},_0x5c2cda={},_0x1ca8e3;return db[_0x9087('0x30')][_0x9087('0x56')]({'where':{'id':_0x7da4fb[_0x9087('0x47')]['id']}})[_0x9087('0x27')](handleEntityNotFound(_0x572fd3,null))[_0x9087('0x27')](function(_0x17aa11){if(_0x17aa11){_0x1ca8e3=_0x17aa11[_0x9087('0x29')]({'plain':!![]});_0x5c2cda['model']=_['keys'](db[_0x9087('0x57')][_0x9087('0x49')]);_0x5c2cda[_0x9087('0x33')]=_[_0x9087('0x48')](_0x7da4fb[_0x9087('0x33')]);_0x5c2cda[_0x9087('0x3d')]=_[_0x9087('0x36')](_0x5c2cda[_0x9087('0x34')],_0x5c2cda['query']);_0x8542a8[_0x9087('0x35')]=_[_0x9087('0x36')](_0x5c2cda[_0x9087('0x34')],qs['fields'](_0x7da4fb['query'][_0x9087('0x37')]));_0x8542a8[_0x9087('0x35')]=_0x8542a8['attributes'][_0x9087('0x38')]?_0x8542a8[_0x9087('0x35')]:_0x5c2cda[_0x9087('0x34')];if(!_0x7da4fb[_0x9087('0x33')][_0x9087('0x39')](_0x9087('0x58'))){_0x8542a8[_0x9087('0x21')]=qs[_0x9087('0x21')](_0x7da4fb[_0x9087('0x33')][_0x9087('0x21')]);_0x8542a8[_0x9087('0x20')]=qs[_0x9087('0x20')](_0x7da4fb[_0x9087('0x33')]['offset']);}_0x8542a8[_0x9087('0x3a')]=qs[_0x9087('0x3b')](_0x7da4fb[_0x9087('0x33')][_0x9087('0x3b')]);_0x8542a8[_0x9087('0x3c')]=qs[_0x9087('0x3d')](_[_0x9087('0x3e')](_0x7da4fb[_0x9087('0x33')],_0x5c2cda[_0x9087('0x3d')]));_0x8542a8[_0x9087('0x3c')][_0x9087('0x59')]=_0x17aa11['id'];if(_0x7da4fb[_0x9087('0x33')][_0x9087('0x3f')]){_0x8542a8[_0x9087('0x3c')]=_[_0x9087('0x4a')](_0x8542a8[_0x9087('0x3c')],{'$or':_[_0x9087('0x32')](_0x8542a8['attributes'],function(_0x3eb449){var _0x4ae1d3={};_0x4ae1d3[_0x3eb449]={'$like':'%'+_0x7da4fb[_0x9087('0x33')][_0x9087('0x3f')]+'%'};return _0x4ae1d3;})});}_0x8542a8=_['merge']({},_0x8542a8,_0x7da4fb[_0x9087('0x41')]);return db[_0x9087('0x57')][_0x9087('0x44')](_0x8542a8);}})[_0x9087('0x27')](function(_0x176f80){if(_0x176f80){return db[_0x9087('0x5a')][_0x9087('0x5b')]({'where':{'id':_[_0x9087('0x32')](_0x176f80,_0x9087('0x5c')),'role':'agent'},'attributes':['id',_0x9087('0x2e'),_0x9087('0x5d'),_0x9087('0x5e'),_0x9087('0x5f')]});}})[_0x9087('0x27')](function(_0x405943){if(_0x405943){return{'count':_0x405943[_0x9087('0x1f')],'rows':_[_0x9087('0x32')](_0x405943[_0x9087('0x45')],function(_0x59fc7e){return{'membername':_0x59fc7e[_0x9087('0x2e')],'UserId':_0x59fc7e['id'],'queue_name':_0x1ca8e3[_0x9087('0x2e')],'FaxQueueId':_0x1ca8e3['id'],'interface':util[_0x9087('0x60')](_0x9087('0x61'),'SIP',_0x59fc7e[_0x9087('0x2e')]),'penalty':0x0,'paused':_0x59fc7e[_0x9087('0x5d')],'createdAt':_0x59fc7e['createdAt'],'updatedAt':_0x59fc7e[_0x9087('0x5e')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x9087('0x27')](respondWithFilteredResult(_0x572fd3,_0x8542a8))[_0x9087('0x53')](handleError(_0x572fd3,null));};exports[_0x9087('0x62')]=function(_0x5900d4,_0x20bacf,_0x37e5a9){var _0x210dcc={};var _0x1ce2b1={};var _0x2eb7fe;var _0x1bf1f1;return db['FaxQueue'][_0x9087('0x56')]({'where':{'id':_0x5900d4[_0x9087('0x47')]['id']}})[_0x9087('0x27')](handleEntityNotFound(_0x20bacf,null))['then'](function(_0x210acb){if(_0x210acb){_0x2eb7fe=_0x210acb;_0x1ce2b1[_0x9087('0x34')]=_[_0x9087('0x48')](db[_0x9087('0x63')][_0x9087('0x49')]);_0x1ce2b1[_0x9087('0x33')]=_[_0x9087('0x48')](_0x5900d4['query']);_0x1ce2b1[_0x9087('0x3d')]=_[_0x9087('0x36')](_0x1ce2b1[_0x9087('0x34')],_0x1ce2b1[_0x9087('0x33')]);_0x210dcc[_0x9087('0x35')]=_[_0x9087('0x36')](_0x1ce2b1[_0x9087('0x34')],qs[_0x9087('0x37')](_0x5900d4[_0x9087('0x33')][_0x9087('0x37')]));_0x210dcc[_0x9087('0x35')]=_0x210dcc[_0x9087('0x35')][_0x9087('0x38')]?_0x210dcc['attributes']:_0x1ce2b1[_0x9087('0x34')];_0x210dcc[_0x9087('0x3a')]=qs['sort'](_0x5900d4[_0x9087('0x33')][_0x9087('0x3b')]);_0x210dcc[_0x9087('0x3c')]=qs[_0x9087('0x3d')](_[_0x9087('0x3e')](_0x5900d4['query'],_0x1ce2b1[_0x9087('0x3d')]));if(_0x5900d4[_0x9087('0x33')][_0x9087('0x3f')]){_0x210dcc[_0x9087('0x3c')]=_['merge'](_0x210dcc[_0x9087('0x3c')],{'$or':_[_0x9087('0x32')](_0x210dcc[_0x9087('0x35')],function(_0x169c45){var _0x245890={};_0x245890[_0x169c45]={'$like':'%'+_0x5900d4[_0x9087('0x33')][_0x9087('0x3f')]+'%'};return _0x245890;})});}_0x210dcc=_['merge']({},_0x210dcc,_0x5900d4[_0x9087('0x41')]);return _0x2eb7fe[_0x9087('0x62')](_0x210dcc);}})['then'](function(_0x297225){if(_0x297225){_0x1bf1f1=_0x297225['length'];if(!_0x5900d4['query']['hasOwnProperty'](_0x9087('0x58'))){_0x210dcc[_0x9087('0x21')]=qs[_0x9087('0x21')](_0x5900d4[_0x9087('0x33')]['limit']);_0x210dcc['offset']=qs[_0x9087('0x20')](_0x5900d4['query'][_0x9087('0x20')]);}return _0x2eb7fe['getTeams'](_0x210dcc);}})['then'](function(_0x5cb934){if(_0x5cb934){return _0x5cb934?{'count':_0x1bf1f1,'rows':_0x5cb934}:null;}})[_0x9087('0x27')](respondWithResult(_0x20bacf,null))['catch'](handleError(_0x20bacf,null));};exports[_0x9087('0x64')]=function(_0x4c55f8,_0x1f8125,_0x2b47df){var _0xa749ad=_0x4c55f8['body'][_0x9087('0x65')];return db[_0x9087('0x63')][_0x9087('0x44')]({'where':{'id':_0xa749ad},'attributes':['id'],'include':[{'model':db[_0x9087('0x5a')],'as':_0x9087('0x66'),'attributes':['id',_0x9087('0x2e'),_0x9087('0x67'),_0x9087('0x68'),_0x9087('0x69')],'raw':!![]}]})[_0x9087('0x27')](function(_0x241c83){if(_0x241c83){var _0x21a1b4=_[_0x9087('0x6a')](_0x241c83,function(_0x564b05){var _0x33e0b1=_0x564b05[_0x9087('0x29')]({'plain':!![]});return _0x33e0b1[_0x9087('0x66')];});return db[_0x9087('0x30')][_0x9087('0x4b')]({'where':{'id':_0x4c55f8[_0x9087('0x47')]['id']}})[_0x9087('0x27')](function(_0x3e8933){return db[_0x9087('0x6b')][_0x9087('0x6c')](function(_0x2dc1d1){return _0x3e8933[_0x9087('0x64')](_0xa749ad,{'transaction':_0x2dc1d1})[_0x9087('0x27')](function(){return BPromise[_0x9087('0x6d')](_0x21a1b4,function(_0x326655){return db[_0x9087('0x57')][_0x9087('0x6e')]({'where':{'UserId':_0x326655['id'],'FaxQueueId':_0x4c55f8[_0x9087('0x47')]['id']},'transaction':_0x2dc1d1});});})[_0x9087('0x27')](function(){_0x21a1b4[_0x9087('0x6f')](function(_0x1fd554){socket[_0x9087('0x70')](_0x9087('0x71'),{'UserId':_0x1fd554['id'],'FaxQueueId':_0x3e8933['id']});});});});});}})['then'](respondWithStatusCode(_0x1f8125,null))[_0x9087('0x53')](handleError(_0x1f8125,null));};exports[_0x9087('0x72')]=function(_0x284281,_0x3676d6,_0x27b948){return db['Team'][_0x9087('0x44')]({'where':{'id':_0x284281[_0x9087('0x33')]['ids']},'attributes':['id'],'include':[{'model':db[_0x9087('0x5a')],'as':_0x9087('0x66'),'attributes':['id'],'raw':!![]}]})[_0x9087('0x27')](handleEntityNotFound(_0x3676d6,null))[_0x9087('0x27')](function(_0x1d9817){var _0x3bfbdc=_[_0x9087('0x32')](_0x1d9817,'id');var _0x5b288f=[];var _0x1a6788=[];var _0x1e6af0=squel['select']();_0x1e6af0['field'](_0x9087('0x73'))[_0x9087('0x74')](_0x9087('0x75'),'tq')[_0x9087('0x76')](_0x9087('0x77'),'ut',_0x9087('0x78'))['where'](_0x9087('0x79'),_0x284281[_0x9087('0x47')]['id']);for(var _0x506c97=0x0;_0x506c97<_0x1d9817[_0x9087('0x38')];_0x506c97+=0x1){let _0x42255a=_0x1d9817[_0x506c97];for(var _0x5d94d4=0x0;_0x5d94d4<_0x42255a[_0x9087('0x66')][_0x9087('0x38')];_0x5d94d4+=0x1){let _0x16bfe2=_0x42255a[_0x9087('0x66')][_0x5d94d4];var _0xd7a7ac=_0x1e6af0[_0x9087('0x7a')]();_0xd7a7ac[_0x9087('0x3c')](_0x9087('0x7b'),_0x16bfe2['id']);_0x1a6788[_0x9087('0x7c')](db[_0x9087('0x6b')][_0x9087('0x33')](_0xd7a7ac[_0x9087('0x7d')](),{'type':db[_0x9087('0x6b')]['QueryTypes'][_0x9087('0x7e')]})['then'](function(_0x2b42dc){if(_0x2b42dc[_0x9087('0x38')]===0x1){return _0x16bfe2['id'];}else{var _0x4e8076=_['every'](_[_0x9087('0x32')](_0x2b42dc,_0x9087('0x7f')),function(_0x278ba3){return _[_0x9087('0x80')](_0x3bfbdc,_0x278ba3);});if(_0x4e8076){return _0x16bfe2['id'];}}}));}}return BPromise['all'](_0x1a6788)[_0x9087('0x27')](function(_0x562ee2){_0x5b288f=_(_0x5b288f)[_0x9087('0x81')](_0x562ee2)[_0x9087('0x82')]()[_0x9087('0x83')]();return db['FaxQueue']['find']({'where':{'id':_0x284281[_0x9087('0x47')]['id']}})[_0x9087('0x27')](function(_0x375459){return db[_0x9087('0x6b')][_0x9087('0x6c')](function(_0x3d6e7f){return _0x375459[_0x9087('0x72')](_0x284281['query'][_0x9087('0x65')],{'transaction':_0x3d6e7f})['then'](function(){if(!_['isEmpty'](_0x5b288f)){return _0x375459[_0x9087('0x84')](_0x5b288f,{'transaction':_0x3d6e7f});}})[_0x9087('0x27')](function(){_0x5b288f[_0x9087('0x6f')](function(_0x1b7c67){socket[_0x9087('0x70')](_0x9087('0x85'),{'UserId':_0x1b7c67,'FaxQueueId':_0x375459['id']});});});});});});})[_0x9087('0x27')](respondWithStatusCode(_0x3676d6,null))[_0x9087('0x53')](handleError(_0x3676d6,null));};exports[_0x9087('0x86')]=function(_0x5a0e8d,_0x24849f,_0x3a9b21){return db[_0x9087('0x30')]['find']({'where':{'id':_0x5a0e8d['params']['id']}})['then'](handleEntityNotFound(_0x24849f,null))[_0x9087('0x27')](function(_0x3d3ba2){if(_0x3d3ba2){return _0x3d3ba2['addAgents'](_0x5a0e8d[_0x9087('0x4d')][_0x9087('0x65')],_[_0x9087('0x87')](_0x5a0e8d['body'],[_0x9087('0x65'),'id'])||{})[_0x9087('0x88')](function(_0x47fa53){for(var _0x3242ac=0x0;_0x3242ac<_0x5a0e8d['body'][_0x9087('0x65')]['length'];_0x3242ac+=0x1){socket[_0x9087('0x70')](_0x9087('0x71'),{'UserId':_0x5a0e8d[_0x9087('0x4d')]['ids'][_0x3242ac],'FaxQueueId':_0x5a0e8d[_0x9087('0x47')]['id']});}return _0x47fa53;});}})[_0x9087('0x27')](respondWithResult(_0x24849f,null))[_0x9087('0x53')](handleError(_0x24849f,null));};exports[_0x9087('0x84')]=function(_0xe9af7f,_0x7e18ae,_0x188f0d){return db[_0x9087('0x30')]['find']({'where':{'id':_0xe9af7f[_0x9087('0x47')]['id']}})[_0x9087('0x27')](handleEntityNotFound(_0x7e18ae,null))[_0x9087('0x27')](function(_0x107543){if(_0x107543){return _0x107543[_0x9087('0x84')](_0xe9af7f['query'][_0x9087('0x65')])[_0x9087('0x27')](function(){if(_['isArray'](_0xe9af7f['query'][_0x9087('0x65')])){for(var _0x50df19=0x0;_0x50df19<_0xe9af7f[_0x9087('0x33')]['ids']['length'];_0x50df19+=0x1){socket[_0x9087('0x70')](_0x9087('0x85'),{'UserId':Number(_0xe9af7f['query'][_0x9087('0x65')][_0x50df19]),'FaxQueueId':Number(_0xe9af7f[_0x9087('0x47')]['id'])});}}else{socket['emit'](_0x9087('0x85'),{'UserId':Number(_0xe9af7f['query'][_0x9087('0x65')]),'FaxQueueId':Number(_0xe9af7f['params']['id'])});}});}})[_0x9087('0x27')](respondWithStatusCode(_0x7e18ae,null))['catch'](handleError(_0x7e18ae,null));};exports[_0x9087('0x89')]=function(_0x4ac34d,_0x2e27d1,_0x4072bb){var _0x26171a={};var _0x584c01={};var _0x221619;var _0x5dfa4c;return db[_0x9087('0x30')]['findOne']({'where':{'id':_0x4ac34d[_0x9087('0x47')]['id']}})[_0x9087('0x27')](handleEntityNotFound(_0x2e27d1,null))[_0x9087('0x27')](function(_0x5c4ca9){if(_0x5c4ca9){_0x221619=_0x5c4ca9;_0x584c01[_0x9087('0x34')]=_['keys'](db['User'][_0x9087('0x49')]);_0x584c01[_0x9087('0x33')]=_[_0x9087('0x48')](_0x4ac34d[_0x9087('0x33')]);_0x584c01['filters']=_[_0x9087('0x36')](_0x584c01['model'],_0x584c01[_0x9087('0x33')]);_0x26171a['attributes']=_[_0x9087('0x36')](_0x584c01[_0x9087('0x34')],qs[_0x9087('0x37')](_0x4ac34d[_0x9087('0x33')][_0x9087('0x37')]));_0x26171a[_0x9087('0x35')]=_0x26171a[_0x9087('0x35')][_0x9087('0x38')]?_0x26171a[_0x9087('0x35')]:_0x584c01[_0x9087('0x34')];_0x26171a['order']=qs[_0x9087('0x3b')](_0x4ac34d[_0x9087('0x33')][_0x9087('0x3b')]);_0x26171a[_0x9087('0x3c')]=qs[_0x9087('0x3d')](_[_0x9087('0x3e')](_0x4ac34d[_0x9087('0x33')],_0x584c01[_0x9087('0x3d')]));if(_0x4ac34d[_0x9087('0x33')]['filter']){_0x26171a[_0x9087('0x3c')]=_[_0x9087('0x4a')](_0x26171a[_0x9087('0x3c')],{'$or':_['map'](_0x26171a[_0x9087('0x35')],function(_0x372006){var _0x5a3373={};_0x5a3373[_0x372006]={'$like':'%'+_0x4ac34d['query'][_0x9087('0x3f')]+'%'};return _0x5a3373;})});}_0x26171a=_[_0x9087('0x4a')]({},_0x26171a,_0x4ac34d[_0x9087('0x41')]);return _0x221619['getAgents'](_0x26171a);}})[_0x9087('0x27')](function(_0x232249){if(_0x232249){_0x5dfa4c=_0x232249[_0x9087('0x38')];if(!_0x4ac34d['query'][_0x9087('0x39')](_0x9087('0x58'))){_0x26171a[_0x9087('0x21')]=qs[_0x9087('0x21')](_0x4ac34d['query'][_0x9087('0x21')]);_0x26171a[_0x9087('0x20')]=qs[_0x9087('0x20')](_0x4ac34d[_0x9087('0x33')][_0x9087('0x20')]);}return _0x221619[_0x9087('0x89')](_0x26171a);}})[_0x9087('0x27')](function(_0x1d9e2e){if(_0x1d9e2e){return _0x1d9e2e?{'count':_0x5dfa4c,'rows':_0x1d9e2e}:null;}})[_0x9087('0x27')](respondWithResult(_0x2e27d1,null))[_0x9087('0x53')](handleError(_0x2e27d1,null));};
\ No newline at end of file
+var _0x31f0=['merge','options','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','error','describe','findOne','UserFaxQueue','nolimit','order','sort','pick','FaxQueueId','filter','findAndCountAll','UserId','agent','faxPause','updatedAt','createdAt','format','%s/%s','SIP','getTeams','Team','addTeams','ids','User','Agents','online','interface','flatMap','sequelize','each','findOrCreate','forEach','userFaxQueue:save','removeTeams','select','field','tq.TeamId','from','team_has_fax_queues','join','user_has_teams','FaxQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','QueryTypes','every','TeamId','includes','union','transaction','removeAgents','userFaxQueue:remove','addAgents','omit','emit','getAgents','bluebird','lodash','ioredis','../../components/parsers/qs','../../config/logger','api','../../mysqldb','redis','socket.io-emitter','./faxQueue.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','then','destroy','get','FaxQueues','UserProfileResource','name','send','index','map','rawAttributes','type','key','getOptions','where','FaxQueue','include','query','findAll','rows','catch','show','params','model','keys','filters','intersection','attributes','fields','length','includeAll'];(function(_0x147656,_0x205a15){var _0x37e1e9=function(_0xea78b){while(--_0xea78b){_0x147656['push'](_0x147656['shift']());}};_0x37e1e9(++_0x205a15);}(_0x31f0,0xb7));var _0x031f=function(_0x33f6db,_0x277e76){_0x33f6db=_0x33f6db-0x0;var _0x3bc6d0=_0x31f0[_0x33f6db];return _0x3bc6d0;};'use strict';var BPromise=require(_0x031f('0x0'));var util=require('util');var _=require(_0x031f('0x1'));var squel=require('squel');var Redis=require(_0x031f('0x2'));var qs=require(_0x031f('0x3'));var logger=require(_0x031f('0x4'))(_0x031f('0x5'));var config=require('../../config/environment');var db=require(_0x031f('0x6'))['db'];config[_0x031f('0x7')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x031f('0x8'))(new Redis(config['redis']));require(_0x031f('0x9'))[_0x031f('0xa')](socket);function respondWithStatusCode(_0x2569b6,_0x3e41ed){_0x3e41ed=_0x3e41ed||0xcc;return function(_0x4d47c5){if(_0x4d47c5){return _0x2569b6[_0x031f('0xb')](_0x3e41ed);}return _0x2569b6[_0x031f('0xc')](_0x3e41ed)[_0x031f('0xd')]();};}function respondWithResult(_0x439940,_0x3dd729){_0x3dd729=_0x3dd729||0xc8;return function(_0x3b0a17){if(_0x3b0a17){return _0x439940[_0x031f('0xc')](_0x3dd729)[_0x031f('0xe')](_0x3b0a17);}};}function respondWithFilteredResult(_0x4df318,_0x5c3657){return function(_0x353744){if(_0x353744){var _0x28da6e=typeof _0x5c3657[_0x031f('0xf')]===_0x031f('0x10')&&typeof _0x5c3657[_0x031f('0x11')]===_0x031f('0x10');var _0x5d0457=_0x353744[_0x031f('0x12')];var _0x23b40c=_0x28da6e?0x0:_0x5c3657[_0x031f('0xf')];var _0x2e3dfe=_0x28da6e?_0x353744[_0x031f('0x12')]:_0x5c3657['offset']+_0x5c3657['limit'];var _0x1f08db;if(_0x2e3dfe>=_0x5d0457){_0x2e3dfe=_0x5d0457;_0x1f08db=0xc8;}else{_0x1f08db=0xce;}_0x4df318[_0x031f('0xc')](_0x1f08db);return _0x4df318[_0x031f('0x13')](_0x031f('0x14'),_0x23b40c+'-'+_0x2e3dfe+'/'+_0x5d0457)['json'](_0x353744);}return null;};}function saveUpdates(_0x1dc4a7){return function(_0x1d8ac2){if(_0x1d8ac2){return _0x1d8ac2['update'](_0x1dc4a7)[_0x031f('0x15')](function(_0x535e70){return _0x535e70;});}return null;};}function removeEntity(_0x421f75){return function(_0x5f2199){if(_0x5f2199){return _0x5f2199[_0x031f('0x16')]()[_0x031f('0x15')](function(){var _0x1ceddc=_0x5f2199[_0x031f('0x17')]({'plain':!![]});var _0x1b76d6=_0x031f('0x18');return db[_0x031f('0x19')][_0x031f('0x16')]({'where':{'type':_0x1b76d6,'resourceId':_0x1ceddc['id']}})[_0x031f('0x15')](function(){return _0x5f2199;});})['then'](function(){_0x421f75[_0x031f('0xc')](0xcc)[_0x031f('0xd')]();});}};}function handleEntityNotFound(_0x451328){return function(_0x4d6706){if(!_0x4d6706){_0x451328['sendStatus'](0x194);}return _0x4d6706;};}function handleError(_0xa11a2b,_0x4d0f92){_0x4d0f92=_0x4d0f92||0x1f4;return function(_0x3472a2){logger['error'](_0x3472a2['stack']);if(_0x3472a2['name']){delete _0x3472a2[_0x031f('0x1a')];}_0xa11a2b[_0x031f('0xc')](_0x4d0f92)[_0x031f('0x1b')](_0x3472a2);};}exports[_0x031f('0x1c')]=function(_0x494568,_0x374b65){var _0x5a64c0={};var _0x40cb1c={'count':0x0,'rows':[]};var _0x1f5a14=_[_0x031f('0x1d')](db['FaxQueue'][_0x031f('0x1e')],function(_0x3b2a51){return{'name':_0x3b2a51['fieldName'],'type':_0x3b2a51[_0x031f('0x1f')][_0x031f('0x20')]};});_0x5a64c0=qs[_0x031f('0x21')](_0x1f5a14,_0x494568);var _0x5395ea={'where':_0x5a64c0[_0x031f('0x22')]};return db[_0x031f('0x23')][_0x031f('0x12')](_0x5395ea)[_0x031f('0x15')](function(_0xfaa36){_0x40cb1c[_0x031f('0x12')]=_0xfaa36;_0x5a64c0['include']=qs[_0x031f('0x24')](_0x494568[_0x031f('0x25')]);return db[_0x031f('0x23')][_0x031f('0x26')](_0x5a64c0);})[_0x031f('0x15')](function(_0x2d24f0){_0x40cb1c[_0x031f('0x27')]=_0x2d24f0;return _0x40cb1c;})[_0x031f('0x15')](respondWithFilteredResult(_0x374b65,_0x5a64c0))[_0x031f('0x28')](handleError(_0x374b65,null));};exports[_0x031f('0x29')]=function(_0x2cf3a8,_0x5ec564){var _0xced6ff={'raw':!![],'where':{'id':_0x2cf3a8[_0x031f('0x2a')]['id']}},_0xe5f11c={};_0xe5f11c[_0x031f('0x2b')]=_[_0x031f('0x2c')](db[_0x031f('0x23')][_0x031f('0x1e')]);_0xe5f11c[_0x031f('0x25')]=_[_0x031f('0x2c')](_0x2cf3a8[_0x031f('0x25')]);_0xe5f11c[_0x031f('0x2d')]=_[_0x031f('0x2e')](_0xe5f11c[_0x031f('0x2b')],_0xe5f11c['query']);_0xced6ff[_0x031f('0x2f')]=_[_0x031f('0x2e')](_0xe5f11c['model'],qs[_0x031f('0x30')](_0x2cf3a8[_0x031f('0x25')]['fields']));_0xced6ff[_0x031f('0x2f')]=_0xced6ff[_0x031f('0x2f')][_0x031f('0x31')]?_0xced6ff[_0x031f('0x2f')]:_0xe5f11c['model'];if(_0x2cf3a8['query'][_0x031f('0x32')]){_0xced6ff['include']=[{'all':!![]}];}_0xced6ff=_[_0x031f('0x33')]({},_0xced6ff,_0x2cf3a8[_0x031f('0x34')]);return db[_0x031f('0x23')]['find'](_0xced6ff)['then'](handleEntityNotFound(_0x5ec564,null))[_0x031f('0x15')](respondWithResult(_0x5ec564,null))['catch'](handleError(_0x5ec564,null));};exports['create']=function(_0x2d489a,_0x45e3a4){return db[_0x031f('0x23')][_0x031f('0x35')](_0x2d489a[_0x031f('0x36')],{})[_0x031f('0x15')](function(_0x1ffd03){var _0x55c85f=_0x2d489a[_0x031f('0x37')][_0x031f('0x17')]({'plain':!![]});if(!_0x55c85f)throw new Error(_0x031f('0x38'));if(_0x55c85f[_0x031f('0x39')]==='user'){var _0x2be5d1=_0x1ffd03[_0x031f('0x17')]({'plain':!![]});var _0x2dba8b='FaxQueues';return db[_0x031f('0x3a')][_0x031f('0x3b')]({'where':{'name':_0x2dba8b,'userProfileId':_0x55c85f['userProfileId']},'raw':!![]})[_0x031f('0x15')](function(_0x268dc7){if(_0x268dc7&&_0x268dc7['autoAssociation']===0x0){return db['UserProfileResource'][_0x031f('0x35')]({'name':_0x2be5d1[_0x031f('0x1a')],'resourceId':_0x2be5d1['id'],'type':_0x268dc7[_0x031f('0x1a')],'sectionId':_0x268dc7['id']},{})[_0x031f('0x15')](function(){return _0x1ffd03;});}else{return _0x1ffd03;}})[_0x031f('0x28')](function(_0xf0fb95){logger[_0x031f('0x3c')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xf0fb95);throw _0xf0fb95;});}return _0x1ffd03;})[_0x031f('0x15')](respondWithResult(_0x45e3a4,0xc9))[_0x031f('0x28')](handleError(_0x45e3a4,null));};exports['update']=function(_0x12279a,_0x505e93){if(_0x12279a[_0x031f('0x36')]['id']){delete _0x12279a[_0x031f('0x36')]['id'];}return db['FaxQueue'][_0x031f('0x3b')]({'where':{'id':_0x12279a[_0x031f('0x2a')]['id']}})[_0x031f('0x15')](handleEntityNotFound(_0x505e93,null))['then'](saveUpdates(_0x12279a[_0x031f('0x36')],null))[_0x031f('0x15')](respondWithResult(_0x505e93,null))[_0x031f('0x28')](handleError(_0x505e93,null));};exports[_0x031f('0x16')]=function(_0x177306,_0x193b8f){return db[_0x031f('0x23')][_0x031f('0x3b')]({'where':{'id':_0x177306[_0x031f('0x2a')]['id']}})['then'](handleEntityNotFound(_0x193b8f,null))[_0x031f('0x15')](removeEntity(_0x193b8f,null))[_0x031f('0x28')](handleError(_0x193b8f,null));};exports[_0x031f('0x3d')]=function(_0x3205ce,_0xcf2072){return db[_0x031f('0x23')][_0x031f('0x3d')]()[_0x031f('0x15')](respondWithResult(_0xcf2072,null))[_0x031f('0x28')](handleError(_0xcf2072,null));};exports['getMembers']=function(_0x38539a,_0x5ec593){var _0x512937={'raw':!![],'where':{}},_0x434849={},_0x2359d1;return db[_0x031f('0x23')][_0x031f('0x3e')]({'where':{'id':_0x38539a[_0x031f('0x2a')]['id']}})['then'](handleEntityNotFound(_0x5ec593,null))[_0x031f('0x15')](function(_0x365f8c){if(_0x365f8c){_0x2359d1=_0x365f8c[_0x031f('0x17')]({'plain':!![]});_0x434849['model']=_[_0x031f('0x2c')](db[_0x031f('0x3f')][_0x031f('0x1e')]);_0x434849[_0x031f('0x25')]=_[_0x031f('0x2c')](_0x38539a[_0x031f('0x25')]);_0x434849['filters']=_['intersection'](_0x434849[_0x031f('0x2b')],_0x434849['query']);_0x512937[_0x031f('0x2f')]=_[_0x031f('0x2e')](_0x434849['model'],qs[_0x031f('0x30')](_0x38539a['query']['fields']));_0x512937[_0x031f('0x2f')]=_0x512937['attributes'][_0x031f('0x31')]?_0x512937['attributes']:_0x434849[_0x031f('0x2b')];if(!_0x38539a[_0x031f('0x25')]['hasOwnProperty'](_0x031f('0x40'))){_0x512937[_0x031f('0x11')]=qs['limit'](_0x38539a[_0x031f('0x25')]['limit']);_0x512937[_0x031f('0xf')]=qs['offset'](_0x38539a[_0x031f('0x25')][_0x031f('0xf')]);}_0x512937[_0x031f('0x41')]=qs[_0x031f('0x42')](_0x38539a[_0x031f('0x25')]['sort']);_0x512937[_0x031f('0x22')]=qs['filters'](_[_0x031f('0x43')](_0x38539a[_0x031f('0x25')],_0x434849['filters']));_0x512937[_0x031f('0x22')][_0x031f('0x44')]=_0x365f8c['id'];if(_0x38539a['query'][_0x031f('0x45')]){_0x512937[_0x031f('0x22')]=_[_0x031f('0x33')](_0x512937['where'],{'$or':_[_0x031f('0x1d')](_0x512937['attributes'],function(_0x254604){var _0x5a4aa4={};_0x5a4aa4[_0x254604]={'$like':'%'+_0x38539a[_0x031f('0x25')]['filter']+'%'};return _0x5a4aa4;})});}_0x512937=_[_0x031f('0x33')]({},_0x512937,_0x38539a[_0x031f('0x34')]);return db['UserFaxQueue']['findAll'](_0x512937);}})[_0x031f('0x15')](function(_0x10fa4c){if(_0x10fa4c){return db['User'][_0x031f('0x46')]({'where':{'id':_[_0x031f('0x1d')](_0x10fa4c,_0x031f('0x47')),'role':_0x031f('0x48')},'attributes':['id',_0x031f('0x1a'),_0x031f('0x49'),_0x031f('0x4a'),_0x031f('0x4b')]});}})['then'](function(_0xe452c2){if(_0xe452c2){return{'count':_0xe452c2[_0x031f('0x12')],'rows':_[_0x031f('0x1d')](_0xe452c2['rows'],function(_0x3937b7){return{'membername':_0x3937b7[_0x031f('0x1a')],'UserId':_0x3937b7['id'],'queue_name':_0x2359d1['name'],'FaxQueueId':_0x2359d1['id'],'interface':util[_0x031f('0x4c')](_0x031f('0x4d'),_0x031f('0x4e'),_0x3937b7[_0x031f('0x1a')]),'penalty':0x0,'paused':_0x3937b7['faxPause'],'createdAt':_0x3937b7['createdAt'],'updatedAt':_0x3937b7['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x5ec593,_0x512937))[_0x031f('0x28')](handleError(_0x5ec593,null));};exports[_0x031f('0x4f')]=function(_0x4a7fbb,_0x10531d){var _0x28f026={};var _0x508c4c={};var _0x110495;var _0x26ecb0;return db[_0x031f('0x23')][_0x031f('0x3e')]({'where':{'id':_0x4a7fbb[_0x031f('0x2a')]['id']}})[_0x031f('0x15')](handleEntityNotFound(_0x10531d,null))[_0x031f('0x15')](function(_0x4527e5){if(_0x4527e5){_0x110495=_0x4527e5;_0x508c4c[_0x031f('0x2b')]=_['keys'](db[_0x031f('0x50')]['rawAttributes']);_0x508c4c[_0x031f('0x25')]=_[_0x031f('0x2c')](_0x4a7fbb[_0x031f('0x25')]);_0x508c4c['filters']=_['intersection'](_0x508c4c[_0x031f('0x2b')],_0x508c4c[_0x031f('0x25')]);_0x28f026[_0x031f('0x2f')]=_[_0x031f('0x2e')](_0x508c4c['model'],qs[_0x031f('0x30')](_0x4a7fbb['query']['fields']));_0x28f026[_0x031f('0x2f')]=_0x28f026['attributes']['length']?_0x28f026[_0x031f('0x2f')]:_0x508c4c[_0x031f('0x2b')];_0x28f026[_0x031f('0x41')]=qs[_0x031f('0x42')](_0x4a7fbb[_0x031f('0x25')]['sort']);_0x28f026['where']=qs[_0x031f('0x2d')](_['pick'](_0x4a7fbb[_0x031f('0x25')],_0x508c4c[_0x031f('0x2d')]));if(_0x4a7fbb['query'][_0x031f('0x45')]){_0x28f026[_0x031f('0x22')]=_[_0x031f('0x33')](_0x28f026[_0x031f('0x22')],{'$or':_[_0x031f('0x1d')](_0x28f026[_0x031f('0x2f')],function(_0x5bea08){var _0x58f012={};_0x58f012[_0x5bea08]={'$like':'%'+_0x4a7fbb[_0x031f('0x25')][_0x031f('0x45')]+'%'};return _0x58f012;})});}_0x28f026=_[_0x031f('0x33')]({},_0x28f026,_0x4a7fbb[_0x031f('0x34')]);return _0x110495[_0x031f('0x4f')](_0x28f026);}})[_0x031f('0x15')](function(_0x3cfb21){if(_0x3cfb21){_0x26ecb0=_0x3cfb21['length'];if(!_0x4a7fbb['query']['hasOwnProperty']('nolimit')){_0x28f026[_0x031f('0x11')]=qs[_0x031f('0x11')](_0x4a7fbb[_0x031f('0x25')]['limit']);_0x28f026[_0x031f('0xf')]=qs[_0x031f('0xf')](_0x4a7fbb['query'][_0x031f('0xf')]);}return _0x110495[_0x031f('0x4f')](_0x28f026);}})[_0x031f('0x15')](function(_0x140ccd){if(_0x140ccd){return _0x140ccd?{'count':_0x26ecb0,'rows':_0x140ccd}:null;}})[_0x031f('0x15')](respondWithResult(_0x10531d,null))[_0x031f('0x28')](handleError(_0x10531d,null));};exports[_0x031f('0x51')]=function(_0x5ecbd6,_0x571d15){var _0x8a448f=_0x5ecbd6['body'][_0x031f('0x52')];return db['Team'][_0x031f('0x26')]({'where':{'id':_0x8a448f},'attributes':['id'],'include':[{'model':db[_0x031f('0x53')],'as':_0x031f('0x54'),'attributes':['id','name',_0x031f('0x55'),'voicePause',_0x031f('0x56')],'raw':!![]}]})[_0x031f('0x15')](function(_0x3efa82){if(_0x3efa82){var _0x4e7251=_[_0x031f('0x57')](_0x3efa82,function(_0x398e7c){var _0x3c4b09=_0x398e7c[_0x031f('0x17')]({'plain':!![]});return _0x3c4b09[_0x031f('0x54')];});return db['FaxQueue']['find']({'where':{'id':_0x5ecbd6[_0x031f('0x2a')]['id']}})[_0x031f('0x15')](function(_0x4bc4c7){return db[_0x031f('0x58')]['transaction'](function(_0x2dfff2){return _0x4bc4c7[_0x031f('0x51')](_0x8a448f,{'transaction':_0x2dfff2})[_0x031f('0x15')](function(){return BPromise[_0x031f('0x59')](_0x4e7251,function(_0x52bb92){return db[_0x031f('0x3f')][_0x031f('0x5a')]({'where':{'UserId':_0x52bb92['id'],'FaxQueueId':_0x5ecbd6[_0x031f('0x2a')]['id']},'transaction':_0x2dfff2});});})['then'](function(){_0x4e7251[_0x031f('0x5b')](function(_0xfda893){socket['emit'](_0x031f('0x5c'),{'UserId':_0xfda893['id'],'FaxQueueId':_0x4bc4c7['id']});});});});});}})[_0x031f('0x15')](respondWithStatusCode(_0x571d15,null))[_0x031f('0x28')](handleError(_0x571d15,null));};exports[_0x031f('0x5d')]=function(_0x104025,_0x38a8a4){return db[_0x031f('0x50')]['findAll']({'where':{'id':_0x104025[_0x031f('0x25')][_0x031f('0x52')]},'attributes':['id'],'include':[{'model':db[_0x031f('0x53')],'as':'Agents','attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x38a8a4,null))[_0x031f('0x15')](function(_0x5bd344){var _0x54f02d=_[_0x031f('0x1d')](_0x5bd344,'id');var _0x184bbd=[];var _0x1c8055=[];var _0x1d6aca=squel[_0x031f('0x5e')]();_0x1d6aca[_0x031f('0x5f')](_0x031f('0x60'))[_0x031f('0x61')](_0x031f('0x62'),'tq')[_0x031f('0x63')](_0x031f('0x64'),'ut','ut.TeamId\x20=\x20tq.TeamId')[_0x031f('0x22')](_0x031f('0x65'),_0x104025[_0x031f('0x2a')]['id']);for(var _0x8290bf=0x0;_0x8290bf<_0x5bd344['length'];_0x8290bf+=0x1){let _0x6970f5=_0x5bd344[_0x8290bf];for(var _0x5329c2=0x0;_0x5329c2<_0x6970f5['Agents'][_0x031f('0x31')];_0x5329c2+=0x1){let _0x2f4d09=_0x6970f5['Agents'][_0x5329c2];var _0x510bb6=_0x1d6aca[_0x031f('0x66')]();_0x510bb6[_0x031f('0x22')](_0x031f('0x67'),_0x2f4d09['id']);_0x1c8055[_0x031f('0x68')](db[_0x031f('0x58')][_0x031f('0x25')](_0x510bb6['toString'](),{'type':db[_0x031f('0x58')][_0x031f('0x69')]['SELECT']})[_0x031f('0x15')](function(_0x2f2e96){if(_0x2f2e96[_0x031f('0x31')]===0x1){return _0x2f4d09['id'];}else{var _0x14fc7e=_[_0x031f('0x6a')](_[_0x031f('0x1d')](_0x2f2e96,_0x031f('0x6b')),function(_0x4e9157){return _[_0x031f('0x6c')](_0x54f02d,_0x4e9157);});if(_0x14fc7e){return _0x2f4d09['id'];}}}));}}return BPromise['all'](_0x1c8055)[_0x031f('0x15')](function(_0x1d5d61){_0x184bbd=_(_0x184bbd)[_0x031f('0x6d')](_0x1d5d61)['compact']()['value']();return db['FaxQueue'][_0x031f('0x3b')]({'where':{'id':_0x104025[_0x031f('0x2a')]['id']}})[_0x031f('0x15')](function(_0x2985fe){return db[_0x031f('0x58')][_0x031f('0x6e')](function(_0x232aa0){return _0x2985fe['removeTeams'](_0x104025['query'][_0x031f('0x52')],{'transaction':_0x232aa0})[_0x031f('0x15')](function(){if(!_['isEmpty'](_0x184bbd)){return _0x2985fe[_0x031f('0x6f')](_0x184bbd,{'transaction':_0x232aa0});}})['then'](function(){_0x184bbd[_0x031f('0x5b')](function(_0x20d85a){socket['emit'](_0x031f('0x70'),{'UserId':_0x20d85a,'FaxQueueId':_0x2985fe['id']});});});});});});})[_0x031f('0x15')](respondWithStatusCode(_0x38a8a4,null))['catch'](handleError(_0x38a8a4,null));};exports[_0x031f('0x71')]=function(_0x3c7dee,_0x1b588e){return db['FaxQueue'][_0x031f('0x3b')]({'where':{'id':_0x3c7dee[_0x031f('0x2a')]['id']}})[_0x031f('0x15')](handleEntityNotFound(_0x1b588e,null))[_0x031f('0x15')](function(_0x11165b){if(_0x11165b){return _0x11165b[_0x031f('0x71')](_0x3c7dee['body'][_0x031f('0x52')],_[_0x031f('0x72')](_0x3c7dee[_0x031f('0x36')],[_0x031f('0x52'),'id'])||{})['spread'](function(_0x33bf51){for(var _0x467a76=0x0;_0x467a76<_0x3c7dee['body'][_0x031f('0x52')][_0x031f('0x31')];_0x467a76+=0x1){socket[_0x031f('0x73')](_0x031f('0x5c'),{'UserId':Number(_0x3c7dee[_0x031f('0x36')][_0x031f('0x52')][_0x467a76]),'FaxQueueId':Number(_0x3c7dee[_0x031f('0x2a')]['id'])});}return _0x33bf51;});}})[_0x031f('0x15')](respondWithResult(_0x1b588e,null))[_0x031f('0x28')](handleError(_0x1b588e,null));};exports[_0x031f('0x6f')]=function(_0x16f7a0,_0x2b7347){return db[_0x031f('0x23')][_0x031f('0x3b')]({'where':{'id':_0x16f7a0[_0x031f('0x2a')]['id']}})['then'](handleEntityNotFound(_0x2b7347,null))[_0x031f('0x15')](function(_0x4368d6){if(_0x4368d6){return _0x4368d6[_0x031f('0x6f')](_0x16f7a0[_0x031f('0x25')][_0x031f('0x52')])[_0x031f('0x15')](function(){if(_['isArray'](_0x16f7a0['query']['ids'])){for(var _0x343acc=0x0;_0x343acc<_0x16f7a0[_0x031f('0x25')]['ids'][_0x031f('0x31')];_0x343acc+=0x1){socket[_0x031f('0x73')](_0x031f('0x70'),{'UserId':Number(_0x16f7a0[_0x031f('0x25')]['ids'][_0x343acc]),'FaxQueueId':Number(_0x16f7a0[_0x031f('0x2a')]['id'])});}}else{socket[_0x031f('0x73')](_0x031f('0x70'),{'UserId':Number(_0x16f7a0[_0x031f('0x25')][_0x031f('0x52')]),'FaxQueueId':Number(_0x16f7a0[_0x031f('0x2a')]['id'])});}});}})[_0x031f('0x15')](respondWithStatusCode(_0x2b7347,null))[_0x031f('0x28')](handleError(_0x2b7347,null));};exports[_0x031f('0x74')]=function(_0x3a798a,_0x3e3467){var _0x3eec5b={};var _0x4bd749={};var _0x2541fd;var _0x1f1f0e;return db['FaxQueue'][_0x031f('0x3e')]({'where':{'id':_0x3a798a[_0x031f('0x2a')]['id']}})['then'](handleEntityNotFound(_0x3e3467,null))[_0x031f('0x15')](function(_0x3bc88c){if(_0x3bc88c){_0x2541fd=_0x3bc88c;_0x4bd749[_0x031f('0x2b')]=_[_0x031f('0x2c')](db[_0x031f('0x53')][_0x031f('0x1e')]);_0x4bd749[_0x031f('0x25')]=_[_0x031f('0x2c')](_0x3a798a[_0x031f('0x25')]);_0x4bd749['filters']=_[_0x031f('0x2e')](_0x4bd749[_0x031f('0x2b')],_0x4bd749[_0x031f('0x25')]);_0x3eec5b['attributes']=_['intersection'](_0x4bd749[_0x031f('0x2b')],qs['fields'](_0x3a798a[_0x031f('0x25')][_0x031f('0x30')]));_0x3eec5b['attributes']=_0x3eec5b[_0x031f('0x2f')][_0x031f('0x31')]?_0x3eec5b[_0x031f('0x2f')]:_0x4bd749[_0x031f('0x2b')];_0x3eec5b[_0x031f('0x41')]=qs[_0x031f('0x42')](_0x3a798a[_0x031f('0x25')][_0x031f('0x42')]);_0x3eec5b[_0x031f('0x22')]=qs[_0x031f('0x2d')](_[_0x031f('0x43')](_0x3a798a[_0x031f('0x25')],_0x4bd749[_0x031f('0x2d')]));if(_0x3a798a['query']['filter']){_0x3eec5b[_0x031f('0x22')]=_['merge'](_0x3eec5b[_0x031f('0x22')],{'$or':_[_0x031f('0x1d')](_0x3eec5b[_0x031f('0x2f')],function(_0x513dfc){var _0x21f647={};_0x21f647[_0x513dfc]={'$like':'%'+_0x3a798a[_0x031f('0x25')]['filter']+'%'};return _0x21f647;})});}_0x3eec5b=_[_0x031f('0x33')]({},_0x3eec5b,_0x3a798a[_0x031f('0x34')]);return _0x2541fd[_0x031f('0x74')](_0x3eec5b);}})[_0x031f('0x15')](function(_0x348909){if(_0x348909){_0x1f1f0e=_0x348909[_0x031f('0x31')];if(!_0x3a798a[_0x031f('0x25')]['hasOwnProperty'](_0x031f('0x40'))){_0x3eec5b[_0x031f('0x11')]=qs[_0x031f('0x11')](_0x3a798a[_0x031f('0x25')]['limit']);_0x3eec5b['offset']=qs[_0x031f('0xf')](_0x3a798a['query']['offset']);}return _0x2541fd[_0x031f('0x74')](_0x3eec5b);}})['then'](function(_0x579ade){if(_0x579ade){return _0x579ade?{'count':_0x1f1f0e,'rows':_0x579ade}:null;}})[_0x031f('0x15')](respondWithResult(_0x3e3467,null))[_0x031f('0x28')](handleError(_0x3e3467,null));};
\ No newline at end of file