7db50c06fe4f1c79037d83c961dddf79417c0ae6
[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 _0xfd15=['subtractTime','subtract','seconds','format','YYYY-MM-DD\x20HH:mm:ss','diffTime','sumTime','now','isAfter','jayson/promise','moment','client','http','../../config/logger','xdr','info','debug','stringify','error','stack','request','then','catch','internal','name','interface','GETUSER|','result','length','FOUND','NOTFOUND','getUserByInternal','getUserByInterface','getUserByName','getVoiceQueueByName','GetVoiceQueue','type','acwTimeout','GETVOICEQUEUEBYNAME|','addTime'];(function(_0x19e3f5,_0x34a97f){var _0x59e913=function(_0x4b9fac){while(--_0x4b9fac){_0x19e3f5['push'](_0x19e3f5['shift']());}};_0x59e913(++_0x34a97f);}(_0xfd15,0x171));var _0x5fd1=function(_0x484e36,_0x4482d8){_0x484e36=_0x484e36-0x0;var _0xafc85d=_0xfd15[_0x484e36];return _0xafc85d;};'use strict';var jayson=require(_0x5fd1('0x0'));var moment=require(_0x5fd1('0x1'));var BPromise=require('bluebird');var client=jayson[_0x5fd1('0x2')][_0x5fd1('0x3')]({'port':0x2329});var logger=require(_0x5fd1('0x4'))(_0x5fd1('0x5'));exports[_0x5fd1('0x6')]=function(_0x4d9220){logger[_0x5fd1('0x6')](_0x4d9220);};exports['debug']=function(_0xf9d8f5){logger[_0x5fd1('0x7')](JSON[_0x5fd1('0x8')](_0xf9d8f5));};exports[_0x5fd1('0x9')]=function(_0x205cea){logger[_0x5fd1('0x9')](_0x205cea[_0x5fd1('0xa')]);};exports[_0x5fd1('0xb')]=function(_0x52523d,_0x40a173){return client[_0x5fd1('0xb')](_0x52523d,{'body':_0x40a173})[_0x5fd1('0xc')](function(_0x544fa5){logger['debug'](JSON[_0x5fd1('0x8')](_0x544fa5));})[_0x5fd1('0xd')](function(_0x209f9e){logger[_0x5fd1('0x9')](_0x209f9e[_0x5fd1('0xa')]);});};function getUser(_0x1ee339){return client[_0x5fd1('0xb')]('GetUser',{'options':{'raw':!![],'attributes':['id',_0x5fd1('0xe'),_0x5fd1('0xf'),_0x5fd1('0x10')],'where':_0x1ee339,'limit':0x1}})[_0x5fd1('0xc')](function(_0x417d3f){logger['info'](_0x5fd1('0x11')+JSON[_0x5fd1('0x8')](_0x1ee339)+'|'+(_0x417d3f[_0x5fd1('0x12')][_0x5fd1('0x13')]?_0x5fd1('0x14'):_0x5fd1('0x15')));return _0x417d3f[_0x5fd1('0x12')]['length']?_0x417d3f[_0x5fd1('0x12')][0x0]:null;});}exports[_0x5fd1('0x16')]=function(_0x19060d){return new BPromise(function(_0x5b0cf9,_0x471303){if(_0x19060d){return getUser({'internal':_0x19060d})[_0x5fd1('0xc')](function(_0x4593f5){return _0x5b0cf9(_0x4593f5);})[_0x5fd1('0xd')](function(_0x2a7cee){logger['error'](_0x2a7cee['stack']);return _0x5b0cf9(null);});}else{return _0x5b0cf9(null);}});};exports[_0x5fd1('0x17')]=function(_0x281d76){return new BPromise(function(_0x576810,_0x355ed9){if(_0x281d76){return getUser({'interface':_0x281d76})['then'](function(_0x4c54b2){return _0x576810(_0x4c54b2);})[_0x5fd1('0xd')](function(_0x43cd2d){logger[_0x5fd1('0x9')](_0x43cd2d['stack']);return _0x576810(null);});}else{return _0x576810(null);}});};exports[_0x5fd1('0x18')]=function(_0x2902e7){return new BPromise(function(_0x1149cf,_0x224842){if(_0x2902e7){return getUser({'name':_0x2902e7})[_0x5fd1('0xc')](function(_0x180e59){return _0x1149cf(_0x180e59);})[_0x5fd1('0xd')](function(_0x11bb92){logger[_0x5fd1('0x9')](_0x11bb92[_0x5fd1('0xa')]);return _0x1149cf(null);});}else{return _0x1149cf(null);}});};exports[_0x5fd1('0x19')]=function(_0x324f50){return new BPromise(function(_0xc275ee,_0x41d9b6){if(_0x324f50){return client[_0x5fd1('0xb')](_0x5fd1('0x1a'),{'options':{'raw':!![],'attributes':['id','name',_0x5fd1('0x1b'),'acw',_0x5fd1('0x1c')],'where':{'name':_0x324f50},'limit':0x1}})[_0x5fd1('0xc')](function(_0x51597b){logger[_0x5fd1('0x6')](_0x5fd1('0x1d')+_0x324f50+'|'+(_0x51597b[_0x5fd1('0x12')][_0x5fd1('0x13')]?'FOUND':_0x5fd1('0x15')));return _0xc275ee(_0x51597b[_0x5fd1('0x12')][_0x5fd1('0x13')]?_0x51597b['result'][0x0]:null);})['catch'](function(_0x11e199){logger['error'](_0x11e199[_0x5fd1('0xa')]);return _0xc275ee(null);});}else{return _0xc275ee(null);}});};exports[_0x5fd1('0x1e')]=function(_0xfe5a6f,_0x38760e){return moment(_0xfe5a6f)['add'](_0x38760e,'seconds')['format']('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x5fd1('0x1f')]=function(_0x5971a,_0x517cf4){return moment(_0x5971a)[_0x5fd1('0x20')](_0x517cf4,_0x5fd1('0x21'))[_0x5fd1('0x22')](_0x5fd1('0x23'));};exports[_0x5fd1('0x24')]=function(_0x5b5f0a,_0x2586ac){return moment(_0x5b5f0a)['diff'](moment(_0x2586ac),_0x5fd1('0x21'));};exports[_0x5fd1('0x25')]=function(_0x12e426,_0x291e63){return parseInt(_0x12e426,0xa)+parseInt(_0x291e63,0xa);};exports[_0x5fd1('0x26')]=function(){return moment()[_0x5fd1('0x22')](_0x5fd1('0x23'));};exports['isAfter']=function(_0x814167,_0x42149e){if(_0x42149e){return moment(_0x814167)[_0x5fd1('0x27')](_0x42149e);}else{return!![];}};exports['isBefore']=function(_0x2b8367,_0x29de45){if(_0x29de45){return moment(_0x2b8367)['isBefore'](_0x29de45);}else if(_0x2b8367){return!![];}else{return![];}};