2dd512e27c68f0ab6d900947069f96e628d61c40
[motion2.git] / server / api / variable / variable.rpc.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 _0x17e4=['http','request','then','info','Variable,\x20%s,\x20%s','request\x20sent','Variable,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','ShowVariable','options','attributes','map','include','model','debug','stringify','lodash','bluebird','randomstring','../../config/logger','../../config/environment','jayson/promise'];(function(_0x59ab6e,_0x493ff4){var _0x13994a=function(_0x59fc7a){while(--_0x59fc7a){_0x59ab6e['push'](_0x59ab6e['shift']());}};_0x13994a(++_0x493ff4);}(_0x17e4,0x1b4));var _0x417e=function(_0x52264e,_0x5b9432){_0x52264e=_0x52264e-0x0;var _0x12d8fc=_0x17e4[_0x52264e];return _0x12d8fc;};'use strict';var _=require(_0x417e('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0x417e('0x1'));var rs=require(_0x417e('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0x417e('0x3'))('rpc');var config=require(_0x417e('0x4'));var jayson=require(_0x417e('0x5'));var client=jayson['client'][_0x417e('0x6')]({'port':0x232a});function respondWithRpcPromise(_0x2d838c,_0x248728,_0x49598c){return new BPromise(function(_0x277fd8,_0xda9013){return client[_0x417e('0x7')](_0x2d838c,_0x49598c)[_0x417e('0x8')](function(_0x3efe6a){logger[_0x417e('0x9')](_0x417e('0xa'),_0x248728,_0x417e('0xb'));logger['debug'](_0x417e('0xc'),_0x248728,_0x417e('0xb'),JSON['stringify'](_0x3efe6a));if(_0x3efe6a['error']){if(_0x3efe6a[_0x417e('0xd')][_0x417e('0xe')]===0x1f4){logger[_0x417e('0xd')](_0x417e('0xa'),_0x248728,_0x3efe6a[_0x417e('0xd')][_0x417e('0xf')]);return _0xda9013(_0x3efe6a['error'][_0x417e('0xf')]);}logger[_0x417e('0xd')]('Variable,\x20%s,\x20%s',_0x248728,_0x3efe6a[_0x417e('0xd')][_0x417e('0xf')]);return _0x277fd8(_0x3efe6a['error'][_0x417e('0xf')]);}else{logger['info'](_0x417e('0xa'),_0x248728,'request\x20sent');_0x277fd8(_0x3efe6a[_0x417e('0x10')][_0x417e('0xf')]);}})[_0x417e('0x11')](function(_0xa7dbb4){logger[_0x417e('0xd')]('Variable,\x20%s,\x20%s',_0x248728,_0xa7dbb4);_0xda9013(_0xa7dbb4);});});}exports[_0x417e('0x12')]=function(_0x52b028){var _0x41c4a3=this;return new Promise(function(_0x3c4705,_0x398a33){return db['Variable']['find']({'raw':_0x52b028[_0x417e('0x13')]?_0x52b028['options']['raw']===undefined?!![]:![]:!![],'where':_0x52b028[_0x417e('0x13')]?_0x52b028[_0x417e('0x13')]['where']||null:null,'attributes':_0x52b028[_0x417e('0x13')]?_0x52b028['options'][_0x417e('0x14')]||null:null,'include':_0x52b028['options']?_0x52b028[_0x417e('0x13')]['include']?_[_0x417e('0x15')](_0x52b028['options'][_0x417e('0x16')],function(_0x83a954){return{'model':db[_0x83a954[_0x417e('0x17')]],'as':_0x83a954['as'],'attributes':_0x83a954['attributes'],'include':_0x83a954[_0x417e('0x16')]?_['map'](_0x83a954['include'],function(_0x3512d0){return{'model':db[_0x3512d0[_0x417e('0x17')]],'as':_0x3512d0['as'],'attributes':_0x3512d0[_0x417e('0x14')],'include':_0x3512d0['include']?_['map'](_0x3512d0[_0x417e('0x16')],function(_0x90645a){return{'model':db[_0x90645a[_0x417e('0x17')]],'as':_0x90645a['as'],'attributes':_0x90645a['attributes']};}):[]};}):[]};}):[]:[]})[_0x417e('0x8')](function(_0x484800){logger[_0x417e('0x9')](_0x417e('0x12'),_0x52b028);logger[_0x417e('0x18')]('ShowVariable',_0x52b028,JSON[_0x417e('0x19')](_0x484800));_0x3c4705(_0x484800);})[_0x417e('0x11')](function(_0x51bbef){logger[_0x417e('0xd')]('ShowVariable',_0x51bbef[_0x417e('0xf')],_0x52b028);_0x398a33(_0x41c4a3[_0x417e('0xd')](0x1f4,_0x51bbef[_0x417e('0xf')]));});});};