8f72bab82b1556407f9a135a35cbb0260036d8c1
[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 _0x9686=['error','request','then','[utils][request]\x20name:%s','GetUser','name','interface','[utils][getUser]\x20where:%s','stringify','result','length','info','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','catch','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','getVoiceQueueByName','GetVoiceQueue','type','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','[utils][getVoiceQueueByName]','addTime','add','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diffTime','diff','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','moment','client','http','../../config/logger','inspect','debug'];(function(_0x801bc1,_0x2cc369){var _0x3ff676=function(_0x558fb0){while(--_0x558fb0){_0x801bc1['push'](_0x801bc1['shift']());}};_0x3ff676(++_0x2cc369);}(_0x9686,0xbc));var _0x6968=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x9686[_0x3dd15e];return _0x231fd0;};'use strict';var BPromise=require(_0x6968('0x0'));var jayson=require(_0x6968('0x1'));var moment=require(_0x6968('0x2'));var util=require('util');var client=jayson[_0x6968('0x3')][_0x6968('0x4')]({'port':0x2329});var logger=require(_0x6968('0x5'))('xdr');exports['info']=function(_0x3bb594,_0x460875){logger['info'](_0x3bb594,_0x460875?util[_0x6968('0x6')](_0x460875,{'showHidden':![],'depth':null}):'');};exports[_0x6968('0x7')]=function(_0x475b2d,_0x28a202){logger[_0x6968('0x7')](_0x475b2d,_0x28a202?util[_0x6968('0x6')](_0x28a202,{'showHidden':![],'depth':null}):'');};exports[_0x6968('0x8')]=function(_0x2fa595,_0x159b8e){logger[_0x6968('0x8')](_0x2fa595,_0x159b8e?util['inspect'](_0x159b8e,{'showHidden':![],'depth':null}):'');};exports[_0x6968('0x9')]=function(_0x408bd9,_0x4338d8){return client[_0x6968('0x9')](_0x408bd9,{'body':_0x4338d8})[_0x6968('0xa')](function(_0x297283){logger[_0x6968('0x7')](_0x6968('0xb'),_0x408bd9,_0x297283?util[_0x6968('0x6')](_0x297283,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x399e3b){logger[_0x6968('0x8')]('[utils][request]\x20name:%s',_0x408bd9,_0x399e3b?util[_0x6968('0x6')](_0x399e3b,{'showHidden':![],'depth':null}):'');});};function getUser(_0x2dcc9b){return client['request'](_0x6968('0xc'),{'options':{'raw':!![],'attributes':['id','internal',_0x6968('0xd'),_0x6968('0xe')],'where':_0x2dcc9b,'limit':0x1}})[_0x6968('0xa')](function(_0x41ced7){logger[_0x6968('0x7')](_0x6968('0xf'),JSON[_0x6968('0x10')](_0x2dcc9b),_0x41ced7?util[_0x6968('0x6')](_0x41ced7,{'showHidden':![],'depth':null}):'');return _0x41ced7[_0x6968('0x11')][_0x6968('0x12')]?_0x41ced7[_0x6968('0x11')][0x0]:null;});}exports['getUserByInternal']=function(_0x28d93d){return new BPromise(function(_0x4fc2f7,_0x4b2af9){if(_0x28d93d){return getUser({'internal':_0x28d93d})[_0x6968('0xa')](function(_0x47fa79){logger[_0x6968('0x13')](_0x6968('0x14'),_0x28d93d,_0x47fa79?_0x6968('0x15'):_0x6968('0x16'));return _0x4fc2f7(_0x47fa79);})[_0x6968('0x17')](function(_0xd68d9){logger['error']('[utils][getUserByInternal]',_0xd68d9?util[_0x6968('0x6')](_0xd68d9,{'showHidden':![],'depth':null}):'');return _0x4fc2f7(null);});}return _0x4fc2f7(null);});};exports[_0x6968('0x18')]=function(_0x571f34){return new BPromise(function(_0x35fd20,_0x38ca05){if(_0x571f34){return getUser({'interface':_0x571f34})['then'](function(_0x52ea30){logger[_0x6968('0x13')](_0x6968('0x19'),_0x571f34,_0x52ea30?'found':_0x6968('0x16'));return _0x35fd20(_0x52ea30);})[_0x6968('0x17')](function(_0x459898){logger[_0x6968('0x8')](_0x6968('0x1a'),_0x459898?util[_0x6968('0x6')](_0x459898,{'showHidden':![],'depth':null}):'');return _0x35fd20(null);});}return _0x35fd20(null);});};exports[_0x6968('0x1b')]=function(_0x4a2816){return new BPromise(function(_0x5956bc,_0x4cee29){if(_0x4a2816){return getUser({'name':_0x4a2816})[_0x6968('0xa')](function(_0x4cfc9a){logger[_0x6968('0x13')](_0x6968('0x1c'),_0x4a2816,_0x4cfc9a?_0x6968('0x15'):'notfound');return _0x5956bc(_0x4cfc9a);})[_0x6968('0x17')](function(_0x53f226){logger[_0x6968('0x8')]('[utils][getUserByName]',_0x53f226?util[_0x6968('0x6')](_0x53f226,{'showHidden':![],'depth':null}):'');return _0x5956bc(null);});}return _0x5956bc(null);});};exports[_0x6968('0x1d')]=function(_0x5f5c7d){return new BPromise(function(_0x4ecab8,_0x4563a0){if(_0x5f5c7d){return client[_0x6968('0x9')](_0x6968('0x1e'),{'options':{'raw':!![],'attributes':['id',_0x6968('0xd'),_0x6968('0x1f'),'acw',_0x6968('0x20')],'where':{'name':_0x5f5c7d},'limit':0x1}})[_0x6968('0xa')](function(_0x2ffe0d){logger[_0x6968('0x7')](_0x6968('0x21'),_0x5f5c7d,_0x2ffe0d?util[_0x6968('0x6')](_0x2ffe0d,{'showHidden':![],'depth':null}):'');logger[_0x6968('0x13')](_0x6968('0x22'),_0x5f5c7d,_0x2ffe0d?_0x6968('0x15'):'notfound');return _0x4ecab8(_0x2ffe0d[_0x6968('0x11')][_0x6968('0x12')]?_0x2ffe0d[_0x6968('0x11')][0x0]:null);})[_0x6968('0x17')](function(_0x23bbeb){logger[_0x6968('0x8')](_0x6968('0x23'),_0x23bbeb?util[_0x6968('0x6')](_0x23bbeb,{'showHidden':![],'depth':null}):'');return _0x4ecab8(null);});}return _0x4ecab8(null);});};exports[_0x6968('0x24')]=function(_0x2c098a,_0x132fec){return moment(_0x2c098a)[_0x6968('0x25')](_0x132fec,_0x6968('0x26'))[_0x6968('0x27')](_0x6968('0x28'));};exports[_0x6968('0x29')]=function(_0x326f4b,_0x5e99d1){return moment(_0x326f4b)[_0x6968('0x2a')](_0x5e99d1,_0x6968('0x26'))['format'](_0x6968('0x28'));};exports[_0x6968('0x2b')]=function(_0x54bc40,_0x468f9d){return moment(_0x54bc40)[_0x6968('0x2c')](moment(_0x468f9d),_0x6968('0x26'));};exports[_0x6968('0x2d')]=function(_0x3ad382,_0x4db8f0){return parseInt(_0x3ad382,0xa)+parseInt(_0x4db8f0,0xa);};exports[_0x6968('0x2e')]=function(){return moment()[_0x6968('0x27')](_0x6968('0x28'));};exports[_0x6968('0x2f')]=function(_0x260cb0,_0x5c964b){if(_0x5c964b){return moment(_0x260cb0)[_0x6968('0x2f')](_0x5c964b);}return!![];};exports[_0x6968('0x30')]=function(_0x4546d5,_0x529fb7){if(_0x529fb7){return moment(_0x4546d5)[_0x6968('0x30')](_0x529fb7);}else if(_0x4546d5){return!![];}return![];};