Built motion from commit bab6f49e.|2.6.17
[motion2.git] / server / api / chatQueue / chatQueue.controller.js
index e0cf5aa..be576d5 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc48b=['type','key','model','query','keys','filters','intersection','attributes','length','nolimit','limit','order','sort','where','pick','merge','map','filter','options','includeAll','findAll','rows','show','fields','include','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','findOne','params','rawAttributes','hasOwnProperty','ChatQueueId','UserChatQueue','User','findAndCountAll','UserId','agent','chatPause','createdAt','%s/%s','SIP','updatedAt','getTeams','addTeams','ids','Team','Agents','online','voicePause','interface','flatMap','transaction','findOrCreate','forEach','userChatQueue:save','removeTeams','field','tq.TeamId','team_has_chat_queues','join','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','ut.UserId\x20=\x20?','sequelize','toString','SELECT','every','union','value','isEmpty','emit','userChatQueue:remove','addAgents','spread','removeAgents','getAgents','html-pdf','rimraf','request-promise','moment','bluebird','mustache','util','to-csv','ejs','crypto','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./chatQueue.socket','register','jayson/promise','client','http','then','info','ChatQueue,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','sendStatus','status','end','count','offset','Content-Range','apply','reject','save','get','ChatQueues','UserProfileResource','destroy','stack','name','ChatQueue'];(function(_0x303f5d,_0xc3aa18){var _0x54c6f7=function(_0x2e30d8){while(--_0x2e30d8){_0x303f5d['push'](_0x303f5d['shift']());}};_0x54c6f7(++_0xc3aa18);}(_0xc48b,0xe5));var _0xbc48=function(_0x71c2ac,_0x32eb1f){_0x71c2ac=_0x71c2ac-0x0;var _0x47582e=_0xc48b[_0x71c2ac];return _0x47582e;};'use strict';var pdf=require(_0xbc48('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xbc48('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xbc48('0x2'));var moment=require(_0xbc48('0x3'));var BPromise=require(_0xbc48('0x4'));var Mustache=require(_0xbc48('0x5'));var util=require(_0xbc48('0x6'));var path=require('path');var sox=require('sox');var csv=require(_0xbc48('0x7'));var ejs=require(_0xbc48('0x8'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xbc48('0x9'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0xbc48('0x7'));var querystring=require('querystring');var Papa=require(_0xbc48('0xa'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xbc48('0xb'));var as=require(_0xbc48('0xc'));var hardwareService=require(_0xbc48('0xd'));var logger=require(_0xbc48('0xe'))(_0xbc48('0xf'));var utils=require(_0xbc48('0x10'));var config=require(_0xbc48('0x11'));var licenseUtil=require(_0xbc48('0x12'));var db=require('../../mysqldb')['db'];config[_0xbc48('0x13')]=_[_0xbc48('0x14')](config[_0xbc48('0x13')],{'host':_0xbc48('0x15'),'port':0x18eb});var socket=require(_0xbc48('0x16'))(new Redis(config['redis']));require(_0xbc48('0x17'))[_0xbc48('0x18')](socket);var jayson=require(_0xbc48('0x19'));var client=jayson[_0xbc48('0x1a')][_0xbc48('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x5c9a0d,_0x84c706,_0x3090d5,_0x2e51c4){return new BPromise(function(_0x4179a7,_0x26e5ae){var _0x46b30c=_0x2e51c4||client;return _0x46b30c['request'](_0x5c9a0d,_0x3090d5)[_0xbc48('0x1c')](function(_0x1df845){logger[_0xbc48('0x1d')](_0xbc48('0x1e'),_0x84c706,_0xbc48('0x1f'));logger[_0xbc48('0x20')]('ChatQueue,\x20%s,\x20%s,\x20%s',_0x84c706,_0xbc48('0x1f'),JSON[_0xbc48('0x21')](_0x1df845));if(_0x1df845[_0xbc48('0x22')]){if(_0x1df845[_0xbc48('0x22')][_0xbc48('0x23')]===0x1f4){logger['error'](_0xbc48('0x1e'),_0x84c706,_0x1df845[_0xbc48('0x22')]['message']);return _0x26e5ae(_0x1df845[_0xbc48('0x22')][_0xbc48('0x24')]);}logger[_0xbc48('0x22')](_0xbc48('0x1e'),_0x84c706,_0x1df845[_0xbc48('0x22')][_0xbc48('0x24')]);return _0x4179a7(_0x1df845[_0xbc48('0x22')][_0xbc48('0x24')]);}else{logger[_0xbc48('0x1d')](_0xbc48('0x1e'),_0x84c706,_0xbc48('0x1f'));_0x4179a7(_0x1df845[_0xbc48('0x25')]['message']);}})[_0xbc48('0x26')](function(_0x3e7689){logger[_0xbc48('0x22')](_0xbc48('0x1e'),_0x84c706,_0x3e7689);_0x26e5ae(_0x3e7689);});});}function respondWithStatusCode(_0x2ccae0,_0x3680a5){_0x3680a5=_0x3680a5||0xcc;return function(_0x118484){if(_0x118484){return _0x2ccae0[_0xbc48('0x27')](_0x3680a5);}return _0x2ccae0[_0xbc48('0x28')](_0x3680a5)[_0xbc48('0x29')]();};}function respondWithResult(_0x2bc86a,_0x4ec9c9){_0x4ec9c9=_0x4ec9c9||0xc8;return function(_0x4d4345){if(_0x4d4345){return _0x2bc86a[_0xbc48('0x28')](_0x4ec9c9)['json'](_0x4d4345);}};}function respondWithFilteredResult(_0x2b054e,_0x2c17f5){return function(_0x268fc4){if(_0x268fc4){var _0x2b9313=_0x268fc4[_0xbc48('0x2a')],_0x208f3e=_0x2c17f5[_0xbc48('0x2b')],_0x434844=_0x2c17f5['offset']+_0x2c17f5['limit'],_0x53b8d9;if(_0x434844>=_0x2b9313){_0x434844=_0x2b9313;_0x53b8d9=0xc8;}else{_0x53b8d9=0xce;}_0x2b054e[_0xbc48('0x28')](_0x53b8d9);return _0x2b054e['set'](_0xbc48('0x2c'),_0x208f3e+'-'+_0x434844+'/'+_0x2b9313)['json'](_0x268fc4);}return null;};}function patchUpdates(_0x56aa15){return function(_0x50f3fd){try{jsonpatch[_0xbc48('0x2d')](_0x50f3fd,_0x56aa15,!![]);}catch(_0x435084){return BPromise[_0xbc48('0x2e')](_0x435084);}return _0x50f3fd[_0xbc48('0x2f')]();};}function saveUpdates(_0x4413d5,_0x4f771b){return function(_0x56560f){if(_0x56560f){return _0x56560f['update'](_0x4413d5)[_0xbc48('0x1c')](function(_0x438809){return _0x438809;});}return null;};}function removeEntity(_0x55fd84,_0x1a1383){return function(_0x1405cd){if(_0x1405cd){return _0x1405cd['destroy']()['then'](function(){var _0x1d7cfd=_0x1405cd[_0xbc48('0x30')]({'plain':!![]});var _0x3fdcc0=_0xbc48('0x31');return db[_0xbc48('0x32')][_0xbc48('0x33')]({'where':{'type':_0x3fdcc0,'resourceId':_0x1d7cfd['id']}})[_0xbc48('0x1c')](function(){return _0x1405cd;});})[_0xbc48('0x1c')](function(){_0x55fd84[_0xbc48('0x28')](0xcc)['end']();});}};}function handleEntityNotFound(_0x518721,_0x30417b){return function(_0x37a1f2){if(!_0x37a1f2){_0x518721['sendStatus'](0x194);}return _0x37a1f2;};}function handleError(_0x37461b,_0x1a7723){_0x1a7723=_0x1a7723||0x1f4;return function(_0x539132){logger[_0xbc48('0x22')](_0x539132[_0xbc48('0x34')]);if(_0x539132[_0xbc48('0x35')]){delete _0x539132['name'];}_0x37461b['status'](_0x1a7723)['send'](_0x539132);};}exports['index']=function(_0x5cc47d,_0x1659fc){var _0x58bc5c={},_0x5ceb94={},_0x5d763f={'count':0x0,'rows':[]};var _0x23c4b2=_['map'](db[_0xbc48('0x36')]['rawAttributes'],function(_0x1275f0){return{'name':_0x1275f0['fieldName'],'type':_0x1275f0[_0xbc48('0x37')][_0xbc48('0x38')]};});_0x5ceb94[_0xbc48('0x39')]=_['map'](_0x23c4b2,_0xbc48('0x35'));_0x5ceb94[_0xbc48('0x3a')]=_[_0xbc48('0x3b')](_0x5cc47d[_0xbc48('0x3a')]);_0x5ceb94[_0xbc48('0x3c')]=_[_0xbc48('0x3d')](_0x5ceb94[_0xbc48('0x39')],_0x5ceb94[_0xbc48('0x3a')]);_0x58bc5c[_0xbc48('0x3e')]=_[_0xbc48('0x3d')](_0x5ceb94[_0xbc48('0x39')],qs['fields'](_0x5cc47d['query']['fields']));_0x58bc5c[_0xbc48('0x3e')]=_0x58bc5c[_0xbc48('0x3e')][_0xbc48('0x3f')]?_0x58bc5c[_0xbc48('0x3e')]:_0x5ceb94['model'];if(!_0x5cc47d[_0xbc48('0x3a')]['hasOwnProperty'](_0xbc48('0x40'))){_0x58bc5c[_0xbc48('0x41')]=qs[_0xbc48('0x41')](_0x5cc47d[_0xbc48('0x3a')]['limit']);_0x58bc5c[_0xbc48('0x2b')]=qs[_0xbc48('0x2b')](_0x5cc47d[_0xbc48('0x3a')][_0xbc48('0x2b')]);}_0x58bc5c[_0xbc48('0x42')]=qs[_0xbc48('0x43')](_0x5cc47d[_0xbc48('0x3a')][_0xbc48('0x43')]);_0x58bc5c[_0xbc48('0x44')]=qs[_0xbc48('0x3c')](_[_0xbc48('0x45')](_0x5cc47d[_0xbc48('0x3a')],_0x5ceb94[_0xbc48('0x3c')]),_0x23c4b2);if(_0x5cc47d[_0xbc48('0x3a')]['filter']){_0x58bc5c['where']=_[_0xbc48('0x46')](_0x58bc5c[_0xbc48('0x44')],{'$or':_[_0xbc48('0x47')](_0x23c4b2,function(_0x1632ce){if(_0x1632ce[_0xbc48('0x37')]!=='VIRTUAL'){var _0x1ff2b2={};_0x1ff2b2[_0x1632ce['name']]={'$like':'%'+_0x5cc47d[_0xbc48('0x3a')][_0xbc48('0x48')]+'%'};return _0x1ff2b2;}})});}_0x58bc5c=_[_0xbc48('0x46')]({},_0x58bc5c,_0x5cc47d[_0xbc48('0x49')]);var _0x46ca0b={'where':_0x58bc5c[_0xbc48('0x44')]};return db[_0xbc48('0x36')][_0xbc48('0x2a')](_0x46ca0b)[_0xbc48('0x1c')](function(_0xdae9e1){_0x5d763f[_0xbc48('0x2a')]=_0xdae9e1;if(_0x5cc47d['query'][_0xbc48('0x4a')]){_0x58bc5c['include']=[{'all':!![]}];}return db['ChatQueue'][_0xbc48('0x4b')](_0x58bc5c);})[_0xbc48('0x1c')](function(_0x2cb789){_0x5d763f[_0xbc48('0x4c')]=_0x2cb789;return _0x5d763f;})['then'](respondWithFilteredResult(_0x1659fc,_0x58bc5c))[_0xbc48('0x26')](handleError(_0x1659fc,null));};exports[_0xbc48('0x4d')]=function(_0x8d5862,_0x1313bc){var _0x570500={'raw':!![],'where':{'id':_0x8d5862['params']['id']}},_0x45cbb2={};_0x45cbb2['model']=_['keys'](db[_0xbc48('0x36')]['rawAttributes']);_0x45cbb2['query']=_['keys'](_0x8d5862[_0xbc48('0x3a')]);_0x45cbb2[_0xbc48('0x3c')]=_[_0xbc48('0x3d')](_0x45cbb2[_0xbc48('0x39')],_0x45cbb2[_0xbc48('0x3a')]);_0x570500[_0xbc48('0x3e')]=_[_0xbc48('0x3d')](_0x45cbb2[_0xbc48('0x39')],qs[_0xbc48('0x4e')](_0x8d5862[_0xbc48('0x3a')]['fields']));_0x570500[_0xbc48('0x3e')]=_0x570500[_0xbc48('0x3e')]['length']?_0x570500[_0xbc48('0x3e')]:_0x45cbb2[_0xbc48('0x39')];if(_0x8d5862['query']['includeAll']){_0x570500[_0xbc48('0x4f')]=[{'all':!![]}];}_0x570500=_[_0xbc48('0x46')]({},_0x570500,_0x8d5862['options']);return db[_0xbc48('0x36')]['find'](_0x570500)[_0xbc48('0x1c')](handleEntityNotFound(_0x1313bc,null))[_0xbc48('0x1c')](respondWithResult(_0x1313bc,null))[_0xbc48('0x26')](handleError(_0x1313bc,null));};exports[_0xbc48('0x50')]=function(_0x31e7f4,_0x313080){return db[_0xbc48('0x36')][_0xbc48('0x50')](_0x31e7f4[_0xbc48('0x51')],{})[_0xbc48('0x1c')](function(_0x10f719){var _0x3d638e=_0x31e7f4[_0xbc48('0x52')][_0xbc48('0x30')]({'plain':!![]});if(!_0x3d638e)throw new Error(_0xbc48('0x53'));if(_0x3d638e[_0xbc48('0x54')]===_0xbc48('0x52')){var _0x1d9108=_0x10f719['get']({'plain':!![]});var _0x7302c=_0xbc48('0x31');return db[_0xbc48('0x55')][_0xbc48('0x56')]({'where':{'name':_0x7302c,'userProfileId':_0x3d638e[_0xbc48('0x57')]},'raw':!![]})[_0xbc48('0x1c')](function(_0x492eb3){if(_0x492eb3&&_0x492eb3[_0xbc48('0x58')]===0x0){return db['UserProfileResource'][_0xbc48('0x50')]({'name':_0x1d9108['name'],'resourceId':_0x1d9108['id'],'type':_0x492eb3[_0xbc48('0x35')],'sectionId':_0x492eb3['id']},{})[_0xbc48('0x1c')](function(){return _0x10f719;});}else{return _0x10f719;}})[_0xbc48('0x26')](function(_0xda0fb4){logger[_0xbc48('0x22')](_0xbc48('0x59'),_0xda0fb4);throw _0xda0fb4;});}return _0x10f719;})[_0xbc48('0x1c')](respondWithResult(_0x313080,0xc9))[_0xbc48('0x26')](handleError(_0x313080,null));};exports['update']=function(_0x5257e9,_0x4357fa){if(_0x5257e9[_0xbc48('0x51')]['id']){delete _0x5257e9[_0xbc48('0x51')]['id'];}return db[_0xbc48('0x36')][_0xbc48('0x56')]({'where':{'id':_0x5257e9['params']['id']}})['then'](handleEntityNotFound(_0x4357fa,null))[_0xbc48('0x1c')](saveUpdates(_0x5257e9[_0xbc48('0x51')],null))[_0xbc48('0x1c')](respondWithResult(_0x4357fa,null))[_0xbc48('0x26')](handleError(_0x4357fa,null));};exports[_0xbc48('0x33')]=function(_0x1e3064,_0x24672d){return db[_0xbc48('0x36')]['find']({'where':{'id':_0x1e3064['params']['id']}})[_0xbc48('0x1c')](handleEntityNotFound(_0x24672d,null))['then'](removeEntity(_0x24672d,null))[_0xbc48('0x26')](handleError(_0x24672d,null));};exports[_0xbc48('0x5a')]=function(_0x963f1d,_0x341720){return db['ChatQueue'][_0xbc48('0x5a')]()[_0xbc48('0x1c')](respondWithResult(_0x341720,null))[_0xbc48('0x26')](handleError(_0x341720,null));};exports[_0xbc48('0x5b')]=function(_0x4ac60e,_0x5ca808,_0x1439b9){var _0x372fa3={'raw':!![],'where':{}},_0x3c64ce={},_0x2a2129;return db[_0xbc48('0x36')][_0xbc48('0x5c')]({'where':{'id':_0x4ac60e[_0xbc48('0x5d')]['id']}})['then'](handleEntityNotFound(_0x5ca808,null))[_0xbc48('0x1c')](function(_0xc6c9cd){if(_0xc6c9cd){_0x2a2129=_0xc6c9cd[_0xbc48('0x30')]({'plain':!![]});_0x3c64ce[_0xbc48('0x39')]=_[_0xbc48('0x3b')](db['UserChatQueue'][_0xbc48('0x5e')]);_0x3c64ce[_0xbc48('0x3a')]=_[_0xbc48('0x3b')](_0x4ac60e[_0xbc48('0x3a')]);_0x3c64ce['filters']=_[_0xbc48('0x3d')](_0x3c64ce[_0xbc48('0x39')],_0x3c64ce[_0xbc48('0x3a')]);_0x372fa3[_0xbc48('0x3e')]=_[_0xbc48('0x3d')](_0x3c64ce['model'],qs[_0xbc48('0x4e')](_0x4ac60e[_0xbc48('0x3a')][_0xbc48('0x4e')]));_0x372fa3[_0xbc48('0x3e')]=_0x372fa3[_0xbc48('0x3e')]['length']?_0x372fa3[_0xbc48('0x3e')]:_0x3c64ce[_0xbc48('0x39')];if(!_0x4ac60e[_0xbc48('0x3a')][_0xbc48('0x5f')](_0xbc48('0x40'))){_0x372fa3[_0xbc48('0x41')]=qs['limit'](_0x4ac60e[_0xbc48('0x3a')][_0xbc48('0x41')]);_0x372fa3[_0xbc48('0x2b')]=qs[_0xbc48('0x2b')](_0x4ac60e['query'][_0xbc48('0x2b')]);}_0x372fa3[_0xbc48('0x42')]=qs[_0xbc48('0x43')](_0x4ac60e['query']['sort']);_0x372fa3['where']=qs[_0xbc48('0x3c')](_[_0xbc48('0x45')](_0x4ac60e[_0xbc48('0x3a')],_0x3c64ce['filters']));_0x372fa3['where'][_0xbc48('0x60')]=_0xc6c9cd['id'];if(_0x4ac60e[_0xbc48('0x3a')]['filter']){_0x372fa3[_0xbc48('0x44')]=_[_0xbc48('0x46')](_0x372fa3[_0xbc48('0x44')],{'$or':_['map'](_0x372fa3[_0xbc48('0x3e')],function(_0x6ea7f7){var _0x1dc5bc={};_0x1dc5bc[_0x6ea7f7]={'$like':'%'+_0x4ac60e['query'][_0xbc48('0x48')]+'%'};return _0x1dc5bc;})});}_0x372fa3=_[_0xbc48('0x46')]({},_0x372fa3,_0x4ac60e[_0xbc48('0x49')]);return db[_0xbc48('0x61')][_0xbc48('0x4b')](_0x372fa3);}})[_0xbc48('0x1c')](function(_0xadd9cf){if(_0xadd9cf){return db[_0xbc48('0x62')][_0xbc48('0x63')]({'where':{'id':_[_0xbc48('0x47')](_0xadd9cf,_0xbc48('0x64')),'role':_0xbc48('0x65')},'attributes':['id',_0xbc48('0x35'),_0xbc48('0x66'),'updatedAt',_0xbc48('0x67')]});}})[_0xbc48('0x1c')](function(_0xc6b913){if(_0xc6b913){return{'count':_0xc6b913[_0xbc48('0x2a')],'rows':_[_0xbc48('0x47')](_0xc6b913[_0xbc48('0x4c')],function(_0x12f008){return{'membername':_0x12f008[_0xbc48('0x35')],'UserId':_0x12f008['id'],'queue_name':_0x2a2129['name'],'ChatQueueId':_0x2a2129['id'],'interface':util['format'](_0xbc48('0x68'),_0xbc48('0x69'),_0x12f008['name']),'penalty':0x0,'paused':_0x12f008[_0xbc48('0x66')],'createdAt':_0x12f008[_0xbc48('0x67')],'updatedAt':_0x12f008[_0xbc48('0x6a')]};})};}else{return{'count':0x0,'rows':[]};}})[_0xbc48('0x1c')](respondWithFilteredResult(_0x5ca808,_0x372fa3))['catch'](handleError(_0x5ca808,null));};exports[_0xbc48('0x6b')]=function(_0x54b1bb,_0x1ecfaa,_0xa3d42c){var _0x3b994c={};var _0x15d2b3={};var _0x264cdb;var _0x253d41;return db[_0xbc48('0x36')][_0xbc48('0x5c')]({'where':{'id':_0x54b1bb['params']['id']}})['then'](handleEntityNotFound(_0x1ecfaa,null))[_0xbc48('0x1c')](function(_0x48f3b8){if(_0x48f3b8){_0x264cdb=_0x48f3b8;_0x15d2b3['model']=_[_0xbc48('0x3b')](db['Team'][_0xbc48('0x5e')]);_0x15d2b3[_0xbc48('0x3a')]=_['keys'](_0x54b1bb[_0xbc48('0x3a')]);_0x15d2b3[_0xbc48('0x3c')]=_['intersection'](_0x15d2b3[_0xbc48('0x39')],_0x15d2b3[_0xbc48('0x3a')]);_0x3b994c['attributes']=_[_0xbc48('0x3d')](_0x15d2b3[_0xbc48('0x39')],qs['fields'](_0x54b1bb[_0xbc48('0x3a')][_0xbc48('0x4e')]));_0x3b994c[_0xbc48('0x3e')]=_0x3b994c[_0xbc48('0x3e')][_0xbc48('0x3f')]?_0x3b994c['attributes']:_0x15d2b3[_0xbc48('0x39')];_0x3b994c[_0xbc48('0x42')]=qs[_0xbc48('0x43')](_0x54b1bb[_0xbc48('0x3a')][_0xbc48('0x43')]);_0x3b994c[_0xbc48('0x44')]=qs[_0xbc48('0x3c')](_[_0xbc48('0x45')](_0x54b1bb[_0xbc48('0x3a')],_0x15d2b3[_0xbc48('0x3c')]));if(_0x54b1bb['query'][_0xbc48('0x48')]){_0x3b994c[_0xbc48('0x44')]=_[_0xbc48('0x46')](_0x3b994c[_0xbc48('0x44')],{'$or':_[_0xbc48('0x47')](_0x3b994c[_0xbc48('0x3e')],function(_0x3455c4){var _0x28e202={};_0x28e202[_0x3455c4]={'$like':'%'+_0x54b1bb[_0xbc48('0x3a')][_0xbc48('0x48')]+'%'};return _0x28e202;})});}_0x3b994c=_['merge']({},_0x3b994c,_0x54b1bb[_0xbc48('0x49')]);return _0x264cdb[_0xbc48('0x6b')](_0x3b994c);}})[_0xbc48('0x1c')](function(_0x5736e){if(_0x5736e){_0x253d41=_0x5736e[_0xbc48('0x3f')];if(!_0x54b1bb[_0xbc48('0x3a')][_0xbc48('0x5f')](_0xbc48('0x40'))){_0x3b994c[_0xbc48('0x41')]=qs[_0xbc48('0x41')](_0x54b1bb['query'][_0xbc48('0x41')]);_0x3b994c['offset']=qs[_0xbc48('0x2b')](_0x54b1bb[_0xbc48('0x3a')]['offset']);}return _0x264cdb[_0xbc48('0x6b')](_0x3b994c);}})[_0xbc48('0x1c')](function(_0x6904e2){if(_0x6904e2){return _0x6904e2?{'count':_0x253d41,'rows':_0x6904e2}:null;}})['then'](respondWithResult(_0x1ecfaa,null))['catch'](handleError(_0x1ecfaa,null));};exports[_0xbc48('0x6c')]=function(_0x15c270,_0x2d487f,_0x179d64){var _0x39f6b3=_0x15c270[_0xbc48('0x51')][_0xbc48('0x6d')];return db[_0xbc48('0x6e')][_0xbc48('0x4b')]({'where':{'id':_0x39f6b3},'attributes':['id'],'include':[{'model':db[_0xbc48('0x62')],'as':_0xbc48('0x6f'),'attributes':['id',_0xbc48('0x35'),_0xbc48('0x70'),_0xbc48('0x71'),_0xbc48('0x72')],'raw':!![]}]})['then'](function(_0xd11c96){if(_0xd11c96){var _0x3fb442=_[_0xbc48('0x73')](_0xd11c96,function(_0x1f29c0){var _0x34a7e4=_0x1f29c0[_0xbc48('0x30')]({'plain':!![]});return _0x34a7e4[_0xbc48('0x6f')];});return db[_0xbc48('0x36')][_0xbc48('0x56')]({'where':{'id':_0x15c270['params']['id']}})[_0xbc48('0x1c')](function(_0x943685){return db['sequelize'][_0xbc48('0x74')](function(_0x428210){return _0x943685[_0xbc48('0x6c')](_0x39f6b3,{'transaction':_0x428210})[_0xbc48('0x1c')](function(){return BPromise['each'](_0x3fb442,function(_0x57bd45){return db[_0xbc48('0x61')][_0xbc48('0x75')]({'where':{'UserId':_0x57bd45['id'],'ChatQueueId':_0x15c270[_0xbc48('0x5d')]['id']},'transaction':_0x428210});});})[_0xbc48('0x1c')](function(){_0x3fb442[_0xbc48('0x76')](function(_0x5b0cc7){socket['emit'](_0xbc48('0x77'),{'UserId':_0x5b0cc7['id'],'ChatQueueId':_0x943685['id']});});});});});}})['then'](respondWithStatusCode(_0x2d487f,null))[_0xbc48('0x26')](handleError(_0x2d487f,null));};exports[_0xbc48('0x78')]=function(_0xe96e1,_0x3ff3f5,_0x5d6ccb){return db[_0xbc48('0x6e')][_0xbc48('0x4b')]({'where':{'id':_0xe96e1['query'][_0xbc48('0x6d')]},'attributes':['id'],'include':[{'model':db[_0xbc48('0x62')],'as':_0xbc48('0x6f'),'attributes':['id'],'raw':!![]}]})[_0xbc48('0x1c')](handleEntityNotFound(_0x3ff3f5,null))[_0xbc48('0x1c')](function(_0x43a2a3){var _0xcfaec2=_[_0xbc48('0x47')](_0x43a2a3,'id');var _0x47c757=[];var _0x103cd1=[];var _0x589856=squel['select']();_0x589856[_0xbc48('0x79')](_0xbc48('0x7a'))['from'](_0xbc48('0x7b'),'tq')[_0xbc48('0x7c')]('user_has_teams','ut',_0xbc48('0x7d'))[_0xbc48('0x44')](_0xbc48('0x7e'),_0xe96e1[_0xbc48('0x5d')]['id']);for(var _0xf3af6=0x0;_0xf3af6<_0x43a2a3[_0xbc48('0x3f')];_0xf3af6+=0x1){let _0x5798e5=_0x43a2a3[_0xf3af6];for(var _0x17b005=0x0;_0x17b005<_0x5798e5['Agents'][_0xbc48('0x3f')];_0x17b005+=0x1){let _0x52a14c=_0x5798e5['Agents'][_0x17b005];var _0x4c992c=_0x589856[_0xbc48('0x7f')]();_0x4c992c[_0xbc48('0x44')](_0xbc48('0x80'),_0x52a14c['id']);_0x103cd1['push'](db[_0xbc48('0x81')][_0xbc48('0x3a')](_0x4c992c[_0xbc48('0x82')](),{'type':db[_0xbc48('0x81')]['QueryTypes'][_0xbc48('0x83')]})[_0xbc48('0x1c')](function(_0x4bb1b0){if(_0x4bb1b0[_0xbc48('0x3f')]===0x1){return _0x52a14c['id'];}else{var _0x4d012f=_[_0xbc48('0x84')](_['map'](_0x4bb1b0,'TeamId'),function(_0x37845f){return _['includes'](_0xcfaec2,_0x37845f);});if(_0x4d012f){return _0x52a14c['id'];}}}));}}return BPromise['all'](_0x103cd1)[_0xbc48('0x1c')](function(_0x1ae457){_0x47c757=_(_0x47c757)[_0xbc48('0x85')](_0x1ae457)['compact']()[_0xbc48('0x86')]();return db['ChatQueue'][_0xbc48('0x56')]({'where':{'id':_0xe96e1[_0xbc48('0x5d')]['id']}})[_0xbc48('0x1c')](function(_0x819cbf){return db[_0xbc48('0x81')][_0xbc48('0x74')](function(_0x472419){return _0x819cbf['removeTeams'](_0xe96e1[_0xbc48('0x3a')][_0xbc48('0x6d')],{'transaction':_0x472419})[_0xbc48('0x1c')](function(){if(!_[_0xbc48('0x87')](_0x47c757)){return _0x819cbf['removeAgents'](_0x47c757,{'transaction':_0x472419});}})[_0xbc48('0x1c')](function(){_0x47c757['forEach'](function(_0xfbd987){socket[_0xbc48('0x88')](_0xbc48('0x89'),{'UserId':_0xfbd987,'ChatQueueId':_0x819cbf['id']});});});});});});})['then'](respondWithStatusCode(_0x3ff3f5,null))[_0xbc48('0x26')](handleError(_0x3ff3f5,null));};exports[_0xbc48('0x8a')]=function(_0x5eca00,_0x1adc60,_0x50dcbb){return db[_0xbc48('0x36')][_0xbc48('0x56')]({'where':{'id':_0x5eca00[_0xbc48('0x5d')]['id']}})[_0xbc48('0x1c')](handleEntityNotFound(_0x1adc60,null))['then'](function(_0x2e8d10){if(_0x2e8d10){return _0x2e8d10[_0xbc48('0x8a')](_0x5eca00[_0xbc48('0x51')][_0xbc48('0x6d')],_['omit'](_0x5eca00['body'],['ids','id'])||{})[_0xbc48('0x8b')](function(_0x400a55){for(var _0x37ab26=0x0;_0x37ab26<_0x5eca00[_0xbc48('0x51')][_0xbc48('0x6d')][_0xbc48('0x3f')];_0x37ab26+=0x1){socket[_0xbc48('0x88')](_0xbc48('0x77'),{'UserId':_0x5eca00[_0xbc48('0x51')][_0xbc48('0x6d')][_0x37ab26],'ChatQueueId':_0x5eca00[_0xbc48('0x5d')]['id']});}return _0x400a55;});}})[_0xbc48('0x1c')](respondWithResult(_0x1adc60,null))['catch'](handleError(_0x1adc60,null));};exports['removeAgents']=function(_0xf531a2,_0x3b5998,_0x2e5e41){return db[_0xbc48('0x36')][_0xbc48('0x56')]({'where':{'id':_0xf531a2['params']['id']}})[_0xbc48('0x1c')](handleEntityNotFound(_0x3b5998,null))['then'](function(_0x278bbc){if(_0x278bbc){return _0x278bbc[_0xbc48('0x8c')](_0xf531a2[_0xbc48('0x3a')][_0xbc48('0x6d')])[_0xbc48('0x1c')](function(){if(_['isArray'](_0xf531a2[_0xbc48('0x3a')]['ids'])){for(var _0x52d039=0x0;_0x52d039<_0xf531a2[_0xbc48('0x3a')][_0xbc48('0x6d')][_0xbc48('0x3f')];_0x52d039+=0x1){socket['emit'](_0xbc48('0x89'),{'UserId':Number(_0xf531a2[_0xbc48('0x3a')][_0xbc48('0x6d')][_0x52d039]),'ChatQueueId':Number(_0xf531a2['params']['id'])});}}else{socket['emit'](_0xbc48('0x89'),{'UserId':Number(_0xf531a2['query'][_0xbc48('0x6d')]),'ChatQueueId':Number(_0xf531a2[_0xbc48('0x5d')]['id'])});}});}})['then'](respondWithStatusCode(_0x3b5998,null))['catch'](handleError(_0x3b5998,null));};exports[_0xbc48('0x8d')]=function(_0xa2e459,_0x36bf7d,_0x40ed96){var _0x3da31a={};var _0x42f127={};var _0x30c077;var _0x648e90;return db['ChatQueue'][_0xbc48('0x5c')]({'where':{'id':_0xa2e459[_0xbc48('0x5d')]['id']}})[_0xbc48('0x1c')](handleEntityNotFound(_0x36bf7d,null))['then'](function(_0x39cd72){if(_0x39cd72){_0x30c077=_0x39cd72;_0x42f127[_0xbc48('0x39')]=_[_0xbc48('0x3b')](db['User'][_0xbc48('0x5e')]);_0x42f127[_0xbc48('0x3a')]=_['keys'](_0xa2e459[_0xbc48('0x3a')]);_0x42f127['filters']=_['intersection'](_0x42f127[_0xbc48('0x39')],_0x42f127[_0xbc48('0x3a')]);_0x3da31a[_0xbc48('0x3e')]=_[_0xbc48('0x3d')](_0x42f127[_0xbc48('0x39')],qs[_0xbc48('0x4e')](_0xa2e459[_0xbc48('0x3a')][_0xbc48('0x4e')]));_0x3da31a[_0xbc48('0x3e')]=_0x3da31a[_0xbc48('0x3e')][_0xbc48('0x3f')]?_0x3da31a['attributes']:_0x42f127[_0xbc48('0x39')];_0x3da31a[_0xbc48('0x42')]=qs[_0xbc48('0x43')](_0xa2e459[_0xbc48('0x3a')][_0xbc48('0x43')]);_0x3da31a[_0xbc48('0x44')]=qs['filters'](_[_0xbc48('0x45')](_0xa2e459[_0xbc48('0x3a')],_0x42f127[_0xbc48('0x3c')]));if(_0xa2e459['query'][_0xbc48('0x48')]){_0x3da31a[_0xbc48('0x44')]=_[_0xbc48('0x46')](_0x3da31a[_0xbc48('0x44')],{'$or':_[_0xbc48('0x47')](_0x3da31a[_0xbc48('0x3e')],function(_0x36289f){var _0x3cddd0={};_0x3cddd0[_0x36289f]={'$like':'%'+_0xa2e459[_0xbc48('0x3a')][_0xbc48('0x48')]+'%'};return _0x3cddd0;})});}_0x3da31a=_[_0xbc48('0x46')]({},_0x3da31a,_0xa2e459[_0xbc48('0x49')]);return _0x30c077[_0xbc48('0x8d')](_0x3da31a);}})[_0xbc48('0x1c')](function(_0x401e2d){if(_0x401e2d){_0x648e90=_0x401e2d[_0xbc48('0x3f')];if(!_0xa2e459[_0xbc48('0x3a')][_0xbc48('0x5f')]('nolimit')){_0x3da31a[_0xbc48('0x41')]=qs[_0xbc48('0x41')](_0xa2e459[_0xbc48('0x3a')][_0xbc48('0x41')]);_0x3da31a[_0xbc48('0x2b')]=qs[_0xbc48('0x2b')](_0xa2e459[_0xbc48('0x3a')][_0xbc48('0x2b')]);}return _0x30c077[_0xbc48('0x8d')](_0x3da31a);}})['then'](function(_0x3d611b){if(_0x3d611b){return _0x3d611b?{'count':_0x648e90,'rows':_0x3d611b}:null;}})[_0xbc48('0x1c')](respondWithResult(_0x36bf7d,null))[_0xbc48('0x26')](handleError(_0x36bf7d,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