b53857ea96b8df8a8e381868b90cc8ec0b952f0e
[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 _0x0f25=['diffTime','isAfter','isBefore','bluebird','jayson/promise','util','client','http','../../config/logger','info','inspect','debug','error','request','then','[utils][request]\x20name:%s','catch','GetUser','name','interface','[utils][getUser]\x20where:%s','stringify','result','length','getUserByInternal','[utils][getUserByInternal]\x20internal:%s\x20%s','found','[utils][getUserByInternal]','[utils][getUserByInterface]\x20interface:%s\x20%s','notfound','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]','type','acw','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]','addTime','add','seconds','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','format'];(function(_0x4005fe,_0x1fc3c1){var _0x50022d=function(_0x2ce718){while(--_0x2ce718){_0x4005fe['push'](_0x4005fe['shift']());}};_0x50022d(++_0x1fc3c1);}(_0x0f25,0xdf));var _0x50f2=function(_0x47579b,_0x4ea44e){_0x47579b=_0x47579b-0x0;var _0x4e47f5=_0x0f25[_0x47579b];return _0x4e47f5;};'use strict';var BPromise=require(_0x50f2('0x0'));var jayson=require(_0x50f2('0x1'));var moment=require('moment');var util=require(_0x50f2('0x2'));var client=jayson[_0x50f2('0x3')][_0x50f2('0x4')]({'port':0x2329});var logger=require(_0x50f2('0x5'))('xdr');exports['info']=function(_0x19e72e,_0x101e24){logger[_0x50f2('0x6')](_0x19e72e,_0x101e24?util[_0x50f2('0x7')](_0x101e24,{'showHidden':![],'depth':null}):'');};exports[_0x50f2('0x8')]=function(_0x379d0b,_0x19e3ce){logger[_0x50f2('0x8')](_0x379d0b,_0x19e3ce?util[_0x50f2('0x7')](_0x19e3ce,{'showHidden':![],'depth':null}):'');};exports[_0x50f2('0x9')]=function(_0x519b84,_0x58ce92){logger[_0x50f2('0x9')](_0x519b84,_0x58ce92?util[_0x50f2('0x7')](_0x58ce92,{'showHidden':![],'depth':null}):'');};exports[_0x50f2('0xa')]=function(_0x134bb4,_0xaca1fd){return client[_0x50f2('0xa')](_0x134bb4,{'body':_0xaca1fd})[_0x50f2('0xb')](function(_0x31cb73){logger[_0x50f2('0x8')](_0x50f2('0xc'),_0x134bb4,_0x31cb73?util[_0x50f2('0x7')](_0x31cb73,{'showHidden':![],'depth':null}):'');})[_0x50f2('0xd')](function(_0x2c513f){logger[_0x50f2('0x9')](_0x50f2('0xc'),_0x134bb4,_0x2c513f?util['inspect'](_0x2c513f,{'showHidden':![],'depth':null}):'');});};function getUser(_0x437fb7){return client[_0x50f2('0xa')](_0x50f2('0xe'),{'options':{'raw':!![],'attributes':['id','internal',_0x50f2('0xf'),_0x50f2('0x10')],'where':_0x437fb7,'limit':0x1}})['then'](function(_0x5c6c2b){logger['debug'](_0x50f2('0x11'),JSON[_0x50f2('0x12')](_0x437fb7),_0x5c6c2b?util[_0x50f2('0x7')](_0x5c6c2b,{'showHidden':![],'depth':null}):'');return _0x5c6c2b[_0x50f2('0x13')][_0x50f2('0x14')]?_0x5c6c2b[_0x50f2('0x13')][0x0]:null;});}exports[_0x50f2('0x15')]=function(_0xedbb5a){return new BPromise(function(_0x3caca9,_0x36a5f7){if(_0xedbb5a){return getUser({'internal':_0xedbb5a})['then'](function(_0x173ce6){logger[_0x50f2('0x6')](_0x50f2('0x16'),_0xedbb5a,_0x173ce6?_0x50f2('0x17'):'notfound');return _0x3caca9(_0x173ce6);})[_0x50f2('0xd')](function(_0x1779cb){logger['error'](_0x50f2('0x18'),_0x1779cb?util[_0x50f2('0x7')](_0x1779cb,{'showHidden':![],'depth':null}):'');return _0x3caca9(null);});}return _0x3caca9(null);});};exports['getUserByInterface']=function(_0x4b6eda){return new BPromise(function(_0x2592bd,_0x234703){if(_0x4b6eda){return getUser({'interface':_0x4b6eda})[_0x50f2('0xb')](function(_0x54a53d){logger['info'](_0x50f2('0x19'),_0x4b6eda,_0x54a53d?_0x50f2('0x17'):_0x50f2('0x1a'));return _0x2592bd(_0x54a53d);})['catch'](function(_0x5523bd){logger[_0x50f2('0x9')](_0x50f2('0x1b'),_0x5523bd?util[_0x50f2('0x7')](_0x5523bd,{'showHidden':![],'depth':null}):'');return _0x2592bd(null);});}return _0x2592bd(null);});};exports[_0x50f2('0x1c')]=function(_0x549f7f){return new BPromise(function(_0x4a4577,_0x4b26ad){if(_0x549f7f){return getUser({'name':_0x549f7f})[_0x50f2('0xb')](function(_0x13da77){logger[_0x50f2('0x6')]('[utils][getUserByName]\x20name:%s\x20%s',_0x549f7f,_0x13da77?'found':_0x50f2('0x1a'));return _0x4a4577(_0x13da77);})[_0x50f2('0xd')](function(_0x29ce54){logger[_0x50f2('0x9')](_0x50f2('0x1d'),_0x29ce54?util['inspect'](_0x29ce54,{'showHidden':![],'depth':null}):'');return _0x4a4577(null);});}return _0x4a4577(null);});};exports['getVoiceQueueByName']=function(_0xbb398c){return new BPromise(function(_0x5c6703,_0x24df1f){if(_0xbb398c){return client[_0x50f2('0xa')]('GetVoiceQueue',{'options':{'raw':!![],'attributes':['id',_0x50f2('0xf'),_0x50f2('0x1e'),_0x50f2('0x1f'),'acwTimeout'],'where':{'name':_0xbb398c},'limit':0x1}})[_0x50f2('0xb')](function(_0x55cf78){logger[_0x50f2('0x8')](_0x50f2('0x20'),_0xbb398c,_0x55cf78?util[_0x50f2('0x7')](_0x55cf78,{'showHidden':![],'depth':null}):'');logger[_0x50f2('0x6')]('[utils][getVoiceQueueByName]\x20name:%s\x20%s',_0xbb398c,_0x55cf78?_0x50f2('0x17'):_0x50f2('0x1a'));return _0x5c6703(_0x55cf78[_0x50f2('0x13')]['length']?_0x55cf78[_0x50f2('0x13')][0x0]:null);})[_0x50f2('0xd')](function(_0x4ba4c2){logger[_0x50f2('0x9')](_0x50f2('0x21'),_0x4ba4c2?util[_0x50f2('0x7')](_0x4ba4c2,{'showHidden':![],'depth':null}):'');return _0x5c6703(null);});}return _0x5c6703(null);});};exports[_0x50f2('0x22')]=function(_0x320807,_0x2e7e7e){return moment(_0x320807)[_0x50f2('0x23')](_0x2e7e7e,_0x50f2('0x24'))['format'](_0x50f2('0x25'));};exports[_0x50f2('0x26')]=function(_0x2801eb,_0xde6926){return moment(_0x2801eb)[_0x50f2('0x27')](_0xde6926,'seconds')[_0x50f2('0x28')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x50f2('0x29')]=function(_0x253d6b,_0x2dd13a){return moment(_0x253d6b)['diff'](moment(_0x2dd13a),_0x50f2('0x24'));};exports['sumTime']=function(_0x51b501,_0x5ed302){return parseInt(_0x51b501,0xa)+parseInt(_0x5ed302,0xa);};exports['now']=function(){return moment()[_0x50f2('0x28')](_0x50f2('0x25'));};exports[_0x50f2('0x2a')]=function(_0x31b6ff,_0x4b8eb4){if(_0x4b8eb4){return moment(_0x31b6ff)['isAfter'](_0x4b8eb4);}return!![];};exports[_0x50f2('0x2b')]=function(_0x200004,_0x31bd7a){if(_0x31bd7a){return moment(_0x200004)['isBefore'](_0x31bd7a);}else if(_0x200004){return!![];}return![];};