652c7b0dba5c63b36b54f1d29542bf82b99bccf4
[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 _0x6597=['jayson/promise','client','http','request','then','info','Campaign,\x20%s,\x20%s','debug','request\x20sent','error','message','result','catch','GetCampaign','Campaign','findAll','options','raw','where','attributes','limit','include','map','model','stringify','lodash','util','moment','randomstring','../../mysqldb','../../config/environment'];(function(_0xfc478e,_0x22c938){var _0x2e521f=function(_0x26c801){while(--_0x26c801){_0xfc478e['push'](_0xfc478e['shift']());}};_0x2e521f(++_0x22c938);}(_0x6597,0x16e));var _0x7659=function(_0x389c70,_0x973171){_0x389c70=_0x389c70-0x0;var _0x256e52=_0x6597[_0x389c70];return _0x256e52;};'use strict';var _=require(_0x7659('0x0'));var util=require(_0x7659('0x1'));var moment=require(_0x7659('0x2'));var BPromise=require('bluebird');var rs=require(_0x7659('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x7659('0x4'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')('rpc');var config=require(_0x7659('0x5'));var jayson=require(_0x7659('0x6'));var client=jayson[_0x7659('0x7')][_0x7659('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x11cb28,_0x5c4e7f,_0x5ae101){return new BPromise(function(_0x3cfb33,_0x361918){return client[_0x7659('0x9')](_0x11cb28,_0x5ae101)[_0x7659('0xa')](function(_0x597553){logger[_0x7659('0xb')](_0x7659('0xc'),_0x5c4e7f,'request\x20sent');logger[_0x7659('0xd')]('Campaign,\x20%s,\x20%s,\x20%s',_0x5c4e7f,_0x7659('0xe'),JSON['stringify'](_0x597553));if(_0x597553[_0x7659('0xf')]){if(_0x597553[_0x7659('0xf')]['code']===0x1f4){logger[_0x7659('0xf')](_0x7659('0xc'),_0x5c4e7f,_0x597553['error'][_0x7659('0x10')]);return _0x361918(_0x597553['error']['message']);}logger[_0x7659('0xf')](_0x7659('0xc'),_0x5c4e7f,_0x597553[_0x7659('0xf')][_0x7659('0x10')]);return _0x3cfb33(_0x597553[_0x7659('0xf')]['message']);}else{logger['info'](_0x7659('0xc'),_0x5c4e7f,_0x7659('0xe'));_0x3cfb33(_0x597553[_0x7659('0x11')][_0x7659('0x10')]);}})[_0x7659('0x12')](function(_0x26a0f0){logger['error'](_0x7659('0xc'),_0x5c4e7f,_0x26a0f0);_0x361918(_0x26a0f0);});});}exports[_0x7659('0x13')]=function(_0x471b17){var _0x2f1e6c=this;return new Promise(function(_0x100953,_0x201fee){return db[_0x7659('0x14')][_0x7659('0x15')]({'raw':_0x471b17[_0x7659('0x16')]?_0x471b17[_0x7659('0x16')][_0x7659('0x17')]===undefined?!![]:![]:!![],'where':_0x471b17[_0x7659('0x16')]?_0x471b17[_0x7659('0x16')][_0x7659('0x18')]||null:null,'attributes':_0x471b17[_0x7659('0x16')]?_0x471b17['options'][_0x7659('0x19')]||null:null,'limit':_0x471b17[_0x7659('0x16')]?_0x471b17[_0x7659('0x16')][_0x7659('0x1a')]||null:null,'include':_0x471b17['options']?_0x471b17['options'][_0x7659('0x1b')]?_[_0x7659('0x1c')](_0x471b17[_0x7659('0x16')]['include'],function(_0x45058f){return{'model':db[_0x45058f[_0x7659('0x1d')]],'as':_0x45058f['as'],'attributes':_0x45058f[_0x7659('0x19')],'include':_0x45058f['include']?_[_0x7659('0x1c')](_0x45058f[_0x7659('0x1b')],function(_0x185fb1){return{'model':db[_0x185fb1[_0x7659('0x1d')]],'as':_0x185fb1['as'],'attributes':_0x185fb1[_0x7659('0x19')],'include':_0x185fb1[_0x7659('0x1b')]?_[_0x7659('0x1c')](_0x185fb1[_0x7659('0x1b')],function(_0x24967b){return{'model':db[_0x24967b['model']],'as':_0x24967b['as'],'attributes':_0x24967b[_0x7659('0x19')]};}):[]};}):[]};}):[]:[]})[_0x7659('0xa')](function(_0x4e450f){logger[_0x7659('0xb')]('GetCampaign',_0x471b17);logger[_0x7659('0xd')](_0x7659('0x13'),_0x471b17,JSON[_0x7659('0x1e')](_0x4e450f));_0x100953(_0x4e450f);})['catch'](function(_0x99da88){logger[_0x7659('0xf')](_0x7659('0x13'),_0x99da88[_0x7659('0x10')],_0x471b17);_0x201fee(_0x2f1e6c[_0x7659('0xf')](0x1f4,_0x99da88[_0x7659('0x10')]));});});};