Built motion from commit 26159a51.|2.5.44
[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 _0xa945=['add','format','subtractTime','subtract','seconds','YYYY-MM-DD\x20HH:mm:ss','diffTime','diff','isAfter','isBefore','bluebird','jayson/promise','moment','http','xdr','info','inspect','debug','error','request','catch','[utils][request]\x20name:%s','internal','interface','then','[utils][getUser]\x20where:%s','stringify','result','length','[utils][getUserByInternal]\x20internal:%s\x20%s','notfound','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','found','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','name','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s\x20%s','addTime'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0xa945,0x118));var _0x5a94=function(_0x439ce1,_0x978302){_0x439ce1=_0x439ce1-0x0;var _0x1164d6=_0xa945[_0x439ce1];return _0x1164d6;};'use strict';var BPromise=require(_0x5a94('0x0'));var jayson=require(_0x5a94('0x1'));var moment=require(_0x5a94('0x2'));var util=require('util');var client=jayson['client'][_0x5a94('0x3')]({'port':0x2329});var logger=require('../../config/logger')(_0x5a94('0x4'));exports['info']=function(_0x27c3db,_0x4b5341){logger[_0x5a94('0x5')](_0x27c3db,_0x4b5341?util[_0x5a94('0x6')](_0x4b5341,{'showHidden':![],'depth':null}):'');};exports['debug']=function(_0x36fe63,_0x14fa1a){logger[_0x5a94('0x7')](_0x36fe63,_0x14fa1a?util[_0x5a94('0x6')](_0x14fa1a,{'showHidden':![],'depth':null}):'');};exports[_0x5a94('0x8')]=function(_0x2f795f,_0xae329){logger['error'](_0x2f795f,_0xae329?util['inspect'](_0xae329,{'showHidden':![],'depth':null}):'');};exports[_0x5a94('0x9')]=function(_0x46ca0b,_0x199c8b){return client[_0x5a94('0x9')](_0x46ca0b,{'body':_0x199c8b})['then'](function(_0x1134c9){logger[_0x5a94('0x7')]('[utils][request]\x20name:%s',_0x46ca0b,_0x1134c9?util[_0x5a94('0x6')](_0x1134c9,{'showHidden':![],'depth':null}):'');})[_0x5a94('0xa')](function(_0x19d545){logger[_0x5a94('0x8')](_0x5a94('0xb'),_0x46ca0b,_0x19d545?util[_0x5a94('0x6')](_0x19d545,{'showHidden':![],'depth':null}):'');});};function getUser(_0x260d6f){return client['request']('GetUser',{'options':{'raw':!![],'attributes':['id',_0x5a94('0xc'),'name',_0x5a94('0xd')],'where':_0x260d6f,'limit':0x1}})[_0x5a94('0xe')](function(_0x3f66c0){logger[_0x5a94('0x7')](_0x5a94('0xf'),JSON[_0x5a94('0x10')](_0x260d6f),_0x3f66c0?util[_0x5a94('0x6')](_0x3f66c0,{'showHidden':![],'depth':null}):'');return _0x3f66c0[_0x5a94('0x11')][_0x5a94('0x12')]?_0x3f66c0[_0x5a94('0x11')][0x0]:null;});}exports['getUserByInternal']=function(_0x180844){return new BPromise(function(_0x14bb6f,_0x2bb579){if(_0x180844){return getUser({'internal':_0x180844})[_0x5a94('0xe')](function(_0x153ec0){logger[_0x5a94('0x5')](_0x5a94('0x13'),_0x180844,_0x153ec0?'found':_0x5a94('0x14'));return _0x14bb6f(_0x153ec0);})[_0x5a94('0xa')](function(_0x1997a4){logger[_0x5a94('0x8')]('[utils][getUserByInternal]',_0x1997a4?util['inspect'](_0x1997a4,{'showHidden':![],'depth':null}):'');return _0x14bb6f(null);});}return _0x14bb6f(null);});};exports[_0x5a94('0x15')]=function(_0x2a12ca){return new BPromise(function(_0x10d6de,_0x5785be){if(_0x2a12ca){return getUser({'interface':_0x2a12ca})['then'](function(_0x3acfe5){logger[_0x5a94('0x5')](_0x5a94('0x16'),_0x2a12ca,_0x3acfe5?_0x5a94('0x17'):_0x5a94('0x14'));return _0x10d6de(_0x3acfe5);})['catch'](function(_0x9cdff5){logger[_0x5a94('0x8')](_0x5a94('0x18'),_0x9cdff5?util[_0x5a94('0x6')](_0x9cdff5,{'showHidden':![],'depth':null}):'');return _0x10d6de(null);});}return _0x10d6de(null);});};exports[_0x5a94('0x19')]=function(_0x1ca07d){return new BPromise(function(_0x5cb23b,_0x2b2735){if(_0x1ca07d){return getUser({'name':_0x1ca07d})[_0x5a94('0xe')](function(_0x365461){logger[_0x5a94('0x5')](_0x5a94('0x1a'),_0x1ca07d,_0x365461?_0x5a94('0x17'):_0x5a94('0x14'));return _0x5cb23b(_0x365461);})['catch'](function(_0x39e661){logger['error'](_0x5a94('0x1b'),_0x39e661?util[_0x5a94('0x6')](_0x39e661,{'showHidden':![],'depth':null}):'');return _0x5cb23b(null);});}return _0x5cb23b(null);});};exports[_0x5a94('0x1c')]=function(_0xfb92cd){return new BPromise(function(_0x5f4d33,_0x21a038){if(_0xfb92cd){return client[_0x5a94('0x9')](_0x5a94('0x1d'),{'options':{'raw':!![],'attributes':['id',_0x5a94('0x1e'),'type',_0x5a94('0x1f'),_0x5a94('0x20')],'where':{'name':_0xfb92cd},'limit':0x1}})[_0x5a94('0xe')](function(_0x4d613c){logger[_0x5a94('0x7')]('[utils][getVoiceQueueByName]\x20name:%s',_0xfb92cd,_0x4d613c?util[_0x5a94('0x6')](_0x4d613c,{'showHidden':![],'depth':null}):'');logger[_0x5a94('0x5')](_0x5a94('0x21'),_0xfb92cd,_0x4d613c?_0x5a94('0x17'):_0x5a94('0x14'));return _0x5f4d33(_0x4d613c['result']['length']?_0x4d613c[_0x5a94('0x11')][0x0]:null);})['catch'](function(_0x57c355){logger[_0x5a94('0x8')]('[utils][getVoiceQueueByName]',_0x57c355?util[_0x5a94('0x6')](_0x57c355,{'showHidden':![],'depth':null}):'');return _0x5f4d33(null);});}return _0x5f4d33(null);});};exports[_0x5a94('0x22')]=function(_0xe5d890,_0x33860f){return moment(_0xe5d890)[_0x5a94('0x23')](_0x33860f,'seconds')[_0x5a94('0x24')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x5a94('0x25')]=function(_0x775704,_0x510e33){return moment(_0x775704)[_0x5a94('0x26')](_0x510e33,_0x5a94('0x27'))[_0x5a94('0x24')](_0x5a94('0x28'));};exports[_0x5a94('0x29')]=function(_0xf457f0,_0x306464){return moment(_0xf457f0)[_0x5a94('0x2a')](moment(_0x306464),_0x5a94('0x27'));};exports['sumTime']=function(_0x5d539f,_0x2b5f13){return parseInt(_0x5d539f,0xa)+parseInt(_0x2b5f13,0xa);};exports['now']=function(){return moment()[_0x5a94('0x24')](_0x5a94('0x28'));};exports[_0x5a94('0x2b')]=function(_0x36c757,_0x488be3){if(_0x488be3){return moment(_0x36c757)[_0x5a94('0x2b')](_0x488be3);}return!![];};exports['isBefore']=function(_0x435927,_0x355db5){if(_0x355db5){return moment(_0x435927)[_0x5a94('0x2c')](_0x355db5);}else if(_0x435927){return!![];}return![];};