ba5068a787e488b83ae683c5246c1d08ed06eb44
[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 _0xbcd1=['Agents','online','interface','flatMap','sequelize','each','findOrCreate','emit','userChatQueue:save','removeTeams','select','field','team_has_chat_queues','ut.TeamId\x20=\x20tq.TeamId','clone','push','toString','SELECT','every','TeamId','includes','all','transaction','isEmpty','removeAgents','forEach','userChatQueue:remove','addAgents','omit','spread','isArray','getAgents','bluebird','util','squel','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment','defaults','redis','localhost','socket.io-emitter','register','sendStatus','status','end','json','undefined','limit','count','offset','set','Content-Range','update','then','ChatQueues','destroy','error','name','send','index','ChatQueue','rawAttributes','fieldName','type','where','include','query','findAll','rows','catch','show','params','model','keys','filters','intersection','attributes','fields','length','includeAll','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','get','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','findOne','UserChatQueue','hasOwnProperty','order','sort','ChatQueueId','filter','merge','map','User','findAndCountAll','UserId','agent','chatPause','createdAt','format','%s/%s','SIP','updatedAt','Team','pick','getTeams','addTeams','ids'];(function(_0x4ca00e,_0x554842){var _0x2c9cb1=function(_0x1cc376){while(--_0x1cc376){_0x4ca00e['push'](_0x4ca00e['shift']());}};_0x2c9cb1(++_0x554842);}(_0xbcd1,0x110));var _0x1bcd=function(_0x5991d7,_0x3ca7f8){_0x5991d7=_0x5991d7-0x0;var _0x5b299d=_0xbcd1[_0x5991d7];return _0x5b299d;};'use strict';var BPromise=require(_0x1bcd('0x0'));var util=require(_0x1bcd('0x1'));var _=require('lodash');var squel=require(_0x1bcd('0x2'));var Redis=require(_0x1bcd('0x3'));var qs=require(_0x1bcd('0x4'));var logger=require(_0x1bcd('0x5'))(_0x1bcd('0x6'));var config=require(_0x1bcd('0x7'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x1bcd('0x8')](config[_0x1bcd('0x9')],{'host':_0x1bcd('0xa'),'port':0x18eb});var socket=require(_0x1bcd('0xb'))(new Redis(config['redis']));require('./chatQueue.socket')[_0x1bcd('0xc')](socket);function respondWithStatusCode(_0x24c715,_0x17e7e3){_0x17e7e3=_0x17e7e3||0xcc;return function(_0x251ea0){if(_0x251ea0){return _0x24c715[_0x1bcd('0xd')](_0x17e7e3);}return _0x24c715[_0x1bcd('0xe')](_0x17e7e3)[_0x1bcd('0xf')]();};}function respondWithResult(_0xd28ec6,_0x5b2ffe){_0x5b2ffe=_0x5b2ffe||0xc8;return function(_0x3dccc5){if(_0x3dccc5){return _0xd28ec6[_0x1bcd('0xe')](_0x5b2ffe)[_0x1bcd('0x10')](_0x3dccc5);}};}function respondWithFilteredResult(_0x592e5f,_0xadc1f7){return function(_0x41b30f){if(_0x41b30f){var _0x4a3d45=typeof _0xadc1f7['offset']===_0x1bcd('0x11')&&typeof _0xadc1f7[_0x1bcd('0x12')]===_0x1bcd('0x11');var _0x533a96=_0x41b30f[_0x1bcd('0x13')];var _0x2107e5=_0x4a3d45?0x0:_0xadc1f7[_0x1bcd('0x14')];var _0x333b1b=_0x4a3d45?_0x41b30f[_0x1bcd('0x13')]:_0xadc1f7[_0x1bcd('0x14')]+_0xadc1f7['limit'];var _0x166349;if(_0x333b1b>=_0x533a96){_0x333b1b=_0x533a96;_0x166349=0xc8;}else{_0x166349=0xce;}_0x592e5f[_0x1bcd('0xe')](_0x166349);return _0x592e5f[_0x1bcd('0x15')](_0x1bcd('0x16'),_0x2107e5+'-'+_0x333b1b+'/'+_0x533a96)[_0x1bcd('0x10')](_0x41b30f);}return null;};}function saveUpdates(_0x32c222){return function(_0x19cb7d){if(_0x19cb7d){return _0x19cb7d[_0x1bcd('0x17')](_0x32c222)[_0x1bcd('0x18')](function(_0x251adc){return _0x251adc;});}return null;};}function removeEntity(_0x88a497){return function(_0x10f845){if(_0x10f845){return _0x10f845['destroy']()[_0x1bcd('0x18')](function(){var _0x9005f3=_0x10f845['get']({'plain':!![]});var _0x1c9a18=_0x1bcd('0x19');return db['UserProfileResource'][_0x1bcd('0x1a')]({'where':{'type':_0x1c9a18,'resourceId':_0x9005f3['id']}})['then'](function(){return _0x10f845;});})['then'](function(){_0x88a497[_0x1bcd('0xe')](0xcc)['end']();});}};}function handleEntityNotFound(_0x36e361){return function(_0x986650){if(!_0x986650){_0x36e361['sendStatus'](0x194);}return _0x986650;};}function handleError(_0x5ce437,_0x1c412f){_0x1c412f=_0x1c412f||0x1f4;return function(_0x2a177d){logger[_0x1bcd('0x1b')](_0x2a177d['stack']);if(_0x2a177d[_0x1bcd('0x1c')]){delete _0x2a177d[_0x1bcd('0x1c')];}_0x5ce437[_0x1bcd('0xe')](_0x1c412f)[_0x1bcd('0x1d')](_0x2a177d);};}exports[_0x1bcd('0x1e')]=function(_0x3977c5,_0x1e693d){var _0x586907={};var _0x1c7e69={'count':0x0,'rows':[]};var _0x3e9939=_['map'](db[_0x1bcd('0x1f')][_0x1bcd('0x20')],function(_0x4468e4){return{'name':_0x4468e4[_0x1bcd('0x21')],'type':_0x4468e4[_0x1bcd('0x22')]['key']};});_0x586907=qs['getOptions'](_0x3e9939,_0x3977c5);var _0x383a0b={'where':_0x586907[_0x1bcd('0x23')]};return db[_0x1bcd('0x1f')][_0x1bcd('0x13')](_0x383a0b)[_0x1bcd('0x18')](function(_0x455466){_0x1c7e69[_0x1bcd('0x13')]=_0x455466;_0x586907[_0x1bcd('0x24')]=qs['include'](_0x3977c5[_0x1bcd('0x25')]);return db[_0x1bcd('0x1f')][_0x1bcd('0x26')](_0x586907);})['then'](function(_0x39cf69){_0x1c7e69[_0x1bcd('0x27')]=_0x39cf69;return _0x1c7e69;})['then'](respondWithFilteredResult(_0x1e693d,_0x586907))[_0x1bcd('0x28')](handleError(_0x1e693d,null));};exports[_0x1bcd('0x29')]=function(_0x4d9d0e,_0x4bcc94){var _0x500d93={'raw':!![],'where':{'id':_0x4d9d0e[_0x1bcd('0x2a')]['id']}},_0x45e7d2={};_0x45e7d2[_0x1bcd('0x2b')]=_['keys'](db['ChatQueue'][_0x1bcd('0x20')]);_0x45e7d2[_0x1bcd('0x25')]=_[_0x1bcd('0x2c')](_0x4d9d0e['query']);_0x45e7d2[_0x1bcd('0x2d')]=_[_0x1bcd('0x2e')](_0x45e7d2[_0x1bcd('0x2b')],_0x45e7d2[_0x1bcd('0x25')]);_0x500d93[_0x1bcd('0x2f')]=_[_0x1bcd('0x2e')](_0x45e7d2[_0x1bcd('0x2b')],qs[_0x1bcd('0x30')](_0x4d9d0e[_0x1bcd('0x25')][_0x1bcd('0x30')]));_0x500d93[_0x1bcd('0x2f')]=_0x500d93['attributes'][_0x1bcd('0x31')]?_0x500d93[_0x1bcd('0x2f')]:_0x45e7d2[_0x1bcd('0x2b')];if(_0x4d9d0e['query'][_0x1bcd('0x32')]){_0x500d93[_0x1bcd('0x24')]=[{'all':!![]}];}_0x500d93=_['merge']({},_0x500d93,_0x4d9d0e[_0x1bcd('0x33')]);return db['ChatQueue'][_0x1bcd('0x34')](_0x500d93)[_0x1bcd('0x18')](handleEntityNotFound(_0x4bcc94,null))['then'](respondWithResult(_0x4bcc94,null))['catch'](handleError(_0x4bcc94,null));};exports[_0x1bcd('0x35')]=function(_0x1b9307,_0x3809a2){return db[_0x1bcd('0x1f')]['create'](_0x1b9307[_0x1bcd('0x36')],{})['then'](function(_0x288bb3){var _0x498937=_0x1b9307[_0x1bcd('0x37')]['get']({'plain':!![]});if(!_0x498937)throw new Error(_0x1bcd('0x38'));if(_0x498937[_0x1bcd('0x39')]===_0x1bcd('0x37')){var _0x35f658=_0x288bb3[_0x1bcd('0x3a')]({'plain':!![]});var _0x1419b1=_0x1bcd('0x19');return db['UserProfileSection'][_0x1bcd('0x34')]({'where':{'name':_0x1419b1,'userProfileId':_0x498937[_0x1bcd('0x3b')]},'raw':!![]})[_0x1bcd('0x18')](function(_0x197251){if(_0x197251&&_0x197251[_0x1bcd('0x3c')]===0x0){return db[_0x1bcd('0x3d')]['create']({'name':_0x35f658[_0x1bcd('0x1c')],'resourceId':_0x35f658['id'],'type':_0x197251[_0x1bcd('0x1c')],'sectionId':_0x197251['id']},{})[_0x1bcd('0x18')](function(){return _0x288bb3;});}else{return _0x288bb3;}})['catch'](function(_0x17c062){logger[_0x1bcd('0x1b')](_0x1bcd('0x3e'),_0x17c062);throw _0x17c062;});}return _0x288bb3;})[_0x1bcd('0x18')](respondWithResult(_0x3809a2,0xc9))[_0x1bcd('0x28')](handleError(_0x3809a2,null));};exports['update']=function(_0x46bd5f,_0xb2f4be){if(_0x46bd5f[_0x1bcd('0x36')]['id']){delete _0x46bd5f[_0x1bcd('0x36')]['id'];}return db[_0x1bcd('0x1f')]['find']({'where':{'id':_0x46bd5f[_0x1bcd('0x2a')]['id']}})[_0x1bcd('0x18')](handleEntityNotFound(_0xb2f4be,null))[_0x1bcd('0x18')](saveUpdates(_0x46bd5f[_0x1bcd('0x36')],null))[_0x1bcd('0x18')](respondWithResult(_0xb2f4be,null))[_0x1bcd('0x28')](handleError(_0xb2f4be,null));};exports['destroy']=function(_0xcb5f,_0x213b4e){return db[_0x1bcd('0x1f')][_0x1bcd('0x34')]({'where':{'id':_0xcb5f[_0x1bcd('0x2a')]['id']}})[_0x1bcd('0x18')](handleEntityNotFound(_0x213b4e,null))['then'](removeEntity(_0x213b4e,null))[_0x1bcd('0x28')](handleError(_0x213b4e,null));};exports['describe']=function(_0x43d425,_0x211435){return db[_0x1bcd('0x1f')][_0x1bcd('0x3f')]()['then'](respondWithResult(_0x211435,null))['catch'](handleError(_0x211435,null));};exports['getMembers']=function(_0x52e110,_0x4ede57){var _0x26d389={'raw':!![],'where':{}},_0x2fd9ed={},_0x21ed02;return db[_0x1bcd('0x1f')][_0x1bcd('0x40')]({'where':{'id':_0x52e110[_0x1bcd('0x2a')]['id']}})[_0x1bcd('0x18')](handleEntityNotFound(_0x4ede57,null))['then'](function(_0x43c9e6){if(_0x43c9e6){_0x21ed02=_0x43c9e6[_0x1bcd('0x3a')]({'plain':!![]});_0x2fd9ed[_0x1bcd('0x2b')]=_[_0x1bcd('0x2c')](db[_0x1bcd('0x41')][_0x1bcd('0x20')]);_0x2fd9ed[_0x1bcd('0x25')]=_['keys'](_0x52e110[_0x1bcd('0x25')]);_0x2fd9ed['filters']=_[_0x1bcd('0x2e')](_0x2fd9ed[_0x1bcd('0x2b')],_0x2fd9ed[_0x1bcd('0x25')]);_0x26d389['attributes']=_[_0x1bcd('0x2e')](_0x2fd9ed[_0x1bcd('0x2b')],qs[_0x1bcd('0x30')](_0x52e110[_0x1bcd('0x25')][_0x1bcd('0x30')]));_0x26d389[_0x1bcd('0x2f')]=_0x26d389[_0x1bcd('0x2f')][_0x1bcd('0x31')]?_0x26d389['attributes']:_0x2fd9ed[_0x1bcd('0x2b')];if(!_0x52e110[_0x1bcd('0x25')][_0x1bcd('0x42')]('nolimit')){_0x26d389['limit']=qs[_0x1bcd('0x12')](_0x52e110[_0x1bcd('0x25')][_0x1bcd('0x12')]);_0x26d389[_0x1bcd('0x14')]=qs[_0x1bcd('0x14')](_0x52e110['query'][_0x1bcd('0x14')]);}_0x26d389[_0x1bcd('0x43')]=qs[_0x1bcd('0x44')](_0x52e110[_0x1bcd('0x25')][_0x1bcd('0x44')]);_0x26d389[_0x1bcd('0x23')]=qs[_0x1bcd('0x2d')](_['pick'](_0x52e110[_0x1bcd('0x25')],_0x2fd9ed[_0x1bcd('0x2d')]));_0x26d389[_0x1bcd('0x23')][_0x1bcd('0x45')]=_0x43c9e6['id'];if(_0x52e110[_0x1bcd('0x25')][_0x1bcd('0x46')]){_0x26d389[_0x1bcd('0x23')]=_[_0x1bcd('0x47')](_0x26d389['where'],{'$or':_[_0x1bcd('0x48')](_0x26d389['attributes'],function(_0x219d22){var _0x314c44={};_0x314c44[_0x219d22]={'$like':'%'+_0x52e110[_0x1bcd('0x25')][_0x1bcd('0x46')]+'%'};return _0x314c44;})});}_0x26d389=_['merge']({},_0x26d389,_0x52e110[_0x1bcd('0x33')]);return db[_0x1bcd('0x41')][_0x1bcd('0x26')](_0x26d389);}})[_0x1bcd('0x18')](function(_0x1c2076){if(_0x1c2076){return db[_0x1bcd('0x49')][_0x1bcd('0x4a')]({'where':{'id':_[_0x1bcd('0x48')](_0x1c2076,_0x1bcd('0x4b')),'role':_0x1bcd('0x4c')},'attributes':['id','name',_0x1bcd('0x4d'),'updatedAt',_0x1bcd('0x4e')]});}})[_0x1bcd('0x18')](function(_0x503e90){if(_0x503e90){return{'count':_0x503e90[_0x1bcd('0x13')],'rows':_[_0x1bcd('0x48')](_0x503e90[_0x1bcd('0x27')],function(_0x463d91){return{'membername':_0x463d91[_0x1bcd('0x1c')],'UserId':_0x463d91['id'],'queue_name':_0x21ed02[_0x1bcd('0x1c')],'ChatQueueId':_0x21ed02['id'],'interface':util[_0x1bcd('0x4f')](_0x1bcd('0x50'),_0x1bcd('0x51'),_0x463d91['name']),'penalty':0x0,'paused':_0x463d91['chatPause'],'createdAt':_0x463d91['createdAt'],'updatedAt':_0x463d91[_0x1bcd('0x52')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x1bcd('0x18')](respondWithFilteredResult(_0x4ede57,_0x26d389))[_0x1bcd('0x28')](handleError(_0x4ede57,null));};exports['getTeams']=function(_0x465df6,_0xd98cc1){var _0x43ba39={};var _0x4cc7c4={};var _0x55cd0b;var _0x53a118;return db[_0x1bcd('0x1f')]['findOne']({'where':{'id':_0x465df6['params']['id']}})[_0x1bcd('0x18')](handleEntityNotFound(_0xd98cc1,null))[_0x1bcd('0x18')](function(_0x5ce2fa){if(_0x5ce2fa){_0x55cd0b=_0x5ce2fa;_0x4cc7c4[_0x1bcd('0x2b')]=_[_0x1bcd('0x2c')](db[_0x1bcd('0x53')][_0x1bcd('0x20')]);_0x4cc7c4[_0x1bcd('0x25')]=_[_0x1bcd('0x2c')](_0x465df6[_0x1bcd('0x25')]);_0x4cc7c4[_0x1bcd('0x2d')]=_[_0x1bcd('0x2e')](_0x4cc7c4[_0x1bcd('0x2b')],_0x4cc7c4[_0x1bcd('0x25')]);_0x43ba39[_0x1bcd('0x2f')]=_['intersection'](_0x4cc7c4[_0x1bcd('0x2b')],qs[_0x1bcd('0x30')](_0x465df6[_0x1bcd('0x25')][_0x1bcd('0x30')]));_0x43ba39[_0x1bcd('0x2f')]=_0x43ba39[_0x1bcd('0x2f')]['length']?_0x43ba39[_0x1bcd('0x2f')]:_0x4cc7c4['model'];_0x43ba39[_0x1bcd('0x43')]=qs['sort'](_0x465df6[_0x1bcd('0x25')][_0x1bcd('0x44')]);_0x43ba39[_0x1bcd('0x23')]=qs['filters'](_[_0x1bcd('0x54')](_0x465df6[_0x1bcd('0x25')],_0x4cc7c4[_0x1bcd('0x2d')]));if(_0x465df6[_0x1bcd('0x25')][_0x1bcd('0x46')]){_0x43ba39[_0x1bcd('0x23')]=_[_0x1bcd('0x47')](_0x43ba39[_0x1bcd('0x23')],{'$or':_['map'](_0x43ba39[_0x1bcd('0x2f')],function(_0x441fd2){var _0x46c3b8={};_0x46c3b8[_0x441fd2]={'$like':'%'+_0x465df6[_0x1bcd('0x25')][_0x1bcd('0x46')]+'%'};return _0x46c3b8;})});}_0x43ba39=_['merge']({},_0x43ba39,_0x465df6[_0x1bcd('0x33')]);return _0x55cd0b[_0x1bcd('0x55')](_0x43ba39);}})[_0x1bcd('0x18')](function(_0x55acaa){if(_0x55acaa){_0x53a118=_0x55acaa['length'];if(!_0x465df6['query'][_0x1bcd('0x42')]('nolimit')){_0x43ba39[_0x1bcd('0x12')]=qs[_0x1bcd('0x12')](_0x465df6[_0x1bcd('0x25')][_0x1bcd('0x12')]);_0x43ba39[_0x1bcd('0x14')]=qs[_0x1bcd('0x14')](_0x465df6[_0x1bcd('0x25')][_0x1bcd('0x14')]);}return _0x55cd0b[_0x1bcd('0x55')](_0x43ba39);}})[_0x1bcd('0x18')](function(_0x4cef1f){if(_0x4cef1f){return _0x4cef1f?{'count':_0x53a118,'rows':_0x4cef1f}:null;}})[_0x1bcd('0x18')](respondWithResult(_0xd98cc1,null))[_0x1bcd('0x28')](handleError(_0xd98cc1,null));};exports[_0x1bcd('0x56')]=function(_0x1c38ad,_0x4f4c63){var _0x42af52=_0x1c38ad[_0x1bcd('0x36')][_0x1bcd('0x57')];return db[_0x1bcd('0x53')][_0x1bcd('0x26')]({'where':{'id':_0x42af52},'attributes':['id'],'include':[{'model':db[_0x1bcd('0x49')],'as':_0x1bcd('0x58'),'attributes':['id',_0x1bcd('0x1c'),_0x1bcd('0x59'),'voicePause',_0x1bcd('0x5a')],'raw':!![]}]})[_0x1bcd('0x18')](function(_0x18dc51){if(_0x18dc51){var _0x210bd2=_[_0x1bcd('0x5b')](_0x18dc51,function(_0x1fcdd3){var _0x22766d=_0x1fcdd3[_0x1bcd('0x3a')]({'plain':!![]});return _0x22766d[_0x1bcd('0x58')];});return db[_0x1bcd('0x1f')][_0x1bcd('0x34')]({'where':{'id':_0x1c38ad[_0x1bcd('0x2a')]['id']}})['then'](function(_0x316499){return db[_0x1bcd('0x5c')]['transaction'](function(_0x4452a0){return _0x316499[_0x1bcd('0x56')](_0x42af52,{'transaction':_0x4452a0})[_0x1bcd('0x18')](function(){return BPromise[_0x1bcd('0x5d')](_0x210bd2,function(_0x3c5caf){return db['UserChatQueue'][_0x1bcd('0x5e')]({'where':{'UserId':_0x3c5caf['id'],'ChatQueueId':_0x1c38ad[_0x1bcd('0x2a')]['id']},'transaction':_0x4452a0});});})[_0x1bcd('0x18')](function(){_0x210bd2['forEach'](function(_0x5f096b){socket[_0x1bcd('0x5f')](_0x1bcd('0x60'),{'UserId':_0x5f096b['id'],'ChatQueueId':_0x316499['id']});});});});});}})[_0x1bcd('0x18')](respondWithStatusCode(_0x4f4c63,null))[_0x1bcd('0x28')](handleError(_0x4f4c63,null));};exports[_0x1bcd('0x61')]=function(_0x2cec0b,_0x19efe6){return db['Team'][_0x1bcd('0x26')]({'where':{'id':_0x2cec0b['query'][_0x1bcd('0x57')]},'attributes':['id'],'include':[{'model':db[_0x1bcd('0x49')],'as':_0x1bcd('0x58'),'attributes':['id'],'raw':!![]}]})[_0x1bcd('0x18')](handleEntityNotFound(_0x19efe6,null))['then'](function(_0x59f453){var _0x4ca366=_[_0x1bcd('0x48')](_0x59f453,'id');var _0x51799e=[];var _0x34c042=[];var _0x152a57=squel[_0x1bcd('0x62')]();_0x152a57[_0x1bcd('0x63')]('tq.TeamId')['from'](_0x1bcd('0x64'),'tq')['join']('user_has_teams','ut',_0x1bcd('0x65'))[_0x1bcd('0x23')]('ChatQueueId\x20=\x20?',_0x2cec0b[_0x1bcd('0x2a')]['id']);for(var _0x42aeee=0x0;_0x42aeee<_0x59f453[_0x1bcd('0x31')];_0x42aeee+=0x1){let _0x1f1ac7=_0x59f453[_0x42aeee];for(var _0x23ef27=0x0;_0x23ef27<_0x1f1ac7[_0x1bcd('0x58')][_0x1bcd('0x31')];_0x23ef27+=0x1){let _0x1ac390=_0x1f1ac7[_0x1bcd('0x58')][_0x23ef27];var _0x27eda8=_0x152a57[_0x1bcd('0x66')]();_0x27eda8[_0x1bcd('0x23')]('ut.UserId\x20=\x20?',_0x1ac390['id']);_0x34c042[_0x1bcd('0x67')](db[_0x1bcd('0x5c')][_0x1bcd('0x25')](_0x27eda8[_0x1bcd('0x68')](),{'type':db['sequelize']['QueryTypes'][_0x1bcd('0x69')]})[_0x1bcd('0x18')](function(_0x268642){if(_0x268642[_0x1bcd('0x31')]===0x1){return _0x1ac390['id'];}else{var _0x42ec6a=_[_0x1bcd('0x6a')](_[_0x1bcd('0x48')](_0x268642,_0x1bcd('0x6b')),function(_0x86f988){return _[_0x1bcd('0x6c')](_0x4ca366,_0x86f988);});if(_0x42ec6a){return _0x1ac390['id'];}}}));}}return BPromise[_0x1bcd('0x6d')](_0x34c042)['then'](function(_0x20670a){_0x51799e=_(_0x51799e)['union'](_0x20670a)['compact']()['value']();return db[_0x1bcd('0x1f')][_0x1bcd('0x34')]({'where':{'id':_0x2cec0b[_0x1bcd('0x2a')]['id']}})[_0x1bcd('0x18')](function(_0x51a20d){return db[_0x1bcd('0x5c')][_0x1bcd('0x6e')](function(_0x311a0b){return _0x51a20d[_0x1bcd('0x61')](_0x2cec0b[_0x1bcd('0x25')][_0x1bcd('0x57')],{'transaction':_0x311a0b})['then'](function(){if(!_[_0x1bcd('0x6f')](_0x51799e)){return _0x51a20d[_0x1bcd('0x70')](_0x51799e,{'transaction':_0x311a0b});}})[_0x1bcd('0x18')](function(){_0x51799e[_0x1bcd('0x71')](function(_0x47e070){socket[_0x1bcd('0x5f')](_0x1bcd('0x72'),{'UserId':_0x47e070,'ChatQueueId':_0x51a20d['id']});});});});});});})[_0x1bcd('0x18')](respondWithStatusCode(_0x19efe6,null))[_0x1bcd('0x28')](handleError(_0x19efe6,null));};exports[_0x1bcd('0x73')]=function(_0x59d138,_0x2ab8b9){return db[_0x1bcd('0x1f')]['find']({'where':{'id':_0x59d138[_0x1bcd('0x2a')]['id']}})[_0x1bcd('0x18')](handleEntityNotFound(_0x2ab8b9,null))[_0x1bcd('0x18')](function(_0x169f87){if(_0x169f87){return _0x169f87['addAgents'](_0x59d138[_0x1bcd('0x36')][_0x1bcd('0x57')],_[_0x1bcd('0x74')](_0x59d138[_0x1bcd('0x36')],[_0x1bcd('0x57'),'id'])||{})[_0x1bcd('0x75')](function(_0x40dd22){for(var _0x10f98e=0x0;_0x10f98e<_0x59d138[_0x1bcd('0x36')][_0x1bcd('0x57')]['length'];_0x10f98e+=0x1){socket[_0x1bcd('0x5f')](_0x1bcd('0x60'),{'UserId':Number(_0x59d138[_0x1bcd('0x36')][_0x1bcd('0x57')][_0x10f98e]),'ChatQueueId':Number(_0x59d138[_0x1bcd('0x2a')]['id'])});}return _0x40dd22;});}})[_0x1bcd('0x18')](respondWithResult(_0x2ab8b9,null))[_0x1bcd('0x28')](handleError(_0x2ab8b9,null));};exports['removeAgents']=function(_0x51ab68,_0x1756ad){return db[_0x1bcd('0x1f')][_0x1bcd('0x34')]({'where':{'id':_0x51ab68['params']['id']}})[_0x1bcd('0x18')](handleEntityNotFound(_0x1756ad,null))[_0x1bcd('0x18')](function(_0x15e8ca){if(_0x15e8ca){return _0x15e8ca[_0x1bcd('0x70')](_0x51ab68['query']['ids'])[_0x1bcd('0x18')](function(){if(_[_0x1bcd('0x76')](_0x51ab68[_0x1bcd('0x25')]['ids'])){for(var _0x54325a=0x0;_0x54325a<_0x51ab68['query'][_0x1bcd('0x57')][_0x1bcd('0x31')];_0x54325a+=0x1){socket[_0x1bcd('0x5f')](_0x1bcd('0x72'),{'UserId':Number(_0x51ab68[_0x1bcd('0x25')][_0x1bcd('0x57')][_0x54325a]),'ChatQueueId':Number(_0x51ab68[_0x1bcd('0x2a')]['id'])});}}else{socket[_0x1bcd('0x5f')]('userChatQueue:remove',{'UserId':Number(_0x51ab68[_0x1bcd('0x25')][_0x1bcd('0x57')]),'ChatQueueId':Number(_0x51ab68[_0x1bcd('0x2a')]['id'])});}});}})[_0x1bcd('0x18')](respondWithStatusCode(_0x1756ad,null))[_0x1bcd('0x28')](handleError(_0x1756ad,null));};exports[_0x1bcd('0x77')]=function(_0x236e8f,_0x480771){var _0x538886={};var _0x400121={};var _0x18d49a;var _0x5e034b;return db[_0x1bcd('0x1f')][_0x1bcd('0x40')]({'where':{'id':_0x236e8f[_0x1bcd('0x2a')]['id']}})['then'](handleEntityNotFound(_0x480771,null))[_0x1bcd('0x18')](function(_0xe296ef){if(_0xe296ef){_0x18d49a=_0xe296ef;_0x400121['model']=_[_0x1bcd('0x2c')](db[_0x1bcd('0x49')][_0x1bcd('0x20')]);_0x400121[_0x1bcd('0x25')]=_[_0x1bcd('0x2c')](_0x236e8f['query']);_0x400121[_0x1bcd('0x2d')]=_[_0x1bcd('0x2e')](_0x400121['model'],_0x400121['query']);_0x538886['attributes']=_['intersection'](_0x400121[_0x1bcd('0x2b')],qs[_0x1bcd('0x30')](_0x236e8f[_0x1bcd('0x25')]['fields']));_0x538886['attributes']=_0x538886[_0x1bcd('0x2f')][_0x1bcd('0x31')]?_0x538886[_0x1bcd('0x2f')]:_0x400121[_0x1bcd('0x2b')];_0x538886[_0x1bcd('0x43')]=qs[_0x1bcd('0x44')](_0x236e8f[_0x1bcd('0x25')][_0x1bcd('0x44')]);_0x538886[_0x1bcd('0x23')]=qs[_0x1bcd('0x2d')](_[_0x1bcd('0x54')](_0x236e8f[_0x1bcd('0x25')],_0x400121[_0x1bcd('0x2d')]));if(_0x236e8f['query']['filter']){_0x538886[_0x1bcd('0x23')]=_[_0x1bcd('0x47')](_0x538886[_0x1bcd('0x23')],{'$or':_[_0x1bcd('0x48')](_0x538886[_0x1bcd('0x2f')],function(_0x10b43c){var _0x3c2b5e={};_0x3c2b5e[_0x10b43c]={'$like':'%'+_0x236e8f[_0x1bcd('0x25')][_0x1bcd('0x46')]+'%'};return _0x3c2b5e;})});}_0x538886=_[_0x1bcd('0x47')]({},_0x538886,_0x236e8f[_0x1bcd('0x33')]);return _0x18d49a[_0x1bcd('0x77')](_0x538886);}})[_0x1bcd('0x18')](function(_0x2f360d){if(_0x2f360d){_0x5e034b=_0x2f360d[_0x1bcd('0x31')];if(!_0x236e8f[_0x1bcd('0x25')][_0x1bcd('0x42')]('nolimit')){_0x538886[_0x1bcd('0x12')]=qs[_0x1bcd('0x12')](_0x236e8f[_0x1bcd('0x25')][_0x1bcd('0x12')]);_0x538886[_0x1bcd('0x14')]=qs[_0x1bcd('0x14')](_0x236e8f[_0x1bcd('0x25')][_0x1bcd('0x14')]);}return _0x18d49a['getAgents'](_0x538886);}})[_0x1bcd('0x18')](function(_0x267440){if(_0x267440){return _0x267440?{'count':_0x5e034b,'rows':_0x267440}:null;}})[_0x1bcd('0x18')](respondWithResult(_0x480771,null))[_0x1bcd('0x28')](handleError(_0x480771,null));};