c98c502403624003e42a60e512d137bc73427499
[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 _0xb27f=['isBefore','bluebird','jayson/promise','moment','util','client','http','xdr','info','inspect','debug','error','request','then','[utils][request]\x20name:%s','catch','GetUser','internal','interface','[utils][getUser]\x20where:%s','stringify','length','result','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','name','type','[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'];(function(_0x269ee8,_0x477226){var _0x4d98bd=function(_0x20d4c4){while(--_0x20d4c4){_0x269ee8['push'](_0x269ee8['shift']());}};_0x4d98bd(++_0x477226);}(_0xb27f,0x67));var _0xfb27=function(_0x3f3adc,_0x12f0f1){_0x3f3adc=_0x3f3adc-0x0;var _0x414332=_0xb27f[_0x3f3adc];return _0x414332;};'use strict';var BPromise=require(_0xfb27('0x0'));var jayson=require(_0xfb27('0x1'));var moment=require(_0xfb27('0x2'));var util=require(_0xfb27('0x3'));var client=jayson[_0xfb27('0x4')][_0xfb27('0x5')]({'port':0x2329});var logger=require('../../config/logger')(_0xfb27('0x6'));exports[_0xfb27('0x7')]=function(_0x56051f,_0x3c2b6d){logger[_0xfb27('0x7')](_0x56051f,_0x3c2b6d?util[_0xfb27('0x8')](_0x3c2b6d,{'showHidden':![],'depth':null}):'');};exports[_0xfb27('0x9')]=function(_0x106cb1,_0x178a5a){logger['debug'](_0x106cb1,_0x178a5a?util[_0xfb27('0x8')](_0x178a5a,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x5a8986,_0x391709){logger[_0xfb27('0xa')](_0x5a8986,_0x391709?util['inspect'](_0x391709,{'showHidden':![],'depth':null}):'');};exports[_0xfb27('0xb')]=function(_0x17eadf,_0x5771e8){return client[_0xfb27('0xb')](_0x17eadf,{'body':_0x5771e8})[_0xfb27('0xc')](function(_0x178995){logger[_0xfb27('0x9')](_0xfb27('0xd'),_0x17eadf,_0x178995?util[_0xfb27('0x8')](_0x178995,{'showHidden':![],'depth':null}):'');})[_0xfb27('0xe')](function(_0x1b2058){logger['error']('[utils][request]\x20name:%s',_0x17eadf,_0x1b2058?util[_0xfb27('0x8')](_0x1b2058,{'showHidden':![],'depth':null}):'');});};function getUser(_0x5d7603){return client[_0xfb27('0xb')](_0xfb27('0xf'),{'options':{'raw':!![],'attributes':['id',_0xfb27('0x10'),'name',_0xfb27('0x11')],'where':_0x5d7603,'limit':0x1}})[_0xfb27('0xc')](function(_0x1dd78a){logger[_0xfb27('0x9')](_0xfb27('0x12'),JSON[_0xfb27('0x13')](_0x5d7603),_0x1dd78a?util['inspect'](_0x1dd78a,{'showHidden':![],'depth':null}):'');return _0x1dd78a['result'][_0xfb27('0x14')]?_0x1dd78a[_0xfb27('0x15')][0x0]:null;});}exports[_0xfb27('0x16')]=function(_0x50336d){return new BPromise(function(_0x31fe39,_0x5b93d8){if(_0x50336d){return getUser({'internal':_0x50336d})[_0xfb27('0xc')](function(_0xdcabac){logger[_0xfb27('0x7')](_0xfb27('0x17'),_0x50336d,_0xdcabac?_0xfb27('0x18'):_0xfb27('0x19'));return _0x31fe39(_0xdcabac);})[_0xfb27('0xe')](function(_0x430500){logger[_0xfb27('0xa')](_0xfb27('0x1a'),_0x430500?util[_0xfb27('0x8')](_0x430500,{'showHidden':![],'depth':null}):'');return _0x31fe39(null);});}return _0x31fe39(null);});};exports[_0xfb27('0x1b')]=function(_0x30ba88){return new BPromise(function(_0x5487e3,_0x31c6cf){if(_0x30ba88){return getUser({'interface':_0x30ba88})[_0xfb27('0xc')](function(_0x4d40e1){logger['info'](_0xfb27('0x1c'),_0x30ba88,_0x4d40e1?_0xfb27('0x18'):_0xfb27('0x19'));return _0x5487e3(_0x4d40e1);})[_0xfb27('0xe')](function(_0xac56a){logger[_0xfb27('0xa')]('[utils][getUserByInterface]',_0xac56a?util[_0xfb27('0x8')](_0xac56a,{'showHidden':![],'depth':null}):'');return _0x5487e3(null);});}return _0x5487e3(null);});};exports[_0xfb27('0x1d')]=function(_0x444e32){return new BPromise(function(_0x5b732c,_0x5a4fa2){if(_0x444e32){return getUser({'name':_0x444e32})[_0xfb27('0xc')](function(_0x26180e){logger[_0xfb27('0x7')](_0xfb27('0x1e'),_0x444e32,_0x26180e?_0xfb27('0x18'):'notfound');return _0x5b732c(_0x26180e);})[_0xfb27('0xe')](function(_0x45a338){logger[_0xfb27('0xa')](_0xfb27('0x1f'),_0x45a338?util['inspect'](_0x45a338,{'showHidden':![],'depth':null}):'');return _0x5b732c(null);});}return _0x5b732c(null);});};exports[_0xfb27('0x20')]=function(_0x356c73){return new BPromise(function(_0x3677ce,_0xd01cde){if(_0x356c73){return client['request'](_0xfb27('0x21'),{'options':{'raw':!![],'attributes':['id',_0xfb27('0x22'),_0xfb27('0x23'),'acw','acwTimeout'],'where':{'name':_0x356c73},'limit':0x1}})[_0xfb27('0xc')](function(_0x5d930f){logger['debug']('[utils][getVoiceQueueByName]\x20name:%s',_0x356c73,_0x5d930f?util['inspect'](_0x5d930f,{'showHidden':![],'depth':null}):'');logger[_0xfb27('0x7')](_0xfb27('0x24'),_0x356c73,_0x5d930f?'found':_0xfb27('0x19'));return _0x3677ce(_0x5d930f[_0xfb27('0x15')][_0xfb27('0x14')]?_0x5d930f[_0xfb27('0x15')][0x0]:null);})[_0xfb27('0xe')](function(_0x1b5326){logger['error'](_0xfb27('0x25'),_0x1b5326?util[_0xfb27('0x8')](_0x1b5326,{'showHidden':![],'depth':null}):'');return _0x3677ce(null);});}return _0x3677ce(null);});};exports[_0xfb27('0x26')]=function(_0x443be3,_0x38c022){return moment(_0x443be3)[_0xfb27('0x27')](_0x38c022,_0xfb27('0x28'))[_0xfb27('0x29')](_0xfb27('0x2a'));};exports[_0xfb27('0x2b')]=function(_0x3924ef,_0x22b34f){return moment(_0x3924ef)[_0xfb27('0x2c')](_0x22b34f,_0xfb27('0x28'))[_0xfb27('0x29')](_0xfb27('0x2a'));};exports[_0xfb27('0x2d')]=function(_0x12fcdb,_0x288777){return moment(_0x12fcdb)[_0xfb27('0x2e')](moment(_0x288777),_0xfb27('0x28'));};exports[_0xfb27('0x2f')]=function(_0x2b1e1f,_0x1ddf78){return parseInt(_0x2b1e1f,0xa)+parseInt(_0x1ddf78,0xa);};exports[_0xfb27('0x30')]=function(){return moment()['format'](_0xfb27('0x2a'));};exports[_0xfb27('0x31')]=function(_0x534864,_0x4237f9){if(_0x4237f9){return moment(_0x534864)['isAfter'](_0x4237f9);}return!![];};exports[_0xfb27('0x32')]=function(_0x4f87b5,_0x25e98b){if(_0x25e98b){return moment(_0x4f87b5)[_0xfb27('0x32')](_0x25e98b);}else if(_0x4f87b5){return!![];}return![];};