ed42b8f51b38d716e8ff10d5c96bc4c2185c4fed
[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 _0x60b0=['getUserByInternal','then','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','type','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','seconds','diff','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','moment','util','client','../../config/logger','xdr','info','debug','inspect','error','request','[utils][request]\x20name:%s','catch','GetUser','internal','name','interface','[utils][getUser]\x20where:%s','stringify','length','result'];(function(_0xd09668,_0x1435b2){var _0x68726=function(_0x54a030){while(--_0x54a030){_0xd09668['push'](_0xd09668['shift']());}};_0x68726(++_0x1435b2);}(_0x60b0,0x77));var _0x060b=function(_0x4de877,_0x340170){_0x4de877=_0x4de877-0x0;var _0xb2cfeb=_0x60b0[_0x4de877];return _0xb2cfeb;};'use strict';var BPromise=require(_0x060b('0x0'));var jayson=require(_0x060b('0x1'));var moment=require(_0x060b('0x2'));var util=require(_0x060b('0x3'));var client=jayson[_0x060b('0x4')]['http']({'port':0x2329});var logger=require(_0x060b('0x5'))(_0x060b('0x6'));exports['info']=function(_0x527216,_0x4fa7d3){logger[_0x060b('0x7')](_0x527216,_0x4fa7d3?util['inspect'](_0x4fa7d3,{'showHidden':![],'depth':null}):'');};exports[_0x060b('0x8')]=function(_0x443c79,_0x222945){logger['debug'](_0x443c79,_0x222945?util[_0x060b('0x9')](_0x222945,{'showHidden':![],'depth':null}):'');};exports[_0x060b('0xa')]=function(_0x8cc615,_0xa6ac17){logger[_0x060b('0xa')](_0x8cc615,_0xa6ac17?util['inspect'](_0xa6ac17,{'showHidden':![],'depth':null}):'');};exports[_0x060b('0xb')]=function(_0x1bbc0f,_0x160fed){return client[_0x060b('0xb')](_0x1bbc0f,{'body':_0x160fed})['then'](function(_0x451ffd){logger[_0x060b('0x8')](_0x060b('0xc'),_0x1bbc0f,_0x451ffd?util[_0x060b('0x9')](_0x451ffd,{'showHidden':![],'depth':null}):'');})[_0x060b('0xd')](function(_0x570065){logger['error']('[utils][request]\x20name:%s',_0x1bbc0f,_0x570065?util[_0x060b('0x9')](_0x570065,{'showHidden':![],'depth':null}):'');});};function getUser(_0x1c3796){return client[_0x060b('0xb')](_0x060b('0xe'),{'options':{'raw':!![],'attributes':['id',_0x060b('0xf'),_0x060b('0x10'),_0x060b('0x11')],'where':_0x1c3796,'limit':0x1}})['then'](function(_0x4190b5){logger[_0x060b('0x8')](_0x060b('0x12'),JSON[_0x060b('0x13')](_0x1c3796),_0x4190b5?util[_0x060b('0x9')](_0x4190b5,{'showHidden':![],'depth':null}):'');return _0x4190b5['result'][_0x060b('0x14')]?_0x4190b5[_0x060b('0x15')][0x0]:null;});}exports[_0x060b('0x16')]=function(_0x4194c9){return new BPromise(function(_0x3cce9c,_0x2f9beb){if(_0x4194c9){return getUser({'internal':_0x4194c9})[_0x060b('0x17')](function(_0x61bb65){logger['info'](_0x060b('0x18'),_0x4194c9,_0x61bb65?_0x060b('0x19'):_0x060b('0x1a'));return _0x3cce9c(_0x61bb65);})[_0x060b('0xd')](function(_0x3ef756){logger[_0x060b('0xa')]('[utils][getUserByInternal]',_0x3ef756?util[_0x060b('0x9')](_0x3ef756,{'showHidden':![],'depth':null}):'');return _0x3cce9c(null);});}return _0x3cce9c(null);});};exports[_0x060b('0x1b')]=function(_0x31d8b6){return new BPromise(function(_0x2572bb,_0x26215f){if(_0x31d8b6){return getUser({'interface':_0x31d8b6})[_0x060b('0x17')](function(_0x94d29e){logger[_0x060b('0x7')](_0x060b('0x1c'),_0x31d8b6,_0x94d29e?_0x060b('0x19'):_0x060b('0x1a'));return _0x2572bb(_0x94d29e);})[_0x060b('0xd')](function(_0x340b73){logger[_0x060b('0xa')]('[utils][getUserByInterface]',_0x340b73?util[_0x060b('0x9')](_0x340b73,{'showHidden':![],'depth':null}):'');return _0x2572bb(null);});}return _0x2572bb(null);});};exports[_0x060b('0x1d')]=function(_0x16aa9a){return new BPromise(function(_0x28b4f9,_0x5d129b){if(_0x16aa9a){return getUser({'name':_0x16aa9a})[_0x060b('0x17')](function(_0x2dbff7){logger[_0x060b('0x7')](_0x060b('0x1e'),_0x16aa9a,_0x2dbff7?'found':_0x060b('0x1a'));return _0x28b4f9(_0x2dbff7);})['catch'](function(_0xea3717){logger[_0x060b('0xa')](_0x060b('0x1f'),_0xea3717?util[_0x060b('0x9')](_0xea3717,{'showHidden':![],'depth':null}):'');return _0x28b4f9(null);});}return _0x28b4f9(null);});};exports[_0x060b('0x20')]=function(_0x5b3c8b){return new BPromise(function(_0x524293,_0x2a3523){if(_0x5b3c8b){return client[_0x060b('0xb')](_0x060b('0x21'),{'options':{'raw':!![],'attributes':['id',_0x060b('0x10'),_0x060b('0x22'),'acw',_0x060b('0x23')],'where':{'name':_0x5b3c8b},'limit':0x1}})[_0x060b('0x17')](function(_0x39536d){logger[_0x060b('0x8')](_0x060b('0x24'),_0x5b3c8b,_0x39536d?util[_0x060b('0x9')](_0x39536d,{'showHidden':![],'depth':null}):'');logger[_0x060b('0x7')](_0x060b('0x25'),_0x5b3c8b,_0x39536d?_0x060b('0x19'):_0x060b('0x1a'));return _0x524293(_0x39536d['result'][_0x060b('0x14')]?_0x39536d['result'][0x0]:null);})[_0x060b('0xd')](function(_0x110d05){logger['error']('[utils][getVoiceQueueByName]',_0x110d05?util['inspect'](_0x110d05,{'showHidden':![],'depth':null}):'');return _0x524293(null);});}return _0x524293(null);});};exports['addTime']=function(_0x435078,_0x19edbf){return moment(_0x435078)['add'](_0x19edbf,'seconds')[_0x060b('0x26')](_0x060b('0x27'));};exports[_0x060b('0x28')]=function(_0xaadc9a,_0x51903c){return moment(_0xaadc9a)['subtract'](_0x51903c,_0x060b('0x29'))[_0x060b('0x26')](_0x060b('0x27'));};exports['diffTime']=function(_0x349f81,_0x3241e9){return moment(_0x349f81)[_0x060b('0x2a')](moment(_0x3241e9),_0x060b('0x29'));};exports[_0x060b('0x2b')]=function(_0x4d25aa,_0x541fd6){return parseInt(_0x4d25aa,0xa)+parseInt(_0x541fd6,0xa);};exports[_0x060b('0x2c')]=function(){return moment()['format'](_0x060b('0x27'));};exports['isAfter']=function(_0x2125a2,_0x34491d){if(_0x34491d){return moment(_0x2125a2)[_0x060b('0x2d')](_0x34491d);}return!![];};exports[_0x060b('0x2e')]=function(_0x286706,_0x5e4240){if(_0x5e4240){return moment(_0x286706)['isBefore'](_0x5e4240);}else if(_0x286706){return!![];}return![];};