Built motion from commit 3a7e82ea.|2.6.29
[motion2.git] / server / api / realtime / realtime.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 _0x9dd3=['getAgents','query','globalQueueFilter','globalStatusFilter','pauseTypeFilter','pause','*pause','resolve','then','channel','Channel\x20parameter\x20%s\x20is\x20invalid','toLowerCase','sort','globalStatus','validateSortParameter','getUpdatedSortOptions','fields','join','order','getAgentIdsByQueues','getRealtimeAgents','rows','getSortedAgentsIdsByStatus','getAgentIdsByStatus','length','User','rawAttributes','type','key','role','getOptions','raw','sequelize','FIELD(id,','forEach','push','Pause','where','merge','user','userProfileId','Agents','online','assign','omit','UserProfile','map','find','getAgentStatus','includes','voiceStatus','talking','Status','sortAgentsByStatus','getRealtimeAgentsQueryFields','pick','catch','getQueues','isValidChannel','format','startCase','Queue','fieldName','name','voice','outbound','dialActive','dialMethod','QueueCampaigns','Queues','filter','getResources','getRealtimeQueues','initializeQueues','lodash','util','../../components/realtime/agents','../../components/realtime/queues','../../config/utils','../../errors/api','APIBadRequestError','undefined','count','offset','limit','Content-Range'];(function(_0x139d70,_0x179bca){var _0x1144ff=function(_0x2f4dd2){while(--_0x2f4dd2){_0x139d70['push'](_0x139d70['shift']());}};_0x1144ff(++_0x179bca);}(_0x9dd3,0x1a2));var _0x39dd=function(_0x51332e,_0x4fe7ff){_0x51332e=_0x51332e-0x0;var _0x3fd27a=_0x9dd3[_0x51332e];return _0x3fd27a;};'use strict';var _=require(_0x39dd('0x0'));var util=require(_0x39dd('0x1'));var rta=require(_0x39dd('0x2'));var rtq=require(_0x39dd('0x3'));var qs=require('../../components/parsers/qs');var utils=require(_0x39dd('0x4'));var db=require('../../mysqldb')['db'];var APIBadRequestError=require(_0x39dd('0x5'))[_0x39dd('0x6')];var APIHandleError=require(_0x39dd('0x5'))['handleError'];function respondWithFilteredResult(_0x4da1eb,_0x47cb91){return function(_0xfd7a21){if(_0xfd7a21){var _0x347e4b=typeof _0x47cb91['offset']===_0x39dd('0x7')&&typeof _0x47cb91['limit']===_0x39dd('0x7');var _0x74c92=_0xfd7a21[_0x39dd('0x8')];var _0x14b5d0=_0x347e4b?0x0:_0x47cb91[_0x39dd('0x9')];var _0x5d1b9e=_0x347e4b?_0xfd7a21[_0x39dd('0x8')]:_0x47cb91['offset']+_0x47cb91[_0x39dd('0xa')];var _0x171b15;if(_0x5d1b9e>=_0x74c92){_0x5d1b9e=_0x74c92;_0x171b15=0xc8;}else{_0x171b15=0xce;}_0x4da1eb['status'](_0x171b15);return _0x4da1eb['set'](_0x39dd('0xb'),_0x14b5d0+'-'+_0x5d1b9e+'/'+_0x74c92)['json'](_0xfd7a21);}return null;};}exports[_0x39dd('0xc')]=function(_0x916da4,_0x1ae946){var _0x522116={'count':0x0,'rows':[]};var _0x28b023={};var _0x123da2;var _0x408c8e=utils['getChannels']();var _0x3bfc0c;var _0x4b56e1;var _0x4a935e=_0x916da4[_0x39dd('0xd')][_0x39dd('0xe')];var _0x297ac6=_0x916da4[_0x39dd('0xd')][_0x39dd('0xf')];var _0x555b17=_0x916da4[_0x39dd('0xd')][_0x39dd('0x10')];var _0x19edb7=_0x297ac6===_0x39dd('0x11')||_0x297ac6===_0x39dd('0x12')?!![]:![];var _0x564fdb=[];var _0x1edbdf;var _0x3361fd;Promise[_0x39dd('0x13')]()[_0x39dd('0x14')](function(){if(_0x916da4[_0x39dd('0xd')][_0x39dd('0x15')]){if(!utils['isValidChannel'](_0x916da4[_0x39dd('0xd')][_0x39dd('0x15')])){throw new APIBadRequestError(util['format'](_0x39dd('0x16'),_0x916da4[_0x39dd('0xd')][_0x39dd('0x15')]));}_0x123da2=_0x916da4[_0x39dd('0xd')][_0x39dd('0x15')][_0x39dd('0x17')]();}if(!_0x916da4[_0x39dd('0xd')][_0x39dd('0x18')]||!_0x916da4[_0x39dd('0xd')][_0x39dd('0x18')]['includes'](_0x39dd('0x19'))){_0x916da4[_0x39dd('0xd')][_0x39dd('0x18')]=rta[_0x39dd('0x1a')](_0x916da4[_0x39dd('0xd')][_0x39dd('0x18')]);return;}var _0x196102=rta[_0x39dd('0x1b')](_0x916da4[_0x39dd('0xd')][_0x39dd('0x18')]);_0x916da4[_0x39dd('0xd')][_0x39dd('0x18')]=_0x196102[_0x39dd('0x1c')][_0x39dd('0x1d')](',');_0x1edbdf=_0x196102[_0x39dd('0x1e')];})[_0x39dd('0x14')](function(){if(!_0x4a935e){return[];}return rta[_0x39dd('0x1f')](_0x4a935e,_0x123da2);})[_0x39dd('0x14')](function(_0x8b3979){_0x564fdb=_0x8b3979;return rta[_0x39dd('0x20')]();})[_0x39dd('0x14')](function(_0x7d40b3){_0x4b56e1=_0x7d40b3[_0x39dd('0x21')];if((!_0x297ac6||_0x19edb7)&&!_0x1edbdf){return _0x564fdb;}if(_0x1edbdf&&!_0x297ac6){return rta[_0x39dd('0x22')](_0x4b56e1,_0x564fdb,_0x1edbdf);}else{return rta[_0x39dd('0x23')](_0x4b56e1,_0x564fdb,_0x297ac6);}})[_0x39dd('0x14')](function(_0x3ab967){_0x564fdb=_0x3ab967;var _0x5569a4=![];if(_0x564fdb[_0x39dd('0x24')]===0x0){if(_0x4a935e||_0x297ac6){_0x5569a4=!![];}if(_0x19edb7){_0x5569a4=![];}}if(_0x5569a4){return _0x522116;}var _0x1b57b9=_['map'](db[_0x39dd('0x25')][_0x39dd('0x26')],function(_0x45c569){return{'name':_0x45c569['fieldName'],'type':_0x45c569[_0x39dd('0x27')][_0x39dd('0x28')]};});_0x916da4[_0x39dd('0xd')][_0x39dd('0x29')]='agent';_0x28b023=qs[_0x39dd('0x2a')](_0x1b57b9,_0x916da4);_0x28b023[_0x39dd('0x2b')]=!![];var _0x4a4138=[];if(_0x564fdb[_0x39dd('0x24')]>0x0){_0x4a4138['push']({'id':{'$in':_0x564fdb}});if(_0x1edbdf&&!_0x297ac6){_0x3361fd=[db[_0x39dd('0x2c')]['literal'](_0x39dd('0x2d')+_0x564fdb+')')];_0x28b023[_0x39dd('0x1e')]=_0x3361fd;}}if(_0x19edb7){_0x408c8e[_0x39dd('0x2e')](function(_0x5e194a){var _0xe8d267=!![];if(_0x297ac6===_0x39dd('0x12')&&_0x123da2!==_0x5e194a){_0xe8d267=![];}_0x4a4138[_0x39dd('0x2f')]({[_0x5e194a+_0x39dd('0x30')]:_0xe8d267});});if(_0x555b17){_0x4a4138['push']({'pauseType':_0x555b17});}}else if(_0x297ac6){_0x408c8e[_0x39dd('0x2e')](function(_0x2734b0){_0x4a4138['push']({[_0x2734b0+_0x39dd('0x30')]:![]});});}_0x28b023[_0x39dd('0x31')]=_[_0x39dd('0x32')](_0x28b023['where'],{'$and':_0x4a4138});if(_0x916da4[_0x39dd('0x33')][_0x39dd('0x29')]===_0x39dd('0x33')){var _0x395bb5={'params':{'id':_0x916da4[_0x39dd('0x33')][_0x39dd('0x34')]},'query':{'section':_0x39dd('0x35'),'role':'agent','raw':!![],'ids':_0x564fdb,'customSorting':_0x3361fd}};if(_0x916da4['query'][_0x39dd('0x36')]){_0x395bb5[_0x39dd('0xd')][_0x39dd('0x36')]=!![];}if(_0x19edb7){_0x395bb5[_0x39dd('0xd')]['extraQueryConditions']=_0x4a4138;}_0x395bb5[_0x39dd('0xd')]=Object[_0x39dd('0x37')](_0x395bb5[_0x39dd('0xd')],_[_0x39dd('0x38')](_0x916da4[_0x39dd('0xd')],'id'));return db[_0x39dd('0x39')]['getResources'](_0x395bb5);}return db['User']['findAndCountAll'](_0x28b023);})['then'](function(_0x52ae1a){_0x522116[_0x39dd('0x8')]=_0x52ae1a[_0x39dd('0x8')];_0x3bfc0c=_0x52ae1a['rows'];return _0x3bfc0c[_0x39dd('0x3a')](function(_0x6f5451){var _0xaf7cc7=_[_0x39dd('0x3b')](_0x4b56e1,['id',_0x6f5451['id']]);if(_0xaf7cc7){var _0x5d85dc=rta['filterAgentAttributes'](_0xaf7cc7);_[_0x39dd('0x32')](_0x6f5451,_0x5d85dc);}_0x6f5451[_0x39dd('0x19')]=rta[_0x39dd('0x3c')](_0x6f5451);if(_0x6f5451[_0x39dd('0x19')][_0x39dd('0x3d')](_0x39dd('0x11'))){_0x408c8e[_0x39dd('0x2e')](function(_0x4b5ec7){if(_0x6f5451[_0x4b5ec7+_0x39dd('0x30')]){if(_0x4b5ec7==='voice'){if(_0x6f5451[_0x39dd('0x3e')]!==_0x39dd('0x3f')){_0x6f5451[_0x39dd('0x3e')]=_0x39dd('0x11');}}else{_0x6f5451[_0x4b5ec7+_0x39dd('0x40')]=_0x39dd('0x11');}}});}return _0x6f5451;});})[_0x39dd('0x14')](function(_0x1f5e3e){if(!_0x1edbdf||_0x3361fd){return _0x1f5e3e;}return rta[_0x39dd('0x41')](_0x1f5e3e,_0x1edbdf);})[_0x39dd('0x14')](function(_0x3ec4bb){var _0x31ff6b=rta[_0x39dd('0x42')]();_0x522116[_0x39dd('0x21')]=_0x3ec4bb[_0x39dd('0x3a')](function(_0x199155){return _[_0x39dd('0x43')](_0x199155,_0x31ff6b);});return _0x522116;})[_0x39dd('0x14')](respondWithFilteredResult(_0x1ae946,_0x28b023))[_0x39dd('0x44')](APIHandleError(_0x1ae946));};exports[_0x39dd('0x45')]=function(_0x3a9424,_0xa86d87){var _0x383ed4={'count':0x0,'rows':[]};var _0x16fece={};var _0x112779;var _0x4c50a4;var _0x499bce;Promise[_0x39dd('0x13')]()[_0x39dd('0x14')](function(){if(_0x3a9424[_0x39dd('0xd')][_0x39dd('0x15')]){if(!utils[_0x39dd('0x46')](_0x3a9424[_0x39dd('0xd')][_0x39dd('0x15')])){throw new APIBadRequestError(util[_0x39dd('0x47')](_0x39dd('0x16'),_0x3a9424[_0x39dd('0xd')][_0x39dd('0x15')]));}_0x112779=_0x3a9424[_0x39dd('0xd')][_0x39dd('0x15')][_0x39dd('0x17')]();}var _0x3a13fd=_[_0x39dd('0x48')](_0x112779)+_0x39dd('0x49');var _0x5eec10=_[_0x39dd('0x3a')](db[_0x3a13fd]['rawAttributes'],function(_0x1ee42c){return{'name':_0x1ee42c[_0x39dd('0x4a')],'type':_0x1ee42c[_0x39dd('0x27')]['key']};});if(!_0x3a9424[_0x39dd('0xd')]['fields']){var _0x2e252d=['id',_0x39dd('0x4b')];if(_0x112779===_0x39dd('0x4c')){_0x2e252d[_0x39dd('0x2f')]('type');if(_0x3a9424[_0x39dd('0xd')][_0x39dd('0x27')]===_0x39dd('0x4d')){_0x2e252d[_0x39dd('0x2f')]([_0x39dd('0x4e'),_0x39dd('0x4f')]);}}_0x3a9424[_0x39dd('0xd')]['fields']=_0x2e252d[_0x39dd('0x1d')](',');}_0x16fece=qs[_0x39dd('0x2a')](_0x5eec10,_0x3a9424);if(_0x3a9424[_0x39dd('0x33')]['role']===_0x39dd('0x33')){var _0x2b7574={'params':{'id':_0x3a9424[_0x39dd('0x33')][_0x39dd('0x34')]},'query':{'section':_0x112779===_0x39dd('0x4c')&&_0x3a9424[_0x39dd('0xd')]['type']===_0x39dd('0x4d')?_0x39dd('0x50'):_[_0x39dd('0x48')](_0x112779)+_0x39dd('0x51'),'type':_0x3a9424['query'][_0x39dd('0x27')],'nolimit':!![],'sort':_0x39dd('0x4b'),'filter':_0x3a9424['query'][_0x39dd('0x52')]}};_0x2b7574[_0x39dd('0xd')]=Object[_0x39dd('0x37')](_0x2b7574['query'],_0x3a9424['query']);delete _0x2b7574[_0x39dd('0xd')]['id'];return db[_0x39dd('0x39')][_0x39dd('0x53')](_0x2b7574);}return db[_0x3a13fd]['findAndCountAll'](_0x16fece);})['then'](function(_0x39f9a5){_0x383ed4[_0x39dd('0x8')]=_0x39f9a5[_0x39dd('0x8')];_0x4c50a4=_0x39f9a5['rows'];return rtq[_0x39dd('0x54')](_0x3a9424,_0x112779);})[_0x39dd('0x14')](function(_0x46224b){_0x499bce=_0x46224b[_0x39dd('0x21')];return rtq[_0x39dd('0x55')](_0x4c50a4,_0x499bce,_0x112779,_0x3a9424[_0x39dd('0xd')][_0x39dd('0x27')]);})['then'](function(_0x5001b1){_0x383ed4[_0x39dd('0x21')]=_0x5001b1;return _0x383ed4;})[_0x39dd('0x14')](respondWithFilteredResult(_0xa86d87,_0x16fece))[_0x39dd('0x44')](APIHandleError(_0xa86d87));};