Built motion from commit d9028345.|2.5.43
[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 _0x7f73=['bluebird','jayson/promise','util','client','http','xdr','info','inspect','debug','error','request','then','[utils][request]\x20name:%s','internal','name','interface','[utils][getUser]\x20where:%s','stringify','result','length','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','found','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','notfound','catch','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','getVoiceQueueByName','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','[utils][getVoiceQueueByName]','addTime','seconds','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','format','diffTime','diff','sumTime','now','isAfter','isBefore'];(function(_0x58afd5,_0x534a48){var _0x3e503b=function(_0x27ba44){while(--_0x27ba44){_0x58afd5['push'](_0x58afd5['shift']());}};_0x3e503b(++_0x534a48);}(_0x7f73,0xfa));var _0x37f7=function(_0x1cd1b4,_0x367e20){_0x1cd1b4=_0x1cd1b4-0x0;var _0x170d0f=_0x7f73[_0x1cd1b4];return _0x170d0f;};'use strict';var BPromise=require(_0x37f7('0x0'));var jayson=require(_0x37f7('0x1'));var moment=require('moment');var util=require(_0x37f7('0x2'));var client=jayson[_0x37f7('0x3')][_0x37f7('0x4')]({'port':0x2329});var logger=require('../../config/logger')(_0x37f7('0x5'));exports[_0x37f7('0x6')]=function(_0x412bc7,_0x19f16c){logger[_0x37f7('0x6')](_0x412bc7,_0x19f16c?util[_0x37f7('0x7')](_0x19f16c,{'showHidden':![],'depth':null}):'');};exports[_0x37f7('0x8')]=function(_0x5e7831,_0x2f5f79){logger['debug'](_0x5e7831,_0x2f5f79?util['inspect'](_0x2f5f79,{'showHidden':![],'depth':null}):'');};exports[_0x37f7('0x9')]=function(_0x239691,_0x41c84c){logger['error'](_0x239691,_0x41c84c?util['inspect'](_0x41c84c,{'showHidden':![],'depth':null}):'');};exports[_0x37f7('0xa')]=function(_0x412f80,_0x26236d){return client[_0x37f7('0xa')](_0x412f80,{'body':_0x26236d})[_0x37f7('0xb')](function(_0x1e7b32){logger['debug']('[utils][request]\x20name:%s',_0x412f80,_0x1e7b32?util[_0x37f7('0x7')](_0x1e7b32,{'showHidden':![],'depth':null}):'');})['catch'](function(_0xcefe42){logger[_0x37f7('0x9')](_0x37f7('0xc'),_0x412f80,_0xcefe42?util['inspect'](_0xcefe42,{'showHidden':![],'depth':null}):'');});};function getUser(_0x16ca86){return client['request']('GetUser',{'options':{'raw':!![],'attributes':['id',_0x37f7('0xd'),_0x37f7('0xe'),_0x37f7('0xf')],'where':_0x16ca86,'limit':0x1}})[_0x37f7('0xb')](function(_0x3264df){logger['debug'](_0x37f7('0x10'),JSON[_0x37f7('0x11')](_0x16ca86),_0x3264df?util['inspect'](_0x3264df,{'showHidden':![],'depth':null}):'');return _0x3264df[_0x37f7('0x12')][_0x37f7('0x13')]?_0x3264df['result'][0x0]:null;});}exports[_0x37f7('0x14')]=function(_0x1b7916){return new BPromise(function(_0xcaa401,_0x56e684){if(_0x1b7916){return getUser({'internal':_0x1b7916})[_0x37f7('0xb')](function(_0x2b1a38){logger['info'](_0x37f7('0x15'),_0x1b7916,_0x2b1a38?_0x37f7('0x16'):'notfound');return _0xcaa401(_0x2b1a38);})['catch'](function(_0x5088e9){logger[_0x37f7('0x9')](_0x37f7('0x17'),_0x5088e9?util[_0x37f7('0x7')](_0x5088e9,{'showHidden':![],'depth':null}):'');return _0xcaa401(null);});}return _0xcaa401(null);});};exports[_0x37f7('0x18')]=function(_0x1733ce){return new BPromise(function(_0x55eac1,_0xe04517){if(_0x1733ce){return getUser({'interface':_0x1733ce})[_0x37f7('0xb')](function(_0x19ba27){logger['info'](_0x37f7('0x19'),_0x1733ce,_0x19ba27?_0x37f7('0x16'):_0x37f7('0x1a'));return _0x55eac1(_0x19ba27);})[_0x37f7('0x1b')](function(_0x2d8138){logger[_0x37f7('0x9')]('[utils][getUserByInterface]',_0x2d8138?util[_0x37f7('0x7')](_0x2d8138,{'showHidden':![],'depth':null}):'');return _0x55eac1(null);});}return _0x55eac1(null);});};exports[_0x37f7('0x1c')]=function(_0x50fa6b){return new BPromise(function(_0x350d71,_0x408dfa){if(_0x50fa6b){return getUser({'name':_0x50fa6b})['then'](function(_0x27436e){logger[_0x37f7('0x6')](_0x37f7('0x1d'),_0x50fa6b,_0x27436e?'found':_0x37f7('0x1a'));return _0x350d71(_0x27436e);})[_0x37f7('0x1b')](function(_0x4f6007){logger[_0x37f7('0x9')]('[utils][getUserByName]',_0x4f6007?util['inspect'](_0x4f6007,{'showHidden':![],'depth':null}):'');return _0x350d71(null);});}return _0x350d71(null);});};exports[_0x37f7('0x1e')]=function(_0x2e8cba){return new BPromise(function(_0x219790,_0x1c4a5b){if(_0x2e8cba){return client[_0x37f7('0xa')](_0x37f7('0x1f'),{'options':{'raw':!![],'attributes':['id',_0x37f7('0xe'),_0x37f7('0x20'),_0x37f7('0x21'),_0x37f7('0x22')],'where':{'name':_0x2e8cba},'limit':0x1}})[_0x37f7('0xb')](function(_0x417468){logger[_0x37f7('0x8')](_0x37f7('0x23'),_0x2e8cba,_0x417468?util[_0x37f7('0x7')](_0x417468,{'showHidden':![],'depth':null}):'');logger['info'](_0x37f7('0x24'),_0x2e8cba,_0x417468?_0x37f7('0x16'):_0x37f7('0x1a'));return _0x219790(_0x417468[_0x37f7('0x12')]['length']?_0x417468['result'][0x0]:null);})[_0x37f7('0x1b')](function(_0x379855){logger['error'](_0x37f7('0x25'),_0x379855?util['inspect'](_0x379855,{'showHidden':![],'depth':null}):'');return _0x219790(null);});}return _0x219790(null);});};exports[_0x37f7('0x26')]=function(_0x3fedbf,_0x3dd942){return moment(_0x3fedbf)['add'](_0x3dd942,_0x37f7('0x27'))['format'](_0x37f7('0x28'));};exports[_0x37f7('0x29')]=function(_0x3d5e91,_0x4aada3){return moment(_0x3d5e91)[_0x37f7('0x2a')](_0x4aada3,_0x37f7('0x27'))[_0x37f7('0x2b')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x37f7('0x2c')]=function(_0xa976e7,_0x283a8e){return moment(_0xa976e7)[_0x37f7('0x2d')](moment(_0x283a8e),'seconds');};exports[_0x37f7('0x2e')]=function(_0x433431,_0x3a7913){return parseInt(_0x433431,0xa)+parseInt(_0x3a7913,0xa);};exports[_0x37f7('0x2f')]=function(){return moment()[_0x37f7('0x2b')](_0x37f7('0x28'));};exports[_0x37f7('0x30')]=function(_0x5b21d7,_0xdaac8){if(_0xdaac8){return moment(_0x5b21d7)[_0x37f7('0x30')](_0xdaac8);}return!![];};exports[_0x37f7('0x31')]=function(_0x29898b,_0xdf9fc9){if(_0xdf9fc9){return moment(_0x29898b)[_0x37f7('0x31')](_0xdf9fc9);}else if(_0x29898b){return!![];}return![];};