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 _0xf241=['isAfter','isBefore','jayson/promise','bluebird','http','../../config/logger','xdr','info','debug','stringify','error','stack','request','then','catch','GetUser','name','interface','result','FOUND','getUserByInternal','getUserByInterface','getUserByName','GetVoiceQueue','type','acw','acwTimeout','GETVOICEQUEUEBYNAME|','length','addTime','add','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtract','diffTime','diff','sumTime'];(function(_0x1ff2ec,_0x386e86){var _0x405683=function(_0x22f921){while(--_0x22f921){_0x1ff2ec['push'](_0x1ff2ec['shift']());}};_0x405683(++_0x386e86);}(_0xf241,0x1a4));var _0x1f24=function(_0x2c91e9,_0x2fb965){_0x2c91e9=_0x2c91e9-0x0;var _0x13f0ff=_0xf241[_0x2c91e9];return _0x13f0ff;};'use strict';var jayson=require(_0x1f24('0x0'));var moment=require('moment');var BPromise=require(_0x1f24('0x1'));var client=jayson['client'][_0x1f24('0x2')]({'port':0x2329});var logger=require(_0x1f24('0x3'))(_0x1f24('0x4'));exports[_0x1f24('0x5')]=function(_0x13cb28){logger[_0x1f24('0x5')](_0x13cb28);};exports[_0x1f24('0x6')]=function(_0x13319a){logger[_0x1f24('0x6')](JSON[_0x1f24('0x7')](_0x13319a));};exports[_0x1f24('0x8')]=function(_0x3ba3c5){logger[_0x1f24('0x8')](_0x3ba3c5[_0x1f24('0x9')]);};exports[_0x1f24('0xa')]=function(_0x54ac9e,_0x4f358e){return client[_0x1f24('0xa')](_0x54ac9e,{'body':_0x4f358e})[_0x1f24('0xb')](function(_0x25a667){logger[_0x1f24('0x6')](JSON['stringify'](_0x25a667));})[_0x1f24('0xc')](function(_0xd3877f){logger[_0x1f24('0x8')](_0xd3877f[_0x1f24('0x9')]);});};function getUser(_0x2122c1){return client[_0x1f24('0xa')](_0x1f24('0xd'),{'options':{'raw':!![],'attributes':['id','internal',_0x1f24('0xe'),_0x1f24('0xf')],'where':_0x2122c1,'limit':0x1}})[_0x1f24('0xb')](function(_0x17d80b){logger[_0x1f24('0x5')]('GETUSER|'+JSON[_0x1f24('0x7')](_0x2122c1)+'|'+(_0x17d80b[_0x1f24('0x10')]['length']?_0x1f24('0x11'):'NOTFOUND'));return _0x17d80b[_0x1f24('0x10')]['length']?_0x17d80b['result'][0x0]:null;});}exports[_0x1f24('0x12')]=function(_0x4b9b4f){return new BPromise(function(_0x4535ec,_0x2263c9){if(_0x4b9b4f){return getUser({'internal':_0x4b9b4f})[_0x1f24('0xb')](function(_0x509558){return _0x4535ec(_0x509558);})[_0x1f24('0xc')](function(_0x20448d){logger[_0x1f24('0x8')](_0x20448d[_0x1f24('0x9')]);return _0x4535ec(null);});}else{return _0x4535ec(null);}});};exports[_0x1f24('0x13')]=function(_0x4f7428){return new BPromise(function(_0x3266f,_0x211900){if(_0x4f7428){return getUser({'interface':_0x4f7428})[_0x1f24('0xb')](function(_0x43f063){return _0x3266f(_0x43f063);})[_0x1f24('0xc')](function(_0x5dc47f){logger['error'](_0x5dc47f['stack']);return _0x3266f(null);});}else{return _0x3266f(null);}});};exports[_0x1f24('0x14')]=function(_0x4f46cd){return new BPromise(function(_0x2378af,_0x5c67a2){if(_0x4f46cd){return getUser({'name':_0x4f46cd})['then'](function(_0x29420a){return _0x2378af(_0x29420a);})[_0x1f24('0xc')](function(_0x186cc8){logger[_0x1f24('0x8')](_0x186cc8[_0x1f24('0x9')]);return _0x2378af(null);});}else{return _0x2378af(null);}});};exports['getVoiceQueueByName']=function(_0x23d6a6){return new BPromise(function(_0x208159,_0x2a4282){if(_0x23d6a6){return client['request'](_0x1f24('0x15'),{'options':{'raw':!![],'attributes':['id','name',_0x1f24('0x16'),_0x1f24('0x17'),_0x1f24('0x18')],'where':{'name':_0x23d6a6},'limit':0x1}})[_0x1f24('0xb')](function(_0x380fd3){logger['info'](_0x1f24('0x19')+_0x23d6a6+'|'+(_0x380fd3[_0x1f24('0x10')][_0x1f24('0x1a')]?_0x1f24('0x11'):'NOTFOUND'));return _0x208159(_0x380fd3[_0x1f24('0x10')][_0x1f24('0x1a')]?_0x380fd3[_0x1f24('0x10')][0x0]:null);})['catch'](function(_0x15c7ad){logger[_0x1f24('0x8')](_0x15c7ad[_0x1f24('0x9')]);return _0x208159(null);});}else{return _0x208159(null);}});};exports[_0x1f24('0x1b')]=function(_0x191e3a,_0x3e4c40){return moment(_0x191e3a)[_0x1f24('0x1c')](_0x3e4c40,_0x1f24('0x1d'))[_0x1f24('0x1e')](_0x1f24('0x1f'));};exports['subtractTime']=function(_0x292176,_0x4d1540){return moment(_0x292176)[_0x1f24('0x20')](_0x4d1540,'seconds')['format']('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x1f24('0x21')]=function(_0x1f6f84,_0x348d5f){return moment(_0x1f6f84)[_0x1f24('0x22')](moment(_0x348d5f),_0x1f24('0x1d'));};exports[_0x1f24('0x23')]=function(_0xd60bfb,_0x53d8c7){return parseInt(_0xd60bfb,0xa)+parseInt(_0x53d8c7,0xa);};exports['now']=function(){return moment()[_0x1f24('0x1e')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x1f24('0x24')]=function(_0x31f6b3,_0x55da1e){if(_0x55da1e){return moment(_0x31f6b3)[_0x1f24('0x24')](_0x55da1e);}else{return!![];}};exports[_0x1f24('0x25')]=function(_0x21fcb0,_0x503c4e){if(_0x503c4e){return moment(_0x21fcb0)[_0x1f24('0x25')](_0x503c4e);}else if(_0x21fcb0){return!![];}else{return![];}};