4af8467051725f0ffcf6b1d63346824d78f84b92
[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 _0x6c20=['client','xdr','info','inspect','debug','error','request','then','[utils][request]\x20name:%s','catch','GetUser','name','interface','[utils][getUser]\x20where:%s','stringify','result','notfound','[utils][getUserByInternal]','getUserByInterface','found','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s\x20%s','length','[utils][getVoiceQueueByName]','add','seconds','format','subtractTime','subtract','YYYY-MM-DD\x20HH:mm:ss','diffTime','diff','sumTime','now','isAfter','isBefore','bluebird','jayson/promise'];(function(_0x4b4154,_0x38a122){var _0x340ed7=function(_0x1250b9){while(--_0x1250b9){_0x4b4154['push'](_0x4b4154['shift']());}};_0x340ed7(++_0x38a122);}(_0x6c20,0x88));var _0x06c2=function(_0xced98a,_0x5cb79a){_0xced98a=_0xced98a-0x0;var _0x2055db=_0x6c20[_0xced98a];return _0x2055db;};'use strict';var BPromise=require(_0x06c2('0x0'));var jayson=require(_0x06c2('0x1'));var moment=require('moment');var util=require('util');var client=jayson[_0x06c2('0x2')]['http']({'port':0x2329});var logger=require('../../config/logger')(_0x06c2('0x3'));exports[_0x06c2('0x4')]=function(_0x169412,_0x2c7843){logger[_0x06c2('0x4')](_0x169412,_0x2c7843?util[_0x06c2('0x5')](_0x2c7843,{'showHidden':![],'depth':null}):'');};exports[_0x06c2('0x6')]=function(_0xb513a1,_0x164b3a){logger['debug'](_0xb513a1,_0x164b3a?util[_0x06c2('0x5')](_0x164b3a,{'showHidden':![],'depth':null}):'');};exports[_0x06c2('0x7')]=function(_0x4286d5,_0x5512e0){logger['error'](_0x4286d5,_0x5512e0?util['inspect'](_0x5512e0,{'showHidden':![],'depth':null}):'');};exports[_0x06c2('0x8')]=function(_0x2993fd,_0x740542){return client[_0x06c2('0x8')](_0x2993fd,{'body':_0x740542})[_0x06c2('0x9')](function(_0x15fde6){logger[_0x06c2('0x6')](_0x06c2('0xa'),_0x2993fd,_0x15fde6?util[_0x06c2('0x5')](_0x15fde6,{'showHidden':![],'depth':null}):'');})[_0x06c2('0xb')](function(_0x49e385){logger[_0x06c2('0x7')](_0x06c2('0xa'),_0x2993fd,_0x49e385?util[_0x06c2('0x5')](_0x49e385,{'showHidden':![],'depth':null}):'');});};function getUser(_0x17b7c3){return client['request'](_0x06c2('0xc'),{'options':{'raw':!![],'attributes':['id','internal',_0x06c2('0xd'),_0x06c2('0xe')],'where':_0x17b7c3,'limit':0x1}})[_0x06c2('0x9')](function(_0x3ca58e){logger['debug'](_0x06c2('0xf'),JSON[_0x06c2('0x10')](_0x17b7c3),_0x3ca58e?util[_0x06c2('0x5')](_0x3ca58e,{'showHidden':![],'depth':null}):'');return _0x3ca58e[_0x06c2('0x11')]['length']?_0x3ca58e['result'][0x0]:null;});}exports['getUserByInternal']=function(_0x4bf48d){return new BPromise(function(_0x5649d2,_0x4bcba7){if(_0x4bf48d){return getUser({'internal':_0x4bf48d})[_0x06c2('0x9')](function(_0x303497){logger['info']('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x4bf48d,_0x303497?'found':_0x06c2('0x12'));return _0x5649d2(_0x303497);})[_0x06c2('0xb')](function(_0x26ad55){logger[_0x06c2('0x7')](_0x06c2('0x13'),_0x26ad55?util[_0x06c2('0x5')](_0x26ad55,{'showHidden':![],'depth':null}):'');return _0x5649d2(null);});}return _0x5649d2(null);});};exports[_0x06c2('0x14')]=function(_0x5440ea){return new BPromise(function(_0x42cfd2,_0x1e6a10){if(_0x5440ea){return getUser({'interface':_0x5440ea})[_0x06c2('0x9')](function(_0x3a3056){logger['info']('[utils][getUserByInterface]\x20interface:%s\x20%s',_0x5440ea,_0x3a3056?_0x06c2('0x15'):'notfound');return _0x42cfd2(_0x3a3056);})[_0x06c2('0xb')](function(_0x3026ae){logger[_0x06c2('0x7')](_0x06c2('0x16'),_0x3026ae?util['inspect'](_0x3026ae,{'showHidden':![],'depth':null}):'');return _0x42cfd2(null);});}return _0x42cfd2(null);});};exports[_0x06c2('0x17')]=function(_0x395b2e){return new BPromise(function(_0x128e64,_0xb56c17){if(_0x395b2e){return getUser({'name':_0x395b2e})[_0x06c2('0x9')](function(_0x30bece){logger[_0x06c2('0x4')](_0x06c2('0x18'),_0x395b2e,_0x30bece?_0x06c2('0x15'):_0x06c2('0x12'));return _0x128e64(_0x30bece);})[_0x06c2('0xb')](function(_0x4c12ca){logger[_0x06c2('0x7')](_0x06c2('0x19'),_0x4c12ca?util[_0x06c2('0x5')](_0x4c12ca,{'showHidden':![],'depth':null}):'');return _0x128e64(null);});}return _0x128e64(null);});};exports[_0x06c2('0x1a')]=function(_0xe2b961){return new BPromise(function(_0x2c6a15,_0x4330f0){if(_0xe2b961){return client['request'](_0x06c2('0x1b'),{'options':{'raw':!![],'attributes':['id',_0x06c2('0xd'),_0x06c2('0x1c'),_0x06c2('0x1d'),_0x06c2('0x1e')],'where':{'name':_0xe2b961},'limit':0x1}})['then'](function(_0x3e4d7f){logger[_0x06c2('0x6')]('[utils][getVoiceQueueByName]\x20name:%s',_0xe2b961,_0x3e4d7f?util[_0x06c2('0x5')](_0x3e4d7f,{'showHidden':![],'depth':null}):'');logger['info'](_0x06c2('0x1f'),_0xe2b961,_0x3e4d7f?_0x06c2('0x15'):_0x06c2('0x12'));return _0x2c6a15(_0x3e4d7f['result'][_0x06c2('0x20')]?_0x3e4d7f[_0x06c2('0x11')][0x0]:null);})[_0x06c2('0xb')](function(_0x5be2cd){logger[_0x06c2('0x7')](_0x06c2('0x21'),_0x5be2cd?util['inspect'](_0x5be2cd,{'showHidden':![],'depth':null}):'');return _0x2c6a15(null);});}return _0x2c6a15(null);});};exports['addTime']=function(_0x286ba4,_0x4cc4d3){return moment(_0x286ba4)[_0x06c2('0x22')](_0x4cc4d3,_0x06c2('0x23'))[_0x06c2('0x24')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x06c2('0x25')]=function(_0x31a790,_0x1fcba8){return moment(_0x31a790)[_0x06c2('0x26')](_0x1fcba8,_0x06c2('0x23'))['format'](_0x06c2('0x27'));};exports[_0x06c2('0x28')]=function(_0x1c933d,_0x1cd245){return moment(_0x1c933d)[_0x06c2('0x29')](moment(_0x1cd245),_0x06c2('0x23'));};exports[_0x06c2('0x2a')]=function(_0x1ad475,_0x1fe07a){return parseInt(_0x1ad475,0xa)+parseInt(_0x1fe07a,0xa);};exports[_0x06c2('0x2b')]=function(){return moment()['format'](_0x06c2('0x27'));};exports[_0x06c2('0x2c')]=function(_0x1e053f,_0x1a6ba7){if(_0x1a6ba7){return moment(_0x1e053f)[_0x06c2('0x2c')](_0x1a6ba7);}return!![];};exports[_0x06c2('0x2d')]=function(_0x507e63,_0x552982){if(_0x552982){return moment(_0x507e63)['isBefore'](_0x552982);}else if(_0x507e63){return!![];}return![];};