Built motion from commit ffdca78c.|2.6.24
[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 _0xb05b=['stringify','result','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','[utils][getUserByInterface]','[utils][getUserByName]\x20name:%s\x20%s','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','length','addTime','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diffTime','diff','sumTime','now','isAfter','isBefore','bluebird','moment','http','../../config/logger','xdr','info','inspect','debug','error','request','then','[utils][request]\x20name:%s','catch','name','interface','[utils][getUser]\x20where:%s'];(function(_0x4360c4,_0x2f8209){var _0x3168c8=function(_0x309523){while(--_0x309523){_0x4360c4['push'](_0x4360c4['shift']());}};_0x3168c8(++_0x2f8209);}(_0xb05b,0xd1));var _0xbb05=function(_0x38576d,_0x527dc7){_0x38576d=_0x38576d-0x0;var _0x32534a=_0xb05b[_0x38576d];return _0x32534a;};'use strict';var BPromise=require(_0xbb05('0x0'));var jayson=require('jayson/promise');var moment=require(_0xbb05('0x1'));var util=require('util');var client=jayson['client'][_0xbb05('0x2')]({'port':0x2329});var logger=require(_0xbb05('0x3'))(_0xbb05('0x4'));exports['info']=function(_0x92f705,_0x29beea){logger[_0xbb05('0x5')](_0x92f705,_0x29beea?util[_0xbb05('0x6')](_0x29beea,{'showHidden':![],'depth':null}):'');};exports[_0xbb05('0x7')]=function(_0xf4d8e7,_0x51d2b7){logger[_0xbb05('0x7')](_0xf4d8e7,_0x51d2b7?util[_0xbb05('0x6')](_0x51d2b7,{'showHidden':![],'depth':null}):'');};exports[_0xbb05('0x8')]=function(_0x1d3c66,_0x25a16a){logger['error'](_0x1d3c66,_0x25a16a?util[_0xbb05('0x6')](_0x25a16a,{'showHidden':![],'depth':null}):'');};exports[_0xbb05('0x9')]=function(_0x34af12,_0x1856a8){return client['request'](_0x34af12,{'body':_0x1856a8})[_0xbb05('0xa')](function(_0x2c7557){logger[_0xbb05('0x7')](_0xbb05('0xb'),_0x34af12,_0x2c7557?util[_0xbb05('0x6')](_0x2c7557,{'showHidden':![],'depth':null}):'');})[_0xbb05('0xc')](function(_0x4ded7a){logger[_0xbb05('0x8')](_0xbb05('0xb'),_0x34af12,_0x4ded7a?util[_0xbb05('0x6')](_0x4ded7a,{'showHidden':![],'depth':null}):'');});};function getUser(_0x34599b){return client['request']('GetUser',{'options':{'raw':!![],'attributes':['id','internal',_0xbb05('0xd'),_0xbb05('0xe')],'where':_0x34599b,'limit':0x1}})['then'](function(_0x364374){logger[_0xbb05('0x7')](_0xbb05('0xf'),JSON[_0xbb05('0x10')](_0x34599b),_0x364374?util['inspect'](_0x364374,{'showHidden':![],'depth':null}):'');return _0x364374[_0xbb05('0x11')]['length']?_0x364374['result'][0x0]:null;});}exports[_0xbb05('0x12')]=function(_0x1aeb45){return new BPromise(function(_0x42c09d,_0x4f471f){if(_0x1aeb45){return getUser({'internal':_0x1aeb45})[_0xbb05('0xa')](function(_0x1c41ba){logger['info'](_0xbb05('0x13'),_0x1aeb45,_0x1c41ba?_0xbb05('0x14'):_0xbb05('0x15'));return _0x42c09d(_0x1c41ba);})[_0xbb05('0xc')](function(_0x3ec838){logger[_0xbb05('0x8')](_0xbb05('0x16'),_0x3ec838?util[_0xbb05('0x6')](_0x3ec838,{'showHidden':![],'depth':null}):'');return _0x42c09d(null);});}return _0x42c09d(null);});};exports[_0xbb05('0x17')]=function(_0x589a31){return new BPromise(function(_0x3f7006,_0x30f80f){if(_0x589a31){return getUser({'interface':_0x589a31})[_0xbb05('0xa')](function(_0x244d24){logger[_0xbb05('0x5')](_0xbb05('0x18'),_0x589a31,_0x244d24?_0xbb05('0x14'):_0xbb05('0x15'));return _0x3f7006(_0x244d24);})['catch'](function(_0x3cf56d){logger['error'](_0xbb05('0x19'),_0x3cf56d?util['inspect'](_0x3cf56d,{'showHidden':![],'depth':null}):'');return _0x3f7006(null);});}return _0x3f7006(null);});};exports['getUserByName']=function(_0x4d4e22){return new BPromise(function(_0x5385d3,_0x9ad76c){if(_0x4d4e22){return getUser({'name':_0x4d4e22})[_0xbb05('0xa')](function(_0x311b14){logger[_0xbb05('0x5')](_0xbb05('0x1a'),_0x4d4e22,_0x311b14?_0xbb05('0x14'):_0xbb05('0x15'));return _0x5385d3(_0x311b14);})['catch'](function(_0x414707){logger[_0xbb05('0x8')]('[utils][getUserByName]',_0x414707?util[_0xbb05('0x6')](_0x414707,{'showHidden':![],'depth':null}):'');return _0x5385d3(null);});}return _0x5385d3(null);});};exports['getVoiceQueueByName']=function(_0x3387f6){return new BPromise(function(_0x4b2a03,_0x26ceb6){if(_0x3387f6){return client['request'](_0xbb05('0x1b'),{'options':{'raw':!![],'attributes':['id',_0xbb05('0xd'),_0xbb05('0x1c'),_0xbb05('0x1d'),_0xbb05('0x1e')],'where':{'name':_0x3387f6},'limit':0x1}})[_0xbb05('0xa')](function(_0x17ec86){logger[_0xbb05('0x7')](_0xbb05('0x1f'),_0x3387f6,_0x17ec86?util[_0xbb05('0x6')](_0x17ec86,{'showHidden':![],'depth':null}):'');logger['info']('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0x3387f6,_0x17ec86?_0xbb05('0x14'):'notfound');return _0x4b2a03(_0x17ec86[_0xbb05('0x11')][_0xbb05('0x20')]?_0x17ec86['result'][0x0]:null);})['catch'](function(_0x41791d){logger[_0xbb05('0x8')]('[utils][getVoiceQueueByName]',_0x41791d?util[_0xbb05('0x6')](_0x41791d,{'showHidden':![],'depth':null}):'');return _0x4b2a03(null);});}return _0x4b2a03(null);});};exports[_0xbb05('0x21')]=function(_0x25e023,_0x9d4bd){return moment(_0x25e023)['add'](_0x9d4bd,_0xbb05('0x22'))[_0xbb05('0x23')](_0xbb05('0x24'));};exports[_0xbb05('0x25')]=function(_0x27f0f8,_0x5dd1fd){return moment(_0x27f0f8)[_0xbb05('0x26')](_0x5dd1fd,_0xbb05('0x22'))['format']('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xbb05('0x27')]=function(_0x16ea4d,_0x5f2ffc){return moment(_0x16ea4d)[_0xbb05('0x28')](moment(_0x5f2ffc),_0xbb05('0x22'));};exports[_0xbb05('0x29')]=function(_0x168b42,_0x436ee6){return parseInt(_0x168b42,0xa)+parseInt(_0x436ee6,0xa);};exports[_0xbb05('0x2a')]=function(){return moment()[_0xbb05('0x23')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xbb05('0x2b')]=function(_0x116578,_0x42381f){if(_0x42381f){return moment(_0x116578)[_0xbb05('0x2b')](_0x42381f);}return!![];};exports[_0xbb05('0x2c')]=function(_0x4038ec,_0x2a9de3){if(_0x2a9de3){return moment(_0x4038ec)[_0xbb05('0x2c')](_0x2a9de3);}else if(_0x4038ec){return!![];}return![];};