Built motion from commit 3c2ce842.|2.6.31
[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 _0xabf4=['redis','defaults','localhost','./chatQueue.socket','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','type','key','where','include','query','findAll','show','params','model','keys','filters','attributes','intersection','fields','length','includeAll','merge','find','catch','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','UserChatQueue','hasOwnProperty','nolimit','order','sort','pick','filter','options','findAndCountAll','UserId','agent','chatPause','updatedAt','createdAt','rows','format','%s/%s','SIP','getTeams','findOne','Team','ids','User','Agents','online','voicePause','flatMap','transaction','addTeams','each','findOrCreate','forEach','emit','userChatQueue:save','removeTeams','select','field','tq.TeamId','from','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','sequelize','QueryTypes','every','includes','all','union','value','userChatQueue:remove','addAgents','omit','spread','removeAgents','getAgents','util','lodash','squel','../../components/parsers/qs','../../config/logger','api','../../mysqldb'];(function(_0x3d79ac,_0x222051){var _0x475b30=function(_0x119831){while(--_0x119831){_0x3d79ac['push'](_0x3d79ac['shift']());}};_0x475b30(++_0x222051);}(_0xabf4,0x77));var _0x4abf=function(_0x34f41a,_0x5f1d24){_0x34f41a=_0x34f41a-0x0;var _0x4bfb9b=_0xabf4[_0x34f41a];return _0x4bfb9b;};'use strict';var BPromise=require('bluebird');var util=require(_0x4abf('0x0'));var _=require(_0x4abf('0x1'));var squel=require(_0x4abf('0x2'));var Redis=require('ioredis');var qs=require(_0x4abf('0x3'));var logger=require(_0x4abf('0x4'))(_0x4abf('0x5'));var config=require('../../config/environment');var db=require(_0x4abf('0x6'))['db'];config[_0x4abf('0x7')]=_[_0x4abf('0x8')](config['redis'],{'host':_0x4abf('0x9'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4abf('0x7')]));require(_0x4abf('0xa'))[_0x4abf('0xb')](socket);function respondWithStatusCode(_0x53a02a,_0x211221){_0x211221=_0x211221||0xcc;return function(_0x3c47e4){if(_0x3c47e4){return _0x53a02a[_0x4abf('0xc')](_0x211221);}return _0x53a02a[_0x4abf('0xd')](_0x211221)[_0x4abf('0xe')]();};}function respondWithResult(_0x155768,_0xc4914){_0xc4914=_0xc4914||0xc8;return function(_0x473f5a){if(_0x473f5a){return _0x155768['status'](_0xc4914)[_0x4abf('0xf')](_0x473f5a);}};}function respondWithFilteredResult(_0x41b901,_0x2b6cae){return function(_0x2a9487){if(_0x2a9487){var _0x5169cf=typeof _0x2b6cae[_0x4abf('0x10')]===_0x4abf('0x11')&&typeof _0x2b6cae[_0x4abf('0x12')]==='undefined';var _0x2ad0a1=_0x2a9487[_0x4abf('0x13')];var _0x188a43=_0x5169cf?0x0:_0x2b6cae[_0x4abf('0x10')];var _0x5f452f=_0x5169cf?_0x2a9487[_0x4abf('0x13')]:_0x2b6cae[_0x4abf('0x10')]+_0x2b6cae[_0x4abf('0x12')];var _0x470aaa;if(_0x5f452f>=_0x2ad0a1){_0x5f452f=_0x2ad0a1;_0x470aaa=0xc8;}else{_0x470aaa=0xce;}_0x41b901['status'](_0x470aaa);return _0x41b901[_0x4abf('0x14')](_0x4abf('0x15'),_0x188a43+'-'+_0x5f452f+'/'+_0x2ad0a1)[_0x4abf('0xf')](_0x2a9487);}return null;};}function saveUpdates(_0x1f0bce){return function(_0xc2b78d){if(_0xc2b78d){return _0xc2b78d[_0x4abf('0x16')](_0x1f0bce)[_0x4abf('0x17')](function(_0x1d9bfa){return _0x1d9bfa;});}return null;};}function removeEntity(_0x178917){return function(_0x79d84f){if(_0x79d84f){return _0x79d84f[_0x4abf('0x18')]()['then'](function(){var _0x2072f1=_0x79d84f[_0x4abf('0x19')]({'plain':!![]});var _0x3745da=_0x4abf('0x1a');return db[_0x4abf('0x1b')][_0x4abf('0x18')]({'where':{'type':_0x3745da,'resourceId':_0x2072f1['id']}})[_0x4abf('0x17')](function(){return _0x79d84f;});})['then'](function(){_0x178917[_0x4abf('0xd')](0xcc)['end']();});}};}function handleEntityNotFound(_0x11b45b){return function(_0x38768b){if(!_0x38768b){_0x11b45b[_0x4abf('0xc')](0x194);}return _0x38768b;};}function handleError(_0xfa066e,_0x2044f9){_0x2044f9=_0x2044f9||0x1f4;return function(_0x186023){logger[_0x4abf('0x1c')](_0x186023[_0x4abf('0x1d')]);if(_0x186023[_0x4abf('0x1e')]){delete _0x186023[_0x4abf('0x1e')];}_0xfa066e[_0x4abf('0xd')](_0x2044f9)[_0x4abf('0x1f')](_0x186023);};}exports[_0x4abf('0x20')]=function(_0x5cb8dc,_0x58f8d7){var _0x56c923={};var _0x5de50d={'count':0x0,'rows':[]};var _0x42c656=_[_0x4abf('0x21')](db[_0x4abf('0x22')][_0x4abf('0x23')],function(_0x3a3668){return{'name':_0x3a3668['fieldName'],'type':_0x3a3668[_0x4abf('0x24')][_0x4abf('0x25')]};});_0x56c923=qs['getOptions'](_0x42c656,_0x5cb8dc);var _0xd08200={'where':_0x56c923[_0x4abf('0x26')]};return db[_0x4abf('0x22')][_0x4abf('0x13')](_0xd08200)[_0x4abf('0x17')](function(_0xec4417){_0x5de50d[_0x4abf('0x13')]=_0xec4417;_0x56c923[_0x4abf('0x27')]=qs['include'](_0x5cb8dc[_0x4abf('0x28')]);return db['ChatQueue'][_0x4abf('0x29')](_0x56c923);})[_0x4abf('0x17')](function(_0x2c4650){_0x5de50d['rows']=_0x2c4650;return _0x5de50d;})[_0x4abf('0x17')](respondWithFilteredResult(_0x58f8d7,_0x56c923))['catch'](handleError(_0x58f8d7,null));};exports[_0x4abf('0x2a')]=function(_0x231b39,_0x12a277){var _0x34a12f={'raw':!![],'where':{'id':_0x231b39[_0x4abf('0x2b')]['id']}},_0x5d90e9={};_0x5d90e9[_0x4abf('0x2c')]=_[_0x4abf('0x2d')](db['ChatQueue']['rawAttributes']);_0x5d90e9[_0x4abf('0x28')]=_[_0x4abf('0x2d')](_0x231b39[_0x4abf('0x28')]);_0x5d90e9[_0x4abf('0x2e')]=_['intersection'](_0x5d90e9['model'],_0x5d90e9[_0x4abf('0x28')]);_0x34a12f[_0x4abf('0x2f')]=_[_0x4abf('0x30')](_0x5d90e9['model'],qs[_0x4abf('0x31')](_0x231b39[_0x4abf('0x28')]['fields']));_0x34a12f['attributes']=_0x34a12f[_0x4abf('0x2f')][_0x4abf('0x32')]?_0x34a12f[_0x4abf('0x2f')]:_0x5d90e9[_0x4abf('0x2c')];if(_0x231b39['query'][_0x4abf('0x33')]){_0x34a12f[_0x4abf('0x27')]=[{'all':!![]}];}_0x34a12f=_[_0x4abf('0x34')]({},_0x34a12f,_0x231b39['options']);return db[_0x4abf('0x22')][_0x4abf('0x35')](_0x34a12f)[_0x4abf('0x17')](handleEntityNotFound(_0x12a277,null))['then'](respondWithResult(_0x12a277,null))[_0x4abf('0x36')](handleError(_0x12a277,null));};exports[_0x4abf('0x37')]=function(_0x3d78f4,_0x2a243e){return db[_0x4abf('0x22')][_0x4abf('0x37')](_0x3d78f4[_0x4abf('0x38')],{})[_0x4abf('0x17')](function(_0x574548){var _0x1c17cd=_0x3d78f4['user']['get']({'plain':!![]});if(!_0x1c17cd)throw new Error(_0x4abf('0x39'));if(_0x1c17cd[_0x4abf('0x3a')]===_0x4abf('0x3b')){var _0x1e2377=_0x574548[_0x4abf('0x19')]({'plain':!![]});var _0x505339=_0x4abf('0x1a');return db[_0x4abf('0x3c')][_0x4abf('0x35')]({'where':{'name':_0x505339,'userProfileId':_0x1c17cd[_0x4abf('0x3d')]},'raw':!![]})[_0x4abf('0x17')](function(_0x49e4fd){if(_0x49e4fd&&_0x49e4fd[_0x4abf('0x3e')]===0x0){return db[_0x4abf('0x1b')][_0x4abf('0x37')]({'name':_0x1e2377[_0x4abf('0x1e')],'resourceId':_0x1e2377['id'],'type':_0x49e4fd['name'],'sectionId':_0x49e4fd['id']},{})[_0x4abf('0x17')](function(){return _0x574548;});}else{return _0x574548;}})[_0x4abf('0x36')](function(_0x531abe){logger[_0x4abf('0x1c')](_0x4abf('0x3f'),_0x531abe);throw _0x531abe;});}return _0x574548;})[_0x4abf('0x17')](respondWithResult(_0x2a243e,0xc9))[_0x4abf('0x36')](handleError(_0x2a243e,null));};exports[_0x4abf('0x16')]=function(_0x31ac3d,_0x40055d){if(_0x31ac3d[_0x4abf('0x38')]['id']){delete _0x31ac3d[_0x4abf('0x38')]['id'];}return db[_0x4abf('0x22')]['find']({'where':{'id':_0x31ac3d[_0x4abf('0x2b')]['id']}})['then'](handleEntityNotFound(_0x40055d,null))[_0x4abf('0x17')](saveUpdates(_0x31ac3d['body'],null))[_0x4abf('0x17')](respondWithResult(_0x40055d,null))[_0x4abf('0x36')](handleError(_0x40055d,null));};exports[_0x4abf('0x18')]=function(_0x2a90be,_0x2695e3){return db[_0x4abf('0x22')][_0x4abf('0x35')]({'where':{'id':_0x2a90be['params']['id']}})[_0x4abf('0x17')](handleEntityNotFound(_0x2695e3,null))[_0x4abf('0x17')](removeEntity(_0x2695e3,null))[_0x4abf('0x36')](handleError(_0x2695e3,null));};exports['describe']=function(_0x54d590,_0x2c6b76){return db[_0x4abf('0x22')][_0x4abf('0x40')]()['then'](respondWithResult(_0x2c6b76,null))[_0x4abf('0x36')](handleError(_0x2c6b76,null));};exports[_0x4abf('0x41')]=function(_0x28a756,_0xec661a){var _0x1f3a7d={'raw':!![],'where':{}},_0x14ac29={},_0x2fbf68;return db[_0x4abf('0x22')]['findOne']({'where':{'id':_0x28a756['params']['id']}})['then'](handleEntityNotFound(_0xec661a,null))[_0x4abf('0x17')](function(_0xec48ef){if(_0xec48ef){_0x2fbf68=_0xec48ef[_0x4abf('0x19')]({'plain':!![]});_0x14ac29[_0x4abf('0x2c')]=_[_0x4abf('0x2d')](db[_0x4abf('0x42')][_0x4abf('0x23')]);_0x14ac29['query']=_[_0x4abf('0x2d')](_0x28a756[_0x4abf('0x28')]);_0x14ac29[_0x4abf('0x2e')]=_[_0x4abf('0x30')](_0x14ac29[_0x4abf('0x2c')],_0x14ac29[_0x4abf('0x28')]);_0x1f3a7d[_0x4abf('0x2f')]=_[_0x4abf('0x30')](_0x14ac29[_0x4abf('0x2c')],qs[_0x4abf('0x31')](_0x28a756['query'][_0x4abf('0x31')]));_0x1f3a7d['attributes']=_0x1f3a7d[_0x4abf('0x2f')][_0x4abf('0x32')]?_0x1f3a7d[_0x4abf('0x2f')]:_0x14ac29[_0x4abf('0x2c')];if(!_0x28a756[_0x4abf('0x28')][_0x4abf('0x43')](_0x4abf('0x44'))){_0x1f3a7d[_0x4abf('0x12')]=qs[_0x4abf('0x12')](_0x28a756[_0x4abf('0x28')][_0x4abf('0x12')]);_0x1f3a7d['offset']=qs[_0x4abf('0x10')](_0x28a756[_0x4abf('0x28')]['offset']);}_0x1f3a7d[_0x4abf('0x45')]=qs[_0x4abf('0x46')](_0x28a756[_0x4abf('0x28')][_0x4abf('0x46')]);_0x1f3a7d[_0x4abf('0x26')]=qs[_0x4abf('0x2e')](_[_0x4abf('0x47')](_0x28a756[_0x4abf('0x28')],_0x14ac29[_0x4abf('0x2e')]));_0x1f3a7d[_0x4abf('0x26')]['ChatQueueId']=_0xec48ef['id'];if(_0x28a756[_0x4abf('0x28')][_0x4abf('0x48')]){_0x1f3a7d[_0x4abf('0x26')]=_['merge'](_0x1f3a7d[_0x4abf('0x26')],{'$or':_[_0x4abf('0x21')](_0x1f3a7d['attributes'],function(_0x1f531f){var _0x47f0ec={};_0x47f0ec[_0x1f531f]={'$like':'%'+_0x28a756[_0x4abf('0x28')][_0x4abf('0x48')]+'%'};return _0x47f0ec;})});}_0x1f3a7d=_[_0x4abf('0x34')]({},_0x1f3a7d,_0x28a756[_0x4abf('0x49')]);return db[_0x4abf('0x42')]['findAll'](_0x1f3a7d);}})['then'](function(_0x24cff2){if(_0x24cff2){return db['User'][_0x4abf('0x4a')]({'where':{'id':_['map'](_0x24cff2,_0x4abf('0x4b')),'role':_0x4abf('0x4c')},'attributes':['id',_0x4abf('0x1e'),_0x4abf('0x4d'),_0x4abf('0x4e'),_0x4abf('0x4f')]});}})['then'](function(_0xe7383e){if(_0xe7383e){return{'count':_0xe7383e['count'],'rows':_[_0x4abf('0x21')](_0xe7383e[_0x4abf('0x50')],function(_0x185d54){return{'membername':_0x185d54[_0x4abf('0x1e')],'UserId':_0x185d54['id'],'queue_name':_0x2fbf68[_0x4abf('0x1e')],'ChatQueueId':_0x2fbf68['id'],'interface':util[_0x4abf('0x51')](_0x4abf('0x52'),_0x4abf('0x53'),_0x185d54['name']),'penalty':0x0,'paused':_0x185d54['chatPause'],'createdAt':_0x185d54[_0x4abf('0x4f')],'updatedAt':_0x185d54[_0x4abf('0x4e')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x4abf('0x17')](respondWithFilteredResult(_0xec661a,_0x1f3a7d))[_0x4abf('0x36')](handleError(_0xec661a,null));};exports[_0x4abf('0x54')]=function(_0x281c85,_0xd468a9){var _0x584084={};var _0x34232e={};var _0x4d89de;var _0xcf48fd;return db[_0x4abf('0x22')][_0x4abf('0x55')]({'where':{'id':_0x281c85['params']['id']}})[_0x4abf('0x17')](handleEntityNotFound(_0xd468a9,null))[_0x4abf('0x17')](function(_0xec860){if(_0xec860){_0x4d89de=_0xec860;_0x34232e[_0x4abf('0x2c')]=_[_0x4abf('0x2d')](db[_0x4abf('0x56')][_0x4abf('0x23')]);_0x34232e[_0x4abf('0x28')]=_['keys'](_0x281c85[_0x4abf('0x28')]);_0x34232e['filters']=_[_0x4abf('0x30')](_0x34232e[_0x4abf('0x2c')],_0x34232e['query']);_0x584084['attributes']=_[_0x4abf('0x30')](_0x34232e['model'],qs['fields'](_0x281c85[_0x4abf('0x28')]['fields']));_0x584084['attributes']=_0x584084['attributes']['length']?_0x584084[_0x4abf('0x2f')]:_0x34232e[_0x4abf('0x2c')];_0x584084['order']=qs['sort'](_0x281c85[_0x4abf('0x28')][_0x4abf('0x46')]);_0x584084['where']=qs['filters'](_[_0x4abf('0x47')](_0x281c85[_0x4abf('0x28')],_0x34232e[_0x4abf('0x2e')]));if(_0x281c85[_0x4abf('0x28')]['filter']){_0x584084['where']=_[_0x4abf('0x34')](_0x584084[_0x4abf('0x26')],{'$or':_[_0x4abf('0x21')](_0x584084['attributes'],function(_0x4937b8){var _0xd6f5e5={};_0xd6f5e5[_0x4937b8]={'$like':'%'+_0x281c85[_0x4abf('0x28')][_0x4abf('0x48')]+'%'};return _0xd6f5e5;})});}_0x584084=_[_0x4abf('0x34')]({},_0x584084,_0x281c85['options']);return _0x4d89de[_0x4abf('0x54')](_0x584084);}})[_0x4abf('0x17')](function(_0x484881){if(_0x484881){_0xcf48fd=_0x484881[_0x4abf('0x32')];if(!_0x281c85[_0x4abf('0x28')]['hasOwnProperty'](_0x4abf('0x44'))){_0x584084[_0x4abf('0x12')]=qs[_0x4abf('0x12')](_0x281c85[_0x4abf('0x28')][_0x4abf('0x12')]);_0x584084[_0x4abf('0x10')]=qs[_0x4abf('0x10')](_0x281c85[_0x4abf('0x28')]['offset']);}return _0x4d89de[_0x4abf('0x54')](_0x584084);}})['then'](function(_0x4012a0){if(_0x4012a0){return _0x4012a0?{'count':_0xcf48fd,'rows':_0x4012a0}:null;}})[_0x4abf('0x17')](respondWithResult(_0xd468a9,null))[_0x4abf('0x36')](handleError(_0xd468a9,null));};exports['addTeams']=function(_0x519fb7,_0x4da9a2){var _0x91f1e4=_0x519fb7['body'][_0x4abf('0x57')];return db[_0x4abf('0x56')][_0x4abf('0x29')]({'where':{'id':_0x91f1e4},'attributes':['id'],'include':[{'model':db[_0x4abf('0x58')],'as':_0x4abf('0x59'),'attributes':['id','name',_0x4abf('0x5a'),_0x4abf('0x5b'),'interface'],'raw':!![]}]})[_0x4abf('0x17')](function(_0x4f9a08){if(_0x4f9a08){var _0x73ebb=_[_0x4abf('0x5c')](_0x4f9a08,function(_0x1284a9){var _0x7d871f=_0x1284a9[_0x4abf('0x19')]({'plain':!![]});return _0x7d871f[_0x4abf('0x59')];});return db[_0x4abf('0x22')][_0x4abf('0x35')]({'where':{'id':_0x519fb7[_0x4abf('0x2b')]['id']}})[_0x4abf('0x17')](function(_0x413c32){return db['sequelize'][_0x4abf('0x5d')](function(_0x545df7){return _0x413c32[_0x4abf('0x5e')](_0x91f1e4,{'transaction':_0x545df7})[_0x4abf('0x17')](function(){return BPromise[_0x4abf('0x5f')](_0x73ebb,function(_0x466fe5){return db[_0x4abf('0x42')][_0x4abf('0x60')]({'where':{'UserId':_0x466fe5['id'],'ChatQueueId':_0x519fb7[_0x4abf('0x2b')]['id']},'transaction':_0x545df7});});})['then'](function(){_0x73ebb[_0x4abf('0x61')](function(_0x23a2d4){socket[_0x4abf('0x62')](_0x4abf('0x63'),{'UserId':_0x23a2d4['id'],'ChatQueueId':_0x413c32['id']});});});});});}})['then'](respondWithStatusCode(_0x4da9a2,null))[_0x4abf('0x36')](handleError(_0x4da9a2,null));};exports[_0x4abf('0x64')]=function(_0x5ea920,_0x25ee71){return db[_0x4abf('0x56')][_0x4abf('0x29')]({'where':{'id':_0x5ea920['query'][_0x4abf('0x57')]},'attributes':['id'],'include':[{'model':db[_0x4abf('0x58')],'as':_0x4abf('0x59'),'attributes':['id'],'raw':!![]}]})[_0x4abf('0x17')](handleEntityNotFound(_0x25ee71,null))[_0x4abf('0x17')](function(_0x115e27){var _0x3809ff=_[_0x4abf('0x21')](_0x115e27,'id');var _0x15b882=[];var _0x5475ca=[];var _0x4ef80d=squel[_0x4abf('0x65')]();_0x4ef80d[_0x4abf('0x66')](_0x4abf('0x67'))[_0x4abf('0x68')]('team_has_chat_queues','tq')[_0x4abf('0x69')](_0x4abf('0x6a'),'ut',_0x4abf('0x6b'))[_0x4abf('0x26')](_0x4abf('0x6c'),_0x5ea920[_0x4abf('0x2b')]['id']);for(var _0x3a056b=0x0;_0x3a056b<_0x115e27[_0x4abf('0x32')];_0x3a056b+=0x1){let _0x305d12=_0x115e27[_0x3a056b];for(var _0x156fdd=0x0;_0x156fdd<_0x305d12[_0x4abf('0x59')][_0x4abf('0x32')];_0x156fdd+=0x1){let _0x4b3e33=_0x305d12[_0x4abf('0x59')][_0x156fdd];var _0x5bf25d=_0x4ef80d[_0x4abf('0x6d')]();_0x5bf25d[_0x4abf('0x26')](_0x4abf('0x6e'),_0x4b3e33['id']);_0x5475ca[_0x4abf('0x6f')](db['sequelize'][_0x4abf('0x28')](_0x5bf25d[_0x4abf('0x70')](),{'type':db[_0x4abf('0x71')][_0x4abf('0x72')]['SELECT']})[_0x4abf('0x17')](function(_0x23aa05){if(_0x23aa05[_0x4abf('0x32')]===0x1){return _0x4b3e33['id'];}else{var _0x4b8da9=_[_0x4abf('0x73')](_[_0x4abf('0x21')](_0x23aa05,'TeamId'),function(_0x4bb8f){return _[_0x4abf('0x74')](_0x3809ff,_0x4bb8f);});if(_0x4b8da9){return _0x4b3e33['id'];}}}));}}return BPromise[_0x4abf('0x75')](_0x5475ca)[_0x4abf('0x17')](function(_0x4a39f6){_0x15b882=_(_0x15b882)[_0x4abf('0x76')](_0x4a39f6)['compact']()[_0x4abf('0x77')]();return db[_0x4abf('0x22')]['find']({'where':{'id':_0x5ea920[_0x4abf('0x2b')]['id']}})[_0x4abf('0x17')](function(_0x1bc6fa){return db[_0x4abf('0x71')][_0x4abf('0x5d')](function(_0x109c52){return _0x1bc6fa[_0x4abf('0x64')](_0x5ea920[_0x4abf('0x28')]['ids'],{'transaction':_0x109c52})[_0x4abf('0x17')](function(){if(!_['isEmpty'](_0x15b882)){return _0x1bc6fa['removeAgents'](_0x15b882,{'transaction':_0x109c52});}})[_0x4abf('0x17')](function(){_0x15b882[_0x4abf('0x61')](function(_0x38a577){socket['emit'](_0x4abf('0x78'),{'UserId':_0x38a577,'ChatQueueId':_0x1bc6fa['id']});});});});});});})[_0x4abf('0x17')](respondWithStatusCode(_0x25ee71,null))[_0x4abf('0x36')](handleError(_0x25ee71,null));};exports[_0x4abf('0x79')]=function(_0x474fdd,_0x1ad492){return db[_0x4abf('0x22')][_0x4abf('0x35')]({'where':{'id':_0x474fdd[_0x4abf('0x2b')]['id']}})[_0x4abf('0x17')](handleEntityNotFound(_0x1ad492,null))['then'](function(_0x371639){if(_0x371639){return _0x371639['addAgents'](_0x474fdd['body'][_0x4abf('0x57')],_[_0x4abf('0x7a')](_0x474fdd[_0x4abf('0x38')],[_0x4abf('0x57'),'id'])||{})[_0x4abf('0x7b')](function(_0x67f9a4){for(var _0x5aef6e=0x0;_0x5aef6e<_0x474fdd[_0x4abf('0x38')]['ids'][_0x4abf('0x32')];_0x5aef6e+=0x1){socket[_0x4abf('0x62')](_0x4abf('0x63'),{'UserId':Number(_0x474fdd[_0x4abf('0x38')][_0x4abf('0x57')][_0x5aef6e]),'ChatQueueId':Number(_0x474fdd['params']['id'])});}return _0x67f9a4;});}})['then'](respondWithResult(_0x1ad492,null))[_0x4abf('0x36')](handleError(_0x1ad492,null));};exports[_0x4abf('0x7c')]=function(_0x56df70,_0x3e70bd){return db['ChatQueue'][_0x4abf('0x35')]({'where':{'id':_0x56df70[_0x4abf('0x2b')]['id']}})['then'](handleEntityNotFound(_0x3e70bd,null))[_0x4abf('0x17')](function(_0x198776){if(_0x198776){return _0x198776[_0x4abf('0x7c')](_0x56df70[_0x4abf('0x28')][_0x4abf('0x57')])[_0x4abf('0x17')](function(){if(_['isArray'](_0x56df70[_0x4abf('0x28')]['ids'])){for(var _0x2d9aeb=0x0;_0x2d9aeb<_0x56df70[_0x4abf('0x28')]['ids'][_0x4abf('0x32')];_0x2d9aeb+=0x1){socket[_0x4abf('0x62')](_0x4abf('0x78'),{'UserId':Number(_0x56df70[_0x4abf('0x28')][_0x4abf('0x57')][_0x2d9aeb]),'ChatQueueId':Number(_0x56df70[_0x4abf('0x2b')]['id'])});}}else{socket[_0x4abf('0x62')]('userChatQueue:remove',{'UserId':Number(_0x56df70[_0x4abf('0x28')][_0x4abf('0x57')]),'ChatQueueId':Number(_0x56df70[_0x4abf('0x2b')]['id'])});}});}})[_0x4abf('0x17')](respondWithStatusCode(_0x3e70bd,null))['catch'](handleError(_0x3e70bd,null));};exports[_0x4abf('0x7d')]=function(_0x36c929,_0x43f626){var _0x235b68={};var _0xb55a4={};var _0x498ceb;var _0x476963;return db['ChatQueue'][_0x4abf('0x55')]({'where':{'id':_0x36c929['params']['id']}})[_0x4abf('0x17')](handleEntityNotFound(_0x43f626,null))[_0x4abf('0x17')](function(_0x1d9ac3){if(_0x1d9ac3){_0x498ceb=_0x1d9ac3;_0xb55a4[_0x4abf('0x2c')]=_['keys'](db[_0x4abf('0x58')][_0x4abf('0x23')]);_0xb55a4['query']=_[_0x4abf('0x2d')](_0x36c929[_0x4abf('0x28')]);_0xb55a4[_0x4abf('0x2e')]=_[_0x4abf('0x30')](_0xb55a4[_0x4abf('0x2c')],_0xb55a4[_0x4abf('0x28')]);_0x235b68[_0x4abf('0x2f')]=_[_0x4abf('0x30')](_0xb55a4[_0x4abf('0x2c')],qs[_0x4abf('0x31')](_0x36c929['query']['fields']));_0x235b68[_0x4abf('0x2f')]=_0x235b68[_0x4abf('0x2f')][_0x4abf('0x32')]?_0x235b68[_0x4abf('0x2f')]:_0xb55a4[_0x4abf('0x2c')];_0x235b68[_0x4abf('0x45')]=qs[_0x4abf('0x46')](_0x36c929[_0x4abf('0x28')][_0x4abf('0x46')]);_0x235b68[_0x4abf('0x26')]=qs[_0x4abf('0x2e')](_[_0x4abf('0x47')](_0x36c929[_0x4abf('0x28')],_0xb55a4['filters']));if(_0x36c929[_0x4abf('0x28')][_0x4abf('0x48')]){_0x235b68[_0x4abf('0x26')]=_[_0x4abf('0x34')](_0x235b68[_0x4abf('0x26')],{'$or':_[_0x4abf('0x21')](_0x235b68['attributes'],function(_0x41c95f){var _0x192c85={};_0x192c85[_0x41c95f]={'$like':'%'+_0x36c929[_0x4abf('0x28')][_0x4abf('0x48')]+'%'};return _0x192c85;})});}_0x235b68=_['merge']({},_0x235b68,_0x36c929[_0x4abf('0x49')]);return _0x498ceb[_0x4abf('0x7d')](_0x235b68);}})[_0x4abf('0x17')](function(_0x2d9546){if(_0x2d9546){_0x476963=_0x2d9546[_0x4abf('0x32')];if(!_0x36c929[_0x4abf('0x28')][_0x4abf('0x43')]('nolimit')){_0x235b68['limit']=qs[_0x4abf('0x12')](_0x36c929[_0x4abf('0x28')][_0x4abf('0x12')]);_0x235b68[_0x4abf('0x10')]=qs[_0x4abf('0x10')](_0x36c929[_0x4abf('0x28')][_0x4abf('0x10')]);}return _0x498ceb[_0x4abf('0x7d')](_0x235b68);}})['then'](function(_0x1063b8){if(_0x1063b8){return _0x1063b8?{'count':_0x476963,'rows':_0x1063b8}:null;}})[_0x4abf('0x17')](respondWithResult(_0x43f626,null))[_0x4abf('0x36')](handleError(_0x43f626,null));};