3924485b6d909460c8b120a0c0ece35d1dfae5db
[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 _0xc6df=['subtract','seconds','diffTime','diff','sumTime','now','isAfter','moment','util','../../config/logger','xdr','info','inspect','debug','error','request','then','[utils][request]\x20name:%s','catch','GetUser','internal','name','interface','[utils][getUser]\x20where:%s','stringify','result','length','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','[utils][getUserByName]\x20name:%s\x20%s','getVoiceQueueByName','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s\x20%s','[utils][getVoiceQueueByName]','addTime','add','format','YYYY-MM-DD\x20HH:mm:ss'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xc6df,0x115));var _0xfc6d=function(_0x34af2c,_0x3be462){_0x34af2c=_0x34af2c-0x0;var _0x1bb889=_0xc6df[_0x34af2c];return _0x1bb889;};'use strict';var BPromise=require('bluebird');var jayson=require('jayson/promise');var moment=require(_0xfc6d('0x0'));var util=require(_0xfc6d('0x1'));var client=jayson['client']['http']({'port':0x2329});var logger=require(_0xfc6d('0x2'))(_0xfc6d('0x3'));exports[_0xfc6d('0x4')]=function(_0x1e23a6,_0x3f5725){logger[_0xfc6d('0x4')](_0x1e23a6,_0x3f5725?util[_0xfc6d('0x5')](_0x3f5725,{'showHidden':![],'depth':null}):'');};exports[_0xfc6d('0x6')]=function(_0x4c9ead,_0x33714f){logger[_0xfc6d('0x6')](_0x4c9ead,_0x33714f?util[_0xfc6d('0x5')](_0x33714f,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x51ccc3,_0x40b7d8){logger[_0xfc6d('0x7')](_0x51ccc3,_0x40b7d8?util['inspect'](_0x40b7d8,{'showHidden':![],'depth':null}):'');};exports[_0xfc6d('0x8')]=function(_0x4fdff8,_0x43904f){return client['request'](_0x4fdff8,{'body':_0x43904f})[_0xfc6d('0x9')](function(_0x33e307){logger[_0xfc6d('0x6')](_0xfc6d('0xa'),_0x4fdff8,_0x33e307?util[_0xfc6d('0x5')](_0x33e307,{'showHidden':![],'depth':null}):'');})[_0xfc6d('0xb')](function(_0x551be5){logger[_0xfc6d('0x7')](_0xfc6d('0xa'),_0x4fdff8,_0x551be5?util[_0xfc6d('0x5')](_0x551be5,{'showHidden':![],'depth':null}):'');});};function getUser(_0x5b65f5){return client['request'](_0xfc6d('0xc'),{'options':{'raw':!![],'attributes':['id',_0xfc6d('0xd'),_0xfc6d('0xe'),_0xfc6d('0xf')],'where':_0x5b65f5,'limit':0x1}})[_0xfc6d('0x9')](function(_0x3372ef){logger[_0xfc6d('0x6')](_0xfc6d('0x10'),JSON[_0xfc6d('0x11')](_0x5b65f5),_0x3372ef?util[_0xfc6d('0x5')](_0x3372ef,{'showHidden':![],'depth':null}):'');return _0x3372ef[_0xfc6d('0x12')][_0xfc6d('0x13')]?_0x3372ef[_0xfc6d('0x12')][0x0]:null;});}exports[_0xfc6d('0x14')]=function(_0x148fe9){return new BPromise(function(_0x56cc8f,_0x8b8ceb){if(_0x148fe9){return getUser({'internal':_0x148fe9})['then'](function(_0x1f702a){logger[_0xfc6d('0x4')](_0xfc6d('0x15'),_0x148fe9,_0x1f702a?_0xfc6d('0x16'):_0xfc6d('0x17'));return _0x56cc8f(_0x1f702a);})[_0xfc6d('0xb')](function(_0x5dff37){logger[_0xfc6d('0x7')](_0xfc6d('0x18'),_0x5dff37?util['inspect'](_0x5dff37,{'showHidden':![],'depth':null}):'');return _0x56cc8f(null);});}return _0x56cc8f(null);});};exports[_0xfc6d('0x19')]=function(_0x56f774){return new BPromise(function(_0x7abeb4,_0x7204d9){if(_0x56f774){return getUser({'interface':_0x56f774})[_0xfc6d('0x9')](function(_0x4b0792){logger[_0xfc6d('0x4')](_0xfc6d('0x1a'),_0x56f774,_0x4b0792?_0xfc6d('0x16'):_0xfc6d('0x17'));return _0x7abeb4(_0x4b0792);})[_0xfc6d('0xb')](function(_0x105b2e){logger[_0xfc6d('0x7')]('[utils][getUserByInterface]',_0x105b2e?util[_0xfc6d('0x5')](_0x105b2e,{'showHidden':![],'depth':null}):'');return _0x7abeb4(null);});}return _0x7abeb4(null);});};exports['getUserByName']=function(_0x3ea395){return new BPromise(function(_0x494bd9,_0x31fa6f){if(_0x3ea395){return getUser({'name':_0x3ea395})[_0xfc6d('0x9')](function(_0x1196fb){logger[_0xfc6d('0x4')](_0xfc6d('0x1b'),_0x3ea395,_0x1196fb?'found':_0xfc6d('0x17'));return _0x494bd9(_0x1196fb);})[_0xfc6d('0xb')](function(_0x2c2486){logger['error']('[utils][getUserByName]',_0x2c2486?util[_0xfc6d('0x5')](_0x2c2486,{'showHidden':![],'depth':null}):'');return _0x494bd9(null);});}return _0x494bd9(null);});};exports[_0xfc6d('0x1c')]=function(_0x466a1a){return new BPromise(function(_0x17b976,_0x26cda6){if(_0x466a1a){return client[_0xfc6d('0x8')]('GetVoiceQueue',{'options':{'raw':!![],'attributes':['id',_0xfc6d('0xe'),_0xfc6d('0x1d'),_0xfc6d('0x1e'),_0xfc6d('0x1f')],'where':{'name':_0x466a1a},'limit':0x1}})[_0xfc6d('0x9')](function(_0x47c574){logger[_0xfc6d('0x6')]('[utils][getVoiceQueueByName]\x20name:%s',_0x466a1a,_0x47c574?util['inspect'](_0x47c574,{'showHidden':![],'depth':null}):'');logger['info'](_0xfc6d('0x20'),_0x466a1a,_0x47c574?_0xfc6d('0x16'):_0xfc6d('0x17'));return _0x17b976(_0x47c574[_0xfc6d('0x12')]['length']?_0x47c574[_0xfc6d('0x12')][0x0]:null);})[_0xfc6d('0xb')](function(_0x32bc60){logger['error'](_0xfc6d('0x21'),_0x32bc60?util['inspect'](_0x32bc60,{'showHidden':![],'depth':null}):'');return _0x17b976(null);});}return _0x17b976(null);});};exports[_0xfc6d('0x22')]=function(_0x3e1ce3,_0x25f29e){return moment(_0x3e1ce3)[_0xfc6d('0x23')](_0x25f29e,'seconds')[_0xfc6d('0x24')](_0xfc6d('0x25'));};exports['subtractTime']=function(_0xb4e3b5,_0x442efc){return moment(_0xb4e3b5)[_0xfc6d('0x26')](_0x442efc,_0xfc6d('0x27'))[_0xfc6d('0x24')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xfc6d('0x28')]=function(_0x45a8e0,_0x418bdc){return moment(_0x45a8e0)[_0xfc6d('0x29')](moment(_0x418bdc),_0xfc6d('0x27'));};exports[_0xfc6d('0x2a')]=function(_0x551745,_0x4238da){return parseInt(_0x551745,0xa)+parseInt(_0x4238da,0xa);};exports[_0xfc6d('0x2b')]=function(){return moment()[_0xfc6d('0x24')](_0xfc6d('0x25'));};exports[_0xfc6d('0x2c')]=function(_0x40c666,_0x2b7912){if(_0x2b7912){return moment(_0x40c666)[_0xfc6d('0x2c')](_0x2b7912);}return!![];};exports['isBefore']=function(_0x430a67,_0x3e83e3){if(_0x3e83e3){return moment(_0x430a67)['isBefore'](_0x3e83e3);}else if(_0x430a67){return!![];}return![];};