fa4f7738964eca21a50f075098766c2be5e21472
[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 _0xc926=['error','request','then','catch','[utils][request]\x20name:%s','GetUser','internal','name','interface','[utils][getUser]\x20where:%s','stringify','result','length','getUserByInternal','notfound','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','found','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','getVoiceQueueByName','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]','addTime','add','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','seconds','diffTime','diff','now','isBefore','bluebird','jayson/promise','util','http','../../config/logger','info','debug','inspect'];(function(_0x11dc93,_0x54f49a){var _0x58680e=function(_0x326fd4){while(--_0x326fd4){_0x11dc93['push'](_0x11dc93['shift']());}};_0x58680e(++_0x54f49a);}(_0xc926,0x196));var _0x6c92=function(_0x47d52d,_0x3c9536){_0x47d52d=_0x47d52d-0x0;var _0x5f4986=_0xc926[_0x47d52d];return _0x5f4986;};'use strict';var BPromise=require(_0x6c92('0x0'));var jayson=require(_0x6c92('0x1'));var moment=require('moment');var util=require(_0x6c92('0x2'));var client=jayson['client'][_0x6c92('0x3')]({'port':0x2329});var logger=require(_0x6c92('0x4'))('xdr');exports['info']=function(_0x5c76d6,_0x157c27){logger[_0x6c92('0x5')](_0x5c76d6,_0x157c27?util['inspect'](_0x157c27,{'showHidden':![],'depth':null}):'');};exports[_0x6c92('0x6')]=function(_0x413407,_0x3833b4){logger['debug'](_0x413407,_0x3833b4?util[_0x6c92('0x7')](_0x3833b4,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x57eafb,_0x3b753c){logger[_0x6c92('0x8')](_0x57eafb,_0x3b753c?util[_0x6c92('0x7')](_0x3b753c,{'showHidden':![],'depth':null}):'');};exports[_0x6c92('0x9')]=function(_0x462764,_0x4930ad){return client['request'](_0x462764,{'body':_0x4930ad})[_0x6c92('0xa')](function(_0x191a41){logger[_0x6c92('0x6')]('[utils][request]\x20name:%s',_0x462764,_0x191a41?util[_0x6c92('0x7')](_0x191a41,{'showHidden':![],'depth':null}):'');})[_0x6c92('0xb')](function(_0x245633){logger['error'](_0x6c92('0xc'),_0x462764,_0x245633?util['inspect'](_0x245633,{'showHidden':![],'depth':null}):'');});};function getUser(_0x287bd6){return client[_0x6c92('0x9')](_0x6c92('0xd'),{'options':{'raw':!![],'attributes':['id',_0x6c92('0xe'),_0x6c92('0xf'),_0x6c92('0x10')],'where':_0x287bd6,'limit':0x1}})[_0x6c92('0xa')](function(_0x28e8b2){logger[_0x6c92('0x6')](_0x6c92('0x11'),JSON[_0x6c92('0x12')](_0x287bd6),_0x28e8b2?util[_0x6c92('0x7')](_0x28e8b2,{'showHidden':![],'depth':null}):'');return _0x28e8b2[_0x6c92('0x13')][_0x6c92('0x14')]?_0x28e8b2[_0x6c92('0x13')][0x0]:null;});}exports[_0x6c92('0x15')]=function(_0x446032){return new BPromise(function(_0x276196,_0x2a7571){if(_0x446032){return getUser({'internal':_0x446032})[_0x6c92('0xa')](function(_0x200f38){logger[_0x6c92('0x5')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x446032,_0x200f38?'found':_0x6c92('0x16'));return _0x276196(_0x200f38);})[_0x6c92('0xb')](function(_0xac1b65){logger['error']('[utils][getUserByInternal]',_0xac1b65?util[_0x6c92('0x7')](_0xac1b65,{'showHidden':![],'depth':null}):'');return _0x276196(null);});}return _0x276196(null);});};exports[_0x6c92('0x17')]=function(_0xf2e0b4){return new BPromise(function(_0x4da864,_0x2a73f3){if(_0xf2e0b4){return getUser({'interface':_0xf2e0b4})[_0x6c92('0xa')](function(_0x4164f1){logger[_0x6c92('0x5')](_0x6c92('0x18'),_0xf2e0b4,_0x4164f1?_0x6c92('0x19'):'notfound');return _0x4da864(_0x4164f1);})[_0x6c92('0xb')](function(_0x5d6eb6){logger['error'](_0x6c92('0x1a'),_0x5d6eb6?util[_0x6c92('0x7')](_0x5d6eb6,{'showHidden':![],'depth':null}):'');return _0x4da864(null);});}return _0x4da864(null);});};exports[_0x6c92('0x1b')]=function(_0x1c43bc){return new BPromise(function(_0x402eb9,_0x50333f){if(_0x1c43bc){return getUser({'name':_0x1c43bc})[_0x6c92('0xa')](function(_0x250f89){logger[_0x6c92('0x5')](_0x6c92('0x1c'),_0x1c43bc,_0x250f89?_0x6c92('0x19'):'notfound');return _0x402eb9(_0x250f89);})[_0x6c92('0xb')](function(_0x61bd6b){logger['error']('[utils][getUserByName]',_0x61bd6b?util[_0x6c92('0x7')](_0x61bd6b,{'showHidden':![],'depth':null}):'');return _0x402eb9(null);});}return _0x402eb9(null);});};exports[_0x6c92('0x1d')]=function(_0x19ceb1){return new BPromise(function(_0x3ea21c,_0x34353b){if(_0x19ceb1){return client[_0x6c92('0x9')](_0x6c92('0x1e'),{'options':{'raw':!![],'attributes':['id',_0x6c92('0xf'),_0x6c92('0x1f'),_0x6c92('0x20'),_0x6c92('0x21')],'where':{'name':_0x19ceb1},'limit':0x1}})[_0x6c92('0xa')](function(_0x1cbaf7){logger['debug'](_0x6c92('0x22'),_0x19ceb1,_0x1cbaf7?util[_0x6c92('0x7')](_0x1cbaf7,{'showHidden':![],'depth':null}):'');logger[_0x6c92('0x5')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0x19ceb1,_0x1cbaf7?_0x6c92('0x19'):_0x6c92('0x16'));return _0x3ea21c(_0x1cbaf7[_0x6c92('0x13')][_0x6c92('0x14')]?_0x1cbaf7[_0x6c92('0x13')][0x0]:null);})[_0x6c92('0xb')](function(_0x2c8d84){logger['error'](_0x6c92('0x23'),_0x2c8d84?util[_0x6c92('0x7')](_0x2c8d84,{'showHidden':![],'depth':null}):'');return _0x3ea21c(null);});}return _0x3ea21c(null);});};exports[_0x6c92('0x24')]=function(_0x5122df,_0x2cd8ff){return moment(_0x5122df)[_0x6c92('0x25')](_0x2cd8ff,'seconds')[_0x6c92('0x26')](_0x6c92('0x27'));};exports[_0x6c92('0x28')]=function(_0x129996,_0x529b2e){return moment(_0x129996)['subtract'](_0x529b2e,_0x6c92('0x29'))[_0x6c92('0x26')](_0x6c92('0x27'));};exports[_0x6c92('0x2a')]=function(_0x4d3492,_0x164a22){return moment(_0x4d3492)[_0x6c92('0x2b')](moment(_0x164a22),_0x6c92('0x29'));};exports['sumTime']=function(_0x5d9969,_0x5e9ed6){return parseInt(_0x5d9969,0xa)+parseInt(_0x5e9ed6,0xa);};exports[_0x6c92('0x2c')]=function(){return moment()[_0x6c92('0x26')](_0x6c92('0x27'));};exports['isAfter']=function(_0x40a208,_0x27e471){if(_0x27e471){return moment(_0x40a208)['isAfter'](_0x27e471);}return!![];};exports[_0x6c92('0x2d')]=function(_0x3126ac,_0xd9ceee){if(_0xd9ceee){return moment(_0x3126ac)[_0x6c92('0x2d')](_0xd9ceee);}else if(_0x3126ac){return!![];}return![];};