Built motion from commit eddce310.|2.6.12
[motion2.git] / server / services / xdr / utils.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 _0x3759=['debug','inspect','error','request','[utils][request]\x20name:%s','internal','then','stringify','result','length','getUserByInternal','found','notfound','[utils][getUserByInternal]','[utils][getUserByInterface]\x20interface:%s\x20%s','catch','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]','GetVoiceQueue','name','type','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtract','diffTime','diff','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','moment','util','client','xdr','info'];(function(_0x5f049d,_0x31a171){var _0x27b1c5=function(_0x4ee6bc){while(--_0x4ee6bc){_0x5f049d['push'](_0x5f049d['shift']());}};_0x27b1c5(++_0x31a171);}(_0x3759,0x131));var _0x9375=function(_0xfb03e5,_0x25c988){_0xfb03e5=_0xfb03e5-0x0;var _0x2bce94=_0x3759[_0xfb03e5];return _0x2bce94;};'use strict';var BPromise=require(_0x9375('0x0'));var jayson=require(_0x9375('0x1'));var moment=require(_0x9375('0x2'));var util=require(_0x9375('0x3'));var client=jayson[_0x9375('0x4')]['http']({'port':0x2329});var logger=require('../../config/logger')(_0x9375('0x5'));exports[_0x9375('0x6')]=function(_0x593f50,_0x1ec343){logger[_0x9375('0x6')](_0x593f50,_0x1ec343?util['inspect'](_0x1ec343,{'showHidden':![],'depth':null}):'');};exports[_0x9375('0x7')]=function(_0x2e5a30,_0x259bc2){logger[_0x9375('0x7')](_0x2e5a30,_0x259bc2?util[_0x9375('0x8')](_0x259bc2,{'showHidden':![],'depth':null}):'');};exports[_0x9375('0x9')]=function(_0x3d8bc8,_0x44fa56){logger['error'](_0x3d8bc8,_0x44fa56?util['inspect'](_0x44fa56,{'showHidden':![],'depth':null}):'');};exports['request']=function(_0x34b7a8,_0x14c75c){return client[_0x9375('0xa')](_0x34b7a8,{'body':_0x14c75c})['then'](function(_0x2be560){logger[_0x9375('0x7')](_0x9375('0xb'),_0x34b7a8,_0x2be560?util[_0x9375('0x8')](_0x2be560,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x21d0c4){logger[_0x9375('0x9')](_0x9375('0xb'),_0x34b7a8,_0x21d0c4?util[_0x9375('0x8')](_0x21d0c4,{'showHidden':![],'depth':null}):'');});};function getUser(_0x4c4ce3){return client['request']('GetUser',{'options':{'raw':!![],'attributes':['id',_0x9375('0xc'),'name','interface'],'where':_0x4c4ce3,'limit':0x1}})[_0x9375('0xd')](function(_0x4402a5){logger[_0x9375('0x7')]('[utils][getUser]\x20where:%s',JSON[_0x9375('0xe')](_0x4c4ce3),_0x4402a5?util['inspect'](_0x4402a5,{'showHidden':![],'depth':null}):'');return _0x4402a5[_0x9375('0xf')][_0x9375('0x10')]?_0x4402a5['result'][0x0]:null;});}exports[_0x9375('0x11')]=function(_0x55874c){return new BPromise(function(_0x5e915d,_0x369c37){if(_0x55874c){return getUser({'internal':_0x55874c})[_0x9375('0xd')](function(_0x3f8f03){logger[_0x9375('0x6')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x55874c,_0x3f8f03?_0x9375('0x12'):_0x9375('0x13'));return _0x5e915d(_0x3f8f03);})['catch'](function(_0x19146f){logger[_0x9375('0x9')](_0x9375('0x14'),_0x19146f?util[_0x9375('0x8')](_0x19146f,{'showHidden':![],'depth':null}):'');return _0x5e915d(null);});}return _0x5e915d(null);});};exports['getUserByInterface']=function(_0x298a8b){return new BPromise(function(_0x38a4a5,_0x3408f8){if(_0x298a8b){return getUser({'interface':_0x298a8b})[_0x9375('0xd')](function(_0x2b77e4){logger[_0x9375('0x6')](_0x9375('0x15'),_0x298a8b,_0x2b77e4?'found':'notfound');return _0x38a4a5(_0x2b77e4);})[_0x9375('0x16')](function(_0x1c36b0){logger[_0x9375('0x9')](_0x9375('0x17'),_0x1c36b0?util[_0x9375('0x8')](_0x1c36b0,{'showHidden':![],'depth':null}):'');return _0x38a4a5(null);});}return _0x38a4a5(null);});};exports[_0x9375('0x18')]=function(_0x2af28c){return new BPromise(function(_0x4985d2,_0x4f74f8){if(_0x2af28c){return getUser({'name':_0x2af28c})[_0x9375('0xd')](function(_0x395097){logger[_0x9375('0x6')]('[utils][getUserByName]\x20name:%s\x20%s',_0x2af28c,_0x395097?'found':_0x9375('0x13'));return _0x4985d2(_0x395097);})['catch'](function(_0x1925d4){logger[_0x9375('0x9')](_0x9375('0x19'),_0x1925d4?util[_0x9375('0x8')](_0x1925d4,{'showHidden':![],'depth':null}):'');return _0x4985d2(null);});}return _0x4985d2(null);});};exports['getVoiceQueueByName']=function(_0x872be7){return new BPromise(function(_0x4e8233,_0x54013f){if(_0x872be7){return client[_0x9375('0xa')](_0x9375('0x1a'),{'options':{'raw':!![],'attributes':['id',_0x9375('0x1b'),_0x9375('0x1c'),'acw','acwTimeout'],'where':{'name':_0x872be7},'limit':0x1}})[_0x9375('0xd')](function(_0x196499){logger[_0x9375('0x7')]('[utils][getVoiceQueueByName]\x20name:%s',_0x872be7,_0x196499?util[_0x9375('0x8')](_0x196499,{'showHidden':![],'depth':null}):'');logger[_0x9375('0x6')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0x872be7,_0x196499?'found':_0x9375('0x13'));return _0x4e8233(_0x196499[_0x9375('0xf')][_0x9375('0x10')]?_0x196499[_0x9375('0xf')][0x0]:null);})['catch'](function(_0x1ceb9a){logger[_0x9375('0x9')]('[utils][getVoiceQueueByName]',_0x1ceb9a?util[_0x9375('0x8')](_0x1ceb9a,{'showHidden':![],'depth':null}):'');return _0x4e8233(null);});}return _0x4e8233(null);});};exports['addTime']=function(_0x4e85ab,_0x57790e){return moment(_0x4e85ab)['add'](_0x57790e,_0x9375('0x1d'))[_0x9375('0x1e')](_0x9375('0x1f'));};exports['subtractTime']=function(_0x383884,_0x382d48){return moment(_0x383884)[_0x9375('0x20')](_0x382d48,_0x9375('0x1d'))[_0x9375('0x1e')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x9375('0x21')]=function(_0x319b1e,_0x3cb68a){return moment(_0x319b1e)[_0x9375('0x22')](moment(_0x3cb68a),'seconds');};exports[_0x9375('0x23')]=function(_0x44b5dd,_0x4dff8d){return parseInt(_0x44b5dd,0xa)+parseInt(_0x4dff8d,0xa);};exports[_0x9375('0x24')]=function(){return moment()[_0x9375('0x1e')](_0x9375('0x1f'));};exports['isAfter']=function(_0x32f62c,_0x3ade88){if(_0x3ade88){return moment(_0x32f62c)[_0x9375('0x25')](_0x3ade88);}return!![];};exports['isBefore']=function(_0x4a9c0d,_0x24b10d){if(_0x24b10d){return moment(_0x4a9c0d)[_0x9375('0x26')](_0x24b10d);}else if(_0x4a9c0d){return!![];}return![];};