Built motion from commit (unavailable).|2.5.4
[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 _0x5623=['acwTimeout','GETVOICEQUEUEBYNAME|','add','format','subtractTime','subtract','seconds','YYYY-MM-DD\x20HH:mm:ss','diffTime','diff','sumTime','now','isAfter','isBefore','jayson/promise','moment','http','../../config/logger','xdr','info','debug','stringify','stack','request','then','catch','error','GetUser','name','interface','GETUSER|','result','length','FOUND','NOTFOUND','getUserByInternal','getUserByInterface','getUserByName','getVoiceQueueByName','GetVoiceQueue','type','acw'];(function(_0x1395a2,_0x5255a2){var _0x529a96=function(_0x5d4f4f){while(--_0x5d4f4f){_0x1395a2['push'](_0x1395a2['shift']());}};_0x529a96(++_0x5255a2);}(_0x5623,0x15e));var _0x3562=function(_0x1e2857,_0x54c755){_0x1e2857=_0x1e2857-0x0;var _0x4e66c2=_0x5623[_0x1e2857];return _0x4e66c2;};'use strict';var jayson=require(_0x3562('0x0'));var moment=require(_0x3562('0x1'));var BPromise=require('bluebird');var client=jayson['client'][_0x3562('0x2')]({'port':0x2329});var logger=require(_0x3562('0x3'))(_0x3562('0x4'));exports[_0x3562('0x5')]=function(_0x12c7e9){logger[_0x3562('0x5')](_0x12c7e9);};exports[_0x3562('0x6')]=function(_0x4462a0){logger[_0x3562('0x6')](JSON[_0x3562('0x7')](_0x4462a0));};exports['error']=function(_0x454b68){logger['error'](_0x454b68[_0x3562('0x8')]);};exports[_0x3562('0x9')]=function(_0xb973a7,_0x265574){return client['request'](_0xb973a7,{'body':_0x265574})[_0x3562('0xa')](function(_0x55fdfa){logger[_0x3562('0x6')](JSON[_0x3562('0x7')](_0x55fdfa));})[_0x3562('0xb')](function(_0x34256f){logger[_0x3562('0xc')](_0x34256f[_0x3562('0x8')]);});};function getUser(_0x59b07c){return client[_0x3562('0x9')](_0x3562('0xd'),{'options':{'raw':!![],'attributes':['id','internal',_0x3562('0xe'),_0x3562('0xf')],'where':_0x59b07c,'limit':0x1}})[_0x3562('0xa')](function(_0x49489e){logger[_0x3562('0x5')](_0x3562('0x10')+JSON['stringify'](_0x59b07c)+'|'+(_0x49489e[_0x3562('0x11')][_0x3562('0x12')]?_0x3562('0x13'):_0x3562('0x14')));return _0x49489e[_0x3562('0x11')][_0x3562('0x12')]?_0x49489e[_0x3562('0x11')][0x0]:null;});}exports[_0x3562('0x15')]=function(_0x38dc4a){return new BPromise(function(_0x42207e,_0x219749){if(_0x38dc4a){return getUser({'internal':_0x38dc4a})['then'](function(_0x7a0dd9){return _0x42207e(_0x7a0dd9);})[_0x3562('0xb')](function(_0x4b8cc3){logger[_0x3562('0xc')](_0x4b8cc3[_0x3562('0x8')]);return _0x42207e(null);});}else{return _0x42207e(null);}});};exports[_0x3562('0x16')]=function(_0x502224){return new BPromise(function(_0x8311a7,_0x53b60b){if(_0x502224){return getUser({'interface':_0x502224})['then'](function(_0x340950){return _0x8311a7(_0x340950);})['catch'](function(_0x4b9ea4){logger[_0x3562('0xc')](_0x4b9ea4[_0x3562('0x8')]);return _0x8311a7(null);});}else{return _0x8311a7(null);}});};exports[_0x3562('0x17')]=function(_0x5f4a18){return new BPromise(function(_0x461d3c,_0x32aa76){if(_0x5f4a18){return getUser({'name':_0x5f4a18})[_0x3562('0xa')](function(_0x188793){return _0x461d3c(_0x188793);})[_0x3562('0xb')](function(_0x13e7b0){logger[_0x3562('0xc')](_0x13e7b0[_0x3562('0x8')]);return _0x461d3c(null);});}else{return _0x461d3c(null);}});};exports[_0x3562('0x18')]=function(_0x4821fd){return new BPromise(function(_0x35e5df,_0x28f573){if(_0x4821fd){return client[_0x3562('0x9')](_0x3562('0x19'),{'options':{'raw':!![],'attributes':['id',_0x3562('0xe'),_0x3562('0x1a'),_0x3562('0x1b'),_0x3562('0x1c')],'where':{'name':_0x4821fd},'limit':0x1}})['then'](function(_0x1128cb){logger['info'](_0x3562('0x1d')+_0x4821fd+'|'+(_0x1128cb[_0x3562('0x11')][_0x3562('0x12')]?'FOUND':_0x3562('0x14')));return _0x35e5df(_0x1128cb['result']['length']?_0x1128cb[_0x3562('0x11')][0x0]:null);})[_0x3562('0xb')](function(_0x4ff62f){logger[_0x3562('0xc')](_0x4ff62f['stack']);return _0x35e5df(null);});}else{return _0x35e5df(null);}});};exports['addTime']=function(_0x4c88ae,_0x103b12){return moment(_0x4c88ae)[_0x3562('0x1e')](_0x103b12,'seconds')[_0x3562('0x1f')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0x3562('0x20')]=function(_0x7acbdc,_0x4d6037){return moment(_0x7acbdc)[_0x3562('0x21')](_0x4d6037,_0x3562('0x22'))[_0x3562('0x1f')](_0x3562('0x23'));};exports[_0x3562('0x24')]=function(_0xcc089e,_0x2af2ee){return moment(_0xcc089e)[_0x3562('0x25')](moment(_0x2af2ee),'seconds');};exports[_0x3562('0x26')]=function(_0x596ba8,_0x37f3ca){return parseInt(_0x596ba8,0xa)+parseInt(_0x37f3ca,0xa);};exports[_0x3562('0x27')]=function(){return moment()['format'](_0x3562('0x23'));};exports[_0x3562('0x28')]=function(_0x5574ee,_0xf77988){if(_0xf77988){return moment(_0x5574ee)[_0x3562('0x28')](_0xf77988);}else{return!![];}};exports[_0x3562('0x29')]=function(_0x362ab5,_0x42f505){if(_0x42f505){return moment(_0x362ab5)[_0x3562('0x29')](_0x42f505);}else if(_0x362ab5){return!![];}else{return![];}};