72b816890ae24e3a24d757e3d53a1168a6575f54
[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 _0x05b0=['debug','catch','moment','bluebird','ioredis','../../mysqldb','../../config/logger','rpc','jayson/promise','client','http','request','then','Campaign,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','result','Campaign','findAll','options','attributes','limit','include','map','model','GetCampaign'];(function(_0xfae23b,_0x2be4ba){var _0x200640=function(_0x4ae258){while(--_0x4ae258){_0xfae23b['push'](_0xfae23b['shift']());}};_0x200640(++_0x2be4ba);}(_0x05b0,0x188));var _0x005b=function(_0x27bcdc,_0x34de59){_0x27bcdc=_0x27bcdc-0x0;var _0x128954=_0x05b0[_0x27bcdc];return _0x128954;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0x005b('0x0'));var BPromise=require(_0x005b('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x005b('0x2'));var db=require(_0x005b('0x3'))['db'];var utils=require('../../config/utils');var logger=require(_0x005b('0x4'))(_0x005b('0x5'));var config=require('../../config/environment');var jayson=require(_0x005b('0x6'));var client=jayson[_0x005b('0x7')][_0x005b('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x98e71c,_0x224c8d,_0x35998d){return new BPromise(function(_0x263bc9,_0x5cff7f){return client[_0x005b('0x9')](_0x98e71c,_0x35998d)[_0x005b('0xa')](function(_0x4c5552){logger['info'](_0x005b('0xb'),_0x224c8d,'request\x20sent');logger['debug']('Campaign,\x20%s,\x20%s,\x20%s',_0x224c8d,_0x005b('0xc'),JSON[_0x005b('0xd')](_0x4c5552));if(_0x4c5552['error']){if(_0x4c5552[_0x005b('0xe')][_0x005b('0xf')]===0x1f4){logger[_0x005b('0xe')](_0x005b('0xb'),_0x224c8d,_0x4c5552[_0x005b('0xe')][_0x005b('0x10')]);return _0x5cff7f(_0x4c5552[_0x005b('0xe')]['message']);}logger['error']('Campaign,\x20%s,\x20%s',_0x224c8d,_0x4c5552[_0x005b('0xe')]['message']);return _0x263bc9(_0x4c5552[_0x005b('0xe')]['message']);}else{logger[_0x005b('0x11')](_0x005b('0xb'),_0x224c8d,_0x005b('0xc'));_0x263bc9(_0x4c5552[_0x005b('0x12')][_0x005b('0x10')]);}})['catch'](function(_0xa3c3fb){logger[_0x005b('0xe')](_0x005b('0xb'),_0x224c8d,_0xa3c3fb);_0x5cff7f(_0xa3c3fb);});});}exports['GetCampaign']=function(_0x206c0a){var _0x5114ad=this;return new Promise(function(_0x50a6eb,_0x2d62b6){return db[_0x005b('0x13')][_0x005b('0x14')]({'raw':_0x206c0a[_0x005b('0x15')]?_0x206c0a[_0x005b('0x15')]['raw']===undefined?!![]:![]:!![],'where':_0x206c0a[_0x005b('0x15')]?_0x206c0a[_0x005b('0x15')]['where']||null:null,'attributes':_0x206c0a[_0x005b('0x15')]?_0x206c0a[_0x005b('0x15')][_0x005b('0x16')]||null:null,'limit':_0x206c0a['options']?_0x206c0a[_0x005b('0x15')][_0x005b('0x17')]||null:null,'include':_0x206c0a[_0x005b('0x15')]?_0x206c0a[_0x005b('0x15')][_0x005b('0x18')]?_[_0x005b('0x19')](_0x206c0a['options'][_0x005b('0x18')],function(_0x169428){return{'model':db[_0x169428[_0x005b('0x1a')]],'as':_0x169428['as'],'attributes':_0x169428['attributes'],'include':_0x169428[_0x005b('0x18')]?_['map'](_0x169428[_0x005b('0x18')],function(_0x527294){return{'model':db[_0x527294['model']],'as':_0x527294['as'],'attributes':_0x527294[_0x005b('0x16')],'include':_0x527294[_0x005b('0x18')]?_[_0x005b('0x19')](_0x527294[_0x005b('0x18')],function(_0x6730d4){return{'model':db[_0x6730d4[_0x005b('0x1a')]],'as':_0x6730d4['as'],'attributes':_0x6730d4[_0x005b('0x16')]};}):[]};}):[]};}):[]:[]})[_0x005b('0xa')](function(_0x4e9072){logger[_0x005b('0x11')](_0x005b('0x1b'),_0x206c0a);logger[_0x005b('0x1c')](_0x005b('0x1b'),_0x206c0a,JSON[_0x005b('0xd')](_0x4e9072));_0x50a6eb(_0x4e9072);})[_0x005b('0x1d')](function(_0x4775a2){logger['error'](_0x005b('0x1b'),_0x4775a2[_0x005b('0x10')],_0x206c0a);_0x2d62b6(_0x5114ad[_0x005b('0xe')](0x1f4,_0x4775a2[_0x005b('0x10')]));});});};