8e2c9dcc48fa6661e4e5b71c7a969c62ec255bad
[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 _0xfbd2=['now','isAfter','isBefore','bluebird','jayson/promise','moment','util','client','http','xdr','inspect','debug','error','request','catch','[utils][request]\x20name:%s','GetUser','interface','result','getUserByInternal','info','[utils][getUserByInternal]\x20internal:%s\x20%s','notfound','[utils][getUserByInternal]','getUserByInterface','then','[utils][getUserByInterface]\x20interface:%s\x20%s','found','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s\x20%s','addTime','YYYY-MM-DD\x20HH:mm:ss','subtract','seconds','format','diffTime'];(function(_0x2a6926,_0x38b208){var _0x261776=function(_0x522802){while(--_0x522802){_0x2a6926['push'](_0x2a6926['shift']());}};_0x261776(++_0x38b208);}(_0xfbd2,0x143));var _0x2fbd=function(_0x15afc8,_0x3f4ecc){_0x15afc8=_0x15afc8-0x0;var _0x4fb952=_0xfbd2[_0x15afc8];return _0x4fb952;};'use strict';var BPromise=require(_0x2fbd('0x0'));var jayson=require(_0x2fbd('0x1'));var moment=require(_0x2fbd('0x2'));var util=require(_0x2fbd('0x3'));var client=jayson[_0x2fbd('0x4')][_0x2fbd('0x5')]({'port':0x2329});var logger=require('../../config/logger')(_0x2fbd('0x6'));exports['info']=function(_0x457795,_0x46dca7){logger['info'](_0x457795,_0x46dca7?util[_0x2fbd('0x7')](_0x46dca7,{'showHidden':![],'depth':null}):'');};exports['debug']=function(_0xf5f6e1,_0xa256e4){logger[_0x2fbd('0x8')](_0xf5f6e1,_0xa256e4?util[_0x2fbd('0x7')](_0xa256e4,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x7cb134,_0x243553){logger[_0x2fbd('0x9')](_0x7cb134,_0x243553?util[_0x2fbd('0x7')](_0x243553,{'showHidden':![],'depth':null}):'');};exports[_0x2fbd('0xa')]=function(_0x3d0acf,_0xa25a6e){return client['request'](_0x3d0acf,{'body':_0xa25a6e})['then'](function(_0x3c3bbe){logger[_0x2fbd('0x8')]('[utils][request]\x20name:%s',_0x3d0acf,_0x3c3bbe?util[_0x2fbd('0x7')](_0x3c3bbe,{'showHidden':![],'depth':null}):'');})[_0x2fbd('0xb')](function(_0x45f5ee){logger['error'](_0x2fbd('0xc'),_0x3d0acf,_0x45f5ee?util['inspect'](_0x45f5ee,{'showHidden':![],'depth':null}):'');});};function getUser(_0x1a2141){return client[_0x2fbd('0xa')](_0x2fbd('0xd'),{'options':{'raw':!![],'attributes':['id','internal','name',_0x2fbd('0xe')],'where':_0x1a2141,'limit':0x1}})['then'](function(_0x1cd588){logger['debug']('[utils][getUser]\x20where:%s',JSON['stringify'](_0x1a2141),_0x1cd588?util['inspect'](_0x1cd588,{'showHidden':![],'depth':null}):'');return _0x1cd588[_0x2fbd('0xf')]['length']?_0x1cd588['result'][0x0]:null;});}exports[_0x2fbd('0x10')]=function(_0x171cd7){return new BPromise(function(_0x2bb92c,_0xc39169){if(_0x171cd7){return getUser({'internal':_0x171cd7})['then'](function(_0x5734b4){logger[_0x2fbd('0x11')](_0x2fbd('0x12'),_0x171cd7,_0x5734b4?'found':_0x2fbd('0x13'));return _0x2bb92c(_0x5734b4);})['catch'](function(_0x393b19){logger['error'](_0x2fbd('0x14'),_0x393b19?util[_0x2fbd('0x7')](_0x393b19,{'showHidden':![],'depth':null}):'');return _0x2bb92c(null);});}return _0x2bb92c(null);});};exports[_0x2fbd('0x15')]=function(_0x2b5cda){return new BPromise(function(_0x359e5f,_0x39b8a0){if(_0x2b5cda){return getUser({'interface':_0x2b5cda})[_0x2fbd('0x16')](function(_0xe75cfb){logger[_0x2fbd('0x11')](_0x2fbd('0x17'),_0x2b5cda,_0xe75cfb?'found':_0x2fbd('0x13'));return _0x359e5f(_0xe75cfb);})[_0x2fbd('0xb')](function(_0x43a115){logger[_0x2fbd('0x9')]('[utils][getUserByInterface]',_0x43a115?util[_0x2fbd('0x7')](_0x43a115,{'showHidden':![],'depth':null}):'');return _0x359e5f(null);});}return _0x359e5f(null);});};exports['getUserByName']=function(_0x58e85a){return new BPromise(function(_0x4a5b18,_0x5a00f2){if(_0x58e85a){return getUser({'name':_0x58e85a})[_0x2fbd('0x16')](function(_0x2bbae0){logger[_0x2fbd('0x11')]('[utils][getUserByName]\x20name:%s\x20%s',_0x58e85a,_0x2bbae0?_0x2fbd('0x18'):'notfound');return _0x4a5b18(_0x2bbae0);})[_0x2fbd('0xb')](function(_0x23241c){logger['error'](_0x2fbd('0x19'),_0x23241c?util['inspect'](_0x23241c,{'showHidden':![],'depth':null}):'');return _0x4a5b18(null);});}return _0x4a5b18(null);});};exports[_0x2fbd('0x1a')]=function(_0x4d58fe){return new BPromise(function(_0x534058,_0x270375){if(_0x4d58fe){return client[_0x2fbd('0xa')](_0x2fbd('0x1b'),{'options':{'raw':!![],'attributes':['id','name','type',_0x2fbd('0x1c'),_0x2fbd('0x1d')],'where':{'name':_0x4d58fe},'limit':0x1}})[_0x2fbd('0x16')](function(_0x26306f){logger[_0x2fbd('0x8')]('[utils][getVoiceQueueByName]\x20name:%s',_0x4d58fe,_0x26306f?util[_0x2fbd('0x7')](_0x26306f,{'showHidden':![],'depth':null}):'');logger['info'](_0x2fbd('0x1e'),_0x4d58fe,_0x26306f?_0x2fbd('0x18'):_0x2fbd('0x13'));return _0x534058(_0x26306f[_0x2fbd('0xf')]['length']?_0x26306f[_0x2fbd('0xf')][0x0]:null);})['catch'](function(_0x4a0006){logger[_0x2fbd('0x9')]('[utils][getVoiceQueueByName]',_0x4a0006?util['inspect'](_0x4a0006,{'showHidden':![],'depth':null}):'');return _0x534058(null);});}return _0x534058(null);});};exports[_0x2fbd('0x1f')]=function(_0x4fa531,_0x5f42bb){return moment(_0x4fa531)['add'](_0x5f42bb,'seconds')['format'](_0x2fbd('0x20'));};exports['subtractTime']=function(_0x4f89ca,_0x4fe0bd){return moment(_0x4f89ca)[_0x2fbd('0x21')](_0x4fe0bd,_0x2fbd('0x22'))[_0x2fbd('0x23')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x2fbd('0x24')]=function(_0x5c81d0,_0x310da8){return moment(_0x5c81d0)['diff'](moment(_0x310da8),_0x2fbd('0x22'));};exports['sumTime']=function(_0x117eda,_0x16c5b0){return parseInt(_0x117eda,0xa)+parseInt(_0x16c5b0,0xa);};exports[_0x2fbd('0x25')]=function(){return moment()[_0x2fbd('0x23')](_0x2fbd('0x20'));};exports['isAfter']=function(_0x5d5c92,_0x521398){if(_0x521398){return moment(_0x5d5c92)[_0x2fbd('0x26')](_0x521398);}return!![];};exports[_0x2fbd('0x27')]=function(_0x36a848,_0x5c37ae){if(_0x5c37ae){return moment(_0x36a848)[_0x2fbd('0x27')](_0x5c37ae);}else if(_0x36a848){return!![];}return![];};