9717bec835763cf61fea5745ff9ce883669a9b96
[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 _0xb1f7=['debug','error','request','then','[utils][request]\x20name:%s','catch','GetUser','internal','interface','[utils][getUser]\x20where:%s','stringify','result','length','found','notfound','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','getUserByName','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','addTime','add','seconds','subtractTime','subtract','format','YYYY-MM-DD\x20HH:mm:ss','diff','sumTime','now','isAfter','bluebird','jayson/promise','moment','util','client','http','../../config/logger','xdr','info','inspect'];(function(_0x42cae2,_0x284ef8){var _0x5f256f=function(_0x41abc8){while(--_0x41abc8){_0x42cae2['push'](_0x42cae2['shift']());}};_0x5f256f(++_0x284ef8);}(_0xb1f7,0x19d));var _0x7b1f=function(_0xbef885,_0x245e90){_0xbef885=_0xbef885-0x0;var _0x5502f0=_0xb1f7[_0xbef885];return _0x5502f0;};'use strict';var BPromise=require(_0x7b1f('0x0'));var jayson=require(_0x7b1f('0x1'));var moment=require(_0x7b1f('0x2'));var util=require(_0x7b1f('0x3'));var client=jayson[_0x7b1f('0x4')][_0x7b1f('0x5')]({'port':0x2329});var logger=require(_0x7b1f('0x6'))(_0x7b1f('0x7'));exports[_0x7b1f('0x8')]=function(_0x2941cc,_0x23838f){logger[_0x7b1f('0x8')](_0x2941cc,_0x23838f?util[_0x7b1f('0x9')](_0x23838f,{'showHidden':![],'depth':null}):'');};exports[_0x7b1f('0xa')]=function(_0x2c6da6,_0x467c4c){logger[_0x7b1f('0xa')](_0x2c6da6,_0x467c4c?util[_0x7b1f('0x9')](_0x467c4c,{'showHidden':![],'depth':null}):'');};exports[_0x7b1f('0xb')]=function(_0x2783a0,_0x2df717){logger[_0x7b1f('0xb')](_0x2783a0,_0x2df717?util[_0x7b1f('0x9')](_0x2df717,{'showHidden':![],'depth':null}):'');};exports['request']=function(_0x5bda9a,_0x4802ab){return client[_0x7b1f('0xc')](_0x5bda9a,{'body':_0x4802ab})[_0x7b1f('0xd')](function(_0x1d0989){logger['debug'](_0x7b1f('0xe'),_0x5bda9a,_0x1d0989?util[_0x7b1f('0x9')](_0x1d0989,{'showHidden':![],'depth':null}):'');})[_0x7b1f('0xf')](function(_0x3484db){logger['error'](_0x7b1f('0xe'),_0x5bda9a,_0x3484db?util[_0x7b1f('0x9')](_0x3484db,{'showHidden':![],'depth':null}):'');});};function getUser(_0x416c65){return client[_0x7b1f('0xc')](_0x7b1f('0x10'),{'options':{'raw':!![],'attributes':['id',_0x7b1f('0x11'),'name',_0x7b1f('0x12')],'where':_0x416c65,'limit':0x1}})['then'](function(_0x57f110){logger[_0x7b1f('0xa')](_0x7b1f('0x13'),JSON[_0x7b1f('0x14')](_0x416c65),_0x57f110?util['inspect'](_0x57f110,{'showHidden':![],'depth':null}):'');return _0x57f110[_0x7b1f('0x15')][_0x7b1f('0x16')]?_0x57f110['result'][0x0]:null;});}exports['getUserByInternal']=function(_0x5576ca){return new BPromise(function(_0x1c269c,_0x3b768b){if(_0x5576ca){return getUser({'internal':_0x5576ca})[_0x7b1f('0xd')](function(_0x4dca3b){logger[_0x7b1f('0x8')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x5576ca,_0x4dca3b?_0x7b1f('0x17'):_0x7b1f('0x18'));return _0x1c269c(_0x4dca3b);})[_0x7b1f('0xf')](function(_0x5890af){logger[_0x7b1f('0xb')]('[utils][getUserByInternal]',_0x5890af?util[_0x7b1f('0x9')](_0x5890af,{'showHidden':![],'depth':null}):'');return _0x1c269c(null);});}return _0x1c269c(null);});};exports[_0x7b1f('0x19')]=function(_0xf5a059){return new BPromise(function(_0xc3a52a,_0x48487d){if(_0xf5a059){return getUser({'interface':_0xf5a059})['then'](function(_0x264483){logger['info'](_0x7b1f('0x1a'),_0xf5a059,_0x264483?_0x7b1f('0x17'):_0x7b1f('0x18'));return _0xc3a52a(_0x264483);})['catch'](function(_0x580cbb){logger[_0x7b1f('0xb')]('[utils][getUserByInterface]',_0x580cbb?util[_0x7b1f('0x9')](_0x580cbb,{'showHidden':![],'depth':null}):'');return _0xc3a52a(null);});}return _0xc3a52a(null);});};exports[_0x7b1f('0x1b')]=function(_0x309bd6){return new BPromise(function(_0x5de8e2,_0x3d6dc6){if(_0x309bd6){return getUser({'name':_0x309bd6})[_0x7b1f('0xd')](function(_0x299df8){logger[_0x7b1f('0x8')]('[utils][getUserByName]\x20name:%s\x20%s',_0x309bd6,_0x299df8?_0x7b1f('0x17'):_0x7b1f('0x18'));return _0x5de8e2(_0x299df8);})[_0x7b1f('0xf')](function(_0xf3764a){logger['error'](_0x7b1f('0x1c'),_0xf3764a?util[_0x7b1f('0x9')](_0xf3764a,{'showHidden':![],'depth':null}):'');return _0x5de8e2(null);});}return _0x5de8e2(null);});};exports[_0x7b1f('0x1d')]=function(_0x46842d){return new BPromise(function(_0x455f0a,_0x4be6da){if(_0x46842d){return client[_0x7b1f('0xc')](_0x7b1f('0x1e'),{'options':{'raw':!![],'attributes':['id','name',_0x7b1f('0x1f'),_0x7b1f('0x20'),_0x7b1f('0x21')],'where':{'name':_0x46842d},'limit':0x1}})[_0x7b1f('0xd')](function(_0x7eb9d3){logger['debug'](_0x7b1f('0x22'),_0x46842d,_0x7eb9d3?util[_0x7b1f('0x9')](_0x7eb9d3,{'showHidden':![],'depth':null}):'');logger[_0x7b1f('0x8')](_0x7b1f('0x23'),_0x46842d,_0x7eb9d3?_0x7b1f('0x17'):_0x7b1f('0x18'));return _0x455f0a(_0x7eb9d3[_0x7b1f('0x15')]['length']?_0x7eb9d3[_0x7b1f('0x15')][0x0]:null);})[_0x7b1f('0xf')](function(_0xa9bc63){logger[_0x7b1f('0xb')]('[utils][getVoiceQueueByName]',_0xa9bc63?util[_0x7b1f('0x9')](_0xa9bc63,{'showHidden':![],'depth':null}):'');return _0x455f0a(null);});}return _0x455f0a(null);});};exports[_0x7b1f('0x24')]=function(_0x1b969c,_0x35260c){return moment(_0x1b969c)[_0x7b1f('0x25')](_0x35260c,_0x7b1f('0x26'))['format']('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x7b1f('0x27')]=function(_0x2562b3,_0x4f2979){return moment(_0x2562b3)[_0x7b1f('0x28')](_0x4f2979,'seconds')[_0x7b1f('0x29')](_0x7b1f('0x2a'));};exports['diffTime']=function(_0x291038,_0x31669a){return moment(_0x291038)[_0x7b1f('0x2b')](moment(_0x31669a),_0x7b1f('0x26'));};exports[_0x7b1f('0x2c')]=function(_0x4f6944,_0x46f649){return parseInt(_0x4f6944,0xa)+parseInt(_0x46f649,0xa);};exports[_0x7b1f('0x2d')]=function(){return moment()[_0x7b1f('0x29')](_0x7b1f('0x2a'));};exports['isAfter']=function(_0x1f43ff,_0x50c9d8){if(_0x50c9d8){return moment(_0x1f43ff)[_0x7b1f('0x2e')](_0x50c9d8);}return!![];};exports['isBefore']=function(_0x4a8d93,_0x2b06ca){if(_0x2b06ca){return moment(_0x4a8d93)['isBefore'](_0x2b06ca);}else if(_0x4a8d93){return!![];}return![];};