Built motion from commit (unavailable).|2.4.6
[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 _0x14f6=['diff','isAfter','jayson/promise','client','../../config/logger','xdr','info','debug','stringify','error','stack','request','then','internal','name','interface','GETUSER|','result','length','FOUND','NOTFOUND','getUserByInternal','catch','getUserByInterface','getUserByName','getVoiceQueueByName','acw','acwTimeout','GETVOICEQUEUEBYNAME|','addTime','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diffTime'];(function(_0x549faf,_0x1d43b3){var _0x4bfbcc=function(_0x5708d9){while(--_0x5708d9){_0x549faf['push'](_0x549faf['shift']());}};_0x4bfbcc(++_0x1d43b3);}(_0x14f6,0x16a));var _0x614f=function(_0x58998e,_0x5e6d19){_0x58998e=_0x58998e-0x0;var _0x1a5d1a=_0x14f6[_0x58998e];return _0x1a5d1a;};'use strict';var jayson=require(_0x614f('0x0'));var moment=require('moment');var BPromise=require('bluebird');var client=jayson[_0x614f('0x1')]['http']({'port':0x2329});var logger=require(_0x614f('0x2'))(_0x614f('0x3'));exports['info']=function(_0x2f9e68){logger[_0x614f('0x4')](_0x2f9e68);};exports[_0x614f('0x5')]=function(_0x37bfd7){logger[_0x614f('0x5')](JSON[_0x614f('0x6')](_0x37bfd7));};exports['error']=function(_0x581f8e){logger[_0x614f('0x7')](_0x581f8e[_0x614f('0x8')]);};exports[_0x614f('0x9')]=function(_0x4a33ad,_0x4007cd){return client[_0x614f('0x9')](_0x4a33ad,{'body':_0x4007cd})[_0x614f('0xa')](function(_0x363080){logger[_0x614f('0x5')](JSON[_0x614f('0x6')](_0x363080));})['catch'](function(_0x265d5f){logger[_0x614f('0x7')](_0x265d5f['stack']);});};function getUser(_0x57902a){return client[_0x614f('0x9')]('GetUser',{'options':{'raw':!![],'attributes':['id',_0x614f('0xb'),_0x614f('0xc'),_0x614f('0xd')],'where':_0x57902a,'limit':0x1}})[_0x614f('0xa')](function(_0x1f273f){logger[_0x614f('0x4')](_0x614f('0xe')+JSON[_0x614f('0x6')](_0x57902a)+'|'+(_0x1f273f[_0x614f('0xf')][_0x614f('0x10')]?_0x614f('0x11'):_0x614f('0x12')));return _0x1f273f[_0x614f('0xf')][_0x614f('0x10')]?_0x1f273f[_0x614f('0xf')][0x0]:null;});}exports[_0x614f('0x13')]=function(_0x28768e){return new BPromise(function(_0x2154f5,_0x11005e){if(_0x28768e){return getUser({'internal':_0x28768e})[_0x614f('0xa')](function(_0x2a2ec0){return _0x2154f5(_0x2a2ec0);})[_0x614f('0x14')](function(_0x56cb9a){logger['error'](_0x56cb9a[_0x614f('0x8')]);return _0x2154f5(null);});}else{return _0x2154f5(null);}});};exports[_0x614f('0x15')]=function(_0xdf41bd){return new BPromise(function(_0x45f6fc,_0x2591bb){if(_0xdf41bd){return getUser({'interface':_0xdf41bd})['then'](function(_0x1f78b2){return _0x45f6fc(_0x1f78b2);})[_0x614f('0x14')](function(_0x291f46){logger[_0x614f('0x7')](_0x291f46[_0x614f('0x8')]);return _0x45f6fc(null);});}else{return _0x45f6fc(null);}});};exports[_0x614f('0x16')]=function(_0x24ab80){return new BPromise(function(_0x41611d,_0x192887){if(_0x24ab80){return getUser({'name':_0x24ab80})[_0x614f('0xa')](function(_0x50ae1e){return _0x41611d(_0x50ae1e);})['catch'](function(_0x579770){logger['error'](_0x579770[_0x614f('0x8')]);return _0x41611d(null);});}else{return _0x41611d(null);}});};exports[_0x614f('0x17')]=function(_0x59ea7b){return new BPromise(function(_0x221be5,_0x3abac7){if(_0x59ea7b){return client[_0x614f('0x9')]('GetVoiceQueue',{'options':{'raw':!![],'attributes':['id','name','type',_0x614f('0x18'),_0x614f('0x19')],'where':{'name':_0x59ea7b},'limit':0x1}})[_0x614f('0xa')](function(_0x3b7bd9){logger[_0x614f('0x4')](_0x614f('0x1a')+_0x59ea7b+'|'+(_0x3b7bd9[_0x614f('0xf')]['length']?_0x614f('0x11'):_0x614f('0x12')));return _0x221be5(_0x3b7bd9[_0x614f('0xf')][_0x614f('0x10')]?_0x3b7bd9['result'][0x0]:null);})[_0x614f('0x14')](function(_0x570877){logger[_0x614f('0x7')](_0x570877[_0x614f('0x8')]);return _0x221be5(null);});}else{return _0x221be5(null);}});};exports[_0x614f('0x1b')]=function(_0x5783a7,_0x311ed7){return moment(_0x5783a7)['add'](_0x311ed7,_0x614f('0x1c'))[_0x614f('0x1d')](_0x614f('0x1e'));};exports[_0x614f('0x1f')]=function(_0x54ce6e,_0x2a417c){return moment(_0x54ce6e)[_0x614f('0x20')](_0x2a417c,_0x614f('0x1c'))[_0x614f('0x1d')](_0x614f('0x1e'));};exports[_0x614f('0x21')]=function(_0x52a5a6,_0xbfb1cb){return moment(_0x52a5a6)[_0x614f('0x22')](moment(_0xbfb1cb),_0x614f('0x1c'));};exports['sumTime']=function(_0x464378,_0x1e9c4f){return parseInt(_0x464378,0xa)+parseInt(_0x1e9c4f,0xa);};exports['now']=function(){return moment()['format'](_0x614f('0x1e'));};exports[_0x614f('0x23')]=function(_0x38eae2,_0x49f21c){if(_0x49f21c){return moment(_0x38eae2)[_0x614f('0x23')](_0x49f21c);}else{return!![];}};exports['isBefore']=function(_0x110744,_0x245e42){if(_0x245e42){return moment(_0x110744)['isBefore'](_0x245e42);}else if(_0x110744){return!![];}else{return![];}};