Built motion from commit (unavailable).|2.5.4
[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 _0x2c6b=['stringify','error','stack','request','name','then','GETUSER|','result','length','FOUND','NOTFOUND','getUserByInternal','getUserByInterface','catch','getVoiceQueueByName','GetVoiceQueue','type','GETVOICEQUEUEBYNAME|','addTime','add','seconds','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','format','diffTime','sumTime','now','isAfter','isBefore','moment','client','../../config/logger','xdr','info','debug'];(function(_0x52a347,_0x52f6c6){var _0x321672=function(_0x5797e8){while(--_0x5797e8){_0x52a347['push'](_0x52a347['shift']());}};_0x321672(++_0x52f6c6);}(_0x2c6b,0x1ce));var _0xb2c6=function(_0x1ebe2e,_0x18b57a){_0x1ebe2e=_0x1ebe2e-0x0;var _0x4c883b=_0x2c6b[_0x1ebe2e];return _0x4c883b;};'use strict';var jayson=require('jayson/promise');var moment=require(_0xb2c6('0x0'));var BPromise=require('bluebird');var client=jayson[_0xb2c6('0x1')]['http']({'port':0x2329});var logger=require(_0xb2c6('0x2'))(_0xb2c6('0x3'));exports[_0xb2c6('0x4')]=function(_0x54b488){logger[_0xb2c6('0x4')](_0x54b488);};exports['debug']=function(_0x1082b7){logger[_0xb2c6('0x5')](JSON[_0xb2c6('0x6')](_0x1082b7));};exports[_0xb2c6('0x7')]=function(_0x539f01){logger['error'](_0x539f01[_0xb2c6('0x8')]);};exports['request']=function(_0x4ea34f,_0x2bc9f8){return client['request'](_0x4ea34f,{'body':_0x2bc9f8})['then'](function(_0x52559c){logger['debug'](JSON[_0xb2c6('0x6')](_0x52559c));})['catch'](function(_0x3ccd91){logger[_0xb2c6('0x7')](_0x3ccd91[_0xb2c6('0x8')]);});};function getUser(_0x59eb1a){return client[_0xb2c6('0x9')]('GetUser',{'options':{'raw':!![],'attributes':['id','internal',_0xb2c6('0xa'),'interface'],'where':_0x59eb1a,'limit':0x1}})[_0xb2c6('0xb')](function(_0x3114a9){logger[_0xb2c6('0x4')](_0xb2c6('0xc')+JSON[_0xb2c6('0x6')](_0x59eb1a)+'|'+(_0x3114a9[_0xb2c6('0xd')][_0xb2c6('0xe')]?_0xb2c6('0xf'):_0xb2c6('0x10')));return _0x3114a9[_0xb2c6('0xd')][_0xb2c6('0xe')]?_0x3114a9[_0xb2c6('0xd')][0x0]:null;});}exports[_0xb2c6('0x11')]=function(_0x5ac6c7){return new BPromise(function(_0x3d0f3a,_0xee5ce2){if(_0x5ac6c7){return getUser({'internal':_0x5ac6c7})[_0xb2c6('0xb')](function(_0x37dc4f){return _0x3d0f3a(_0x37dc4f);})['catch'](function(_0x378e9e){logger[_0xb2c6('0x7')](_0x378e9e[_0xb2c6('0x8')]);return _0x3d0f3a(null);});}else{return _0x3d0f3a(null);}});};exports[_0xb2c6('0x12')]=function(_0x4c31d8){return new BPromise(function(_0xce2ecd,_0x3687bd){if(_0x4c31d8){return getUser({'interface':_0x4c31d8})[_0xb2c6('0xb')](function(_0x3cb28c){return _0xce2ecd(_0x3cb28c);})[_0xb2c6('0x13')](function(_0x1aa924){logger[_0xb2c6('0x7')](_0x1aa924['stack']);return _0xce2ecd(null);});}else{return _0xce2ecd(null);}});};exports['getUserByName']=function(_0x442827){return new BPromise(function(_0xbeac67,_0x4c3d73){if(_0x442827){return getUser({'name':_0x442827})[_0xb2c6('0xb')](function(_0x20bd85){return _0xbeac67(_0x20bd85);})['catch'](function(_0x26fa08){logger['error'](_0x26fa08['stack']);return _0xbeac67(null);});}else{return _0xbeac67(null);}});};exports[_0xb2c6('0x14')]=function(_0x45c7bd){return new BPromise(function(_0xa66ce3,_0x53e3b9){if(_0x45c7bd){return client[_0xb2c6('0x9')](_0xb2c6('0x15'),{'options':{'raw':!![],'attributes':['id','name',_0xb2c6('0x16'),'acw','acwTimeout'],'where':{'name':_0x45c7bd},'limit':0x1}})['then'](function(_0x5e7495){logger['info'](_0xb2c6('0x17')+_0x45c7bd+'|'+(_0x5e7495[_0xb2c6('0xd')][_0xb2c6('0xe')]?_0xb2c6('0xf'):'NOTFOUND'));return _0xa66ce3(_0x5e7495[_0xb2c6('0xd')][_0xb2c6('0xe')]?_0x5e7495[_0xb2c6('0xd')][0x0]:null);})[_0xb2c6('0x13')](function(_0x3bb75c){logger[_0xb2c6('0x7')](_0x3bb75c[_0xb2c6('0x8')]);return _0xa66ce3(null);});}else{return _0xa66ce3(null);}});};exports[_0xb2c6('0x18')]=function(_0x2b8d3e,_0x3b3a56){return moment(_0x2b8d3e)[_0xb2c6('0x19')](_0x3b3a56,_0xb2c6('0x1a'))['format'](_0xb2c6('0x1b'));};exports[_0xb2c6('0x1c')]=function(_0x196278,_0x14ca15){return moment(_0x196278)[_0xb2c6('0x1d')](_0x14ca15,_0xb2c6('0x1a'))[_0xb2c6('0x1e')](_0xb2c6('0x1b'));};exports[_0xb2c6('0x1f')]=function(_0x3b2650,_0x4be301){return moment(_0x3b2650)['diff'](moment(_0x4be301),_0xb2c6('0x1a'));};exports[_0xb2c6('0x20')]=function(_0x1ce173,_0x6b4563){return parseInt(_0x1ce173,0xa)+parseInt(_0x6b4563,0xa);};exports[_0xb2c6('0x21')]=function(){return moment()[_0xb2c6('0x1e')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xb2c6('0x22')]=function(_0xea70ef,_0x450674){if(_0x450674){return moment(_0xea70ef)[_0xb2c6('0x22')](_0x450674);}else{return!![];}};exports[_0xb2c6('0x23')]=function(_0x4b5201,_0x62af5a){if(_0x62af5a){return moment(_0x4b5201)[_0xb2c6('0x23')](_0x62af5a);}else if(_0x4b5201){return!![];}else{return![];}};