5af0047d32fabe8cd5402c5b6f05f26b91ed43f6
[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 _0x4b8f=['add','seconds','YYYY-MM-DD\x20HH:mm:ss','subtract','diffTime','diff','now','format','isAfter','isBefore','bluebird','jayson/promise','moment','util','client','http','../../config/logger','xdr','info','inspect','debug','error','request','[utils][request]\x20name:%s','catch','GetUser','name','interface','then','[utils][getUser]\x20where:%s','stringify','length','[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','getVoiceQueueByName','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','result','addTime'];(function(_0x45d55e,_0x2fede3){var _0x29812a=function(_0x3c6830){while(--_0x3c6830){_0x45d55e['push'](_0x45d55e['shift']());}};_0x29812a(++_0x2fede3);}(_0x4b8f,0x66));var _0xf4b8=function(_0x14bc06,_0x2a1b0e){_0x14bc06=_0x14bc06-0x0;var _0xf0312f=_0x4b8f[_0x14bc06];return _0xf0312f;};'use strict';var BPromise=require(_0xf4b8('0x0'));var jayson=require(_0xf4b8('0x1'));var moment=require(_0xf4b8('0x2'));var util=require(_0xf4b8('0x3'));var client=jayson[_0xf4b8('0x4')][_0xf4b8('0x5')]({'port':0x2329});var logger=require(_0xf4b8('0x6'))(_0xf4b8('0x7'));exports[_0xf4b8('0x8')]=function(_0x9b0572,_0x45623e){logger[_0xf4b8('0x8')](_0x9b0572,_0x45623e?util[_0xf4b8('0x9')](_0x45623e,{'showHidden':![],'depth':null}):'');};exports['debug']=function(_0x458f42,_0x244958){logger[_0xf4b8('0xa')](_0x458f42,_0x244958?util['inspect'](_0x244958,{'showHidden':![],'depth':null}):'');};exports[_0xf4b8('0xb')]=function(_0x48cc8e,_0x152122){logger['error'](_0x48cc8e,_0x152122?util[_0xf4b8('0x9')](_0x152122,{'showHidden':![],'depth':null}):'');};exports[_0xf4b8('0xc')]=function(_0x4f85d6,_0x1aa0ae){return client[_0xf4b8('0xc')](_0x4f85d6,{'body':_0x1aa0ae})['then'](function(_0x3e5ae4){logger[_0xf4b8('0xa')](_0xf4b8('0xd'),_0x4f85d6,_0x3e5ae4?util[_0xf4b8('0x9')](_0x3e5ae4,{'showHidden':![],'depth':null}):'');})[_0xf4b8('0xe')](function(_0x5394e2){logger['error'](_0xf4b8('0xd'),_0x4f85d6,_0x5394e2?util[_0xf4b8('0x9')](_0x5394e2,{'showHidden':![],'depth':null}):'');});};function getUser(_0x181029){return client['request'](_0xf4b8('0xf'),{'options':{'raw':!![],'attributes':['id','internal',_0xf4b8('0x10'),_0xf4b8('0x11')],'where':_0x181029,'limit':0x1}})[_0xf4b8('0x12')](function(_0x117db4){logger[_0xf4b8('0xa')](_0xf4b8('0x13'),JSON[_0xf4b8('0x14')](_0x181029),_0x117db4?util[_0xf4b8('0x9')](_0x117db4,{'showHidden':![],'depth':null}):'');return _0x117db4['result'][_0xf4b8('0x15')]?_0x117db4['result'][0x0]:null;});}exports['getUserByInternal']=function(_0x49ef2f){return new BPromise(function(_0x3e3c98,_0xf44455){if(_0x49ef2f){return getUser({'internal':_0x49ef2f})[_0xf4b8('0x12')](function(_0x64a3d0){logger['info'](_0xf4b8('0x16'),_0x49ef2f,_0x64a3d0?_0xf4b8('0x17'):_0xf4b8('0x18'));return _0x3e3c98(_0x64a3d0);})['catch'](function(_0x5a13b1){logger[_0xf4b8('0xb')](_0xf4b8('0x19'),_0x5a13b1?util['inspect'](_0x5a13b1,{'showHidden':![],'depth':null}):'');return _0x3e3c98(null);});}return _0x3e3c98(null);});};exports[_0xf4b8('0x1a')]=function(_0x2a43c7){return new BPromise(function(_0x1d9d28,_0xb5304f){if(_0x2a43c7){return getUser({'interface':_0x2a43c7})[_0xf4b8('0x12')](function(_0x3ad985){logger['info'](_0xf4b8('0x1b'),_0x2a43c7,_0x3ad985?'found':'notfound');return _0x1d9d28(_0x3ad985);})['catch'](function(_0x3b1572){logger[_0xf4b8('0xb')](_0xf4b8('0x1c'),_0x3b1572?util[_0xf4b8('0x9')](_0x3b1572,{'showHidden':![],'depth':null}):'');return _0x1d9d28(null);});}return _0x1d9d28(null);});};exports[_0xf4b8('0x1d')]=function(_0x5c5eb3){return new BPromise(function(_0x5828b0,_0x89429d){if(_0x5c5eb3){return getUser({'name':_0x5c5eb3})[_0xf4b8('0x12')](function(_0x5cbfdf){logger[_0xf4b8('0x8')](_0xf4b8('0x1e'),_0x5c5eb3,_0x5cbfdf?_0xf4b8('0x17'):_0xf4b8('0x18'));return _0x5828b0(_0x5cbfdf);})[_0xf4b8('0xe')](function(_0x5279a5){logger[_0xf4b8('0xb')]('[utils][getUserByName]',_0x5279a5?util[_0xf4b8('0x9')](_0x5279a5,{'showHidden':![],'depth':null}):'');return _0x5828b0(null);});}return _0x5828b0(null);});};exports[_0xf4b8('0x1f')]=function(_0x5826ac){return new BPromise(function(_0x5dd159,_0x5633ae){if(_0x5826ac){return client[_0xf4b8('0xc')]('GetVoiceQueue',{'options':{'raw':!![],'attributes':['id','name','type','acw','acwTimeout'],'where':{'name':_0x5826ac},'limit':0x1}})[_0xf4b8('0x12')](function(_0x251036){logger[_0xf4b8('0xa')](_0xf4b8('0x20'),_0x5826ac,_0x251036?util[_0xf4b8('0x9')](_0x251036,{'showHidden':![],'depth':null}):'');logger[_0xf4b8('0x8')](_0xf4b8('0x21'),_0x5826ac,_0x251036?_0xf4b8('0x17'):_0xf4b8('0x18'));return _0x5dd159(_0x251036[_0xf4b8('0x22')][_0xf4b8('0x15')]?_0x251036[_0xf4b8('0x22')][0x0]:null);})[_0xf4b8('0xe')](function(_0x203e53){logger[_0xf4b8('0xb')]('[utils][getVoiceQueueByName]',_0x203e53?util['inspect'](_0x203e53,{'showHidden':![],'depth':null}):'');return _0x5dd159(null);});}return _0x5dd159(null);});};exports[_0xf4b8('0x23')]=function(_0x502b8a,_0x1859c9){return moment(_0x502b8a)[_0xf4b8('0x24')](_0x1859c9,_0xf4b8('0x25'))['format'](_0xf4b8('0x26'));};exports['subtractTime']=function(_0x2604b4,_0x488306){return moment(_0x2604b4)[_0xf4b8('0x27')](_0x488306,_0xf4b8('0x25'))['format'](_0xf4b8('0x26'));};exports[_0xf4b8('0x28')]=function(_0x3465f4,_0x1dc047){return moment(_0x3465f4)[_0xf4b8('0x29')](moment(_0x1dc047),_0xf4b8('0x25'));};exports['sumTime']=function(_0x301f58,_0x3b6dc0){return parseInt(_0x301f58,0xa)+parseInt(_0x3b6dc0,0xa);};exports[_0xf4b8('0x2a')]=function(){return moment()[_0xf4b8('0x2b')](_0xf4b8('0x26'));};exports['isAfter']=function(_0x2d18c6,_0x2a91af){if(_0x2a91af){return moment(_0x2d18c6)[_0xf4b8('0x2c')](_0x2a91af);}return!![];};exports[_0xf4b8('0x2d')]=function(_0x5b195d,_0xa8c3ea){if(_0xa8c3ea){return moment(_0x5b195d)[_0xf4b8('0x2d')](_0xa8c3ea);}else if(_0x5b195d){return!![];}return![];};