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 _0x341b=['GetUser','internal','GETUSER|','result','length','FOUND','NOTFOUND','getUserByInternal','getUserByInterface','getUserByName','GetVoiceQueue','name','acw','GETVOICEQUEUEBYNAME|','add','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diffTime','sumTime','now','isAfter','jayson/promise','moment','client','http','info','debug','stringify','error','stack','request','then','catch'];(function(_0x594ee0,_0x481731){var _0x41d4df=function(_0x5194f5){while(--_0x5194f5){_0x594ee0['push'](_0x594ee0['shift']());}};_0x41d4df(++_0x481731);}(_0x341b,0xf0));var _0xb341=function(_0x36cb9c,_0x5e5f20){_0x36cb9c=_0x36cb9c-0x0;var _0x391f0c=_0x341b[_0x36cb9c];return _0x391f0c;};'use strict';var jayson=require(_0xb341('0x0'));var moment=require(_0xb341('0x1'));var BPromise=require('bluebird');var client=jayson[_0xb341('0x2')][_0xb341('0x3')]({'port':0x2329});var logger=require('../../config/logger')('xdr');exports[_0xb341('0x4')]=function(_0x28520d){logger[_0xb341('0x4')](_0x28520d);};exports[_0xb341('0x5')]=function(_0x1944cf){logger[_0xb341('0x5')](JSON[_0xb341('0x6')](_0x1944cf));};exports[_0xb341('0x7')]=function(_0x2f871f){logger[_0xb341('0x7')](_0x2f871f[_0xb341('0x8')]);};exports[_0xb341('0x9')]=function(_0x4edf76,_0x34b05a){return client[_0xb341('0x9')](_0x4edf76,{'body':_0x34b05a})[_0xb341('0xa')](function(_0x28adbb){logger[_0xb341('0x5')](JSON[_0xb341('0x6')](_0x28adbb));})[_0xb341('0xb')](function(_0x6fe40f){logger['error'](_0x6fe40f['stack']);});};function getUser(_0x5c846f){return client[_0xb341('0x9')](_0xb341('0xc'),{'options':{'raw':!![],'attributes':['id',_0xb341('0xd'),'name','interface'],'where':_0x5c846f,'limit':0x1}})[_0xb341('0xa')](function(_0x4b260a){logger[_0xb341('0x4')](_0xb341('0xe')+JSON[_0xb341('0x6')](_0x5c846f)+'|'+(_0x4b260a[_0xb341('0xf')][_0xb341('0x10')]?_0xb341('0x11'):_0xb341('0x12')));return _0x4b260a[_0xb341('0xf')][_0xb341('0x10')]?_0x4b260a[_0xb341('0xf')][0x0]:null;});}exports[_0xb341('0x13')]=function(_0x1ce211){return new BPromise(function(_0x45ecf3,_0x1c2d2d){if(_0x1ce211){return getUser({'internal':_0x1ce211})[_0xb341('0xa')](function(_0x125514){return _0x45ecf3(_0x125514);})['catch'](function(_0x59e5fb){logger['error'](_0x59e5fb['stack']);return _0x45ecf3(null);});}else{return _0x45ecf3(null);}});};exports[_0xb341('0x14')]=function(_0x147bc8){return new BPromise(function(_0x6620c4,_0x316afb){if(_0x147bc8){return getUser({'interface':_0x147bc8})[_0xb341('0xa')](function(_0x3e4b51){return _0x6620c4(_0x3e4b51);})[_0xb341('0xb')](function(_0x10e85c){logger['error'](_0x10e85c[_0xb341('0x8')]);return _0x6620c4(null);});}else{return _0x6620c4(null);}});};exports[_0xb341('0x15')]=function(_0x1d6889){return new BPromise(function(_0x7b1a62,_0x4a8888){if(_0x1d6889){return getUser({'name':_0x1d6889})[_0xb341('0xa')](function(_0x1ac49f){return _0x7b1a62(_0x1ac49f);})[_0xb341('0xb')](function(_0x4e8d3c){logger[_0xb341('0x7')](_0x4e8d3c['stack']);return _0x7b1a62(null);});}else{return _0x7b1a62(null);}});};exports['getVoiceQueueByName']=function(_0x52082d){return new BPromise(function(_0xf4d0aa,_0x4fd360){if(_0x52082d){return client[_0xb341('0x9')](_0xb341('0x16'),{'options':{'raw':!![],'attributes':['id',_0xb341('0x17'),'type',_0xb341('0x18'),'acwTimeout'],'where':{'name':_0x52082d},'limit':0x1}})[_0xb341('0xa')](function(_0x1fdbe4){logger[_0xb341('0x4')](_0xb341('0x19')+_0x52082d+'|'+(_0x1fdbe4['result'][_0xb341('0x10')]?_0xb341('0x11'):'NOTFOUND'));return _0xf4d0aa(_0x1fdbe4[_0xb341('0xf')]['length']?_0x1fdbe4['result'][0x0]:null);})[_0xb341('0xb')](function(_0x28a6e6){logger[_0xb341('0x7')](_0x28a6e6[_0xb341('0x8')]);return _0xf4d0aa(null);});}else{return _0xf4d0aa(null);}});};exports['addTime']=function(_0x26972e,_0x4a63b8){return moment(_0x26972e)[_0xb341('0x1a')](_0x4a63b8,_0xb341('0x1b'))[_0xb341('0x1c')](_0xb341('0x1d'));};exports[_0xb341('0x1e')]=function(_0x1fc5e5,_0x30d7af){return moment(_0x1fc5e5)[_0xb341('0x1f')](_0x30d7af,'seconds')[_0xb341('0x1c')](_0xb341('0x1d'));};exports[_0xb341('0x20')]=function(_0x10e363,_0x2cebb8){return moment(_0x10e363)['diff'](moment(_0x2cebb8),_0xb341('0x1b'));};exports[_0xb341('0x21')]=function(_0x42a53c,_0x4d7c02){return parseInt(_0x42a53c,0xa)+parseInt(_0x4d7c02,0xa);};exports[_0xb341('0x22')]=function(){return moment()[_0xb341('0x1c')](_0xb341('0x1d'));};exports[_0xb341('0x23')]=function(_0x4a54d2,_0x3b96ca){if(_0x3b96ca){return moment(_0x4a54d2)[_0xb341('0x23')](_0x3b96ca);}else{return!![];}};exports['isBefore']=function(_0x405b69,_0x52d525){if(_0x52d525){return moment(_0x405b69)['isBefore'](_0x52d525);}else if(_0x405b69){return!![];}else{return![];}};