Built motion from commit 97153652.|2.6.26
[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 _0xb27f=['pick','catch','getQueues','startCase','name','voice','outbound','dialActive','dialMethod','fields','QueueCampaigns','filter','UserProfile','getRealtimeQueues','../../components/realtime/agents','../../components/realtime/queues','../../components/parsers/qs','../../config/utils','../../mysqldb','../../errors/api','APIBadRequestError','handleError','offset','limit','undefined','count','status','set','Content-Range','json','getAgents','getChannels','query','globalQueueFilter','globalStatusFilter','pause','resolve','then','channel','isValidChannel','format','Channel\x20parameter\x20%s\x20is\x20invalid','toLowerCase','sort','globalStatus','validateSortParameter','getUpdatedSortOptions','join','order','getAgentIdsByQueues','getRealtimeAgents','getSortedAgentsIdsByStatus','length','map','User','rawAttributes','fieldName','type','key','role','getOptions','raw','push','sequelize','literal','FIELD(id,','forEach','*pause','Pause','where','merge','user','userProfileId','Agents','agent','online','extraQueryConditions','assign','getResources','findAndCountAll','rows','find','filterAgentAttributes','talking','voiceStatus','Status','sortAgentsByStatus','getRealtimeAgentsQueryFields'];(function(_0x37f02e,_0x24e12d){var _0x546b92=function(_0x410325){while(--_0x410325){_0x37f02e['push'](_0x37f02e['shift']());}};_0x546b92(++_0x24e12d);}(_0xb27f,0x116));var _0xfb27=function(_0x62a5e3,_0x4c3238){_0x62a5e3=_0x62a5e3-0x0;var _0x383e85=_0xb27f[_0x62a5e3];return _0x383e85;};'use strict';var _=require('lodash');var util=require('util');var rta=require(_0xfb27('0x0'));var rtq=require(_0xfb27('0x1'));var qs=require(_0xfb27('0x2'));var utils=require(_0xfb27('0x3'));var db=require(_0xfb27('0x4'))['db'];var APIBadRequestError=require(_0xfb27('0x5'))[_0xfb27('0x6')];var APIHandleError=require(_0xfb27('0x5'))[_0xfb27('0x7')];function respondWithFilteredResult(_0x44fe00,_0x279223){return function(_0x5c4653){if(_0x5c4653){var _0x259c11=typeof _0x279223[_0xfb27('0x8')]==='undefined'&&typeof _0x279223[_0xfb27('0x9')]===_0xfb27('0xa');var _0x32fc99=_0x5c4653[_0xfb27('0xb')];var _0x5de7b5=_0x259c11?0x0:_0x279223[_0xfb27('0x8')];var _0x4842b1=_0x259c11?_0x5c4653[_0xfb27('0xb')]:_0x279223[_0xfb27('0x8')]+_0x279223['limit'];var _0x16f2c6;if(_0x4842b1>=_0x32fc99){_0x4842b1=_0x32fc99;_0x16f2c6=0xc8;}else{_0x16f2c6=0xce;}_0x44fe00[_0xfb27('0xc')](_0x16f2c6);return _0x44fe00[_0xfb27('0xd')](_0xfb27('0xe'),_0x5de7b5+'-'+_0x4842b1+'/'+_0x32fc99)[_0xfb27('0xf')](_0x5c4653);}return null;};}exports[_0xfb27('0x10')]=function(_0x2de11c,_0xd3d0da){var _0x345f2f={'count':0x0,'rows':[]};var _0x1b5cf8={};var _0xa0e47c;var _0x4c7f2d=utils[_0xfb27('0x11')]();var _0x37a7aa;var _0x42f7e6;var _0x2d0aa7=_0x2de11c[_0xfb27('0x12')][_0xfb27('0x13')];var _0x49bfd2=_0x2de11c[_0xfb27('0x12')][_0xfb27('0x14')];var _0x4f27d5=_0x2de11c[_0xfb27('0x12')]['pauseTypeFilter'];var _0x483a53=_0x49bfd2===_0xfb27('0x15')||_0x49bfd2==='*pause'?!![]:![];var _0xb7b8ff=[];var _0x3002de;var _0x2a6ec0;Promise[_0xfb27('0x16')]()[_0xfb27('0x17')](function(){if(_0x2de11c[_0xfb27('0x12')][_0xfb27('0x18')]){if(!utils[_0xfb27('0x19')](_0x2de11c[_0xfb27('0x12')]['channel'])){throw new APIBadRequestError(util[_0xfb27('0x1a')](_0xfb27('0x1b'),_0x2de11c[_0xfb27('0x12')][_0xfb27('0x18')]));}_0xa0e47c=_0x2de11c[_0xfb27('0x12')][_0xfb27('0x18')][_0xfb27('0x1c')]();}if(!_0x2de11c['query'][_0xfb27('0x1d')]||!_0x2de11c[_0xfb27('0x12')][_0xfb27('0x1d')]['includes'](_0xfb27('0x1e'))){_0x2de11c[_0xfb27('0x12')]['sort']=rta[_0xfb27('0x1f')](_0x2de11c[_0xfb27('0x12')][_0xfb27('0x1d')]);return;}var _0x1bd6ff=rta[_0xfb27('0x20')](_0x2de11c[_0xfb27('0x12')][_0xfb27('0x1d')]);_0x2de11c[_0xfb27('0x12')]['sort']=_0x1bd6ff['fields'][_0xfb27('0x21')](',');_0x3002de=_0x1bd6ff[_0xfb27('0x22')];})[_0xfb27('0x17')](function(){if(!_0x2d0aa7){return[];}return rta[_0xfb27('0x23')](_0x2d0aa7,_0xa0e47c);})['then'](function(_0x5317bc){_0xb7b8ff=_0x5317bc;return rta[_0xfb27('0x24')]();})[_0xfb27('0x17')](function(_0x3d2f05){_0x42f7e6=_0x3d2f05['rows'];if((!_0x49bfd2||_0x483a53)&&!_0x3002de){return _0xb7b8ff;}if(_0x3002de&&!_0x49bfd2){return rta[_0xfb27('0x25')](_0x42f7e6,_0xb7b8ff,_0x3002de);}else{return rta['getAgentIdsByStatus'](_0x42f7e6,_0xb7b8ff,_0x49bfd2);}})['then'](function(_0x1860ad){_0xb7b8ff=_0x1860ad;var _0x14699e=![];if(_0xb7b8ff[_0xfb27('0x26')]===0x0){if(_0x2d0aa7||_0x49bfd2){_0x14699e=!![];}if(_0x483a53){_0x14699e=![];}}if(_0x14699e){return _0x345f2f;}var _0x4857da=_[_0xfb27('0x27')](db[_0xfb27('0x28')][_0xfb27('0x29')],function(_0x4a02a1){return{'name':_0x4a02a1[_0xfb27('0x2a')],'type':_0x4a02a1[_0xfb27('0x2b')][_0xfb27('0x2c')]};});_0x2de11c[_0xfb27('0x12')][_0xfb27('0x2d')]='agent';_0x1b5cf8=qs[_0xfb27('0x2e')](_0x4857da,_0x2de11c);_0x1b5cf8[_0xfb27('0x2f')]=!![];var _0x30e0c0=[];if(_0xb7b8ff['length']>0x0){_0x30e0c0[_0xfb27('0x30')]({'id':{'$in':_0xb7b8ff}});if(_0x3002de&&!_0x49bfd2){_0x2a6ec0=[db[_0xfb27('0x31')][_0xfb27('0x32')](_0xfb27('0x33')+_0xb7b8ff+')')];_0x1b5cf8[_0xfb27('0x22')]=_0x2a6ec0;}}if(_0x483a53){_0x4c7f2d[_0xfb27('0x34')](function(_0x34e46c){var _0x110d72=!![];if(_0x49bfd2===_0xfb27('0x35')&&_0xa0e47c!==_0x34e46c){_0x110d72=![];}_0x30e0c0[_0xfb27('0x30')]({[_0x34e46c+_0xfb27('0x36')]:_0x110d72});});if(_0x4f27d5){_0x30e0c0[_0xfb27('0x30')]({'pauseType':_0x4f27d5});}}else if(_0x49bfd2){_0x4c7f2d['forEach'](function(_0x5512c7){_0x30e0c0[_0xfb27('0x30')]({[_0x5512c7+'Pause']:![]});});}_0x1b5cf8[_0xfb27('0x37')]=_[_0xfb27('0x38')](_0x1b5cf8['where'],{'$and':_0x30e0c0});if(_0x2de11c[_0xfb27('0x39')][_0xfb27('0x2d')]===_0xfb27('0x39')){var _0x1a6e5b={'params':{'id':_0x2de11c[_0xfb27('0x39')][_0xfb27('0x3a')]},'query':{'section':_0xfb27('0x3b'),'role':_0xfb27('0x3c'),'raw':!![],'ids':_0xb7b8ff,'customSorting':_0x2a6ec0}};if(_0x2de11c[_0xfb27('0x12')]['online']){_0x1a6e5b[_0xfb27('0x12')][_0xfb27('0x3d')]=!![];}if(_0x483a53){_0x1a6e5b[_0xfb27('0x12')][_0xfb27('0x3e')]=_0x30e0c0;}_0x1a6e5b[_0xfb27('0x12')]=Object[_0xfb27('0x3f')](_0x1a6e5b[_0xfb27('0x12')],_0x2de11c[_0xfb27('0x12')]);return db['UserProfile'][_0xfb27('0x40')](_0x1a6e5b);}return db['User'][_0xfb27('0x41')](_0x1b5cf8);})[_0xfb27('0x17')](function(_0x15c857){_0x345f2f[_0xfb27('0xb')]=_0x15c857[_0xfb27('0xb')];_0x37a7aa=_0x15c857[_0xfb27('0x42')];return _0x37a7aa[_0xfb27('0x27')](function(_0x787fbc){var _0x1d138e=_[_0xfb27('0x43')](_0x42f7e6,['id',_0x787fbc['id']]);if(_0x1d138e){var _0x172abc=rta[_0xfb27('0x44')](_0x1d138e);_[_0xfb27('0x38')](_0x787fbc,_0x172abc);}_0x787fbc['globalStatus']=rta['getAgentStatus'](_0x787fbc);if(_0x787fbc['globalStatus']['includes'](_0xfb27('0x15'))){_0x4c7f2d[_0xfb27('0x34')](function(_0x3ade31){if(_0x787fbc[_0x3ade31+'Pause']){if(_0x3ade31==='voice'){if(_0x787fbc['voiceStatus']!==_0xfb27('0x45')){_0x787fbc[_0xfb27('0x46')]=_0xfb27('0x15');}}else{_0x787fbc[_0x3ade31+_0xfb27('0x47')]='pause';}}});}return _0x787fbc;});})[_0xfb27('0x17')](function(_0x1b5698){if(!_0x3002de||_0x2a6ec0){return _0x1b5698;}return rta[_0xfb27('0x48')](_0x1b5698,_0x3002de);})[_0xfb27('0x17')](function(_0x5578a3){var _0x1fac76=rta[_0xfb27('0x49')]();_0x345f2f['rows']=_0x5578a3[_0xfb27('0x27')](function(_0x6ffb9a){return _[_0xfb27('0x4a')](_0x6ffb9a,_0x1fac76);});return _0x345f2f;})[_0xfb27('0x17')](respondWithFilteredResult(_0xd3d0da,_0x1b5cf8))[_0xfb27('0x4b')](APIHandleError(_0xd3d0da));};exports[_0xfb27('0x4c')]=function(_0x3d5e71,_0x1170f0){var _0x2b61ca={'count':0x0,'rows':[]};var _0x4c8eb2={};var _0x5bae2c;var _0x4381b6;var _0x531ca9;Promise[_0xfb27('0x16')]()[_0xfb27('0x17')](function(){if(_0x3d5e71['query'][_0xfb27('0x18')]){if(!utils[_0xfb27('0x19')](_0x3d5e71[_0xfb27('0x12')][_0xfb27('0x18')])){throw new APIBadRequestError(util['format'](_0xfb27('0x1b'),_0x3d5e71[_0xfb27('0x12')]['channel']));}_0x5bae2c=_0x3d5e71[_0xfb27('0x12')]['channel']['toLowerCase']();}var _0x43cf7f=_[_0xfb27('0x4d')](_0x5bae2c)+'Queue';var _0x13572f=_[_0xfb27('0x27')](db[_0x43cf7f][_0xfb27('0x29')],function(_0xbcb3b0){return{'name':_0xbcb3b0[_0xfb27('0x2a')],'type':_0xbcb3b0[_0xfb27('0x2b')][_0xfb27('0x2c')]};});if(!_0x3d5e71['query']['fields']){var _0x16afe1=['id',_0xfb27('0x4e')];if(_0x5bae2c===_0xfb27('0x4f')){_0x16afe1['push'](_0xfb27('0x2b'));if(_0x3d5e71[_0xfb27('0x12')][_0xfb27('0x2b')]===_0xfb27('0x50')){_0x16afe1[_0xfb27('0x30')]([_0xfb27('0x51'),_0xfb27('0x52')]);}}_0x3d5e71['query'][_0xfb27('0x53')]=_0x16afe1[_0xfb27('0x21')](',');}_0x4c8eb2=qs[_0xfb27('0x2e')](_0x13572f,_0x3d5e71);if(_0x3d5e71[_0xfb27('0x39')]['role']===_0xfb27('0x39')){var _0x50cdbd={'params':{'id':_0x3d5e71[_0xfb27('0x39')]['userProfileId']},'query':{'section':_0x5bae2c===_0xfb27('0x4f')&&_0x3d5e71['query'][_0xfb27('0x2b')]===_0xfb27('0x50')?_0xfb27('0x54'):_[_0xfb27('0x4d')](_0x5bae2c)+'Queues','type':_0x3d5e71[_0xfb27('0x12')][_0xfb27('0x2b')],'nolimit':!![],'sort':_0xfb27('0x4e'),'filter':_0x3d5e71[_0xfb27('0x12')][_0xfb27('0x55')]}};_0x50cdbd[_0xfb27('0x12')]=Object['assign'](_0x50cdbd[_0xfb27('0x12')],_0x3d5e71[_0xfb27('0x12')]);delete _0x50cdbd[_0xfb27('0x12')]['id'];return db[_0xfb27('0x56')]['getResources'](_0x50cdbd);}return db[_0x43cf7f]['findAndCountAll'](_0x4c8eb2);})[_0xfb27('0x17')](function(_0x1889d1){_0x2b61ca[_0xfb27('0xb')]=_0x1889d1['count'];_0x4381b6=_0x1889d1[_0xfb27('0x42')];return rtq[_0xfb27('0x57')](_0x3d5e71,_0x5bae2c);})[_0xfb27('0x17')](function(_0x5ccc2c){_0x531ca9=_0x5ccc2c[_0xfb27('0x42')];return rtq['initializeQueues'](_0x4381b6,_0x531ca9,_0x5bae2c,_0x3d5e71[_0xfb27('0x12')][_0xfb27('0x2b')]);})[_0xfb27('0x17')](function(_0x3b86d1){_0x2b61ca[_0xfb27('0x42')]=_0x3b86d1;return _0x2b61ca;})['then'](respondWithFilteredResult(_0x1170f0,_0x4c8eb2))[_0xfb27('0x4b')](APIHandleError(_0x1170f0));};