72cabf45f1a9acb1088a21bf79e5c7a9300491dc
[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 _0x27ef=['catch','Variable','find','options','raw','attributes','include','map','model','ShowVariable','stringify','lodash','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','request','then','info','Variable,\x20%s,\x20%s','request\x20sent','debug','Variable,\x20%s,\x20%s,\x20%s','error','message','result'];(function(_0xa1bae2,_0x352272){var _0x2f3344=function(_0x336692){while(--_0x336692){_0xa1bae2['push'](_0xa1bae2['shift']());}};_0x2f3344(++_0x352272);}(_0x27ef,0xb5));var _0xf27e=function(_0x4f828c,_0x2f6cac){_0x4f828c=_0x4f828c-0x0;var _0x1fea4d=_0x27ef[_0x4f828c];return _0x1fea4d;};'use strict';var _=require(_0xf27e('0x0'));var util=require(_0xf27e('0x1'));var moment=require(_0xf27e('0x2'));var BPromise=require('bluebird');var rs=require(_0xf27e('0x3'));var fs=require('fs');var Redis=require(_0xf27e('0x4'));var db=require(_0xf27e('0x5'))['db'];var utils=require(_0xf27e('0x6'));var logger=require(_0xf27e('0x7'))(_0xf27e('0x8'));var config=require(_0xf27e('0x9'));var jayson=require(_0xf27e('0xa'));var client=jayson[_0xf27e('0xb')][_0xf27e('0xc')]({'port':0x232a});function respondWithRpcPromise(_0x477b7a,_0x27cd21,_0x313615){return new BPromise(function(_0x20606b,_0x58ed79){return client[_0xf27e('0xd')](_0x477b7a,_0x313615)[_0xf27e('0xe')](function(_0x3d0dd7){logger[_0xf27e('0xf')](_0xf27e('0x10'),_0x27cd21,_0xf27e('0x11'));logger[_0xf27e('0x12')](_0xf27e('0x13'),_0x27cd21,_0xf27e('0x11'),JSON['stringify'](_0x3d0dd7));if(_0x3d0dd7['error']){if(_0x3d0dd7[_0xf27e('0x14')]['code']===0x1f4){logger['error']('Variable,\x20%s,\x20%s',_0x27cd21,_0x3d0dd7[_0xf27e('0x14')][_0xf27e('0x15')]);return _0x58ed79(_0x3d0dd7[_0xf27e('0x14')][_0xf27e('0x15')]);}logger[_0xf27e('0x14')](_0xf27e('0x10'),_0x27cd21,_0x3d0dd7['error'][_0xf27e('0x15')]);return _0x20606b(_0x3d0dd7[_0xf27e('0x14')]['message']);}else{logger['info'](_0xf27e('0x10'),_0x27cd21,_0xf27e('0x11'));_0x20606b(_0x3d0dd7[_0xf27e('0x16')]['message']);}})[_0xf27e('0x17')](function(_0x1f25ab){logger[_0xf27e('0x14')](_0xf27e('0x10'),_0x27cd21,_0x1f25ab);_0x58ed79(_0x1f25ab);});});}exports['ShowVariable']=function(_0x5bce68){var _0x5417fd=this;return new Promise(function(_0x480810,_0x3b8e94){return db[_0xf27e('0x18')][_0xf27e('0x19')]({'raw':_0x5bce68['options']?_0x5bce68[_0xf27e('0x1a')][_0xf27e('0x1b')]===undefined?!![]:![]:!![],'where':_0x5bce68[_0xf27e('0x1a')]?_0x5bce68[_0xf27e('0x1a')]['where']||null:null,'attributes':_0x5bce68['options']?_0x5bce68[_0xf27e('0x1a')][_0xf27e('0x1c')]||null:null,'include':_0x5bce68[_0xf27e('0x1a')]?_0x5bce68[_0xf27e('0x1a')][_0xf27e('0x1d')]?_[_0xf27e('0x1e')](_0x5bce68[_0xf27e('0x1a')][_0xf27e('0x1d')],function(_0x173f46){return{'model':db[_0x173f46[_0xf27e('0x1f')]],'as':_0x173f46['as'],'attributes':_0x173f46[_0xf27e('0x1c')],'include':_0x173f46['include']?_[_0xf27e('0x1e')](_0x173f46[_0xf27e('0x1d')],function(_0x48d194){return{'model':db[_0x48d194[_0xf27e('0x1f')]],'as':_0x48d194['as'],'attributes':_0x48d194[_0xf27e('0x1c')],'include':_0x48d194[_0xf27e('0x1d')]?_[_0xf27e('0x1e')](_0x48d194[_0xf27e('0x1d')],function(_0x4f69f8){return{'model':db[_0x4f69f8[_0xf27e('0x1f')]],'as':_0x4f69f8['as'],'attributes':_0x4f69f8[_0xf27e('0x1c')]};}):[]};}):[]};}):[]:[]})[_0xf27e('0xe')](function(_0x38c0ad){logger[_0xf27e('0xf')](_0xf27e('0x20'),_0x5bce68);logger[_0xf27e('0x12')](_0xf27e('0x20'),_0x5bce68,JSON[_0xf27e('0x21')](_0x38c0ad));_0x480810(_0x38c0ad);})['catch'](function(_0x184fd4){logger[_0xf27e('0x14')](_0xf27e('0x20'),_0x184fd4[_0xf27e('0x15')],_0x5bce68);_0x3b8e94(_0x5417fd['error'](0x1f4,_0x184fd4[_0xf27e('0x15')]));});});};