Built motion from commit (unavailable).|2.5.29
[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 _0x318f=['model','map','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','order','sort','where','pick','filter','options','include','findAll','params','includeAll','find','create','body','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','ChatQueues','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','getMembers','UserChatQueue','rawAttributes','nolimit','ChatQueueId','merge','User','findAndCountAll','UserId','chatPause','updatedAt','rows','format','%s/%s','SIP','createdAt','getTeams','Team','addTeams','Agents','voicePause','flatMap','sequelize','transaction','emit','removeTeams','ids','select','field','tq.TeamId','from','team_has_chat_queues','join','user_has_teams','ut.TeamId\x20=\x20tq.TeamId','ChatQueueId\x20=\x20?','clone','push','toString','QueryTypes','SELECT','every','TeamId','includes','all','union','compact','value','removeAgents','forEach','userChatQueue:remove','addAgents','spread','userChatQueue:save','isArray','findOne','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./chatQueue.socket','jayson/promise','client','request','then','ChatQueue,\x20%s,\x20%s','request\x20sent','debug','ChatQueue,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','sendStatus','end','status','json','offset','limit','undefined','count','set','Content-Range','reject','update','destroy','UserProfileResource','name','send','ChatQueue','type','key'];(function(_0x31cb5f,_0x2df766){var _0x586042=function(_0x53c807){while(--_0x53c807){_0x31cb5f['push'](_0x31cb5f['shift']());}};_0x586042(++_0x2df766);}(_0x318f,0x191));var _0xf318=function(_0x48908f,_0x3d091d){_0x48908f=_0x48908f-0x0;var _0x4f90f7=_0x318f[_0x48908f];return _0x4f90f7;};'use strict';var emlformat=require(_0xf318('0x0'));var rimraf=require(_0xf318('0x1'));var zipdir=require(_0xf318('0x2'));var jsonpatch=require(_0xf318('0x3'));var rp=require('request-promise');var moment=require(_0xf318('0x4'));var BPromise=require(_0xf318('0x5'));var Mustache=require(_0xf318('0x6'));var util=require('util');var path=require(_0xf318('0x7'));var sox=require(_0xf318('0x8'));var csv=require(_0xf318('0x9'));var ejs=require(_0xf318('0xa'));var fs=require('fs');var fs_extra=require(_0xf318('0xb'));var _=require(_0xf318('0xc'));var squel=require(_0xf318('0xd'));var crypto=require(_0xf318('0xe'));var jsforce=require('jsforce');var deskjs=require(_0xf318('0xf'));var toCsv=require(_0xf318('0x9'));var querystring=require('querystring');var Papa=require(_0xf318('0x10'));var Redis=require(_0xf318('0x11'));var authService=require(_0xf318('0x12'));var qs=require(_0xf318('0x13'));var as=require(_0xf318('0x14'));var hardwareService=require(_0xf318('0x15'));var logger=require(_0xf318('0x16'))(_0xf318('0x17'));var utils=require(_0xf318('0x18'));var config=require(_0xf318('0x19'));var licenseUtil=require(_0xf318('0x1a'));var db=require(_0xf318('0x1b'))['db'];config[_0xf318('0x1c')]=_[_0xf318('0x1d')](config[_0xf318('0x1c')],{'host':_0xf318('0x1e'),'port':0x18eb});var socket=require(_0xf318('0x1f'))(new Redis(config[_0xf318('0x1c')]));require(_0xf318('0x20'))['register'](socket);var jayson=require(_0xf318('0x21'));var client=jayson[_0xf318('0x22')]['http']({'port':0x232a});function respondWithRpcPromise(_0x3f4554,_0x27182e,_0x43f2d2,_0x30757b){return new BPromise(function(_0x7590a4,_0x26e98f){var _0x9f53e5=_0x30757b||client;return _0x9f53e5[_0xf318('0x23')](_0x3f4554,_0x43f2d2)[_0xf318('0x24')](function(_0x141ec9){logger['info'](_0xf318('0x25'),_0x27182e,_0xf318('0x26'));logger[_0xf318('0x27')](_0xf318('0x28'),_0x27182e,_0xf318('0x26'),JSON[_0xf318('0x29')](_0x141ec9));if(_0x141ec9['error']){if(_0x141ec9[_0xf318('0x2a')][_0xf318('0x2b')]===0x1f4){logger['error']('ChatQueue,\x20%s,\x20%s',_0x27182e,_0x141ec9[_0xf318('0x2a')][_0xf318('0x2c')]);return _0x26e98f(_0x141ec9[_0xf318('0x2a')][_0xf318('0x2c')]);}logger[_0xf318('0x2a')](_0xf318('0x25'),_0x27182e,_0x141ec9['error'][_0xf318('0x2c')]);return _0x7590a4(_0x141ec9['error'][_0xf318('0x2c')]);}else{logger[_0xf318('0x2d')](_0xf318('0x25'),_0x27182e,_0xf318('0x26'));_0x7590a4(_0x141ec9[_0xf318('0x2e')][_0xf318('0x2c')]);}})[_0xf318('0x2f')](function(_0x2649d8){logger[_0xf318('0x2a')](_0xf318('0x25'),_0x27182e,_0x2649d8);_0x26e98f(_0x2649d8);});});}function respondWithStatusCode(_0x39dfb8,_0xdd99a3){_0xdd99a3=_0xdd99a3||0xcc;return function(_0x482bb9){if(_0x482bb9){return _0x39dfb8[_0xf318('0x30')](_0xdd99a3);}return _0x39dfb8['status'](_0xdd99a3)[_0xf318('0x31')]();};}function respondWithResult(_0x42aaee,_0x26cead){_0x26cead=_0x26cead||0xc8;return function(_0x5f3465){if(_0x5f3465){return _0x42aaee[_0xf318('0x32')](_0x26cead)[_0xf318('0x33')](_0x5f3465);}};}function respondWithFilteredResult(_0x513af2,_0x3c190b){return function(_0x297467){if(_0x297467){var _0x207c65=typeof _0x3c190b[_0xf318('0x34')]==='undefined'&&typeof _0x3c190b[_0xf318('0x35')]===_0xf318('0x36');var _0x578a2e=_0x297467[_0xf318('0x37')];var _0x889baa=_0x207c65?0x0:_0x3c190b[_0xf318('0x34')];var _0x28e912=_0x207c65?_0x297467[_0xf318('0x37')]:_0x3c190b['offset']+_0x3c190b['limit'];var _0x37cd88;if(_0x28e912>=_0x578a2e){_0x28e912=_0x578a2e;_0x37cd88=0xc8;}else{_0x37cd88=0xce;}_0x513af2[_0xf318('0x32')](_0x37cd88);return _0x513af2[_0xf318('0x38')](_0xf318('0x39'),_0x889baa+'-'+_0x28e912+'/'+_0x578a2e)['json'](_0x297467);}return null;};}function patchUpdates(_0x37d65a){return function(_0x16d063){try{jsonpatch['apply'](_0x16d063,_0x37d65a,!![]);}catch(_0x425a66){return BPromise[_0xf318('0x3a')](_0x425a66);}return _0x16d063['save']();};}function saveUpdates(_0x430b5e,_0x32f843){return function(_0x218771){if(_0x218771){return _0x218771[_0xf318('0x3b')](_0x430b5e)['then'](function(_0x415de8){return _0x415de8;});}return null;};}function removeEntity(_0x27c3e8,_0x2f2fc3){return function(_0x216f71){if(_0x216f71){return _0x216f71[_0xf318('0x3c')]()['then'](function(){var _0x3a2090=_0x216f71['get']({'plain':!![]});var _0xd0f654='ChatQueues';return db[_0xf318('0x3d')]['destroy']({'where':{'type':_0xd0f654,'resourceId':_0x3a2090['id']}})[_0xf318('0x24')](function(){return _0x216f71;});})[_0xf318('0x24')](function(){_0x27c3e8[_0xf318('0x32')](0xcc)[_0xf318('0x31')]();});}};}function handleEntityNotFound(_0x1cec26,_0x3b951c){return function(_0x5d9d35){if(!_0x5d9d35){_0x1cec26[_0xf318('0x30')](0x194);}return _0x5d9d35;};}function handleError(_0x21dec4,_0x56d9ce){_0x56d9ce=_0x56d9ce||0x1f4;return function(_0x26dd81){logger['error'](_0x26dd81['stack']);if(_0x26dd81[_0xf318('0x3e')]){delete _0x26dd81['name'];}_0x21dec4['status'](_0x56d9ce)[_0xf318('0x3f')](_0x26dd81);};}exports['index']=function(_0x316557,_0x27cdb6){var _0x394bef={},_0x5e93bc={},_0x41d3e9={'count':0x0,'rows':[]};var _0x21031d=_['map'](db[_0xf318('0x40')]['rawAttributes'],function(_0x43f2e0){return{'name':_0x43f2e0['fieldName'],'type':_0x43f2e0[_0xf318('0x41')][_0xf318('0x42')]};});_0x5e93bc[_0xf318('0x43')]=_[_0xf318('0x44')](_0x21031d,_0xf318('0x3e'));_0x5e93bc['query']=_[_0xf318('0x45')](_0x316557[_0xf318('0x46')]);_0x5e93bc[_0xf318('0x47')]=_[_0xf318('0x48')](_0x5e93bc['model'],_0x5e93bc[_0xf318('0x46')]);_0x394bef['attributes']=_[_0xf318('0x48')](_0x5e93bc[_0xf318('0x43')],qs[_0xf318('0x49')](_0x316557[_0xf318('0x46')][_0xf318('0x49')]));_0x394bef['attributes']=_0x394bef[_0xf318('0x4a')][_0xf318('0x4b')]?_0x394bef[_0xf318('0x4a')]:_0x5e93bc[_0xf318('0x43')];if(!_0x316557[_0xf318('0x46')][_0xf318('0x4c')]('nolimit')){_0x394bef[_0xf318('0x35')]=qs['limit'](_0x316557[_0xf318('0x46')][_0xf318('0x35')]);_0x394bef[_0xf318('0x34')]=qs[_0xf318('0x34')](_0x316557[_0xf318('0x46')][_0xf318('0x34')]);}_0x394bef[_0xf318('0x4d')]=qs[_0xf318('0x4e')](_0x316557[_0xf318('0x46')][_0xf318('0x4e')]);_0x394bef[_0xf318('0x4f')]=qs[_0xf318('0x47')](_[_0xf318('0x50')](_0x316557[_0xf318('0x46')],_0x5e93bc[_0xf318('0x47')]),_0x21031d);if(_0x316557[_0xf318('0x46')][_0xf318('0x51')]){_0x394bef[_0xf318('0x4f')]=_['merge'](_0x394bef[_0xf318('0x4f')],{'$or':_[_0xf318('0x44')](_0x21031d,function(_0x375afa){if(_0x375afa[_0xf318('0x41')]!=='VIRTUAL'){var _0x29028d={};_0x29028d[_0x375afa['name']]={'$like':'%'+_0x316557[_0xf318('0x46')][_0xf318('0x51')]+'%'};return _0x29028d;}})});}_0x394bef=_['merge']({},_0x394bef,_0x316557[_0xf318('0x52')]);var _0x1c0ebe={'where':_0x394bef[_0xf318('0x4f')]};return db[_0xf318('0x40')]['count'](_0x1c0ebe)[_0xf318('0x24')](function(_0x11311a){_0x41d3e9['count']=_0x11311a;if(_0x316557[_0xf318('0x46')]['includeAll']){_0x394bef[_0xf318('0x53')]=[{'all':!![]}];}return db[_0xf318('0x40')][_0xf318('0x54')](_0x394bef);})[_0xf318('0x24')](function(_0x34abc3){_0x41d3e9['rows']=_0x34abc3;return _0x41d3e9;})[_0xf318('0x24')](respondWithFilteredResult(_0x27cdb6,_0x394bef))[_0xf318('0x2f')](handleError(_0x27cdb6,null));};exports['show']=function(_0xdfa9f6,_0x30a31c){var _0x537d9e={'raw':!![],'where':{'id':_0xdfa9f6[_0xf318('0x55')]['id']}},_0x446aa9={};_0x446aa9[_0xf318('0x43')]=_[_0xf318('0x45')](db[_0xf318('0x40')]['rawAttributes']);_0x446aa9[_0xf318('0x46')]=_[_0xf318('0x45')](_0xdfa9f6['query']);_0x446aa9[_0xf318('0x47')]=_['intersection'](_0x446aa9[_0xf318('0x43')],_0x446aa9[_0xf318('0x46')]);_0x537d9e[_0xf318('0x4a')]=_['intersection'](_0x446aa9[_0xf318('0x43')],qs['fields'](_0xdfa9f6[_0xf318('0x46')][_0xf318('0x49')]));_0x537d9e[_0xf318('0x4a')]=_0x537d9e['attributes'][_0xf318('0x4b')]?_0x537d9e[_0xf318('0x4a')]:_0x446aa9[_0xf318('0x43')];if(_0xdfa9f6[_0xf318('0x46')][_0xf318('0x56')]){_0x537d9e[_0xf318('0x53')]=[{'all':!![]}];}_0x537d9e=_['merge']({},_0x537d9e,_0xdfa9f6['options']);return db[_0xf318('0x40')][_0xf318('0x57')](_0x537d9e)[_0xf318('0x24')](handleEntityNotFound(_0x30a31c,null))[_0xf318('0x24')](respondWithResult(_0x30a31c,null))[_0xf318('0x2f')](handleError(_0x30a31c,null));};exports[_0xf318('0x58')]=function(_0x5582f5,_0x4f7fc1){return db[_0xf318('0x40')]['create'](_0x5582f5[_0xf318('0x59')],{})['then'](function(_0x11fa45){var _0x238421=_0x5582f5['user'][_0xf318('0x5a')]({'plain':!![]});if(!_0x238421)throw new Error(_0xf318('0x5b'));if(_0x238421[_0xf318('0x5c')]==='user'){var _0x425a2f=_0x11fa45[_0xf318('0x5a')]({'plain':!![]});var _0x45ebd4=_0xf318('0x5d');return db[_0xf318('0x5e')][_0xf318('0x57')]({'where':{'name':_0x45ebd4,'userProfileId':_0x238421[_0xf318('0x5f')]},'raw':!![]})[_0xf318('0x24')](function(_0x156f6e){if(_0x156f6e&&_0x156f6e[_0xf318('0x60')]===0x0){return db[_0xf318('0x3d')][_0xf318('0x58')]({'name':_0x425a2f[_0xf318('0x3e')],'resourceId':_0x425a2f['id'],'type':_0x156f6e[_0xf318('0x3e')],'sectionId':_0x156f6e['id']},{})[_0xf318('0x24')](function(){return _0x11fa45;});}else{return _0x11fa45;}})['catch'](function(_0x2a5a07){logger['error'](_0xf318('0x61'),_0x2a5a07);throw _0x2a5a07;});}return _0x11fa45;})[_0xf318('0x24')](respondWithResult(_0x4f7fc1,0xc9))[_0xf318('0x2f')](handleError(_0x4f7fc1,null));};exports[_0xf318('0x3b')]=function(_0x4500ca,_0x1b8493){if(_0x4500ca[_0xf318('0x59')]['id']){delete _0x4500ca[_0xf318('0x59')]['id'];}return db[_0xf318('0x40')][_0xf318('0x57')]({'where':{'id':_0x4500ca[_0xf318('0x55')]['id']}})[_0xf318('0x24')](handleEntityNotFound(_0x1b8493,null))[_0xf318('0x24')](saveUpdates(_0x4500ca[_0xf318('0x59')],null))[_0xf318('0x24')](respondWithResult(_0x1b8493,null))[_0xf318('0x2f')](handleError(_0x1b8493,null));};exports['destroy']=function(_0xe2ab02,_0x1d518a){return db[_0xf318('0x40')][_0xf318('0x57')]({'where':{'id':_0xe2ab02['params']['id']}})[_0xf318('0x24')](handleEntityNotFound(_0x1d518a,null))[_0xf318('0x24')](removeEntity(_0x1d518a,null))['catch'](handleError(_0x1d518a,null));};exports[_0xf318('0x62')]=function(_0x180bca,_0x51b9ad){return db[_0xf318('0x40')][_0xf318('0x62')]()[_0xf318('0x24')](respondWithResult(_0x51b9ad,null))[_0xf318('0x2f')](handleError(_0x51b9ad,null));};exports[_0xf318('0x63')]=function(_0x11b75e,_0x2ba8a7,_0x173498){var _0x347925={'raw':!![],'where':{}},_0x4c62cc={},_0x4dcd37;return db[_0xf318('0x40')]['findOne']({'where':{'id':_0x11b75e[_0xf318('0x55')]['id']}})[_0xf318('0x24')](handleEntityNotFound(_0x2ba8a7,null))['then'](function(_0xc7fc28){if(_0xc7fc28){_0x4dcd37=_0xc7fc28['get']({'plain':!![]});_0x4c62cc[_0xf318('0x43')]=_[_0xf318('0x45')](db[_0xf318('0x64')][_0xf318('0x65')]);_0x4c62cc[_0xf318('0x46')]=_[_0xf318('0x45')](_0x11b75e[_0xf318('0x46')]);_0x4c62cc[_0xf318('0x47')]=_['intersection'](_0x4c62cc[_0xf318('0x43')],_0x4c62cc['query']);_0x347925[_0xf318('0x4a')]=_[_0xf318('0x48')](_0x4c62cc[_0xf318('0x43')],qs[_0xf318('0x49')](_0x11b75e[_0xf318('0x46')][_0xf318('0x49')]));_0x347925[_0xf318('0x4a')]=_0x347925[_0xf318('0x4a')][_0xf318('0x4b')]?_0x347925[_0xf318('0x4a')]:_0x4c62cc[_0xf318('0x43')];if(!_0x11b75e[_0xf318('0x46')]['hasOwnProperty'](_0xf318('0x66'))){_0x347925[_0xf318('0x35')]=qs['limit'](_0x11b75e[_0xf318('0x46')][_0xf318('0x35')]);_0x347925[_0xf318('0x34')]=qs[_0xf318('0x34')](_0x11b75e[_0xf318('0x46')]['offset']);}_0x347925[_0xf318('0x4d')]=qs[_0xf318('0x4e')](_0x11b75e[_0xf318('0x46')][_0xf318('0x4e')]);_0x347925[_0xf318('0x4f')]=qs['filters'](_[_0xf318('0x50')](_0x11b75e[_0xf318('0x46')],_0x4c62cc[_0xf318('0x47')]));_0x347925['where'][_0xf318('0x67')]=_0xc7fc28['id'];if(_0x11b75e[_0xf318('0x46')]['filter']){_0x347925[_0xf318('0x4f')]=_[_0xf318('0x68')](_0x347925[_0xf318('0x4f')],{'$or':_[_0xf318('0x44')](_0x347925[_0xf318('0x4a')],function(_0x25aa9d){var _0x38be15={};_0x38be15[_0x25aa9d]={'$like':'%'+_0x11b75e[_0xf318('0x46')][_0xf318('0x51')]+'%'};return _0x38be15;})});}_0x347925=_[_0xf318('0x68')]({},_0x347925,_0x11b75e[_0xf318('0x52')]);return db[_0xf318('0x64')][_0xf318('0x54')](_0x347925);}})[_0xf318('0x24')](function(_0x22723b){if(_0x22723b){return db[_0xf318('0x69')][_0xf318('0x6a')]({'where':{'id':_[_0xf318('0x44')](_0x22723b,_0xf318('0x6b')),'role':'agent'},'attributes':['id',_0xf318('0x3e'),_0xf318('0x6c'),_0xf318('0x6d'),'createdAt']});}})['then'](function(_0x1ce4cc){if(_0x1ce4cc){return{'count':_0x1ce4cc[_0xf318('0x37')],'rows':_[_0xf318('0x44')](_0x1ce4cc[_0xf318('0x6e')],function(_0xb62589){return{'membername':_0xb62589[_0xf318('0x3e')],'UserId':_0xb62589['id'],'queue_name':_0x4dcd37[_0xf318('0x3e')],'ChatQueueId':_0x4dcd37['id'],'interface':util[_0xf318('0x6f')](_0xf318('0x70'),_0xf318('0x71'),_0xb62589['name']),'penalty':0x0,'paused':_0xb62589[_0xf318('0x6c')],'createdAt':_0xb62589[_0xf318('0x72')],'updatedAt':_0xb62589['updatedAt']};})};}else{return{'count':0x0,'rows':[]};}})[_0xf318('0x24')](respondWithFilteredResult(_0x2ba8a7,_0x347925))[_0xf318('0x2f')](handleError(_0x2ba8a7,null));};exports[_0xf318('0x73')]=function(_0x1c161f,_0x2852f7,_0x28ad8c){var _0x21e12e={};var _0x429210={};var _0x57fef5;var _0xd905cb;return db[_0xf318('0x40')]['findOne']({'where':{'id':_0x1c161f[_0xf318('0x55')]['id']}})[_0xf318('0x24')](handleEntityNotFound(_0x2852f7,null))['then'](function(_0x561793){if(_0x561793){_0x57fef5=_0x561793;_0x429210[_0xf318('0x43')]=_[_0xf318('0x45')](db[_0xf318('0x74')][_0xf318('0x65')]);_0x429210['query']=_[_0xf318('0x45')](_0x1c161f[_0xf318('0x46')]);_0x429210[_0xf318('0x47')]=_['intersection'](_0x429210[_0xf318('0x43')],_0x429210[_0xf318('0x46')]);_0x21e12e[_0xf318('0x4a')]=_[_0xf318('0x48')](_0x429210[_0xf318('0x43')],qs['fields'](_0x1c161f[_0xf318('0x46')][_0xf318('0x49')]));_0x21e12e['attributes']=_0x21e12e[_0xf318('0x4a')][_0xf318('0x4b')]?_0x21e12e[_0xf318('0x4a')]:_0x429210[_0xf318('0x43')];_0x21e12e[_0xf318('0x4d')]=qs['sort'](_0x1c161f[_0xf318('0x46')][_0xf318('0x4e')]);_0x21e12e[_0xf318('0x4f')]=qs['filters'](_[_0xf318('0x50')](_0x1c161f[_0xf318('0x46')],_0x429210[_0xf318('0x47')]));if(_0x1c161f[_0xf318('0x46')]['filter']){_0x21e12e['where']=_[_0xf318('0x68')](_0x21e12e[_0xf318('0x4f')],{'$or':_[_0xf318('0x44')](_0x21e12e[_0xf318('0x4a')],function(_0x4e1d1b){var _0x269daa={};_0x269daa[_0x4e1d1b]={'$like':'%'+_0x1c161f['query'][_0xf318('0x51')]+'%'};return _0x269daa;})});}_0x21e12e=_[_0xf318('0x68')]({},_0x21e12e,_0x1c161f[_0xf318('0x52')]);return _0x57fef5[_0xf318('0x73')](_0x21e12e);}})[_0xf318('0x24')](function(_0x3dd4ec){if(_0x3dd4ec){_0xd905cb=_0x3dd4ec[_0xf318('0x4b')];if(!_0x1c161f['query'][_0xf318('0x4c')](_0xf318('0x66'))){_0x21e12e['limit']=qs[_0xf318('0x35')](_0x1c161f['query']['limit']);_0x21e12e['offset']=qs[_0xf318('0x34')](_0x1c161f[_0xf318('0x46')][_0xf318('0x34')]);}return _0x57fef5[_0xf318('0x73')](_0x21e12e);}})[_0xf318('0x24')](function(_0x550350){if(_0x550350){return _0x550350?{'count':_0xd905cb,'rows':_0x550350}:null;}})[_0xf318('0x24')](respondWithResult(_0x2852f7,null))['catch'](handleError(_0x2852f7,null));};exports[_0xf318('0x75')]=function(_0x2ec2c2,_0x1fdba4,_0xcc065b){var _0x1fbc03=_0x2ec2c2[_0xf318('0x59')]['ids'];return db[_0xf318('0x74')][_0xf318('0x54')]({'where':{'id':_0x1fbc03},'attributes':['id'],'include':[{'model':db['User'],'as':_0xf318('0x76'),'attributes':['id',_0xf318('0x3e'),'online',_0xf318('0x77'),'interface'],'raw':!![]}]})[_0xf318('0x24')](function(_0x2287c8){if(_0x2287c8){var _0x15ad5a=_[_0xf318('0x78')](_0x2287c8,function(_0x14098f){var _0x1cc7dd=_0x14098f[_0xf318('0x5a')]({'plain':!![]});return _0x1cc7dd[_0xf318('0x76')];});return db[_0xf318('0x40')][_0xf318('0x57')]({'where':{'id':_0x2ec2c2[_0xf318('0x55')]['id']}})[_0xf318('0x24')](function(_0x309a52){return db[_0xf318('0x79')][_0xf318('0x7a')](function(_0xfc6367){return _0x309a52[_0xf318('0x75')](_0x1fbc03,{'transaction':_0xfc6367})[_0xf318('0x24')](function(){return BPromise['each'](_0x15ad5a,function(_0x1da840){return db[_0xf318('0x64')]['findOrCreate']({'where':{'UserId':_0x1da840['id'],'ChatQueueId':_0x2ec2c2[_0xf318('0x55')]['id']},'transaction':_0xfc6367});});})[_0xf318('0x24')](function(){_0x15ad5a['forEach'](function(_0x562b48){socket[_0xf318('0x7b')]('userChatQueue:save',{'UserId':_0x562b48['id'],'ChatQueueId':_0x309a52['id']});});});});});}})[_0xf318('0x24')](respondWithStatusCode(_0x1fdba4,null))['catch'](handleError(_0x1fdba4,null));};exports[_0xf318('0x7c')]=function(_0xef60ae,_0x42ab7c,_0x3cccb6){return db[_0xf318('0x74')][_0xf318('0x54')]({'where':{'id':_0xef60ae[_0xf318('0x46')][_0xf318('0x7d')]},'attributes':['id'],'include':[{'model':db[_0xf318('0x69')],'as':'Agents','attributes':['id'],'raw':!![]}]})[_0xf318('0x24')](handleEntityNotFound(_0x42ab7c,null))[_0xf318('0x24')](function(_0x4e03e2){var _0x4e4a44=_['map'](_0x4e03e2,'id');var _0x70c0fa=[];var _0x49027e=[];var _0x5c31dd=squel[_0xf318('0x7e')]();_0x5c31dd[_0xf318('0x7f')](_0xf318('0x80'))[_0xf318('0x81')](_0xf318('0x82'),'tq')[_0xf318('0x83')](_0xf318('0x84'),'ut',_0xf318('0x85'))[_0xf318('0x4f')](_0xf318('0x86'),_0xef60ae[_0xf318('0x55')]['id']);for(var _0x40eedc=0x0;_0x40eedc<_0x4e03e2[_0xf318('0x4b')];_0x40eedc+=0x1){let _0x72d822=_0x4e03e2[_0x40eedc];for(var _0x2531a0=0x0;_0x2531a0<_0x72d822[_0xf318('0x76')][_0xf318('0x4b')];_0x2531a0+=0x1){let _0x2f94c0=_0x72d822['Agents'][_0x2531a0];var _0x4e6531=_0x5c31dd[_0xf318('0x87')]();_0x4e6531[_0xf318('0x4f')]('ut.UserId\x20=\x20?',_0x2f94c0['id']);_0x49027e[_0xf318('0x88')](db[_0xf318('0x79')][_0xf318('0x46')](_0x4e6531[_0xf318('0x89')](),{'type':db[_0xf318('0x79')][_0xf318('0x8a')][_0xf318('0x8b')]})['then'](function(_0x7e5652){if(_0x7e5652[_0xf318('0x4b')]===0x1){return _0x2f94c0['id'];}else{var _0x15480a=_[_0xf318('0x8c')](_[_0xf318('0x44')](_0x7e5652,_0xf318('0x8d')),function(_0x32ab0f){return _[_0xf318('0x8e')](_0x4e4a44,_0x32ab0f);});if(_0x15480a){return _0x2f94c0['id'];}}}));}}return BPromise[_0xf318('0x8f')](_0x49027e)[_0xf318('0x24')](function(_0x582167){_0x70c0fa=_(_0x70c0fa)[_0xf318('0x90')](_0x582167)[_0xf318('0x91')]()[_0xf318('0x92')]();return db[_0xf318('0x40')]['find']({'where':{'id':_0xef60ae['params']['id']}})[_0xf318('0x24')](function(_0x5b7c90){return db[_0xf318('0x79')][_0xf318('0x7a')](function(_0x27a390){return _0x5b7c90[_0xf318('0x7c')](_0xef60ae[_0xf318('0x46')][_0xf318('0x7d')],{'transaction':_0x27a390})[_0xf318('0x24')](function(){if(!_['isEmpty'](_0x70c0fa)){return _0x5b7c90[_0xf318('0x93')](_0x70c0fa,{'transaction':_0x27a390});}})['then'](function(){_0x70c0fa[_0xf318('0x94')](function(_0x118cce){socket[_0xf318('0x7b')](_0xf318('0x95'),{'UserId':_0x118cce,'ChatQueueId':_0x5b7c90['id']});});});});});});})['then'](respondWithStatusCode(_0x42ab7c,null))['catch'](handleError(_0x42ab7c,null));};exports[_0xf318('0x96')]=function(_0x5ea601,_0x4e9ea8,_0x11b294){return db[_0xf318('0x40')]['find']({'where':{'id':_0x5ea601[_0xf318('0x55')]['id']}})['then'](handleEntityNotFound(_0x4e9ea8,null))[_0xf318('0x24')](function(_0x4b2117){if(_0x4b2117){return _0x4b2117['addAgents'](_0x5ea601[_0xf318('0x59')][_0xf318('0x7d')],_['omit'](_0x5ea601[_0xf318('0x59')],[_0xf318('0x7d'),'id'])||{})[_0xf318('0x97')](function(_0x526b2e){for(var _0x3b997d=0x0;_0x3b997d<_0x5ea601[_0xf318('0x59')][_0xf318('0x7d')][_0xf318('0x4b')];_0x3b997d+=0x1){socket[_0xf318('0x7b')](_0xf318('0x98'),{'UserId':_0x5ea601['body'][_0xf318('0x7d')][_0x3b997d],'ChatQueueId':_0x5ea601[_0xf318('0x55')]['id']});}return _0x526b2e;});}})['then'](respondWithResult(_0x4e9ea8,null))[_0xf318('0x2f')](handleError(_0x4e9ea8,null));};exports[_0xf318('0x93')]=function(_0x330607,_0x3a26e4,_0x3e8606){return db[_0xf318('0x40')][_0xf318('0x57')]({'where':{'id':_0x330607[_0xf318('0x55')]['id']}})[_0xf318('0x24')](handleEntityNotFound(_0x3a26e4,null))[_0xf318('0x24')](function(_0x115fd9){if(_0x115fd9){return _0x115fd9[_0xf318('0x93')](_0x330607[_0xf318('0x46')]['ids'])[_0xf318('0x24')](function(){if(_[_0xf318('0x99')](_0x330607[_0xf318('0x46')][_0xf318('0x7d')])){for(var _0x238f61=0x0;_0x238f61<_0x330607['query'][_0xf318('0x7d')][_0xf318('0x4b')];_0x238f61+=0x1){socket[_0xf318('0x7b')](_0xf318('0x95'),{'UserId':Number(_0x330607[_0xf318('0x46')][_0xf318('0x7d')][_0x238f61]),'ChatQueueId':Number(_0x330607[_0xf318('0x55')]['id'])});}}else{socket[_0xf318('0x7b')](_0xf318('0x95'),{'UserId':Number(_0x330607[_0xf318('0x46')][_0xf318('0x7d')]),'ChatQueueId':Number(_0x330607[_0xf318('0x55')]['id'])});}});}})[_0xf318('0x24')](respondWithStatusCode(_0x3a26e4,null))[_0xf318('0x2f')](handleError(_0x3a26e4,null));};exports['getAgents']=function(_0x522503,_0x5708ac,_0x209125){var _0x133ba0={};var _0x48a5ad={};var _0x27be66;var _0x4ba910;return db[_0xf318('0x40')][_0xf318('0x9a')]({'where':{'id':_0x522503[_0xf318('0x55')]['id']}})[_0xf318('0x24')](handleEntityNotFound(_0x5708ac,null))[_0xf318('0x24')](function(_0x12cae4){if(_0x12cae4){_0x27be66=_0x12cae4;_0x48a5ad[_0xf318('0x43')]=_['keys'](db[_0xf318('0x69')][_0xf318('0x65')]);_0x48a5ad[_0xf318('0x46')]=_[_0xf318('0x45')](_0x522503[_0xf318('0x46')]);_0x48a5ad['filters']=_[_0xf318('0x48')](_0x48a5ad['model'],_0x48a5ad[_0xf318('0x46')]);_0x133ba0[_0xf318('0x4a')]=_[_0xf318('0x48')](_0x48a5ad['model'],qs['fields'](_0x522503[_0xf318('0x46')][_0xf318('0x49')]));_0x133ba0[_0xf318('0x4a')]=_0x133ba0[_0xf318('0x4a')][_0xf318('0x4b')]?_0x133ba0[_0xf318('0x4a')]:_0x48a5ad[_0xf318('0x43')];_0x133ba0['order']=qs[_0xf318('0x4e')](_0x522503['query'][_0xf318('0x4e')]);_0x133ba0['where']=qs[_0xf318('0x47')](_[_0xf318('0x50')](_0x522503['query'],_0x48a5ad['filters']));if(_0x522503[_0xf318('0x46')][_0xf318('0x51')]){_0x133ba0[_0xf318('0x4f')]=_[_0xf318('0x68')](_0x133ba0[_0xf318('0x4f')],{'$or':_[_0xf318('0x44')](_0x133ba0['attributes'],function(_0x3db5da){var _0xc35c5e={};_0xc35c5e[_0x3db5da]={'$like':'%'+_0x522503[_0xf318('0x46')]['filter']+'%'};return _0xc35c5e;})});}_0x133ba0=_['merge']({},_0x133ba0,_0x522503['options']);return _0x27be66[_0xf318('0x9b')](_0x133ba0);}})[_0xf318('0x24')](function(_0x2a5b9d){if(_0x2a5b9d){_0x4ba910=_0x2a5b9d['length'];if(!_0x522503['query'][_0xf318('0x4c')](_0xf318('0x66'))){_0x133ba0[_0xf318('0x35')]=qs[_0xf318('0x35')](_0x522503[_0xf318('0x46')][_0xf318('0x35')]);_0x133ba0[_0xf318('0x34')]=qs[_0xf318('0x34')](_0x522503[_0xf318('0x46')][_0xf318('0x34')]);}return _0x27be66[_0xf318('0x9b')](_0x133ba0);}})[_0xf318('0x24')](function(_0x36812b){if(_0x36812b){return _0x36812b?{'count':_0x4ba910,'rows':_0x36812b}:null;}})[_0xf318('0x24')](respondWithResult(_0x5708ac,null))['catch'](handleError(_0x5708ac,null));};