bba416e19302f9645c1f455a1fda9a6e02d515e3
[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 _0x15b2=['userChatQueue:save','select','field','tq.TeamId','from','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','QueryTypes','SELECT','every','TeamId','all','union','value','removeTeams','ids','isEmpty','removeAgents','userChatQueue:remove','addAgents','getAgents','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','redis','socket.io-emitter','./chatQueue.socket','register','jayson/promise','request','info','ChatQueue,\x20%s,\x20%s','request\x20sent','debug','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','code','error','message','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','reject','update','destroy','ChatQueues','UserProfileResource','then','stack','name','send','render','merge','body','contact','agent','index','map','ChatQueue','rawAttributes','fieldName','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','sort','pick','filter','where','type','options','includeAll','findAll','rows','show','params','find','create','user','get','UserProfileSection','userProfileId','autoAssociation','catch','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','findOne','UserChatQueue','length','User','findAndCountAll','UserId','chatPause','updatedAt','createdAt','format','%s/%s','SIP','Team','order','getTeams','addTeams','Agents','online','voicePause','interface','flatMap','sequelize','transaction','each','findOrCreate','forEach','emit'];(function(_0x55843a,_0x592001){var _0x159860=function(_0x479122){while(--_0x479122){_0x55843a['push'](_0x55843a['shift']());}};_0x159860(++_0x592001);}(_0x15b2,0x145));var _0x215b=function(_0x2110bb,_0x5bf49e){_0x2110bb=_0x2110bb-0x0;var _0x5cf87c=_0x15b2[_0x2110bb];return _0x5cf87c;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x215b('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x215b('0x1'));var rp=require(_0x215b('0x2'));var moment=require('moment');var BPromise=require(_0x215b('0x3'));var Mustache=require(_0x215b('0x4'));var util=require(_0x215b('0x5'));var path=require(_0x215b('0x6'));var sox=require('sox');var csv=require(_0x215b('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x215b('0x8'));var _=require(_0x215b('0x9'));var squel=require(_0x215b('0xa'));var crypto=require(_0x215b('0xb'));var jsforce=require(_0x215b('0xc'));var deskjs=require(_0x215b('0xd'));var toCsv=require('to-csv');var querystring=require(_0x215b('0xe'));var Papa=require(_0x215b('0xf'));var Redis=require('ioredis');var authService=require(_0x215b('0x10'));var qs=require(_0x215b('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x215b('0x12'))('api');var utils=require(_0x215b('0x13'));var config=require(_0x215b('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0x215b('0x15'))['db'];config['redis']=_['defaults'](config[_0x215b('0x16')],{'host':'localhost','port':0x18eb});var socket=require(_0x215b('0x17'))(new Redis(config['redis']));require(_0x215b('0x18'))[_0x215b('0x19')](socket);var jayson=require(_0x215b('0x1a'));var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x4c39d1,_0x1006fe,_0x1c4030,_0x2d04cb){return new BPromise(function(_0x2e96f5,_0x35508e){var _0x31a491=_0x2d04cb||client;return _0x31a491[_0x215b('0x1b')](_0x4c39d1,_0x1c4030)['then'](function(_0x31d565){logger[_0x215b('0x1c')](_0x215b('0x1d'),_0x1006fe,_0x215b('0x1e'));logger[_0x215b('0x1f')](_0x215b('0x20'),_0x1006fe,_0x215b('0x1e'),JSON[_0x215b('0x21')](_0x31d565));if(_0x31d565['error']){if(_0x31d565['error'][_0x215b('0x22')]===0x1f4){logger['error'](_0x215b('0x1d'),_0x1006fe,_0x31d565[_0x215b('0x23')][_0x215b('0x24')]);return _0x35508e(_0x31d565[_0x215b('0x23')][_0x215b('0x24')]);}logger[_0x215b('0x23')](_0x215b('0x1d'),_0x1006fe,_0x31d565[_0x215b('0x23')]['message']);return _0x2e96f5(_0x31d565['error'][_0x215b('0x24')]);}else{logger['info'](_0x215b('0x1d'),_0x1006fe,_0x215b('0x1e'));_0x2e96f5(_0x31d565['result'][_0x215b('0x24')]);}})['catch'](function(_0x43e2dd){logger[_0x215b('0x23')](_0x215b('0x1d'),_0x1006fe,_0x43e2dd);_0x35508e(_0x43e2dd);});});}function respondWithStatusCode(_0x245a36,_0x1f30b1){_0x1f30b1=_0x1f30b1||0xcc;return function(_0x2b02d1){if(_0x2b02d1){return _0x245a36[_0x215b('0x25')](_0x1f30b1);}return _0x245a36[_0x215b('0x26')](_0x1f30b1)['end']();};}function respondWithResult(_0xb623f9,_0x1f1a6f){_0x1f1a6f=_0x1f1a6f||0xc8;return function(_0x47d96d){if(_0x47d96d){return _0xb623f9[_0x215b('0x26')](_0x1f1a6f)[_0x215b('0x27')](_0x47d96d);}};}function respondWithFilteredResult(_0x1470ac,_0x5df10e){return function(_0x23ffca){if(_0x23ffca){var _0x41b373=typeof _0x5df10e[_0x215b('0x28')]===_0x215b('0x29')&&typeof _0x5df10e[_0x215b('0x2a')]===_0x215b('0x29');var _0x56e1ac=_0x23ffca[_0x215b('0x2b')];var _0x3903b7=_0x41b373?0x0:_0x5df10e[_0x215b('0x28')];var _0x1d449b=_0x41b373?_0x23ffca['count']:_0x5df10e['offset']+_0x5df10e['limit'];var _0x4f83a2;if(_0x1d449b>=_0x56e1ac){_0x1d449b=_0x56e1ac;_0x4f83a2=0xc8;}else{_0x4f83a2=0xce;}_0x1470ac['status'](_0x4f83a2);return _0x1470ac[_0x215b('0x2c')](_0x215b('0x2d'),_0x3903b7+'-'+_0x1d449b+'/'+_0x56e1ac)[_0x215b('0x27')](_0x23ffca);}return null;};}function patchUpdates(_0xd25833){return function(_0x58380f){try{jsonpatch['apply'](_0x58380f,_0xd25833,!![]);}catch(_0x558d0f){return BPromise[_0x215b('0x2e')](_0x558d0f);}return _0x58380f['save']();};}function saveUpdates(_0x4e4802,_0xf6eda){return function(_0x15e6e9){if(_0x15e6e9){return _0x15e6e9[_0x215b('0x2f')](_0x4e4802)['then'](function(_0x311ed0){return _0x311ed0;});}return null;};}function removeEntity(_0x29d522,_0x4f17aa){return function(_0x586668){if(_0x586668){return _0x586668[_0x215b('0x30')]()['then'](function(){var _0x8e63fc=_0x586668['get']({'plain':!![]});var _0x50ddf5=_0x215b('0x31');return db[_0x215b('0x32')][_0x215b('0x30')]({'where':{'type':_0x50ddf5,'resourceId':_0x8e63fc['id']}})['then'](function(){return _0x586668;});})[_0x215b('0x33')](function(){_0x29d522['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x210713,_0x133d07){return function(_0xbf51cb){if(!_0xbf51cb){_0x210713[_0x215b('0x25')](0x194);}return _0xbf51cb;};}function handleError(_0x20acb8,_0x215581){_0x215581=_0x215581||0x1f4;return function(_0x53ae3b){logger[_0x215b('0x23')](_0x53ae3b[_0x215b('0x34')]);if(_0x53ae3b['name']){delete _0x53ae3b[_0x215b('0x35')];}_0x20acb8[_0x215b('0x26')](_0x215581)[_0x215b('0x36')](_0x53ae3b);};}function getMustacheRender(_0xd72a58,_0x48ecbc){return Mustache[_0x215b('0x37')](_0xd72a58,_[_0x215b('0x38')](_0x48ecbc[_0x215b('0x39')],{'contact':_0x48ecbc[_0x215b('0x3a')],'message':_0x48ecbc[_0x215b('0x24')],'agent':_0x48ecbc[_0x215b('0x3b')],'interaction':_0x48ecbc['interaction'],'account':_0x48ecbc['account']}))||'';}exports[_0x215b('0x3c')]=function(_0x41ecf6,_0x5aaedd){var _0x927241={},_0x9e73cc={},_0x1cf253={'count':0x0,'rows':[]};var _0x4cdbfe=_[_0x215b('0x3d')](db[_0x215b('0x3e')][_0x215b('0x3f')],function(_0x5ee11b){return{'name':_0x5ee11b[_0x215b('0x40')],'type':_0x5ee11b['type']['key']};});_0x9e73cc[_0x215b('0x41')]=_[_0x215b('0x3d')](_0x4cdbfe,_0x215b('0x35'));_0x9e73cc['query']=_[_0x215b('0x42')](_0x41ecf6[_0x215b('0x43')]);_0x9e73cc[_0x215b('0x44')]=_[_0x215b('0x45')](_0x9e73cc['model'],_0x9e73cc[_0x215b('0x43')]);_0x927241[_0x215b('0x46')]=_[_0x215b('0x45')](_0x9e73cc[_0x215b('0x41')],qs[_0x215b('0x47')](_0x41ecf6['query'][_0x215b('0x47')]));_0x927241['attributes']=_0x927241[_0x215b('0x46')]['length']?_0x927241[_0x215b('0x46')]:_0x9e73cc[_0x215b('0x41')];if(!_0x41ecf6[_0x215b('0x43')][_0x215b('0x48')](_0x215b('0x49'))){_0x927241['limit']=qs['limit'](_0x41ecf6[_0x215b('0x43')]['limit']);_0x927241[_0x215b('0x28')]=qs[_0x215b('0x28')](_0x41ecf6[_0x215b('0x43')][_0x215b('0x28')]);}_0x927241['order']=qs[_0x215b('0x4a')](_0x41ecf6[_0x215b('0x43')][_0x215b('0x4a')]);_0x927241['where']=qs[_0x215b('0x44')](_[_0x215b('0x4b')](_0x41ecf6[_0x215b('0x43')],_0x9e73cc[_0x215b('0x44')]),_0x4cdbfe);if(_0x41ecf6['query'][_0x215b('0x4c')]){_0x927241['where']=_[_0x215b('0x38')](_0x927241[_0x215b('0x4d')],{'$or':_['map'](_0x4cdbfe,function(_0x45703f){if(_0x45703f[_0x215b('0x4e')]!=='VIRTUAL'){var _0x533571={};_0x533571[_0x45703f[_0x215b('0x35')]]={'$like':'%'+_0x41ecf6[_0x215b('0x43')][_0x215b('0x4c')]+'%'};return _0x533571;}})});}_0x927241=_['merge']({},_0x927241,_0x41ecf6[_0x215b('0x4f')]);var _0x3de6b9={'where':_0x927241[_0x215b('0x4d')]};return db[_0x215b('0x3e')]['count'](_0x3de6b9)[_0x215b('0x33')](function(_0x5ece9b){_0x1cf253[_0x215b('0x2b')]=_0x5ece9b;if(_0x41ecf6[_0x215b('0x43')][_0x215b('0x50')]){_0x927241['include']=[{'all':!![]}];}return db[_0x215b('0x3e')][_0x215b('0x51')](_0x927241);})['then'](function(_0x535f37){_0x1cf253[_0x215b('0x52')]=_0x535f37;return _0x1cf253;})[_0x215b('0x33')](respondWithFilteredResult(_0x5aaedd,_0x927241))['catch'](handleError(_0x5aaedd,null));};exports[_0x215b('0x53')]=function(_0x1f4317,_0x3504e5){var _0x30ea6a={'raw':!![],'where':{'id':_0x1f4317[_0x215b('0x54')]['id']}},_0x428215={};_0x428215[_0x215b('0x41')]=_['keys'](db['ChatQueue'][_0x215b('0x3f')]);_0x428215[_0x215b('0x43')]=_['keys'](_0x1f4317[_0x215b('0x43')]);_0x428215[_0x215b('0x44')]=_[_0x215b('0x45')](_0x428215[_0x215b('0x41')],_0x428215[_0x215b('0x43')]);_0x30ea6a['attributes']=_[_0x215b('0x45')](_0x428215[_0x215b('0x41')],qs[_0x215b('0x47')](_0x1f4317['query'][_0x215b('0x47')]));_0x30ea6a[_0x215b('0x46')]=_0x30ea6a[_0x215b('0x46')]['length']?_0x30ea6a['attributes']:_0x428215[_0x215b('0x41')];if(_0x1f4317['query'][_0x215b('0x50')]){_0x30ea6a['include']=[{'all':!![]}];}_0x30ea6a=_[_0x215b('0x38')]({},_0x30ea6a,_0x1f4317['options']);return db[_0x215b('0x3e')][_0x215b('0x55')](_0x30ea6a)['then'](handleEntityNotFound(_0x3504e5,null))[_0x215b('0x33')](respondWithResult(_0x3504e5,null))['catch'](handleError(_0x3504e5,null));};exports[_0x215b('0x56')]=function(_0x35b870,_0xe10156){return db[_0x215b('0x3e')]['create'](_0x35b870[_0x215b('0x39')],{})['then'](function(_0x2fa0cd){var _0x71df9f=_0x35b870[_0x215b('0x57')][_0x215b('0x58')]({'plain':!![]});if(!_0x71df9f)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x71df9f['role']===_0x215b('0x57')){var _0x474020=_0x2fa0cd[_0x215b('0x58')]({'plain':!![]});var _0x1b9aa5=_0x215b('0x31');return db[_0x215b('0x59')][_0x215b('0x55')]({'where':{'name':_0x1b9aa5,'userProfileId':_0x71df9f[_0x215b('0x5a')]},'raw':!![]})[_0x215b('0x33')](function(_0x483d6c){if(_0x483d6c&&_0x483d6c[_0x215b('0x5b')]===0x0){return db[_0x215b('0x32')][_0x215b('0x56')]({'name':_0x474020[_0x215b('0x35')],'resourceId':_0x474020['id'],'type':_0x483d6c[_0x215b('0x35')],'sectionId':_0x483d6c['id']},{})[_0x215b('0x33')](function(){return _0x2fa0cd;});}else{return _0x2fa0cd;}})[_0x215b('0x5c')](function(_0x19c629){logger[_0x215b('0x23')](_0x215b('0x5d'),_0x19c629);throw _0x19c629;});}return _0x2fa0cd;})[_0x215b('0x33')](respondWithResult(_0xe10156,0xc9))[_0x215b('0x5c')](handleError(_0xe10156,null));};exports[_0x215b('0x2f')]=function(_0x34a4af,_0x4f65c6){if(_0x34a4af[_0x215b('0x39')]['id']){delete _0x34a4af[_0x215b('0x39')]['id'];}return db[_0x215b('0x3e')][_0x215b('0x55')]({'where':{'id':_0x34a4af['params']['id']}})['then'](handleEntityNotFound(_0x4f65c6,null))[_0x215b('0x33')](saveUpdates(_0x34a4af[_0x215b('0x39')],null))[_0x215b('0x33')](respondWithResult(_0x4f65c6,null))[_0x215b('0x5c')](handleError(_0x4f65c6,null));};exports['destroy']=function(_0xf7497c,_0x5616d0){return db[_0x215b('0x3e')][_0x215b('0x55')]({'where':{'id':_0xf7497c[_0x215b('0x54')]['id']}})[_0x215b('0x33')](handleEntityNotFound(_0x5616d0,null))[_0x215b('0x33')](removeEntity(_0x5616d0,null))[_0x215b('0x5c')](handleError(_0x5616d0,null));};exports['describe']=function(_0x2328a2,_0x18e7bb){return db[_0x215b('0x3e')][_0x215b('0x5e')]()[_0x215b('0x33')](respondWithResult(_0x18e7bb,null))[_0x215b('0x5c')](handleError(_0x18e7bb,null));};exports['getMembers']=function(_0xe026c4,_0x3ff49d,_0x106595){var _0x50345f={'raw':!![],'where':{}},_0x1303d6={},_0x15d701;return db['ChatQueue'][_0x215b('0x5f')]({'where':{'id':_0xe026c4[_0x215b('0x54')]['id']}})['then'](handleEntityNotFound(_0x3ff49d,null))[_0x215b('0x33')](function(_0x1ce54d){if(_0x1ce54d){_0x15d701=_0x1ce54d['get']({'plain':!![]});_0x1303d6['model']=_[_0x215b('0x42')](db[_0x215b('0x60')]['rawAttributes']);_0x1303d6[_0x215b('0x43')]=_['keys'](_0xe026c4[_0x215b('0x43')]);_0x1303d6['filters']=_[_0x215b('0x45')](_0x1303d6[_0x215b('0x41')],_0x1303d6['query']);_0x50345f[_0x215b('0x46')]=_['intersection'](_0x1303d6[_0x215b('0x41')],qs[_0x215b('0x47')](_0xe026c4[_0x215b('0x43')][_0x215b('0x47')]));_0x50345f[_0x215b('0x46')]=_0x50345f[_0x215b('0x46')][_0x215b('0x61')]?_0x50345f[_0x215b('0x46')]:_0x1303d6[_0x215b('0x41')];if(!_0xe026c4['query'][_0x215b('0x48')]('nolimit')){_0x50345f[_0x215b('0x2a')]=qs[_0x215b('0x2a')](_0xe026c4[_0x215b('0x43')][_0x215b('0x2a')]);_0x50345f[_0x215b('0x28')]=qs[_0x215b('0x28')](_0xe026c4[_0x215b('0x43')]['offset']);}_0x50345f['order']=qs[_0x215b('0x4a')](_0xe026c4['query'][_0x215b('0x4a')]);_0x50345f[_0x215b('0x4d')]=qs[_0x215b('0x44')](_[_0x215b('0x4b')](_0xe026c4['query'],_0x1303d6[_0x215b('0x44')]));_0x50345f[_0x215b('0x4d')]['ChatQueueId']=_0x1ce54d['id'];if(_0xe026c4['query'][_0x215b('0x4c')]){_0x50345f[_0x215b('0x4d')]=_['merge'](_0x50345f[_0x215b('0x4d')],{'$or':_[_0x215b('0x3d')](_0x50345f[_0x215b('0x46')],function(_0x483e5e){var _0x2e8a49={};_0x2e8a49[_0x483e5e]={'$like':'%'+_0xe026c4[_0x215b('0x43')]['filter']+'%'};return _0x2e8a49;})});}_0x50345f=_[_0x215b('0x38')]({},_0x50345f,_0xe026c4[_0x215b('0x4f')]);return db[_0x215b('0x60')][_0x215b('0x51')](_0x50345f);}})[_0x215b('0x33')](function(_0x473b8d){if(_0x473b8d){return db[_0x215b('0x62')][_0x215b('0x63')]({'where':{'id':_[_0x215b('0x3d')](_0x473b8d,_0x215b('0x64')),'role':'agent'},'attributes':['id',_0x215b('0x35'),_0x215b('0x65'),_0x215b('0x66'),_0x215b('0x67')]});}})[_0x215b('0x33')](function(_0x2c581d){if(_0x2c581d){return{'count':_0x2c581d[_0x215b('0x2b')],'rows':_[_0x215b('0x3d')](_0x2c581d[_0x215b('0x52')],function(_0x399f34){return{'membername':_0x399f34['name'],'UserId':_0x399f34['id'],'queue_name':_0x15d701[_0x215b('0x35')],'ChatQueueId':_0x15d701['id'],'interface':util[_0x215b('0x68')](_0x215b('0x69'),_0x215b('0x6a'),_0x399f34[_0x215b('0x35')]),'penalty':0x0,'paused':_0x399f34[_0x215b('0x65')],'createdAt':_0x399f34[_0x215b('0x67')],'updatedAt':_0x399f34[_0x215b('0x66')]};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x3ff49d,_0x50345f))[_0x215b('0x5c')](handleError(_0x3ff49d,null));};exports['getTeams']=function(_0x2f5654,_0x4ee4a1,_0x114ce3){var _0x4546c5={};var _0x3f77c0={};var _0x42ca65;var _0x56cf5f;return db[_0x215b('0x3e')]['findOne']({'where':{'id':_0x2f5654[_0x215b('0x54')]['id']}})['then'](handleEntityNotFound(_0x4ee4a1,null))[_0x215b('0x33')](function(_0x1cf9e6){if(_0x1cf9e6){_0x42ca65=_0x1cf9e6;_0x3f77c0[_0x215b('0x41')]=_[_0x215b('0x42')](db[_0x215b('0x6b')]['rawAttributes']);_0x3f77c0['query']=_[_0x215b('0x42')](_0x2f5654[_0x215b('0x43')]);_0x3f77c0['filters']=_[_0x215b('0x45')](_0x3f77c0['model'],_0x3f77c0[_0x215b('0x43')]);_0x4546c5[_0x215b('0x46')]=_[_0x215b('0x45')](_0x3f77c0[_0x215b('0x41')],qs[_0x215b('0x47')](_0x2f5654[_0x215b('0x43')][_0x215b('0x47')]));_0x4546c5[_0x215b('0x46')]=_0x4546c5[_0x215b('0x46')]['length']?_0x4546c5[_0x215b('0x46')]:_0x3f77c0[_0x215b('0x41')];_0x4546c5[_0x215b('0x6c')]=qs[_0x215b('0x4a')](_0x2f5654[_0x215b('0x43')][_0x215b('0x4a')]);_0x4546c5[_0x215b('0x4d')]=qs[_0x215b('0x44')](_[_0x215b('0x4b')](_0x2f5654['query'],_0x3f77c0[_0x215b('0x44')]));if(_0x2f5654['query']['filter']){_0x4546c5[_0x215b('0x4d')]=_[_0x215b('0x38')](_0x4546c5[_0x215b('0x4d')],{'$or':_[_0x215b('0x3d')](_0x4546c5[_0x215b('0x46')],function(_0x13b78a){var _0x3f3cb0={};_0x3f3cb0[_0x13b78a]={'$like':'%'+_0x2f5654[_0x215b('0x43')]['filter']+'%'};return _0x3f3cb0;})});}_0x4546c5=_['merge']({},_0x4546c5,_0x2f5654[_0x215b('0x4f')]);return _0x42ca65[_0x215b('0x6d')](_0x4546c5);}})[_0x215b('0x33')](function(_0x5d8d0b){if(_0x5d8d0b){_0x56cf5f=_0x5d8d0b[_0x215b('0x61')];if(!_0x2f5654[_0x215b('0x43')][_0x215b('0x48')]('nolimit')){_0x4546c5[_0x215b('0x2a')]=qs['limit'](_0x2f5654[_0x215b('0x43')]['limit']);_0x4546c5['offset']=qs[_0x215b('0x28')](_0x2f5654['query'][_0x215b('0x28')]);}return _0x42ca65['getTeams'](_0x4546c5);}})[_0x215b('0x33')](function(_0x1358e6){if(_0x1358e6){return _0x1358e6?{'count':_0x56cf5f,'rows':_0x1358e6}:null;}})['then'](respondWithResult(_0x4ee4a1,null))[_0x215b('0x5c')](handleError(_0x4ee4a1,null));};exports[_0x215b('0x6e')]=function(_0x3d5a73,_0xd9ccc3,_0x4cbc0e){var _0x2a3702=_0x3d5a73[_0x215b('0x39')]['ids'];return db[_0x215b('0x6b')][_0x215b('0x51')]({'where':{'id':_0x2a3702},'attributes':['id'],'include':[{'model':db[_0x215b('0x62')],'as':_0x215b('0x6f'),'attributes':['id',_0x215b('0x35'),_0x215b('0x70'),_0x215b('0x71'),_0x215b('0x72')],'raw':!![]}]})[_0x215b('0x33')](function(_0x3888fa){if(_0x3888fa){var _0x30f7bc=_[_0x215b('0x73')](_0x3888fa,function(_0x42f99a){var _0x17b9a0=_0x42f99a[_0x215b('0x58')]({'plain':!![]});return _0x17b9a0[_0x215b('0x6f')];});return db[_0x215b('0x3e')][_0x215b('0x55')]({'where':{'id':_0x3d5a73[_0x215b('0x54')]['id']}})[_0x215b('0x33')](function(_0x4f6891){return db[_0x215b('0x74')][_0x215b('0x75')](function(_0x55a7ef){return _0x4f6891['addTeams'](_0x2a3702,{'transaction':_0x55a7ef})[_0x215b('0x33')](function(){return BPromise[_0x215b('0x76')](_0x30f7bc,function(_0x1b8954){return db[_0x215b('0x60')][_0x215b('0x77')]({'where':{'UserId':_0x1b8954['id'],'ChatQueueId':_0x3d5a73[_0x215b('0x54')]['id']},'transaction':_0x55a7ef});});})[_0x215b('0x33')](function(){_0x30f7bc[_0x215b('0x78')](function(_0x287abb){socket[_0x215b('0x79')](_0x215b('0x7a'),{'UserId':_0x287abb['id'],'ChatQueueId':_0x4f6891['id']});});});});});}})[_0x215b('0x33')](respondWithStatusCode(_0xd9ccc3,null))['catch'](handleError(_0xd9ccc3,null));};exports['removeTeams']=function(_0x24581d,_0x356392,_0x278df7){return db[_0x215b('0x6b')][_0x215b('0x51')]({'where':{'id':_0x24581d['query']['ids']},'attributes':['id'],'include':[{'model':db['User'],'as':_0x215b('0x6f'),'attributes':['id'],'raw':!![]}]})[_0x215b('0x33')](handleEntityNotFound(_0x356392,null))[_0x215b('0x33')](function(_0x11c1db){var _0x30b6db=_[_0x215b('0x3d')](_0x11c1db,'id');var _0xc3a727=[];var _0x728d45=[];var _0x1726d8=squel[_0x215b('0x7b')]();_0x1726d8[_0x215b('0x7c')](_0x215b('0x7d'))[_0x215b('0x7e')]('team_has_chat_queues','tq')[_0x215b('0x7f')](_0x215b('0x80'),'ut',_0x215b('0x81'))[_0x215b('0x4d')](_0x215b('0x82'),_0x24581d['params']['id']);for(var _0x259c7e=0x0;_0x259c7e<_0x11c1db[_0x215b('0x61')];_0x259c7e+=0x1){let _0x4152c4=_0x11c1db[_0x259c7e];for(var _0x39827d=0x0;_0x39827d<_0x4152c4[_0x215b('0x6f')][_0x215b('0x61')];_0x39827d+=0x1){let _0x1da22e=_0x4152c4[_0x215b('0x6f')][_0x39827d];var _0x5c6a60=_0x1726d8[_0x215b('0x83')]();_0x5c6a60['where'](_0x215b('0x84'),_0x1da22e['id']);_0x728d45[_0x215b('0x85')](db[_0x215b('0x74')][_0x215b('0x43')](_0x5c6a60[_0x215b('0x86')](),{'type':db[_0x215b('0x74')][_0x215b('0x87')][_0x215b('0x88')]})['then'](function(_0x22e37e){if(_0x22e37e[_0x215b('0x61')]===0x1){return _0x1da22e['id'];}else{var _0x5b9165=_[_0x215b('0x89')](_[_0x215b('0x3d')](_0x22e37e,_0x215b('0x8a')),function(_0x571633){return _['includes'](_0x30b6db,_0x571633);});if(_0x5b9165){return _0x1da22e['id'];}}}));}}return BPromise[_0x215b('0x8b')](_0x728d45)['then'](function(_0x47bc67){_0xc3a727=_(_0xc3a727)[_0x215b('0x8c')](_0x47bc67)['compact']()[_0x215b('0x8d')]();return db[_0x215b('0x3e')][_0x215b('0x55')]({'where':{'id':_0x24581d['params']['id']}})['then'](function(_0x4b9b2f){return db[_0x215b('0x74')][_0x215b('0x75')](function(_0x292b60){return _0x4b9b2f[_0x215b('0x8e')](_0x24581d[_0x215b('0x43')][_0x215b('0x8f')],{'transaction':_0x292b60})['then'](function(){if(!_[_0x215b('0x90')](_0xc3a727)){return _0x4b9b2f[_0x215b('0x91')](_0xc3a727,{'transaction':_0x292b60});}})[_0x215b('0x33')](function(){_0xc3a727[_0x215b('0x78')](function(_0x46c7b9){socket[_0x215b('0x79')](_0x215b('0x92'),{'UserId':_0x46c7b9,'ChatQueueId':_0x4b9b2f['id']});});});});});});})[_0x215b('0x33')](respondWithStatusCode(_0x356392,null))[_0x215b('0x5c')](handleError(_0x356392,null));};exports['addAgents']=function(_0x224662,_0x27022f,_0x16eef8){return db[_0x215b('0x3e')][_0x215b('0x55')]({'where':{'id':_0x224662[_0x215b('0x54')]['id']}})['then'](handleEntityNotFound(_0x27022f,null))[_0x215b('0x33')](function(_0x52789a){if(_0x52789a){return _0x52789a[_0x215b('0x93')](_0x224662[_0x215b('0x39')]['ids'],_['omit'](_0x224662[_0x215b('0x39')],[_0x215b('0x8f'),'id'])||{})['spread'](function(_0x523330){for(var _0x3f7ff4=0x0;_0x3f7ff4<_0x224662[_0x215b('0x39')][_0x215b('0x8f')][_0x215b('0x61')];_0x3f7ff4+=0x1){socket[_0x215b('0x79')](_0x215b('0x7a'),{'UserId':_0x224662[_0x215b('0x39')][_0x215b('0x8f')][_0x3f7ff4],'ChatQueueId':_0x224662[_0x215b('0x54')]['id']});}return _0x523330;});}})[_0x215b('0x33')](respondWithResult(_0x27022f,null))[_0x215b('0x5c')](handleError(_0x27022f,null));};exports[_0x215b('0x91')]=function(_0x16401e,_0x16ed47,_0x5aafe8){return db[_0x215b('0x3e')][_0x215b('0x55')]({'where':{'id':_0x16401e[_0x215b('0x54')]['id']}})['then'](handleEntityNotFound(_0x16ed47,null))[_0x215b('0x33')](function(_0x3d8642){if(_0x3d8642){return _0x3d8642[_0x215b('0x91')](_0x16401e['query'][_0x215b('0x8f')])[_0x215b('0x33')](function(){if(_['isArray'](_0x16401e[_0x215b('0x43')][_0x215b('0x8f')])){for(var _0x5641c1=0x0;_0x5641c1<_0x16401e['query']['ids'][_0x215b('0x61')];_0x5641c1+=0x1){socket[_0x215b('0x79')](_0x215b('0x92'),{'UserId':Number(_0x16401e[_0x215b('0x43')][_0x215b('0x8f')][_0x5641c1]),'ChatQueueId':Number(_0x16401e[_0x215b('0x54')]['id'])});}}else{socket['emit']('userChatQueue:remove',{'UserId':Number(_0x16401e['query']['ids']),'ChatQueueId':Number(_0x16401e[_0x215b('0x54')]['id'])});}});}})['then'](respondWithStatusCode(_0x16ed47,null))[_0x215b('0x5c')](handleError(_0x16ed47,null));};exports[_0x215b('0x94')]=function(_0x4531f6,_0x4f534a,_0x32db83){var _0x3a936f={};var _0x265e65={};var _0x5624df;var _0x7e18d5;return db['ChatQueue'][_0x215b('0x5f')]({'where':{'id':_0x4531f6['params']['id']}})[_0x215b('0x33')](handleEntityNotFound(_0x4f534a,null))[_0x215b('0x33')](function(_0x34d065){if(_0x34d065){_0x5624df=_0x34d065;_0x265e65[_0x215b('0x41')]=_['keys'](db['User'][_0x215b('0x3f')]);_0x265e65[_0x215b('0x43')]=_['keys'](_0x4531f6[_0x215b('0x43')]);_0x265e65['filters']=_[_0x215b('0x45')](_0x265e65[_0x215b('0x41')],_0x265e65['query']);_0x3a936f[_0x215b('0x46')]=_[_0x215b('0x45')](_0x265e65[_0x215b('0x41')],qs[_0x215b('0x47')](_0x4531f6[_0x215b('0x43')][_0x215b('0x47')]));_0x3a936f[_0x215b('0x46')]=_0x3a936f[_0x215b('0x46')][_0x215b('0x61')]?_0x3a936f[_0x215b('0x46')]:_0x265e65[_0x215b('0x41')];_0x3a936f['order']=qs['sort'](_0x4531f6[_0x215b('0x43')][_0x215b('0x4a')]);_0x3a936f[_0x215b('0x4d')]=qs[_0x215b('0x44')](_['pick'](_0x4531f6[_0x215b('0x43')],_0x265e65[_0x215b('0x44')]));if(_0x4531f6[_0x215b('0x43')][_0x215b('0x4c')]){_0x3a936f[_0x215b('0x4d')]=_[_0x215b('0x38')](_0x3a936f[_0x215b('0x4d')],{'$or':_[_0x215b('0x3d')](_0x3a936f[_0x215b('0x46')],function(_0x435e38){var _0x3f6dec={};_0x3f6dec[_0x435e38]={'$like':'%'+_0x4531f6[_0x215b('0x43')]['filter']+'%'};return _0x3f6dec;})});}_0x3a936f=_[_0x215b('0x38')]({},_0x3a936f,_0x4531f6['options']);return _0x5624df['getAgents'](_0x3a936f);}})[_0x215b('0x33')](function(_0x3f54f7){if(_0x3f54f7){_0x7e18d5=_0x3f54f7['length'];if(!_0x4531f6[_0x215b('0x43')]['hasOwnProperty'](_0x215b('0x49'))){_0x3a936f[_0x215b('0x2a')]=qs[_0x215b('0x2a')](_0x4531f6[_0x215b('0x43')]['limit']);_0x3a936f[_0x215b('0x28')]=qs[_0x215b('0x28')](_0x4531f6['query'][_0x215b('0x28')]);}return _0x5624df['getAgents'](_0x3a936f);}})[_0x215b('0x33')](function(_0x4b296a){if(_0x4b296a){return _0x4b296a?{'count':_0x7e18d5,'rows':_0x4b296a}:null;}})[_0x215b('0x33')](respondWithResult(_0x4f534a,null))['catch'](handleError(_0x4f534a,null));};