Built motion from commit ddca4d0d.|2.5.47
[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 _0xbb00=['util','http','../../config/logger','xdr','info','inspect','debug','error','request','then','[utils][request]\x20name:%s','GetUser','internal','name','interface','[utils][getUser]\x20where:%s','stringify','result','length','getUserByInternal','found','notfound','[utils][getUserByInternal]','getUserByInterface','[utils][getUserByInterface]\x20interface:%s\x20%s','catch','[utils][getUserByInterface]','getUserByName','[utils][getUserByName]\x20name:%s\x20%s','[utils][getUserByName]','getVoiceQueueByName','GetVoiceQueue','type','acw','acwTimeout','[utils][getVoiceQueueByName]\x20name:%s','[utils][getVoiceQueueByName]\x20name:%s\x20%s','[utils][getVoiceQueueByName]','addTime','add','seconds','format','diffTime','diff','now','YYYY-MM-DD\x20HH:mm:ss','isAfter','isBefore','bluebird','jayson/promise'];(function(_0x33cf43,_0x4b4de9){var _0x521db5=function(_0x994173){while(--_0x994173){_0x33cf43['push'](_0x33cf43['shift']());}};_0x521db5(++_0x4b4de9);}(_0xbb00,0x94));var _0x0bb0=function(_0x370eb5,_0x568fa3){_0x370eb5=_0x370eb5-0x0;var _0x28852f=_0xbb00[_0x370eb5];return _0x28852f;};'use strict';var BPromise=require(_0x0bb0('0x0'));var jayson=require(_0x0bb0('0x1'));var moment=require('moment');var util=require(_0x0bb0('0x2'));var client=jayson['client'][_0x0bb0('0x3')]({'port':0x2329});var logger=require(_0x0bb0('0x4'))(_0x0bb0('0x5'));exports['info']=function(_0x23b0d3,_0x4e0d4d){logger[_0x0bb0('0x6')](_0x23b0d3,_0x4e0d4d?util[_0x0bb0('0x7')](_0x4e0d4d,{'showHidden':![],'depth':null}):'');};exports[_0x0bb0('0x8')]=function(_0x8dc784,_0x5addae){logger[_0x0bb0('0x8')](_0x8dc784,_0x5addae?util[_0x0bb0('0x7')](_0x5addae,{'showHidden':![],'depth':null}):'');};exports[_0x0bb0('0x9')]=function(_0x35cade,_0x16973e){logger[_0x0bb0('0x9')](_0x35cade,_0x16973e?util[_0x0bb0('0x7')](_0x16973e,{'showHidden':![],'depth':null}):'');};exports[_0x0bb0('0xa')]=function(_0x3a9210,_0x16258b){return client[_0x0bb0('0xa')](_0x3a9210,{'body':_0x16258b})[_0x0bb0('0xb')](function(_0x52e795){logger[_0x0bb0('0x8')](_0x0bb0('0xc'),_0x3a9210,_0x52e795?util[_0x0bb0('0x7')](_0x52e795,{'showHidden':![],'depth':null}):'');})['catch'](function(_0x3c2388){logger[_0x0bb0('0x9')](_0x0bb0('0xc'),_0x3a9210,_0x3c2388?util['inspect'](_0x3c2388,{'showHidden':![],'depth':null}):'');});};function getUser(_0x429646){return client[_0x0bb0('0xa')](_0x0bb0('0xd'),{'options':{'raw':!![],'attributes':['id',_0x0bb0('0xe'),_0x0bb0('0xf'),_0x0bb0('0x10')],'where':_0x429646,'limit':0x1}})[_0x0bb0('0xb')](function(_0x4d4829){logger[_0x0bb0('0x8')](_0x0bb0('0x11'),JSON[_0x0bb0('0x12')](_0x429646),_0x4d4829?util[_0x0bb0('0x7')](_0x4d4829,{'showHidden':![],'depth':null}):'');return _0x4d4829[_0x0bb0('0x13')][_0x0bb0('0x14')]?_0x4d4829[_0x0bb0('0x13')][0x0]:null;});}exports[_0x0bb0('0x15')]=function(_0x35785c){return new BPromise(function(_0x532cf2,_0xfd35ee){if(_0x35785c){return getUser({'internal':_0x35785c})['then'](function(_0x5502df){logger[_0x0bb0('0x6')]('[utils][getUserByInternal]\x20internal:%s\x20%s',_0x35785c,_0x5502df?_0x0bb0('0x16'):_0x0bb0('0x17'));return _0x532cf2(_0x5502df);})['catch'](function(_0x46bb3a){logger[_0x0bb0('0x9')](_0x0bb0('0x18'),_0x46bb3a?util[_0x0bb0('0x7')](_0x46bb3a,{'showHidden':![],'depth':null}):'');return _0x532cf2(null);});}return _0x532cf2(null);});};exports[_0x0bb0('0x19')]=function(_0x408558){return new BPromise(function(_0xfc694e,_0x35c5e4){if(_0x408558){return getUser({'interface':_0x408558})[_0x0bb0('0xb')](function(_0x4d986c){logger[_0x0bb0('0x6')](_0x0bb0('0x1a'),_0x408558,_0x4d986c?_0x0bb0('0x16'):'notfound');return _0xfc694e(_0x4d986c);})[_0x0bb0('0x1b')](function(_0x1f2c05){logger[_0x0bb0('0x9')](_0x0bb0('0x1c'),_0x1f2c05?util[_0x0bb0('0x7')](_0x1f2c05,{'showHidden':![],'depth':null}):'');return _0xfc694e(null);});}return _0xfc694e(null);});};exports[_0x0bb0('0x1d')]=function(_0x551cf2){return new BPromise(function(_0x56a6f6,_0x4bf35e){if(_0x551cf2){return getUser({'name':_0x551cf2})[_0x0bb0('0xb')](function(_0x21624e){logger['info'](_0x0bb0('0x1e'),_0x551cf2,_0x21624e?_0x0bb0('0x16'):'notfound');return _0x56a6f6(_0x21624e);})[_0x0bb0('0x1b')](function(_0x296a43){logger[_0x0bb0('0x9')](_0x0bb0('0x1f'),_0x296a43?util[_0x0bb0('0x7')](_0x296a43,{'showHidden':![],'depth':null}):'');return _0x56a6f6(null);});}return _0x56a6f6(null);});};exports[_0x0bb0('0x20')]=function(_0x4ee06b){return new BPromise(function(_0xbf444e,_0x433f5a){if(_0x4ee06b){return client[_0x0bb0('0xa')](_0x0bb0('0x21'),{'options':{'raw':!![],'attributes':['id','name',_0x0bb0('0x22'),_0x0bb0('0x23'),_0x0bb0('0x24')],'where':{'name':_0x4ee06b},'limit':0x1}})[_0x0bb0('0xb')](function(_0x13bbf3){logger[_0x0bb0('0x8')](_0x0bb0('0x25'),_0x4ee06b,_0x13bbf3?util[_0x0bb0('0x7')](_0x13bbf3,{'showHidden':![],'depth':null}):'');logger[_0x0bb0('0x6')](_0x0bb0('0x26'),_0x4ee06b,_0x13bbf3?_0x0bb0('0x16'):_0x0bb0('0x17'));return _0xbf444e(_0x13bbf3[_0x0bb0('0x13')][_0x0bb0('0x14')]?_0x13bbf3[_0x0bb0('0x13')][0x0]:null);})[_0x0bb0('0x1b')](function(_0xe852c0){logger['error'](_0x0bb0('0x27'),_0xe852c0?util['inspect'](_0xe852c0,{'showHidden':![],'depth':null}):'');return _0xbf444e(null);});}return _0xbf444e(null);});};exports[_0x0bb0('0x28')]=function(_0x47b49c,_0x51c8db){return moment(_0x47b49c)[_0x0bb0('0x29')](_0x51c8db,_0x0bb0('0x2a'))[_0x0bb0('0x2b')]('YYYY-MM-DD\x20HH:mm:ss');};exports['subtractTime']=function(_0x158028,_0x381601){return moment(_0x158028)['subtract'](_0x381601,'seconds')[_0x0bb0('0x2b')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x0bb0('0x2c')]=function(_0x11c70b,_0x3e741d){return moment(_0x11c70b)[_0x0bb0('0x2d')](moment(_0x3e741d),_0x0bb0('0x2a'));};exports['sumTime']=function(_0x56797d,_0x400465){return parseInt(_0x56797d,0xa)+parseInt(_0x400465,0xa);};exports[_0x0bb0('0x2e')]=function(){return moment()[_0x0bb0('0x2b')](_0x0bb0('0x2f'));};exports[_0x0bb0('0x30')]=function(_0x4994f5,_0x50515a){if(_0x50515a){return moment(_0x4994f5)['isAfter'](_0x50515a);}return!![];};exports['isBefore']=function(_0x3e0695,_0x30ec46){if(_0x30ec46){return moment(_0x3e0695)[_0x0bb0('0x31')](_0x30ec46);}else if(_0x3e0695){return!![];}return![];};