Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / chatQueue / chatQueue.controller.js
index 2dc0713..12a9b88 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3cdd=['merge','options','includeAll','include','rows','show','params','rawAttributes','intersection','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','ChatQueues','UserProfileSection','userProfileId','autoAssociation','update','body','describe','getMembers','findOne','UserChatQueue','length','pick','findAll','User','findAndCountAll','UserId','agent','chatPause','updatedAt','createdAt','%s/%s','getTeams','Team','Agents','online','voicePause','interface','flatMap','transaction','addTeams','userChatQueue:save','removeTeams','select','field','tq.TeamId','from','team_has_chat_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','push','sequelize','QueryTypes','all','union','compact','value','ids','isEmpty','forEach','emit','userChatQueue:remove','addAgents','spread','removeAgents','isArray','getAgents','eml-format','zip-dir','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','./chatQueue.socket','register','client','http','request','then','info','ChatQueue,\x20%s,\x20%s','request\x20sent','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','code','error','message','result','catch','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','get','UserProfileResource','destroy','name','send','index','map','ChatQueue','fieldName','type','key','query','keys','filters','model','fields','attributes','hasOwnProperty','nolimit','order','sort','where','filter','VIRTUAL'];(function(_0x232cf2,_0x4ffb79){var _0x463cec=function(_0x581b60){while(--_0x581b60){_0x232cf2['push'](_0x232cf2['shift']());}};_0x463cec(++_0x4ffb79);}(_0x3cdd,0x176));var _0xd3cd=function(_0x4f4695,_0x440225){_0x4f4695=_0x4f4695-0x0;var _0x1674f8=_0x3cdd[_0x4f4695];return _0x1674f8;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xd3cd('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xd3cd('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xd3cd('0x2'));var BPromise=require(_0xd3cd('0x3'));var Mustache=require(_0xd3cd('0x4'));var util=require(_0xd3cd('0x5'));var path=require(_0xd3cd('0x6'));var sox=require(_0xd3cd('0x7'));var csv=require(_0xd3cd('0x8'));var ejs=require(_0xd3cd('0x9'));var fs=require('fs');var _=require(_0xd3cd('0xa'));var squel=require(_0xd3cd('0xb'));var crypto=require(_0xd3cd('0xc'));var jsforce=require(_0xd3cd('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xd3cd('0x8'));var querystring=require('querystring');var Papa=require(_0xd3cd('0xe'));var Redis=require(_0xd3cd('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xd3cd('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xd3cd('0x11'));var logger=require(_0xd3cd('0x12'))(_0xd3cd('0x13'));var utils=require(_0xd3cd('0x14'));var config=require(_0xd3cd('0x15'));var licenseUtil=require(_0xd3cd('0x16'));var db=require(_0xd3cd('0x17'))['db'];config['redis']=_[_0xd3cd('0x18')](config[_0xd3cd('0x19')],{'host':_0xd3cd('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xd3cd('0x19')]));require(_0xd3cd('0x1b'))[_0xd3cd('0x1c')](socket);var jayson=require('jayson/promise');var client=jayson[_0xd3cd('0x1d')][_0xd3cd('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x371b2a,_0x37b299,_0x2cbc42,_0x50cfc6){return new BPromise(function(_0x1b1d70,_0x3b2591){var _0x1418e8=_0x50cfc6||client;return _0x1418e8[_0xd3cd('0x1f')](_0x371b2a,_0x2cbc42)[_0xd3cd('0x20')](function(_0x28062b){logger[_0xd3cd('0x21')](_0xd3cd('0x22'),_0x37b299,_0xd3cd('0x23'));logger['debug'](_0xd3cd('0x24'),_0x37b299,_0xd3cd('0x23'),JSON[_0xd3cd('0x25')](_0x28062b));if(_0x28062b['error']){if(_0x28062b['error'][_0xd3cd('0x26')]===0x1f4){logger['error'](_0xd3cd('0x22'),_0x37b299,_0x28062b[_0xd3cd('0x27')][_0xd3cd('0x28')]);return _0x3b2591(_0x28062b[_0xd3cd('0x27')][_0xd3cd('0x28')]);}logger[_0xd3cd('0x27')]('ChatQueue,\x20%s,\x20%s',_0x37b299,_0x28062b[_0xd3cd('0x27')][_0xd3cd('0x28')]);return _0x1b1d70(_0x28062b[_0xd3cd('0x27')][_0xd3cd('0x28')]);}else{logger[_0xd3cd('0x21')]('ChatQueue,\x20%s,\x20%s',_0x37b299,_0xd3cd('0x23'));_0x1b1d70(_0x28062b[_0xd3cd('0x29')][_0xd3cd('0x28')]);}})[_0xd3cd('0x2a')](function(_0x221144){logger[_0xd3cd('0x27')]('ChatQueue,\x20%s,\x20%s',_0x37b299,_0x221144);_0x3b2591(_0x221144);});});}function respondWithStatusCode(_0x3f3111,_0x1b3f6e){_0x1b3f6e=_0x1b3f6e||0xcc;return function(_0x4e2517){if(_0x4e2517){return _0x3f3111[_0xd3cd('0x2b')](_0x1b3f6e);}return _0x3f3111[_0xd3cd('0x2c')](_0x1b3f6e)[_0xd3cd('0x2d')]();};}function respondWithResult(_0x489c15,_0x6c7987){_0x6c7987=_0x6c7987||0xc8;return function(_0x52c982){if(_0x52c982){return _0x489c15[_0xd3cd('0x2c')](_0x6c7987)[_0xd3cd('0x2e')](_0x52c982);}};}function respondWithFilteredResult(_0x392e99,_0x5729f8){return function(_0x28333a){if(_0x28333a){var _0x364bf3=_0x28333a[_0xd3cd('0x2f')],_0x2ef240=_0x5729f8[_0xd3cd('0x30')],_0x314ea6=_0x5729f8['offset']+_0x5729f8[_0xd3cd('0x31')],_0x494ad4;if(_0x314ea6>=_0x364bf3){_0x314ea6=_0x364bf3;_0x494ad4=0xc8;}else{_0x494ad4=0xce;}_0x392e99['status'](_0x494ad4);return _0x392e99[_0xd3cd('0x32')](_0xd3cd('0x33'),_0x2ef240+'-'+_0x314ea6+'/'+_0x364bf3)[_0xd3cd('0x2e')](_0x28333a);}return null;};}function patchUpdates(_0x5a0d27){return function(_0x36a06e){try{jsonpatch[_0xd3cd('0x34')](_0x36a06e,_0x5a0d27,!![]);}catch(_0x5e99a2){return BPromise[_0xd3cd('0x35')](_0x5e99a2);}return _0x36a06e[_0xd3cd('0x36')]();};}function saveUpdates(_0x4fb2ad,_0x44e630){return function(_0x3aeab9){if(_0x3aeab9){return _0x3aeab9['update'](_0x4fb2ad)[_0xd3cd('0x20')](function(_0x2abe45){return _0x2abe45;});}return null;};}function removeEntity(_0x388987,_0x1a744b){return function(_0xf6c32d){if(_0xf6c32d){return _0xf6c32d['destroy']()[_0xd3cd('0x20')](function(){var _0x2bb1af=_0xf6c32d[_0xd3cd('0x37')]({'plain':!![]});var _0x3ee6fb='ChatQueues';return db[_0xd3cd('0x38')][_0xd3cd('0x39')]({'where':{'type':_0x3ee6fb,'resourceId':_0x2bb1af['id']}})[_0xd3cd('0x20')](function(){return _0xf6c32d;});})[_0xd3cd('0x20')](function(){_0x388987[_0xd3cd('0x2c')](0xcc)[_0xd3cd('0x2d')]();});}};}function handleEntityNotFound(_0x8ca3f6,_0x26b9c4){return function(_0x2f1277){if(!_0x2f1277){_0x8ca3f6[_0xd3cd('0x2b')](0x194);}return _0x2f1277;};}function handleError(_0x5d1f27,_0x402ccf){_0x402ccf=_0x402ccf||0x1f4;return function(_0xa04edf){logger[_0xd3cd('0x27')](_0xa04edf['stack']);if(_0xa04edf[_0xd3cd('0x3a')]){delete _0xa04edf['name'];}_0x5d1f27[_0xd3cd('0x2c')](_0x402ccf)[_0xd3cd('0x3b')](_0xa04edf);};}exports[_0xd3cd('0x3c')]=function(_0x24ac3d,_0x11aeaf){var _0x168324={},_0x1e6af5={},_0x22543f={'count':0x0,'rows':[]};var _0x25e4c3=_[_0xd3cd('0x3d')](db[_0xd3cd('0x3e')]['rawAttributes'],function(_0x48556c){return{'name':_0x48556c[_0xd3cd('0x3f')],'type':_0x48556c[_0xd3cd('0x40')][_0xd3cd('0x41')]};});_0x1e6af5['model']=_['map'](_0x25e4c3,'name');_0x1e6af5[_0xd3cd('0x42')]=_[_0xd3cd('0x43')](_0x24ac3d[_0xd3cd('0x42')]);_0x1e6af5[_0xd3cd('0x44')]=_['intersection'](_0x1e6af5[_0xd3cd('0x45')],_0x1e6af5[_0xd3cd('0x42')]);_0x168324['attributes']=_['intersection'](_0x1e6af5[_0xd3cd('0x45')],qs[_0xd3cd('0x46')](_0x24ac3d[_0xd3cd('0x42')][_0xd3cd('0x46')]));_0x168324[_0xd3cd('0x47')]=_0x168324[_0xd3cd('0x47')]['length']?_0x168324['attributes']:_0x1e6af5['model'];if(!_0x24ac3d[_0xd3cd('0x42')][_0xd3cd('0x48')](_0xd3cd('0x49'))){_0x168324['limit']=qs[_0xd3cd('0x31')](_0x24ac3d[_0xd3cd('0x42')][_0xd3cd('0x31')]);_0x168324['offset']=qs[_0xd3cd('0x30')](_0x24ac3d[_0xd3cd('0x42')]['offset']);}_0x168324[_0xd3cd('0x4a')]=qs[_0xd3cd('0x4b')](_0x24ac3d['query'][_0xd3cd('0x4b')]);_0x168324[_0xd3cd('0x4c')]=qs[_0xd3cd('0x44')](_['pick'](_0x24ac3d[_0xd3cd('0x42')],_0x1e6af5[_0xd3cd('0x44')]),_0x25e4c3);if(_0x24ac3d[_0xd3cd('0x42')][_0xd3cd('0x4d')]){_0x168324[_0xd3cd('0x4c')]=_['merge'](_0x168324[_0xd3cd('0x4c')],{'$or':_[_0xd3cd('0x3d')](_0x25e4c3,function(_0x557f9f){if(_0x557f9f['type']!==_0xd3cd('0x4e')){var _0x12e8e1={};_0x12e8e1[_0x557f9f[_0xd3cd('0x3a')]]={'$like':'%'+_0x24ac3d[_0xd3cd('0x42')][_0xd3cd('0x4d')]+'%'};return _0x12e8e1;}})});}_0x168324=_[_0xd3cd('0x4f')]({},_0x168324,_0x24ac3d[_0xd3cd('0x50')]);var _0x27f0af={'where':_0x168324[_0xd3cd('0x4c')]};return db[_0xd3cd('0x3e')][_0xd3cd('0x2f')](_0x27f0af)['then'](function(_0x312572){_0x22543f['count']=_0x312572;if(_0x24ac3d['query'][_0xd3cd('0x51')]){_0x168324[_0xd3cd('0x52')]=[{'all':!![]}];}return db[_0xd3cd('0x3e')]['findAll'](_0x168324);})['then'](function(_0x676813){_0x22543f[_0xd3cd('0x53')]=_0x676813;return _0x22543f;})[_0xd3cd('0x20')](respondWithFilteredResult(_0x11aeaf,_0x168324))[_0xd3cd('0x2a')](handleError(_0x11aeaf,null));};exports[_0xd3cd('0x54')]=function(_0x243ed1,_0x5e3725){var _0x5e3b35={'raw':!![],'where':{'id':_0x243ed1[_0xd3cd('0x55')]['id']}},_0x52a0a1={};_0x52a0a1[_0xd3cd('0x45')]=_['keys'](db[_0xd3cd('0x3e')][_0xd3cd('0x56')]);_0x52a0a1[_0xd3cd('0x42')]=_[_0xd3cd('0x43')](_0x243ed1['query']);_0x52a0a1[_0xd3cd('0x44')]=_[_0xd3cd('0x57')](_0x52a0a1[_0xd3cd('0x45')],_0x52a0a1[_0xd3cd('0x42')]);_0x5e3b35[_0xd3cd('0x47')]=_['intersection'](_0x52a0a1[_0xd3cd('0x45')],qs[_0xd3cd('0x46')](_0x243ed1[_0xd3cd('0x42')]['fields']));_0x5e3b35[_0xd3cd('0x47')]=_0x5e3b35[_0xd3cd('0x47')]['length']?_0x5e3b35[_0xd3cd('0x47')]:_0x52a0a1[_0xd3cd('0x45')];if(_0x243ed1[_0xd3cd('0x42')][_0xd3cd('0x51')]){_0x5e3b35[_0xd3cd('0x52')]=[{'all':!![]}];}_0x5e3b35=_[_0xd3cd('0x4f')]({},_0x5e3b35,_0x243ed1[_0xd3cd('0x50')]);return db['ChatQueue'][_0xd3cd('0x58')](_0x5e3b35)[_0xd3cd('0x20')](handleEntityNotFound(_0x5e3725,null))[_0xd3cd('0x20')](respondWithResult(_0x5e3725,null))['catch'](handleError(_0x5e3725,null));};exports[_0xd3cd('0x59')]=function(_0x27072b,_0x12e29e){return db[_0xd3cd('0x3e')][_0xd3cd('0x59')](_0x27072b['body'],{})[_0xd3cd('0x20')](function(_0x319891){var _0x184f97=_0x27072b[_0xd3cd('0x5a')][_0xd3cd('0x37')]({'plain':!![]});if(!_0x184f97)throw new Error(_0xd3cd('0x5b'));if(_0x184f97['role']===_0xd3cd('0x5a')){var _0x53c7ca=_0x319891[_0xd3cd('0x37')]({'plain':!![]});var _0xc5691d=_0xd3cd('0x5c');return db[_0xd3cd('0x5d')][_0xd3cd('0x58')]({'where':{'name':_0xc5691d,'userProfileId':_0x184f97[_0xd3cd('0x5e')]},'raw':!![]})['then'](function(_0x4cb0c8){if(_0x4cb0c8&&_0x4cb0c8[_0xd3cd('0x5f')]===0x0){return db['UserProfileResource'][_0xd3cd('0x59')]({'name':_0x53c7ca[_0xd3cd('0x3a')],'resourceId':_0x53c7ca['id'],'type':_0x4cb0c8[_0xd3cd('0x3a')],'sectionId':_0x4cb0c8['id']},{})[_0xd3cd('0x20')](function(){return _0x319891;});}else{return _0x319891;}})['catch'](function(_0x16dd22){logger[_0xd3cd('0x27')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x16dd22);throw _0x16dd22;});}return _0x319891;})[_0xd3cd('0x20')](respondWithResult(_0x12e29e,0xc9))[_0xd3cd('0x2a')](handleError(_0x12e29e,null));};exports[_0xd3cd('0x60')]=function(_0x2c66f1,_0x5b8f1d){if(_0x2c66f1['body']['id']){delete _0x2c66f1[_0xd3cd('0x61')]['id'];}return db[_0xd3cd('0x3e')][_0xd3cd('0x58')]({'where':{'id':_0x2c66f1['params']['id']}})[_0xd3cd('0x20')](handleEntityNotFound(_0x5b8f1d,null))[_0xd3cd('0x20')](saveUpdates(_0x2c66f1[_0xd3cd('0x61')],null))['then'](respondWithResult(_0x5b8f1d,null))[_0xd3cd('0x2a')](handleError(_0x5b8f1d,null));};exports['destroy']=function(_0x2edf7c,_0x54d649){return db[_0xd3cd('0x3e')][_0xd3cd('0x58')]({'where':{'id':_0x2edf7c[_0xd3cd('0x55')]['id']}})[_0xd3cd('0x20')](handleEntityNotFound(_0x54d649,null))[_0xd3cd('0x20')](removeEntity(_0x54d649,null))[_0xd3cd('0x2a')](handleError(_0x54d649,null));};exports[_0xd3cd('0x62')]=function(_0x3eae2a,_0x5ed138){return db[_0xd3cd('0x3e')][_0xd3cd('0x62')]()['then'](respondWithResult(_0x5ed138,null))[_0xd3cd('0x2a')](handleError(_0x5ed138,null));};exports[_0xd3cd('0x63')]=function(_0x38a2ee,_0x279674,_0x334fd6){var _0x12a6d3={'raw':!![],'where':{}},_0xff8bdf={},_0x36aa70;return db['ChatQueue'][_0xd3cd('0x64')]({'where':{'id':_0x38a2ee[_0xd3cd('0x55')]['id']}})[_0xd3cd('0x20')](handleEntityNotFound(_0x279674,null))['then'](function(_0x41614a){if(_0x41614a){_0x36aa70=_0x41614a['get']({'plain':!![]});_0xff8bdf['model']=_['keys'](db[_0xd3cd('0x65')][_0xd3cd('0x56')]);_0xff8bdf[_0xd3cd('0x42')]=_[_0xd3cd('0x43')](_0x38a2ee[_0xd3cd('0x42')]);_0xff8bdf['filters']=_['intersection'](_0xff8bdf[_0xd3cd('0x45')],_0xff8bdf['query']);_0x12a6d3[_0xd3cd('0x47')]=_[_0xd3cd('0x57')](_0xff8bdf[_0xd3cd('0x45')],qs[_0xd3cd('0x46')](_0x38a2ee['query']['fields']));_0x12a6d3['attributes']=_0x12a6d3[_0xd3cd('0x47')][_0xd3cd('0x66')]?_0x12a6d3['attributes']:_0xff8bdf[_0xd3cd('0x45')];if(!_0x38a2ee[_0xd3cd('0x42')][_0xd3cd('0x48')](_0xd3cd('0x49'))){_0x12a6d3['limit']=qs[_0xd3cd('0x31')](_0x38a2ee['query']['limit']);_0x12a6d3[_0xd3cd('0x30')]=qs[_0xd3cd('0x30')](_0x38a2ee['query'][_0xd3cd('0x30')]);}_0x12a6d3[_0xd3cd('0x4a')]=qs[_0xd3cd('0x4b')](_0x38a2ee[_0xd3cd('0x42')]['sort']);_0x12a6d3[_0xd3cd('0x4c')]=qs[_0xd3cd('0x44')](_[_0xd3cd('0x67')](_0x38a2ee[_0xd3cd('0x42')],_0xff8bdf[_0xd3cd('0x44')]));_0x12a6d3[_0xd3cd('0x4c')]['ChatQueueId']=_0x41614a['id'];if(_0x38a2ee[_0xd3cd('0x42')]['filter']){_0x12a6d3[_0xd3cd('0x4c')]=_[_0xd3cd('0x4f')](_0x12a6d3[_0xd3cd('0x4c')],{'$or':_[_0xd3cd('0x3d')](_0x12a6d3['attributes'],function(_0x271c0d){var _0x381055={};_0x381055[_0x271c0d]={'$like':'%'+_0x38a2ee['query'][_0xd3cd('0x4d')]+'%'};return _0x381055;})});}_0x12a6d3=_[_0xd3cd('0x4f')]({},_0x12a6d3,_0x38a2ee[_0xd3cd('0x50')]);return db['UserChatQueue'][_0xd3cd('0x68')](_0x12a6d3);}})[_0xd3cd('0x20')](function(_0x19f42d){if(_0x19f42d){return db[_0xd3cd('0x69')][_0xd3cd('0x6a')]({'where':{'id':_[_0xd3cd('0x3d')](_0x19f42d,_0xd3cd('0x6b')),'role':_0xd3cd('0x6c')},'attributes':['id',_0xd3cd('0x3a'),_0xd3cd('0x6d'),_0xd3cd('0x6e'),_0xd3cd('0x6f')]});}})[_0xd3cd('0x20')](function(_0x1a8a4f){if(_0x1a8a4f){return{'count':_0x1a8a4f['count'],'rows':_['map'](_0x1a8a4f[_0xd3cd('0x53')],function(_0x12e66d){return{'membername':_0x12e66d[_0xd3cd('0x3a')],'UserId':_0x12e66d['id'],'queue_name':_0x36aa70[_0xd3cd('0x3a')],'ChatQueueId':_0x36aa70['id'],'interface':util['format'](_0xd3cd('0x70'),'SIP',_0x12e66d[_0xd3cd('0x3a')]),'penalty':0x0,'paused':_0x12e66d[_0xd3cd('0x6d')],'createdAt':_0x12e66d[_0xd3cd('0x6f')],'updatedAt':_0x12e66d[_0xd3cd('0x6e')]};})};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithFilteredResult(_0x279674,_0x12a6d3))[_0xd3cd('0x2a')](handleError(_0x279674,null));};exports[_0xd3cd('0x71')]=function(_0x1b9eb5,_0xd19ba2,_0x434158){var _0x22197d={};var _0x28e424={};var _0x32022e;var _0x26d048;return db['ChatQueue']['findOne']({'where':{'id':_0x1b9eb5[_0xd3cd('0x55')]['id']}})[_0xd3cd('0x20')](handleEntityNotFound(_0xd19ba2,null))[_0xd3cd('0x20')](function(_0x17bed7){if(_0x17bed7){_0x32022e=_0x17bed7;_0x28e424['model']=_[_0xd3cd('0x43')](db[_0xd3cd('0x72')][_0xd3cd('0x56')]);_0x28e424[_0xd3cd('0x42')]=_[_0xd3cd('0x43')](_0x1b9eb5[_0xd3cd('0x42')]);_0x28e424[_0xd3cd('0x44')]=_[_0xd3cd('0x57')](_0x28e424[_0xd3cd('0x45')],_0x28e424[_0xd3cd('0x42')]);_0x22197d[_0xd3cd('0x47')]=_[_0xd3cd('0x57')](_0x28e424[_0xd3cd('0x45')],qs[_0xd3cd('0x46')](_0x1b9eb5[_0xd3cd('0x42')][_0xd3cd('0x46')]));_0x22197d[_0xd3cd('0x47')]=_0x22197d['attributes'][_0xd3cd('0x66')]?_0x22197d['attributes']:_0x28e424[_0xd3cd('0x45')];_0x22197d['order']=qs[_0xd3cd('0x4b')](_0x1b9eb5[_0xd3cd('0x42')][_0xd3cd('0x4b')]);_0x22197d['where']=qs[_0xd3cd('0x44')](_[_0xd3cd('0x67')](_0x1b9eb5[_0xd3cd('0x42')],_0x28e424[_0xd3cd('0x44')]));if(_0x1b9eb5['query'][_0xd3cd('0x4d')]){_0x22197d['where']=_['merge'](_0x22197d[_0xd3cd('0x4c')],{'$or':_[_0xd3cd('0x3d')](_0x22197d['attributes'],function(_0x334f85){var _0x139f97={};_0x139f97[_0x334f85]={'$like':'%'+_0x1b9eb5[_0xd3cd('0x42')][_0xd3cd('0x4d')]+'%'};return _0x139f97;})});}_0x22197d=_[_0xd3cd('0x4f')]({},_0x22197d,_0x1b9eb5[_0xd3cd('0x50')]);return _0x32022e[_0xd3cd('0x71')](_0x22197d);}})[_0xd3cd('0x20')](function(_0x34d233){if(_0x34d233){_0x26d048=_0x34d233[_0xd3cd('0x66')];if(!_0x1b9eb5['query'][_0xd3cd('0x48')](_0xd3cd('0x49'))){_0x22197d[_0xd3cd('0x31')]=qs[_0xd3cd('0x31')](_0x1b9eb5['query'][_0xd3cd('0x31')]);_0x22197d[_0xd3cd('0x30')]=qs[_0xd3cd('0x30')](_0x1b9eb5['query']['offset']);}return _0x32022e[_0xd3cd('0x71')](_0x22197d);}})[_0xd3cd('0x20')](function(_0x2bfe39){if(_0x2bfe39){return _0x2bfe39?{'count':_0x26d048,'rows':_0x2bfe39}:null;}})[_0xd3cd('0x20')](respondWithResult(_0xd19ba2,null))[_0xd3cd('0x2a')](handleError(_0xd19ba2,null));};exports['addTeams']=function(_0x47ab0f,_0x2e9f7b,_0x2e160e){var _0x158c90=_0x47ab0f[_0xd3cd('0x61')]['ids'];return db[_0xd3cd('0x72')][_0xd3cd('0x68')]({'where':{'id':_0x158c90},'attributes':['id'],'include':[{'model':db[_0xd3cd('0x69')],'as':_0xd3cd('0x73'),'attributes':['id',_0xd3cd('0x3a'),_0xd3cd('0x74'),_0xd3cd('0x75'),_0xd3cd('0x76')],'raw':!![]}]})['then'](function(_0x14718e){if(_0x14718e){var _0x625cd=_[_0xd3cd('0x77')](_0x14718e,function(_0x1b3af4){var _0x1a41f4=_0x1b3af4[_0xd3cd('0x37')]({'plain':!![]});return _0x1a41f4[_0xd3cd('0x73')];});return db[_0xd3cd('0x3e')][_0xd3cd('0x58')]({'where':{'id':_0x47ab0f['params']['id']}})[_0xd3cd('0x20')](function(_0x52559f){return db['sequelize'][_0xd3cd('0x78')](function(_0x20bd93){return _0x52559f[_0xd3cd('0x79')](_0x158c90,{'transaction':_0x20bd93})[_0xd3cd('0x20')](function(){return BPromise['each'](_0x625cd,function(_0x3e2299){return db[_0xd3cd('0x65')]['findOrCreate']({'where':{'UserId':_0x3e2299['id'],'ChatQueueId':_0x47ab0f[_0xd3cd('0x55')]['id']},'transaction':_0x20bd93});});})[_0xd3cd('0x20')](function(){_0x625cd['forEach'](function(_0x359bc0){socket['emit'](_0xd3cd('0x7a'),{'UserId':_0x359bc0['id'],'ChatQueueId':_0x52559f['id']});});});});});}})[_0xd3cd('0x20')](respondWithStatusCode(_0x2e9f7b,null))[_0xd3cd('0x2a')](handleError(_0x2e9f7b,null));};exports[_0xd3cd('0x7b')]=function(_0x35829d,_0xd72f9f,_0x33f093){return db[_0xd3cd('0x72')][_0xd3cd('0x68')]({'where':{'id':_0x35829d[_0xd3cd('0x42')]['ids']},'attributes':['id'],'include':[{'model':db[_0xd3cd('0x69')],'as':_0xd3cd('0x73'),'attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0xd72f9f,null))[_0xd3cd('0x20')](function(_0x59fb60){var _0x169336=_['map'](_0x59fb60,'id');var _0x1aec76=[];var _0x451b36=[];var _0x1b67c5=squel[_0xd3cd('0x7c')]();_0x1b67c5[_0xd3cd('0x7d')](_0xd3cd('0x7e'))[_0xd3cd('0x7f')](_0xd3cd('0x80'),'tq')[_0xd3cd('0x81')](_0xd3cd('0x82'),'ut',_0xd3cd('0x83'))[_0xd3cd('0x4c')](_0xd3cd('0x84'),_0x35829d[_0xd3cd('0x55')]['id']);for(var _0x1a10d8=0x0;_0x1a10d8<_0x59fb60[_0xd3cd('0x66')];_0x1a10d8+=0x1){let _0x3439d6=_0x59fb60[_0x1a10d8];for(var _0x753fab=0x0;_0x753fab<_0x3439d6[_0xd3cd('0x73')][_0xd3cd('0x66')];_0x753fab+=0x1){let _0x118694=_0x3439d6[_0xd3cd('0x73')][_0x753fab];var _0x282f7b=_0x1b67c5[_0xd3cd('0x85')]();_0x282f7b[_0xd3cd('0x4c')]('ut.UserId\x20=\x20?',_0x118694['id']);_0x451b36[_0xd3cd('0x86')](db['sequelize'][_0xd3cd('0x42')](_0x282f7b['toString'](),{'type':db[_0xd3cd('0x87')][_0xd3cd('0x88')]['SELECT']})['then'](function(_0xacfa89){if(_0xacfa89[_0xd3cd('0x66')]===0x1){return _0x118694['id'];}else{var _0x20d475=_['every'](_[_0xd3cd('0x3d')](_0xacfa89,'TeamId'),function(_0x518508){return _['includes'](_0x169336,_0x518508);});if(_0x20d475){return _0x118694['id'];}}}));}}return BPromise[_0xd3cd('0x89')](_0x451b36)[_0xd3cd('0x20')](function(_0x4c8fdb){_0x1aec76=_(_0x1aec76)[_0xd3cd('0x8a')](_0x4c8fdb)[_0xd3cd('0x8b')]()[_0xd3cd('0x8c')]();return db[_0xd3cd('0x3e')]['find']({'where':{'id':_0x35829d[_0xd3cd('0x55')]['id']}})[_0xd3cd('0x20')](function(_0x59ef5e){return db['sequelize']['transaction'](function(_0x1776db){return _0x59ef5e[_0xd3cd('0x7b')](_0x35829d[_0xd3cd('0x42')][_0xd3cd('0x8d')],{'transaction':_0x1776db})[_0xd3cd('0x20')](function(){if(!_[_0xd3cd('0x8e')](_0x1aec76)){return _0x59ef5e['removeAgents'](_0x1aec76,{'transaction':_0x1776db});}})[_0xd3cd('0x20')](function(){_0x1aec76[_0xd3cd('0x8f')](function(_0x2d0e39){socket[_0xd3cd('0x90')](_0xd3cd('0x91'),{'UserId':_0x2d0e39,'ChatQueueId':_0x59ef5e['id']});});});});});});})[_0xd3cd('0x20')](respondWithStatusCode(_0xd72f9f,null))[_0xd3cd('0x2a')](handleError(_0xd72f9f,null));};exports[_0xd3cd('0x92')]=function(_0x58552c,_0x45e449,_0x412ce5){return db[_0xd3cd('0x3e')]['find']({'where':{'id':_0x58552c[_0xd3cd('0x55')]['id']}})[_0xd3cd('0x20')](handleEntityNotFound(_0x45e449,null))[_0xd3cd('0x20')](function(_0x126c40){if(_0x126c40){return _0x126c40[_0xd3cd('0x92')](_0x58552c['body']['ids'],_['omit'](_0x58552c[_0xd3cd('0x61')],['ids','id'])||{})[_0xd3cd('0x93')](function(_0x3a5e9c){for(var _0xb0871=0x0;_0xb0871<_0x58552c[_0xd3cd('0x61')][_0xd3cd('0x8d')][_0xd3cd('0x66')];_0xb0871+=0x1){socket[_0xd3cd('0x90')](_0xd3cd('0x7a'),{'UserId':_0x58552c[_0xd3cd('0x61')]['ids'][_0xb0871],'ChatQueueId':_0x58552c[_0xd3cd('0x55')]['id']});}return _0x3a5e9c;});}})[_0xd3cd('0x20')](respondWithResult(_0x45e449,null))[_0xd3cd('0x2a')](handleError(_0x45e449,null));};exports[_0xd3cd('0x94')]=function(_0x90053f,_0x5395dc,_0x572313){return db['ChatQueue']['find']({'where':{'id':_0x90053f[_0xd3cd('0x55')]['id']}})['then'](handleEntityNotFound(_0x5395dc,null))[_0xd3cd('0x20')](function(_0x4f7d10){if(_0x4f7d10){return _0x4f7d10['removeAgents'](_0x90053f[_0xd3cd('0x42')][_0xd3cd('0x8d')])[_0xd3cd('0x20')](function(){if(_[_0xd3cd('0x95')](_0x90053f[_0xd3cd('0x42')][_0xd3cd('0x8d')])){for(var _0x167680=0x0;_0x167680<_0x90053f['query'][_0xd3cd('0x8d')][_0xd3cd('0x66')];_0x167680+=0x1){socket[_0xd3cd('0x90')](_0xd3cd('0x91'),{'UserId':Number(_0x90053f['query'][_0xd3cd('0x8d')][_0x167680]),'ChatQueueId':Number(_0x90053f[_0xd3cd('0x55')]['id'])});}}else{socket['emit'](_0xd3cd('0x91'),{'UserId':Number(_0x90053f[_0xd3cd('0x42')][_0xd3cd('0x8d')]),'ChatQueueId':Number(_0x90053f[_0xd3cd('0x55')]['id'])});}});}})['then'](respondWithStatusCode(_0x5395dc,null))['catch'](handleError(_0x5395dc,null));};exports[_0xd3cd('0x96')]=function(_0x3baebf,_0xa597db,_0x49ee14){var _0xbb0aea={};var _0x32530e={};var _0x305ae0;var _0x28ae81;return db[_0xd3cd('0x3e')][_0xd3cd('0x64')]({'where':{'id':_0x3baebf['params']['id']}})[_0xd3cd('0x20')](handleEntityNotFound(_0xa597db,null))['then'](function(_0x555242){if(_0x555242){_0x305ae0=_0x555242;_0x32530e[_0xd3cd('0x45')]=_[_0xd3cd('0x43')](db[_0xd3cd('0x69')]['rawAttributes']);_0x32530e[_0xd3cd('0x42')]=_[_0xd3cd('0x43')](_0x3baebf['query']);_0x32530e[_0xd3cd('0x44')]=_['intersection'](_0x32530e['model'],_0x32530e[_0xd3cd('0x42')]);_0xbb0aea[_0xd3cd('0x47')]=_[_0xd3cd('0x57')](_0x32530e[_0xd3cd('0x45')],qs[_0xd3cd('0x46')](_0x3baebf['query'][_0xd3cd('0x46')]));_0xbb0aea[_0xd3cd('0x47')]=_0xbb0aea['attributes'][_0xd3cd('0x66')]?_0xbb0aea['attributes']:_0x32530e[_0xd3cd('0x45')];_0xbb0aea['order']=qs['sort'](_0x3baebf[_0xd3cd('0x42')][_0xd3cd('0x4b')]);_0xbb0aea[_0xd3cd('0x4c')]=qs[_0xd3cd('0x44')](_[_0xd3cd('0x67')](_0x3baebf['query'],_0x32530e[_0xd3cd('0x44')]));if(_0x3baebf[_0xd3cd('0x42')][_0xd3cd('0x4d')]){_0xbb0aea[_0xd3cd('0x4c')]=_[_0xd3cd('0x4f')](_0xbb0aea[_0xd3cd('0x4c')],{'$or':_[_0xd3cd('0x3d')](_0xbb0aea[_0xd3cd('0x47')],function(_0x1573f3){var _0x348840={};_0x348840[_0x1573f3]={'$like':'%'+_0x3baebf[_0xd3cd('0x42')][_0xd3cd('0x4d')]+'%'};return _0x348840;})});}_0xbb0aea=_[_0xd3cd('0x4f')]({},_0xbb0aea,_0x3baebf[_0xd3cd('0x50')]);return _0x305ae0[_0xd3cd('0x96')](_0xbb0aea);}})[_0xd3cd('0x20')](function(_0x6aa6fd){if(_0x6aa6fd){_0x28ae81=_0x6aa6fd[_0xd3cd('0x66')];if(!_0x3baebf[_0xd3cd('0x42')][_0xd3cd('0x48')](_0xd3cd('0x49'))){_0xbb0aea['limit']=qs['limit'](_0x3baebf[_0xd3cd('0x42')]['limit']);_0xbb0aea[_0xd3cd('0x30')]=qs[_0xd3cd('0x30')](_0x3baebf[_0xd3cd('0x42')][_0xd3cd('0x30')]);}return _0x305ae0[_0xd3cd('0x96')](_0xbb0aea);}})[_0xd3cd('0x20')](function(_0x2c16b0){if(_0x2c16b0){return _0x2c16b0?{'count':_0x28ae81,'rows':_0x2c16b0}:null;}})[_0xd3cd('0x20')](respondWithResult(_0xa597db,null))[_0xd3cd('0x2a')](handleError(_0xa597db,null));};
\ No newline at end of file
+var _0x762e=['localhost','socket.io-emitter','./chatQueue.socket','register','jayson/promise','client','http','request','then','request\x20sent','debug','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','ChatQueue,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','offset','undefined','limit','count','apply','save','destroy','get','ChatQueues','UserProfileResource','stack','name','send','index','map','ChatQueue','rawAttributes','fieldName','key','model','query','keys','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','filters','filter','merge','type','VIRTUAL','includeAll','include','findAll','show','params','length','options','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','find','autoAssociation','update','describe','getMembers','order','pick','UserChatQueue','findAndCountAll','UserId','agent','chatPause','updatedAt','createdAt','rows','format','%s/%s','SIP','getTeams','addTeams','Team','User','Agents','voicePause','flatMap','sequelize','each','forEach','emit','removeTeams','ids','select','field','tq.TeamId','team_has_chat_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','toString','SELECT','every','includes','all','union','compact','value','removeAgents','userChatQueue:remove','addAgents','omit','spread','userChatQueue:save','isArray','getAgents','findOne','rimraf','zip-dir','fast-json-patch','moment','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults'];(function(_0x3a6a37,_0x136baf){var _0x17c7e1=function(_0x1afebe){while(--_0x1afebe){_0x3a6a37['push'](_0x3a6a37['shift']());}};_0x17c7e1(++_0x136baf);}(_0x762e,0x11a));var _0xe762=function(_0x28b5e9,_0x4b442f){_0x28b5e9=_0x28b5e9-0x0;var _0x23e6a4=_0x762e[_0x28b5e9];return _0x23e6a4;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xe762('0x0'));var zipdir=require(_0xe762('0x1'));var jsonpatch=require(_0xe762('0x2'));var rp=require('request-promise');var moment=require(_0xe762('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xe762('0x4'));var util=require(_0xe762('0x5'));var path=require('path');var sox=require(_0xe762('0x6'));var csv=require(_0xe762('0x7'));var ejs=require(_0xe762('0x8'));var fs=require('fs');var fs_extra=require(_0xe762('0x9'));var _=require(_0xe762('0xa'));var squel=require(_0xe762('0xb'));var crypto=require(_0xe762('0xc'));var jsforce=require(_0xe762('0xd'));var deskjs=require(_0xe762('0xe'));var toCsv=require('to-csv');var querystring=require(_0xe762('0xf'));var Papa=require('papaparse');var Redis=require(_0xe762('0x10'));var authService=require(_0xe762('0x11'));var qs=require(_0xe762('0x12'));var as=require(_0xe762('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xe762('0x14'))(_0xe762('0x15'));var utils=require(_0xe762('0x16'));var config=require(_0xe762('0x17'));var licenseUtil=require(_0xe762('0x18'));var db=require(_0xe762('0x19'))['db'];config[_0xe762('0x1a')]=_[_0xe762('0x1b')](config[_0xe762('0x1a')],{'host':_0xe762('0x1c'),'port':0x18eb});var socket=require(_0xe762('0x1d'))(new Redis(config[_0xe762('0x1a')]));require(_0xe762('0x1e'))[_0xe762('0x1f')](socket);var jayson=require(_0xe762('0x20'));var client=jayson[_0xe762('0x21')][_0xe762('0x22')]({'port':0x232a});function respondWithRpcPromise(_0x575d40,_0x25c862,_0x459e28,_0x125239){return new BPromise(function(_0x65098,_0x274cdb){var _0x34f3bc=_0x125239||client;return _0x34f3bc[_0xe762('0x23')](_0x575d40,_0x459e28)[_0xe762('0x24')](function(_0x51ef17){logger['info']('ChatQueue,\x20%s,\x20%s',_0x25c862,_0xe762('0x25'));logger[_0xe762('0x26')](_0xe762('0x27'),_0x25c862,_0xe762('0x25'),JSON[_0xe762('0x28')](_0x51ef17));if(_0x51ef17['error']){if(_0x51ef17[_0xe762('0x29')][_0xe762('0x2a')]===0x1f4){logger[_0xe762('0x29')](_0xe762('0x2b'),_0x25c862,_0x51ef17['error'][_0xe762('0x2c')]);return _0x274cdb(_0x51ef17['error'][_0xe762('0x2c')]);}logger[_0xe762('0x29')](_0xe762('0x2b'),_0x25c862,_0x51ef17['error'][_0xe762('0x2c')]);return _0x65098(_0x51ef17['error']['message']);}else{logger['info']('ChatQueue,\x20%s,\x20%s',_0x25c862,_0xe762('0x25'));_0x65098(_0x51ef17[_0xe762('0x2d')][_0xe762('0x2c')]);}})[_0xe762('0x2e')](function(_0x4f44ae){logger[_0xe762('0x29')](_0xe762('0x2b'),_0x25c862,_0x4f44ae);_0x274cdb(_0x4f44ae);});});}function respondWithStatusCode(_0x4db0d9,_0x19b084){_0x19b084=_0x19b084||0xcc;return function(_0x5d8b6d){if(_0x5d8b6d){return _0x4db0d9[_0xe762('0x2f')](_0x19b084);}return _0x4db0d9[_0xe762('0x30')](_0x19b084)[_0xe762('0x31')]();};}function respondWithResult(_0x4cd4ad,_0x1f349f){_0x1f349f=_0x1f349f||0xc8;return function(_0x3b5f71){if(_0x3b5f71){return _0x4cd4ad[_0xe762('0x30')](_0x1f349f)[_0xe762('0x32')](_0x3b5f71);}};}function respondWithFilteredResult(_0x3397e0,_0xc1bc78){return function(_0x9238eb){if(_0x9238eb){var _0x45bb50=typeof _0xc1bc78[_0xe762('0x33')]===_0xe762('0x34')&&typeof _0xc1bc78[_0xe762('0x35')]===_0xe762('0x34');var _0x5bcaed=_0x9238eb[_0xe762('0x36')];var _0x1892c3=_0x45bb50?0x0:_0xc1bc78['offset'];var _0x45f607=_0x45bb50?_0x9238eb[_0xe762('0x36')]:_0xc1bc78['offset']+_0xc1bc78[_0xe762('0x35')];var _0x5cd2b8;if(_0x45f607>=_0x5bcaed){_0x45f607=_0x5bcaed;_0x5cd2b8=0xc8;}else{_0x5cd2b8=0xce;}_0x3397e0[_0xe762('0x30')](_0x5cd2b8);return _0x3397e0['set']('Content-Range',_0x1892c3+'-'+_0x45f607+'/'+_0x5bcaed)[_0xe762('0x32')](_0x9238eb);}return null;};}function patchUpdates(_0x153910){return function(_0xfabf63){try{jsonpatch[_0xe762('0x37')](_0xfabf63,_0x153910,!![]);}catch(_0x4e977f){return BPromise['reject'](_0x4e977f);}return _0xfabf63[_0xe762('0x38')]();};}function saveUpdates(_0x2809e5,_0x2a4481){return function(_0x223952){if(_0x223952){return _0x223952['update'](_0x2809e5)[_0xe762('0x24')](function(_0x3bbeee){return _0x3bbeee;});}return null;};}function removeEntity(_0x56312b,_0x66b31b){return function(_0x349acb){if(_0x349acb){return _0x349acb[_0xe762('0x39')]()[_0xe762('0x24')](function(){var _0x121720=_0x349acb[_0xe762('0x3a')]({'plain':!![]});var _0x5b86a1=_0xe762('0x3b');return db[_0xe762('0x3c')]['destroy']({'where':{'type':_0x5b86a1,'resourceId':_0x121720['id']}})['then'](function(){return _0x349acb;});})['then'](function(){_0x56312b[_0xe762('0x30')](0xcc)[_0xe762('0x31')]();});}};}function handleEntityNotFound(_0x46a6db,_0x527bc6){return function(_0x2bd6b5){if(!_0x2bd6b5){_0x46a6db[_0xe762('0x2f')](0x194);}return _0x2bd6b5;};}function handleError(_0x4bfd96,_0x3acd50){_0x3acd50=_0x3acd50||0x1f4;return function(_0x2c3922){logger[_0xe762('0x29')](_0x2c3922[_0xe762('0x3d')]);if(_0x2c3922[_0xe762('0x3e')]){delete _0x2c3922[_0xe762('0x3e')];}_0x4bfd96[_0xe762('0x30')](_0x3acd50)[_0xe762('0x3f')](_0x2c3922);};}exports[_0xe762('0x40')]=function(_0x436c88,_0x5e2a33){var _0x12138c={},_0x3362f4={},_0x4147f0={'count':0x0,'rows':[]};var _0x1220b1=_[_0xe762('0x41')](db[_0xe762('0x42')][_0xe762('0x43')],function(_0x69fed7){return{'name':_0x69fed7[_0xe762('0x44')],'type':_0x69fed7['type'][_0xe762('0x45')]};});_0x3362f4[_0xe762('0x46')]=_[_0xe762('0x41')](_0x1220b1,_0xe762('0x3e'));_0x3362f4[_0xe762('0x47')]=_[_0xe762('0x48')](_0x436c88[_0xe762('0x47')]);_0x3362f4['filters']=_[_0xe762('0x49')](_0x3362f4['model'],_0x3362f4[_0xe762('0x47')]);_0x12138c[_0xe762('0x4a')]=_['intersection'](_0x3362f4[_0xe762('0x46')],qs[_0xe762('0x4b')](_0x436c88['query'][_0xe762('0x4b')]));_0x12138c[_0xe762('0x4a')]=_0x12138c[_0xe762('0x4a')]['length']?_0x12138c[_0xe762('0x4a')]:_0x3362f4['model'];if(!_0x436c88[_0xe762('0x47')][_0xe762('0x4c')](_0xe762('0x4d'))){_0x12138c[_0xe762('0x35')]=qs[_0xe762('0x35')](_0x436c88[_0xe762('0x47')][_0xe762('0x35')]);_0x12138c[_0xe762('0x33')]=qs[_0xe762('0x33')](_0x436c88[_0xe762('0x47')]['offset']);}_0x12138c['order']=qs[_0xe762('0x4e')](_0x436c88[_0xe762('0x47')][_0xe762('0x4e')]);_0x12138c[_0xe762('0x4f')]=qs['filters'](_['pick'](_0x436c88['query'],_0x3362f4[_0xe762('0x50')]),_0x1220b1);if(_0x436c88[_0xe762('0x47')][_0xe762('0x51')]){_0x12138c[_0xe762('0x4f')]=_[_0xe762('0x52')](_0x12138c[_0xe762('0x4f')],{'$or':_[_0xe762('0x41')](_0x1220b1,function(_0x1859e5){if(_0x1859e5[_0xe762('0x53')]!==_0xe762('0x54')){var _0x3925e6={};_0x3925e6[_0x1859e5[_0xe762('0x3e')]]={'$like':'%'+_0x436c88[_0xe762('0x47')][_0xe762('0x51')]+'%'};return _0x3925e6;}})});}_0x12138c=_[_0xe762('0x52')]({},_0x12138c,_0x436c88['options']);var _0x26168b={'where':_0x12138c[_0xe762('0x4f')]};return db[_0xe762('0x42')][_0xe762('0x36')](_0x26168b)[_0xe762('0x24')](function(_0x5b9ee3){_0x4147f0[_0xe762('0x36')]=_0x5b9ee3;if(_0x436c88['query'][_0xe762('0x55')]){_0x12138c[_0xe762('0x56')]=[{'all':!![]}];}return db[_0xe762('0x42')][_0xe762('0x57')](_0x12138c);})[_0xe762('0x24')](function(_0x55c272){_0x4147f0['rows']=_0x55c272;return _0x4147f0;})['then'](respondWithFilteredResult(_0x5e2a33,_0x12138c))[_0xe762('0x2e')](handleError(_0x5e2a33,null));};exports[_0xe762('0x58')]=function(_0x4bfe03,_0x4f2dcf){var _0x1f5f18={'raw':!![],'where':{'id':_0x4bfe03[_0xe762('0x59')]['id']}},_0x2fa0f1={};_0x2fa0f1[_0xe762('0x46')]=_[_0xe762('0x48')](db[_0xe762('0x42')][_0xe762('0x43')]);_0x2fa0f1[_0xe762('0x47')]=_[_0xe762('0x48')](_0x4bfe03['query']);_0x2fa0f1[_0xe762('0x50')]=_[_0xe762('0x49')](_0x2fa0f1[_0xe762('0x46')],_0x2fa0f1[_0xe762('0x47')]);_0x1f5f18['attributes']=_['intersection'](_0x2fa0f1[_0xe762('0x46')],qs[_0xe762('0x4b')](_0x4bfe03[_0xe762('0x47')][_0xe762('0x4b')]));_0x1f5f18[_0xe762('0x4a')]=_0x1f5f18['attributes'][_0xe762('0x5a')]?_0x1f5f18[_0xe762('0x4a')]:_0x2fa0f1[_0xe762('0x46')];if(_0x4bfe03['query'][_0xe762('0x55')]){_0x1f5f18['include']=[{'all':!![]}];}_0x1f5f18=_[_0xe762('0x52')]({},_0x1f5f18,_0x4bfe03[_0xe762('0x5b')]);return db[_0xe762('0x42')]['find'](_0x1f5f18)['then'](handleEntityNotFound(_0x4f2dcf,null))[_0xe762('0x24')](respondWithResult(_0x4f2dcf,null))[_0xe762('0x2e')](handleError(_0x4f2dcf,null));};exports['create']=function(_0x385949,_0x25b422){return db[_0xe762('0x42')][_0xe762('0x5c')](_0x385949[_0xe762('0x5d')],{})[_0xe762('0x24')](function(_0x15fc52){var _0xb197e1=_0x385949[_0xe762('0x5e')][_0xe762('0x3a')]({'plain':!![]});if(!_0xb197e1)throw new Error(_0xe762('0x5f'));if(_0xb197e1['role']===_0xe762('0x5e')){var _0x9a4341=_0x15fc52['get']({'plain':!![]});var _0x41b963=_0xe762('0x3b');return db['UserProfileSection'][_0xe762('0x60')]({'where':{'name':_0x41b963,'userProfileId':_0xb197e1['userProfileId']},'raw':!![]})['then'](function(_0x12ad16){if(_0x12ad16&&_0x12ad16[_0xe762('0x61')]===0x0){return db[_0xe762('0x3c')][_0xe762('0x5c')]({'name':_0x9a4341[_0xe762('0x3e')],'resourceId':_0x9a4341['id'],'type':_0x12ad16['name'],'sectionId':_0x12ad16['id']},{})['then'](function(){return _0x15fc52;});}else{return _0x15fc52;}})['catch'](function(_0x106a67){logger[_0xe762('0x29')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x106a67);throw _0x106a67;});}return _0x15fc52;})[_0xe762('0x24')](respondWithResult(_0x25b422,0xc9))['catch'](handleError(_0x25b422,null));};exports[_0xe762('0x62')]=function(_0x2e7614,_0x579709){if(_0x2e7614[_0xe762('0x5d')]['id']){delete _0x2e7614[_0xe762('0x5d')]['id'];}return db[_0xe762('0x42')][_0xe762('0x60')]({'where':{'id':_0x2e7614[_0xe762('0x59')]['id']}})[_0xe762('0x24')](handleEntityNotFound(_0x579709,null))[_0xe762('0x24')](saveUpdates(_0x2e7614[_0xe762('0x5d')],null))[_0xe762('0x24')](respondWithResult(_0x579709,null))['catch'](handleError(_0x579709,null));};exports['destroy']=function(_0xfe1e74,_0x61f3ae){return db[_0xe762('0x42')][_0xe762('0x60')]({'where':{'id':_0xfe1e74[_0xe762('0x59')]['id']}})[_0xe762('0x24')](handleEntityNotFound(_0x61f3ae,null))['then'](removeEntity(_0x61f3ae,null))['catch'](handleError(_0x61f3ae,null));};exports[_0xe762('0x63')]=function(_0x3f7b3a,_0x1e4cf0){return db[_0xe762('0x42')][_0xe762('0x63')]()[_0xe762('0x24')](respondWithResult(_0x1e4cf0,null))['catch'](handleError(_0x1e4cf0,null));};exports[_0xe762('0x64')]=function(_0x34237f,_0x82a19f,_0x510cc1){var _0x10507c={'raw':!![],'where':{}},_0x48b39b={},_0x31d250;return db[_0xe762('0x42')]['findOne']({'where':{'id':_0x34237f[_0xe762('0x59')]['id']}})[_0xe762('0x24')](handleEntityNotFound(_0x82a19f,null))['then'](function(_0x56c92b){if(_0x56c92b){_0x31d250=_0x56c92b[_0xe762('0x3a')]({'plain':!![]});_0x48b39b['model']=_[_0xe762('0x48')](db['UserChatQueue'][_0xe762('0x43')]);_0x48b39b['query']=_[_0xe762('0x48')](_0x34237f[_0xe762('0x47')]);_0x48b39b[_0xe762('0x50')]=_[_0xe762('0x49')](_0x48b39b[_0xe762('0x46')],_0x48b39b[_0xe762('0x47')]);_0x10507c['attributes']=_[_0xe762('0x49')](_0x48b39b[_0xe762('0x46')],qs['fields'](_0x34237f['query']['fields']));_0x10507c['attributes']=_0x10507c[_0xe762('0x4a')][_0xe762('0x5a')]?_0x10507c['attributes']:_0x48b39b['model'];if(!_0x34237f[_0xe762('0x47')]['hasOwnProperty'](_0xe762('0x4d'))){_0x10507c[_0xe762('0x35')]=qs['limit'](_0x34237f[_0xe762('0x47')][_0xe762('0x35')]);_0x10507c['offset']=qs[_0xe762('0x33')](_0x34237f[_0xe762('0x47')][_0xe762('0x33')]);}_0x10507c[_0xe762('0x65')]=qs[_0xe762('0x4e')](_0x34237f[_0xe762('0x47')]['sort']);_0x10507c[_0xe762('0x4f')]=qs[_0xe762('0x50')](_[_0xe762('0x66')](_0x34237f[_0xe762('0x47')],_0x48b39b[_0xe762('0x50')]));_0x10507c[_0xe762('0x4f')]['ChatQueueId']=_0x56c92b['id'];if(_0x34237f['query'][_0xe762('0x51')]){_0x10507c['where']=_[_0xe762('0x52')](_0x10507c[_0xe762('0x4f')],{'$or':_[_0xe762('0x41')](_0x10507c[_0xe762('0x4a')],function(_0x528cc8){var _0xae3c55={};_0xae3c55[_0x528cc8]={'$like':'%'+_0x34237f['query'][_0xe762('0x51')]+'%'};return _0xae3c55;})});}_0x10507c=_[_0xe762('0x52')]({},_0x10507c,_0x34237f[_0xe762('0x5b')]);return db[_0xe762('0x67')][_0xe762('0x57')](_0x10507c);}})[_0xe762('0x24')](function(_0x386679){if(_0x386679){return db['User'][_0xe762('0x68')]({'where':{'id':_['map'](_0x386679,_0xe762('0x69')),'role':_0xe762('0x6a')},'attributes':['id',_0xe762('0x3e'),_0xe762('0x6b'),_0xe762('0x6c'),_0xe762('0x6d')]});}})['then'](function(_0x37cbcc){if(_0x37cbcc){return{'count':_0x37cbcc['count'],'rows':_[_0xe762('0x41')](_0x37cbcc[_0xe762('0x6e')],function(_0x4de74c){return{'membername':_0x4de74c[_0xe762('0x3e')],'UserId':_0x4de74c['id'],'queue_name':_0x31d250[_0xe762('0x3e')],'ChatQueueId':_0x31d250['id'],'interface':util[_0xe762('0x6f')](_0xe762('0x70'),_0xe762('0x71'),_0x4de74c[_0xe762('0x3e')]),'penalty':0x0,'paused':_0x4de74c[_0xe762('0x6b')],'createdAt':_0x4de74c[_0xe762('0x6d')],'updatedAt':_0x4de74c[_0xe762('0x6c')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xe762('0x24')](respondWithFilteredResult(_0x82a19f,_0x10507c))[_0xe762('0x2e')](handleError(_0x82a19f,null));};exports['getTeams']=function(_0x59d0b3,_0x7ccc31,_0x4457c9){var _0x2c8878={};var _0x6583f6={};var _0x288f9e;var _0x312e64;return db[_0xe762('0x42')]['findOne']({'where':{'id':_0x59d0b3[_0xe762('0x59')]['id']}})['then'](handleEntityNotFound(_0x7ccc31,null))['then'](function(_0x5a369c){if(_0x5a369c){_0x288f9e=_0x5a369c;_0x6583f6[_0xe762('0x46')]=_[_0xe762('0x48')](db['Team'][_0xe762('0x43')]);_0x6583f6[_0xe762('0x47')]=_[_0xe762('0x48')](_0x59d0b3['query']);_0x6583f6[_0xe762('0x50')]=_[_0xe762('0x49')](_0x6583f6[_0xe762('0x46')],_0x6583f6[_0xe762('0x47')]);_0x2c8878['attributes']=_[_0xe762('0x49')](_0x6583f6['model'],qs[_0xe762('0x4b')](_0x59d0b3[_0xe762('0x47')]['fields']));_0x2c8878['attributes']=_0x2c8878[_0xe762('0x4a')][_0xe762('0x5a')]?_0x2c8878[_0xe762('0x4a')]:_0x6583f6[_0xe762('0x46')];_0x2c8878[_0xe762('0x65')]=qs[_0xe762('0x4e')](_0x59d0b3['query'][_0xe762('0x4e')]);_0x2c8878[_0xe762('0x4f')]=qs[_0xe762('0x50')](_[_0xe762('0x66')](_0x59d0b3[_0xe762('0x47')],_0x6583f6[_0xe762('0x50')]));if(_0x59d0b3['query'][_0xe762('0x51')]){_0x2c8878[_0xe762('0x4f')]=_['merge'](_0x2c8878['where'],{'$or':_[_0xe762('0x41')](_0x2c8878['attributes'],function(_0x14c3fd){var _0x147c4f={};_0x147c4f[_0x14c3fd]={'$like':'%'+_0x59d0b3[_0xe762('0x47')][_0xe762('0x51')]+'%'};return _0x147c4f;})});}_0x2c8878=_[_0xe762('0x52')]({},_0x2c8878,_0x59d0b3['options']);return _0x288f9e[_0xe762('0x72')](_0x2c8878);}})['then'](function(_0x307d9f){if(_0x307d9f){_0x312e64=_0x307d9f[_0xe762('0x5a')];if(!_0x59d0b3['query']['hasOwnProperty'](_0xe762('0x4d'))){_0x2c8878[_0xe762('0x35')]=qs[_0xe762('0x35')](_0x59d0b3[_0xe762('0x47')][_0xe762('0x35')]);_0x2c8878[_0xe762('0x33')]=qs[_0xe762('0x33')](_0x59d0b3[_0xe762('0x47')][_0xe762('0x33')]);}return _0x288f9e['getTeams'](_0x2c8878);}})[_0xe762('0x24')](function(_0xf6790f){if(_0xf6790f){return _0xf6790f?{'count':_0x312e64,'rows':_0xf6790f}:null;}})['then'](respondWithResult(_0x7ccc31,null))[_0xe762('0x2e')](handleError(_0x7ccc31,null));};exports[_0xe762('0x73')]=function(_0x4a566e,_0x1a3e99,_0x1cfd6e){var _0x3ab5ed=_0x4a566e[_0xe762('0x5d')]['ids'];return db[_0xe762('0x74')][_0xe762('0x57')]({'where':{'id':_0x3ab5ed},'attributes':['id'],'include':[{'model':db[_0xe762('0x75')],'as':_0xe762('0x76'),'attributes':['id',_0xe762('0x3e'),'online',_0xe762('0x77'),'interface'],'raw':!![]}]})[_0xe762('0x24')](function(_0x4cd22f){if(_0x4cd22f){var _0x44a731=_[_0xe762('0x78')](_0x4cd22f,function(_0x159c47){var _0x28292d=_0x159c47[_0xe762('0x3a')]({'plain':!![]});return _0x28292d['Agents'];});return db[_0xe762('0x42')]['find']({'where':{'id':_0x4a566e[_0xe762('0x59')]['id']}})[_0xe762('0x24')](function(_0x30acf3){return db[_0xe762('0x79')]['transaction'](function(_0x323f76){return _0x30acf3[_0xe762('0x73')](_0x3ab5ed,{'transaction':_0x323f76})[_0xe762('0x24')](function(){return BPromise[_0xe762('0x7a')](_0x44a731,function(_0x1ff6b8){return db[_0xe762('0x67')]['findOrCreate']({'where':{'UserId':_0x1ff6b8['id'],'ChatQueueId':_0x4a566e['params']['id']},'transaction':_0x323f76});});})[_0xe762('0x24')](function(){_0x44a731[_0xe762('0x7b')](function(_0x2619e8){socket[_0xe762('0x7c')]('userChatQueue:save',{'UserId':_0x2619e8['id'],'ChatQueueId':_0x30acf3['id']});});});});});}})['then'](respondWithStatusCode(_0x1a3e99,null))[_0xe762('0x2e')](handleError(_0x1a3e99,null));};exports[_0xe762('0x7d')]=function(_0x147200,_0x4d4f7b,_0xbbf374){return db[_0xe762('0x74')]['findAll']({'where':{'id':_0x147200[_0xe762('0x47')][_0xe762('0x7e')]},'attributes':['id'],'include':[{'model':db[_0xe762('0x75')],'as':'Agents','attributes':['id'],'raw':!![]}]})['then'](handleEntityNotFound(_0x4d4f7b,null))[_0xe762('0x24')](function(_0x5cf827){var _0x4f8be4=_[_0xe762('0x41')](_0x5cf827,'id');var _0x60207e=[];var _0x5dfed8=[];var _0x1f813e=squel[_0xe762('0x7f')]();_0x1f813e[_0xe762('0x80')](_0xe762('0x81'))['from'](_0xe762('0x82'),'tq')[_0xe762('0x83')](_0xe762('0x84'),'ut',_0xe762('0x85'))[_0xe762('0x4f')](_0xe762('0x86'),_0x147200[_0xe762('0x59')]['id']);for(var _0x37288a=0x0;_0x37288a<_0x5cf827[_0xe762('0x5a')];_0x37288a+=0x1){let _0x54c418=_0x5cf827[_0x37288a];for(var _0x3624ee=0x0;_0x3624ee<_0x54c418[_0xe762('0x76')][_0xe762('0x5a')];_0x3624ee+=0x1){let _0x1369f3=_0x54c418[_0xe762('0x76')][_0x3624ee];var _0x22cdf5=_0x1f813e[_0xe762('0x87')]();_0x22cdf5[_0xe762('0x4f')](_0xe762('0x88'),_0x1369f3['id']);_0x5dfed8[_0xe762('0x89')](db[_0xe762('0x79')][_0xe762('0x47')](_0x22cdf5[_0xe762('0x8a')](),{'type':db[_0xe762('0x79')]['QueryTypes'][_0xe762('0x8b')]})[_0xe762('0x24')](function(_0x2d7d72){if(_0x2d7d72[_0xe762('0x5a')]===0x1){return _0x1369f3['id'];}else{var _0x18d408=_[_0xe762('0x8c')](_[_0xe762('0x41')](_0x2d7d72,'TeamId'),function(_0x56eef8){return _[_0xe762('0x8d')](_0x4f8be4,_0x56eef8);});if(_0x18d408){return _0x1369f3['id'];}}}));}}return BPromise[_0xe762('0x8e')](_0x5dfed8)[_0xe762('0x24')](function(_0x4fc449){_0x60207e=_(_0x60207e)[_0xe762('0x8f')](_0x4fc449)[_0xe762('0x90')]()[_0xe762('0x91')]();return db['ChatQueue'][_0xe762('0x60')]({'where':{'id':_0x147200[_0xe762('0x59')]['id']}})[_0xe762('0x24')](function(_0x5eee8c){return db[_0xe762('0x79')]['transaction'](function(_0x13b176){return _0x5eee8c[_0xe762('0x7d')](_0x147200[_0xe762('0x47')]['ids'],{'transaction':_0x13b176})[_0xe762('0x24')](function(){if(!_['isEmpty'](_0x60207e)){return _0x5eee8c[_0xe762('0x92')](_0x60207e,{'transaction':_0x13b176});}})['then'](function(){_0x60207e[_0xe762('0x7b')](function(_0x2e39e6){socket[_0xe762('0x7c')](_0xe762('0x93'),{'UserId':_0x2e39e6,'ChatQueueId':_0x5eee8c['id']});});});});});});})['then'](respondWithStatusCode(_0x4d4f7b,null))[_0xe762('0x2e')](handleError(_0x4d4f7b,null));};exports[_0xe762('0x94')]=function(_0x4d235c,_0xf09a0a,_0x260c63){return db['ChatQueue'][_0xe762('0x60')]({'where':{'id':_0x4d235c[_0xe762('0x59')]['id']}})[_0xe762('0x24')](handleEntityNotFound(_0xf09a0a,null))['then'](function(_0x347c0e){if(_0x347c0e){return _0x347c0e['addAgents'](_0x4d235c[_0xe762('0x5d')][_0xe762('0x7e')],_[_0xe762('0x95')](_0x4d235c[_0xe762('0x5d')],[_0xe762('0x7e'),'id'])||{})[_0xe762('0x96')](function(_0x48b9a8){for(var _0x44fc86=0x0;_0x44fc86<_0x4d235c[_0xe762('0x5d')]['ids'][_0xe762('0x5a')];_0x44fc86+=0x1){socket[_0xe762('0x7c')](_0xe762('0x97'),{'UserId':Number(_0x4d235c['body'][_0xe762('0x7e')][_0x44fc86]),'ChatQueueId':Number(_0x4d235c[_0xe762('0x59')]['id'])});}return _0x48b9a8;});}})[_0xe762('0x24')](respondWithResult(_0xf09a0a,null))['catch'](handleError(_0xf09a0a,null));};exports[_0xe762('0x92')]=function(_0x960542,_0xa5b551,_0x4c00e1){return db[_0xe762('0x42')][_0xe762('0x60')]({'where':{'id':_0x960542[_0xe762('0x59')]['id']}})['then'](handleEntityNotFound(_0xa5b551,null))['then'](function(_0x4ae0f3){if(_0x4ae0f3){return _0x4ae0f3['removeAgents'](_0x960542[_0xe762('0x47')][_0xe762('0x7e')])[_0xe762('0x24')](function(){if(_[_0xe762('0x98')](_0x960542['query'][_0xe762('0x7e')])){for(var _0x2eccf7=0x0;_0x2eccf7<_0x960542[_0xe762('0x47')][_0xe762('0x7e')][_0xe762('0x5a')];_0x2eccf7+=0x1){socket[_0xe762('0x7c')](_0xe762('0x93'),{'UserId':Number(_0x960542[_0xe762('0x47')][_0xe762('0x7e')][_0x2eccf7]),'ChatQueueId':Number(_0x960542['params']['id'])});}}else{socket[_0xe762('0x7c')](_0xe762('0x93'),{'UserId':Number(_0x960542['query'][_0xe762('0x7e')]),'ChatQueueId':Number(_0x960542['params']['id'])});}});}})[_0xe762('0x24')](respondWithStatusCode(_0xa5b551,null))[_0xe762('0x2e')](handleError(_0xa5b551,null));};exports[_0xe762('0x99')]=function(_0x458448,_0x3f3140,_0xf8049){var _0x13c4b3={};var _0x5ea102={};var _0x54d0b7;var _0x1e4266;return db[_0xe762('0x42')][_0xe762('0x9a')]({'where':{'id':_0x458448[_0xe762('0x59')]['id']}})['then'](handleEntityNotFound(_0x3f3140,null))[_0xe762('0x24')](function(_0xcb608d){if(_0xcb608d){_0x54d0b7=_0xcb608d;_0x5ea102[_0xe762('0x46')]=_[_0xe762('0x48')](db['User'][_0xe762('0x43')]);_0x5ea102[_0xe762('0x47')]=_['keys'](_0x458448[_0xe762('0x47')]);_0x5ea102['filters']=_[_0xe762('0x49')](_0x5ea102[_0xe762('0x46')],_0x5ea102[_0xe762('0x47')]);_0x13c4b3[_0xe762('0x4a')]=_['intersection'](_0x5ea102[_0xe762('0x46')],qs[_0xe762('0x4b')](_0x458448[_0xe762('0x47')][_0xe762('0x4b')]));_0x13c4b3[_0xe762('0x4a')]=_0x13c4b3[_0xe762('0x4a')][_0xe762('0x5a')]?_0x13c4b3[_0xe762('0x4a')]:_0x5ea102[_0xe762('0x46')];_0x13c4b3['order']=qs[_0xe762('0x4e')](_0x458448[_0xe762('0x47')]['sort']);_0x13c4b3[_0xe762('0x4f')]=qs[_0xe762('0x50')](_[_0xe762('0x66')](_0x458448[_0xe762('0x47')],_0x5ea102['filters']));if(_0x458448[_0xe762('0x47')]['filter']){_0x13c4b3[_0xe762('0x4f')]=_[_0xe762('0x52')](_0x13c4b3[_0xe762('0x4f')],{'$or':_[_0xe762('0x41')](_0x13c4b3[_0xe762('0x4a')],function(_0x3fd9bb){var _0x2ce560={};_0x2ce560[_0x3fd9bb]={'$like':'%'+_0x458448[_0xe762('0x47')]['filter']+'%'};return _0x2ce560;})});}_0x13c4b3=_[_0xe762('0x52')]({},_0x13c4b3,_0x458448[_0xe762('0x5b')]);return _0x54d0b7[_0xe762('0x99')](_0x13c4b3);}})[_0xe762('0x24')](function(_0x4bcdff){if(_0x4bcdff){_0x1e4266=_0x4bcdff[_0xe762('0x5a')];if(!_0x458448[_0xe762('0x47')]['hasOwnProperty']('nolimit')){_0x13c4b3[_0xe762('0x35')]=qs[_0xe762('0x35')](_0x458448[_0xe762('0x47')][_0xe762('0x35')]);_0x13c4b3[_0xe762('0x33')]=qs[_0xe762('0x33')](_0x458448['query']['offset']);}return _0x54d0b7[_0xe762('0x99')](_0x13c4b3);}})[_0xe762('0x24')](function(_0x404743){if(_0x404743){return _0x404743?{'count':_0x1e4266,'rows':_0x404743}:null;}})[_0xe762('0x24')](respondWithResult(_0x3f3140,null))['catch'](handleError(_0x3f3140,null));};
\ No newline at end of file