ca9f88b41960b9de56e20e3b96ea6856a6c1c0cb
[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 _0xf77f=['[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','length','[utils][getVoiceQueueByName]','addTime','add','seconds','subtractTime','subtract','format','YYYY-MM-DD\x20HH:mm:ss','diff','sumTime','isAfter','isBefore','bluebird','moment','util','client','http','../../config/logger','xdr','info','inspect','debug','error','request','[utils][request]\x20name:%s','GetUser','internal','name','then','[utils][getUser]\x20where:%s','stringify','result','notfound','catch','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','found','[utils][getUserByInterface]','[utils][getUserByName]\x20name:%s\x20%s'];(function(_0x2bff0b,_0x449287){var _0x28f51c=function(_0x2a6b34){while(--_0x2a6b34){_0x2bff0b['push'](_0x2bff0b['shift']());}};_0x28f51c(++_0x449287);}(_0xf77f,0x134));var _0xff77=function(_0x243b2f,_0x30aa15){_0x243b2f=_0x243b2f-0x0;var _0xcb3c2d=_0xf77f[_0x243b2f];return _0xcb3c2d;};'use strict';var BPromise=require(_0xff77('0x0'));var jayson=require('jayson/promise');var moment=require(_0xff77('0x1'));var util=require(_0xff77('0x2'));var client=jayson[_0xff77('0x3')][_0xff77('0x4')]({'port':0x2329});var logger=require(_0xff77('0x5'))(_0xff77('0x6'));exports[_0xff77('0x7')]=function(_0x46d176,_0x5ecdd9){logger[_0xff77('0x7')](_0x46d176,_0x5ecdd9?util[_0xff77('0x8')](_0x5ecdd9,{'showHidden':![],'depth':null}):'');};exports['debug']=function(_0x4e6e64,_0x3c7cd9){logger[_0xff77('0x9')](_0x4e6e64,_0x3c7cd9?util[_0xff77('0x8')](_0x3c7cd9,{'showHidden':![],'depth':null}):'');};exports[_0xff77('0xa')]=function(_0x4a4f77,_0x224f88){logger[_0xff77('0xa')](_0x4a4f77,_0x224f88?util[_0xff77('0x8')](_0x224f88,{'showHidden':![],'depth':null}):'');};exports[_0xff77('0xb')]=function(_0x155db7,_0x2d4d30){return client[_0xff77('0xb')](_0x155db7,{'body':_0x2d4d30})['then'](function(_0x17ef60){logger[_0xff77('0x9')](_0xff77('0xc'),_0x155db7,_0x17ef60?util[_0xff77('0x8')](_0x17ef60,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x5a1287){logger['error'](_0xff77('0xc'),_0x155db7,_0x5a1287?util[_0xff77('0x8')](_0x5a1287,{'showHidden':![],'depth':null}):'');});};function getUser(_0x4b3e95){return client[_0xff77('0xb')](_0xff77('0xd'),{'options':{'raw':!![],'attributes':['id',_0xff77('0xe'),_0xff77('0xf'),'interface'],'where':_0x4b3e95,'limit':0x1}})[_0xff77('0x10')](function(_0xb191b3){logger[_0xff77('0x9')](_0xff77('0x11'),JSON[_0xff77('0x12')](_0x4b3e95),_0xb191b3?util['inspect'](_0xb191b3,{'showHidden':![],'depth':null}):'');return _0xb191b3['result']['length']?_0xb191b3[_0xff77('0x13')][0x0]:null;});}exports['getUserByInternal']=function(_0x69d6c9){return new BPromise(function(_0x5e48e3,_0x4574d3){if(_0x69d6c9){return getUser({'internal':_0x69d6c9})['then'](function(_0x16078f){logger[_0xff77('0x7')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x69d6c9,_0x16078f?'found':_0xff77('0x14'));return _0x5e48e3(_0x16078f);})[_0xff77('0x15')](function(_0x26b323){logger['error'](_0xff77('0x16'),_0x26b323?util[_0xff77('0x8')](_0x26b323,{'showHidden':![],'depth':null}):'');return _0x5e48e3(null);});}return _0x5e48e3(null);});};exports[_0xff77('0x17')]=function(_0x299e79){return new BPromise(function(_0x1eed7f,_0x19d1ee){if(_0x299e79){return getUser({'interface':_0x299e79})['then'](function(_0x28d57d){logger[_0xff77('0x7')](_0xff77('0x18'),_0x299e79,_0x28d57d?_0xff77('0x19'):_0xff77('0x14'));return _0x1eed7f(_0x28d57d);})['catch'](function(_0x238374){logger[_0xff77('0xa')](_0xff77('0x1a'),_0x238374?util[_0xff77('0x8')](_0x238374,{'showHidden':![],'depth':null}):'');return _0x1eed7f(null);});}return _0x1eed7f(null);});};exports['getUserByName']=function(_0x40f114){return new BPromise(function(_0x1fb504,_0x44dc37){if(_0x40f114){return getUser({'name':_0x40f114})[_0xff77('0x10')](function(_0x4ddfaa){logger['info'](_0xff77('0x1b'),_0x40f114,_0x4ddfaa?_0xff77('0x19'):_0xff77('0x14'));return _0x1fb504(_0x4ddfaa);})[_0xff77('0x15')](function(_0x33e69f){logger[_0xff77('0xa')](_0xff77('0x1c'),_0x33e69f?util[_0xff77('0x8')](_0x33e69f,{'showHidden':![],'depth':null}):'');return _0x1fb504(null);});}return _0x1fb504(null);});};exports[_0xff77('0x1d')]=function(_0x14ca34){return new BPromise(function(_0x527bd8,_0x199f40){if(_0x14ca34){return client[_0xff77('0xb')](_0xff77('0x1e'),{'options':{'raw':!![],'attributes':['id',_0xff77('0xf'),'type',_0xff77('0x1f'),_0xff77('0x20')],'where':{'name':_0x14ca34},'limit':0x1}})['then'](function(_0x6c362b){logger[_0xff77('0x9')](_0xff77('0x21'),_0x14ca34,_0x6c362b?util['inspect'](_0x6c362b,{'showHidden':![],'depth':null}):'');logger[_0xff77('0x7')](_0xff77('0x22'),_0x14ca34,_0x6c362b?'found':_0xff77('0x14'));return _0x527bd8(_0x6c362b['result'][_0xff77('0x23')]?_0x6c362b['result'][0x0]:null);})[_0xff77('0x15')](function(_0x618109){logger[_0xff77('0xa')](_0xff77('0x24'),_0x618109?util[_0xff77('0x8')](_0x618109,{'showHidden':![],'depth':null}):'');return _0x527bd8(null);});}return _0x527bd8(null);});};exports[_0xff77('0x25')]=function(_0xe7a76f,_0x2d1410){return moment(_0xe7a76f)[_0xff77('0x26')](_0x2d1410,_0xff77('0x27'))['format']('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xff77('0x28')]=function(_0x318001,_0x2d83d4){return moment(_0x318001)[_0xff77('0x29')](_0x2d83d4,_0xff77('0x27'))[_0xff77('0x2a')](_0xff77('0x2b'));};exports['diffTime']=function(_0x5a6a07,_0x1f2e47){return moment(_0x5a6a07)[_0xff77('0x2c')](moment(_0x1f2e47),_0xff77('0x27'));};exports[_0xff77('0x2d')]=function(_0x5328d5,_0x1b1de4){return parseInt(_0x5328d5,0xa)+parseInt(_0x1b1de4,0xa);};exports['now']=function(){return moment()[_0xff77('0x2a')](_0xff77('0x2b'));};exports[_0xff77('0x2e')]=function(_0x5be65a,_0x283311){if(_0x283311){return moment(_0x5be65a)[_0xff77('0x2e')](_0x283311);}return!![];};exports[_0xff77('0x2f')]=function(_0x310009,_0x334baa){if(_0x334baa){return moment(_0x310009)['isBefore'](_0x334baa);}else if(_0x310009){return!![];}return![];};