Built motion from commit 9e1399f3.|2.5.37
[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 _0x91f8=['debug','error','request','[utils][request]\x20name:%s','GetUser','internal','name','then','[utils][getUser]\x20where:%s','stringify','result','length','getUserByInternal','found','notfound','catch','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','addTime','seconds','YYYY-MM-DD\x20HH:mm:ss','subtractTime','format','diffTime','diff','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','moment','util','client','http','../../config/logger','xdr','info','inspect'];(function(_0x2641f9,_0x26715f){var _0x585741=function(_0x2d1462){while(--_0x2d1462){_0x2641f9['push'](_0x2641f9['shift']());}};_0x585741(++_0x26715f);}(_0x91f8,0x13f));var _0x891f=function(_0x128de4,_0x511592){_0x128de4=_0x128de4-0x0;var _0x167659=_0x91f8[_0x128de4];return _0x167659;};'use strict';var BPromise=require(_0x891f('0x0'));var jayson=require(_0x891f('0x1'));var moment=require(_0x891f('0x2'));var util=require(_0x891f('0x3'));var client=jayson[_0x891f('0x4')][_0x891f('0x5')]({'port':0x2329});var logger=require(_0x891f('0x6'))(_0x891f('0x7'));exports['info']=function(_0x381674,_0x61a1c0){logger[_0x891f('0x8')](_0x381674,_0x61a1c0?util[_0x891f('0x9')](_0x61a1c0,{'showHidden':![],'depth':null}):'');};exports['debug']=function(_0x1723af,_0x574b79){logger[_0x891f('0xa')](_0x1723af,_0x574b79?util[_0x891f('0x9')](_0x574b79,{'showHidden':![],'depth':null}):'');};exports[_0x891f('0xb')]=function(_0x5506b3,_0x51a692){logger[_0x891f('0xb')](_0x5506b3,_0x51a692?util[_0x891f('0x9')](_0x51a692,{'showHidden':![],'depth':null}):'');};exports['request']=function(_0x198a69,_0x1f4d97){return client[_0x891f('0xc')](_0x198a69,{'body':_0x1f4d97})['then'](function(_0xe033ac){logger[_0x891f('0xa')]('[utils][request]\x20name:%s',_0x198a69,_0xe033ac?util[_0x891f('0x9')](_0xe033ac,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x2e50c0){logger[_0x891f('0xb')](_0x891f('0xd'),_0x198a69,_0x2e50c0?util[_0x891f('0x9')](_0x2e50c0,{'showHidden':![],'depth':null}):'');});};function getUser(_0x2dfdd0){return client[_0x891f('0xc')](_0x891f('0xe'),{'options':{'raw':!![],'attributes':['id',_0x891f('0xf'),_0x891f('0x10'),'interface'],'where':_0x2dfdd0,'limit':0x1}})[_0x891f('0x11')](function(_0x23f6cc){logger[_0x891f('0xa')](_0x891f('0x12'),JSON[_0x891f('0x13')](_0x2dfdd0),_0x23f6cc?util[_0x891f('0x9')](_0x23f6cc,{'showHidden':![],'depth':null}):'');return _0x23f6cc[_0x891f('0x14')][_0x891f('0x15')]?_0x23f6cc[_0x891f('0x14')][0x0]:null;});}exports[_0x891f('0x16')]=function(_0x4cb3e1){return new BPromise(function(_0x21b1ff,_0x2739c8){if(_0x4cb3e1){return getUser({'internal':_0x4cb3e1})[_0x891f('0x11')](function(_0xa6d5e0){logger[_0x891f('0x8')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x4cb3e1,_0xa6d5e0?_0x891f('0x17'):_0x891f('0x18'));return _0x21b1ff(_0xa6d5e0);})[_0x891f('0x19')](function(_0x329d9b){logger[_0x891f('0xb')](_0x891f('0x1a'),_0x329d9b?util[_0x891f('0x9')](_0x329d9b,{'showHidden':![],'depth':null}):'');return _0x21b1ff(null);});}return _0x21b1ff(null);});};exports[_0x891f('0x1b')]=function(_0x4bfbd0){return new BPromise(function(_0x2ce130,_0x1ef9bf){if(_0x4bfbd0){return getUser({'interface':_0x4bfbd0})[_0x891f('0x11')](function(_0x798f0b){logger[_0x891f('0x8')]('[utils][getUserByInterface]\x20interface:%s\x20%s',_0x4bfbd0,_0x798f0b?'found':_0x891f('0x18'));return _0x2ce130(_0x798f0b);})[_0x891f('0x19')](function(_0x5f0e90){logger[_0x891f('0xb')](_0x891f('0x1c'),_0x5f0e90?util['inspect'](_0x5f0e90,{'showHidden':![],'depth':null}):'');return _0x2ce130(null);});}return _0x2ce130(null);});};exports[_0x891f('0x1d')]=function(_0x5c21a0){return new BPromise(function(_0xc518d1,_0x288f87){if(_0x5c21a0){return getUser({'name':_0x5c21a0})[_0x891f('0x11')](function(_0x1734bb){logger[_0x891f('0x8')]('[utils][getUserByName]\x20name:%s\x20%s',_0x5c21a0,_0x1734bb?_0x891f('0x17'):_0x891f('0x18'));return _0xc518d1(_0x1734bb);})[_0x891f('0x19')](function(_0x536418){logger[_0x891f('0xb')](_0x891f('0x1e'),_0x536418?util[_0x891f('0x9')](_0x536418,{'showHidden':![],'depth':null}):'');return _0xc518d1(null);});}return _0xc518d1(null);});};exports[_0x891f('0x1f')]=function(_0x2ebd84){return new BPromise(function(_0x5d4179,_0x1154cc){if(_0x2ebd84){return client['request'](_0x891f('0x20'),{'options':{'raw':!![],'attributes':['id',_0x891f('0x10'),'type','acw',_0x891f('0x21')],'where':{'name':_0x2ebd84},'limit':0x1}})[_0x891f('0x11')](function(_0x4dce22){logger['debug'](_0x891f('0x22'),_0x2ebd84,_0x4dce22?util[_0x891f('0x9')](_0x4dce22,{'showHidden':![],'depth':null}):'');logger['info'](_0x891f('0x23'),_0x2ebd84,_0x4dce22?_0x891f('0x17'):'notfound');return _0x5d4179(_0x4dce22[_0x891f('0x14')][_0x891f('0x15')]?_0x4dce22[_0x891f('0x14')][0x0]:null);})[_0x891f('0x19')](function(_0x31a144){logger[_0x891f('0xb')]('[utils][getVoiceQueueByName]',_0x31a144?util[_0x891f('0x9')](_0x31a144,{'showHidden':![],'depth':null}):'');return _0x5d4179(null);});}return _0x5d4179(null);});};exports[_0x891f('0x24')]=function(_0x4c72a7,_0x1bfa41){return moment(_0x4c72a7)['add'](_0x1bfa41,_0x891f('0x25'))['format'](_0x891f('0x26'));};exports[_0x891f('0x27')]=function(_0x24710e,_0x205e5a){return moment(_0x24710e)['subtract'](_0x205e5a,_0x891f('0x25'))[_0x891f('0x28')](_0x891f('0x26'));};exports[_0x891f('0x29')]=function(_0x4724a6,_0x4ed369){return moment(_0x4724a6)[_0x891f('0x2a')](moment(_0x4ed369),_0x891f('0x25'));};exports[_0x891f('0x2b')]=function(_0x1595d6,_0x5ca57e){return parseInt(_0x1595d6,0xa)+parseInt(_0x5ca57e,0xa);};exports[_0x891f('0x2c')]=function(){return moment()[_0x891f('0x28')](_0x891f('0x26'));};exports[_0x891f('0x2d')]=function(_0x10b0fe,_0x4a11da){if(_0x4a11da){return moment(_0x10b0fe)['isAfter'](_0x4a11da);}return!![];};exports[_0x891f('0x2e')]=function(_0x40cd3e,_0x1b423f){if(_0x1b423f){return moment(_0x40cd3e)[_0x891f('0x2e')](_0x1b423f);}else if(_0x40cd3e){return!![];}return![];};