Built motion from commit fade34fd.|2.5.41
[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 _0x889f=['status','end','offset','undefined','limit','count','Content-Range','json','save','update','then','destroy','get','OpenchannelQueues','UserProfileResource','error','stack','name','index','map','OpenchannelQueue','fieldName','type','key','query','model','fields','attributes','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','where','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','keys','rawAttributes','intersection','find','catch','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','describe','UserOpenchannelQueue','OpenchannelQueueId','options','findAndCountAll','UserId','openchannelPause','updatedAt','createdAt','%s/%s','getTeams','findOne','addTeams','Team','User','online','voicePause','interface','flatMap','Agents','sequelize','transaction','each','findOrCreate','forEach','emit','userOpenchannelQueue:save','removeTeams','ids','select','field','tq.TeamId','from','join','ut.TeamId\x20=\x20tq.TeamId','OpenchannelQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','QueryTypes','SELECT','includes','all','union','value','isEmpty','removeAgents','userOpenchannelQueue:remove','addAgents','omit','isArray','getAgents','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','ejs','fs-extra','squel','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','redis','socket.io-emitter','./openchannelQueue.socket','register','sendStatus'];(function(_0x220afa,_0xf5f6cc){var _0x1b79d1=function(_0x178a39){while(--_0x178a39){_0x220afa['push'](_0x220afa['shift']());}};_0x1b79d1(++_0xf5f6cc);}(_0x889f,0xf6));var _0xf889=function(_0x4b2863,_0x494899){_0x4b2863=_0x4b2863-0x0;var _0x567d67=_0x889f[_0x4b2863];return _0x567d67;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf889('0x0'));var zipdir=require(_0xf889('0x1'));var jsonpatch=require(_0xf889('0x2'));var rp=require('request-promise');var moment=require(_0xf889('0x3'));var BPromise=require(_0xf889('0x4'));var Mustache=require(_0xf889('0x5'));var util=require(_0xf889('0x6'));var path=require(_0xf889('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xf889('0x8'));var fs=require('fs');var fs_extra=require(_0xf889('0x9'));var _=require('lodash');var squel=require(_0xf889('0xa'));var crypto=require(_0xf889('0xb'));var jsforce=require(_0xf889('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xf889('0xd'));var querystring=require(_0xf889('0xe'));var Papa=require(_0xf889('0xf'));var Redis=require(_0xf889('0x10'));var authService=require(_0xf889('0x11'));var qs=require(_0xf889('0x12'));var as=require(_0xf889('0x13'));var hardwareService=require(_0xf889('0x14'));var logger=require(_0xf889('0x15'))(_0xf889('0x16'));var utils=require('../../config/utils');var config=require(_0xf889('0x17'));var licenseUtil=require(_0xf889('0x18'));var db=require('../../mysqldb')['db'];config[_0xf889('0x19')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xf889('0x1a'))(new Redis(config[_0xf889('0x19')]));require(_0xf889('0x1b'))[_0xf889('0x1c')](socket);function respondWithStatusCode(_0x3d23c6,_0x939fd5){_0x939fd5=_0x939fd5||0xcc;return function(_0xee3cfc){if(_0xee3cfc){return _0x3d23c6[_0xf889('0x1d')](_0x939fd5);}return _0x3d23c6[_0xf889('0x1e')](_0x939fd5)[_0xf889('0x1f')]();};}function respondWithResult(_0x18fc92,_0x1751da){_0x1751da=_0x1751da||0xc8;return function(_0x497cac){if(_0x497cac){return _0x18fc92[_0xf889('0x1e')](_0x1751da)['json'](_0x497cac);}};}function respondWithFilteredResult(_0x33ae76,_0x20d4b6){return function(_0x321e5c){if(_0x321e5c){var _0x3f409a=typeof _0x20d4b6[_0xf889('0x20')]===_0xf889('0x21')&&typeof _0x20d4b6[_0xf889('0x22')]===_0xf889('0x21');var _0xb98b3b=_0x321e5c[_0xf889('0x23')];var _0x3c91e7=_0x3f409a?0x0:_0x20d4b6[_0xf889('0x20')];var _0x3f2530=_0x3f409a?_0x321e5c[_0xf889('0x23')]:_0x20d4b6[_0xf889('0x20')]+_0x20d4b6[_0xf889('0x22')];var _0x3c7136;if(_0x3f2530>=_0xb98b3b){_0x3f2530=_0xb98b3b;_0x3c7136=0xc8;}else{_0x3c7136=0xce;}_0x33ae76[_0xf889('0x1e')](_0x3c7136);return _0x33ae76['set'](_0xf889('0x24'),_0x3c91e7+'-'+_0x3f2530+'/'+_0xb98b3b)[_0xf889('0x25')](_0x321e5c);}return null;};}function patchUpdates(_0x43d77e){return function(_0x221f33){try{jsonpatch['apply'](_0x221f33,_0x43d77e,!![]);}catch(_0x3f33e1){return BPromise['reject'](_0x3f33e1);}return _0x221f33[_0xf889('0x26')]();};}function saveUpdates(_0x4cd675,_0x12a9fd){return function(_0xde02b9){if(_0xde02b9){return _0xde02b9[_0xf889('0x27')](_0x4cd675)[_0xf889('0x28')](function(_0x356cf1){return _0x356cf1;});}return null;};}function removeEntity(_0x103ff8,_0x17e650){return function(_0x2d6f53){if(_0x2d6f53){return _0x2d6f53[_0xf889('0x29')]()['then'](function(){var _0x3a404d=_0x2d6f53[_0xf889('0x2a')]({'plain':!![]});var _0x3f9462=_0xf889('0x2b');return db[_0xf889('0x2c')]['destroy']({'where':{'type':_0x3f9462,'resourceId':_0x3a404d['id']}})[_0xf889('0x28')](function(){return _0x2d6f53;});})[_0xf889('0x28')](function(){_0x103ff8['status'](0xcc)[_0xf889('0x1f')]();});}};}function handleEntityNotFound(_0x13081e,_0x57e2ea){return function(_0x4027b6){if(!_0x4027b6){_0x13081e[_0xf889('0x1d')](0x194);}return _0x4027b6;};}function handleError(_0x4aa3d1,_0x5bb3ac){_0x5bb3ac=_0x5bb3ac||0x1f4;return function(_0x4da384){logger[_0xf889('0x2d')](_0x4da384[_0xf889('0x2e')]);if(_0x4da384['name']){delete _0x4da384[_0xf889('0x2f')];}_0x4aa3d1['status'](_0x5bb3ac)['send'](_0x4da384);};}exports[_0xf889('0x30')]=function(_0x5bbc62,_0x3c7c9a){var _0x3ed254={},_0x583156={},_0x460759={'count':0x0,'rows':[]};var _0x163194=_[_0xf889('0x31')](db[_0xf889('0x32')]['rawAttributes'],function(_0x2961e5){return{'name':_0x2961e5[_0xf889('0x33')],'type':_0x2961e5[_0xf889('0x34')][_0xf889('0x35')]};});_0x583156['model']=_[_0xf889('0x31')](_0x163194,_0xf889('0x2f'));_0x583156['query']=_['keys'](_0x5bbc62[_0xf889('0x36')]);_0x583156['filters']=_['intersection'](_0x583156['model'],_0x583156['query']);_0x3ed254['attributes']=_['intersection'](_0x583156[_0xf889('0x37')],qs[_0xf889('0x38')](_0x5bbc62[_0xf889('0x36')]['fields']));_0x3ed254[_0xf889('0x39')]=_0x3ed254[_0xf889('0x39')][_0xf889('0x3a')]?_0x3ed254[_0xf889('0x39')]:_0x583156[_0xf889('0x37')];if(!_0x5bbc62['query'][_0xf889('0x3b')](_0xf889('0x3c'))){_0x3ed254[_0xf889('0x22')]=qs[_0xf889('0x22')](_0x5bbc62[_0xf889('0x36')][_0xf889('0x22')]);_0x3ed254['offset']=qs[_0xf889('0x20')](_0x5bbc62[_0xf889('0x36')][_0xf889('0x20')]);}_0x3ed254[_0xf889('0x3d')]=qs[_0xf889('0x3e')](_0x5bbc62[_0xf889('0x36')][_0xf889('0x3e')]);_0x3ed254['where']=qs[_0xf889('0x3f')](_[_0xf889('0x40')](_0x5bbc62[_0xf889('0x36')],_0x583156[_0xf889('0x3f')]),_0x163194);if(_0x5bbc62[_0xf889('0x36')][_0xf889('0x41')]){_0x3ed254[_0xf889('0x42')]=_[_0xf889('0x43')](_0x3ed254[_0xf889('0x42')],{'$or':_[_0xf889('0x31')](_0x163194,function(_0x3ee114){if(_0x3ee114[_0xf889('0x34')]!==_0xf889('0x44')){var _0x27f962={};_0x27f962[_0x3ee114[_0xf889('0x2f')]]={'$like':'%'+_0x5bbc62[_0xf889('0x36')][_0xf889('0x41')]+'%'};return _0x27f962;}})});}_0x3ed254=_[_0xf889('0x43')]({},_0x3ed254,_0x5bbc62['options']);var _0x8b2c05={'where':_0x3ed254[_0xf889('0x42')]};return db[_0xf889('0x32')][_0xf889('0x23')](_0x8b2c05)[_0xf889('0x28')](function(_0xa73a46){_0x460759['count']=_0xa73a46;if(_0x5bbc62[_0xf889('0x36')][_0xf889('0x45')]){_0x3ed254[_0xf889('0x46')]=[{'all':!![]}];}return db['OpenchannelQueue'][_0xf889('0x47')](_0x3ed254);})[_0xf889('0x28')](function(_0x1a8171){_0x460759[_0xf889('0x48')]=_0x1a8171;return _0x460759;})[_0xf889('0x28')](respondWithFilteredResult(_0x3c7c9a,_0x3ed254))['catch'](handleError(_0x3c7c9a,null));};exports[_0xf889('0x49')]=function(_0x1015ae,_0x547009){var _0x58ce91={'raw':!![],'where':{'id':_0x1015ae[_0xf889('0x4a')]['id']}},_0x165778={};_0x165778[_0xf889('0x37')]=_[_0xf889('0x4b')](db[_0xf889('0x32')][_0xf889('0x4c')]);_0x165778[_0xf889('0x36')]=_[_0xf889('0x4b')](_0x1015ae['query']);_0x165778['filters']=_[_0xf889('0x4d')](_0x165778[_0xf889('0x37')],_0x165778[_0xf889('0x36')]);_0x58ce91['attributes']=_[_0xf889('0x4d')](_0x165778[_0xf889('0x37')],qs['fields'](_0x1015ae['query'][_0xf889('0x38')]));_0x58ce91[_0xf889('0x39')]=_0x58ce91['attributes'][_0xf889('0x3a')]?_0x58ce91[_0xf889('0x39')]:_0x165778[_0xf889('0x37')];if(_0x1015ae[_0xf889('0x36')][_0xf889('0x45')]){_0x58ce91[_0xf889('0x46')]=[{'all':!![]}];}_0x58ce91=_[_0xf889('0x43')]({},_0x58ce91,_0x1015ae['options']);return db[_0xf889('0x32')][_0xf889('0x4e')](_0x58ce91)['then'](handleEntityNotFound(_0x547009,null))[_0xf889('0x28')](respondWithResult(_0x547009,null))[_0xf889('0x4f')](handleError(_0x547009,null));};exports[_0xf889('0x50')]=function(_0x20be56,_0xb9d143){return db['OpenchannelQueue']['create'](_0x20be56[_0xf889('0x51')],{})['then'](function(_0x387bb5){var _0x5aab30=_0x20be56[_0xf889('0x52')]['get']({'plain':!![]});if(!_0x5aab30)throw new Error(_0xf889('0x53'));if(_0x5aab30[_0xf889('0x54')]==='user'){var _0x487b27=_0x387bb5[_0xf889('0x2a')]({'plain':!![]});var _0x4c42df=_0xf889('0x2b');return db['UserProfileSection']['find']({'where':{'name':_0x4c42df,'userProfileId':_0x5aab30[_0xf889('0x55')]},'raw':!![]})[_0xf889('0x28')](function(_0x1be7cd){if(_0x1be7cd&&_0x1be7cd['autoAssociation']===0x0){return db['UserProfileResource'][_0xf889('0x50')]({'name':_0x487b27[_0xf889('0x2f')],'resourceId':_0x487b27['id'],'type':_0x1be7cd[_0xf889('0x2f')],'sectionId':_0x1be7cd['id']},{})[_0xf889('0x28')](function(){return _0x387bb5;});}else{return _0x387bb5;}})[_0xf889('0x4f')](function(_0x133575){logger[_0xf889('0x2d')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x133575);throw _0x133575;});}return _0x387bb5;})[_0xf889('0x28')](respondWithResult(_0xb9d143,0xc9))[_0xf889('0x4f')](handleError(_0xb9d143,null));};exports[_0xf889('0x27')]=function(_0x302855,_0x2d3dd0){if(_0x302855[_0xf889('0x51')]['id']){delete _0x302855['body']['id'];}return db[_0xf889('0x32')]['find']({'where':{'id':_0x302855['params']['id']}})['then'](handleEntityNotFound(_0x2d3dd0,null))[_0xf889('0x28')](saveUpdates(_0x302855[_0xf889('0x51')],null))[_0xf889('0x28')](respondWithResult(_0x2d3dd0,null))['catch'](handleError(_0x2d3dd0,null));};exports[_0xf889('0x29')]=function(_0x2a51fa,_0x34e486){return db[_0xf889('0x32')][_0xf889('0x4e')]({'where':{'id':_0x2a51fa[_0xf889('0x4a')]['id']}})[_0xf889('0x28')](handleEntityNotFound(_0x34e486,null))[_0xf889('0x28')](removeEntity(_0x34e486,null))['catch'](handleError(_0x34e486,null));};exports[_0xf889('0x56')]=function(_0x478011,_0x233c3b){return db[_0xf889('0x32')]['describe']()[_0xf889('0x28')](respondWithResult(_0x233c3b,null))['catch'](handleError(_0x233c3b,null));};exports['getMembers']=function(_0x22aa71,_0x46cd1e,_0x5a9695){var _0x359e09={'raw':!![],'where':{}},_0xc9e63b={},_0xbbe0ba;return db[_0xf889('0x32')]['findOne']({'where':{'id':_0x22aa71['params']['id']}})[_0xf889('0x28')](handleEntityNotFound(_0x46cd1e,null))[_0xf889('0x28')](function(_0x2c1da1){if(_0x2c1da1){_0xbbe0ba=_0x2c1da1[_0xf889('0x2a')]({'plain':!![]});_0xc9e63b[_0xf889('0x37')]=_[_0xf889('0x4b')](db[_0xf889('0x57')][_0xf889('0x4c')]);_0xc9e63b[_0xf889('0x36')]=_['keys'](_0x22aa71['query']);_0xc9e63b[_0xf889('0x3f')]=_['intersection'](_0xc9e63b[_0xf889('0x37')],_0xc9e63b[_0xf889('0x36')]);_0x359e09[_0xf889('0x39')]=_['intersection'](_0xc9e63b[_0xf889('0x37')],qs[_0xf889('0x38')](_0x22aa71[_0xf889('0x36')][_0xf889('0x38')]));_0x359e09['attributes']=_0x359e09[_0xf889('0x39')]['length']?_0x359e09[_0xf889('0x39')]:_0xc9e63b[_0xf889('0x37')];if(!_0x22aa71['query'][_0xf889('0x3b')]('nolimit')){_0x359e09['limit']=qs['limit'](_0x22aa71[_0xf889('0x36')][_0xf889('0x22')]);_0x359e09[_0xf889('0x20')]=qs[_0xf889('0x20')](_0x22aa71['query']['offset']);}_0x359e09[_0xf889('0x3d')]=qs[_0xf889('0x3e')](_0x22aa71['query'][_0xf889('0x3e')]);_0x359e09[_0xf889('0x42')]=qs[_0xf889('0x3f')](_[_0xf889('0x40')](_0x22aa71[_0xf889('0x36')],_0xc9e63b[_0xf889('0x3f')]));_0x359e09[_0xf889('0x42')][_0xf889('0x58')]=_0x2c1da1['id'];if(_0x22aa71[_0xf889('0x36')][_0xf889('0x41')]){_0x359e09[_0xf889('0x42')]=_[_0xf889('0x43')](_0x359e09[_0xf889('0x42')],{'$or':_[_0xf889('0x31')](_0x359e09['attributes'],function(_0x13c973){var _0xebd7bd={};_0xebd7bd[_0x13c973]={'$like':'%'+_0x22aa71[_0xf889('0x36')]['filter']+'%'};return _0xebd7bd;})});}_0x359e09=_[_0xf889('0x43')]({},_0x359e09,_0x22aa71[_0xf889('0x59')]);return db[_0xf889('0x57')][_0xf889('0x47')](_0x359e09);}})['then'](function(_0x56d88a){if(_0x56d88a){return db['User'][_0xf889('0x5a')]({'where':{'id':_[_0xf889('0x31')](_0x56d88a,_0xf889('0x5b')),'role':'agent'},'attributes':['id','name',_0xf889('0x5c'),_0xf889('0x5d'),_0xf889('0x5e')]});}})[_0xf889('0x28')](function(_0xb001b4){if(_0xb001b4){return{'count':_0xb001b4[_0xf889('0x23')],'rows':_[_0xf889('0x31')](_0xb001b4[_0xf889('0x48')],function(_0x22def0){return{'membername':_0x22def0[_0xf889('0x2f')],'UserId':_0x22def0['id'],'queue_name':_0xbbe0ba[_0xf889('0x2f')],'OpenchannelQueueId':_0xbbe0ba['id'],'interface':util['format'](_0xf889('0x5f'),'SIP',_0x22def0[_0xf889('0x2f')]),'penalty':0x0,'paused':_0x22def0['openchannelPause'],'createdAt':_0x22def0[_0xf889('0x5e')],'updatedAt':_0x22def0['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0xf889('0x28')](respondWithFilteredResult(_0x46cd1e,_0x359e09))['catch'](handleError(_0x46cd1e,null));};exports[_0xf889('0x60')]=function(_0x167583,_0x58159d,_0x53a0a3){var _0x4606a2={};var _0xf263b={};var _0x529715;var _0x3aafea;return db['OpenchannelQueue'][_0xf889('0x61')]({'where':{'id':_0x167583[_0xf889('0x4a')]['id']}})[_0xf889('0x28')](handleEntityNotFound(_0x58159d,null))[_0xf889('0x28')](function(_0x26efe4){if(_0x26efe4){_0x529715=_0x26efe4;_0xf263b[_0xf889('0x37')]=_[_0xf889('0x4b')](db['Team']['rawAttributes']);_0xf263b['query']=_[_0xf889('0x4b')](_0x167583[_0xf889('0x36')]);_0xf263b[_0xf889('0x3f')]=_[_0xf889('0x4d')](_0xf263b[_0xf889('0x37')],_0xf263b['query']);_0x4606a2[_0xf889('0x39')]=_['intersection'](_0xf263b['model'],qs['fields'](_0x167583[_0xf889('0x36')]['fields']));_0x4606a2[_0xf889('0x39')]=_0x4606a2[_0xf889('0x39')][_0xf889('0x3a')]?_0x4606a2[_0xf889('0x39')]:_0xf263b['model'];_0x4606a2[_0xf889('0x3d')]=qs[_0xf889('0x3e')](_0x167583['query'][_0xf889('0x3e')]);_0x4606a2[_0xf889('0x42')]=qs[_0xf889('0x3f')](_[_0xf889('0x40')](_0x167583['query'],_0xf263b[_0xf889('0x3f')]));if(_0x167583[_0xf889('0x36')][_0xf889('0x41')]){_0x4606a2[_0xf889('0x42')]=_[_0xf889('0x43')](_0x4606a2[_0xf889('0x42')],{'$or':_[_0xf889('0x31')](_0x4606a2['attributes'],function(_0x1e87b5){var _0x27fa80={};_0x27fa80[_0x1e87b5]={'$like':'%'+_0x167583[_0xf889('0x36')][_0xf889('0x41')]+'%'};return _0x27fa80;})});}_0x4606a2=_[_0xf889('0x43')]({},_0x4606a2,_0x167583[_0xf889('0x59')]);return _0x529715[_0xf889('0x60')](_0x4606a2);}})[_0xf889('0x28')](function(_0x35112b){if(_0x35112b){_0x3aafea=_0x35112b['length'];if(!_0x167583[_0xf889('0x36')][_0xf889('0x3b')]('nolimit')){_0x4606a2[_0xf889('0x22')]=qs[_0xf889('0x22')](_0x167583['query'][_0xf889('0x22')]);_0x4606a2['offset']=qs[_0xf889('0x20')](_0x167583[_0xf889('0x36')][_0xf889('0x20')]);}return _0x529715[_0xf889('0x60')](_0x4606a2);}})[_0xf889('0x28')](function(_0x1e336a){if(_0x1e336a){return _0x1e336a?{'count':_0x3aafea,'rows':_0x1e336a}:null;}})[_0xf889('0x28')](respondWithResult(_0x58159d,null))[_0xf889('0x4f')](handleError(_0x58159d,null));};exports[_0xf889('0x62')]=function(_0x2e0d50,_0x40e15e,_0x4fb208){var _0x3f3a24=_0x2e0d50[_0xf889('0x51')]['ids'];return db[_0xf889('0x63')][_0xf889('0x47')]({'where':{'id':_0x3f3a24},'attributes':['id'],'include':[{'model':db[_0xf889('0x64')],'as':'Agents','attributes':['id',_0xf889('0x2f'),_0xf889('0x65'),_0xf889('0x66'),_0xf889('0x67')],'raw':!![]}]})[_0xf889('0x28')](function(_0x324a2c){if(_0x324a2c){var _0x36b55d=_[_0xf889('0x68')](_0x324a2c,function(_0x2f9aa8){var _0x502245=_0x2f9aa8['get']({'plain':!![]});return _0x502245[_0xf889('0x69')];});return db[_0xf889('0x32')][_0xf889('0x4e')]({'where':{'id':_0x2e0d50[_0xf889('0x4a')]['id']}})[_0xf889('0x28')](function(_0x45cd18){return db[_0xf889('0x6a')][_0xf889('0x6b')](function(_0x1a9188){return _0x45cd18[_0xf889('0x62')](_0x3f3a24,{'transaction':_0x1a9188})[_0xf889('0x28')](function(){return BPromise[_0xf889('0x6c')](_0x36b55d,function(_0x308255){return db['UserOpenchannelQueue'][_0xf889('0x6d')]({'where':{'UserId':_0x308255['id'],'OpenchannelQueueId':_0x2e0d50[_0xf889('0x4a')]['id']},'transaction':_0x1a9188});});})[_0xf889('0x28')](function(){_0x36b55d[_0xf889('0x6e')](function(_0x1b5bab){socket[_0xf889('0x6f')](_0xf889('0x70'),{'UserId':_0x1b5bab['id'],'OpenchannelQueueId':_0x45cd18['id']});});});});});}})[_0xf889('0x28')](respondWithStatusCode(_0x40e15e,null))[_0xf889('0x4f')](handleError(_0x40e15e,null));};exports[_0xf889('0x71')]=function(_0x15107f,_0x4683bd,_0x1ea582){return db[_0xf889('0x63')][_0xf889('0x47')]({'where':{'id':_0x15107f[_0xf889('0x36')][_0xf889('0x72')]},'attributes':['id'],'include':[{'model':db[_0xf889('0x64')],'as':'Agents','attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x4683bd,null))[_0xf889('0x28')](function(_0x1bdbd8){var _0x222e86=_[_0xf889('0x31')](_0x1bdbd8,'id');var _0x5bc4b2=[];var _0x5c457c=[];var _0x151c6c=squel[_0xf889('0x73')]();_0x151c6c[_0xf889('0x74')](_0xf889('0x75'))[_0xf889('0x76')]('team_has_openchannel_queues','tq')[_0xf889('0x77')]('user_has_teams','ut',_0xf889('0x78'))['where'](_0xf889('0x79'),_0x15107f[_0xf889('0x4a')]['id']);for(var _0x230f25=0x0;_0x230f25<_0x1bdbd8[_0xf889('0x3a')];_0x230f25+=0x1){let _0x2409f4=_0x1bdbd8[_0x230f25];for(var _0x55110c=0x0;_0x55110c<_0x2409f4[_0xf889('0x69')][_0xf889('0x3a')];_0x55110c+=0x1){let _0x1604f2=_0x2409f4[_0xf889('0x69')][_0x55110c];var _0x495a6b=_0x151c6c[_0xf889('0x7a')]();_0x495a6b[_0xf889('0x42')](_0xf889('0x7b'),_0x1604f2['id']);_0x5c457c[_0xf889('0x7c')](db[_0xf889('0x6a')][_0xf889('0x36')](_0x495a6b['toString'](),{'type':db['sequelize'][_0xf889('0x7d')][_0xf889('0x7e')]})[_0xf889('0x28')](function(_0x3b11e2){if(_0x3b11e2[_0xf889('0x3a')]===0x1){return _0x1604f2['id'];}else{var _0x122a2a=_['every'](_[_0xf889('0x31')](_0x3b11e2,'TeamId'),function(_0x1b2b7f){return _[_0xf889('0x7f')](_0x222e86,_0x1b2b7f);});if(_0x122a2a){return _0x1604f2['id'];}}}));}}return BPromise[_0xf889('0x80')](_0x5c457c)[_0xf889('0x28')](function(_0x1dce1a){_0x5bc4b2=_(_0x5bc4b2)[_0xf889('0x81')](_0x1dce1a)['compact']()[_0xf889('0x82')]();return db[_0xf889('0x32')][_0xf889('0x4e')]({'where':{'id':_0x15107f[_0xf889('0x4a')]['id']}})[_0xf889('0x28')](function(_0x4954fa){return db[_0xf889('0x6a')][_0xf889('0x6b')](function(_0x139430){return _0x4954fa[_0xf889('0x71')](_0x15107f[_0xf889('0x36')][_0xf889('0x72')],{'transaction':_0x139430})[_0xf889('0x28')](function(){if(!_[_0xf889('0x83')](_0x5bc4b2)){return _0x4954fa[_0xf889('0x84')](_0x5bc4b2,{'transaction':_0x139430});}})['then'](function(){_0x5bc4b2[_0xf889('0x6e')](function(_0x3db10c){socket[_0xf889('0x6f')](_0xf889('0x85'),{'UserId':_0x3db10c,'OpenchannelQueueId':_0x4954fa['id']});});});});});});})[_0xf889('0x28')](respondWithStatusCode(_0x4683bd,null))['catch'](handleError(_0x4683bd,null));};exports[_0xf889('0x86')]=function(_0x45b402,_0x5be19d,_0x2f18f5){return db[_0xf889('0x32')][_0xf889('0x4e')]({'where':{'id':_0x45b402[_0xf889('0x4a')]['id']}})['then'](handleEntityNotFound(_0x5be19d,null))[_0xf889('0x28')](function(_0x3a007c){if(_0x3a007c){return _0x3a007c[_0xf889('0x86')](_0x45b402[_0xf889('0x51')]['ids'],_[_0xf889('0x87')](_0x45b402[_0xf889('0x51')],[_0xf889('0x72'),'id'])||{})['spread'](function(_0x5db905){for(var _0x489075=0x0;_0x489075<_0x45b402[_0xf889('0x51')]['ids'][_0xf889('0x3a')];_0x489075+=0x1){socket[_0xf889('0x6f')]('userOpenchannelQueue:save',{'UserId':Number(_0x45b402[_0xf889('0x51')][_0xf889('0x72')][_0x489075]),'OpenchannelQueueId':Number(_0x45b402[_0xf889('0x4a')]['id'])});}return _0x5db905;});}})['then'](respondWithResult(_0x5be19d,null))[_0xf889('0x4f')](handleError(_0x5be19d,null));};exports[_0xf889('0x84')]=function(_0x3d8c58,_0x383517,_0x26c521){return db[_0xf889('0x32')]['find']({'where':{'id':_0x3d8c58[_0xf889('0x4a')]['id']}})[_0xf889('0x28')](handleEntityNotFound(_0x383517,null))[_0xf889('0x28')](function(_0x3cfc42){if(_0x3cfc42){return _0x3cfc42[_0xf889('0x84')](_0x3d8c58[_0xf889('0x36')][_0xf889('0x72')])[_0xf889('0x28')](function(){if(_[_0xf889('0x88')](_0x3d8c58[_0xf889('0x36')][_0xf889('0x72')])){for(var _0x5c08fe=0x0;_0x5c08fe<_0x3d8c58[_0xf889('0x36')][_0xf889('0x72')][_0xf889('0x3a')];_0x5c08fe+=0x1){socket[_0xf889('0x6f')](_0xf889('0x85'),{'UserId':Number(_0x3d8c58[_0xf889('0x36')][_0xf889('0x72')][_0x5c08fe]),'OpenchannelQueueId':Number(_0x3d8c58[_0xf889('0x4a')]['id'])});}}else{socket['emit'](_0xf889('0x85'),{'UserId':Number(_0x3d8c58['query'][_0xf889('0x72')]),'OpenchannelQueueId':Number(_0x3d8c58[_0xf889('0x4a')]['id'])});}});}})['then'](respondWithStatusCode(_0x383517,null))['catch'](handleError(_0x383517,null));};exports['getAgents']=function(_0x2d13b8,_0x45998e,_0x3a28fa){var _0x1217b8={};var _0x2d3835={};var _0xb347d2;var _0x3e6b5b;return db[_0xf889('0x32')][_0xf889('0x61')]({'where':{'id':_0x2d13b8[_0xf889('0x4a')]['id']}})[_0xf889('0x28')](handleEntityNotFound(_0x45998e,null))[_0xf889('0x28')](function(_0x4a6bdb){if(_0x4a6bdb){_0xb347d2=_0x4a6bdb;_0x2d3835[_0xf889('0x37')]=_['keys'](db[_0xf889('0x64')][_0xf889('0x4c')]);_0x2d3835['query']=_[_0xf889('0x4b')](_0x2d13b8['query']);_0x2d3835[_0xf889('0x3f')]=_[_0xf889('0x4d')](_0x2d3835['model'],_0x2d3835[_0xf889('0x36')]);_0x1217b8['attributes']=_[_0xf889('0x4d')](_0x2d3835[_0xf889('0x37')],qs['fields'](_0x2d13b8[_0xf889('0x36')][_0xf889('0x38')]));_0x1217b8[_0xf889('0x39')]=_0x1217b8[_0xf889('0x39')][_0xf889('0x3a')]?_0x1217b8[_0xf889('0x39')]:_0x2d3835[_0xf889('0x37')];_0x1217b8['order']=qs[_0xf889('0x3e')](_0x2d13b8['query'][_0xf889('0x3e')]);_0x1217b8[_0xf889('0x42')]=qs[_0xf889('0x3f')](_[_0xf889('0x40')](_0x2d13b8[_0xf889('0x36')],_0x2d3835[_0xf889('0x3f')]));if(_0x2d13b8[_0xf889('0x36')][_0xf889('0x41')]){_0x1217b8[_0xf889('0x42')]=_['merge'](_0x1217b8['where'],{'$or':_[_0xf889('0x31')](_0x1217b8[_0xf889('0x39')],function(_0x1d7733){var _0x3b229d={};_0x3b229d[_0x1d7733]={'$like':'%'+_0x2d13b8['query']['filter']+'%'};return _0x3b229d;})});}_0x1217b8=_[_0xf889('0x43')]({},_0x1217b8,_0x2d13b8['options']);return _0xb347d2[_0xf889('0x89')](_0x1217b8);}})[_0xf889('0x28')](function(_0x57b332){if(_0x57b332){_0x3e6b5b=_0x57b332['length'];if(!_0x2d13b8[_0xf889('0x36')][_0xf889('0x3b')](_0xf889('0x3c'))){_0x1217b8['limit']=qs[_0xf889('0x22')](_0x2d13b8[_0xf889('0x36')][_0xf889('0x22')]);_0x1217b8[_0xf889('0x20')]=qs[_0xf889('0x20')](_0x2d13b8[_0xf889('0x36')][_0xf889('0x20')]);}return _0xb347d2['getAgents'](_0x1217b8);}})[_0xf889('0x28')](function(_0x2979f0){if(_0x2979f0){return _0x2979f0?{'count':_0x3e6b5b,'rows':_0x2979f0}:null;}})[_0xf889('0x28')](respondWithResult(_0x45998e,null))[_0xf889('0x4f')](handleError(_0x45998e,null));};