7cd8de02a277f0a5fd81bec76d41aba1a0815a16
[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 _0x2b55=['bluebird','jayson/promise','moment','util','client','http','../../config/logger','info','inspect','debug','error','request','then','[utils][request]\x20name:%s','GetUser','internal','name','[utils][getUser]\x20where:%s','stringify','result','getUserByInternal','notfound','[utils][getUserByInternal]','getUserByInterface','found','catch','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','length','[utils][getVoiceQueueByName]','addTime','add','seconds','YYYY-MM-DD\x20HH:mm:ss','subtract','format','diff','now','isAfter','isBefore'];(function(_0x50b850,_0x797ed2){var _0x348619=function(_0x2b12f5){while(--_0x2b12f5){_0x50b850['push'](_0x50b850['shift']());}};_0x348619(++_0x797ed2);}(_0x2b55,0x180));var _0x52b5=function(_0x9b05c9,_0x27eaac){_0x9b05c9=_0x9b05c9-0x0;var _0x2afae6=_0x2b55[_0x9b05c9];return _0x2afae6;};'use strict';var BPromise=require(_0x52b5('0x0'));var jayson=require(_0x52b5('0x1'));var moment=require(_0x52b5('0x2'));var util=require(_0x52b5('0x3'));var client=jayson[_0x52b5('0x4')][_0x52b5('0x5')]({'port':0x2329});var logger=require(_0x52b5('0x6'))('xdr');exports['info']=function(_0x341e04,_0x1d6238){logger[_0x52b5('0x7')](_0x341e04,_0x1d6238?util[_0x52b5('0x8')](_0x1d6238,{'showHidden':![],'depth':null}):'');};exports[_0x52b5('0x9')]=function(_0x1c1ea2,_0x2bf6ad){logger[_0x52b5('0x9')](_0x1c1ea2,_0x2bf6ad?util['inspect'](_0x2bf6ad,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x41c510,_0xb8782){logger[_0x52b5('0xa')](_0x41c510,_0xb8782?util['inspect'](_0xb8782,{'showHidden':![],'depth':null}):'');};exports[_0x52b5('0xb')]=function(_0x22b926,_0x1d8e82){return client[_0x52b5('0xb')](_0x22b926,{'body':_0x1d8e82})[_0x52b5('0xc')](function(_0xa381a6){logger[_0x52b5('0x9')](_0x52b5('0xd'),_0x22b926,_0xa381a6?util['inspect'](_0xa381a6,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x408ee0){logger[_0x52b5('0xa')](_0x52b5('0xd'),_0x22b926,_0x408ee0?util[_0x52b5('0x8')](_0x408ee0,{'showHidden':![],'depth':null}):'');});};function getUser(_0x266473){return client[_0x52b5('0xb')](_0x52b5('0xe'),{'options':{'raw':!![],'attributes':['id',_0x52b5('0xf'),_0x52b5('0x10'),'interface'],'where':_0x266473,'limit':0x1}})[_0x52b5('0xc')](function(_0xf3dfdf){logger[_0x52b5('0x9')](_0x52b5('0x11'),JSON[_0x52b5('0x12')](_0x266473),_0xf3dfdf?util['inspect'](_0xf3dfdf,{'showHidden':![],'depth':null}):'');return _0xf3dfdf['result']['length']?_0xf3dfdf[_0x52b5('0x13')][0x0]:null;});}exports[_0x52b5('0x14')]=function(_0x4cf4fe){return new BPromise(function(_0x38b3e8,_0x519ba5){if(_0x4cf4fe){return getUser({'internal':_0x4cf4fe})['then'](function(_0x4f0395){logger[_0x52b5('0x7')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x4cf4fe,_0x4f0395?'found':_0x52b5('0x15'));return _0x38b3e8(_0x4f0395);})['catch'](function(_0x498f13){logger['error'](_0x52b5('0x16'),_0x498f13?util['inspect'](_0x498f13,{'showHidden':![],'depth':null}):'');return _0x38b3e8(null);});}return _0x38b3e8(null);});};exports[_0x52b5('0x17')]=function(_0x947724){return new BPromise(function(_0x215800,_0x42af66){if(_0x947724){return getUser({'interface':_0x947724})[_0x52b5('0xc')](function(_0x1ab366){logger['info']('[utils][getUserByInterface]\x20interface:%s\x20%s',_0x947724,_0x1ab366?_0x52b5('0x18'):_0x52b5('0x15'));return _0x215800(_0x1ab366);})[_0x52b5('0x19')](function(_0x440d52){logger[_0x52b5('0xa')](_0x52b5('0x1a'),_0x440d52?util[_0x52b5('0x8')](_0x440d52,{'showHidden':![],'depth':null}):'');return _0x215800(null);});}return _0x215800(null);});};exports[_0x52b5('0x1b')]=function(_0x43bc34){return new BPromise(function(_0x4ead4d,_0x4bb73e){if(_0x43bc34){return getUser({'name':_0x43bc34})[_0x52b5('0xc')](function(_0x17df7b){logger['info'](_0x52b5('0x1c'),_0x43bc34,_0x17df7b?_0x52b5('0x18'):_0x52b5('0x15'));return _0x4ead4d(_0x17df7b);})[_0x52b5('0x19')](function(_0x374ea2){logger[_0x52b5('0xa')](_0x52b5('0x1d'),_0x374ea2?util['inspect'](_0x374ea2,{'showHidden':![],'depth':null}):'');return _0x4ead4d(null);});}return _0x4ead4d(null);});};exports['getVoiceQueueByName']=function(_0x36c3e2){return new BPromise(function(_0x465d31,_0x30fd70){if(_0x36c3e2){return client['request'](_0x52b5('0x1e'),{'options':{'raw':!![],'attributes':['id','name',_0x52b5('0x1f'),_0x52b5('0x20'),_0x52b5('0x21')],'where':{'name':_0x36c3e2},'limit':0x1}})['then'](function(_0x1dfc7f){logger[_0x52b5('0x9')](_0x52b5('0x22'),_0x36c3e2,_0x1dfc7f?util[_0x52b5('0x8')](_0x1dfc7f,{'showHidden':![],'depth':null}):'');logger[_0x52b5('0x7')](_0x52b5('0x23'),_0x36c3e2,_0x1dfc7f?_0x52b5('0x18'):_0x52b5('0x15'));return _0x465d31(_0x1dfc7f['result'][_0x52b5('0x24')]?_0x1dfc7f[_0x52b5('0x13')][0x0]:null);})[_0x52b5('0x19')](function(_0x2904ef){logger[_0x52b5('0xa')](_0x52b5('0x25'),_0x2904ef?util[_0x52b5('0x8')](_0x2904ef,{'showHidden':![],'depth':null}):'');return _0x465d31(null);});}return _0x465d31(null);});};exports[_0x52b5('0x26')]=function(_0x3f9574,_0x28a7fe){return moment(_0x3f9574)[_0x52b5('0x27')](_0x28a7fe,_0x52b5('0x28'))['format'](_0x52b5('0x29'));};exports['subtractTime']=function(_0x52c727,_0x499f97){return moment(_0x52c727)[_0x52b5('0x2a')](_0x499f97,_0x52b5('0x28'))[_0x52b5('0x2b')](_0x52b5('0x29'));};exports['diffTime']=function(_0x245a93,_0xc66095){return moment(_0x245a93)[_0x52b5('0x2c')](moment(_0xc66095),_0x52b5('0x28'));};exports['sumTime']=function(_0x8dc534,_0x29753e){return parseInt(_0x8dc534,0xa)+parseInt(_0x29753e,0xa);};exports[_0x52b5('0x2d')]=function(){return moment()[_0x52b5('0x2b')](_0x52b5('0x29'));};exports['isAfter']=function(_0x4adfa9,_0x207108){if(_0x207108){return moment(_0x4adfa9)[_0x52b5('0x2e')](_0x207108);}return!![];};exports[_0x52b5('0x2f')]=function(_0x1bcf2a,_0x2865c1){if(_0x2865c1){return moment(_0x1bcf2a)[_0x52b5('0x2f')](_0x2865c1);}else if(_0x1bcf2a){return!![];}return![];};