b73c04c1c9411ba4d97da6badf1c1ed8cd749996
[motion2.git] / server / api / campaign / campaign.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 _0x4d9e=['where','attributes','limit','include','model','map','lodash','bluebird','ioredis','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','request','then','info','request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s','stringify','error','Campaign,\x20%s,\x20%s','message','catch','GetCampaign','Campaign','findAll','options'];(function(_0x4a7631,_0x2c85b9){var _0x1a5a6f=function(_0x1ee3fd){while(--_0x1ee3fd){_0x4a7631['push'](_0x4a7631['shift']());}};_0x1a5a6f(++_0x2c85b9);}(_0x4d9e,0x18c));var _0xe4d9=function(_0x540b50,_0x2e201b){_0x540b50=_0x540b50-0x0;var _0x5c9243=_0x4d9e[_0x540b50];return _0x5c9243;};'use strict';var _=require(_0xe4d9('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0xe4d9('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0xe4d9('0x2'));var db=require('../../mysqldb')['db'];var utils=require(_0xe4d9('0x3'));var logger=require(_0xe4d9('0x4'))('rpc');var config=require(_0xe4d9('0x5'));var jayson=require(_0xe4d9('0x6'));var client=jayson[_0xe4d9('0x7')][_0xe4d9('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x125dbc,_0x32222c,_0x54a63a){return new BPromise(function(_0x36316f,_0x1d3810){return client[_0xe4d9('0x9')](_0x125dbc,_0x54a63a)[_0xe4d9('0xa')](function(_0x3f8937){logger[_0xe4d9('0xb')]('Campaign,\x20%s,\x20%s',_0x32222c,_0xe4d9('0xc'));logger[_0xe4d9('0xd')](_0xe4d9('0xe'),_0x32222c,_0xe4d9('0xc'),JSON[_0xe4d9('0xf')](_0x3f8937));if(_0x3f8937[_0xe4d9('0x10')]){if(_0x3f8937[_0xe4d9('0x10')]['code']===0x1f4){logger['error']('Campaign,\x20%s,\x20%s',_0x32222c,_0x3f8937['error']['message']);return _0x1d3810(_0x3f8937['error']['message']);}logger['error'](_0xe4d9('0x11'),_0x32222c,_0x3f8937[_0xe4d9('0x10')][_0xe4d9('0x12')]);return _0x36316f(_0x3f8937['error'][_0xe4d9('0x12')]);}else{logger[_0xe4d9('0xb')](_0xe4d9('0x11'),_0x32222c,_0xe4d9('0xc'));_0x36316f(_0x3f8937['result'][_0xe4d9('0x12')]);}})[_0xe4d9('0x13')](function(_0x4687f8){logger['error']('Campaign,\x20%s,\x20%s',_0x32222c,_0x4687f8);_0x1d3810(_0x4687f8);});});}exports[_0xe4d9('0x14')]=function(_0x112315){var _0x5ab3d1=this;return new Promise(function(_0x2e1490,_0x4f8dba){return db[_0xe4d9('0x15')][_0xe4d9('0x16')]({'raw':_0x112315[_0xe4d9('0x17')]?_0x112315[_0xe4d9('0x17')]['raw']===undefined?!![]:![]:!![],'where':_0x112315[_0xe4d9('0x17')]?_0x112315[_0xe4d9('0x17')][_0xe4d9('0x18')]||null:null,'attributes':_0x112315[_0xe4d9('0x17')]?_0x112315[_0xe4d9('0x17')][_0xe4d9('0x19')]||null:null,'limit':_0x112315[_0xe4d9('0x17')]?_0x112315[_0xe4d9('0x17')][_0xe4d9('0x1a')]||null:null,'include':_0x112315['options']?_0x112315[_0xe4d9('0x17')][_0xe4d9('0x1b')]?_['map'](_0x112315[_0xe4d9('0x17')]['include'],function(_0x14f3d7){return{'model':db[_0x14f3d7[_0xe4d9('0x1c')]],'as':_0x14f3d7['as'],'attributes':_0x14f3d7['attributes'],'include':_0x14f3d7[_0xe4d9('0x1b')]?_[_0xe4d9('0x1d')](_0x14f3d7['include'],function(_0xc5be1b){return{'model':db[_0xc5be1b[_0xe4d9('0x1c')]],'as':_0xc5be1b['as'],'attributes':_0xc5be1b[_0xe4d9('0x19')],'include':_0xc5be1b['include']?_['map'](_0xc5be1b[_0xe4d9('0x1b')],function(_0x2846e2){return{'model':db[_0x2846e2['model']],'as':_0x2846e2['as'],'attributes':_0x2846e2['attributes']};}):[]};}):[]};}):[]:[]})['then'](function(_0x529e2b){logger[_0xe4d9('0xb')]('GetCampaign',_0x112315);logger[_0xe4d9('0xd')](_0xe4d9('0x14'),_0x112315,JSON[_0xe4d9('0xf')](_0x529e2b));_0x2e1490(_0x529e2b);})['catch'](function(_0xec8d64){logger[_0xe4d9('0x10')](_0xe4d9('0x14'),_0xec8d64[_0xe4d9('0x12')],_0x112315);_0x4f8dba(_0x5ab3d1[_0xe4d9('0x10')](0x1f4,_0xec8d64[_0xe4d9('0x12')]));});});};