Built motion from commit 994c64e1.|2.6.1
[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 _0x094c=['then','[utils][getUser]\x20where:%s','stringify','result','length','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','found','notfound','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','getUserByName','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','name','type','acw','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','[utils][getVoiceQueueByName]','add','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diff','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','util','client','../../config/logger','xdr','info','inspect','debug','error','request','catch','[utils][request]\x20name:%s','GetUser','interface'];(function(_0x1e4e5f,_0x2ffab4){var _0x376761=function(_0x3c7f4d){while(--_0x3c7f4d){_0x1e4e5f['push'](_0x1e4e5f['shift']());}};_0x376761(++_0x2ffab4);}(_0x094c,0x7e));var _0xc094=function(_0xfa3280,_0x42246f){_0xfa3280=_0xfa3280-0x0;var _0x1d6b04=_0x094c[_0xfa3280];return _0x1d6b04;};'use strict';var BPromise=require(_0xc094('0x0'));var jayson=require(_0xc094('0x1'));var moment=require('moment');var util=require(_0xc094('0x2'));var client=jayson[_0xc094('0x3')]['http']({'port':0x2329});var logger=require(_0xc094('0x4'))(_0xc094('0x5'));exports[_0xc094('0x6')]=function(_0x1cabd7,_0x1fcdcb){logger['info'](_0x1cabd7,_0x1fcdcb?util[_0xc094('0x7')](_0x1fcdcb,{'showHidden':![],'depth':null}):'');};exports[_0xc094('0x8')]=function(_0x20ffd4,_0x457789){logger[_0xc094('0x8')](_0x20ffd4,_0x457789?util[_0xc094('0x7')](_0x457789,{'showHidden':![],'depth':null}):'');};exports[_0xc094('0x9')]=function(_0x33f12d,_0x38d97f){logger[_0xc094('0x9')](_0x33f12d,_0x38d97f?util[_0xc094('0x7')](_0x38d97f,{'showHidden':![],'depth':null}):'');};exports[_0xc094('0xa')]=function(_0x2c0793,_0x19277c){return client[_0xc094('0xa')](_0x2c0793,{'body':_0x19277c})['then'](function(_0x16b970){logger['debug']('[utils][request]\x20name:%s',_0x2c0793,_0x16b970?util[_0xc094('0x7')](_0x16b970,{'showHidden':![],'depth':null}):'');})[_0xc094('0xb')](function(_0x491810){logger[_0xc094('0x9')](_0xc094('0xc'),_0x2c0793,_0x491810?util['inspect'](_0x491810,{'showHidden':![],'depth':null}):'');});};function getUser(_0x4caa6f){return client['request'](_0xc094('0xd'),{'options':{'raw':!![],'attributes':['id','internal','name',_0xc094('0xe')],'where':_0x4caa6f,'limit':0x1}})[_0xc094('0xf')](function(_0x48bd8c){logger['debug'](_0xc094('0x10'),JSON[_0xc094('0x11')](_0x4caa6f),_0x48bd8c?util[_0xc094('0x7')](_0x48bd8c,{'showHidden':![],'depth':null}):'');return _0x48bd8c[_0xc094('0x12')][_0xc094('0x13')]?_0x48bd8c[_0xc094('0x12')][0x0]:null;});}exports[_0xc094('0x14')]=function(_0x5a6cd2){return new BPromise(function(_0x23ea73,_0x518166){if(_0x5a6cd2){return getUser({'internal':_0x5a6cd2})[_0xc094('0xf')](function(_0x3842ca){logger[_0xc094('0x6')](_0xc094('0x15'),_0x5a6cd2,_0x3842ca?_0xc094('0x16'):_0xc094('0x17'));return _0x23ea73(_0x3842ca);})[_0xc094('0xb')](function(_0x4bdf60){logger[_0xc094('0x9')]('[utils][getUserByInternal]',_0x4bdf60?util[_0xc094('0x7')](_0x4bdf60,{'showHidden':![],'depth':null}):'');return _0x23ea73(null);});}return _0x23ea73(null);});};exports[_0xc094('0x18')]=function(_0x4ffdc6){return new BPromise(function(_0x20ed5b,_0x2fcd2b){if(_0x4ffdc6){return getUser({'interface':_0x4ffdc6})[_0xc094('0xf')](function(_0xf2239f){logger[_0xc094('0x6')](_0xc094('0x19'),_0x4ffdc6,_0xf2239f?_0xc094('0x16'):_0xc094('0x17'));return _0x20ed5b(_0xf2239f);})['catch'](function(_0x438a28){logger[_0xc094('0x9')]('[utils][getUserByInterface]',_0x438a28?util[_0xc094('0x7')](_0x438a28,{'showHidden':![],'depth':null}):'');return _0x20ed5b(null);});}return _0x20ed5b(null);});};exports[_0xc094('0x1a')]=function(_0x2495e6){return new BPromise(function(_0x18c450,_0x103fcd){if(_0x2495e6){return getUser({'name':_0x2495e6})[_0xc094('0xf')](function(_0x4d90bd){logger[_0xc094('0x6')]('[utils][getUserByName]\x20name:%s\x20%s',_0x2495e6,_0x4d90bd?_0xc094('0x16'):_0xc094('0x17'));return _0x18c450(_0x4d90bd);})[_0xc094('0xb')](function(_0x37cc22){logger[_0xc094('0x9')](_0xc094('0x1b'),_0x37cc22?util['inspect'](_0x37cc22,{'showHidden':![],'depth':null}):'');return _0x18c450(null);});}return _0x18c450(null);});};exports[_0xc094('0x1c')]=function(_0x1336e7){return new BPromise(function(_0x40d9ea,_0x53123d){if(_0x1336e7){return client[_0xc094('0xa')](_0xc094('0x1d'),{'options':{'raw':!![],'attributes':['id',_0xc094('0x1e'),_0xc094('0x1f'),_0xc094('0x20'),'acwTimeout'],'where':{'name':_0x1336e7},'limit':0x1}})[_0xc094('0xf')](function(_0xc92b6a){logger['debug'](_0xc094('0x21'),_0x1336e7,_0xc92b6a?util[_0xc094('0x7')](_0xc92b6a,{'showHidden':![],'depth':null}):'');logger[_0xc094('0x6')](_0xc094('0x22'),_0x1336e7,_0xc92b6a?'found':'notfound');return _0x40d9ea(_0xc92b6a[_0xc094('0x12')][_0xc094('0x13')]?_0xc92b6a[_0xc094('0x12')][0x0]:null);})['catch'](function(_0x1a8f9c){logger[_0xc094('0x9')](_0xc094('0x23'),_0x1a8f9c?util['inspect'](_0x1a8f9c,{'showHidden':![],'depth':null}):'');return _0x40d9ea(null);});}return _0x40d9ea(null);});};exports['addTime']=function(_0x5a6f75,_0x5f7eba){return moment(_0x5a6f75)[_0xc094('0x24')](_0x5f7eba,_0xc094('0x25'))[_0xc094('0x26')](_0xc094('0x27'));};exports[_0xc094('0x28')]=function(_0x22427c,_0x26cb6a){return moment(_0x22427c)[_0xc094('0x29')](_0x26cb6a,'seconds')['format'](_0xc094('0x27'));};exports['diffTime']=function(_0x7d16f0,_0x40d5fa){return moment(_0x7d16f0)[_0xc094('0x2a')](moment(_0x40d5fa),_0xc094('0x25'));};exports[_0xc094('0x2b')]=function(_0x11e9e9,_0x22904f){return parseInt(_0x11e9e9,0xa)+parseInt(_0x22904f,0xa);};exports[_0xc094('0x2c')]=function(){return moment()[_0xc094('0x26')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xc094('0x2d')]=function(_0x5d61ce,_0x32598b){if(_0x32598b){return moment(_0x5d61ce)['isAfter'](_0x32598b);}return!![];};exports[_0xc094('0x2e')]=function(_0x4c98ad,_0x307d5b){if(_0x307d5b){return moment(_0x4c98ad)['isBefore'](_0x307d5b);}else if(_0x4c98ad){return!![];}return![];};