Built motion from commit 53172ac8.|2.6.30
[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 _0x655f=['moment','util','client','../../config/logger','xdr','info','inspect','debug','error','request','then','[utils][request]\x20name:%s','catch','GetUser','name','interface','[utils][getUser]\x20where:%s','stringify','result','length','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','notfound','[utils][getUserByInternal]','[utils][getUserByInterface]\x20interface:%s\x20%s','found','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','addTime','subtractTime','subtract','seconds','YYYY-MM-DD\x20HH:mm:ss','diffTime','diff','sumTime','now','format','isAfter','isBefore','bluebird','jayson/promise'];(function(_0x3c2a69,_0x4c8b41){var _0x596bc8=function(_0x1b4b7c){while(--_0x1b4b7c){_0x3c2a69['push'](_0x3c2a69['shift']());}};_0x596bc8(++_0x4c8b41);}(_0x655f,0xc6));var _0xf655=function(_0x277a47,_0x31bf51){_0x277a47=_0x277a47-0x0;var _0x4d86e2=_0x655f[_0x277a47];return _0x4d86e2;};'use strict';var BPromise=require(_0xf655('0x0'));var jayson=require(_0xf655('0x1'));var moment=require(_0xf655('0x2'));var util=require(_0xf655('0x3'));var client=jayson[_0xf655('0x4')]['http']({'port':0x2329});var logger=require(_0xf655('0x5'))(_0xf655('0x6'));exports[_0xf655('0x7')]=function(_0x49f8f2,_0x1bd587){logger[_0xf655('0x7')](_0x49f8f2,_0x1bd587?util[_0xf655('0x8')](_0x1bd587,{'showHidden':![],'depth':null}):'');};exports[_0xf655('0x9')]=function(_0x2ceb7f,_0x159ef0){logger[_0xf655('0x9')](_0x2ceb7f,_0x159ef0?util[_0xf655('0x8')](_0x159ef0,{'showHidden':![],'depth':null}):'');};exports['error']=function(_0x23567a,_0x59f643){logger[_0xf655('0xa')](_0x23567a,_0x59f643?util[_0xf655('0x8')](_0x59f643,{'showHidden':![],'depth':null}):'');};exports[_0xf655('0xb')]=function(_0x2016ee,_0x128d2d){return client[_0xf655('0xb')](_0x2016ee,{'body':_0x128d2d})[_0xf655('0xc')](function(_0x33c1cd){logger[_0xf655('0x9')](_0xf655('0xd'),_0x2016ee,_0x33c1cd?util['inspect'](_0x33c1cd,{'showHidden':![],'depth':null}):'');})[_0xf655('0xe')](function(_0x4ddeb7){logger[_0xf655('0xa')]('[utils][request]\x20name:%s',_0x2016ee,_0x4ddeb7?util['inspect'](_0x4ddeb7,{'showHidden':![],'depth':null}):'');});};function getUser(_0xaacf75){return client[_0xf655('0xb')](_0xf655('0xf'),{'options':{'raw':!![],'attributes':['id','internal',_0xf655('0x10'),_0xf655('0x11')],'where':_0xaacf75,'limit':0x1}})['then'](function(_0xa713c0){logger[_0xf655('0x9')](_0xf655('0x12'),JSON[_0xf655('0x13')](_0xaacf75),_0xa713c0?util[_0xf655('0x8')](_0xa713c0,{'showHidden':![],'depth':null}):'');return _0xa713c0[_0xf655('0x14')][_0xf655('0x15')]?_0xa713c0[_0xf655('0x14')][0x0]:null;});}exports[_0xf655('0x16')]=function(_0x285119){return new BPromise(function(_0x14fd84,_0x3e46f8){if(_0x285119){return getUser({'internal':_0x285119})[_0xf655('0xc')](function(_0x43096f){logger[_0xf655('0x7')](_0xf655('0x17'),_0x285119,_0x43096f?'found':_0xf655('0x18'));return _0x14fd84(_0x43096f);})[_0xf655('0xe')](function(_0x3e97a7){logger[_0xf655('0xa')](_0xf655('0x19'),_0x3e97a7?util['inspect'](_0x3e97a7,{'showHidden':![],'depth':null}):'');return _0x14fd84(null);});}return _0x14fd84(null);});};exports['getUserByInterface']=function(_0x286e37){return new BPromise(function(_0x4299da,_0x1e45bb){if(_0x286e37){return getUser({'interface':_0x286e37})[_0xf655('0xc')](function(_0x5c422e){logger['info'](_0xf655('0x1a'),_0x286e37,_0x5c422e?_0xf655('0x1b'):'notfound');return _0x4299da(_0x5c422e);})['catch'](function(_0x210636){logger[_0xf655('0xa')](_0xf655('0x1c'),_0x210636?util[_0xf655('0x8')](_0x210636,{'showHidden':![],'depth':null}):'');return _0x4299da(null);});}return _0x4299da(null);});};exports[_0xf655('0x1d')]=function(_0x609c97){return new BPromise(function(_0x2e1429,_0x500f35){if(_0x609c97){return getUser({'name':_0x609c97})['then'](function(_0x20a739){logger[_0xf655('0x7')](_0xf655('0x1e'),_0x609c97,_0x20a739?'found':_0xf655('0x18'));return _0x2e1429(_0x20a739);})[_0xf655('0xe')](function(_0xd87394){logger[_0xf655('0xa')](_0xf655('0x1f'),_0xd87394?util[_0xf655('0x8')](_0xd87394,{'showHidden':![],'depth':null}):'');return _0x2e1429(null);});}return _0x2e1429(null);});};exports[_0xf655('0x20')]=function(_0x11e580){return new BPromise(function(_0x5803b4,_0x24e293){if(_0x11e580){return client[_0xf655('0xb')](_0xf655('0x21'),{'options':{'raw':!![],'attributes':['id','name',_0xf655('0x22'),_0xf655('0x23'),_0xf655('0x24')],'where':{'name':_0x11e580},'limit':0x1}})[_0xf655('0xc')](function(_0x3abbfb){logger[_0xf655('0x9')](_0xf655('0x25'),_0x11e580,_0x3abbfb?util[_0xf655('0x8')](_0x3abbfb,{'showHidden':![],'depth':null}):'');logger[_0xf655('0x7')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0x11e580,_0x3abbfb?_0xf655('0x1b'):_0xf655('0x18'));return _0x5803b4(_0x3abbfb[_0xf655('0x14')][_0xf655('0x15')]?_0x3abbfb[_0xf655('0x14')][0x0]:null);})[_0xf655('0xe')](function(_0x3f67f3){logger['error']('[utils][getVoiceQueueByName]',_0x3f67f3?util['inspect'](_0x3f67f3,{'showHidden':![],'depth':null}):'');return _0x5803b4(null);});}return _0x5803b4(null);});};exports[_0xf655('0x26')]=function(_0x577956,_0xe4bbec){return moment(_0x577956)['add'](_0xe4bbec,'seconds')['format']('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xf655('0x27')]=function(_0x157596,_0x1e6cd2){return moment(_0x157596)[_0xf655('0x28')](_0x1e6cd2,_0xf655('0x29'))['format'](_0xf655('0x2a'));};exports[_0xf655('0x2b')]=function(_0x346ea9,_0x4f46bb){return moment(_0x346ea9)[_0xf655('0x2c')](moment(_0x4f46bb),_0xf655('0x29'));};exports[_0xf655('0x2d')]=function(_0x3ad279,_0x1f7f49){return parseInt(_0x3ad279,0xa)+parseInt(_0x1f7f49,0xa);};exports[_0xf655('0x2e')]=function(){return moment()[_0xf655('0x2f')](_0xf655('0x2a'));};exports[_0xf655('0x30')]=function(_0x431ae8,_0x620e67){if(_0x620e67){return moment(_0x431ae8)[_0xf655('0x30')](_0x620e67);}return!![];};exports['isBefore']=function(_0x2b346b,_0x41e322){if(_0x41e322){return moment(_0x2b346b)[_0xf655('0x31')](_0x41e322);}else if(_0x2b346b){return!![];}return![];};