eec3c31ae764f2e50318853686fc86a66604b0c9
[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 _0x144a=['then','stringify','result','length','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','[utils][getUserByInternal]','[utils][getUserByInterface]\x20interface:%s\x20%s','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]','getVoiceQueueByName','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]','addTime','add','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diffTime','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','moment','util','client','http','../../config/logger','xdr','info','inspect','debug','error','request','catch','[utils][request]\x20name:%s','GetUser','internal','name','interface'];(function(_0x177e14,_0x401d6b){var _0x4dcdfe=function(_0x2c0158){while(--_0x2c0158){_0x177e14['push'](_0x177e14['shift']());}};_0x4dcdfe(++_0x401d6b);}(_0x144a,0xe7));var _0xa144=function(_0x30804f,_0x226d94){_0x30804f=_0x30804f-0x0;var _0x235ebf=_0x144a[_0x30804f];return _0x235ebf;};'use strict';var BPromise=require(_0xa144('0x0'));var jayson=require(_0xa144('0x1'));var moment=require(_0xa144('0x2'));var util=require(_0xa144('0x3'));var client=jayson[_0xa144('0x4')][_0xa144('0x5')]({'port':0x2329});var logger=require(_0xa144('0x6'))(_0xa144('0x7'));exports[_0xa144('0x8')]=function(_0x1109b4,_0x3d3555){logger[_0xa144('0x8')](_0x1109b4,_0x3d3555?util[_0xa144('0x9')](_0x3d3555,{'showHidden':![],'depth':null}):'');};exports[_0xa144('0xa')]=function(_0x27aebd,_0x30964d){logger[_0xa144('0xa')](_0x27aebd,_0x30964d?util[_0xa144('0x9')](_0x30964d,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x2afb2d,_0xe845ad){logger[_0xa144('0xb')](_0x2afb2d,_0xe845ad?util[_0xa144('0x9')](_0xe845ad,{'showHidden':![],'depth':null}):'');};exports[_0xa144('0xc')]=function(_0x440aa2,_0x45e2ea){return client['request'](_0x440aa2,{'body':_0x45e2ea})['then'](function(_0x449b73){logger[_0xa144('0xa')]('[utils][request]\x20name:%s',_0x440aa2,_0x449b73?util['inspect'](_0x449b73,{'showHidden':![],'depth':null}):'');})[_0xa144('0xd')](function(_0x29700a){logger[_0xa144('0xb')](_0xa144('0xe'),_0x440aa2,_0x29700a?util['inspect'](_0x29700a,{'showHidden':![],'depth':null}):'');});};function getUser(_0x1fd80b){return client[_0xa144('0xc')](_0xa144('0xf'),{'options':{'raw':!![],'attributes':['id',_0xa144('0x10'),_0xa144('0x11'),_0xa144('0x12')],'where':_0x1fd80b,'limit':0x1}})[_0xa144('0x13')](function(_0x521510){logger[_0xa144('0xa')]('[utils][getUser]\x20where:%s',JSON[_0xa144('0x14')](_0x1fd80b),_0x521510?util[_0xa144('0x9')](_0x521510,{'showHidden':![],'depth':null}):'');return _0x521510[_0xa144('0x15')][_0xa144('0x16')]?_0x521510[_0xa144('0x15')][0x0]:null;});}exports[_0xa144('0x17')]=function(_0x37d7ca){return new BPromise(function(_0x37cdaa,_0x8eafbf){if(_0x37d7ca){return getUser({'internal':_0x37d7ca})['then'](function(_0x2cba05){logger['info'](_0xa144('0x18'),_0x37d7ca,_0x2cba05?_0xa144('0x19'):_0xa144('0x1a'));return _0x37cdaa(_0x2cba05);})['catch'](function(_0x4eafb4){logger['error'](_0xa144('0x1b'),_0x4eafb4?util[_0xa144('0x9')](_0x4eafb4,{'showHidden':![],'depth':null}):'');return _0x37cdaa(null);});}return _0x37cdaa(null);});};exports['getUserByInterface']=function(_0x2aa390){return new BPromise(function(_0x2d526e,_0x3fbe){if(_0x2aa390){return getUser({'interface':_0x2aa390})['then'](function(_0x896974){logger[_0xa144('0x8')](_0xa144('0x1c'),_0x2aa390,_0x896974?'found':'notfound');return _0x2d526e(_0x896974);})[_0xa144('0xd')](function(_0x3b7c73){logger[_0xa144('0xb')](_0xa144('0x1d'),_0x3b7c73?util[_0xa144('0x9')](_0x3b7c73,{'showHidden':![],'depth':null}):'');return _0x2d526e(null);});}return _0x2d526e(null);});};exports[_0xa144('0x1e')]=function(_0x180b97){return new BPromise(function(_0x53836a,_0x2d5ffb){if(_0x180b97){return getUser({'name':_0x180b97})[_0xa144('0x13')](function(_0x52c8c8){logger['info']('[utils][getUserByName]\x20name:%s\x20%s',_0x180b97,_0x52c8c8?'found':_0xa144('0x1a'));return _0x53836a(_0x52c8c8);})[_0xa144('0xd')](function(_0x4feddf){logger['error'](_0xa144('0x1f'),_0x4feddf?util[_0xa144('0x9')](_0x4feddf,{'showHidden':![],'depth':null}):'');return _0x53836a(null);});}return _0x53836a(null);});};exports[_0xa144('0x20')]=function(_0xb7d8b8){return new BPromise(function(_0x2beac8,_0x54f6e2){if(_0xb7d8b8){return client[_0xa144('0xc')]('GetVoiceQueue',{'options':{'raw':!![],'attributes':['id',_0xa144('0x11'),_0xa144('0x21'),_0xa144('0x22'),_0xa144('0x23')],'where':{'name':_0xb7d8b8},'limit':0x1}})[_0xa144('0x13')](function(_0x47476b){logger[_0xa144('0xa')](_0xa144('0x24'),_0xb7d8b8,_0x47476b?util[_0xa144('0x9')](_0x47476b,{'showHidden':![],'depth':null}):'');logger[_0xa144('0x8')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0xb7d8b8,_0x47476b?_0xa144('0x19'):_0xa144('0x1a'));return _0x2beac8(_0x47476b['result'][_0xa144('0x16')]?_0x47476b['result'][0x0]:null);})[_0xa144('0xd')](function(_0x6a119e){logger[_0xa144('0xb')](_0xa144('0x25'),_0x6a119e?util['inspect'](_0x6a119e,{'showHidden':![],'depth':null}):'');return _0x2beac8(null);});}return _0x2beac8(null);});};exports[_0xa144('0x26')]=function(_0x5d6f15,_0x4e43a4){return moment(_0x5d6f15)[_0xa144('0x27')](_0x4e43a4,_0xa144('0x28'))[_0xa144('0x29')](_0xa144('0x2a'));};exports[_0xa144('0x2b')]=function(_0x3ce77d,_0x1beeb4){return moment(_0x3ce77d)[_0xa144('0x2c')](_0x1beeb4,'seconds')[_0xa144('0x29')](_0xa144('0x2a'));};exports[_0xa144('0x2d')]=function(_0x495f0c,_0x124218){return moment(_0x495f0c)['diff'](moment(_0x124218),'seconds');};exports[_0xa144('0x2e')]=function(_0xe6c4c3,_0x7e9cd9){return parseInt(_0xe6c4c3,0xa)+parseInt(_0x7e9cd9,0xa);};exports[_0xa144('0x2f')]=function(){return moment()['format'](_0xa144('0x2a'));};exports[_0xa144('0x30')]=function(_0x17aee8,_0x2cd0ab){if(_0x2cd0ab){return moment(_0x17aee8)[_0xa144('0x30')](_0x2cd0ab);}return!![];};exports['isBefore']=function(_0x1577b4,_0x41cf2c){if(_0x41cf2c){return moment(_0x1577b4)[_0xa144('0x31')](_0x41cf2c);}else if(_0x1577b4){return!![];}return![];};