a14a2a2a97a1a604e529f1f0fff02e75e21a76cc
[motion2.git] / server / api / chatQueue / chatQueue.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 _0xc152=['%s/%s','SIP','createdAt','getTeams','findOne','Team','addTeams','Agents','online','voicePause','interface','flatMap','transaction','forEach','emit','removeTeams','ids','select','field','from','team_has_chat_queues','join','ChatQueueId\x20=\x20?','clone','push','toString','QueryTypes','SELECT','TeamId','includes','all','union','compact','sequelize','isEmpty','removeAgents','userChatQueue:remove','addAgents','omit','spread','userChatQueue:save','isArray','getAgents','bluebird','squel','ioredis','../../config/logger','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','update','then','destroy','get','ChatQueues','UserProfileResource','error','stack','name','send','index','map','ChatQueue','rawAttributes','where','include','query','findAll','rows','catch','params','model','keys','filters','intersection','attributes','fields','length','merge','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','UserChatQueue','hasOwnProperty','nolimit','order','sort','pick','ChatQueueId','filter','User','findAndCountAll','UserId','chatPause','updatedAt','format'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xc152,0x187));var _0x2c15=function(_0x4b6993,_0x4e2252){_0x4b6993=_0x4b6993-0x0;var _0x3679d1=_0xc152[_0x4b6993];return _0x3679d1;};'use strict';var BPromise=require(_0x2c15('0x0'));var util=require('util');var _=require('lodash');var squel=require(_0x2c15('0x1'));var Redis=require(_0x2c15('0x2'));var qs=require('../../components/parsers/qs');var logger=require(_0x2c15('0x3'))('api');var config=require(_0x2c15('0x4'));var db=require(_0x2c15('0x5'))['db'];config['redis']=_[_0x2c15('0x6')](config[_0x2c15('0x7')],{'host':_0x2c15('0x8'),'port':0x18eb});var socket=require(_0x2c15('0x9'))(new Redis(config[_0x2c15('0x7')]));require('./chatQueue.socket')[_0x2c15('0xa')](socket);function respondWithStatusCode(_0x1a30f4,_0x5cf65b){_0x5cf65b=_0x5cf65b||0xcc;return function(_0x29aa74){if(_0x29aa74){return _0x1a30f4[_0x2c15('0xb')](_0x5cf65b);}return _0x1a30f4[_0x2c15('0xc')](_0x5cf65b)[_0x2c15('0xd')]();};}function respondWithResult(_0x1ea989,_0x3a68ba){_0x3a68ba=_0x3a68ba||0xc8;return function(_0xbb9b68){if(_0xbb9b68){return _0x1ea989[_0x2c15('0xc')](_0x3a68ba)[_0x2c15('0xe')](_0xbb9b68);}};}function respondWithFilteredResult(_0x19904d,_0x41c3b6){return function(_0xb06d41){if(_0xb06d41){var _0x597a91=typeof _0x41c3b6[_0x2c15('0xf')]===_0x2c15('0x10')&&typeof _0x41c3b6[_0x2c15('0x11')]===_0x2c15('0x10');var _0x58d5be=_0xb06d41[_0x2c15('0x12')];var _0x34bb73=_0x597a91?0x0:_0x41c3b6['offset'];var _0x3ebe53=_0x597a91?_0xb06d41['count']:_0x41c3b6['offset']+_0x41c3b6[_0x2c15('0x11')];var _0x5488d2;if(_0x3ebe53>=_0x58d5be){_0x3ebe53=_0x58d5be;_0x5488d2=0xc8;}else{_0x5488d2=0xce;}_0x19904d['status'](_0x5488d2);return _0x19904d[_0x2c15('0x13')](_0x2c15('0x14'),_0x34bb73+'-'+_0x3ebe53+'/'+_0x58d5be)['json'](_0xb06d41);}return null;};}function saveUpdates(_0x27a753){return function(_0x342726){if(_0x342726){return _0x342726[_0x2c15('0x15')](_0x27a753)[_0x2c15('0x16')](function(_0x1da2a7){return _0x1da2a7;});}return null;};}function removeEntity(_0x2e1258){return function(_0xaebab1){if(_0xaebab1){return _0xaebab1[_0x2c15('0x17')]()['then'](function(){var _0xc79045=_0xaebab1[_0x2c15('0x18')]({'plain':!![]});var _0x17339e=_0x2c15('0x19');return db[_0x2c15('0x1a')][_0x2c15('0x17')]({'where':{'type':_0x17339e,'resourceId':_0xc79045['id']}})[_0x2c15('0x16')](function(){return _0xaebab1;});})[_0x2c15('0x16')](function(){_0x2e1258[_0x2c15('0xc')](0xcc)[_0x2c15('0xd')]();});}};}function handleEntityNotFound(_0x3f8db6){return function(_0x8cf318){if(!_0x8cf318){_0x3f8db6[_0x2c15('0xb')](0x194);}return _0x8cf318;};}function handleError(_0x6d79d3,_0x5c7892){_0x5c7892=_0x5c7892||0x1f4;return function(_0x513e33){logger[_0x2c15('0x1b')](_0x513e33[_0x2c15('0x1c')]);if(_0x513e33[_0x2c15('0x1d')]){delete _0x513e33[_0x2c15('0x1d')];}_0x6d79d3[_0x2c15('0xc')](_0x5c7892)[_0x2c15('0x1e')](_0x513e33);};}exports[_0x2c15('0x1f')]=function(_0x43f1c7,_0x7cbd27){var _0x3ec325={};var _0xe9ca67={'count':0x0,'rows':[]};var _0x4a169c=_[_0x2c15('0x20')](db[_0x2c15('0x21')][_0x2c15('0x22')],function(_0x549fba){return{'name':_0x549fba['fieldName'],'type':_0x549fba['type']['key']};});_0x3ec325=qs['getOptions'](_0x4a169c,_0x43f1c7);var _0x327e2e={'where':_0x3ec325[_0x2c15('0x23')]};return db['ChatQueue'][_0x2c15('0x12')](_0x327e2e)[_0x2c15('0x16')](function(_0xf28872){_0xe9ca67[_0x2c15('0x12')]=_0xf28872;_0x3ec325[_0x2c15('0x24')]=qs['include'](_0x43f1c7[_0x2c15('0x25')]);return db['ChatQueue'][_0x2c15('0x26')](_0x3ec325);})[_0x2c15('0x16')](function(_0x5b85d6){_0xe9ca67[_0x2c15('0x27')]=_0x5b85d6;return _0xe9ca67;})['then'](respondWithFilteredResult(_0x7cbd27,_0x3ec325))[_0x2c15('0x28')](handleError(_0x7cbd27,null));};exports['show']=function(_0xe58be2,_0x3a39b8){var _0x260872={'raw':!![],'where':{'id':_0xe58be2[_0x2c15('0x29')]['id']}},_0x5a8a1e={};_0x5a8a1e[_0x2c15('0x2a')]=_[_0x2c15('0x2b')](db['ChatQueue']['rawAttributes']);_0x5a8a1e[_0x2c15('0x25')]=_[_0x2c15('0x2b')](_0xe58be2[_0x2c15('0x25')]);_0x5a8a1e[_0x2c15('0x2c')]=_[_0x2c15('0x2d')](_0x5a8a1e[_0x2c15('0x2a')],_0x5a8a1e[_0x2c15('0x25')]);_0x260872[_0x2c15('0x2e')]=_['intersection'](_0x5a8a1e[_0x2c15('0x2a')],qs[_0x2c15('0x2f')](_0xe58be2['query'][_0x2c15('0x2f')]));_0x260872[_0x2c15('0x2e')]=_0x260872[_0x2c15('0x2e')][_0x2c15('0x30')]?_0x260872[_0x2c15('0x2e')]:_0x5a8a1e['model'];if(_0xe58be2[_0x2c15('0x25')]['includeAll']){_0x260872[_0x2c15('0x24')]=[{'all':!![]}];}_0x260872=_[_0x2c15('0x31')]({},_0x260872,_0xe58be2[_0x2c15('0x32')]);return db['ChatQueue'][_0x2c15('0x33')](_0x260872)[_0x2c15('0x16')](handleEntityNotFound(_0x3a39b8,null))[_0x2c15('0x16')](respondWithResult(_0x3a39b8,null))['catch'](handleError(_0x3a39b8,null));};exports[_0x2c15('0x34')]=function(_0x30cd0b,_0x58727b){return db[_0x2c15('0x21')]['create'](_0x30cd0b[_0x2c15('0x35')],{})[_0x2c15('0x16')](function(_0x9cd1bc){var _0x21617c=_0x30cd0b[_0x2c15('0x36')][_0x2c15('0x18')]({'plain':!![]});if(!_0x21617c)throw new Error(_0x2c15('0x37'));if(_0x21617c[_0x2c15('0x38')]==='user'){var _0x8e5e1a=_0x9cd1bc[_0x2c15('0x18')]({'plain':!![]});var _0x4f77f8='ChatQueues';return db['UserProfileSection'][_0x2c15('0x33')]({'where':{'name':_0x4f77f8,'userProfileId':_0x21617c['userProfileId']},'raw':!![]})[_0x2c15('0x16')](function(_0x4a9958){if(_0x4a9958&&_0x4a9958['autoAssociation']===0x0){return db[_0x2c15('0x1a')][_0x2c15('0x34')]({'name':_0x8e5e1a['name'],'resourceId':_0x8e5e1a['id'],'type':_0x4a9958['name'],'sectionId':_0x4a9958['id']},{})[_0x2c15('0x16')](function(){return _0x9cd1bc;});}else{return _0x9cd1bc;}})['catch'](function(_0x9f4c40){logger['error'](_0x2c15('0x39'),_0x9f4c40);throw _0x9f4c40;});}return _0x9cd1bc;})['then'](respondWithResult(_0x58727b,0xc9))[_0x2c15('0x28')](handleError(_0x58727b,null));};exports[_0x2c15('0x15')]=function(_0x4146d7,_0x55a8e9){if(_0x4146d7[_0x2c15('0x35')]['id']){delete _0x4146d7[_0x2c15('0x35')]['id'];}return db[_0x2c15('0x21')][_0x2c15('0x33')]({'where':{'id':_0x4146d7[_0x2c15('0x29')]['id']}})[_0x2c15('0x16')](handleEntityNotFound(_0x55a8e9,null))['then'](saveUpdates(_0x4146d7[_0x2c15('0x35')],null))[_0x2c15('0x16')](respondWithResult(_0x55a8e9,null))[_0x2c15('0x28')](handleError(_0x55a8e9,null));};exports[_0x2c15('0x17')]=function(_0x28c4e3,_0x4dc2fe){return db[_0x2c15('0x21')][_0x2c15('0x33')]({'where':{'id':_0x28c4e3[_0x2c15('0x29')]['id']}})[_0x2c15('0x16')](handleEntityNotFound(_0x4dc2fe,null))['then'](removeEntity(_0x4dc2fe,null))['catch'](handleError(_0x4dc2fe,null));};exports[_0x2c15('0x3a')]=function(_0x690a90,_0x39639a){return db[_0x2c15('0x21')][_0x2c15('0x3a')]()['then'](respondWithResult(_0x39639a,null))[_0x2c15('0x28')](handleError(_0x39639a,null));};exports['getMembers']=function(_0x1a58a8,_0x25825a){var _0xb8a8d2={'raw':!![],'where':{}},_0x59a6fb={},_0x38e8f8;return db[_0x2c15('0x21')]['findOne']({'where':{'id':_0x1a58a8[_0x2c15('0x29')]['id']}})[_0x2c15('0x16')](handleEntityNotFound(_0x25825a,null))[_0x2c15('0x16')](function(_0x487eac){if(_0x487eac){_0x38e8f8=_0x487eac['get']({'plain':!![]});_0x59a6fb[_0x2c15('0x2a')]=_[_0x2c15('0x2b')](db[_0x2c15('0x3b')][_0x2c15('0x22')]);_0x59a6fb[_0x2c15('0x25')]=_[_0x2c15('0x2b')](_0x1a58a8['query']);_0x59a6fb['filters']=_[_0x2c15('0x2d')](_0x59a6fb[_0x2c15('0x2a')],_0x59a6fb[_0x2c15('0x25')]);_0xb8a8d2[_0x2c15('0x2e')]=_[_0x2c15('0x2d')](_0x59a6fb['model'],qs[_0x2c15('0x2f')](_0x1a58a8[_0x2c15('0x25')][_0x2c15('0x2f')]));_0xb8a8d2[_0x2c15('0x2e')]=_0xb8a8d2[_0x2c15('0x2e')]['length']?_0xb8a8d2[_0x2c15('0x2e')]:_0x59a6fb[_0x2c15('0x2a')];if(!_0x1a58a8[_0x2c15('0x25')][_0x2c15('0x3c')](_0x2c15('0x3d'))){_0xb8a8d2[_0x2c15('0x11')]=qs['limit'](_0x1a58a8[_0x2c15('0x25')][_0x2c15('0x11')]);_0xb8a8d2['offset']=qs[_0x2c15('0xf')](_0x1a58a8[_0x2c15('0x25')]['offset']);}_0xb8a8d2[_0x2c15('0x3e')]=qs[_0x2c15('0x3f')](_0x1a58a8[_0x2c15('0x25')][_0x2c15('0x3f')]);_0xb8a8d2[_0x2c15('0x23')]=qs['filters'](_[_0x2c15('0x40')](_0x1a58a8[_0x2c15('0x25')],_0x59a6fb[_0x2c15('0x2c')]));_0xb8a8d2[_0x2c15('0x23')][_0x2c15('0x41')]=_0x487eac['id'];if(_0x1a58a8['query'][_0x2c15('0x42')]){_0xb8a8d2[_0x2c15('0x23')]=_[_0x2c15('0x31')](_0xb8a8d2[_0x2c15('0x23')],{'$or':_[_0x2c15('0x20')](_0xb8a8d2[_0x2c15('0x2e')],function(_0x3ab00b){var _0x1782e9={};_0x1782e9[_0x3ab00b]={'$like':'%'+_0x1a58a8['query'][_0x2c15('0x42')]+'%'};return _0x1782e9;})});}_0xb8a8d2=_[_0x2c15('0x31')]({},_0xb8a8d2,_0x1a58a8[_0x2c15('0x32')]);return db[_0x2c15('0x3b')]['findAll'](_0xb8a8d2);}})[_0x2c15('0x16')](function(_0x49d34f){if(_0x49d34f){return db[_0x2c15('0x43')][_0x2c15('0x44')]({'where':{'id':_['map'](_0x49d34f,_0x2c15('0x45')),'role':'agent'},'attributes':['id',_0x2c15('0x1d'),_0x2c15('0x46'),_0x2c15('0x47'),'createdAt']});}})[_0x2c15('0x16')](function(_0x417d62){if(_0x417d62){return{'count':_0x417d62[_0x2c15('0x12')],'rows':_['map'](_0x417d62['rows'],function(_0x238cd0){return{'membername':_0x238cd0[_0x2c15('0x1d')],'UserId':_0x238cd0['id'],'queue_name':_0x38e8f8[_0x2c15('0x1d')],'ChatQueueId':_0x38e8f8['id'],'interface':util[_0x2c15('0x48')](_0x2c15('0x49'),_0x2c15('0x4a'),_0x238cd0[_0x2c15('0x1d')]),'penalty':0x0,'paused':_0x238cd0[_0x2c15('0x46')],'createdAt':_0x238cd0[_0x2c15('0x4b')],'updatedAt':_0x238cd0[_0x2c15('0x47')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x2c15('0x16')](respondWithFilteredResult(_0x25825a,_0xb8a8d2))[_0x2c15('0x28')](handleError(_0x25825a,null));};exports[_0x2c15('0x4c')]=function(_0x3cece5,_0x4e7655){var _0xf6354e={};var _0x5eb3b7={};var _0x3e693a;var _0x29429b;return db[_0x2c15('0x21')][_0x2c15('0x4d')]({'where':{'id':_0x3cece5[_0x2c15('0x29')]['id']}})[_0x2c15('0x16')](handleEntityNotFound(_0x4e7655,null))[_0x2c15('0x16')](function(_0x22373d){if(_0x22373d){_0x3e693a=_0x22373d;_0x5eb3b7[_0x2c15('0x2a')]=_[_0x2c15('0x2b')](db[_0x2c15('0x4e')]['rawAttributes']);_0x5eb3b7[_0x2c15('0x25')]=_['keys'](_0x3cece5['query']);_0x5eb3b7[_0x2c15('0x2c')]=_['intersection'](_0x5eb3b7[_0x2c15('0x2a')],_0x5eb3b7[_0x2c15('0x25')]);_0xf6354e['attributes']=_['intersection'](_0x5eb3b7[_0x2c15('0x2a')],qs[_0x2c15('0x2f')](_0x3cece5[_0x2c15('0x25')][_0x2c15('0x2f')]));_0xf6354e[_0x2c15('0x2e')]=_0xf6354e[_0x2c15('0x2e')][_0x2c15('0x30')]?_0xf6354e[_0x2c15('0x2e')]:_0x5eb3b7[_0x2c15('0x2a')];_0xf6354e[_0x2c15('0x3e')]=qs[_0x2c15('0x3f')](_0x3cece5['query'][_0x2c15('0x3f')]);_0xf6354e[_0x2c15('0x23')]=qs['filters'](_['pick'](_0x3cece5['query'],_0x5eb3b7['filters']));if(_0x3cece5[_0x2c15('0x25')][_0x2c15('0x42')]){_0xf6354e[_0x2c15('0x23')]=_[_0x2c15('0x31')](_0xf6354e[_0x2c15('0x23')],{'$or':_['map'](_0xf6354e[_0x2c15('0x2e')],function(_0x6a45d){var _0x30e843={};_0x30e843[_0x6a45d]={'$like':'%'+_0x3cece5[_0x2c15('0x25')][_0x2c15('0x42')]+'%'};return _0x30e843;})});}_0xf6354e=_[_0x2c15('0x31')]({},_0xf6354e,_0x3cece5[_0x2c15('0x32')]);return _0x3e693a['getTeams'](_0xf6354e);}})['then'](function(_0x2d5683){if(_0x2d5683){_0x29429b=_0x2d5683[_0x2c15('0x30')];if(!_0x3cece5[_0x2c15('0x25')][_0x2c15('0x3c')](_0x2c15('0x3d'))){_0xf6354e['limit']=qs[_0x2c15('0x11')](_0x3cece5[_0x2c15('0x25')][_0x2c15('0x11')]);_0xf6354e[_0x2c15('0xf')]=qs['offset'](_0x3cece5[_0x2c15('0x25')][_0x2c15('0xf')]);}return _0x3e693a[_0x2c15('0x4c')](_0xf6354e);}})[_0x2c15('0x16')](function(_0x10a253){if(_0x10a253){return _0x10a253?{'count':_0x29429b,'rows':_0x10a253}:null;}})[_0x2c15('0x16')](respondWithResult(_0x4e7655,null))[_0x2c15('0x28')](handleError(_0x4e7655,null));};exports[_0x2c15('0x4f')]=function(_0x4559b4,_0x253c11){var _0x12910f=_0x4559b4[_0x2c15('0x35')]['ids'];return db[_0x2c15('0x4e')][_0x2c15('0x26')]({'where':{'id':_0x12910f},'attributes':['id'],'include':[{'model':db[_0x2c15('0x43')],'as':_0x2c15('0x50'),'attributes':['id','name',_0x2c15('0x51'),_0x2c15('0x52'),_0x2c15('0x53')],'raw':!![]}]})[_0x2c15('0x16')](function(_0x6b5b34){if(_0x6b5b34){var _0x247ee9=_[_0x2c15('0x54')](_0x6b5b34,function(_0xe6e34e){var _0x54b1bd=_0xe6e34e[_0x2c15('0x18')]({'plain':!![]});return _0x54b1bd[_0x2c15('0x50')];});return db[_0x2c15('0x21')][_0x2c15('0x33')]({'where':{'id':_0x4559b4['params']['id']}})[_0x2c15('0x16')](function(_0x172895){return db['sequelize'][_0x2c15('0x55')](function(_0xc15f5d){return _0x172895['addTeams'](_0x12910f,{'transaction':_0xc15f5d})[_0x2c15('0x16')](function(){return BPromise['each'](_0x247ee9,function(_0x510559){return db['UserChatQueue']['findOrCreate']({'where':{'UserId':_0x510559['id'],'ChatQueueId':_0x4559b4[_0x2c15('0x29')]['id']},'transaction':_0xc15f5d});});})[_0x2c15('0x16')](function(){_0x247ee9[_0x2c15('0x56')](function(_0x4a3e08){socket[_0x2c15('0x57')]('userChatQueue:save',{'UserId':_0x4a3e08['id'],'ChatQueueId':_0x172895['id']});});});});});}})['then'](respondWithStatusCode(_0x253c11,null))['catch'](handleError(_0x253c11,null));};exports[_0x2c15('0x58')]=function(_0x43a1a4,_0x28a6b2){return db[_0x2c15('0x4e')][_0x2c15('0x26')]({'where':{'id':_0x43a1a4['query'][_0x2c15('0x59')]},'attributes':['id'],'include':[{'model':db[_0x2c15('0x43')],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0x2c15('0x16')](handleEntityNotFound(_0x28a6b2,null))[_0x2c15('0x16')](function(_0x1c3147){var _0x296145=_[_0x2c15('0x20')](_0x1c3147,'id');var _0x5d0cde=[];var _0x52c6f4=[];var _0xf49b11=squel[_0x2c15('0x5a')]();_0xf49b11[_0x2c15('0x5b')]('tq.TeamId')[_0x2c15('0x5c')](_0x2c15('0x5d'),'tq')[_0x2c15('0x5e')]('user_has_teams','ut','ut.TeamId\x20=\x20tq.TeamId')['where'](_0x2c15('0x5f'),_0x43a1a4[_0x2c15('0x29')]['id']);for(var _0x3edaa4=0x0;_0x3edaa4<_0x1c3147['length'];_0x3edaa4+=0x1){let _0x1409a4=_0x1c3147[_0x3edaa4];for(var _0x18460f=0x0;_0x18460f<_0x1409a4[_0x2c15('0x50')][_0x2c15('0x30')];_0x18460f+=0x1){let _0x39fb31=_0x1409a4[_0x2c15('0x50')][_0x18460f];var _0x3ca30c=_0xf49b11[_0x2c15('0x60')]();_0x3ca30c[_0x2c15('0x23')]('ut.UserId\x20=\x20?',_0x39fb31['id']);_0x52c6f4[_0x2c15('0x61')](db['sequelize'][_0x2c15('0x25')](_0x3ca30c[_0x2c15('0x62')](),{'type':db['sequelize'][_0x2c15('0x63')][_0x2c15('0x64')]})[_0x2c15('0x16')](function(_0x2a5b7f){if(_0x2a5b7f['length']===0x1){return _0x39fb31['id'];}else{var _0x87e9e8=_['every'](_['map'](_0x2a5b7f,_0x2c15('0x65')),function(_0x9a9c0b){return _[_0x2c15('0x66')](_0x296145,_0x9a9c0b);});if(_0x87e9e8){return _0x39fb31['id'];}}}));}}return BPromise[_0x2c15('0x67')](_0x52c6f4)[_0x2c15('0x16')](function(_0x49ee50){_0x5d0cde=_(_0x5d0cde)[_0x2c15('0x68')](_0x49ee50)[_0x2c15('0x69')]()['value']();return db[_0x2c15('0x21')][_0x2c15('0x33')]({'where':{'id':_0x43a1a4['params']['id']}})[_0x2c15('0x16')](function(_0x3eac12){return db[_0x2c15('0x6a')][_0x2c15('0x55')](function(_0x480844){return _0x3eac12['removeTeams'](_0x43a1a4[_0x2c15('0x25')][_0x2c15('0x59')],{'transaction':_0x480844})[_0x2c15('0x16')](function(){if(!_[_0x2c15('0x6b')](_0x5d0cde)){return _0x3eac12[_0x2c15('0x6c')](_0x5d0cde,{'transaction':_0x480844});}})[_0x2c15('0x16')](function(){_0x5d0cde['forEach'](function(_0x34aaa1){socket[_0x2c15('0x57')](_0x2c15('0x6d'),{'UserId':_0x34aaa1,'ChatQueueId':_0x3eac12['id']});});});});});});})[_0x2c15('0x16')](respondWithStatusCode(_0x28a6b2,null))['catch'](handleError(_0x28a6b2,null));};exports['addAgents']=function(_0x2ebb9c,_0x1ab350){return db[_0x2c15('0x21')][_0x2c15('0x33')]({'where':{'id':_0x2ebb9c[_0x2c15('0x29')]['id']}})[_0x2c15('0x16')](handleEntityNotFound(_0x1ab350,null))['then'](function(_0x2b1354){if(_0x2b1354){return _0x2b1354[_0x2c15('0x6e')](_0x2ebb9c[_0x2c15('0x35')]['ids'],_[_0x2c15('0x6f')](_0x2ebb9c['body'],[_0x2c15('0x59'),'id'])||{})[_0x2c15('0x70')](function(_0x365183){for(var _0xd4300f=0x0;_0xd4300f<_0x2ebb9c['body'][_0x2c15('0x59')][_0x2c15('0x30')];_0xd4300f+=0x1){socket[_0x2c15('0x57')](_0x2c15('0x71'),{'UserId':Number(_0x2ebb9c[_0x2c15('0x35')]['ids'][_0xd4300f]),'ChatQueueId':Number(_0x2ebb9c[_0x2c15('0x29')]['id'])});}return _0x365183;});}})[_0x2c15('0x16')](respondWithResult(_0x1ab350,null))[_0x2c15('0x28')](handleError(_0x1ab350,null));};exports[_0x2c15('0x6c')]=function(_0x1314df,_0x39a3dc){return db['ChatQueue'][_0x2c15('0x33')]({'where':{'id':_0x1314df['params']['id']}})['then'](handleEntityNotFound(_0x39a3dc,null))[_0x2c15('0x16')](function(_0x28ff12){if(_0x28ff12){return _0x28ff12[_0x2c15('0x6c')](_0x1314df[_0x2c15('0x25')][_0x2c15('0x59')])[_0x2c15('0x16')](function(){if(_[_0x2c15('0x72')](_0x1314df[_0x2c15('0x25')][_0x2c15('0x59')])){for(var _0x47f059=0x0;_0x47f059<_0x1314df[_0x2c15('0x25')][_0x2c15('0x59')]['length'];_0x47f059+=0x1){socket[_0x2c15('0x57')]('userChatQueue:remove',{'UserId':Number(_0x1314df[_0x2c15('0x25')][_0x2c15('0x59')][_0x47f059]),'ChatQueueId':Number(_0x1314df[_0x2c15('0x29')]['id'])});}}else{socket['emit'](_0x2c15('0x6d'),{'UserId':Number(_0x1314df[_0x2c15('0x25')]['ids']),'ChatQueueId':Number(_0x1314df[_0x2c15('0x29')]['id'])});}});}})[_0x2c15('0x16')](respondWithStatusCode(_0x39a3dc,null))[_0x2c15('0x28')](handleError(_0x39a3dc,null));};exports[_0x2c15('0x73')]=function(_0x864b7b,_0x15265d){var _0x35d894={};var _0x26981a={};var _0x1d2a7c;var _0x55ea01;return db[_0x2c15('0x21')][_0x2c15('0x4d')]({'where':{'id':_0x864b7b[_0x2c15('0x29')]['id']}})['then'](handleEntityNotFound(_0x15265d,null))[_0x2c15('0x16')](function(_0x51d069){if(_0x51d069){_0x1d2a7c=_0x51d069;_0x26981a['model']=_[_0x2c15('0x2b')](db[_0x2c15('0x43')][_0x2c15('0x22')]);_0x26981a[_0x2c15('0x25')]=_[_0x2c15('0x2b')](_0x864b7b[_0x2c15('0x25')]);_0x26981a[_0x2c15('0x2c')]=_[_0x2c15('0x2d')](_0x26981a[_0x2c15('0x2a')],_0x26981a[_0x2c15('0x25')]);_0x35d894[_0x2c15('0x2e')]=_[_0x2c15('0x2d')](_0x26981a[_0x2c15('0x2a')],qs[_0x2c15('0x2f')](_0x864b7b[_0x2c15('0x25')][_0x2c15('0x2f')]));_0x35d894[_0x2c15('0x2e')]=_0x35d894[_0x2c15('0x2e')]['length']?_0x35d894[_0x2c15('0x2e')]:_0x26981a['model'];_0x35d894[_0x2c15('0x3e')]=qs[_0x2c15('0x3f')](_0x864b7b[_0x2c15('0x25')][_0x2c15('0x3f')]);_0x35d894[_0x2c15('0x23')]=qs[_0x2c15('0x2c')](_[_0x2c15('0x40')](_0x864b7b[_0x2c15('0x25')],_0x26981a[_0x2c15('0x2c')]));if(_0x864b7b[_0x2c15('0x25')][_0x2c15('0x42')]){_0x35d894[_0x2c15('0x23')]=_[_0x2c15('0x31')](_0x35d894[_0x2c15('0x23')],{'$or':_[_0x2c15('0x20')](_0x35d894['attributes'],function(_0x1fae34){var _0x10332f={};_0x10332f[_0x1fae34]={'$like':'%'+_0x864b7b[_0x2c15('0x25')][_0x2c15('0x42')]+'%'};return _0x10332f;})});}_0x35d894=_[_0x2c15('0x31')]({},_0x35d894,_0x864b7b[_0x2c15('0x32')]);return _0x1d2a7c[_0x2c15('0x73')](_0x35d894);}})['then'](function(_0x2bb79c){if(_0x2bb79c){_0x55ea01=_0x2bb79c[_0x2c15('0x30')];if(!_0x864b7b[_0x2c15('0x25')][_0x2c15('0x3c')](_0x2c15('0x3d'))){_0x35d894['limit']=qs[_0x2c15('0x11')](_0x864b7b[_0x2c15('0x25')][_0x2c15('0x11')]);_0x35d894[_0x2c15('0xf')]=qs[_0x2c15('0xf')](_0x864b7b[_0x2c15('0x25')][_0x2c15('0xf')]);}return _0x1d2a7c[_0x2c15('0x73')](_0x35d894);}})[_0x2c15('0x16')](function(_0x4a4e02){if(_0x4a4e02){return _0x4a4e02?{'count':_0x55ea01,'rows':_0x4a4e02}:null;}})[_0x2c15('0x16')](respondWithResult(_0x15265d,null))[_0x2c15('0x28')](handleError(_0x15265d,null));};