2140d15191bfad67d89f80a1ca9237e52a483b4a
[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 _0xf367=['json','update','then','destroy','get','OpenchannelQueues','error','stack','name','index','map','OpenchannelQueue','rawAttributes','type','key','getOptions','where','query','findAll','rows','catch','show','params','model','keys','intersection','attributes','fields','length','includeAll','merge','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','find','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','findOne','hasOwnProperty','nolimit','order','sort','filters','pick','OpenchannelQueueId','filter','UserOpenchannelQueue','User','findAndCountAll','UserId','agent','openchannelPause','createdAt','format','%s/%s','SIP','updatedAt','getTeams','Team','options','addTeams','Agents','interface','sequelize','transaction','each','emit','userOpenchannelQueue:save','removeTeams','ids','select','field','tq.TeamId','from','team_has_openchannel_queues','user_has_teams','OpenchannelQueueId\x20=\x20?','clone','push','toString','QueryTypes','SELECT','every','TeamId','includes','all','union','value','isEmpty','removeAgents','forEach','userOpenchannelQueue:remove','addAgents','omit','spread','isArray','getAgents','bluebird','util','lodash','squel','ioredis','../../components/parsers/qs','../../config/logger','redis','defaults','./openchannelQueue.socket','register','sendStatus','end','status','offset','undefined','limit','count','set','Content-Range'];(function(_0x2dc1e3,_0x3d3c68){var _0x14b567=function(_0x4b63e3){while(--_0x4b63e3){_0x2dc1e3['push'](_0x2dc1e3['shift']());}};_0x14b567(++_0x3d3c68);}(_0xf367,0x1d0));var _0x7f36=function(_0x340763,_0x59c92b){_0x340763=_0x340763-0x0;var _0x230091=_0xf367[_0x340763];return _0x230091;};'use strict';var BPromise=require(_0x7f36('0x0'));var util=require(_0x7f36('0x1'));var _=require(_0x7f36('0x2'));var squel=require(_0x7f36('0x3'));var Redis=require(_0x7f36('0x4'));var qs=require(_0x7f36('0x5'));var logger=require(_0x7f36('0x6'))('api');var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config[_0x7f36('0x7')]=_[_0x7f36('0x8')](config[_0x7f36('0x7')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x7f36('0x7')]));require(_0x7f36('0x9'))[_0x7f36('0xa')](socket);function respondWithStatusCode(_0x9a5451,_0x8a3f23){_0x8a3f23=_0x8a3f23||0xcc;return function(_0x2dd1b8){if(_0x2dd1b8){return _0x9a5451[_0x7f36('0xb')](_0x8a3f23);}return _0x9a5451['status'](_0x8a3f23)[_0x7f36('0xc')]();};}function respondWithResult(_0x173a32,_0xaa2af0){_0xaa2af0=_0xaa2af0||0xc8;return function(_0x414bbb){if(_0x414bbb){return _0x173a32[_0x7f36('0xd')](_0xaa2af0)['json'](_0x414bbb);}};}function respondWithFilteredResult(_0x1c7fe1,_0x3da5a4){return function(_0x19ca18){if(_0x19ca18){var _0x570cd6=typeof _0x3da5a4[_0x7f36('0xe')]===_0x7f36('0xf')&&typeof _0x3da5a4[_0x7f36('0x10')]===_0x7f36('0xf');var _0x144720=_0x19ca18[_0x7f36('0x11')];var _0x1ccd71=_0x570cd6?0x0:_0x3da5a4[_0x7f36('0xe')];var _0x438269=_0x570cd6?_0x19ca18[_0x7f36('0x11')]:_0x3da5a4['offset']+_0x3da5a4['limit'];var _0xe86dd;if(_0x438269>=_0x144720){_0x438269=_0x144720;_0xe86dd=0xc8;}else{_0xe86dd=0xce;}_0x1c7fe1[_0x7f36('0xd')](_0xe86dd);return _0x1c7fe1[_0x7f36('0x12')](_0x7f36('0x13'),_0x1ccd71+'-'+_0x438269+'/'+_0x144720)[_0x7f36('0x14')](_0x19ca18);}return null;};}function saveUpdates(_0x16fe5f){return function(_0xf9b3b0){if(_0xf9b3b0){return _0xf9b3b0[_0x7f36('0x15')](_0x16fe5f)[_0x7f36('0x16')](function(_0xd9d35c){return _0xd9d35c;});}return null;};}function removeEntity(_0x23bfb8){return function(_0x4dc67c){if(_0x4dc67c){return _0x4dc67c[_0x7f36('0x17')]()['then'](function(){var _0x117642=_0x4dc67c[_0x7f36('0x18')]({'plain':!![]});var _0x20600e=_0x7f36('0x19');return db['UserProfileResource'][_0x7f36('0x17')]({'where':{'type':_0x20600e,'resourceId':_0x117642['id']}})[_0x7f36('0x16')](function(){return _0x4dc67c;});})[_0x7f36('0x16')](function(){_0x23bfb8[_0x7f36('0xd')](0xcc)[_0x7f36('0xc')]();});}};}function handleEntityNotFound(_0x41c9ae){return function(_0x5550c3){if(!_0x5550c3){_0x41c9ae['sendStatus'](0x194);}return _0x5550c3;};}function handleError(_0x7d314a,_0x279c55){_0x279c55=_0x279c55||0x1f4;return function(_0x5f1b81){logger[_0x7f36('0x1a')](_0x5f1b81[_0x7f36('0x1b')]);if(_0x5f1b81[_0x7f36('0x1c')]){delete _0x5f1b81[_0x7f36('0x1c')];}_0x7d314a['status'](_0x279c55)['send'](_0x5f1b81);};}exports[_0x7f36('0x1d')]=function(_0x2be69d,_0x131404){var _0x40c337={};var _0x7d2207={'count':0x0,'rows':[]};var _0x7b2d07=_[_0x7f36('0x1e')](db[_0x7f36('0x1f')][_0x7f36('0x20')],function(_0x1fb2be){return{'name':_0x1fb2be['fieldName'],'type':_0x1fb2be[_0x7f36('0x21')][_0x7f36('0x22')]};});_0x40c337=qs[_0x7f36('0x23')](_0x7b2d07,_0x2be69d);var _0x5de8e3={'where':_0x40c337[_0x7f36('0x24')]};return db[_0x7f36('0x1f')][_0x7f36('0x11')](_0x5de8e3)[_0x7f36('0x16')](function(_0x507e2c){_0x7d2207[_0x7f36('0x11')]=_0x507e2c;_0x40c337['include']=qs['include'](_0x2be69d[_0x7f36('0x25')]);return db['OpenchannelQueue'][_0x7f36('0x26')](_0x40c337);})[_0x7f36('0x16')](function(_0x298f58){_0x7d2207[_0x7f36('0x27')]=_0x298f58;return _0x7d2207;})[_0x7f36('0x16')](respondWithFilteredResult(_0x131404,_0x40c337))[_0x7f36('0x28')](handleError(_0x131404,null));};exports[_0x7f36('0x29')]=function(_0x435b09,_0x58658b){var _0x158562={'raw':!![],'where':{'id':_0x435b09[_0x7f36('0x2a')]['id']}},_0x2af351={};_0x2af351[_0x7f36('0x2b')]=_[_0x7f36('0x2c')](db['OpenchannelQueue'][_0x7f36('0x20')]);_0x2af351['query']=_['keys'](_0x435b09[_0x7f36('0x25')]);_0x2af351['filters']=_[_0x7f36('0x2d')](_0x2af351[_0x7f36('0x2b')],_0x2af351[_0x7f36('0x25')]);_0x158562[_0x7f36('0x2e')]=_[_0x7f36('0x2d')](_0x2af351[_0x7f36('0x2b')],qs[_0x7f36('0x2f')](_0x435b09[_0x7f36('0x25')][_0x7f36('0x2f')]));_0x158562[_0x7f36('0x2e')]=_0x158562[_0x7f36('0x2e')][_0x7f36('0x30')]?_0x158562[_0x7f36('0x2e')]:_0x2af351['model'];if(_0x435b09[_0x7f36('0x25')][_0x7f36('0x31')]){_0x158562['include']=[{'all':!![]}];}_0x158562=_[_0x7f36('0x32')]({},_0x158562,_0x435b09['options']);return db['OpenchannelQueue']['find'](_0x158562)[_0x7f36('0x16')](handleEntityNotFound(_0x58658b,null))[_0x7f36('0x16')](respondWithResult(_0x58658b,null))['catch'](handleError(_0x58658b,null));};exports[_0x7f36('0x33')]=function(_0x1badf2,_0x3956fc){return db[_0x7f36('0x1f')]['create'](_0x1badf2['body'],{})[_0x7f36('0x16')](function(_0x2d3e2c){var _0x2357de=_0x1badf2[_0x7f36('0x34')][_0x7f36('0x18')]({'plain':!![]});if(!_0x2357de)throw new Error(_0x7f36('0x35'));if(_0x2357de['role']==='user'){var _0x9da675=_0x2d3e2c['get']({'plain':!![]});var _0x4c30bb=_0x7f36('0x19');return db[_0x7f36('0x36')][_0x7f36('0x37')]({'where':{'name':_0x4c30bb,'userProfileId':_0x2357de['userProfileId']},'raw':!![]})['then'](function(_0x3730f1){if(_0x3730f1&&_0x3730f1[_0x7f36('0x38')]===0x0){return db[_0x7f36('0x39')][_0x7f36('0x33')]({'name':_0x9da675[_0x7f36('0x1c')],'resourceId':_0x9da675['id'],'type':_0x3730f1[_0x7f36('0x1c')],'sectionId':_0x3730f1['id']},{})['then'](function(){return _0x2d3e2c;});}else{return _0x2d3e2c;}})[_0x7f36('0x28')](function(_0x15a1aa){logger[_0x7f36('0x1a')](_0x7f36('0x3a'),_0x15a1aa);throw _0x15a1aa;});}return _0x2d3e2c;})['then'](respondWithResult(_0x3956fc,0xc9))[_0x7f36('0x28')](handleError(_0x3956fc,null));};exports[_0x7f36('0x15')]=function(_0x2810a0,_0x1c9a55){if(_0x2810a0[_0x7f36('0x3b')]['id']){delete _0x2810a0[_0x7f36('0x3b')]['id'];}return db[_0x7f36('0x1f')]['find']({'where':{'id':_0x2810a0[_0x7f36('0x2a')]['id']}})['then'](handleEntityNotFound(_0x1c9a55,null))[_0x7f36('0x16')](saveUpdates(_0x2810a0['body'],null))[_0x7f36('0x16')](respondWithResult(_0x1c9a55,null))[_0x7f36('0x28')](handleError(_0x1c9a55,null));};exports['destroy']=function(_0x47520a,_0xaafbb3){return db[_0x7f36('0x1f')][_0x7f36('0x37')]({'where':{'id':_0x47520a[_0x7f36('0x2a')]['id']}})[_0x7f36('0x16')](handleEntityNotFound(_0xaafbb3,null))[_0x7f36('0x16')](removeEntity(_0xaafbb3,null))[_0x7f36('0x28')](handleError(_0xaafbb3,null));};exports[_0x7f36('0x3c')]=function(_0x20b727,_0x36affa){return db['OpenchannelQueue'][_0x7f36('0x3c')]()[_0x7f36('0x16')](respondWithResult(_0x36affa,null))[_0x7f36('0x28')](handleError(_0x36affa,null));};exports['getMembers']=function(_0x13347,_0x3228de){var _0x2e3315={'raw':!![],'where':{}},_0x268e56={},_0x23e4ef;return db[_0x7f36('0x1f')][_0x7f36('0x3d')]({'where':{'id':_0x13347[_0x7f36('0x2a')]['id']}})[_0x7f36('0x16')](handleEntityNotFound(_0x3228de,null))[_0x7f36('0x16')](function(_0x234d44){if(_0x234d44){_0x23e4ef=_0x234d44['get']({'plain':!![]});_0x268e56['model']=_[_0x7f36('0x2c')](db['UserOpenchannelQueue'][_0x7f36('0x20')]);_0x268e56[_0x7f36('0x25')]=_[_0x7f36('0x2c')](_0x13347[_0x7f36('0x25')]);_0x268e56['filters']=_[_0x7f36('0x2d')](_0x268e56['model'],_0x268e56[_0x7f36('0x25')]);_0x2e3315['attributes']=_[_0x7f36('0x2d')](_0x268e56[_0x7f36('0x2b')],qs[_0x7f36('0x2f')](_0x13347['query'][_0x7f36('0x2f')]));_0x2e3315[_0x7f36('0x2e')]=_0x2e3315[_0x7f36('0x2e')][_0x7f36('0x30')]?_0x2e3315[_0x7f36('0x2e')]:_0x268e56[_0x7f36('0x2b')];if(!_0x13347[_0x7f36('0x25')][_0x7f36('0x3e')](_0x7f36('0x3f'))){_0x2e3315[_0x7f36('0x10')]=qs[_0x7f36('0x10')](_0x13347['query'][_0x7f36('0x10')]);_0x2e3315[_0x7f36('0xe')]=qs[_0x7f36('0xe')](_0x13347['query'][_0x7f36('0xe')]);}_0x2e3315[_0x7f36('0x40')]=qs[_0x7f36('0x41')](_0x13347[_0x7f36('0x25')][_0x7f36('0x41')]);_0x2e3315[_0x7f36('0x24')]=qs[_0x7f36('0x42')](_[_0x7f36('0x43')](_0x13347[_0x7f36('0x25')],_0x268e56[_0x7f36('0x42')]));_0x2e3315[_0x7f36('0x24')][_0x7f36('0x44')]=_0x234d44['id'];if(_0x13347[_0x7f36('0x25')][_0x7f36('0x45')]){_0x2e3315[_0x7f36('0x24')]=_[_0x7f36('0x32')](_0x2e3315[_0x7f36('0x24')],{'$or':_[_0x7f36('0x1e')](_0x2e3315[_0x7f36('0x2e')],function(_0xb1ba24){var _0x122d67={};_0x122d67[_0xb1ba24]={'$like':'%'+_0x13347[_0x7f36('0x25')][_0x7f36('0x45')]+'%'};return _0x122d67;})});}_0x2e3315=_[_0x7f36('0x32')]({},_0x2e3315,_0x13347['options']);return db[_0x7f36('0x46')][_0x7f36('0x26')](_0x2e3315);}})[_0x7f36('0x16')](function(_0x56cf9e){if(_0x56cf9e){return db[_0x7f36('0x47')][_0x7f36('0x48')]({'where':{'id':_[_0x7f36('0x1e')](_0x56cf9e,_0x7f36('0x49')),'role':_0x7f36('0x4a')},'attributes':['id','name',_0x7f36('0x4b'),'updatedAt',_0x7f36('0x4c')]});}})['then'](function(_0xc7adb6){if(_0xc7adb6){return{'count':_0xc7adb6[_0x7f36('0x11')],'rows':_[_0x7f36('0x1e')](_0xc7adb6[_0x7f36('0x27')],function(_0x14d8ad){return{'membername':_0x14d8ad[_0x7f36('0x1c')],'UserId':_0x14d8ad['id'],'queue_name':_0x23e4ef[_0x7f36('0x1c')],'OpenchannelQueueId':_0x23e4ef['id'],'interface':util[_0x7f36('0x4d')](_0x7f36('0x4e'),_0x7f36('0x4f'),_0x14d8ad[_0x7f36('0x1c')]),'penalty':0x0,'paused':_0x14d8ad['openchannelPause'],'createdAt':_0x14d8ad[_0x7f36('0x4c')],'updatedAt':_0x14d8ad[_0x7f36('0x50')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x7f36('0x16')](respondWithFilteredResult(_0x3228de,_0x2e3315))['catch'](handleError(_0x3228de,null));};exports[_0x7f36('0x51')]=function(_0xa131f5,_0x2067a2){var _0x2ad4e6={};var _0x1a8e71={};var _0x3902ef;var _0x33001d;return db[_0x7f36('0x1f')][_0x7f36('0x3d')]({'where':{'id':_0xa131f5[_0x7f36('0x2a')]['id']}})['then'](handleEntityNotFound(_0x2067a2,null))[_0x7f36('0x16')](function(_0x40338d){if(_0x40338d){_0x3902ef=_0x40338d;_0x1a8e71[_0x7f36('0x2b')]=_[_0x7f36('0x2c')](db[_0x7f36('0x52')]['rawAttributes']);_0x1a8e71['query']=_['keys'](_0xa131f5[_0x7f36('0x25')]);_0x1a8e71[_0x7f36('0x42')]=_[_0x7f36('0x2d')](_0x1a8e71[_0x7f36('0x2b')],_0x1a8e71['query']);_0x2ad4e6['attributes']=_[_0x7f36('0x2d')](_0x1a8e71[_0x7f36('0x2b')],qs[_0x7f36('0x2f')](_0xa131f5[_0x7f36('0x25')][_0x7f36('0x2f')]));_0x2ad4e6[_0x7f36('0x2e')]=_0x2ad4e6[_0x7f36('0x2e')][_0x7f36('0x30')]?_0x2ad4e6[_0x7f36('0x2e')]:_0x1a8e71[_0x7f36('0x2b')];_0x2ad4e6[_0x7f36('0x40')]=qs[_0x7f36('0x41')](_0xa131f5[_0x7f36('0x25')]['sort']);_0x2ad4e6[_0x7f36('0x24')]=qs[_0x7f36('0x42')](_[_0x7f36('0x43')](_0xa131f5[_0x7f36('0x25')],_0x1a8e71[_0x7f36('0x42')]));if(_0xa131f5['query'][_0x7f36('0x45')]){_0x2ad4e6[_0x7f36('0x24')]=_[_0x7f36('0x32')](_0x2ad4e6[_0x7f36('0x24')],{'$or':_[_0x7f36('0x1e')](_0x2ad4e6['attributes'],function(_0x386a27){var _0x29b882={};_0x29b882[_0x386a27]={'$like':'%'+_0xa131f5['query'][_0x7f36('0x45')]+'%'};return _0x29b882;})});}_0x2ad4e6=_[_0x7f36('0x32')]({},_0x2ad4e6,_0xa131f5[_0x7f36('0x53')]);return _0x3902ef[_0x7f36('0x51')](_0x2ad4e6);}})[_0x7f36('0x16')](function(_0x519995){if(_0x519995){_0x33001d=_0x519995[_0x7f36('0x30')];if(!_0xa131f5['query'][_0x7f36('0x3e')]('nolimit')){_0x2ad4e6[_0x7f36('0x10')]=qs['limit'](_0xa131f5[_0x7f36('0x25')]['limit']);_0x2ad4e6['offset']=qs[_0x7f36('0xe')](_0xa131f5[_0x7f36('0x25')][_0x7f36('0xe')]);}return _0x3902ef[_0x7f36('0x51')](_0x2ad4e6);}})[_0x7f36('0x16')](function(_0x3805ee){if(_0x3805ee){return _0x3805ee?{'count':_0x33001d,'rows':_0x3805ee}:null;}})[_0x7f36('0x16')](respondWithResult(_0x2067a2,null))[_0x7f36('0x28')](handleError(_0x2067a2,null));};exports[_0x7f36('0x54')]=function(_0x2206dd,_0x4df01a){var _0x2a089d=_0x2206dd[_0x7f36('0x3b')]['ids'];return db[_0x7f36('0x52')][_0x7f36('0x26')]({'where':{'id':_0x2a089d},'attributes':['id'],'include':[{'model':db['User'],'as':_0x7f36('0x55'),'attributes':['id',_0x7f36('0x1c'),'online','voicePause',_0x7f36('0x56')],'raw':!![]}]})['then'](function(_0x4fa0c7){if(_0x4fa0c7){var _0x4c0fa8=_['flatMap'](_0x4fa0c7,function(_0x1d26d3){var _0x2a7177=_0x1d26d3['get']({'plain':!![]});return _0x2a7177[_0x7f36('0x55')];});return db[_0x7f36('0x1f')][_0x7f36('0x37')]({'where':{'id':_0x2206dd[_0x7f36('0x2a')]['id']}})[_0x7f36('0x16')](function(_0x571226){return db[_0x7f36('0x57')][_0x7f36('0x58')](function(_0x2cd719){return _0x571226[_0x7f36('0x54')](_0x2a089d,{'transaction':_0x2cd719})[_0x7f36('0x16')](function(){return BPromise[_0x7f36('0x59')](_0x4c0fa8,function(_0x388818){return db['UserOpenchannelQueue']['findOrCreate']({'where':{'UserId':_0x388818['id'],'OpenchannelQueueId':_0x2206dd[_0x7f36('0x2a')]['id']},'transaction':_0x2cd719});});})[_0x7f36('0x16')](function(){_0x4c0fa8['forEach'](function(_0x2a5a1e){socket[_0x7f36('0x5a')](_0x7f36('0x5b'),{'UserId':_0x2a5a1e['id'],'OpenchannelQueueId':_0x571226['id']});});});});});}})['then'](respondWithStatusCode(_0x4df01a,null))['catch'](handleError(_0x4df01a,null));};exports[_0x7f36('0x5c')]=function(_0x467174,_0x568c24){return db[_0x7f36('0x52')][_0x7f36('0x26')]({'where':{'id':_0x467174['query'][_0x7f36('0x5d')]},'attributes':['id'],'include':[{'model':db[_0x7f36('0x47')],'as':_0x7f36('0x55'),'attributes':['id'],'raw':!![]}]})[_0x7f36('0x16')](handleEntityNotFound(_0x568c24,null))[_0x7f36('0x16')](function(_0x1ef135){var _0x208fa3=_[_0x7f36('0x1e')](_0x1ef135,'id');var _0x52e93a=[];var _0x542b5b=[];var _0x47eb3f=squel[_0x7f36('0x5e')]();_0x47eb3f[_0x7f36('0x5f')](_0x7f36('0x60'))[_0x7f36('0x61')](_0x7f36('0x62'),'tq')['join'](_0x7f36('0x63'),'ut','ut.TeamId\x20=\x20tq.TeamId')['where'](_0x7f36('0x64'),_0x467174[_0x7f36('0x2a')]['id']);for(var _0x11b7bb=0x0;_0x11b7bb<_0x1ef135['length'];_0x11b7bb+=0x1){let _0x169da4=_0x1ef135[_0x11b7bb];for(var _0x1c3986=0x0;_0x1c3986<_0x169da4['Agents'][_0x7f36('0x30')];_0x1c3986+=0x1){let _0x310271=_0x169da4[_0x7f36('0x55')][_0x1c3986];var _0x5364b0=_0x47eb3f[_0x7f36('0x65')]();_0x5364b0[_0x7f36('0x24')]('ut.UserId\x20=\x20?',_0x310271['id']);_0x542b5b[_0x7f36('0x66')](db['sequelize'][_0x7f36('0x25')](_0x5364b0[_0x7f36('0x67')](),{'type':db[_0x7f36('0x57')][_0x7f36('0x68')][_0x7f36('0x69')]})[_0x7f36('0x16')](function(_0x577cd5){if(_0x577cd5[_0x7f36('0x30')]===0x1){return _0x310271['id'];}else{var _0x23494b=_[_0x7f36('0x6a')](_[_0x7f36('0x1e')](_0x577cd5,_0x7f36('0x6b')),function(_0x217380){return _[_0x7f36('0x6c')](_0x208fa3,_0x217380);});if(_0x23494b){return _0x310271['id'];}}}));}}return BPromise[_0x7f36('0x6d')](_0x542b5b)['then'](function(_0x2dc920){_0x52e93a=_(_0x52e93a)[_0x7f36('0x6e')](_0x2dc920)['compact']()[_0x7f36('0x6f')]();return db[_0x7f36('0x1f')][_0x7f36('0x37')]({'where':{'id':_0x467174[_0x7f36('0x2a')]['id']}})[_0x7f36('0x16')](function(_0x29c333){return db[_0x7f36('0x57')][_0x7f36('0x58')](function(_0x374aa0){return _0x29c333[_0x7f36('0x5c')](_0x467174[_0x7f36('0x25')][_0x7f36('0x5d')],{'transaction':_0x374aa0})[_0x7f36('0x16')](function(){if(!_[_0x7f36('0x70')](_0x52e93a)){return _0x29c333[_0x7f36('0x71')](_0x52e93a,{'transaction':_0x374aa0});}})[_0x7f36('0x16')](function(){_0x52e93a[_0x7f36('0x72')](function(_0x5e9959){socket[_0x7f36('0x5a')](_0x7f36('0x73'),{'UserId':_0x5e9959,'OpenchannelQueueId':_0x29c333['id']});});});});});});})[_0x7f36('0x16')](respondWithStatusCode(_0x568c24,null))[_0x7f36('0x28')](handleError(_0x568c24,null));};exports[_0x7f36('0x74')]=function(_0x249057,_0x4ff1d0){return db['OpenchannelQueue'][_0x7f36('0x37')]({'where':{'id':_0x249057[_0x7f36('0x2a')]['id']}})[_0x7f36('0x16')](handleEntityNotFound(_0x4ff1d0,null))[_0x7f36('0x16')](function(_0xced7b9){if(_0xced7b9){return _0xced7b9[_0x7f36('0x74')](_0x249057[_0x7f36('0x3b')]['ids'],_[_0x7f36('0x75')](_0x249057['body'],['ids','id'])||{})[_0x7f36('0x76')](function(_0x919114){for(var _0x1d1645=0x0;_0x1d1645<_0x249057[_0x7f36('0x3b')]['ids'][_0x7f36('0x30')];_0x1d1645+=0x1){socket['emit']('userOpenchannelQueue:save',{'UserId':Number(_0x249057['body'][_0x7f36('0x5d')][_0x1d1645]),'OpenchannelQueueId':Number(_0x249057[_0x7f36('0x2a')]['id'])});}return _0x919114;});}})[_0x7f36('0x16')](respondWithResult(_0x4ff1d0,null))[_0x7f36('0x28')](handleError(_0x4ff1d0,null));};exports['removeAgents']=function(_0x523400,_0x59e0f7){return db[_0x7f36('0x1f')][_0x7f36('0x37')]({'where':{'id':_0x523400[_0x7f36('0x2a')]['id']}})[_0x7f36('0x16')](handleEntityNotFound(_0x59e0f7,null))[_0x7f36('0x16')](function(_0x385181){if(_0x385181){return _0x385181[_0x7f36('0x71')](_0x523400[_0x7f36('0x25')][_0x7f36('0x5d')])['then'](function(){if(_[_0x7f36('0x77')](_0x523400[_0x7f36('0x25')]['ids'])){for(var _0x56fb26=0x0;_0x56fb26<_0x523400['query'][_0x7f36('0x5d')][_0x7f36('0x30')];_0x56fb26+=0x1){socket[_0x7f36('0x5a')](_0x7f36('0x73'),{'UserId':Number(_0x523400[_0x7f36('0x25')][_0x7f36('0x5d')][_0x56fb26]),'OpenchannelQueueId':Number(_0x523400[_0x7f36('0x2a')]['id'])});}}else{socket[_0x7f36('0x5a')](_0x7f36('0x73'),{'UserId':Number(_0x523400[_0x7f36('0x25')][_0x7f36('0x5d')]),'OpenchannelQueueId':Number(_0x523400[_0x7f36('0x2a')]['id'])});}});}})[_0x7f36('0x16')](respondWithStatusCode(_0x59e0f7,null))[_0x7f36('0x28')](handleError(_0x59e0f7,null));};exports[_0x7f36('0x78')]=function(_0x29f092,_0x4ee50a){var _0x587a66={};var _0xd37a53={};var _0xde1922;var _0xbcfecc;return db['OpenchannelQueue'][_0x7f36('0x3d')]({'where':{'id':_0x29f092['params']['id']}})[_0x7f36('0x16')](handleEntityNotFound(_0x4ee50a,null))[_0x7f36('0x16')](function(_0x1275fe){if(_0x1275fe){_0xde1922=_0x1275fe;_0xd37a53[_0x7f36('0x2b')]=_[_0x7f36('0x2c')](db[_0x7f36('0x47')][_0x7f36('0x20')]);_0xd37a53[_0x7f36('0x25')]=_[_0x7f36('0x2c')](_0x29f092['query']);_0xd37a53[_0x7f36('0x42')]=_[_0x7f36('0x2d')](_0xd37a53[_0x7f36('0x2b')],_0xd37a53[_0x7f36('0x25')]);_0x587a66['attributes']=_[_0x7f36('0x2d')](_0xd37a53[_0x7f36('0x2b')],qs[_0x7f36('0x2f')](_0x29f092[_0x7f36('0x25')]['fields']));_0x587a66[_0x7f36('0x2e')]=_0x587a66[_0x7f36('0x2e')]['length']?_0x587a66[_0x7f36('0x2e')]:_0xd37a53['model'];_0x587a66['order']=qs[_0x7f36('0x41')](_0x29f092[_0x7f36('0x25')][_0x7f36('0x41')]);_0x587a66['where']=qs[_0x7f36('0x42')](_['pick'](_0x29f092['query'],_0xd37a53[_0x7f36('0x42')]));if(_0x29f092[_0x7f36('0x25')][_0x7f36('0x45')]){_0x587a66[_0x7f36('0x24')]=_['merge'](_0x587a66['where'],{'$or':_[_0x7f36('0x1e')](_0x587a66[_0x7f36('0x2e')],function(_0x3c28b3){var _0x451f6f={};_0x451f6f[_0x3c28b3]={'$like':'%'+_0x29f092[_0x7f36('0x25')][_0x7f36('0x45')]+'%'};return _0x451f6f;})});}_0x587a66=_[_0x7f36('0x32')]({},_0x587a66,_0x29f092[_0x7f36('0x53')]);return _0xde1922[_0x7f36('0x78')](_0x587a66);}})[_0x7f36('0x16')](function(_0x11e495){if(_0x11e495){_0xbcfecc=_0x11e495[_0x7f36('0x30')];if(!_0x29f092[_0x7f36('0x25')][_0x7f36('0x3e')](_0x7f36('0x3f'))){_0x587a66[_0x7f36('0x10')]=qs['limit'](_0x29f092[_0x7f36('0x25')]['limit']);_0x587a66[_0x7f36('0xe')]=qs[_0x7f36('0xe')](_0x29f092[_0x7f36('0x25')]['offset']);}return _0xde1922[_0x7f36('0x78')](_0x587a66);}})['then'](function(_0x16c709){if(_0x16c709){return _0x16c709?{'count':_0xbcfecc,'rows':_0x16c709}:null;}})[_0x7f36('0x16')](respondWithResult(_0x4ee50a,null))[_0x7f36('0x28')](handleError(_0x4ee50a,null));};