Built motion from commit bab6f49e.|2.6.17
[motion2.git] / server / api / chatQueue / chatQueue.controller.js
index 8d6dc73..be576d5 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x15f7=['ut.UserId\x20=\x20?','push','sequelize','QueryTypes','every','includes','all','union','compact','value','isEmpty','removeAgents','emit','addAgents','omit','spread','isArray','userChatQueue:remove','getAgents','html-pdf','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','client','http','test','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','request','then','info','ChatQueue,\x20%s,\x20%s','request\x20sent','debug','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','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','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','filter','merge','includeAll','include','findAll','show','params','length','options','create','body','user','ChatQueues','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','getMembers','findOne','nolimit','UserChatQueue','User','findAndCountAll','UserId','updatedAt','createdAt','rows','format','%s/%s','SIP','getTeams','Team','addTeams','ids','online','voicePause','interface','flatMap','Agents','transaction','each','findOrCreate','forEach','userChatQueue:save','field','tq.TeamId','from','join','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone'];(function(_0xbd3b9c,_0x398223){var _0x33520f=function(_0x4cfa1a){while(--_0x4cfa1a){_0xbd3b9c['push'](_0xbd3b9c['shift']());}};_0x33520f(++_0x398223);}(_0x15f7,0xb0));var _0x715f=function(_0x5c43e1,_0x4c1705){_0x5c43e1=_0x5c43e1-0x0;var _0x397fa7=_0x15f7[_0x5c43e1];return _0x397fa7;};'use strict';var pdf=require(_0x715f('0x0'));var emlformat=require(_0x715f('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x715f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x715f('0x3'));var moment=require(_0x715f('0x4'));var BPromise=require(_0x715f('0x5'));var Mustache=require(_0x715f('0x6'));var util=require(_0x715f('0x7'));var path=require('path');var sox=require(_0x715f('0x8'));var csv=require(_0x715f('0x9'));var ejs=require(_0x715f('0xa'));var fs=require('fs');var _=require(_0x715f('0xb'));var squel=require(_0x715f('0xc'));var crypto=require(_0x715f('0xd'));var jsforce=require(_0x715f('0xe'));var deskjs=require(_0x715f('0xf'));var toCsv=require(_0x715f('0x9'));var querystring=require('querystring');var Papa=require(_0x715f('0x10'));var Redis=require(_0x715f('0x11'));var authService=require(_0x715f('0x12'));var qs=require(_0x715f('0x13'));var as=require(_0x715f('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x715f('0x15'))(_0x715f('0x16'));var utils=require(_0x715f('0x17'));var config=require(_0x715f('0x18'));var db=require(_0x715f('0x19'))['db'];config['redis']=_[_0x715f('0x1a')](config[_0x715f('0x1b')],{'host':_0x715f('0x1c'),'port':0x18eb});var socket=require(_0x715f('0x1d'))(new Redis(config[_0x715f('0x1b')]));require('./chatQueue.socket')[_0x715f('0x1e')](socket);var jayson=require(_0x715f('0x1f'));var client=jayson[_0x715f('0x20')][_0x715f('0x21')]({'port':0x232a});function checkPasswordPattern(_0x15587c,_0x1fdb8f,_0x5d5949){if(_0x5d5949){var _0x4280df=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x4280df[_0x715f('0x22')](_0x1fdb8f)){return _0x15587c;}else{throw new db['Sequelize']['ValidationError'](_0x715f('0x23'));}}else{return _0x15587c;}}function respondWithRpcPromise(_0x524722,_0x52901e,_0x5cd6c4,_0x3f1c3d){return new BPromise(function(_0x1c6e65,_0x5855f3){var _0x1e3a7e=_0x3f1c3d||client;return _0x1e3a7e[_0x715f('0x24')](_0x524722,_0x5cd6c4)[_0x715f('0x25')](function(_0x5e3875){logger[_0x715f('0x26')](_0x715f('0x27'),_0x52901e,_0x715f('0x28'));logger[_0x715f('0x29')](_0x715f('0x2a'),_0x52901e,_0x715f('0x28'),JSON[_0x715f('0x2b')](_0x5e3875));if(_0x5e3875[_0x715f('0x2c')]){if(_0x5e3875[_0x715f('0x2c')]['code']===0x1f4){logger[_0x715f('0x2c')]('ChatQueue,\x20%s,\x20%s',_0x52901e,_0x5e3875[_0x715f('0x2c')][_0x715f('0x2d')]);return _0x5855f3(_0x5e3875[_0x715f('0x2c')][_0x715f('0x2d')]);}logger['error'](_0x715f('0x27'),_0x52901e,_0x5e3875['error']['message']);return _0x1c6e65(_0x5e3875[_0x715f('0x2c')][_0x715f('0x2d')]);}else{logger['info'](_0x715f('0x27'),_0x52901e,'request\x20sent');_0x1c6e65(_0x5e3875[_0x715f('0x2e')]['message']);}})[_0x715f('0x2f')](function(_0x2d677b){logger['error'](_0x715f('0x27'),_0x52901e,_0x2d677b);_0x5855f3(_0x2d677b);});});}function respondWithStatusCode(_0x5c0c75,_0x44cc7c){_0x44cc7c=_0x44cc7c||0xcc;return function(_0x468860){if(_0x468860){return _0x5c0c75[_0x715f('0x30')](_0x44cc7c);}return _0x5c0c75[_0x715f('0x31')](_0x44cc7c)[_0x715f('0x32')]();};}function respondWithResult(_0x49f70c,_0xf53d71){_0xf53d71=_0xf53d71||0xc8;return function(_0x1485a1){if(_0x1485a1){return _0x49f70c[_0x715f('0x31')](_0xf53d71)[_0x715f('0x33')](_0x1485a1);}};}function respondWithFilteredResult(_0x379481,_0x44f836){return function(_0x562c83){if(_0x562c83){var _0x9efa40=_0x562c83[_0x715f('0x34')],_0x37d7db=_0x44f836[_0x715f('0x35')],_0x9617a2=_0x44f836[_0x715f('0x35')]+_0x44f836[_0x715f('0x36')],_0x4ea738;if(_0x9617a2>=_0x9efa40){_0x9617a2=_0x9efa40;_0x4ea738=0xc8;}else{_0x4ea738=0xce;}_0x379481[_0x715f('0x31')](_0x4ea738);return _0x379481[_0x715f('0x37')](_0x715f('0x38'),_0x37d7db+'-'+_0x9617a2+'/'+_0x9efa40)[_0x715f('0x33')](_0x562c83);}return null;};}function patchUpdates(_0x473f55){return function(_0x1bb285){try{jsonpatch[_0x715f('0x39')](_0x1bb285,_0x473f55,!![]);}catch(_0x1db452){return BPromise[_0x715f('0x3a')](_0x1db452);}return _0x1bb285[_0x715f('0x3b')]();};}function saveUpdates(_0x38d16e,_0x38572a){return function(_0x1c97ec){if(_0x1c97ec){return _0x1c97ec['update'](_0x38d16e)[_0x715f('0x25')](function(_0x3935be){return _0x3935be;});}return null;};}function removeEntity(_0x49334b,_0x488077){return function(_0x56bd41){if(_0x56bd41){return _0x56bd41['destroy']()[_0x715f('0x25')](function(){var _0x432a8b=_0x56bd41[_0x715f('0x3c')]({'plain':!![]});var _0x3570c9='ChatQueues';return db[_0x715f('0x3d')][_0x715f('0x3e')]({'where':{'type':_0x3570c9,'resourceId':_0x432a8b['id']}})['then'](function(){return _0x56bd41;});})[_0x715f('0x25')](function(){_0x49334b[_0x715f('0x31')](0xcc)[_0x715f('0x32')]();});}};}function handleEntityNotFound(_0x39fe33,_0x3a1287){return function(_0x6f7b8f){if(!_0x6f7b8f){_0x39fe33[_0x715f('0x30')](0x194);}return _0x6f7b8f;};}function handleError(_0x437325,_0x503f12){_0x503f12=_0x503f12||0x1f4;return function(_0x5d3d99){logger[_0x715f('0x2c')](_0x5d3d99['stack']);if(_0x5d3d99[_0x715f('0x3f')]){delete _0x5d3d99[_0x715f('0x3f')];}_0x437325[_0x715f('0x31')](_0x503f12)[_0x715f('0x40')](_0x5d3d99);};}exports[_0x715f('0x41')]=function(_0x3a5fa9,_0x50861f){var _0x2f95f2={},_0x4adb78={},_0x4e79aa={'count':0x0,'rows':[]};var _0x138b79=_[_0x715f('0x42')](db[_0x715f('0x43')][_0x715f('0x44')],function(_0x1bd8d5){return{'name':_0x1bd8d5[_0x715f('0x45')],'type':_0x1bd8d5[_0x715f('0x46')][_0x715f('0x47')]};});_0x4adb78[_0x715f('0x48')]=_[_0x715f('0x42')](_0x138b79,'name');_0x4adb78[_0x715f('0x49')]=_[_0x715f('0x4a')](_0x3a5fa9[_0x715f('0x49')]);_0x4adb78[_0x715f('0x4b')]=_[_0x715f('0x4c')](_0x4adb78[_0x715f('0x48')],_0x4adb78[_0x715f('0x49')]);_0x2f95f2[_0x715f('0x4d')]=_[_0x715f('0x4c')](_0x4adb78[_0x715f('0x48')],qs['fields'](_0x3a5fa9['query'][_0x715f('0x4e')]));_0x2f95f2[_0x715f('0x4d')]=_0x2f95f2[_0x715f('0x4d')]['length']?_0x2f95f2[_0x715f('0x4d')]:_0x4adb78['model'];if(!_0x3a5fa9['query'][_0x715f('0x4f')]('nolimit')){_0x2f95f2[_0x715f('0x36')]=qs[_0x715f('0x36')](_0x3a5fa9[_0x715f('0x49')]['limit']);_0x2f95f2['offset']=qs['offset'](_0x3a5fa9[_0x715f('0x49')][_0x715f('0x35')]);}_0x2f95f2[_0x715f('0x50')]=qs[_0x715f('0x51')](_0x3a5fa9[_0x715f('0x49')][_0x715f('0x51')]);_0x2f95f2[_0x715f('0x52')]=qs[_0x715f('0x4b')](_[_0x715f('0x53')](_0x3a5fa9[_0x715f('0x49')],_0x4adb78[_0x715f('0x4b')]),_0x138b79);if(_0x3a5fa9[_0x715f('0x49')][_0x715f('0x54')]){_0x2f95f2[_0x715f('0x52')]=_[_0x715f('0x55')](_0x2f95f2[_0x715f('0x52')],{'$or':_[_0x715f('0x42')](_0x138b79,function(_0x3b5ebc){if(_0x3b5ebc['type']!=='VIRTUAL'){var _0x1fdf96={};_0x1fdf96[_0x3b5ebc[_0x715f('0x3f')]]={'$like':'%'+_0x3a5fa9['query'][_0x715f('0x54')]+'%'};return _0x1fdf96;}})});}_0x2f95f2=_[_0x715f('0x55')]({},_0x2f95f2,_0x3a5fa9['options']);var _0x92dd58={'where':_0x2f95f2[_0x715f('0x52')]};return db[_0x715f('0x43')][_0x715f('0x34')](_0x92dd58)['then'](function(_0xfdb65b){_0x4e79aa[_0x715f('0x34')]=_0xfdb65b;if(_0x3a5fa9['query'][_0x715f('0x56')]){_0x2f95f2[_0x715f('0x57')]=[{'all':!![]}];}return db[_0x715f('0x43')][_0x715f('0x58')](_0x2f95f2);})[_0x715f('0x25')](function(_0x36a7ca){_0x4e79aa['rows']=_0x36a7ca;return _0x4e79aa;})[_0x715f('0x25')](respondWithFilteredResult(_0x50861f,_0x2f95f2))[_0x715f('0x2f')](handleError(_0x50861f,null));};exports[_0x715f('0x59')]=function(_0x843135,_0x352ca5){var _0x74178e={'raw':!![],'where':{'id':_0x843135[_0x715f('0x5a')]['id']}},_0x556f05={};_0x556f05[_0x715f('0x48')]=_['keys'](db['ChatQueue'][_0x715f('0x44')]);_0x556f05[_0x715f('0x49')]=_['keys'](_0x843135['query']);_0x556f05[_0x715f('0x4b')]=_['intersection'](_0x556f05[_0x715f('0x48')],_0x556f05[_0x715f('0x49')]);_0x74178e[_0x715f('0x4d')]=_[_0x715f('0x4c')](_0x556f05[_0x715f('0x48')],qs[_0x715f('0x4e')](_0x843135[_0x715f('0x49')][_0x715f('0x4e')]));_0x74178e[_0x715f('0x4d')]=_0x74178e[_0x715f('0x4d')][_0x715f('0x5b')]?_0x74178e[_0x715f('0x4d')]:_0x556f05[_0x715f('0x48')];if(_0x843135[_0x715f('0x49')][_0x715f('0x56')]){_0x74178e['include']=[{'all':!![]}];}_0x74178e=_['merge']({},_0x74178e,_0x843135[_0x715f('0x5c')]);return db[_0x715f('0x43')]['find'](_0x74178e)[_0x715f('0x25')](handleEntityNotFound(_0x352ca5,null))[_0x715f('0x25')](respondWithResult(_0x352ca5,null))[_0x715f('0x2f')](handleError(_0x352ca5,null));};exports['create']=function(_0x1a3c25,_0x535365){return db['ChatQueue'][_0x715f('0x5d')](_0x1a3c25[_0x715f('0x5e')],{})[_0x715f('0x25')](function(_0x2c9075){var _0x1b069e=_0x1a3c25[_0x715f('0x5f')]['get']({'plain':!![]});if(!_0x1b069e)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x1b069e['role']===_0x715f('0x5f')){var _0x48aabf=_0x2c9075[_0x715f('0x3c')]({'plain':!![]});var _0x158485=_0x715f('0x60');return db[_0x715f('0x61')][_0x715f('0x62')]({'where':{'name':_0x158485,'userProfileId':_0x1b069e[_0x715f('0x63')]},'raw':!![]})[_0x715f('0x25')](function(_0x5c630e){if(_0x5c630e&&_0x5c630e[_0x715f('0x64')]===0x0){return db[_0x715f('0x3d')]['create']({'name':_0x48aabf[_0x715f('0x3f')],'resourceId':_0x48aabf['id'],'type':_0x5c630e[_0x715f('0x3f')],'sectionId':_0x5c630e['id']},{})['then'](function(){return _0x2c9075;});}else{return _0x2c9075;}})[_0x715f('0x2f')](function(_0x58e077){logger[_0x715f('0x2c')](_0x715f('0x65'),_0x58e077);throw _0x58e077;});}return _0x2c9075;})[_0x715f('0x25')](respondWithResult(_0x535365,0xc9))[_0x715f('0x2f')](handleError(_0x535365,null));};exports[_0x715f('0x66')]=function(_0x176a1f,_0x5287e5){if(_0x176a1f[_0x715f('0x5e')]['id']){delete _0x176a1f[_0x715f('0x5e')]['id'];}return db[_0x715f('0x43')]['find']({'where':{'id':_0x176a1f['params']['id']}})[_0x715f('0x25')](handleEntityNotFound(_0x5287e5,null))['then'](saveUpdates(_0x176a1f[_0x715f('0x5e')],null))[_0x715f('0x25')](respondWithResult(_0x5287e5,null))[_0x715f('0x2f')](handleError(_0x5287e5,null));};exports[_0x715f('0x3e')]=function(_0x57180d,_0x21ee82){return db[_0x715f('0x43')][_0x715f('0x62')]({'where':{'id':_0x57180d[_0x715f('0x5a')]['id']}})[_0x715f('0x25')](handleEntityNotFound(_0x21ee82,null))[_0x715f('0x25')](removeEntity(_0x21ee82,null))[_0x715f('0x2f')](handleError(_0x21ee82,null));};exports[_0x715f('0x67')]=function(_0x4495e3,_0x4cfefe){return db[_0x715f('0x43')]['describe']()['then'](respondWithResult(_0x4cfefe,null))[_0x715f('0x2f')](handleError(_0x4cfefe,null));};exports[_0x715f('0x68')]=function(_0x136325,_0x363ce0,_0x40c4fd){var _0x50cb61={'raw':!![],'where':{}},_0x317c47={},_0x323325;return db[_0x715f('0x43')][_0x715f('0x69')]({'where':{'id':_0x136325[_0x715f('0x5a')]['id']}})[_0x715f('0x25')](handleEntityNotFound(_0x363ce0,null))[_0x715f('0x25')](function(_0x20b1e1){if(_0x20b1e1){_0x323325=_0x20b1e1['get']({'plain':!![]});_0x317c47['model']=_[_0x715f('0x4a')](db['UserChatQueue'][_0x715f('0x44')]);_0x317c47[_0x715f('0x49')]=_['keys'](_0x136325[_0x715f('0x49')]);_0x317c47['filters']=_['intersection'](_0x317c47[_0x715f('0x48')],_0x317c47[_0x715f('0x49')]);_0x50cb61[_0x715f('0x4d')]=_[_0x715f('0x4c')](_0x317c47[_0x715f('0x48')],qs[_0x715f('0x4e')](_0x136325[_0x715f('0x49')]['fields']));_0x50cb61[_0x715f('0x4d')]=_0x50cb61[_0x715f('0x4d')]['length']?_0x50cb61[_0x715f('0x4d')]:_0x317c47[_0x715f('0x48')];if(!_0x136325[_0x715f('0x49')][_0x715f('0x4f')](_0x715f('0x6a'))){_0x50cb61['limit']=qs['limit'](_0x136325[_0x715f('0x49')]['limit']);_0x50cb61['offset']=qs[_0x715f('0x35')](_0x136325[_0x715f('0x49')][_0x715f('0x35')]);}_0x50cb61['order']=qs[_0x715f('0x51')](_0x136325[_0x715f('0x49')][_0x715f('0x51')]);_0x50cb61[_0x715f('0x52')]=qs[_0x715f('0x4b')](_[_0x715f('0x53')](_0x136325[_0x715f('0x49')],_0x317c47['filters']));_0x50cb61['where']['ChatQueueId']=_0x20b1e1['id'];if(_0x136325[_0x715f('0x49')]['filter']){_0x50cb61[_0x715f('0x52')]=_[_0x715f('0x55')](_0x50cb61[_0x715f('0x52')],{'$or':_[_0x715f('0x42')](_0x50cb61['attributes'],function(_0x504336){var _0x4d83dc={};_0x4d83dc[_0x504336]={'$like':'%'+_0x136325[_0x715f('0x49')][_0x715f('0x54')]+'%'};return _0x4d83dc;})});}_0x50cb61=_[_0x715f('0x55')]({},_0x50cb61,_0x136325[_0x715f('0x5c')]);return db[_0x715f('0x6b')][_0x715f('0x58')](_0x50cb61);}})['then'](function(_0x534b71){if(_0x534b71){return db[_0x715f('0x6c')][_0x715f('0x6d')]({'where':{'id':_[_0x715f('0x42')](_0x534b71,_0x715f('0x6e')),'role':'agent'},'attributes':['id',_0x715f('0x3f'),'chatPause',_0x715f('0x6f'),_0x715f('0x70')]});}})['then'](function(_0xbb315c){if(_0xbb315c){return{'count':_0xbb315c[_0x715f('0x34')],'rows':_[_0x715f('0x42')](_0xbb315c[_0x715f('0x71')],function(_0x1579dd){return{'membername':_0x1579dd['name'],'UserId':_0x1579dd['id'],'queue_name':_0x323325[_0x715f('0x3f')],'ChatQueueId':_0x323325['id'],'interface':util[_0x715f('0x72')](_0x715f('0x73'),_0x715f('0x74'),_0x1579dd['name']),'penalty':0x0,'paused':_0x1579dd['chatPause'],'createdAt':_0x1579dd[_0x715f('0x70')],'updatedAt':_0x1579dd['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0x715f('0x25')](respondWithFilteredResult(_0x363ce0,_0x50cb61))[_0x715f('0x2f')](handleError(_0x363ce0,null));};exports[_0x715f('0x75')]=function(_0x561a37,_0x3d6a02,_0x120927){var _0x524795={};var _0x48f79a={};var _0x250269;var _0x48af7f;return db[_0x715f('0x43')][_0x715f('0x69')]({'where':{'id':_0x561a37['params']['id']}})['then'](handleEntityNotFound(_0x3d6a02,null))[_0x715f('0x25')](function(_0x5b55c6){if(_0x5b55c6){_0x250269=_0x5b55c6;_0x48f79a['model']=_[_0x715f('0x4a')](db[_0x715f('0x76')][_0x715f('0x44')]);_0x48f79a[_0x715f('0x49')]=_[_0x715f('0x4a')](_0x561a37['query']);_0x48f79a[_0x715f('0x4b')]=_[_0x715f('0x4c')](_0x48f79a[_0x715f('0x48')],_0x48f79a['query']);_0x524795[_0x715f('0x4d')]=_[_0x715f('0x4c')](_0x48f79a['model'],qs[_0x715f('0x4e')](_0x561a37[_0x715f('0x49')][_0x715f('0x4e')]));_0x524795[_0x715f('0x4d')]=_0x524795['attributes'][_0x715f('0x5b')]?_0x524795[_0x715f('0x4d')]:_0x48f79a[_0x715f('0x48')];_0x524795[_0x715f('0x50')]=qs[_0x715f('0x51')](_0x561a37[_0x715f('0x49')]['sort']);_0x524795[_0x715f('0x52')]=qs[_0x715f('0x4b')](_[_0x715f('0x53')](_0x561a37[_0x715f('0x49')],_0x48f79a[_0x715f('0x4b')]));if(_0x561a37[_0x715f('0x49')][_0x715f('0x54')]){_0x524795['where']=_[_0x715f('0x55')](_0x524795[_0x715f('0x52')],{'$or':_[_0x715f('0x42')](_0x524795[_0x715f('0x4d')],function(_0x3e602b){var _0x5c62aa={};_0x5c62aa[_0x3e602b]={'$like':'%'+_0x561a37[_0x715f('0x49')][_0x715f('0x54')]+'%'};return _0x5c62aa;})});}_0x524795=_[_0x715f('0x55')]({},_0x524795,_0x561a37['options']);return _0x250269['getTeams'](_0x524795);}})['then'](function(_0x29b8d1){if(_0x29b8d1){_0x48af7f=_0x29b8d1[_0x715f('0x5b')];if(!_0x561a37[_0x715f('0x49')][_0x715f('0x4f')]('nolimit')){_0x524795[_0x715f('0x36')]=qs[_0x715f('0x36')](_0x561a37[_0x715f('0x49')][_0x715f('0x36')]);_0x524795[_0x715f('0x35')]=qs[_0x715f('0x35')](_0x561a37[_0x715f('0x49')]['offset']);}return _0x250269[_0x715f('0x75')](_0x524795);}})[_0x715f('0x25')](function(_0x558818){if(_0x558818){return _0x558818?{'count':_0x48af7f,'rows':_0x558818}:null;}})['then'](respondWithResult(_0x3d6a02,null))[_0x715f('0x2f')](handleError(_0x3d6a02,null));};exports[_0x715f('0x77')]=function(_0x51d3b6,_0x1b80ff,_0x5ad9f9){var _0x4d43b6=_0x51d3b6[_0x715f('0x5e')][_0x715f('0x78')];return db[_0x715f('0x76')][_0x715f('0x58')]({'where':{'id':_0x4d43b6},'attributes':['id'],'include':[{'model':db[_0x715f('0x6c')],'as':'Agents','attributes':['id',_0x715f('0x3f'),_0x715f('0x79'),_0x715f('0x7a'),_0x715f('0x7b')],'raw':!![]}]})['then'](function(_0x5c3518){if(_0x5c3518){var _0xd5511c=_[_0x715f('0x7c')](_0x5c3518,function(_0x14c697){var _0x75acce=_0x14c697[_0x715f('0x3c')]({'plain':!![]});return _0x75acce[_0x715f('0x7d')];});return db['ChatQueue']['find']({'where':{'id':_0x51d3b6[_0x715f('0x5a')]['id']}})[_0x715f('0x25')](function(_0x68d8){return db['sequelize'][_0x715f('0x7e')](function(_0x3b2792){return _0x68d8[_0x715f('0x77')](_0x4d43b6,{'transaction':_0x3b2792})[_0x715f('0x25')](function(){return BPromise[_0x715f('0x7f')](_0xd5511c,function(_0x32984c){return db[_0x715f('0x6b')][_0x715f('0x80')]({'where':{'UserId':_0x32984c['id'],'ChatQueueId':_0x51d3b6['params']['id']},'transaction':_0x3b2792});});})[_0x715f('0x25')](function(){_0xd5511c[_0x715f('0x81')](function(_0x3651f0){socket['emit'](_0x715f('0x82'),{'UserId':_0x3651f0['id'],'ChatQueueId':_0x68d8['id']});});});});});}})[_0x715f('0x25')](respondWithStatusCode(_0x1b80ff,null))[_0x715f('0x2f')](handleError(_0x1b80ff,null));};exports['removeTeams']=function(_0x4099e5,_0x5c5b33,_0x3d114b){return db[_0x715f('0x76')][_0x715f('0x58')]({'where':{'id':_0x4099e5[_0x715f('0x49')][_0x715f('0x78')]},'attributes':['id'],'include':[{'model':db[_0x715f('0x6c')],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0x715f('0x25')](handleEntityNotFound(_0x5c5b33,null))['then'](function(_0x2f2149){var _0x5a2830=_[_0x715f('0x42')](_0x2f2149,'id');var _0x1d3ab3=[];var _0x3f68b7=[];var _0x89609e=squel['select']();_0x89609e[_0x715f('0x83')](_0x715f('0x84'))[_0x715f('0x85')]('team_has_chat_queues','tq')[_0x715f('0x86')]('user_has_teams','ut',_0x715f('0x87'))[_0x715f('0x52')](_0x715f('0x88'),_0x4099e5[_0x715f('0x5a')]['id']);for(var _0x25fc36=0x0;_0x25fc36<_0x2f2149[_0x715f('0x5b')];_0x25fc36+=0x1){let _0x3fda11=_0x2f2149[_0x25fc36];for(var _0x49a801=0x0;_0x49a801<_0x3fda11[_0x715f('0x7d')][_0x715f('0x5b')];_0x49a801+=0x1){let _0x51dad7=_0x3fda11['Agents'][_0x49a801];var _0x41bfc3=_0x89609e[_0x715f('0x89')]();_0x41bfc3[_0x715f('0x52')](_0x715f('0x8a'),_0x51dad7['id']);_0x3f68b7[_0x715f('0x8b')](db[_0x715f('0x8c')][_0x715f('0x49')](_0x41bfc3['toString'](),{'type':db['sequelize'][_0x715f('0x8d')]['SELECT']})[_0x715f('0x25')](function(_0xbf7d65){if(_0xbf7d65[_0x715f('0x5b')]===0x1){return _0x51dad7['id'];}else{var _0x301c8f=_[_0x715f('0x8e')](_[_0x715f('0x42')](_0xbf7d65,'TeamId'),function(_0x305c42){return _[_0x715f('0x8f')](_0x5a2830,_0x305c42);});if(_0x301c8f){return _0x51dad7['id'];}}}));}}return BPromise[_0x715f('0x90')](_0x3f68b7)['then'](function(_0x44bba0){_0x1d3ab3=_(_0x1d3ab3)[_0x715f('0x91')](_0x44bba0)[_0x715f('0x92')]()[_0x715f('0x93')]();return db[_0x715f('0x43')][_0x715f('0x62')]({'where':{'id':_0x4099e5['params']['id']}})[_0x715f('0x25')](function(_0x4b7b07){return db[_0x715f('0x8c')][_0x715f('0x7e')](function(_0x36e557){return _0x4b7b07['removeTeams'](_0x4099e5[_0x715f('0x49')][_0x715f('0x78')],{'transaction':_0x36e557})[_0x715f('0x25')](function(){if(!_[_0x715f('0x94')](_0x1d3ab3)){return _0x4b7b07[_0x715f('0x95')](_0x1d3ab3,{'transaction':_0x36e557});}})[_0x715f('0x25')](function(){_0x1d3ab3[_0x715f('0x81')](function(_0x316cbd){socket[_0x715f('0x96')]('userChatQueue:remove',{'UserId':_0x316cbd,'ChatQueueId':_0x4b7b07['id']});});});});});});})['then'](respondWithStatusCode(_0x5c5b33,null))[_0x715f('0x2f')](handleError(_0x5c5b33,null));};exports['addAgents']=function(_0x27ffef,_0x1d9d3e,_0x5e2c79){return db[_0x715f('0x43')][_0x715f('0x62')]({'where':{'id':_0x27ffef[_0x715f('0x5a')]['id']}})[_0x715f('0x25')](handleEntityNotFound(_0x1d9d3e,null))[_0x715f('0x25')](function(_0x1d9352){if(_0x1d9352){return _0x1d9352[_0x715f('0x97')](_0x27ffef[_0x715f('0x5e')][_0x715f('0x78')],_[_0x715f('0x98')](_0x27ffef[_0x715f('0x5e')],[_0x715f('0x78'),'id'])||{})[_0x715f('0x99')](function(_0x506fe9){for(var _0x2d4f7e=0x0;_0x2d4f7e<_0x27ffef[_0x715f('0x5e')]['ids']['length'];_0x2d4f7e+=0x1){socket[_0x715f('0x96')](_0x715f('0x82'),{'UserId':_0x27ffef[_0x715f('0x5e')][_0x715f('0x78')][_0x2d4f7e],'ChatQueueId':_0x27ffef[_0x715f('0x5a')]['id']});}return _0x506fe9;});}})['then'](respondWithResult(_0x1d9d3e,null))[_0x715f('0x2f')](handleError(_0x1d9d3e,null));};exports['removeAgents']=function(_0x17560e,_0x572011,_0x8bb7a3){return db[_0x715f('0x43')][_0x715f('0x62')]({'where':{'id':_0x17560e[_0x715f('0x5a')]['id']}})[_0x715f('0x25')](handleEntityNotFound(_0x572011,null))[_0x715f('0x25')](function(_0x589a6c){if(_0x589a6c){return _0x589a6c['removeAgents'](_0x17560e[_0x715f('0x49')][_0x715f('0x78')])[_0x715f('0x25')](function(){if(_[_0x715f('0x9a')](_0x17560e[_0x715f('0x49')][_0x715f('0x78')])){for(var _0x1dcb4e=0x0;_0x1dcb4e<_0x17560e['query'][_0x715f('0x78')][_0x715f('0x5b')];_0x1dcb4e+=0x1){socket[_0x715f('0x96')](_0x715f('0x9b'),{'UserId':Number(_0x17560e[_0x715f('0x49')][_0x715f('0x78')][_0x1dcb4e]),'ChatQueueId':Number(_0x17560e[_0x715f('0x5a')]['id'])});}}else{socket[_0x715f('0x96')](_0x715f('0x9b'),{'UserId':Number(_0x17560e[_0x715f('0x49')]['ids']),'ChatQueueId':Number(_0x17560e[_0x715f('0x5a')]['id'])});}});}})[_0x715f('0x25')](respondWithStatusCode(_0x572011,null))[_0x715f('0x2f')](handleError(_0x572011,null));};exports[_0x715f('0x9c')]=function(_0x7214b4,_0x251487,_0x1698ac){var _0x53655d={};var _0x4968f7={};var _0x13dc88;var _0x44a9cb;return db[_0x715f('0x43')]['findOne']({'where':{'id':_0x7214b4[_0x715f('0x5a')]['id']}})[_0x715f('0x25')](handleEntityNotFound(_0x251487,null))[_0x715f('0x25')](function(_0x2d75f7){if(_0x2d75f7){_0x13dc88=_0x2d75f7;_0x4968f7['model']=_[_0x715f('0x4a')](db['User'][_0x715f('0x44')]);_0x4968f7[_0x715f('0x49')]=_['keys'](_0x7214b4[_0x715f('0x49')]);_0x4968f7['filters']=_[_0x715f('0x4c')](_0x4968f7[_0x715f('0x48')],_0x4968f7[_0x715f('0x49')]);_0x53655d[_0x715f('0x4d')]=_[_0x715f('0x4c')](_0x4968f7[_0x715f('0x48')],qs[_0x715f('0x4e')](_0x7214b4['query'][_0x715f('0x4e')]));_0x53655d['attributes']=_0x53655d['attributes'][_0x715f('0x5b')]?_0x53655d[_0x715f('0x4d')]:_0x4968f7[_0x715f('0x48')];_0x53655d[_0x715f('0x50')]=qs[_0x715f('0x51')](_0x7214b4['query']['sort']);_0x53655d[_0x715f('0x52')]=qs[_0x715f('0x4b')](_[_0x715f('0x53')](_0x7214b4[_0x715f('0x49')],_0x4968f7[_0x715f('0x4b')]));if(_0x7214b4['query'][_0x715f('0x54')]){_0x53655d['where']=_[_0x715f('0x55')](_0x53655d['where'],{'$or':_[_0x715f('0x42')](_0x53655d[_0x715f('0x4d')],function(_0x439fa7){var _0x32b53b={};_0x32b53b[_0x439fa7]={'$like':'%'+_0x7214b4[_0x715f('0x49')][_0x715f('0x54')]+'%'};return _0x32b53b;})});}_0x53655d=_[_0x715f('0x55')]({},_0x53655d,_0x7214b4[_0x715f('0x5c')]);return _0x13dc88[_0x715f('0x9c')](_0x53655d);}})[_0x715f('0x25')](function(_0x1e3b58){if(_0x1e3b58){_0x44a9cb=_0x1e3b58['length'];if(!_0x7214b4[_0x715f('0x49')][_0x715f('0x4f')](_0x715f('0x6a'))){_0x53655d[_0x715f('0x36')]=qs['limit'](_0x7214b4['query'][_0x715f('0x36')]);_0x53655d['offset']=qs['offset'](_0x7214b4[_0x715f('0x49')][_0x715f('0x35')]);}return _0x13dc88[_0x715f('0x9c')](_0x53655d);}})[_0x715f('0x25')](function(_0x29bfb9){if(_0x29bfb9){return _0x29bfb9?{'count':_0x44a9cb,'rows':_0x29bfb9}:null;}})[_0x715f('0x25')](respondWithResult(_0x251487,null))[_0x715f('0x2f')](handleError(_0x251487,null));};
\ No newline at end of file
+var _0xfab0=['field','tq.TeamId','from','team_has_chat_queues','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','push','sequelize','toString','QueryTypes','SELECT','every','union','value','transaction','isEmpty','userChatQueue:remove','omit','spread','userChatQueue:save','isArray','getAgents','findOne','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','path','ejs','lodash','crypto','jsforce','to-csv','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatQueue.socket','register','jayson/promise','client','request','then','info','ChatQueue,\x20%s,\x20%s','request\x20sent','error','code','message','catch','sendStatus','status','json','offset','undefined','count','Content-Range','apply','reject','save','destroy','get','UserProfileResource','end','stack','name','index','ChatQueue','rawAttributes','fieldName','type','key','model','map','keys','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','filters','filter','merge','VIRTUAL','options','rows','show','params','includeAll','include','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','ChatQueues','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','getMembers','pick','ChatQueueId','UserChatQueue','findAndCountAll','UserId','agent','chatPause','updatedAt','createdAt','format','%s/%s','SIP','getTeams','addTeams','ids','Team','User','voicePause','interface','flatMap','Agents','each','findOrCreate','forEach','emit','removeTeams','findAll','select'];(function(_0x20961b,_0x121bba){var _0x48ad1c=function(_0xe59db4){while(--_0xe59db4){_0x20961b['push'](_0x20961b['shift']());}};_0x48ad1c(++_0x121bba);}(_0xfab0,0x1e1));var _0x0fab=function(_0x29d4b5,_0x1913e2){_0x29d4b5=_0x29d4b5-0x0;var _0x3fbb01=_0xfab0[_0x29d4b5];return _0x3fbb01;};'use strict';var emlformat=require(_0x0fab('0x0'));var rimraf=require(_0x0fab('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x0fab('0x2'));var rp=require(_0x0fab('0x3'));var moment=require(_0x0fab('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x0fab('0x5'));var util=require(_0x0fab('0x6'));var path=require(_0x0fab('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x0fab('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x0fab('0x9'));var squel=require('squel');var crypto=require(_0x0fab('0xa'));var jsforce=require(_0x0fab('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x0fab('0xc'));var querystring=require('querystring');var Papa=require(_0x0fab('0xd'));var Redis=require('ioredis');var authService=require(_0x0fab('0xe'));var qs=require(_0x0fab('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x0fab('0x10'));var logger=require(_0x0fab('0x11'))(_0x0fab('0x12'));var utils=require(_0x0fab('0x13'));var config=require(_0x0fab('0x14'));var licenseUtil=require(_0x0fab('0x15'));var db=require(_0x0fab('0x16'))['db'];config[_0x0fab('0x17')]=_[_0x0fab('0x18')](config[_0x0fab('0x17')],{'host':_0x0fab('0x19'),'port':0x18eb});var socket=require(_0x0fab('0x1a'))(new Redis(config['redis']));require(_0x0fab('0x1b'))[_0x0fab('0x1c')](socket);var jayson=require(_0x0fab('0x1d'));var client=jayson[_0x0fab('0x1e')]['http']({'port':0x232a});function respondWithRpcPromise(_0x3cb473,_0xc532ed,_0x1da4c9,_0x50e0bd){return new BPromise(function(_0x37a759,_0x1e8c9c){var _0x871a34=_0x50e0bd||client;return _0x871a34[_0x0fab('0x1f')](_0x3cb473,_0x1da4c9)[_0x0fab('0x20')](function(_0x5d1743){logger[_0x0fab('0x21')](_0x0fab('0x22'),_0xc532ed,'request\x20sent');logger['debug']('ChatQueue,\x20%s,\x20%s,\x20%s',_0xc532ed,_0x0fab('0x23'),JSON['stringify'](_0x5d1743));if(_0x5d1743[_0x0fab('0x24')]){if(_0x5d1743[_0x0fab('0x24')][_0x0fab('0x25')]===0x1f4){logger['error']('ChatQueue,\x20%s,\x20%s',_0xc532ed,_0x5d1743[_0x0fab('0x24')][_0x0fab('0x26')]);return _0x1e8c9c(_0x5d1743[_0x0fab('0x24')][_0x0fab('0x26')]);}logger[_0x0fab('0x24')]('ChatQueue,\x20%s,\x20%s',_0xc532ed,_0x5d1743[_0x0fab('0x24')][_0x0fab('0x26')]);return _0x37a759(_0x5d1743['error'][_0x0fab('0x26')]);}else{logger[_0x0fab('0x21')]('ChatQueue,\x20%s,\x20%s',_0xc532ed,'request\x20sent');_0x37a759(_0x5d1743['result'][_0x0fab('0x26')]);}})[_0x0fab('0x27')](function(_0x4c23f5){logger[_0x0fab('0x24')]('ChatQueue,\x20%s,\x20%s',_0xc532ed,_0x4c23f5);_0x1e8c9c(_0x4c23f5);});});}function respondWithStatusCode(_0x163c34,_0x229b30){_0x229b30=_0x229b30||0xcc;return function(_0x23ea75){if(_0x23ea75){return _0x163c34[_0x0fab('0x28')](_0x229b30);}return _0x163c34[_0x0fab('0x29')](_0x229b30)['end']();};}function respondWithResult(_0x2788df,_0x2a61e2){_0x2a61e2=_0x2a61e2||0xc8;return function(_0x404501){if(_0x404501){return _0x2788df[_0x0fab('0x29')](_0x2a61e2)[_0x0fab('0x2a')](_0x404501);}};}function respondWithFilteredResult(_0x53e595,_0x41b638){return function(_0x16b054){if(_0x16b054){var _0x308e57=typeof _0x41b638[_0x0fab('0x2b')]==='undefined'&&typeof _0x41b638['limit']===_0x0fab('0x2c');var _0x9f6dbf=_0x16b054[_0x0fab('0x2d')];var _0x398fd7=_0x308e57?0x0:_0x41b638[_0x0fab('0x2b')];var _0x338a43=_0x308e57?_0x16b054[_0x0fab('0x2d')]:_0x41b638[_0x0fab('0x2b')]+_0x41b638['limit'];var _0x39acae;if(_0x338a43>=_0x9f6dbf){_0x338a43=_0x9f6dbf;_0x39acae=0xc8;}else{_0x39acae=0xce;}_0x53e595[_0x0fab('0x29')](_0x39acae);return _0x53e595['set'](_0x0fab('0x2e'),_0x398fd7+'-'+_0x338a43+'/'+_0x9f6dbf)[_0x0fab('0x2a')](_0x16b054);}return null;};}function patchUpdates(_0x3adea5){return function(_0x5e947f){try{jsonpatch[_0x0fab('0x2f')](_0x5e947f,_0x3adea5,!![]);}catch(_0x5929a2){return BPromise[_0x0fab('0x30')](_0x5929a2);}return _0x5e947f[_0x0fab('0x31')]();};}function saveUpdates(_0x66fffa,_0x62e53d){return function(_0x294257){if(_0x294257){return _0x294257['update'](_0x66fffa)[_0x0fab('0x20')](function(_0x23751c){return _0x23751c;});}return null;};}function removeEntity(_0x1c705d,_0x25808c){return function(_0xb527fe){if(_0xb527fe){return _0xb527fe[_0x0fab('0x32')]()[_0x0fab('0x20')](function(){var _0x1d90f5=_0xb527fe[_0x0fab('0x33')]({'plain':!![]});var _0xc69907='ChatQueues';return db[_0x0fab('0x34')]['destroy']({'where':{'type':_0xc69907,'resourceId':_0x1d90f5['id']}})[_0x0fab('0x20')](function(){return _0xb527fe;});})['then'](function(){_0x1c705d[_0x0fab('0x29')](0xcc)[_0x0fab('0x35')]();});}};}function handleEntityNotFound(_0x32156c,_0x4d00d5){return function(_0x4ee356){if(!_0x4ee356){_0x32156c[_0x0fab('0x28')](0x194);}return _0x4ee356;};}function handleError(_0x29a473,_0x1d6c94){_0x1d6c94=_0x1d6c94||0x1f4;return function(_0x301a98){logger[_0x0fab('0x24')](_0x301a98[_0x0fab('0x36')]);if(_0x301a98[_0x0fab('0x37')]){delete _0x301a98[_0x0fab('0x37')];}_0x29a473['status'](_0x1d6c94)['send'](_0x301a98);};}exports[_0x0fab('0x38')]=function(_0x435bcc,_0x570dea){var _0x3608c3={},_0x50471e={},_0x193a32={'count':0x0,'rows':[]};var _0x148a76=_['map'](db[_0x0fab('0x39')][_0x0fab('0x3a')],function(_0x15a3d2){return{'name':_0x15a3d2[_0x0fab('0x3b')],'type':_0x15a3d2[_0x0fab('0x3c')][_0x0fab('0x3d')]};});_0x50471e[_0x0fab('0x3e')]=_[_0x0fab('0x3f')](_0x148a76,'name');_0x50471e['query']=_[_0x0fab('0x40')](_0x435bcc[_0x0fab('0x41')]);_0x50471e['filters']=_[_0x0fab('0x42')](_0x50471e[_0x0fab('0x3e')],_0x50471e[_0x0fab('0x41')]);_0x3608c3[_0x0fab('0x43')]=_[_0x0fab('0x42')](_0x50471e[_0x0fab('0x3e')],qs[_0x0fab('0x44')](_0x435bcc[_0x0fab('0x41')][_0x0fab('0x44')]));_0x3608c3[_0x0fab('0x43')]=_0x3608c3[_0x0fab('0x43')][_0x0fab('0x45')]?_0x3608c3[_0x0fab('0x43')]:_0x50471e['model'];if(!_0x435bcc[_0x0fab('0x41')][_0x0fab('0x46')](_0x0fab('0x47'))){_0x3608c3['limit']=qs['limit'](_0x435bcc[_0x0fab('0x41')][_0x0fab('0x48')]);_0x3608c3[_0x0fab('0x2b')]=qs[_0x0fab('0x2b')](_0x435bcc[_0x0fab('0x41')][_0x0fab('0x2b')]);}_0x3608c3[_0x0fab('0x49')]=qs[_0x0fab('0x4a')](_0x435bcc[_0x0fab('0x41')][_0x0fab('0x4a')]);_0x3608c3[_0x0fab('0x4b')]=qs[_0x0fab('0x4c')](_['pick'](_0x435bcc[_0x0fab('0x41')],_0x50471e[_0x0fab('0x4c')]),_0x148a76);if(_0x435bcc[_0x0fab('0x41')][_0x0fab('0x4d')]){_0x3608c3[_0x0fab('0x4b')]=_[_0x0fab('0x4e')](_0x3608c3[_0x0fab('0x4b')],{'$or':_[_0x0fab('0x3f')](_0x148a76,function(_0x1c60e0){if(_0x1c60e0['type']!==_0x0fab('0x4f')){var _0x20425b={};_0x20425b[_0x1c60e0['name']]={'$like':'%'+_0x435bcc[_0x0fab('0x41')]['filter']+'%'};return _0x20425b;}})});}_0x3608c3=_[_0x0fab('0x4e')]({},_0x3608c3,_0x435bcc[_0x0fab('0x50')]);var _0x4751a1={'where':_0x3608c3['where']};return db[_0x0fab('0x39')][_0x0fab('0x2d')](_0x4751a1)[_0x0fab('0x20')](function(_0x3f5bbd){_0x193a32['count']=_0x3f5bbd;if(_0x435bcc[_0x0fab('0x41')]['includeAll']){_0x3608c3['include']=[{'all':!![]}];}return db[_0x0fab('0x39')]['findAll'](_0x3608c3);})[_0x0fab('0x20')](function(_0x55034a){_0x193a32[_0x0fab('0x51')]=_0x55034a;return _0x193a32;})[_0x0fab('0x20')](respondWithFilteredResult(_0x570dea,_0x3608c3))[_0x0fab('0x27')](handleError(_0x570dea,null));};exports[_0x0fab('0x52')]=function(_0x2afb97,_0xcf571e){var _0x18f4f1={'raw':!![],'where':{'id':_0x2afb97[_0x0fab('0x53')]['id']}},_0x25c8c9={};_0x25c8c9[_0x0fab('0x3e')]=_[_0x0fab('0x40')](db[_0x0fab('0x39')]['rawAttributes']);_0x25c8c9[_0x0fab('0x41')]=_['keys'](_0x2afb97[_0x0fab('0x41')]);_0x25c8c9['filters']=_[_0x0fab('0x42')](_0x25c8c9[_0x0fab('0x3e')],_0x25c8c9[_0x0fab('0x41')]);_0x18f4f1[_0x0fab('0x43')]=_['intersection'](_0x25c8c9[_0x0fab('0x3e')],qs['fields'](_0x2afb97[_0x0fab('0x41')][_0x0fab('0x44')]));_0x18f4f1[_0x0fab('0x43')]=_0x18f4f1[_0x0fab('0x43')][_0x0fab('0x45')]?_0x18f4f1[_0x0fab('0x43')]:_0x25c8c9['model'];if(_0x2afb97['query'][_0x0fab('0x54')]){_0x18f4f1[_0x0fab('0x55')]=[{'all':!![]}];}_0x18f4f1=_[_0x0fab('0x4e')]({},_0x18f4f1,_0x2afb97[_0x0fab('0x50')]);return db[_0x0fab('0x39')][_0x0fab('0x56')](_0x18f4f1)[_0x0fab('0x20')](handleEntityNotFound(_0xcf571e,null))[_0x0fab('0x20')](respondWithResult(_0xcf571e,null))[_0x0fab('0x27')](handleError(_0xcf571e,null));};exports[_0x0fab('0x57')]=function(_0x1ea20f,_0x3475fc){return db[_0x0fab('0x39')][_0x0fab('0x57')](_0x1ea20f[_0x0fab('0x58')],{})[_0x0fab('0x20')](function(_0x4aef11){var _0x4a6906=_0x1ea20f[_0x0fab('0x59')]['get']({'plain':!![]});if(!_0x4a6906)throw new Error(_0x0fab('0x5a'));if(_0x4a6906['role']==='user'){var _0x527f35=_0x4aef11[_0x0fab('0x33')]({'plain':!![]});var _0x3b0cb8=_0x0fab('0x5b');return db[_0x0fab('0x5c')][_0x0fab('0x56')]({'where':{'name':_0x3b0cb8,'userProfileId':_0x4a6906[_0x0fab('0x5d')]},'raw':!![]})[_0x0fab('0x20')](function(_0x374021){if(_0x374021&&_0x374021[_0x0fab('0x5e')]===0x0){return db[_0x0fab('0x34')]['create']({'name':_0x527f35[_0x0fab('0x37')],'resourceId':_0x527f35['id'],'type':_0x374021['name'],'sectionId':_0x374021['id']},{})['then'](function(){return _0x4aef11;});}else{return _0x4aef11;}})[_0x0fab('0x27')](function(_0x41cc55){logger[_0x0fab('0x24')](_0x0fab('0x5f'),_0x41cc55);throw _0x41cc55;});}return _0x4aef11;})[_0x0fab('0x20')](respondWithResult(_0x3475fc,0xc9))[_0x0fab('0x27')](handleError(_0x3475fc,null));};exports[_0x0fab('0x60')]=function(_0x4de2cc,_0x558059){if(_0x4de2cc[_0x0fab('0x58')]['id']){delete _0x4de2cc[_0x0fab('0x58')]['id'];}return db[_0x0fab('0x39')]['find']({'where':{'id':_0x4de2cc['params']['id']}})[_0x0fab('0x20')](handleEntityNotFound(_0x558059,null))['then'](saveUpdates(_0x4de2cc[_0x0fab('0x58')],null))['then'](respondWithResult(_0x558059,null))[_0x0fab('0x27')](handleError(_0x558059,null));};exports[_0x0fab('0x32')]=function(_0x267bf4,_0x460c80){return db[_0x0fab('0x39')][_0x0fab('0x56')]({'where':{'id':_0x267bf4[_0x0fab('0x53')]['id']}})['then'](handleEntityNotFound(_0x460c80,null))[_0x0fab('0x20')](removeEntity(_0x460c80,null))[_0x0fab('0x27')](handleError(_0x460c80,null));};exports['describe']=function(_0x2f4ee9,_0x5cc387){return db[_0x0fab('0x39')][_0x0fab('0x61')]()[_0x0fab('0x20')](respondWithResult(_0x5cc387,null))[_0x0fab('0x27')](handleError(_0x5cc387,null));};exports[_0x0fab('0x62')]=function(_0x4702d7,_0x493636,_0x257230){var _0x50f66a={'raw':!![],'where':{}},_0x2f4eed={},_0x2f09b2;return db['ChatQueue']['findOne']({'where':{'id':_0x4702d7['params']['id']}})[_0x0fab('0x20')](handleEntityNotFound(_0x493636,null))[_0x0fab('0x20')](function(_0x58d8d2){if(_0x58d8d2){_0x2f09b2=_0x58d8d2[_0x0fab('0x33')]({'plain':!![]});_0x2f4eed['model']=_[_0x0fab('0x40')](db['UserChatQueue']['rawAttributes']);_0x2f4eed[_0x0fab('0x41')]=_['keys'](_0x4702d7[_0x0fab('0x41')]);_0x2f4eed[_0x0fab('0x4c')]=_[_0x0fab('0x42')](_0x2f4eed['model'],_0x2f4eed[_0x0fab('0x41')]);_0x50f66a[_0x0fab('0x43')]=_['intersection'](_0x2f4eed[_0x0fab('0x3e')],qs['fields'](_0x4702d7[_0x0fab('0x41')]['fields']));_0x50f66a[_0x0fab('0x43')]=_0x50f66a[_0x0fab('0x43')][_0x0fab('0x45')]?_0x50f66a[_0x0fab('0x43')]:_0x2f4eed[_0x0fab('0x3e')];if(!_0x4702d7[_0x0fab('0x41')][_0x0fab('0x46')](_0x0fab('0x47'))){_0x50f66a[_0x0fab('0x48')]=qs[_0x0fab('0x48')](_0x4702d7[_0x0fab('0x41')]['limit']);_0x50f66a[_0x0fab('0x2b')]=qs[_0x0fab('0x2b')](_0x4702d7[_0x0fab('0x41')][_0x0fab('0x2b')]);}_0x50f66a[_0x0fab('0x49')]=qs[_0x0fab('0x4a')](_0x4702d7['query'][_0x0fab('0x4a')]);_0x50f66a['where']=qs[_0x0fab('0x4c')](_[_0x0fab('0x63')](_0x4702d7[_0x0fab('0x41')],_0x2f4eed[_0x0fab('0x4c')]));_0x50f66a[_0x0fab('0x4b')][_0x0fab('0x64')]=_0x58d8d2['id'];if(_0x4702d7[_0x0fab('0x41')][_0x0fab('0x4d')]){_0x50f66a[_0x0fab('0x4b')]=_['merge'](_0x50f66a[_0x0fab('0x4b')],{'$or':_[_0x0fab('0x3f')](_0x50f66a['attributes'],function(_0x48afc8){var _0x5f3186={};_0x5f3186[_0x48afc8]={'$like':'%'+_0x4702d7[_0x0fab('0x41')][_0x0fab('0x4d')]+'%'};return _0x5f3186;})});}_0x50f66a=_[_0x0fab('0x4e')]({},_0x50f66a,_0x4702d7[_0x0fab('0x50')]);return db[_0x0fab('0x65')]['findAll'](_0x50f66a);}})[_0x0fab('0x20')](function(_0x595f74){if(_0x595f74){return db['User'][_0x0fab('0x66')]({'where':{'id':_['map'](_0x595f74,_0x0fab('0x67')),'role':_0x0fab('0x68')},'attributes':['id','name',_0x0fab('0x69'),_0x0fab('0x6a'),_0x0fab('0x6b')]});}})[_0x0fab('0x20')](function(_0x1d9ac7){if(_0x1d9ac7){return{'count':_0x1d9ac7[_0x0fab('0x2d')],'rows':_[_0x0fab('0x3f')](_0x1d9ac7['rows'],function(_0x3c4e81){return{'membername':_0x3c4e81[_0x0fab('0x37')],'UserId':_0x3c4e81['id'],'queue_name':_0x2f09b2['name'],'ChatQueueId':_0x2f09b2['id'],'interface':util[_0x0fab('0x6c')](_0x0fab('0x6d'),_0x0fab('0x6e'),_0x3c4e81[_0x0fab('0x37')]),'penalty':0x0,'paused':_0x3c4e81[_0x0fab('0x69')],'createdAt':_0x3c4e81[_0x0fab('0x6b')],'updatedAt':_0x3c4e81[_0x0fab('0x6a')]};})};}else{return{'count':0x0,'rows':[]};}})[_0x0fab('0x20')](respondWithFilteredResult(_0x493636,_0x50f66a))['catch'](handleError(_0x493636,null));};exports[_0x0fab('0x6f')]=function(_0x14b376,_0xd8b4fd,_0x10fa39){var _0x50ffc8={};var _0x5a74a0={};var _0x59a27b;var _0x895c8c;return db[_0x0fab('0x39')]['findOne']({'where':{'id':_0x14b376[_0x0fab('0x53')]['id']}})['then'](handleEntityNotFound(_0xd8b4fd,null))[_0x0fab('0x20')](function(_0x21d1dd){if(_0x21d1dd){_0x59a27b=_0x21d1dd;_0x5a74a0[_0x0fab('0x3e')]=_['keys'](db['Team'][_0x0fab('0x3a')]);_0x5a74a0[_0x0fab('0x41')]=_[_0x0fab('0x40')](_0x14b376[_0x0fab('0x41')]);_0x5a74a0[_0x0fab('0x4c')]=_['intersection'](_0x5a74a0['model'],_0x5a74a0[_0x0fab('0x41')]);_0x50ffc8[_0x0fab('0x43')]=_['intersection'](_0x5a74a0[_0x0fab('0x3e')],qs[_0x0fab('0x44')](_0x14b376[_0x0fab('0x41')][_0x0fab('0x44')]));_0x50ffc8[_0x0fab('0x43')]=_0x50ffc8['attributes']['length']?_0x50ffc8['attributes']:_0x5a74a0[_0x0fab('0x3e')];_0x50ffc8['order']=qs['sort'](_0x14b376['query']['sort']);_0x50ffc8['where']=qs[_0x0fab('0x4c')](_[_0x0fab('0x63')](_0x14b376[_0x0fab('0x41')],_0x5a74a0['filters']));if(_0x14b376['query']['filter']){_0x50ffc8[_0x0fab('0x4b')]=_['merge'](_0x50ffc8[_0x0fab('0x4b')],{'$or':_[_0x0fab('0x3f')](_0x50ffc8[_0x0fab('0x43')],function(_0x10f8bb){var _0xfd015b={};_0xfd015b[_0x10f8bb]={'$like':'%'+_0x14b376[_0x0fab('0x41')][_0x0fab('0x4d')]+'%'};return _0xfd015b;})});}_0x50ffc8=_[_0x0fab('0x4e')]({},_0x50ffc8,_0x14b376[_0x0fab('0x50')]);return _0x59a27b['getTeams'](_0x50ffc8);}})[_0x0fab('0x20')](function(_0x4c5b20){if(_0x4c5b20){_0x895c8c=_0x4c5b20[_0x0fab('0x45')];if(!_0x14b376[_0x0fab('0x41')]['hasOwnProperty'](_0x0fab('0x47'))){_0x50ffc8['limit']=qs[_0x0fab('0x48')](_0x14b376[_0x0fab('0x41')]['limit']);_0x50ffc8[_0x0fab('0x2b')]=qs[_0x0fab('0x2b')](_0x14b376[_0x0fab('0x41')][_0x0fab('0x2b')]);}return _0x59a27b['getTeams'](_0x50ffc8);}})[_0x0fab('0x20')](function(_0x2e0f2d){if(_0x2e0f2d){return _0x2e0f2d?{'count':_0x895c8c,'rows':_0x2e0f2d}:null;}})[_0x0fab('0x20')](respondWithResult(_0xd8b4fd,null))[_0x0fab('0x27')](handleError(_0xd8b4fd,null));};exports[_0x0fab('0x70')]=function(_0x294933,_0x362329,_0x2cb825){var _0x1d77a8=_0x294933[_0x0fab('0x58')][_0x0fab('0x71')];return db[_0x0fab('0x72')]['findAll']({'where':{'id':_0x1d77a8},'attributes':['id'],'include':[{'model':db[_0x0fab('0x73')],'as':'Agents','attributes':['id',_0x0fab('0x37'),'online',_0x0fab('0x74'),_0x0fab('0x75')],'raw':!![]}]})[_0x0fab('0x20')](function(_0x2adaa2){if(_0x2adaa2){var _0x2be28e=_[_0x0fab('0x76')](_0x2adaa2,function(_0x3ad2f8){var _0x3e3261=_0x3ad2f8[_0x0fab('0x33')]({'plain':!![]});return _0x3e3261[_0x0fab('0x77')];});return db['ChatQueue'][_0x0fab('0x56')]({'where':{'id':_0x294933[_0x0fab('0x53')]['id']}})['then'](function(_0x3d05a2){return db['sequelize']['transaction'](function(_0x343245){return _0x3d05a2[_0x0fab('0x70')](_0x1d77a8,{'transaction':_0x343245})[_0x0fab('0x20')](function(){return BPromise[_0x0fab('0x78')](_0x2be28e,function(_0x26cac6){return db[_0x0fab('0x65')][_0x0fab('0x79')]({'where':{'UserId':_0x26cac6['id'],'ChatQueueId':_0x294933['params']['id']},'transaction':_0x343245});});})[_0x0fab('0x20')](function(){_0x2be28e[_0x0fab('0x7a')](function(_0x568c3b){socket[_0x0fab('0x7b')]('userChatQueue:save',{'UserId':_0x568c3b['id'],'ChatQueueId':_0x3d05a2['id']});});});});});}})[_0x0fab('0x20')](respondWithStatusCode(_0x362329,null))[_0x0fab('0x27')](handleError(_0x362329,null));};exports[_0x0fab('0x7c')]=function(_0x4e284f,_0x6873a6,_0x3f6477){return db[_0x0fab('0x72')][_0x0fab('0x7d')]({'where':{'id':_0x4e284f[_0x0fab('0x41')][_0x0fab('0x71')]},'attributes':['id'],'include':[{'model':db[_0x0fab('0x73')],'as':_0x0fab('0x77'),'attributes':['id'],'raw':!![]}]})[_0x0fab('0x20')](handleEntityNotFound(_0x6873a6,null))[_0x0fab('0x20')](function(_0x25c24d){var _0x99df78=_[_0x0fab('0x3f')](_0x25c24d,'id');var _0x3d22db=[];var _0x5314e2=[];var _0x2cccf4=squel[_0x0fab('0x7e')]();_0x2cccf4[_0x0fab('0x7f')](_0x0fab('0x80'))[_0x0fab('0x81')](_0x0fab('0x82'),'tq')['join']('user_has_teams','ut',_0x0fab('0x83'))[_0x0fab('0x4b')](_0x0fab('0x84'),_0x4e284f[_0x0fab('0x53')]['id']);for(var _0x3f56a1=0x0;_0x3f56a1<_0x25c24d[_0x0fab('0x45')];_0x3f56a1+=0x1){let _0x22ab40=_0x25c24d[_0x3f56a1];for(var _0x3d6a00=0x0;_0x3d6a00<_0x22ab40[_0x0fab('0x77')][_0x0fab('0x45')];_0x3d6a00+=0x1){let _0x370247=_0x22ab40[_0x0fab('0x77')][_0x3d6a00];var _0x360f1e=_0x2cccf4[_0x0fab('0x85')]();_0x360f1e[_0x0fab('0x4b')](_0x0fab('0x86'),_0x370247['id']);_0x5314e2[_0x0fab('0x87')](db[_0x0fab('0x88')][_0x0fab('0x41')](_0x360f1e[_0x0fab('0x89')](),{'type':db[_0x0fab('0x88')][_0x0fab('0x8a')][_0x0fab('0x8b')]})[_0x0fab('0x20')](function(_0x30f257){if(_0x30f257[_0x0fab('0x45')]===0x1){return _0x370247['id'];}else{var _0x14cfbe=_[_0x0fab('0x8c')](_['map'](_0x30f257,'TeamId'),function(_0x1be216){return _['includes'](_0x99df78,_0x1be216);});if(_0x14cfbe){return _0x370247['id'];}}}));}}return BPromise['all'](_0x5314e2)[_0x0fab('0x20')](function(_0x19cb82){_0x3d22db=_(_0x3d22db)[_0x0fab('0x8d')](_0x19cb82)['compact']()[_0x0fab('0x8e')]();return db['ChatQueue'][_0x0fab('0x56')]({'where':{'id':_0x4e284f[_0x0fab('0x53')]['id']}})['then'](function(_0x29d4d3){return db[_0x0fab('0x88')][_0x0fab('0x8f')](function(_0x3c3781){return _0x29d4d3['removeTeams'](_0x4e284f[_0x0fab('0x41')][_0x0fab('0x71')],{'transaction':_0x3c3781})[_0x0fab('0x20')](function(){if(!_[_0x0fab('0x90')](_0x3d22db)){return _0x29d4d3['removeAgents'](_0x3d22db,{'transaction':_0x3c3781});}})[_0x0fab('0x20')](function(){_0x3d22db[_0x0fab('0x7a')](function(_0x47639a){socket[_0x0fab('0x7b')](_0x0fab('0x91'),{'UserId':_0x47639a,'ChatQueueId':_0x29d4d3['id']});});});});});});})[_0x0fab('0x20')](respondWithStatusCode(_0x6873a6,null))[_0x0fab('0x27')](handleError(_0x6873a6,null));};exports['addAgents']=function(_0x200a4d,_0x25653f,_0x82dbd7){return db[_0x0fab('0x39')][_0x0fab('0x56')]({'where':{'id':_0x200a4d[_0x0fab('0x53')]['id']}})['then'](handleEntityNotFound(_0x25653f,null))['then'](function(_0x3c9ffc){if(_0x3c9ffc){return _0x3c9ffc['addAgents'](_0x200a4d[_0x0fab('0x58')]['ids'],_[_0x0fab('0x92')](_0x200a4d['body'],['ids','id'])||{})[_0x0fab('0x93')](function(_0x222bea){for(var _0x132dd3=0x0;_0x132dd3<_0x200a4d['body'][_0x0fab('0x71')]['length'];_0x132dd3+=0x1){socket[_0x0fab('0x7b')](_0x0fab('0x94'),{'UserId':Number(_0x200a4d[_0x0fab('0x58')][_0x0fab('0x71')][_0x132dd3]),'ChatQueueId':Number(_0x200a4d[_0x0fab('0x53')]['id'])});}return _0x222bea;});}})['then'](respondWithResult(_0x25653f,null))[_0x0fab('0x27')](handleError(_0x25653f,null));};exports['removeAgents']=function(_0xdc652a,_0x346e71,_0x231588){return db[_0x0fab('0x39')][_0x0fab('0x56')]({'where':{'id':_0xdc652a[_0x0fab('0x53')]['id']}})[_0x0fab('0x20')](handleEntityNotFound(_0x346e71,null))['then'](function(_0x558e20){if(_0x558e20){return _0x558e20['removeAgents'](_0xdc652a[_0x0fab('0x41')]['ids'])[_0x0fab('0x20')](function(){if(_[_0x0fab('0x95')](_0xdc652a[_0x0fab('0x41')][_0x0fab('0x71')])){for(var _0x69d5a8=0x0;_0x69d5a8<_0xdc652a[_0x0fab('0x41')]['ids']['length'];_0x69d5a8+=0x1){socket[_0x0fab('0x7b')]('userChatQueue:remove',{'UserId':Number(_0xdc652a[_0x0fab('0x41')][_0x0fab('0x71')][_0x69d5a8]),'ChatQueueId':Number(_0xdc652a[_0x0fab('0x53')]['id'])});}}else{socket['emit']('userChatQueue:remove',{'UserId':Number(_0xdc652a[_0x0fab('0x41')]['ids']),'ChatQueueId':Number(_0xdc652a[_0x0fab('0x53')]['id'])});}});}})[_0x0fab('0x20')](respondWithStatusCode(_0x346e71,null))[_0x0fab('0x27')](handleError(_0x346e71,null));};exports[_0x0fab('0x96')]=function(_0x432d49,_0x3a4026,_0x3218cd){var _0x3f9c88={};var _0x466275={};var _0x2305c4;var _0x533dc5;return db[_0x0fab('0x39')][_0x0fab('0x97')]({'where':{'id':_0x432d49[_0x0fab('0x53')]['id']}})['then'](handleEntityNotFound(_0x3a4026,null))['then'](function(_0x487b55){if(_0x487b55){_0x2305c4=_0x487b55;_0x466275[_0x0fab('0x3e')]=_[_0x0fab('0x40')](db[_0x0fab('0x73')][_0x0fab('0x3a')]);_0x466275[_0x0fab('0x41')]=_['keys'](_0x432d49[_0x0fab('0x41')]);_0x466275['filters']=_[_0x0fab('0x42')](_0x466275[_0x0fab('0x3e')],_0x466275[_0x0fab('0x41')]);_0x3f9c88['attributes']=_['intersection'](_0x466275[_0x0fab('0x3e')],qs[_0x0fab('0x44')](_0x432d49[_0x0fab('0x41')][_0x0fab('0x44')]));_0x3f9c88['attributes']=_0x3f9c88[_0x0fab('0x43')][_0x0fab('0x45')]?_0x3f9c88[_0x0fab('0x43')]:_0x466275[_0x0fab('0x3e')];_0x3f9c88['order']=qs[_0x0fab('0x4a')](_0x432d49[_0x0fab('0x41')][_0x0fab('0x4a')]);_0x3f9c88[_0x0fab('0x4b')]=qs[_0x0fab('0x4c')](_[_0x0fab('0x63')](_0x432d49['query'],_0x466275[_0x0fab('0x4c')]));if(_0x432d49[_0x0fab('0x41')][_0x0fab('0x4d')]){_0x3f9c88[_0x0fab('0x4b')]=_['merge'](_0x3f9c88[_0x0fab('0x4b')],{'$or':_[_0x0fab('0x3f')](_0x3f9c88[_0x0fab('0x43')],function(_0x1d0b31){var _0xf7b654={};_0xf7b654[_0x1d0b31]={'$like':'%'+_0x432d49[_0x0fab('0x41')][_0x0fab('0x4d')]+'%'};return _0xf7b654;})});}_0x3f9c88=_[_0x0fab('0x4e')]({},_0x3f9c88,_0x432d49['options']);return _0x2305c4['getAgents'](_0x3f9c88);}})[_0x0fab('0x20')](function(_0xcecac6){if(_0xcecac6){_0x533dc5=_0xcecac6[_0x0fab('0x45')];if(!_0x432d49[_0x0fab('0x41')][_0x0fab('0x46')]('nolimit')){_0x3f9c88['limit']=qs[_0x0fab('0x48')](_0x432d49[_0x0fab('0x41')]['limit']);_0x3f9c88[_0x0fab('0x2b')]=qs[_0x0fab('0x2b')](_0x432d49[_0x0fab('0x41')][_0x0fab('0x2b')]);}return _0x2305c4[_0x0fab('0x96')](_0x3f9c88);}})[_0x0fab('0x20')](function(_0x1c2978){if(_0x1c2978){return _0x1c2978?{'count':_0x533dc5,'rows':_0x1c2978}:null;}})['then'](respondWithResult(_0x3a4026,null))[_0x0fab('0x27')](handleError(_0x3a4026,null));};
\ No newline at end of file