Built motion from commit (unavailable).|2.5.10
[motion2.git] / server / api / chatQueue / chatQueue.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _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));};