81e54fbf9e4da1ed7deb583f7253ceb4a2e45f75
[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 _0x5f47=['bluebird','client','../../config/logger','info','debug','stringify','error','request','then','stack','GetUser','internal','name','interface','GETUSER|','result','length','FOUND','NOTFOUND','getUserByInternal','catch','getUserByName','getVoiceQueueByName','GetVoiceQueue','type','acwTimeout','GETVOICEQUEUEBYNAME|','add','seconds','format','subtractTime','subtract','YYYY-MM-DD\x20HH:mm:ss','diffTime','diff','sumTime','now','isAfter','isBefore','jayson/promise','moment'];(function(_0x5b816b,_0x269404){var _0x3363f8=function(_0x2c121f){while(--_0x2c121f){_0x5b816b['push'](_0x5b816b['shift']());}};_0x3363f8(++_0x269404);}(_0x5f47,0x146));var _0x75f4=function(_0x53b243,_0x13e5a6){_0x53b243=_0x53b243-0x0;var _0x502dfd=_0x5f47[_0x53b243];return _0x502dfd;};'use strict';var jayson=require(_0x75f4('0x0'));var moment=require(_0x75f4('0x1'));var BPromise=require(_0x75f4('0x2'));var client=jayson[_0x75f4('0x3')]['http']({'port':0x2329});var logger=require(_0x75f4('0x4'))('xdr');exports[_0x75f4('0x5')]=function(_0xc98c54){logger[_0x75f4('0x5')](_0xc98c54);};exports[_0x75f4('0x6')]=function(_0x141931){logger[_0x75f4('0x6')](JSON[_0x75f4('0x7')](_0x141931));};exports[_0x75f4('0x8')]=function(_0x21328b){logger[_0x75f4('0x8')](_0x21328b['stack']);};exports['request']=function(_0x36ab98,_0x3737a6){return client[_0x75f4('0x9')](_0x36ab98,{'body':_0x3737a6})[_0x75f4('0xa')](function(_0x95222a){logger[_0x75f4('0x6')](JSON[_0x75f4('0x7')](_0x95222a));})['catch'](function(_0x3285c6){logger[_0x75f4('0x8')](_0x3285c6[_0x75f4('0xb')]);});};function getUser(_0x1037d1){return client['request'](_0x75f4('0xc'),{'options':{'raw':!![],'attributes':['id',_0x75f4('0xd'),_0x75f4('0xe'),_0x75f4('0xf')],'where':_0x1037d1,'limit':0x1}})['then'](function(_0x9f99a2){logger['info'](_0x75f4('0x10')+JSON[_0x75f4('0x7')](_0x1037d1)+'|'+(_0x9f99a2[_0x75f4('0x11')][_0x75f4('0x12')]?_0x75f4('0x13'):_0x75f4('0x14')));return _0x9f99a2[_0x75f4('0x11')][_0x75f4('0x12')]?_0x9f99a2[_0x75f4('0x11')][0x0]:null;});}exports[_0x75f4('0x15')]=function(_0x34c5c2){return new BPromise(function(_0x1f84ba,_0x109bdb){if(_0x34c5c2){return getUser({'internal':_0x34c5c2})[_0x75f4('0xa')](function(_0x385508){return _0x1f84ba(_0x385508);})['catch'](function(_0x170e8e){logger[_0x75f4('0x8')](_0x170e8e[_0x75f4('0xb')]);return _0x1f84ba(null);});}else{return _0x1f84ba(null);}});};exports['getUserByInterface']=function(_0x4982a7){return new BPromise(function(_0x14b354,_0x28af6e){if(_0x4982a7){return getUser({'interface':_0x4982a7})[_0x75f4('0xa')](function(_0x4fe624){return _0x14b354(_0x4fe624);})[_0x75f4('0x16')](function(_0xece96f){logger[_0x75f4('0x8')](_0xece96f['stack']);return _0x14b354(null);});}else{return _0x14b354(null);}});};exports[_0x75f4('0x17')]=function(_0x101308){return new BPromise(function(_0x55bccc,_0x167920){if(_0x101308){return getUser({'name':_0x101308})[_0x75f4('0xa')](function(_0x116dd1){return _0x55bccc(_0x116dd1);})[_0x75f4('0x16')](function(_0x65386){logger[_0x75f4('0x8')](_0x65386[_0x75f4('0xb')]);return _0x55bccc(null);});}else{return _0x55bccc(null);}});};exports[_0x75f4('0x18')]=function(_0x52ad02){return new BPromise(function(_0x59e4d1,_0x5b1fc8){if(_0x52ad02){return client[_0x75f4('0x9')](_0x75f4('0x19'),{'options':{'raw':!![],'attributes':['id',_0x75f4('0xe'),_0x75f4('0x1a'),'acw',_0x75f4('0x1b')],'where':{'name':_0x52ad02},'limit':0x1}})[_0x75f4('0xa')](function(_0x44548c){logger[_0x75f4('0x5')](_0x75f4('0x1c')+_0x52ad02+'|'+(_0x44548c[_0x75f4('0x11')][_0x75f4('0x12')]?_0x75f4('0x13'):_0x75f4('0x14')));return _0x59e4d1(_0x44548c[_0x75f4('0x11')][_0x75f4('0x12')]?_0x44548c[_0x75f4('0x11')][0x0]:null);})['catch'](function(_0x50bdd5){logger[_0x75f4('0x8')](_0x50bdd5[_0x75f4('0xb')]);return _0x59e4d1(null);});}else{return _0x59e4d1(null);}});};exports['addTime']=function(_0x160d28,_0x45d8f9){return moment(_0x160d28)[_0x75f4('0x1d')](_0x45d8f9,_0x75f4('0x1e'))[_0x75f4('0x1f')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x75f4('0x20')]=function(_0x22fcfc,_0x5b46be){return moment(_0x22fcfc)[_0x75f4('0x21')](_0x5b46be,'seconds')[_0x75f4('0x1f')](_0x75f4('0x22'));};exports[_0x75f4('0x23')]=function(_0x5d45a6,_0x210c58){return moment(_0x5d45a6)[_0x75f4('0x24')](moment(_0x210c58),_0x75f4('0x1e'));};exports[_0x75f4('0x25')]=function(_0x1a1559,_0x5477ba){return parseInt(_0x1a1559,0xa)+parseInt(_0x5477ba,0xa);};exports[_0x75f4('0x26')]=function(){return moment()[_0x75f4('0x1f')](_0x75f4('0x22'));};exports[_0x75f4('0x27')]=function(_0x355ad0,_0x589877){if(_0x589877){return moment(_0x355ad0)[_0x75f4('0x27')](_0x589877);}else{return!![];}};exports[_0x75f4('0x28')]=function(_0x474ac9,_0x438d71){if(_0x438d71){return moment(_0x474ac9)[_0x75f4('0x28')](_0x438d71);}else if(_0x474ac9){return!![];}else{return![];}};