27785782946e8c5eb9081f1447ee5fd00437dd1b
[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 _0x40bd=['internal','name','interface','stringify','result','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','notfound','catch','[utils][getUserByInternal]','[utils][getUserByInterface]\x20interface:%s\x20%s','found','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','length','[utils][getVoiceQueueByName]','addTime','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diffTime','diff','seconds','now','isAfter','isBefore','bluebird','jayson/promise','client','http','../../config/logger','xdr','info','debug','inspect','error','request','then','[utils][request]\x20name:%s','GetUser'];(function(_0x178e48,_0x3c9509){var _0x440d7e=function(_0xc2f8a0){while(--_0xc2f8a0){_0x178e48['push'](_0x178e48['shift']());}};_0x440d7e(++_0x3c9509);}(_0x40bd,0x1d2));var _0xd40b=function(_0x5af4f0,_0x163be2){_0x5af4f0=_0x5af4f0-0x0;var _0x4eefac=_0x40bd[_0x5af4f0];return _0x4eefac;};'use strict';var BPromise=require(_0xd40b('0x0'));var jayson=require(_0xd40b('0x1'));var moment=require('moment');var util=require('util');var client=jayson[_0xd40b('0x2')][_0xd40b('0x3')]({'port':0x2329});var logger=require(_0xd40b('0x4'))(_0xd40b('0x5'));exports[_0xd40b('0x6')]=function(_0x386c53,_0x299d82){logger[_0xd40b('0x6')](_0x386c53,_0x299d82?util['inspect'](_0x299d82,{'showHidden':![],'depth':null}):'');};exports[_0xd40b('0x7')]=function(_0x118b34,_0x19c798){logger['debug'](_0x118b34,_0x19c798?util[_0xd40b('0x8')](_0x19c798,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x74d181,_0x5bcb1b){logger[_0xd40b('0x9')](_0x74d181,_0x5bcb1b?util['inspect'](_0x5bcb1b,{'showHidden':![],'depth':null}):'');};exports[_0xd40b('0xa')]=function(_0x10c84b,_0x2ea678){return client['request'](_0x10c84b,{'body':_0x2ea678})[_0xd40b('0xb')](function(_0x4ecc11){logger[_0xd40b('0x7')](_0xd40b('0xc'),_0x10c84b,_0x4ecc11?util[_0xd40b('0x8')](_0x4ecc11,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x37bf2e){logger[_0xd40b('0x9')](_0xd40b('0xc'),_0x10c84b,_0x37bf2e?util[_0xd40b('0x8')](_0x37bf2e,{'showHidden':![],'depth':null}):'');});};function getUser(_0x2bfa79){return client[_0xd40b('0xa')](_0xd40b('0xd'),{'options':{'raw':!![],'attributes':['id',_0xd40b('0xe'),_0xd40b('0xf'),_0xd40b('0x10')],'where':_0x2bfa79,'limit':0x1}})[_0xd40b('0xb')](function(_0x4b70bb){logger[_0xd40b('0x7')]('[utils][getUser]\x20where:%s',JSON[_0xd40b('0x11')](_0x2bfa79),_0x4b70bb?util[_0xd40b('0x8')](_0x4b70bb,{'showHidden':![],'depth':null}):'');return _0x4b70bb[_0xd40b('0x12')]['length']?_0x4b70bb['result'][0x0]:null;});}exports[_0xd40b('0x13')]=function(_0x4e20e9){return new BPromise(function(_0x2d008d,_0x4c7689){if(_0x4e20e9){return getUser({'internal':_0x4e20e9})[_0xd40b('0xb')](function(_0x48c750){logger[_0xd40b('0x6')](_0xd40b('0x14'),_0x4e20e9,_0x48c750?'found':_0xd40b('0x15'));return _0x2d008d(_0x48c750);})[_0xd40b('0x16')](function(_0x26bab7){logger[_0xd40b('0x9')](_0xd40b('0x17'),_0x26bab7?util['inspect'](_0x26bab7,{'showHidden':![],'depth':null}):'');return _0x2d008d(null);});}return _0x2d008d(null);});};exports['getUserByInterface']=function(_0x346a90){return new BPromise(function(_0x20d9b5,_0x4f7dc8){if(_0x346a90){return getUser({'interface':_0x346a90})['then'](function(_0xa08de7){logger['info'](_0xd40b('0x18'),_0x346a90,_0xa08de7?_0xd40b('0x19'):'notfound');return _0x20d9b5(_0xa08de7);})[_0xd40b('0x16')](function(_0x1b02b7){logger[_0xd40b('0x9')]('[utils][getUserByInterface]',_0x1b02b7?util[_0xd40b('0x8')](_0x1b02b7,{'showHidden':![],'depth':null}):'');return _0x20d9b5(null);});}return _0x20d9b5(null);});};exports[_0xd40b('0x1a')]=function(_0x5cba5e){return new BPromise(function(_0x28e8fb,_0x217ee1){if(_0x5cba5e){return getUser({'name':_0x5cba5e})[_0xd40b('0xb')](function(_0x2980ac){logger[_0xd40b('0x6')](_0xd40b('0x1b'),_0x5cba5e,_0x2980ac?_0xd40b('0x19'):_0xd40b('0x15'));return _0x28e8fb(_0x2980ac);})[_0xd40b('0x16')](function(_0x3f2da6){logger['error'](_0xd40b('0x1c'),_0x3f2da6?util[_0xd40b('0x8')](_0x3f2da6,{'showHidden':![],'depth':null}):'');return _0x28e8fb(null);});}return _0x28e8fb(null);});};exports[_0xd40b('0x1d')]=function(_0x25f64b){return new BPromise(function(_0x1ca3f3,_0x3dc4e3){if(_0x25f64b){return client[_0xd40b('0xa')](_0xd40b('0x1e'),{'options':{'raw':!![],'attributes':['id',_0xd40b('0xf'),_0xd40b('0x1f'),_0xd40b('0x20'),_0xd40b('0x21')],'where':{'name':_0x25f64b},'limit':0x1}})['then'](function(_0x2bbd1c){logger['debug'](_0xd40b('0x22'),_0x25f64b,_0x2bbd1c?util[_0xd40b('0x8')](_0x2bbd1c,{'showHidden':![],'depth':null}):'');logger[_0xd40b('0x6')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0x25f64b,_0x2bbd1c?'found':_0xd40b('0x15'));return _0x1ca3f3(_0x2bbd1c[_0xd40b('0x12')][_0xd40b('0x23')]?_0x2bbd1c[_0xd40b('0x12')][0x0]:null);})[_0xd40b('0x16')](function(_0x13f738){logger[_0xd40b('0x9')](_0xd40b('0x24'),_0x13f738?util[_0xd40b('0x8')](_0x13f738,{'showHidden':![],'depth':null}):'');return _0x1ca3f3(null);});}return _0x1ca3f3(null);});};exports[_0xd40b('0x25')]=function(_0xf5f6a9,_0x3e3f76){return moment(_0xf5f6a9)['add'](_0x3e3f76,'seconds')[_0xd40b('0x26')](_0xd40b('0x27'));};exports[_0xd40b('0x28')]=function(_0x3b27a9,_0x4aa501){return moment(_0x3b27a9)[_0xd40b('0x29')](_0x4aa501,'seconds')[_0xd40b('0x26')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xd40b('0x2a')]=function(_0x1c2b40,_0x67c2d3){return moment(_0x1c2b40)[_0xd40b('0x2b')](moment(_0x67c2d3),_0xd40b('0x2c'));};exports['sumTime']=function(_0x2cecdd,_0x34422e){return parseInt(_0x2cecdd,0xa)+parseInt(_0x34422e,0xa);};exports[_0xd40b('0x2d')]=function(){return moment()['format'](_0xd40b('0x27'));};exports['isAfter']=function(_0x74f4ba,_0x2ef4a7){if(_0x2ef4a7){return moment(_0x74f4ba)[_0xd40b('0x2e')](_0x2ef4a7);}return!![];};exports[_0xd40b('0x2f')]=function(_0x58dc51,_0x53e10b){if(_0x53e10b){return moment(_0x58dc51)['isBefore'](_0x53e10b);}else if(_0x58dc51){return!![];}return![];};