f168b61480a77e22d40d8a0acb842516f60118ac
[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 _0x2ba6=['add','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtract','diff','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','moment','util','client','../../config/logger','xdr','info','debug','inspect','error','request','then','[utils][request]\x20name:%s','GetUser','internal','name','interface','stringify','result','length','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','catch','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','[utils][getUserByInterface]','[utils][getUserByName]\x20name:%s\x20%s','getVoiceQueueByName','GetVoiceQueue','type','acw','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]','addTime'];(function(_0x38a4a0,_0x4511cc){var _0x44a772=function(_0x77cade){while(--_0x77cade){_0x38a4a0['push'](_0x38a4a0['shift']());}};_0x44a772(++_0x4511cc);}(_0x2ba6,0x1ea));var _0x62ba=function(_0x18437c,_0x47d616){_0x18437c=_0x18437c-0x0;var _0x3f4276=_0x2ba6[_0x18437c];return _0x3f4276;};'use strict';var BPromise=require(_0x62ba('0x0'));var jayson=require(_0x62ba('0x1'));var moment=require(_0x62ba('0x2'));var util=require(_0x62ba('0x3'));var client=jayson[_0x62ba('0x4')]['http']({'port':0x2329});var logger=require(_0x62ba('0x5'))(_0x62ba('0x6'));exports[_0x62ba('0x7')]=function(_0x362f2c,_0x42eef5){logger[_0x62ba('0x7')](_0x362f2c,_0x42eef5?util['inspect'](_0x42eef5,{'showHidden':![],'depth':null}):'');};exports[_0x62ba('0x8')]=function(_0x24c78a,_0x8a432d){logger['debug'](_0x24c78a,_0x8a432d?util[_0x62ba('0x9')](_0x8a432d,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0xb60414,_0xc1cb24){logger[_0x62ba('0xa')](_0xb60414,_0xc1cb24?util[_0x62ba('0x9')](_0xc1cb24,{'showHidden':![],'depth':null}):'');};exports[_0x62ba('0xb')]=function(_0x1c5e97,_0x22e81e){return client[_0x62ba('0xb')](_0x1c5e97,{'body':_0x22e81e})[_0x62ba('0xc')](function(_0x54366b){logger[_0x62ba('0x8')](_0x62ba('0xd'),_0x1c5e97,_0x54366b?util[_0x62ba('0x9')](_0x54366b,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x4a4aeb){logger[_0x62ba('0xa')](_0x62ba('0xd'),_0x1c5e97,_0x4a4aeb?util[_0x62ba('0x9')](_0x4a4aeb,{'showHidden':![],'depth':null}):'');});};function getUser(_0x2bd312){return client[_0x62ba('0xb')](_0x62ba('0xe'),{'options':{'raw':!![],'attributes':['id',_0x62ba('0xf'),_0x62ba('0x10'),_0x62ba('0x11')],'where':_0x2bd312,'limit':0x1}})[_0x62ba('0xc')](function(_0x4535db){logger[_0x62ba('0x8')]('[utils][getUser]\x20where:%s',JSON[_0x62ba('0x12')](_0x2bd312),_0x4535db?util[_0x62ba('0x9')](_0x4535db,{'showHidden':![],'depth':null}):'');return _0x4535db[_0x62ba('0x13')][_0x62ba('0x14')]?_0x4535db['result'][0x0]:null;});}exports[_0x62ba('0x15')]=function(_0x453010){return new BPromise(function(_0x3e0a33,_0x567a38){if(_0x453010){return getUser({'internal':_0x453010})[_0x62ba('0xc')](function(_0x1ea7ab){logger['info'](_0x62ba('0x16'),_0x453010,_0x1ea7ab?_0x62ba('0x17'):_0x62ba('0x18'));return _0x3e0a33(_0x1ea7ab);})[_0x62ba('0x19')](function(_0xf00b36){logger[_0x62ba('0xa')](_0x62ba('0x1a'),_0xf00b36?util[_0x62ba('0x9')](_0xf00b36,{'showHidden':![],'depth':null}):'');return _0x3e0a33(null);});}return _0x3e0a33(null);});};exports[_0x62ba('0x1b')]=function(_0x44ecb3){return new BPromise(function(_0x439cc6,_0x2f7ab2){if(_0x44ecb3){return getUser({'interface':_0x44ecb3})[_0x62ba('0xc')](function(_0x27a867){logger[_0x62ba('0x7')](_0x62ba('0x1c'),_0x44ecb3,_0x27a867?_0x62ba('0x17'):_0x62ba('0x18'));return _0x439cc6(_0x27a867);})[_0x62ba('0x19')](function(_0x84cd96){logger[_0x62ba('0xa')](_0x62ba('0x1d'),_0x84cd96?util[_0x62ba('0x9')](_0x84cd96,{'showHidden':![],'depth':null}):'');return _0x439cc6(null);});}return _0x439cc6(null);});};exports['getUserByName']=function(_0x3b2230){return new BPromise(function(_0x1055a0,_0x146950){if(_0x3b2230){return getUser({'name':_0x3b2230})[_0x62ba('0xc')](function(_0x183b26){logger['info'](_0x62ba('0x1e'),_0x3b2230,_0x183b26?_0x62ba('0x17'):_0x62ba('0x18'));return _0x1055a0(_0x183b26);})['catch'](function(_0x2d2151){logger[_0x62ba('0xa')]('[utils][getUserByName]',_0x2d2151?util[_0x62ba('0x9')](_0x2d2151,{'showHidden':![],'depth':null}):'');return _0x1055a0(null);});}return _0x1055a0(null);});};exports[_0x62ba('0x1f')]=function(_0x8c0e7a){return new BPromise(function(_0x4d4e57,_0x245629){if(_0x8c0e7a){return client[_0x62ba('0xb')](_0x62ba('0x20'),{'options':{'raw':!![],'attributes':['id',_0x62ba('0x10'),_0x62ba('0x21'),_0x62ba('0x22'),'acwTimeout'],'where':{'name':_0x8c0e7a},'limit':0x1}})[_0x62ba('0xc')](function(_0xe587ef){logger['debug'](_0x62ba('0x23'),_0x8c0e7a,_0xe587ef?util[_0x62ba('0x9')](_0xe587ef,{'showHidden':![],'depth':null}):'');logger[_0x62ba('0x7')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0x8c0e7a,_0xe587ef?'found':_0x62ba('0x18'));return _0x4d4e57(_0xe587ef[_0x62ba('0x13')]['length']?_0xe587ef['result'][0x0]:null);})[_0x62ba('0x19')](function(_0x4b09b0){logger[_0x62ba('0xa')](_0x62ba('0x24'),_0x4b09b0?util[_0x62ba('0x9')](_0x4b09b0,{'showHidden':![],'depth':null}):'');return _0x4d4e57(null);});}return _0x4d4e57(null);});};exports[_0x62ba('0x25')]=function(_0x4e4eec,_0x4cd8fb){return moment(_0x4e4eec)[_0x62ba('0x26')](_0x4cd8fb,_0x62ba('0x27'))[_0x62ba('0x28')](_0x62ba('0x29'));};exports['subtractTime']=function(_0x38a866,_0x5b79df){return moment(_0x38a866)[_0x62ba('0x2a')](_0x5b79df,_0x62ba('0x27'))['format'](_0x62ba('0x29'));};exports['diffTime']=function(_0xe225b2,_0x2cc332){return moment(_0xe225b2)[_0x62ba('0x2b')](moment(_0x2cc332),_0x62ba('0x27'));};exports[_0x62ba('0x2c')]=function(_0x5a307c,_0x5c1c6a){return parseInt(_0x5a307c,0xa)+parseInt(_0x5c1c6a,0xa);};exports[_0x62ba('0x2d')]=function(){return moment()[_0x62ba('0x28')](_0x62ba('0x29'));};exports[_0x62ba('0x2e')]=function(_0x7acf85,_0x9b8efe){if(_0x9b8efe){return moment(_0x7acf85)['isAfter'](_0x9b8efe);}return!![];};exports[_0x62ba('0x2f')]=function(_0x194527,_0x5e21cf){if(_0x5e21cf){return moment(_0x194527)[_0x62ba('0x2f')](_0x5e21cf);}else if(_0x194527){return!![];}return![];};