b9a95fc0ab169fb419320f5de3f33687661f7f71
[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 _0x3c81=['GetVoiceQueue','type','acw','acwTimeout','addTime','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diff','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','util','client','http','../../config/logger','debug','inspect','error','request','catch','[utils][request]\x20name:%s','GetUser','internal','name','[utils][getUser]\x20where:%s','stringify','result','length','getUserByInternal','info','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','[utils][getUserByInternal]','getUserByInterface','then','[utils][getUserByInterface]\x20interface:%s\x20%s','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]'];(function(_0x2eb8d5,_0x286712){var _0xc6e6cf=function(_0x372d1e){while(--_0x372d1e){_0x2eb8d5['push'](_0x2eb8d5['shift']());}};_0xc6e6cf(++_0x286712);}(_0x3c81,0x1e5));var _0x13c8=function(_0x15417d,_0x2fc6fb){_0x15417d=_0x15417d-0x0;var _0x43b3f8=_0x3c81[_0x15417d];return _0x43b3f8;};'use strict';var BPromise=require(_0x13c8('0x0'));var jayson=require(_0x13c8('0x1'));var moment=require('moment');var util=require(_0x13c8('0x2'));var client=jayson[_0x13c8('0x3')][_0x13c8('0x4')]({'port':0x2329});var logger=require(_0x13c8('0x5'))('xdr');exports['info']=function(_0x1a652a,_0x37195b){logger['info'](_0x1a652a,_0x37195b?util['inspect'](_0x37195b,{'showHidden':![],'depth':null}):'');};exports[_0x13c8('0x6')]=function(_0x1867c8,_0x35c35f){logger[_0x13c8('0x6')](_0x1867c8,_0x35c35f?util[_0x13c8('0x7')](_0x35c35f,{'showHidden':![],'depth':null}):'');};exports[_0x13c8('0x8')]=function(_0x29a5dd,_0x2bce6c){logger[_0x13c8('0x8')](_0x29a5dd,_0x2bce6c?util[_0x13c8('0x7')](_0x2bce6c,{'showHidden':![],'depth':null}):'');};exports[_0x13c8('0x9')]=function(_0x2fc7c6,_0x1a5492){return client[_0x13c8('0x9')](_0x2fc7c6,{'body':_0x1a5492})['then'](function(_0x1005b9){logger['debug']('[utils][request]\x20name:%s',_0x2fc7c6,_0x1005b9?util[_0x13c8('0x7')](_0x1005b9,{'showHidden':![],'depth':null}):'');})[_0x13c8('0xa')](function(_0x1fd13d){logger[_0x13c8('0x8')](_0x13c8('0xb'),_0x2fc7c6,_0x1fd13d?util['inspect'](_0x1fd13d,{'showHidden':![],'depth':null}):'');});};function getUser(_0x4b3836){return client[_0x13c8('0x9')](_0x13c8('0xc'),{'options':{'raw':!![],'attributes':['id',_0x13c8('0xd'),_0x13c8('0xe'),'interface'],'where':_0x4b3836,'limit':0x1}})['then'](function(_0x37f7cc){logger[_0x13c8('0x6')](_0x13c8('0xf'),JSON[_0x13c8('0x10')](_0x4b3836),_0x37f7cc?util[_0x13c8('0x7')](_0x37f7cc,{'showHidden':![],'depth':null}):'');return _0x37f7cc[_0x13c8('0x11')][_0x13c8('0x12')]?_0x37f7cc[_0x13c8('0x11')][0x0]:null;});}exports[_0x13c8('0x13')]=function(_0x3f202d){return new BPromise(function(_0x1fc78a,_0x5567a6){if(_0x3f202d){return getUser({'internal':_0x3f202d})['then'](function(_0x36a52d){logger[_0x13c8('0x14')](_0x13c8('0x15'),_0x3f202d,_0x36a52d?_0x13c8('0x16'):_0x13c8('0x17'));return _0x1fc78a(_0x36a52d);})[_0x13c8('0xa')](function(_0x4b38ca){logger[_0x13c8('0x8')](_0x13c8('0x18'),_0x4b38ca?util[_0x13c8('0x7')](_0x4b38ca,{'showHidden':![],'depth':null}):'');return _0x1fc78a(null);});}return _0x1fc78a(null);});};exports[_0x13c8('0x19')]=function(_0x42abed){return new BPromise(function(_0x22889e,_0x2a0c2f){if(_0x42abed){return getUser({'interface':_0x42abed})[_0x13c8('0x1a')](function(_0x50d0af){logger[_0x13c8('0x14')](_0x13c8('0x1b'),_0x42abed,_0x50d0af?'found':_0x13c8('0x17'));return _0x22889e(_0x50d0af);})[_0x13c8('0xa')](function(_0x1281d5){logger[_0x13c8('0x8')](_0x13c8('0x1c'),_0x1281d5?util['inspect'](_0x1281d5,{'showHidden':![],'depth':null}):'');return _0x22889e(null);});}return _0x22889e(null);});};exports[_0x13c8('0x1d')]=function(_0x52393d){return new BPromise(function(_0x2113f1,_0xd02b40){if(_0x52393d){return getUser({'name':_0x52393d})[_0x13c8('0x1a')](function(_0x509133){logger[_0x13c8('0x14')](_0x13c8('0x1e'),_0x52393d,_0x509133?_0x13c8('0x16'):_0x13c8('0x17'));return _0x2113f1(_0x509133);})[_0x13c8('0xa')](function(_0x382704){logger[_0x13c8('0x8')](_0x13c8('0x1f'),_0x382704?util[_0x13c8('0x7')](_0x382704,{'showHidden':![],'depth':null}):'');return _0x2113f1(null);});}return _0x2113f1(null);});};exports['getVoiceQueueByName']=function(_0x34c11a){return new BPromise(function(_0x16d3e8,_0x16adef){if(_0x34c11a){return client['request'](_0x13c8('0x20'),{'options':{'raw':!![],'attributes':['id',_0x13c8('0xe'),_0x13c8('0x21'),_0x13c8('0x22'),_0x13c8('0x23')],'where':{'name':_0x34c11a},'limit':0x1}})[_0x13c8('0x1a')](function(_0x202a3d){logger[_0x13c8('0x6')]('[utils][getVoiceQueueByName]\x20name:%s',_0x34c11a,_0x202a3d?util['inspect'](_0x202a3d,{'showHidden':![],'depth':null}):'');logger[_0x13c8('0x14')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0x34c11a,_0x202a3d?_0x13c8('0x16'):'notfound');return _0x16d3e8(_0x202a3d[_0x13c8('0x11')]['length']?_0x202a3d[_0x13c8('0x11')][0x0]:null);})[_0x13c8('0xa')](function(_0x557443){logger['error']('[utils][getVoiceQueueByName]',_0x557443?util[_0x13c8('0x7')](_0x557443,{'showHidden':![],'depth':null}):'');return _0x16d3e8(null);});}return _0x16d3e8(null);});};exports[_0x13c8('0x24')]=function(_0x357657,_0x40141a){return moment(_0x357657)['add'](_0x40141a,_0x13c8('0x25'))[_0x13c8('0x26')](_0x13c8('0x27'));};exports[_0x13c8('0x28')]=function(_0x7d3166,_0x1afd65){return moment(_0x7d3166)[_0x13c8('0x29')](_0x1afd65,_0x13c8('0x25'))[_0x13c8('0x26')](_0x13c8('0x27'));};exports['diffTime']=function(_0x4853bc,_0x52024a){return moment(_0x4853bc)[_0x13c8('0x2a')](moment(_0x52024a),_0x13c8('0x25'));};exports[_0x13c8('0x2b')]=function(_0xcf6edf,_0x184194){return parseInt(_0xcf6edf,0xa)+parseInt(_0x184194,0xa);};exports[_0x13c8('0x2c')]=function(){return moment()[_0x13c8('0x26')](_0x13c8('0x27'));};exports['isAfter']=function(_0x5811e9,_0x419650){if(_0x419650){return moment(_0x5811e9)[_0x13c8('0x2d')](_0x419650);}return!![];};exports[_0x13c8('0x2e')]=function(_0x152e98,_0x9d96d5){if(_0x9d96d5){return moment(_0x152e98)[_0x13c8('0x2e')](_0x9d96d5);}else if(_0x152e98){return!![];}return![];};