c8c3972ee29954de604d580932e67f6fbdce00d0
[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 _0xc46a=['client','http','../../config/logger','xdr','info','debug','stringify','error','stack','request','catch','GetUser','name','then','length','FOUND','result','getUserByInterface','getUserByName','getVoiceQueueByName','GetVoiceQueue','type','acwTimeout','GETVOICEQUEUEBYNAME|','NOTFOUND','addTime','add','seconds','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','diff','now','isAfter','isBefore','jayson/promise','moment'];(function(_0x4f4c2a,_0x5f5a28){var _0xd15be6=function(_0x1bc725){while(--_0x1bc725){_0x4f4c2a['push'](_0x4f4c2a['shift']());}};_0xd15be6(++_0x5f5a28);}(_0xc46a,0x1c6));var _0xac46=function(_0x56dc8c,_0x1b15ca){_0x56dc8c=_0x56dc8c-0x0;var _0x166838=_0xc46a[_0x56dc8c];return _0x166838;};'use strict';var jayson=require(_0xac46('0x0'));var moment=require(_0xac46('0x1'));var BPromise=require('bluebird');var client=jayson[_0xac46('0x2')][_0xac46('0x3')]({'port':0x2329});var logger=require(_0xac46('0x4'))(_0xac46('0x5'));exports['info']=function(_0x3d6fea){logger[_0xac46('0x6')](_0x3d6fea);};exports[_0xac46('0x7')]=function(_0x31d3fa){logger['debug'](JSON[_0xac46('0x8')](_0x31d3fa));};exports[_0xac46('0x9')]=function(_0x1f4e69){logger[_0xac46('0x9')](_0x1f4e69[_0xac46('0xa')]);};exports[_0xac46('0xb')]=function(_0xbe8cf1,_0x325271){return client[_0xac46('0xb')](_0xbe8cf1,{'body':_0x325271})['then'](function(_0x6b9a49){logger[_0xac46('0x7')](JSON[_0xac46('0x8')](_0x6b9a49));})[_0xac46('0xc')](function(_0x479498){logger[_0xac46('0x9')](_0x479498[_0xac46('0xa')]);});};function getUser(_0x54db31){return client[_0xac46('0xb')](_0xac46('0xd'),{'options':{'raw':!![],'attributes':['id','internal',_0xac46('0xe'),'interface'],'where':_0x54db31,'limit':0x1}})[_0xac46('0xf')](function(_0x574d9c){logger['info']('GETUSER|'+JSON[_0xac46('0x8')](_0x54db31)+'|'+(_0x574d9c['result'][_0xac46('0x10')]?_0xac46('0x11'):'NOTFOUND'));return _0x574d9c[_0xac46('0x12')][_0xac46('0x10')]?_0x574d9c['result'][0x0]:null;});}exports['getUserByInternal']=function(_0x2a57ee){return new BPromise(function(_0x5502b5,_0x2225e4){if(_0x2a57ee){return getUser({'internal':_0x2a57ee})[_0xac46('0xf')](function(_0x579600){return _0x5502b5(_0x579600);})['catch'](function(_0x31905f){logger[_0xac46('0x9')](_0x31905f[_0xac46('0xa')]);return _0x5502b5(null);});}else{return _0x5502b5(null);}});};exports[_0xac46('0x13')]=function(_0x565755){return new BPromise(function(_0x4d0281,_0x547aa0){if(_0x565755){return getUser({'interface':_0x565755})[_0xac46('0xf')](function(_0xda093){return _0x4d0281(_0xda093);})[_0xac46('0xc')](function(_0x29d86f){logger[_0xac46('0x9')](_0x29d86f[_0xac46('0xa')]);return _0x4d0281(null);});}else{return _0x4d0281(null);}});};exports[_0xac46('0x14')]=function(_0x4a902d){return new BPromise(function(_0x38124d,_0x43780e){if(_0x4a902d){return getUser({'name':_0x4a902d})[_0xac46('0xf')](function(_0x166783){return _0x38124d(_0x166783);})['catch'](function(_0x4ab127){logger['error'](_0x4ab127['stack']);return _0x38124d(null);});}else{return _0x38124d(null);}});};exports[_0xac46('0x15')]=function(_0x3cd8f3){return new BPromise(function(_0x5a4409,_0x56b3be){if(_0x3cd8f3){return client[_0xac46('0xb')](_0xac46('0x16'),{'options':{'raw':!![],'attributes':['id',_0xac46('0xe'),_0xac46('0x17'),'acw',_0xac46('0x18')],'where':{'name':_0x3cd8f3},'limit':0x1}})[_0xac46('0xf')](function(_0x343d8c){logger['info'](_0xac46('0x19')+_0x3cd8f3+'|'+(_0x343d8c[_0xac46('0x12')]['length']?_0xac46('0x11'):_0xac46('0x1a')));return _0x5a4409(_0x343d8c[_0xac46('0x12')]['length']?_0x343d8c[_0xac46('0x12')][0x0]:null);})[_0xac46('0xc')](function(_0x33abf4){logger[_0xac46('0x9')](_0x33abf4[_0xac46('0xa')]);return _0x5a4409(null);});}else{return _0x5a4409(null);}});};exports[_0xac46('0x1b')]=function(_0x2b10ae,_0x58f5a5){return moment(_0x2b10ae)[_0xac46('0x1c')](_0x58f5a5,_0xac46('0x1d'))[_0xac46('0x1e')](_0xac46('0x1f'));};exports[_0xac46('0x20')]=function(_0x3e4274,_0x349747){return moment(_0x3e4274)[_0xac46('0x21')](_0x349747,_0xac46('0x1d'))[_0xac46('0x1e')](_0xac46('0x1f'));};exports['diffTime']=function(_0x205f39,_0x23800f){return moment(_0x205f39)[_0xac46('0x22')](moment(_0x23800f),_0xac46('0x1d'));};exports['sumTime']=function(_0x38cd48,_0x97e51a){return parseInt(_0x38cd48,0xa)+parseInt(_0x97e51a,0xa);};exports[_0xac46('0x23')]=function(){return moment()[_0xac46('0x1e')](_0xac46('0x1f'));};exports[_0xac46('0x24')]=function(_0x3deec2,_0x22a1e2){if(_0x22a1e2){return moment(_0x3deec2)[_0xac46('0x24')](_0x22a1e2);}else{return!![];}};exports[_0xac46('0x25')]=function(_0x8da576,_0x52f888){if(_0x52f888){return moment(_0x8da576)[_0xac46('0x25')](_0x52f888);}else if(_0x8da576){return!![];}else{return![];}};