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 _0x120f=['sumTime','now','isBefore','client','../../config/logger','xdr','info','debug','stringify','error','request','catch','stack','GetUser','internal','interface','then','GETUSER|','result','length','FOUND','NOTFOUND','getUserByInternal','getUserByInterface','getVoiceQueueByName','name','acw','acwTimeout','GETVOICEQUEUEBYNAME|','addTime','format','YYYY-MM-DD\x20HH:mm:ss','subtractTime','subtract','seconds','diffTime','diff'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x120f,0x12b));var _0xf120=function(_0xf382d,_0x185322){_0xf382d=_0xf382d-0x0;var _0x24d522=_0x120f[_0xf382d];return _0x24d522;};'use strict';var jayson=require('jayson/promise');var moment=require('moment');var BPromise=require('bluebird');var client=jayson[_0xf120('0x0')]['http']({'port':0x2329});var logger=require(_0xf120('0x1'))(_0xf120('0x2'));exports['info']=function(_0x5dd615){logger[_0xf120('0x3')](_0x5dd615);};exports[_0xf120('0x4')]=function(_0x1ec1c0){logger[_0xf120('0x4')](JSON[_0xf120('0x5')](_0x1ec1c0));};exports[_0xf120('0x6')]=function(_0x4da1e9){logger['error'](_0x4da1e9['stack']);};exports[_0xf120('0x7')]=function(_0x3fae7f,_0x1d87dc){return client[_0xf120('0x7')](_0x3fae7f,{'body':_0x1d87dc})['then'](function(_0x41bd63){logger[_0xf120('0x4')](JSON[_0xf120('0x5')](_0x41bd63));})[_0xf120('0x8')](function(_0x267b02){logger[_0xf120('0x6')](_0x267b02[_0xf120('0x9')]);});};function getUser(_0x80ce0){return client[_0xf120('0x7')](_0xf120('0xa'),{'options':{'raw':!![],'attributes':['id',_0xf120('0xb'),'name',_0xf120('0xc')],'where':_0x80ce0,'limit':0x1}})[_0xf120('0xd')](function(_0xa5c05b){logger[_0xf120('0x3')](_0xf120('0xe')+JSON[_0xf120('0x5')](_0x80ce0)+'|'+(_0xa5c05b[_0xf120('0xf')][_0xf120('0x10')]?_0xf120('0x11'):_0xf120('0x12')));return _0xa5c05b['result'][_0xf120('0x10')]?_0xa5c05b[_0xf120('0xf')][0x0]:null;});}exports[_0xf120('0x13')]=function(_0x2a29f7){return new BPromise(function(_0x15dadf,_0x28d81e){if(_0x2a29f7){return getUser({'internal':_0x2a29f7})['then'](function(_0x52ca36){return _0x15dadf(_0x52ca36);})['catch'](function(_0x46c6fa){logger[_0xf120('0x6')](_0x46c6fa[_0xf120('0x9')]);return _0x15dadf(null);});}else{return _0x15dadf(null);}});};exports[_0xf120('0x14')]=function(_0xea0760){return new BPromise(function(_0x269d4c,_0x58cc70){if(_0xea0760){return getUser({'interface':_0xea0760})[_0xf120('0xd')](function(_0x4e45a2){return _0x269d4c(_0x4e45a2);})[_0xf120('0x8')](function(_0x2b6a8a){logger[_0xf120('0x6')](_0x2b6a8a[_0xf120('0x9')]);return _0x269d4c(null);});}else{return _0x269d4c(null);}});};exports['getUserByName']=function(_0x55c7cc){return new BPromise(function(_0x2aff81,_0x273b99){if(_0x55c7cc){return getUser({'name':_0x55c7cc})[_0xf120('0xd')](function(_0x3840a8){return _0x2aff81(_0x3840a8);})[_0xf120('0x8')](function(_0x431b22){logger[_0xf120('0x6')](_0x431b22[_0xf120('0x9')]);return _0x2aff81(null);});}else{return _0x2aff81(null);}});};exports[_0xf120('0x15')]=function(_0x359156){return new BPromise(function(_0x138ac7,_0x5ee300){if(_0x359156){return client[_0xf120('0x7')]('GetVoiceQueue',{'options':{'raw':!![],'attributes':['id',_0xf120('0x16'),'type',_0xf120('0x17'),_0xf120('0x18')],'where':{'name':_0x359156},'limit':0x1}})[_0xf120('0xd')](function(_0x50865e){logger['info'](_0xf120('0x19')+_0x359156+'|'+(_0x50865e['result']['length']?_0xf120('0x11'):_0xf120('0x12')));return _0x138ac7(_0x50865e[_0xf120('0xf')]['length']?_0x50865e[_0xf120('0xf')][0x0]:null);})[_0xf120('0x8')](function(_0x42f63b){logger['error'](_0x42f63b[_0xf120('0x9')]);return _0x138ac7(null);});}else{return _0x138ac7(null);}});};exports[_0xf120('0x1a')]=function(_0x4e507c,_0x26d787){return moment(_0x4e507c)['add'](_0x26d787,'seconds')[_0xf120('0x1b')](_0xf120('0x1c'));};exports[_0xf120('0x1d')]=function(_0x25d519,_0x11540b){return moment(_0x25d519)[_0xf120('0x1e')](_0x11540b,_0xf120('0x1f'))[_0xf120('0x1b')]('YYYY-MM-DD\x20HH:mm:ss');};exports[_0xf120('0x20')]=function(_0xe7becb,_0x56dcc6){return moment(_0xe7becb)[_0xf120('0x21')](moment(_0x56dcc6),_0xf120('0x1f'));};exports[_0xf120('0x22')]=function(_0x880528,_0x326e9f){return parseInt(_0x880528,0xa)+parseInt(_0x326e9f,0xa);};exports[_0xf120('0x23')]=function(){return moment()['format'](_0xf120('0x1c'));};exports['isAfter']=function(_0x471265,_0x4a3def){if(_0x4a3def){return moment(_0x471265)['isAfter'](_0x4a3def);}else{return!![];}};exports[_0xf120('0x24')]=function(_0x62d94b,_0x198b04){if(_0x198b04){return moment(_0x62d94b)[_0xf120('0x24')](_0x198b04);}else if(_0x62d94b){return!![];}else{return![];}};