Built motion from commit 0c5f406c.|2.6.29
[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 _0xd553=['[utils][request]\x20name:%s','GetUser','name','interface','stringify','length','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','catch','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','getVoiceQueueByName','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','result','add','seconds','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','format','diff','now','isAfter','jayson/promise','moment','client','http','info','inspect','debug','error','request','then'];(function(_0x2056b2,_0x2dbfed){var _0x3e1bc2=function(_0x48a18e){while(--_0x48a18e){_0x2056b2['push'](_0x2056b2['shift']());}};_0x3e1bc2(++_0x2dbfed);}(_0xd553,0xc8));var _0x3d55=function(_0x1af98d,_0x3c608e){_0x1af98d=_0x1af98d-0x0;var _0x3553ea=_0xd553[_0x1af98d];return _0x3553ea;};'use strict';var BPromise=require('bluebird');var jayson=require(_0x3d55('0x0'));var moment=require(_0x3d55('0x1'));var util=require('util');var client=jayson[_0x3d55('0x2')][_0x3d55('0x3')]({'port':0x2329});var logger=require('../../config/logger')('xdr');exports[_0x3d55('0x4')]=function(_0x1c8aa5,_0x1c2f1e){logger[_0x3d55('0x4')](_0x1c8aa5,_0x1c2f1e?util[_0x3d55('0x5')](_0x1c2f1e,{'showHidden':![],'depth':null}):'');};exports['debug']=function(_0x56d4fb,_0x34d5df){logger[_0x3d55('0x6')](_0x56d4fb,_0x34d5df?util[_0x3d55('0x5')](_0x34d5df,{'showHidden':![],'depth':null}):'');};exports[_0x3d55('0x7')]=function(_0x34e190,_0x4d1aba){logger[_0x3d55('0x7')](_0x34e190,_0x4d1aba?util[_0x3d55('0x5')](_0x4d1aba,{'showHidden':![],'depth':null}):'');};exports[_0x3d55('0x8')]=function(_0x42e2ce,_0x212208){return client[_0x3d55('0x8')](_0x42e2ce,{'body':_0x212208})[_0x3d55('0x9')](function(_0x286924){logger['debug'](_0x3d55('0xa'),_0x42e2ce,_0x286924?util[_0x3d55('0x5')](_0x286924,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x55e119){logger[_0x3d55('0x7')](_0x3d55('0xa'),_0x42e2ce,_0x55e119?util[_0x3d55('0x5')](_0x55e119,{'showHidden':![],'depth':null}):'');});};function getUser(_0x12d8bc){return client['request'](_0x3d55('0xb'),{'options':{'raw':!![],'attributes':['id','internal',_0x3d55('0xc'),_0x3d55('0xd')],'where':_0x12d8bc,'limit':0x1}})['then'](function(_0x5341aa){logger['debug']('[utils][getUser]\x20where:%s',JSON[_0x3d55('0xe')](_0x12d8bc),_0x5341aa?util[_0x3d55('0x5')](_0x5341aa,{'showHidden':![],'depth':null}):'');return _0x5341aa['result'][_0x3d55('0xf')]?_0x5341aa['result'][0x0]:null;});}exports['getUserByInternal']=function(_0x290c21){return new BPromise(function(_0x1c829e,_0x320f1b){if(_0x290c21){return getUser({'internal':_0x290c21})[_0x3d55('0x9')](function(_0x3e8748){logger['info'](_0x3d55('0x10'),_0x290c21,_0x3e8748?_0x3d55('0x11'):_0x3d55('0x12'));return _0x1c829e(_0x3e8748);})[_0x3d55('0x13')](function(_0x150ee4){logger['error'](_0x3d55('0x14'),_0x150ee4?util[_0x3d55('0x5')](_0x150ee4,{'showHidden':![],'depth':null}):'');return _0x1c829e(null);});}return _0x1c829e(null);});};exports[_0x3d55('0x15')]=function(_0x4eeb5b){return new BPromise(function(_0x435a0d,_0x5adb37){if(_0x4eeb5b){return getUser({'interface':_0x4eeb5b})[_0x3d55('0x9')](function(_0x539c8b){logger['info'](_0x3d55('0x16'),_0x4eeb5b,_0x539c8b?_0x3d55('0x11'):_0x3d55('0x12'));return _0x435a0d(_0x539c8b);})['catch'](function(_0x2d096f){logger[_0x3d55('0x7')]('[utils][getUserByInterface]',_0x2d096f?util[_0x3d55('0x5')](_0x2d096f,{'showHidden':![],'depth':null}):'');return _0x435a0d(null);});}return _0x435a0d(null);});};exports[_0x3d55('0x17')]=function(_0x54296b){return new BPromise(function(_0x194683,_0x36edb8){if(_0x54296b){return getUser({'name':_0x54296b})[_0x3d55('0x9')](function(_0x151322){logger[_0x3d55('0x4')](_0x3d55('0x18'),_0x54296b,_0x151322?_0x3d55('0x11'):_0x3d55('0x12'));return _0x194683(_0x151322);})[_0x3d55('0x13')](function(_0x366f02){logger['error']('[utils][getUserByName]',_0x366f02?util[_0x3d55('0x5')](_0x366f02,{'showHidden':![],'depth':null}):'');return _0x194683(null);});}return _0x194683(null);});};exports[_0x3d55('0x19')]=function(_0x12331c){return new BPromise(function(_0x54f1cd,_0x2eefb3){if(_0x12331c){return client[_0x3d55('0x8')](_0x3d55('0x1a'),{'options':{'raw':!![],'attributes':['id',_0x3d55('0xc'),_0x3d55('0x1b'),_0x3d55('0x1c'),_0x3d55('0x1d')],'where':{'name':_0x12331c},'limit':0x1}})[_0x3d55('0x9')](function(_0x583bd5){logger[_0x3d55('0x6')](_0x3d55('0x1e'),_0x12331c,_0x583bd5?util[_0x3d55('0x5')](_0x583bd5,{'showHidden':![],'depth':null}):'');logger[_0x3d55('0x4')](_0x3d55('0x1f'),_0x12331c,_0x583bd5?_0x3d55('0x11'):_0x3d55('0x12'));return _0x54f1cd(_0x583bd5[_0x3d55('0x20')]['length']?_0x583bd5[_0x3d55('0x20')][0x0]:null);})[_0x3d55('0x13')](function(_0x52b8cc){logger[_0x3d55('0x7')]('[utils][getVoiceQueueByName]',_0x52b8cc?util[_0x3d55('0x5')](_0x52b8cc,{'showHidden':![],'depth':null}):'');return _0x54f1cd(null);});}return _0x54f1cd(null);});};exports['addTime']=function(_0x566bea,_0x35f00f){return moment(_0x566bea)[_0x3d55('0x21')](_0x35f00f,_0x3d55('0x22'))['format'](_0x3d55('0x23'));};exports[_0x3d55('0x24')]=function(_0x440fc6,_0x551caf){return moment(_0x440fc6)[_0x3d55('0x25')](_0x551caf,'seconds')[_0x3d55('0x26')]('YYYY-MM-DD\x20HH:mm:ss');};exports['diffTime']=function(_0x2ddf00,_0x403d63){return moment(_0x2ddf00)[_0x3d55('0x27')](moment(_0x403d63),_0x3d55('0x22'));};exports['sumTime']=function(_0x38067e,_0x92fd8c){return parseInt(_0x38067e,0xa)+parseInt(_0x92fd8c,0xa);};exports[_0x3d55('0x28')]=function(){return moment()[_0x3d55('0x26')](_0x3d55('0x23'));};exports[_0x3d55('0x29')]=function(_0x15cf8f,_0xbd8daa){if(_0xbd8daa){return moment(_0x15cf8f)[_0x3d55('0x29')](_0xbd8daa);}return!![];};exports['isBefore']=function(_0x1bce67,_0x461698){if(_0x461698){return moment(_0x1bce67)['isBefore'](_0x461698);}else if(_0x1bce67){return!![];}return![];};