d65f7fa1e945174ddb8bd143beb6dba6c6818f58
[motion2.git] / server / api / openchannelQueue / openchannelQueue.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xf721=['name','keys','query','intersection','attributes','fields','length','nolimit','limit','order','sort','filters','pick','filter','where','options','OpenchannelQueue','includeAll','rows','catch','show','params','rawAttributes','include','merge','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','find','userProfileId','autoAssociation','error','describe','getMembers','hasOwnProperty','OpenchannelQueueId','UserOpenchannelQueue','User','findAndCountAll','UserId','agent','openchannelPause','updatedAt','createdAt','format','SIP','getTeams','addTeams','ids','Team','Agents','voicePause','interface','sequelize','each','findOrCreate','userOpenchannelQueue:save','removeTeams','findAll','select','tq.TeamId','from','team_has_openchannel_queues','ut.TeamId\x20=\x20tq.TeamId','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','includes','all','union','compact','isEmpty','removeAgents','forEach','emit','userOpenchannelQueue:remove','addAgents','spread','isArray','getAgents','eml-format','rimraf','zip-dir','mustache','util','sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','localhost','sendStatus','end','status','offset','undefined','count','set','json','apply','save','update','get','OpenchannelQueues','UserProfileResource','destroy','then','stack','index','map','fieldName','type','key','model'];(function(_0x451999,_0x1b3908){var _0x1b696e=function(_0x259ab1){while(--_0x259ab1){_0x451999['push'](_0x451999['shift']());}};_0x1b696e(++_0x1b3908);}(_0xf721,0x1ec));var _0x1f72=function(_0x25e109,_0x6ab24c){_0x25e109=_0x25e109-0x0;var _0xc0f7d6=_0xf721[_0x25e109];return _0xc0f7d6;};'use strict';var emlformat=require(_0x1f72('0x0'));var rimraf=require(_0x1f72('0x1'));var zipdir=require(_0x1f72('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x1f72('0x3'));var util=require(_0x1f72('0x4'));var path=require('path');var sox=require(_0x1f72('0x5'));var csv=require(_0x1f72('0x6'));var ejs=require(_0x1f72('0x7'));var fs=require('fs');var fs_extra=require(_0x1f72('0x8'));var _=require(_0x1f72('0x9'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x1f72('0xa'));var deskjs=require(_0x1f72('0xb'));var toCsv=require(_0x1f72('0x6'));var querystring=require(_0x1f72('0xc'));var Papa=require('papaparse');var Redis=require(_0x1f72('0xd'));var authService=require(_0x1f72('0xe'));var qs=require(_0x1f72('0xf'));var as=require(_0x1f72('0x10'));var hardwareService=require(_0x1f72('0x11'));var logger=require(_0x1f72('0x12'))(_0x1f72('0x13'));var utils=require(_0x1f72('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x1f72('0x15'));var db=require(_0x1f72('0x16'))['db'];config[_0x1f72('0x17')]=_['defaults'](config[_0x1f72('0x17')],{'host':_0x1f72('0x18'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./openchannelQueue.socket')['register'](socket);function respondWithStatusCode(_0x1b1518,_0x27cae2){_0x27cae2=_0x27cae2||0xcc;return function(_0x1ce52c){if(_0x1ce52c){return _0x1b1518[_0x1f72('0x19')](_0x27cae2);}return _0x1b1518['status'](_0x27cae2)[_0x1f72('0x1a')]();};}function respondWithResult(_0x4e12b4,_0x9367e4){_0x9367e4=_0x9367e4||0xc8;return function(_0x1bfdbf){if(_0x1bfdbf){return _0x4e12b4[_0x1f72('0x1b')](_0x9367e4)['json'](_0x1bfdbf);}};}function respondWithFilteredResult(_0x3633c0,_0x423e7b){return function(_0x2c84f9){if(_0x2c84f9){var _0x2e3313=typeof _0x423e7b[_0x1f72('0x1c')]===_0x1f72('0x1d')&&typeof _0x423e7b['limit']==='undefined';var _0x15335a=_0x2c84f9[_0x1f72('0x1e')];var _0x158cb8=_0x2e3313?0x0:_0x423e7b[_0x1f72('0x1c')];var _0x2c7c89=_0x2e3313?_0x2c84f9[_0x1f72('0x1e')]:_0x423e7b['offset']+_0x423e7b['limit'];var _0x56efec;if(_0x2c7c89>=_0x15335a){_0x2c7c89=_0x15335a;_0x56efec=0xc8;}else{_0x56efec=0xce;}_0x3633c0['status'](_0x56efec);return _0x3633c0[_0x1f72('0x1f')]('Content-Range',_0x158cb8+'-'+_0x2c7c89+'/'+_0x15335a)[_0x1f72('0x20')](_0x2c84f9);}return null;};}function patchUpdates(_0x7a301c){return function(_0x272f55){try{jsonpatch[_0x1f72('0x21')](_0x272f55,_0x7a301c,!![]);}catch(_0x4369a6){return BPromise['reject'](_0x4369a6);}return _0x272f55[_0x1f72('0x22')]();};}function saveUpdates(_0x48bde3,_0x3c0be5){return function(_0x31f19f){if(_0x31f19f){return _0x31f19f[_0x1f72('0x23')](_0x48bde3)['then'](function(_0x48c40d){return _0x48c40d;});}return null;};}function removeEntity(_0xe414b6,_0x358c75){return function(_0x2255a7){if(_0x2255a7){return _0x2255a7['destroy']()['then'](function(){var _0x3b1fe7=_0x2255a7[_0x1f72('0x24')]({'plain':!![]});var _0x4360b8=_0x1f72('0x25');return db[_0x1f72('0x26')][_0x1f72('0x27')]({'where':{'type':_0x4360b8,'resourceId':_0x3b1fe7['id']}})[_0x1f72('0x28')](function(){return _0x2255a7;});})[_0x1f72('0x28')](function(){_0xe414b6[_0x1f72('0x1b')](0xcc)[_0x1f72('0x1a')]();});}};}function handleEntityNotFound(_0x21cb8f,_0x9ef45b){return function(_0x4c4e41){if(!_0x4c4e41){_0x21cb8f[_0x1f72('0x19')](0x194);}return _0x4c4e41;};}function handleError(_0x193bf6,_0x8f362d){_0x8f362d=_0x8f362d||0x1f4;return function(_0x3390cf){logger['error'](_0x3390cf[_0x1f72('0x29')]);if(_0x3390cf['name']){delete _0x3390cf['name'];}_0x193bf6['status'](_0x8f362d)['send'](_0x3390cf);};}exports[_0x1f72('0x2a')]=function(_0x1010a8,_0x3d362d){var _0x56a898={},_0x3364ac={},_0xedab3f={'count':0x0,'rows':[]};var _0x4c8670=_[_0x1f72('0x2b')](db['OpenchannelQueue']['rawAttributes'],function(_0x4dfc2b){return{'name':_0x4dfc2b[_0x1f72('0x2c')],'type':_0x4dfc2b[_0x1f72('0x2d')][_0x1f72('0x2e')]};});_0x3364ac[_0x1f72('0x2f')]=_[_0x1f72('0x2b')](_0x4c8670,_0x1f72('0x30'));_0x3364ac['query']=_[_0x1f72('0x31')](_0x1010a8[_0x1f72('0x32')]);_0x3364ac['filters']=_[_0x1f72('0x33')](_0x3364ac[_0x1f72('0x2f')],_0x3364ac[_0x1f72('0x32')]);_0x56a898[_0x1f72('0x34')]=_['intersection'](_0x3364ac[_0x1f72('0x2f')],qs[_0x1f72('0x35')](_0x1010a8[_0x1f72('0x32')][_0x1f72('0x35')]));_0x56a898[_0x1f72('0x34')]=_0x56a898[_0x1f72('0x34')][_0x1f72('0x36')]?_0x56a898[_0x1f72('0x34')]:_0x3364ac[_0x1f72('0x2f')];if(!_0x1010a8[_0x1f72('0x32')]['hasOwnProperty'](_0x1f72('0x37'))){_0x56a898[_0x1f72('0x38')]=qs[_0x1f72('0x38')](_0x1010a8['query'][_0x1f72('0x38')]);_0x56a898['offset']=qs[_0x1f72('0x1c')](_0x1010a8[_0x1f72('0x32')][_0x1f72('0x1c')]);}_0x56a898[_0x1f72('0x39')]=qs[_0x1f72('0x3a')](_0x1010a8[_0x1f72('0x32')][_0x1f72('0x3a')]);_0x56a898['where']=qs[_0x1f72('0x3b')](_[_0x1f72('0x3c')](_0x1010a8['query'],_0x3364ac[_0x1f72('0x3b')]),_0x4c8670);if(_0x1010a8['query'][_0x1f72('0x3d')]){_0x56a898[_0x1f72('0x3e')]=_['merge'](_0x56a898[_0x1f72('0x3e')],{'$or':_[_0x1f72('0x2b')](_0x4c8670,function(_0x234241){if(_0x234241[_0x1f72('0x2d')]!=='VIRTUAL'){var _0x5ec9ef={};_0x5ec9ef[_0x234241[_0x1f72('0x30')]]={'$like':'%'+_0x1010a8['query']['filter']+'%'};return _0x5ec9ef;}})});}_0x56a898=_['merge']({},_0x56a898,_0x1010a8[_0x1f72('0x3f')]);var _0x433200={'where':_0x56a898[_0x1f72('0x3e')]};return db[_0x1f72('0x40')][_0x1f72('0x1e')](_0x433200)['then'](function(_0x21a8e0){_0xedab3f[_0x1f72('0x1e')]=_0x21a8e0;if(_0x1010a8[_0x1f72('0x32')][_0x1f72('0x41')]){_0x56a898['include']=[{'all':!![]}];}return db[_0x1f72('0x40')]['findAll'](_0x56a898);})['then'](function(_0x59f95d){_0xedab3f[_0x1f72('0x42')]=_0x59f95d;return _0xedab3f;})[_0x1f72('0x28')](respondWithFilteredResult(_0x3d362d,_0x56a898))[_0x1f72('0x43')](handleError(_0x3d362d,null));};exports[_0x1f72('0x44')]=function(_0x11d916,_0x5d7911){var _0x25b262={'raw':!![],'where':{'id':_0x11d916[_0x1f72('0x45')]['id']}},_0x5ae959={};_0x5ae959['model']=_['keys'](db[_0x1f72('0x40')][_0x1f72('0x46')]);_0x5ae959['query']=_[_0x1f72('0x31')](_0x11d916[_0x1f72('0x32')]);_0x5ae959['filters']=_[_0x1f72('0x33')](_0x5ae959[_0x1f72('0x2f')],_0x5ae959[_0x1f72('0x32')]);_0x25b262[_0x1f72('0x34')]=_[_0x1f72('0x33')](_0x5ae959[_0x1f72('0x2f')],qs[_0x1f72('0x35')](_0x11d916['query'][_0x1f72('0x35')]));_0x25b262[_0x1f72('0x34')]=_0x25b262[_0x1f72('0x34')][_0x1f72('0x36')]?_0x25b262['attributes']:_0x5ae959[_0x1f72('0x2f')];if(_0x11d916[_0x1f72('0x32')][_0x1f72('0x41')]){_0x25b262[_0x1f72('0x47')]=[{'all':!![]}];}_0x25b262=_[_0x1f72('0x48')]({},_0x25b262,_0x11d916['options']);return db[_0x1f72('0x40')]['find'](_0x25b262)[_0x1f72('0x28')](handleEntityNotFound(_0x5d7911,null))[_0x1f72('0x28')](respondWithResult(_0x5d7911,null))[_0x1f72('0x43')](handleError(_0x5d7911,null));};exports[_0x1f72('0x49')]=function(_0x4df6c8,_0x556dbf){return db[_0x1f72('0x40')][_0x1f72('0x49')](_0x4df6c8[_0x1f72('0x4a')],{})[_0x1f72('0x28')](function(_0x692a6c){var _0x2af86d=_0x4df6c8[_0x1f72('0x4b')][_0x1f72('0x24')]({'plain':!![]});if(!_0x2af86d)throw new Error(_0x1f72('0x4c'));if(_0x2af86d['role']==='user'){var _0x5c3fa9=_0x692a6c[_0x1f72('0x24')]({'plain':!![]});var _0x319456=_0x1f72('0x25');return db[_0x1f72('0x4d')][_0x1f72('0x4e')]({'where':{'name':_0x319456,'userProfileId':_0x2af86d[_0x1f72('0x4f')]},'raw':!![]})[_0x1f72('0x28')](function(_0x482544){if(_0x482544&&_0x482544[_0x1f72('0x50')]===0x0){return db[_0x1f72('0x26')][_0x1f72('0x49')]({'name':_0x5c3fa9[_0x1f72('0x30')],'resourceId':_0x5c3fa9['id'],'type':_0x482544[_0x1f72('0x30')],'sectionId':_0x482544['id']},{})[_0x1f72('0x28')](function(){return _0x692a6c;});}else{return _0x692a6c;}})[_0x1f72('0x43')](function(_0x112f49){logger[_0x1f72('0x51')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x112f49);throw _0x112f49;});}return _0x692a6c;})['then'](respondWithResult(_0x556dbf,0xc9))[_0x1f72('0x43')](handleError(_0x556dbf,null));};exports['update']=function(_0x1f4f2a,_0x3faf29){if(_0x1f4f2a[_0x1f72('0x4a')]['id']){delete _0x1f4f2a[_0x1f72('0x4a')]['id'];}return db[_0x1f72('0x40')][_0x1f72('0x4e')]({'where':{'id':_0x1f4f2a[_0x1f72('0x45')]['id']}})[_0x1f72('0x28')](handleEntityNotFound(_0x3faf29,null))['then'](saveUpdates(_0x1f4f2a[_0x1f72('0x4a')],null))['then'](respondWithResult(_0x3faf29,null))['catch'](handleError(_0x3faf29,null));};exports['destroy']=function(_0x2e7876,_0x30ae6b){return db[_0x1f72('0x40')][_0x1f72('0x4e')]({'where':{'id':_0x2e7876[_0x1f72('0x45')]['id']}})[_0x1f72('0x28')](handleEntityNotFound(_0x30ae6b,null))[_0x1f72('0x28')](removeEntity(_0x30ae6b,null))['catch'](handleError(_0x30ae6b,null));};exports[_0x1f72('0x52')]=function(_0x1e8211,_0x54d037){return db[_0x1f72('0x40')][_0x1f72('0x52')]()[_0x1f72('0x28')](respondWithResult(_0x54d037,null))[_0x1f72('0x43')](handleError(_0x54d037,null));};exports[_0x1f72('0x53')]=function(_0x21d0bd,_0x4ff571,_0x358348){var _0x41f8e2={'raw':!![],'where':{}},_0x3f2190={},_0x3f0faf;return db['OpenchannelQueue']['findOne']({'where':{'id':_0x21d0bd[_0x1f72('0x45')]['id']}})['then'](handleEntityNotFound(_0x4ff571,null))[_0x1f72('0x28')](function(_0xca5a8b){if(_0xca5a8b){_0x3f0faf=_0xca5a8b[_0x1f72('0x24')]({'plain':!![]});_0x3f2190['model']=_['keys'](db['UserOpenchannelQueue'][_0x1f72('0x46')]);_0x3f2190[_0x1f72('0x32')]=_[_0x1f72('0x31')](_0x21d0bd[_0x1f72('0x32')]);_0x3f2190['filters']=_[_0x1f72('0x33')](_0x3f2190[_0x1f72('0x2f')],_0x3f2190[_0x1f72('0x32')]);_0x41f8e2['attributes']=_[_0x1f72('0x33')](_0x3f2190['model'],qs[_0x1f72('0x35')](_0x21d0bd[_0x1f72('0x32')][_0x1f72('0x35')]));_0x41f8e2['attributes']=_0x41f8e2[_0x1f72('0x34')]['length']?_0x41f8e2[_0x1f72('0x34')]:_0x3f2190['model'];if(!_0x21d0bd['query'][_0x1f72('0x54')](_0x1f72('0x37'))){_0x41f8e2[_0x1f72('0x38')]=qs[_0x1f72('0x38')](_0x21d0bd[_0x1f72('0x32')]['limit']);_0x41f8e2[_0x1f72('0x1c')]=qs['offset'](_0x21d0bd[_0x1f72('0x32')][_0x1f72('0x1c')]);}_0x41f8e2['order']=qs[_0x1f72('0x3a')](_0x21d0bd[_0x1f72('0x32')][_0x1f72('0x3a')]);_0x41f8e2['where']=qs[_0x1f72('0x3b')](_[_0x1f72('0x3c')](_0x21d0bd[_0x1f72('0x32')],_0x3f2190['filters']));_0x41f8e2[_0x1f72('0x3e')][_0x1f72('0x55')]=_0xca5a8b['id'];if(_0x21d0bd[_0x1f72('0x32')][_0x1f72('0x3d')]){_0x41f8e2[_0x1f72('0x3e')]=_[_0x1f72('0x48')](_0x41f8e2[_0x1f72('0x3e')],{'$or':_['map'](_0x41f8e2['attributes'],function(_0x2eb0e7){var _0x17baf1={};_0x17baf1[_0x2eb0e7]={'$like':'%'+_0x21d0bd[_0x1f72('0x32')][_0x1f72('0x3d')]+'%'};return _0x17baf1;})});}_0x41f8e2=_[_0x1f72('0x48')]({},_0x41f8e2,_0x21d0bd[_0x1f72('0x3f')]);return db[_0x1f72('0x56')]['findAll'](_0x41f8e2);}})[_0x1f72('0x28')](function(_0x111b02){if(_0x111b02){return db[_0x1f72('0x57')][_0x1f72('0x58')]({'where':{'id':_[_0x1f72('0x2b')](_0x111b02,_0x1f72('0x59')),'role':_0x1f72('0x5a')},'attributes':['id',_0x1f72('0x30'),_0x1f72('0x5b'),_0x1f72('0x5c'),_0x1f72('0x5d')]});}})['then'](function(_0x2aafd5){if(_0x2aafd5){return{'count':_0x2aafd5[_0x1f72('0x1e')],'rows':_['map'](_0x2aafd5[_0x1f72('0x42')],function(_0x4e38d7){return{'membername':_0x4e38d7[_0x1f72('0x30')],'UserId':_0x4e38d7['id'],'queue_name':_0x3f0faf['name'],'OpenchannelQueueId':_0x3f0faf['id'],'interface':util[_0x1f72('0x5e')]('%s/%s',_0x1f72('0x5f'),_0x4e38d7[_0x1f72('0x30')]),'penalty':0x0,'paused':_0x4e38d7[_0x1f72('0x5b')],'createdAt':_0x4e38d7[_0x1f72('0x5d')],'updatedAt':_0x4e38d7[_0x1f72('0x5c')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x1f72('0x28')](respondWithFilteredResult(_0x4ff571,_0x41f8e2))[_0x1f72('0x43')](handleError(_0x4ff571,null));};exports[_0x1f72('0x60')]=function(_0x1ed0b7,_0x5da97c,_0x3058a7){var _0x288659={};var _0x53deec={};var _0x36d046;var _0x303743;return db[_0x1f72('0x40')]['findOne']({'where':{'id':_0x1ed0b7[_0x1f72('0x45')]['id']}})['then'](handleEntityNotFound(_0x5da97c,null))[_0x1f72('0x28')](function(_0x43d86a){if(_0x43d86a){_0x36d046=_0x43d86a;_0x53deec[_0x1f72('0x2f')]=_['keys'](db['Team'][_0x1f72('0x46')]);_0x53deec[_0x1f72('0x32')]=_[_0x1f72('0x31')](_0x1ed0b7['query']);_0x53deec['filters']=_[_0x1f72('0x33')](_0x53deec['model'],_0x53deec['query']);_0x288659[_0x1f72('0x34')]=_['intersection'](_0x53deec['model'],qs[_0x1f72('0x35')](_0x1ed0b7['query'][_0x1f72('0x35')]));_0x288659[_0x1f72('0x34')]=_0x288659[_0x1f72('0x34')]['length']?_0x288659['attributes']:_0x53deec[_0x1f72('0x2f')];_0x288659[_0x1f72('0x39')]=qs[_0x1f72('0x3a')](_0x1ed0b7[_0x1f72('0x32')][_0x1f72('0x3a')]);_0x288659[_0x1f72('0x3e')]=qs['filters'](_[_0x1f72('0x3c')](_0x1ed0b7[_0x1f72('0x32')],_0x53deec['filters']));if(_0x1ed0b7['query'][_0x1f72('0x3d')]){_0x288659[_0x1f72('0x3e')]=_[_0x1f72('0x48')](_0x288659[_0x1f72('0x3e')],{'$or':_[_0x1f72('0x2b')](_0x288659['attributes'],function(_0x57f53e){var _0x1a439f={};_0x1a439f[_0x57f53e]={'$like':'%'+_0x1ed0b7[_0x1f72('0x32')][_0x1f72('0x3d')]+'%'};return _0x1a439f;})});}_0x288659=_[_0x1f72('0x48')]({},_0x288659,_0x1ed0b7[_0x1f72('0x3f')]);return _0x36d046['getTeams'](_0x288659);}})[_0x1f72('0x28')](function(_0x453e44){if(_0x453e44){_0x303743=_0x453e44[_0x1f72('0x36')];if(!_0x1ed0b7[_0x1f72('0x32')][_0x1f72('0x54')]('nolimit')){_0x288659['limit']=qs[_0x1f72('0x38')](_0x1ed0b7[_0x1f72('0x32')]['limit']);_0x288659[_0x1f72('0x1c')]=qs[_0x1f72('0x1c')](_0x1ed0b7[_0x1f72('0x32')][_0x1f72('0x1c')]);}return _0x36d046[_0x1f72('0x60')](_0x288659);}})[_0x1f72('0x28')](function(_0x247a36){if(_0x247a36){return _0x247a36?{'count':_0x303743,'rows':_0x247a36}:null;}})[_0x1f72('0x28')](respondWithResult(_0x5da97c,null))[_0x1f72('0x43')](handleError(_0x5da97c,null));};exports[_0x1f72('0x61')]=function(_0x4686e5,_0x1d689d,_0x21f4d4){var _0x24019c=_0x4686e5[_0x1f72('0x4a')][_0x1f72('0x62')];return db[_0x1f72('0x63')]['findAll']({'where':{'id':_0x24019c},'attributes':['id'],'include':[{'model':db[_0x1f72('0x57')],'as':_0x1f72('0x64'),'attributes':['id','name','online',_0x1f72('0x65'),_0x1f72('0x66')],'raw':!![]}]})[_0x1f72('0x28')](function(_0x775246){if(_0x775246){var _0x2b5f9f=_['flatMap'](_0x775246,function(_0xe464c3){var _0x536bdc=_0xe464c3[_0x1f72('0x24')]({'plain':!![]});return _0x536bdc[_0x1f72('0x64')];});return db[_0x1f72('0x40')]['find']({'where':{'id':_0x4686e5[_0x1f72('0x45')]['id']}})[_0x1f72('0x28')](function(_0x298a6f){return db[_0x1f72('0x67')]['transaction'](function(_0x450760){return _0x298a6f[_0x1f72('0x61')](_0x24019c,{'transaction':_0x450760})['then'](function(){return BPromise[_0x1f72('0x68')](_0x2b5f9f,function(_0x52569a){return db['UserOpenchannelQueue'][_0x1f72('0x69')]({'where':{'UserId':_0x52569a['id'],'OpenchannelQueueId':_0x4686e5[_0x1f72('0x45')]['id']},'transaction':_0x450760});});})[_0x1f72('0x28')](function(){_0x2b5f9f['forEach'](function(_0x446860){socket['emit'](_0x1f72('0x6a'),{'UserId':_0x446860['id'],'OpenchannelQueueId':_0x298a6f['id']});});});});});}})['then'](respondWithStatusCode(_0x1d689d,null))[_0x1f72('0x43')](handleError(_0x1d689d,null));};exports[_0x1f72('0x6b')]=function(_0x39359c,_0x281f9a,_0x292562){return db['Team'][_0x1f72('0x6c')]({'where':{'id':_0x39359c[_0x1f72('0x32')][_0x1f72('0x62')]},'attributes':['id'],'include':[{'model':db['User'],'as':_0x1f72('0x64'),'attributes':['id'],'raw':!![]}]})[_0x1f72('0x28')](handleEntityNotFound(_0x281f9a,null))[_0x1f72('0x28')](function(_0x2f2993){var _0x299b92=_[_0x1f72('0x2b')](_0x2f2993,'id');var _0x241855=[];var _0x305799=[];var _0x398a70=squel[_0x1f72('0x6d')]();_0x398a70['field'](_0x1f72('0x6e'))[_0x1f72('0x6f')](_0x1f72('0x70'),'tq')['join']('user_has_teams','ut',_0x1f72('0x71'))['where']('OpenchannelQueueId\x20=\x20?',_0x39359c[_0x1f72('0x45')]['id']);for(var _0x4426e9=0x0;_0x4426e9<_0x2f2993[_0x1f72('0x36')];_0x4426e9+=0x1){let _0x68ebad=_0x2f2993[_0x4426e9];for(var _0xb45a06=0x0;_0xb45a06<_0x68ebad[_0x1f72('0x64')]['length'];_0xb45a06+=0x1){let _0x4d01d5=_0x68ebad[_0x1f72('0x64')][_0xb45a06];var _0x3efd57=_0x398a70[_0x1f72('0x72')]();_0x3efd57[_0x1f72('0x3e')](_0x1f72('0x73'),_0x4d01d5['id']);_0x305799[_0x1f72('0x74')](db[_0x1f72('0x67')][_0x1f72('0x32')](_0x3efd57[_0x1f72('0x75')](),{'type':db[_0x1f72('0x67')][_0x1f72('0x76')][_0x1f72('0x77')]})[_0x1f72('0x28')](function(_0x49a102){if(_0x49a102['length']===0x1){return _0x4d01d5['id'];}else{var _0x396522=_[_0x1f72('0x78')](_[_0x1f72('0x2b')](_0x49a102,_0x1f72('0x79')),function(_0x48eebd){return _[_0x1f72('0x7a')](_0x299b92,_0x48eebd);});if(_0x396522){return _0x4d01d5['id'];}}}));}}return BPromise[_0x1f72('0x7b')](_0x305799)[_0x1f72('0x28')](function(_0x151035){_0x241855=_(_0x241855)[_0x1f72('0x7c')](_0x151035)[_0x1f72('0x7d')]()['value']();return db['OpenchannelQueue'][_0x1f72('0x4e')]({'where':{'id':_0x39359c[_0x1f72('0x45')]['id']}})[_0x1f72('0x28')](function(_0x6bd934){return db[_0x1f72('0x67')]['transaction'](function(_0x269916){return _0x6bd934[_0x1f72('0x6b')](_0x39359c[_0x1f72('0x32')]['ids'],{'transaction':_0x269916})[_0x1f72('0x28')](function(){if(!_[_0x1f72('0x7e')](_0x241855)){return _0x6bd934[_0x1f72('0x7f')](_0x241855,{'transaction':_0x269916});}})[_0x1f72('0x28')](function(){_0x241855[_0x1f72('0x80')](function(_0x4a7f63){socket[_0x1f72('0x81')](_0x1f72('0x82'),{'UserId':_0x4a7f63,'OpenchannelQueueId':_0x6bd934['id']});});});});});});})[_0x1f72('0x28')](respondWithStatusCode(_0x281f9a,null))[_0x1f72('0x43')](handleError(_0x281f9a,null));};exports['addAgents']=function(_0x50437b,_0x1590e9,_0x3a5a9e){return db[_0x1f72('0x40')][_0x1f72('0x4e')]({'where':{'id':_0x50437b[_0x1f72('0x45')]['id']}})[_0x1f72('0x28')](handleEntityNotFound(_0x1590e9,null))['then'](function(_0x3c0ed3){if(_0x3c0ed3){return _0x3c0ed3[_0x1f72('0x83')](_0x50437b['body']['ids'],_['omit'](_0x50437b[_0x1f72('0x4a')],['ids','id'])||{})[_0x1f72('0x84')](function(_0x119911){for(var _0x280b66=0x0;_0x280b66<_0x50437b[_0x1f72('0x4a')][_0x1f72('0x62')][_0x1f72('0x36')];_0x280b66+=0x1){socket[_0x1f72('0x81')](_0x1f72('0x6a'),{'UserId':Number(_0x50437b[_0x1f72('0x4a')]['ids'][_0x280b66]),'OpenchannelQueueId':Number(_0x50437b[_0x1f72('0x45')]['id'])});}return _0x119911;});}})[_0x1f72('0x28')](respondWithResult(_0x1590e9,null))[_0x1f72('0x43')](handleError(_0x1590e9,null));};exports[_0x1f72('0x7f')]=function(_0x334f17,_0x35ca9f,_0x378b09){return db[_0x1f72('0x40')][_0x1f72('0x4e')]({'where':{'id':_0x334f17[_0x1f72('0x45')]['id']}})[_0x1f72('0x28')](handleEntityNotFound(_0x35ca9f,null))[_0x1f72('0x28')](function(_0x20d3f5){if(_0x20d3f5){return _0x20d3f5[_0x1f72('0x7f')](_0x334f17[_0x1f72('0x32')][_0x1f72('0x62')])[_0x1f72('0x28')](function(){if(_[_0x1f72('0x85')](_0x334f17[_0x1f72('0x32')]['ids'])){for(var _0x494242=0x0;_0x494242<_0x334f17[_0x1f72('0x32')][_0x1f72('0x62')][_0x1f72('0x36')];_0x494242+=0x1){socket[_0x1f72('0x81')](_0x1f72('0x82'),{'UserId':Number(_0x334f17[_0x1f72('0x32')]['ids'][_0x494242]),'OpenchannelQueueId':Number(_0x334f17[_0x1f72('0x45')]['id'])});}}else{socket['emit'](_0x1f72('0x82'),{'UserId':Number(_0x334f17[_0x1f72('0x32')]['ids']),'OpenchannelQueueId':Number(_0x334f17[_0x1f72('0x45')]['id'])});}});}})[_0x1f72('0x28')](respondWithStatusCode(_0x35ca9f,null))[_0x1f72('0x43')](handleError(_0x35ca9f,null));};exports[_0x1f72('0x86')]=function(_0x419be5,_0x37b19d,_0xba914d){var _0x57d892={};var _0x55b8e5={};var _0x1b2212;var _0x37f235;return db[_0x1f72('0x40')]['findOne']({'where':{'id':_0x419be5[_0x1f72('0x45')]['id']}})['then'](handleEntityNotFound(_0x37b19d,null))[_0x1f72('0x28')](function(_0x5617b9){if(_0x5617b9){_0x1b2212=_0x5617b9;_0x55b8e5[_0x1f72('0x2f')]=_['keys'](db[_0x1f72('0x57')][_0x1f72('0x46')]);_0x55b8e5['query']=_[_0x1f72('0x31')](_0x419be5[_0x1f72('0x32')]);_0x55b8e5[_0x1f72('0x3b')]=_['intersection'](_0x55b8e5[_0x1f72('0x2f')],_0x55b8e5[_0x1f72('0x32')]);_0x57d892[_0x1f72('0x34')]=_[_0x1f72('0x33')](_0x55b8e5[_0x1f72('0x2f')],qs['fields'](_0x419be5[_0x1f72('0x32')][_0x1f72('0x35')]));_0x57d892[_0x1f72('0x34')]=_0x57d892[_0x1f72('0x34')][_0x1f72('0x36')]?_0x57d892[_0x1f72('0x34')]:_0x55b8e5[_0x1f72('0x2f')];_0x57d892[_0x1f72('0x39')]=qs[_0x1f72('0x3a')](_0x419be5[_0x1f72('0x32')][_0x1f72('0x3a')]);_0x57d892[_0x1f72('0x3e')]=qs[_0x1f72('0x3b')](_['pick'](_0x419be5[_0x1f72('0x32')],_0x55b8e5[_0x1f72('0x3b')]));if(_0x419be5[_0x1f72('0x32')][_0x1f72('0x3d')]){_0x57d892['where']=_['merge'](_0x57d892[_0x1f72('0x3e')],{'$or':_[_0x1f72('0x2b')](_0x57d892[_0x1f72('0x34')],function(_0x4d6d5d){var _0x185628={};_0x185628[_0x4d6d5d]={'$like':'%'+_0x419be5[_0x1f72('0x32')][_0x1f72('0x3d')]+'%'};return _0x185628;})});}_0x57d892=_[_0x1f72('0x48')]({},_0x57d892,_0x419be5[_0x1f72('0x3f')]);return _0x1b2212[_0x1f72('0x86')](_0x57d892);}})[_0x1f72('0x28')](function(_0x5d22c3){if(_0x5d22c3){_0x37f235=_0x5d22c3[_0x1f72('0x36')];if(!_0x419be5[_0x1f72('0x32')][_0x1f72('0x54')](_0x1f72('0x37'))){_0x57d892[_0x1f72('0x38')]=qs[_0x1f72('0x38')](_0x419be5[_0x1f72('0x32')][_0x1f72('0x38')]);_0x57d892[_0x1f72('0x1c')]=qs['offset'](_0x419be5[_0x1f72('0x32')]['offset']);}return _0x1b2212[_0x1f72('0x86')](_0x57d892);}})[_0x1f72('0x28')](function(_0x4daaa9){if(_0x4daaa9){return _0x4daaa9?{'count':_0x37f235,'rows':_0x4daaa9}:null;}})['then'](respondWithResult(_0x37b19d,null))[_0x1f72('0x43')](handleError(_0x37b19d,null));};