Built motion from commit 753c950e.|2.5.42
[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 _0x34d2=['internal','name','interface','[utils][getUser]\x20where:%s','stringify','length','getUserByInternal','then','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','GetVoiceQueue','type','acw','[utils][getVoiceQueueByName]\x20name:%s','result','[utils][getVoiceQueueByName]','addTime','seconds','YYYY-MM-DD\x20HH:mm:ss','subtractTime','format','diffTime','diff','sumTime','isAfter','isBefore','jayson/promise','http','xdr','info','debug','inspect','error','request','catch','GetUser'];(function(_0x5f415d,_0x39b258){var _0x3ac7a6=function(_0x314dc5){while(--_0x314dc5){_0x5f415d['push'](_0x5f415d['shift']());}};_0x3ac7a6(++_0x39b258);}(_0x34d2,0x12a));var _0x234d=function(_0x1e0e31,_0x212cd6){_0x1e0e31=_0x1e0e31-0x0;var _0x495be0=_0x34d2[_0x1e0e31];return _0x495be0;};'use strict';var BPromise=require('bluebird');var jayson=require(_0x234d('0x0'));var moment=require('moment');var util=require('util');var client=jayson['client'][_0x234d('0x1')]({'port':0x2329});var logger=require('../../config/logger')(_0x234d('0x2'));exports[_0x234d('0x3')]=function(_0x5530d7,_0x4ba374){logger[_0x234d('0x3')](_0x5530d7,_0x4ba374?util['inspect'](_0x4ba374,{'showHidden':![],'depth':null}):'');};exports['debug']=function(_0x31aa2c,_0x318ff0){logger[_0x234d('0x4')](_0x31aa2c,_0x318ff0?util[_0x234d('0x5')](_0x318ff0,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x8d0cf2,_0x25e350){logger[_0x234d('0x6')](_0x8d0cf2,_0x25e350?util[_0x234d('0x5')](_0x25e350,{'showHidden':![],'depth':null}):'');};exports[_0x234d('0x7')]=function(_0x3a2a60,_0x3179d1){return client['request'](_0x3a2a60,{'body':_0x3179d1})['then'](function(_0x4b1615){logger[_0x234d('0x4')]('[utils][request]\x20name:%s',_0x3a2a60,_0x4b1615?util[_0x234d('0x5')](_0x4b1615,{'showHidden':![],'depth':null}):'');})[_0x234d('0x8')](function(_0x2c48bb){logger[_0x234d('0x6')]('[utils][request]\x20name:%s',_0x3a2a60,_0x2c48bb?util[_0x234d('0x5')](_0x2c48bb,{'showHidden':![],'depth':null}):'');});};function getUser(_0xca341a){return client['request'](_0x234d('0x9'),{'options':{'raw':!![],'attributes':['id',_0x234d('0xa'),_0x234d('0xb'),_0x234d('0xc')],'where':_0xca341a,'limit':0x1}})['then'](function(_0x560711){logger[_0x234d('0x4')](_0x234d('0xd'),JSON[_0x234d('0xe')](_0xca341a),_0x560711?util[_0x234d('0x5')](_0x560711,{'showHidden':![],'depth':null}):'');return _0x560711['result'][_0x234d('0xf')]?_0x560711['result'][0x0]:null;});}exports[_0x234d('0x10')]=function(_0x2ae590){return new BPromise(function(_0x25e2a2,_0x507967){if(_0x2ae590){return getUser({'internal':_0x2ae590})[_0x234d('0x11')](function(_0x239441){logger[_0x234d('0x3')](_0x234d('0x12'),_0x2ae590,_0x239441?_0x234d('0x13'):_0x234d('0x14'));return _0x25e2a2(_0x239441);})[_0x234d('0x8')](function(_0x316e71){logger[_0x234d('0x6')](_0x234d('0x15'),_0x316e71?util['inspect'](_0x316e71,{'showHidden':![],'depth':null}):'');return _0x25e2a2(null);});}return _0x25e2a2(null);});};exports[_0x234d('0x16')]=function(_0x4a34cd){return new BPromise(function(_0x55b76c,_0x16c748){if(_0x4a34cd){return getUser({'interface':_0x4a34cd})['then'](function(_0x2d59e5){logger['info'](_0x234d('0x17'),_0x4a34cd,_0x2d59e5?_0x234d('0x13'):_0x234d('0x14'));return _0x55b76c(_0x2d59e5);})[_0x234d('0x8')](function(_0x5916db){logger[_0x234d('0x6')](_0x234d('0x18'),_0x5916db?util[_0x234d('0x5')](_0x5916db,{'showHidden':![],'depth':null}):'');return _0x55b76c(null);});}return _0x55b76c(null);});};exports[_0x234d('0x19')]=function(_0x44380a){return new BPromise(function(_0x410323,_0x2dfbe8){if(_0x44380a){return getUser({'name':_0x44380a})[_0x234d('0x11')](function(_0x4d0115){logger[_0x234d('0x3')](_0x234d('0x1a'),_0x44380a,_0x4d0115?_0x234d('0x13'):_0x234d('0x14'));return _0x410323(_0x4d0115);})['catch'](function(_0x4ffb61){logger[_0x234d('0x6')](_0x234d('0x1b'),_0x4ffb61?util[_0x234d('0x5')](_0x4ffb61,{'showHidden':![],'depth':null}):'');return _0x410323(null);});}return _0x410323(null);});};exports['getVoiceQueueByName']=function(_0x56c388){return new BPromise(function(_0x54b8ac,_0x4f029e){if(_0x56c388){return client[_0x234d('0x7')](_0x234d('0x1c'),{'options':{'raw':!![],'attributes':['id',_0x234d('0xb'),_0x234d('0x1d'),_0x234d('0x1e'),'acwTimeout'],'where':{'name':_0x56c388},'limit':0x1}})[_0x234d('0x11')](function(_0x29467c){logger[_0x234d('0x4')](_0x234d('0x1f'),_0x56c388,_0x29467c?util[_0x234d('0x5')](_0x29467c,{'showHidden':![],'depth':null}):'');logger[_0x234d('0x3')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0x56c388,_0x29467c?_0x234d('0x13'):_0x234d('0x14'));return _0x54b8ac(_0x29467c[_0x234d('0x20')][_0x234d('0xf')]?_0x29467c[_0x234d('0x20')][0x0]:null);})['catch'](function(_0x135ce9){logger[_0x234d('0x6')](_0x234d('0x21'),_0x135ce9?util[_0x234d('0x5')](_0x135ce9,{'showHidden':![],'depth':null}):'');return _0x54b8ac(null);});}return _0x54b8ac(null);});};exports[_0x234d('0x22')]=function(_0x554fde,_0x489076){return moment(_0x554fde)['add'](_0x489076,_0x234d('0x23'))['format'](_0x234d('0x24'));};exports[_0x234d('0x25')]=function(_0x1dba4f,_0x21aed3){return moment(_0x1dba4f)['subtract'](_0x21aed3,_0x234d('0x23'))[_0x234d('0x26')](_0x234d('0x24'));};exports[_0x234d('0x27')]=function(_0x1af41a,_0x947a4e){return moment(_0x1af41a)[_0x234d('0x28')](moment(_0x947a4e),_0x234d('0x23'));};exports[_0x234d('0x29')]=function(_0x43d16e,_0x48c1e7){return parseInt(_0x43d16e,0xa)+parseInt(_0x48c1e7,0xa);};exports['now']=function(){return moment()['format']('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x234d('0x2a')]=function(_0x2ddba8,_0x471477){if(_0x471477){return moment(_0x2ddba8)['isAfter'](_0x471477);}return!![];};exports[_0x234d('0x2b')]=function(_0x335266,_0x2c4b1b){if(_0x2c4b1b){return moment(_0x335266)[_0x234d('0x2b')](_0x2c4b1b);}else if(_0x335266){return!![];}return![];};