Built motion from commit (unavailable).|2.3.10
[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 _0x47f2=['rpc','../../config/environment','jayson/promise','client','http','then','info','Variable,\x20%s,\x20%s','request\x20sent','stringify','code','error','message','find','options','include','map','model','attributes','ShowVariable','debug','catch','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger'];(function(_0x578c04,_0x38cd84){var _0x56457a=function(_0x58c57f){while(--_0x58c57f){_0x578c04['push'](_0x578c04['shift']());}};_0x56457a(++_0x38cd84);}(_0x47f2,0x1f2));var _0x247f=function(_0x317fa4,_0x5d944c){_0x317fa4=_0x317fa4-0x0;var _0x2265dc=_0x47f2[_0x317fa4];return _0x2265dc;};'use strict';var _=require('lodash');var util=require('util');var moment=require('moment');var BPromise=require(_0x247f('0x0'));var rs=require(_0x247f('0x1'));var fs=require('fs');var Redis=require(_0x247f('0x2'));var db=require(_0x247f('0x3'))['db'];var utils=require(_0x247f('0x4'));var logger=require(_0x247f('0x5'))(_0x247f('0x6'));var config=require(_0x247f('0x7'));var jayson=require(_0x247f('0x8'));var client=jayson[_0x247f('0x9')][_0x247f('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x489a52,_0x1a74ac,_0x55b7b4){return new BPromise(function(_0x1763e2,_0x272096){return client['request'](_0x489a52,_0x55b7b4)[_0x247f('0xb')](function(_0x42c0fb){logger[_0x247f('0xc')](_0x247f('0xd'),_0x1a74ac,_0x247f('0xe'));logger['debug']('Variable,\x20%s,\x20%s,\x20%s',_0x1a74ac,_0x247f('0xe'),JSON[_0x247f('0xf')](_0x42c0fb));if(_0x42c0fb['error']){if(_0x42c0fb['error'][_0x247f('0x10')]===0x1f4){logger[_0x247f('0x11')](_0x247f('0xd'),_0x1a74ac,_0x42c0fb[_0x247f('0x11')][_0x247f('0x12')]);return _0x272096(_0x42c0fb[_0x247f('0x11')][_0x247f('0x12')]);}logger['error'](_0x247f('0xd'),_0x1a74ac,_0x42c0fb[_0x247f('0x11')][_0x247f('0x12')]);return _0x1763e2(_0x42c0fb[_0x247f('0x11')][_0x247f('0x12')]);}else{logger[_0x247f('0xc')]('Variable,\x20%s,\x20%s',_0x1a74ac,_0x247f('0xe'));_0x1763e2(_0x42c0fb['result'][_0x247f('0x12')]);}})['catch'](function(_0x46bc0f){logger[_0x247f('0x11')](_0x247f('0xd'),_0x1a74ac,_0x46bc0f);_0x272096(_0x46bc0f);});});}exports['ShowVariable']=function(_0x42a484){var _0x30cfed=this;return new Promise(function(_0x54297c,_0x4bbda2){return db['Variable'][_0x247f('0x13')]({'raw':_0x42a484[_0x247f('0x14')]?_0x42a484[_0x247f('0x14')]['raw']===undefined?!![]:![]:!![],'where':_0x42a484['options']?_0x42a484[_0x247f('0x14')]['where']||null:null,'attributes':_0x42a484[_0x247f('0x14')]?_0x42a484[_0x247f('0x14')]['attributes']||null:null,'include':_0x42a484['options']?_0x42a484[_0x247f('0x14')][_0x247f('0x15')]?_[_0x247f('0x16')](_0x42a484[_0x247f('0x14')][_0x247f('0x15')],function(_0x21ef2b){return{'model':db[_0x21ef2b['model']],'as':_0x21ef2b['as'],'attributes':_0x21ef2b['attributes'],'include':_0x21ef2b['include']?_[_0x247f('0x16')](_0x21ef2b[_0x247f('0x15')],function(_0xf6be05){return{'model':db[_0xf6be05[_0x247f('0x17')]],'as':_0xf6be05['as'],'attributes':_0xf6be05[_0x247f('0x18')],'include':_0xf6be05[_0x247f('0x15')]?_['map'](_0xf6be05['include'],function(_0x1c6bdb){return{'model':db[_0x1c6bdb[_0x247f('0x17')]],'as':_0x1c6bdb['as'],'attributes':_0x1c6bdb[_0x247f('0x18')]};}):[]};}):[]};}):[]:[]})[_0x247f('0xb')](function(_0x1d1421){logger['info'](_0x247f('0x19'),_0x42a484);logger[_0x247f('0x1a')]('ShowVariable',_0x42a484,JSON[_0x247f('0xf')](_0x1d1421));_0x54297c(_0x1d1421);})[_0x247f('0x1b')](function(_0x535054){logger['error'](_0x247f('0x19'),_0x535054['message'],_0x42a484);_0x4bbda2(_0x30cfed[_0x247f('0x11')](0x1f4,_0x535054['message']));});});};