3f58a92282f7f9b1d6d684738439845a31c61b02
[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 _0x544f=['http','../../config/logger','xdr','info','inspect','debug','error','request','then','catch','GetUser','internal','name','interface','stringify','length','result','getUserByInternal','found','notfound','[utils][getUserByInternal]','[utils][getUserByInterface]\x20interface:%s\x20%s','[utils][getUserByInterface]','getUserByName','getVoiceQueueByName','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','[utils][getVoiceQueueByName]','addTime','add','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diffTime','seconds','sumTime','now','isAfter','isBefore','bluebird','jayson/promise','moment','client'];(function(_0x215dc8,_0x52c245){var _0x583ea3=function(_0x32350d){while(--_0x32350d){_0x215dc8['push'](_0x215dc8['shift']());}};_0x583ea3(++_0x52c245);}(_0x544f,0xbc));var _0xf544=function(_0x4ff09b,_0x53f67d){_0x4ff09b=_0x4ff09b-0x0;var _0x3f5c2e=_0x544f[_0x4ff09b];return _0x3f5c2e;};'use strict';var BPromise=require(_0xf544('0x0'));var jayson=require(_0xf544('0x1'));var moment=require(_0xf544('0x2'));var util=require('util');var client=jayson[_0xf544('0x3')][_0xf544('0x4')]({'port':0x2329});var logger=require(_0xf544('0x5'))(_0xf544('0x6'));exports['info']=function(_0x4a2100,_0x27aefd){logger[_0xf544('0x7')](_0x4a2100,_0x27aefd?util[_0xf544('0x8')](_0x27aefd,{'showHidden':![],'depth':null}):'');};exports[_0xf544('0x9')]=function(_0x57ff7a,_0x3c1567){logger[_0xf544('0x9')](_0x57ff7a,_0x3c1567?util['inspect'](_0x3c1567,{'showHidden':![],'depth':null}):'');};exports[_0xf544('0xa')]=function(_0x4078d7,_0x4f562b){logger[_0xf544('0xa')](_0x4078d7,_0x4f562b?util[_0xf544('0x8')](_0x4f562b,{'showHidden':![],'depth':null}):'');};exports['request']=function(_0x591db2,_0x4f9ff0){return client[_0xf544('0xb')](_0x591db2,{'body':_0x4f9ff0})[_0xf544('0xc')](function(_0x28ec8e){logger[_0xf544('0x9')]('[utils][request]\x20name:%s',_0x591db2,_0x28ec8e?util['inspect'](_0x28ec8e,{'showHidden':![],'depth':null}):'');})[_0xf544('0xd')](function(_0x4b9236){logger[_0xf544('0xa')]('[utils][request]\x20name:%s',_0x591db2,_0x4b9236?util[_0xf544('0x8')](_0x4b9236,{'showHidden':![],'depth':null}):'');});};function getUser(_0x206de2){return client[_0xf544('0xb')](_0xf544('0xe'),{'options':{'raw':!![],'attributes':['id',_0xf544('0xf'),_0xf544('0x10'),_0xf544('0x11')],'where':_0x206de2,'limit':0x1}})[_0xf544('0xc')](function(_0x1e1844){logger[_0xf544('0x9')]('[utils][getUser]\x20where:%s',JSON[_0xf544('0x12')](_0x206de2),_0x1e1844?util[_0xf544('0x8')](_0x1e1844,{'showHidden':![],'depth':null}):'');return _0x1e1844['result'][_0xf544('0x13')]?_0x1e1844[_0xf544('0x14')][0x0]:null;});}exports[_0xf544('0x15')]=function(_0x5a205f){return new BPromise(function(_0x5aee58,_0x2f1359){if(_0x5a205f){return getUser({'internal':_0x5a205f})[_0xf544('0xc')](function(_0x48232e){logger['info']('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x5a205f,_0x48232e?_0xf544('0x16'):_0xf544('0x17'));return _0x5aee58(_0x48232e);})['catch'](function(_0x25dddf){logger[_0xf544('0xa')](_0xf544('0x18'),_0x25dddf?util[_0xf544('0x8')](_0x25dddf,{'showHidden':![],'depth':null}):'');return _0x5aee58(null);});}return _0x5aee58(null);});};exports['getUserByInterface']=function(_0xae3ca9){return new BPromise(function(_0x12ea8a,_0x576735){if(_0xae3ca9){return getUser({'interface':_0xae3ca9})[_0xf544('0xc')](function(_0x389223){logger['info'](_0xf544('0x19'),_0xae3ca9,_0x389223?_0xf544('0x16'):_0xf544('0x17'));return _0x12ea8a(_0x389223);})[_0xf544('0xd')](function(_0x5d28c0){logger[_0xf544('0xa')](_0xf544('0x1a'),_0x5d28c0?util[_0xf544('0x8')](_0x5d28c0,{'showHidden':![],'depth':null}):'');return _0x12ea8a(null);});}return _0x12ea8a(null);});};exports[_0xf544('0x1b')]=function(_0xf8a79c){return new BPromise(function(_0x1ddcf2,_0x48b7e4){if(_0xf8a79c){return getUser({'name':_0xf8a79c})[_0xf544('0xc')](function(_0x3e210d){logger[_0xf544('0x7')]('[utils][getUserByName]\x20name:%s\x20%s',_0xf8a79c,_0x3e210d?_0xf544('0x16'):_0xf544('0x17'));return _0x1ddcf2(_0x3e210d);})[_0xf544('0xd')](function(_0x4bdd21){logger[_0xf544('0xa')]('[utils][getUserByName]',_0x4bdd21?util[_0xf544('0x8')](_0x4bdd21,{'showHidden':![],'depth':null}):'');return _0x1ddcf2(null);});}return _0x1ddcf2(null);});};exports[_0xf544('0x1c')]=function(_0x1a94d8){return new BPromise(function(_0x520118,_0x40a14b){if(_0x1a94d8){return client['request'](_0xf544('0x1d'),{'options':{'raw':!![],'attributes':['id','name',_0xf544('0x1e'),_0xf544('0x1f'),_0xf544('0x20')],'where':{'name':_0x1a94d8},'limit':0x1}})[_0xf544('0xc')](function(_0x56a7f2){logger[_0xf544('0x9')](_0xf544('0x21'),_0x1a94d8,_0x56a7f2?util[_0xf544('0x8')](_0x56a7f2,{'showHidden':![],'depth':null}):'');logger['info'](_0xf544('0x22'),_0x1a94d8,_0x56a7f2?'found':_0xf544('0x17'));return _0x520118(_0x56a7f2[_0xf544('0x14')][_0xf544('0x13')]?_0x56a7f2[_0xf544('0x14')][0x0]:null);})[_0xf544('0xd')](function(_0x2e6a26){logger['error'](_0xf544('0x23'),_0x2e6a26?util[_0xf544('0x8')](_0x2e6a26,{'showHidden':![],'depth':null}):'');return _0x520118(null);});}return _0x520118(null);});};exports[_0xf544('0x24')]=function(_0x234c87,_0x358ade){return moment(_0x234c87)[_0xf544('0x25')](_0x358ade,'seconds')[_0xf544('0x26')](_0xf544('0x27'));};exports[_0xf544('0x28')]=function(_0x2015fc,_0x50a6ac){return moment(_0x2015fc)[_0xf544('0x29')](_0x50a6ac,'seconds')[_0xf544('0x26')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xf544('0x2a')]=function(_0x4ef7b4,_0x2ae776){return moment(_0x4ef7b4)['diff'](moment(_0x2ae776),_0xf544('0x2b'));};exports[_0xf544('0x2c')]=function(_0x492262,_0x291926){return parseInt(_0x492262,0xa)+parseInt(_0x291926,0xa);};exports[_0xf544('0x2d')]=function(){return moment()[_0xf544('0x26')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xf544('0x2e')]=function(_0x2bd7cc,_0x4b2365){if(_0x4b2365){return moment(_0x2bd7cc)[_0xf544('0x2e')](_0x4b2365);}return!![];};exports[_0xf544('0x2f')]=function(_0xb4f290,_0x23d77e){if(_0x23d77e){return moment(_0xb4f290)[_0xf544('0x2f')](_0x23d77e);}else if(_0xb4f290){return!![];}return![];};