eb1d14f7f011f16f7ae767eb65cdc7dd6bd4239c
[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 _0x3c9f=['getUserByName','[utils][getUserByName]\x20name:%s\x20%s','found','getVoiceQueueByName','GetVoiceQueue','name','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','seconds','diffTime','sumTime','now','isAfter','isBefore','jayson/promise','moment','util','client','http','../../config/logger','xdr','info','inspect','debug','error','request','[utils][request]\x20name:%s','catch','internal','interface','then','[utils][getUser]\x20where:%s','result','length','getUserByInternal','notfound','getUserByInterface','[utils][getUserByInterface]'];(function(_0x396588,_0x222305){var _0x408d3b=function(_0x263eb3){while(--_0x263eb3){_0x396588['push'](_0x396588['shift']());}};_0x408d3b(++_0x222305);}(_0x3c9f,0x148));var _0xf3c9=function(_0x41b9ff,_0x5ae1dd){_0x41b9ff=_0x41b9ff-0x0;var _0x5d6352=_0x3c9f[_0x41b9ff];return _0x5d6352;};'use strict';var BPromise=require('bluebird');var jayson=require(_0xf3c9('0x0'));var moment=require(_0xf3c9('0x1'));var util=require(_0xf3c9('0x2'));var client=jayson[_0xf3c9('0x3')][_0xf3c9('0x4')]({'port':0x2329});var logger=require(_0xf3c9('0x5'))(_0xf3c9('0x6'));exports['info']=function(_0x10bc04,_0x1888d1){logger[_0xf3c9('0x7')](_0x10bc04,_0x1888d1?util[_0xf3c9('0x8')](_0x1888d1,{'showHidden':![],'depth':null}):'');};exports['debug']=function(_0x3ab952,_0x4c25c2){logger[_0xf3c9('0x9')](_0x3ab952,_0x4c25c2?util[_0xf3c9('0x8')](_0x4c25c2,{'showHidden':![],'depth':null}):'');};exports[_0xf3c9('0xa')]=function(_0x29b4af,_0x80858f){logger[_0xf3c9('0xa')](_0x29b4af,_0x80858f?util[_0xf3c9('0x8')](_0x80858f,{'showHidden':![],'depth':null}):'');};exports['request']=function(_0x513a95,_0xf4a849){return client[_0xf3c9('0xb')](_0x513a95,{'body':_0xf4a849})['then'](function(_0x34e8e6){logger[_0xf3c9('0x9')](_0xf3c9('0xc'),_0x513a95,_0x34e8e6?util['inspect'](_0x34e8e6,{'showHidden':![],'depth':null}):'');})[_0xf3c9('0xd')](function(_0xba0072){logger[_0xf3c9('0xa')](_0xf3c9('0xc'),_0x513a95,_0xba0072?util[_0xf3c9('0x8')](_0xba0072,{'showHidden':![],'depth':null}):'');});};function getUser(_0x17bcc2){return client['request']('GetUser',{'options':{'raw':!![],'attributes':['id',_0xf3c9('0xe'),'name',_0xf3c9('0xf')],'where':_0x17bcc2,'limit':0x1}})[_0xf3c9('0x10')](function(_0x1f26d4){logger['debug'](_0xf3c9('0x11'),JSON['stringify'](_0x17bcc2),_0x1f26d4?util[_0xf3c9('0x8')](_0x1f26d4,{'showHidden':![],'depth':null}):'');return _0x1f26d4[_0xf3c9('0x12')][_0xf3c9('0x13')]?_0x1f26d4[_0xf3c9('0x12')][0x0]:null;});}exports[_0xf3c9('0x14')]=function(_0xc3483d){return new BPromise(function(_0x4ba7e5,_0x871c75){if(_0xc3483d){return getUser({'internal':_0xc3483d})[_0xf3c9('0x10')](function(_0x15921f){logger[_0xf3c9('0x7')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0xc3483d,_0x15921f?'found':_0xf3c9('0x15'));return _0x4ba7e5(_0x15921f);})[_0xf3c9('0xd')](function(_0x1b9c78){logger[_0xf3c9('0xa')]('[utils][getUserByInternal]',_0x1b9c78?util['inspect'](_0x1b9c78,{'showHidden':![],'depth':null}):'');return _0x4ba7e5(null);});}return _0x4ba7e5(null);});};exports[_0xf3c9('0x16')]=function(_0x3bddd0){return new BPromise(function(_0x1a97bc,_0x4cd4f9){if(_0x3bddd0){return getUser({'interface':_0x3bddd0})[_0xf3c9('0x10')](function(_0x4a706c){logger[_0xf3c9('0x7')]('[utils][getUserByInterface]\x20interface:%s\x20%s',_0x3bddd0,_0x4a706c?'found':'notfound');return _0x1a97bc(_0x4a706c);})[_0xf3c9('0xd')](function(_0x16cd3b){logger['error'](_0xf3c9('0x17'),_0x16cd3b?util[_0xf3c9('0x8')](_0x16cd3b,{'showHidden':![],'depth':null}):'');return _0x1a97bc(null);});}return _0x1a97bc(null);});};exports[_0xf3c9('0x18')]=function(_0x3a1eec){return new BPromise(function(_0x3cb474,_0x49f93a){if(_0x3a1eec){return getUser({'name':_0x3a1eec})[_0xf3c9('0x10')](function(_0x542f60){logger[_0xf3c9('0x7')](_0xf3c9('0x19'),_0x3a1eec,_0x542f60?_0xf3c9('0x1a'):_0xf3c9('0x15'));return _0x3cb474(_0x542f60);})[_0xf3c9('0xd')](function(_0xcc4cbd){logger[_0xf3c9('0xa')]('[utils][getUserByName]',_0xcc4cbd?util[_0xf3c9('0x8')](_0xcc4cbd,{'showHidden':![],'depth':null}):'');return _0x3cb474(null);});}return _0x3cb474(null);});};exports[_0xf3c9('0x1b')]=function(_0x498320){return new BPromise(function(_0x4539c0,_0x4b616d){if(_0x498320){return client[_0xf3c9('0xb')](_0xf3c9('0x1c'),{'options':{'raw':!![],'attributes':['id',_0xf3c9('0x1d'),'type',_0xf3c9('0x1e'),_0xf3c9('0x1f')],'where':{'name':_0x498320},'limit':0x1}})[_0xf3c9('0x10')](function(_0x190b28){logger['debug'](_0xf3c9('0x20'),_0x498320,_0x190b28?util[_0xf3c9('0x8')](_0x190b28,{'showHidden':![],'depth':null}):'');logger[_0xf3c9('0x7')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0x498320,_0x190b28?_0xf3c9('0x1a'):'notfound');return _0x4539c0(_0x190b28['result']['length']?_0x190b28['result'][0x0]:null);})[_0xf3c9('0xd')](function(_0x3d8853){logger[_0xf3c9('0xa')](_0xf3c9('0x21'),_0x3d8853?util[_0xf3c9('0x8')](_0x3d8853,{'showHidden':![],'depth':null}):'');return _0x4539c0(null);});}return _0x4539c0(null);});};exports['addTime']=function(_0x388697,_0x39a6fc){return moment(_0x388697)['add'](_0x39a6fc,'seconds')[_0xf3c9('0x22')](_0xf3c9('0x23'));};exports[_0xf3c9('0x24')]=function(_0x58f764,_0x2397cb){return moment(_0x58f764)[_0xf3c9('0x25')](_0x2397cb,_0xf3c9('0x26'))[_0xf3c9('0x22')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xf3c9('0x27')]=function(_0x55c887,_0x44cb75){return moment(_0x55c887)['diff'](moment(_0x44cb75),_0xf3c9('0x26'));};exports[_0xf3c9('0x28')]=function(_0x4f56fa,_0x6e272f){return parseInt(_0x4f56fa,0xa)+parseInt(_0x6e272f,0xa);};exports[_0xf3c9('0x29')]=function(){return moment()['format'](_0xf3c9('0x23'));};exports[_0xf3c9('0x2a')]=function(_0x480423,_0x384369){if(_0x384369){return moment(_0x480423)[_0xf3c9('0x2a')](_0x384369);}return!![];};exports[_0xf3c9('0x2b')]=function(_0x58c0ef,_0x270331){if(_0x270331){return moment(_0x58c0ef)[_0xf3c9('0x2b')](_0x270331);}else if(_0x58c0ef){return!![];}return![];};