Built motion from commit 85328c08.|2.5.50
[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 _0x43a5=['add','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','seconds','diffTime','diff','now','isAfter','isBefore','jayson/promise','moment','../../config/logger','info','inspect','debug','then','[utils][request]\x20name:%s','catch','GetUser','internal','name','interface','stringify','result','getUserByInternal','found','notfound','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','error','[utils][getUserByInterface]','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','request','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','length','addTime'];(function(_0x257599,_0x4b624c){var _0x41b318=function(_0x571729){while(--_0x571729){_0x257599['push'](_0x257599['shift']());}};_0x41b318(++_0x4b624c);}(_0x43a5,0x196));var _0x543a=function(_0x122ef9,_0x451d2a){_0x122ef9=_0x122ef9-0x0;var _0x42fba0=_0x43a5[_0x122ef9];return _0x42fba0;};'use strict';var BPromise=require('bluebird');var jayson=require(_0x543a('0x0'));var moment=require(_0x543a('0x1'));var util=require('util');var client=jayson['client']['http']({'port':0x2329});var logger=require(_0x543a('0x2'))('xdr');exports[_0x543a('0x3')]=function(_0x2b33ef,_0x405143){logger[_0x543a('0x3')](_0x2b33ef,_0x405143?util[_0x543a('0x4')](_0x405143,{'showHidden':![],'depth':null}):'');};exports['debug']=function(_0x22b510,_0x3cdafb){logger[_0x543a('0x5')](_0x22b510,_0x3cdafb?util['inspect'](_0x3cdafb,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x5ca969,_0x3f82c4){logger['error'](_0x5ca969,_0x3f82c4?util['inspect'](_0x3f82c4,{'showHidden':![],'depth':null}):'');};exports['request']=function(_0xada5c5,_0x310d1d){return client['request'](_0xada5c5,{'body':_0x310d1d})[_0x543a('0x6')](function(_0x1c7daa){logger[_0x543a('0x5')](_0x543a('0x7'),_0xada5c5,_0x1c7daa?util[_0x543a('0x4')](_0x1c7daa,{'showHidden':![],'depth':null}):'');})[_0x543a('0x8')](function(_0x3d60d7){logger['error'](_0x543a('0x7'),_0xada5c5,_0x3d60d7?util['inspect'](_0x3d60d7,{'showHidden':![],'depth':null}):'');});};function getUser(_0x32f390){return client['request'](_0x543a('0x9'),{'options':{'raw':!![],'attributes':['id',_0x543a('0xa'),_0x543a('0xb'),_0x543a('0xc')],'where':_0x32f390,'limit':0x1}})[_0x543a('0x6')](function(_0x3d8fce){logger[_0x543a('0x5')]('[utils][getUser]\x20where:%s',JSON[_0x543a('0xd')](_0x32f390),_0x3d8fce?util[_0x543a('0x4')](_0x3d8fce,{'showHidden':![],'depth':null}):'');return _0x3d8fce[_0x543a('0xe')]['length']?_0x3d8fce[_0x543a('0xe')][0x0]:null;});}exports[_0x543a('0xf')]=function(_0x38f35d){return new BPromise(function(_0x564eed,_0x558690){if(_0x38f35d){return getUser({'internal':_0x38f35d})[_0x543a('0x6')](function(_0x52e914){logger[_0x543a('0x3')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x38f35d,_0x52e914?_0x543a('0x10'):_0x543a('0x11'));return _0x564eed(_0x52e914);})[_0x543a('0x8')](function(_0x3c50b7){logger['error'](_0x543a('0x12'),_0x3c50b7?util['inspect'](_0x3c50b7,{'showHidden':![],'depth':null}):'');return _0x564eed(null);});}return _0x564eed(null);});};exports[_0x543a('0x13')]=function(_0x52e38c){return new BPromise(function(_0x23f2dd,_0x39a4c4){if(_0x52e38c){return getUser({'interface':_0x52e38c})[_0x543a('0x6')](function(_0x550112){logger[_0x543a('0x3')](_0x543a('0x14'),_0x52e38c,_0x550112?'found':'notfound');return _0x23f2dd(_0x550112);})[_0x543a('0x8')](function(_0xaeb2ed){logger[_0x543a('0x15')](_0x543a('0x16'),_0xaeb2ed?util[_0x543a('0x4')](_0xaeb2ed,{'showHidden':![],'depth':null}):'');return _0x23f2dd(null);});}return _0x23f2dd(null);});};exports['getUserByName']=function(_0x44c651){return new BPromise(function(_0x8c2de,_0xe61429){if(_0x44c651){return getUser({'name':_0x44c651})['then'](function(_0xf1cc78){logger[_0x543a('0x3')](_0x543a('0x17'),_0x44c651,_0xf1cc78?_0x543a('0x10'):_0x543a('0x11'));return _0x8c2de(_0xf1cc78);})[_0x543a('0x8')](function(_0xef9bec){logger[_0x543a('0x15')](_0x543a('0x18'),_0xef9bec?util[_0x543a('0x4')](_0xef9bec,{'showHidden':![],'depth':null}):'');return _0x8c2de(null);});}return _0x8c2de(null);});};exports['getVoiceQueueByName']=function(_0x5cbc0e){return new BPromise(function(_0xbb6bab,_0x373985){if(_0x5cbc0e){return client[_0x543a('0x19')](_0x543a('0x1a'),{'options':{'raw':!![],'attributes':['id',_0x543a('0xb'),_0x543a('0x1b'),_0x543a('0x1c'),_0x543a('0x1d')],'where':{'name':_0x5cbc0e},'limit':0x1}})['then'](function(_0x19ead5){logger['debug'](_0x543a('0x1e'),_0x5cbc0e,_0x19ead5?util[_0x543a('0x4')](_0x19ead5,{'showHidden':![],'depth':null}):'');logger[_0x543a('0x3')](_0x543a('0x1f'),_0x5cbc0e,_0x19ead5?_0x543a('0x10'):_0x543a('0x11'));return _0xbb6bab(_0x19ead5[_0x543a('0xe')][_0x543a('0x20')]?_0x19ead5[_0x543a('0xe')][0x0]:null);})[_0x543a('0x8')](function(_0x455678){logger[_0x543a('0x15')]('[utils][getVoiceQueueByName]',_0x455678?util[_0x543a('0x4')](_0x455678,{'showHidden':![],'depth':null}):'');return _0xbb6bab(null);});}return _0xbb6bab(null);});};exports[_0x543a('0x21')]=function(_0x9c8fdb,_0x36bee0){return moment(_0x9c8fdb)[_0x543a('0x22')](_0x36bee0,'seconds')[_0x543a('0x23')](_0x543a('0x24'));};exports[_0x543a('0x25')]=function(_0x3cce99,_0x573ab5){return moment(_0x3cce99)['subtract'](_0x573ab5,_0x543a('0x26'))[_0x543a('0x23')](_0x543a('0x24'));};exports[_0x543a('0x27')]=function(_0x5b26e4,_0x4de0f5){return moment(_0x5b26e4)[_0x543a('0x28')](moment(_0x4de0f5),_0x543a('0x26'));};exports['sumTime']=function(_0x108a86,_0x234851){return parseInt(_0x108a86,0xa)+parseInt(_0x234851,0xa);};exports[_0x543a('0x29')]=function(){return moment()[_0x543a('0x23')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x543a('0x2a')]=function(_0x4d235b,_0x5bf5b5){if(_0x5bf5b5){return moment(_0x4d235b)[_0x543a('0x2a')](_0x5bf5b5);}return!![];};exports[_0x543a('0x2b')]=function(_0x5acd72,_0x1aa8d9){if(_0x1aa8d9){return moment(_0x5acd72)[_0x543a('0x2b')](_0x1aa8d9);}else if(_0x5acd72){return!![];}return![];};