Built motion from commit 9d0783e6.|2.6.13
[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 _0x6b52=['request','then','[utils][request]\x20name:%s','internal','name','interface','[utils][getUser]\x20where:%s','result','length','getUserByInternal','found','[utils][getUserByInterface]\x20interface:%s\x20%s','notfound','catch','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','type','acw','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','add','seconds','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','format','diffTime','diff','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','moment','util','client','http','../../config/logger','xdr','info','inspect','debug','error'];(function(_0x41b147,_0x52afc9){var _0x5b8d0e=function(_0x2e620d){while(--_0x2e620d){_0x41b147['push'](_0x41b147['shift']());}};_0x5b8d0e(++_0x52afc9);}(_0x6b52,0xdf));var _0x26b5=function(_0x50357d,_0x55b4eb){_0x50357d=_0x50357d-0x0;var _0x12b140=_0x6b52[_0x50357d];return _0x12b140;};'use strict';var BPromise=require(_0x26b5('0x0'));var jayson=require(_0x26b5('0x1'));var moment=require(_0x26b5('0x2'));var util=require(_0x26b5('0x3'));var client=jayson[_0x26b5('0x4')][_0x26b5('0x5')]({'port':0x2329});var logger=require(_0x26b5('0x6'))(_0x26b5('0x7'));exports[_0x26b5('0x8')]=function(_0x1a284c,_0x4bd37b){logger[_0x26b5('0x8')](_0x1a284c,_0x4bd37b?util[_0x26b5('0x9')](_0x4bd37b,{'showHidden':![],'depth':null}):'');};exports[_0x26b5('0xa')]=function(_0x20a9a4,_0x50d289){logger[_0x26b5('0xa')](_0x20a9a4,_0x50d289?util[_0x26b5('0x9')](_0x50d289,{'showHidden':![],'depth':null}):'');};exports[_0x26b5('0xb')]=function(_0x4975a4,_0x343da4){logger[_0x26b5('0xb')](_0x4975a4,_0x343da4?util[_0x26b5('0x9')](_0x343da4,{'showHidden':![],'depth':null}):'');};exports[_0x26b5('0xc')]=function(_0xc1e020,_0x119e9f){return client[_0x26b5('0xc')](_0xc1e020,{'body':_0x119e9f})[_0x26b5('0xd')](function(_0x448692){logger[_0x26b5('0xa')](_0x26b5('0xe'),_0xc1e020,_0x448692?util[_0x26b5('0x9')](_0x448692,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x172e0f){logger['error'](_0x26b5('0xe'),_0xc1e020,_0x172e0f?util[_0x26b5('0x9')](_0x172e0f,{'showHidden':![],'depth':null}):'');});};function getUser(_0x51cc26){return client[_0x26b5('0xc')]('GetUser',{'options':{'raw':!![],'attributes':['id',_0x26b5('0xf'),_0x26b5('0x10'),_0x26b5('0x11')],'where':_0x51cc26,'limit':0x1}})[_0x26b5('0xd')](function(_0x42b21d){logger[_0x26b5('0xa')](_0x26b5('0x12'),JSON['stringify'](_0x51cc26),_0x42b21d?util[_0x26b5('0x9')](_0x42b21d,{'showHidden':![],'depth':null}):'');return _0x42b21d[_0x26b5('0x13')][_0x26b5('0x14')]?_0x42b21d[_0x26b5('0x13')][0x0]:null;});}exports[_0x26b5('0x15')]=function(_0x316e56){return new BPromise(function(_0x143e24,_0x3872b6){if(_0x316e56){return getUser({'internal':_0x316e56})[_0x26b5('0xd')](function(_0x2ae701){logger[_0x26b5('0x8')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x316e56,_0x2ae701?_0x26b5('0x16'):'notfound');return _0x143e24(_0x2ae701);})['catch'](function(_0x52668a){logger[_0x26b5('0xb')]('[utils][getUserByInternal]',_0x52668a?util[_0x26b5('0x9')](_0x52668a,{'showHidden':![],'depth':null}):'');return _0x143e24(null);});}return _0x143e24(null);});};exports['getUserByInterface']=function(_0x38eb85){return new BPromise(function(_0x170e56,_0x17b554){if(_0x38eb85){return getUser({'interface':_0x38eb85})[_0x26b5('0xd')](function(_0x3f6cd0){logger['info'](_0x26b5('0x17'),_0x38eb85,_0x3f6cd0?'found':_0x26b5('0x18'));return _0x170e56(_0x3f6cd0);})[_0x26b5('0x19')](function(_0x325f92){logger[_0x26b5('0xb')](_0x26b5('0x1a'),_0x325f92?util[_0x26b5('0x9')](_0x325f92,{'showHidden':![],'depth':null}):'');return _0x170e56(null);});}return _0x170e56(null);});};exports[_0x26b5('0x1b')]=function(_0xd1ac83){return new BPromise(function(_0x33cdef,_0x5a046f){if(_0xd1ac83){return getUser({'name':_0xd1ac83})[_0x26b5('0xd')](function(_0x1856e2){logger[_0x26b5('0x8')]('[utils][getUserByName]\x20name:%s\x20%s',_0xd1ac83,_0x1856e2?'found':_0x26b5('0x18'));return _0x33cdef(_0x1856e2);})['catch'](function(_0x3c6e7d){logger['error'](_0x26b5('0x1c'),_0x3c6e7d?util[_0x26b5('0x9')](_0x3c6e7d,{'showHidden':![],'depth':null}):'');return _0x33cdef(null);});}return _0x33cdef(null);});};exports[_0x26b5('0x1d')]=function(_0x44ba86){return new BPromise(function(_0x29374d,_0x307514){if(_0x44ba86){return client['request'](_0x26b5('0x1e'),{'options':{'raw':!![],'attributes':['id',_0x26b5('0x10'),_0x26b5('0x1f'),_0x26b5('0x20'),'acwTimeout'],'where':{'name':_0x44ba86},'limit':0x1}})[_0x26b5('0xd')](function(_0x5ba185){logger[_0x26b5('0xa')](_0x26b5('0x21'),_0x44ba86,_0x5ba185?util[_0x26b5('0x9')](_0x5ba185,{'showHidden':![],'depth':null}):'');logger[_0x26b5('0x8')](_0x26b5('0x22'),_0x44ba86,_0x5ba185?'found':_0x26b5('0x18'));return _0x29374d(_0x5ba185[_0x26b5('0x13')][_0x26b5('0x14')]?_0x5ba185['result'][0x0]:null);})[_0x26b5('0x19')](function(_0x452a86){logger[_0x26b5('0xb')]('[utils][getVoiceQueueByName]',_0x452a86?util[_0x26b5('0x9')](_0x452a86,{'showHidden':![],'depth':null}):'');return _0x29374d(null);});}return _0x29374d(null);});};exports['addTime']=function(_0x53e6ac,_0x486c1a){return moment(_0x53e6ac)[_0x26b5('0x23')](_0x486c1a,_0x26b5('0x24'))['format'](_0x26b5('0x25'));};exports[_0x26b5('0x26')]=function(_0x40986f,_0x2d923d){return moment(_0x40986f)[_0x26b5('0x27')](_0x2d923d,_0x26b5('0x24'))[_0x26b5('0x28')](_0x26b5('0x25'));};exports[_0x26b5('0x29')]=function(_0x38460a,_0x3fea73){return moment(_0x38460a)[_0x26b5('0x2a')](moment(_0x3fea73),_0x26b5('0x24'));};exports[_0x26b5('0x2b')]=function(_0x48a14d,_0x49f377){return parseInt(_0x48a14d,0xa)+parseInt(_0x49f377,0xa);};exports[_0x26b5('0x2c')]=function(){return moment()['format'](_0x26b5('0x25'));};exports[_0x26b5('0x2d')]=function(_0x118429,_0x42ab6d){if(_0x42ab6d){return moment(_0x118429)[_0x26b5('0x2d')](_0x42ab6d);}return!![];};exports[_0x26b5('0x2e')]=function(_0x56b664,_0x2fac9a){if(_0x2fac9a){return moment(_0x56b664)[_0x26b5('0x2e')](_0x2fac9a);}else if(_0x56b664){return!![];}return![];};