Built motion from commit 9d1906d1.|2.5.40
[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 _0x946e=['lodash','moment','randomstring','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','request','then','request\x20sent','stringify','code','error','message','Campaign,\x20%s,\x20%s','info','result','catch','GetCampaign','Campaign','options','where','attributes','limit','include','map','model'];(function(_0xb70c8f,_0x590e73){var _0x39cc76=function(_0x58ffe3){while(--_0x58ffe3){_0xb70c8f['push'](_0xb70c8f['shift']());}};_0x39cc76(++_0x590e73);}(_0x946e,0x1d0));var _0xe946=function(_0x2621a2,_0xfcd6af){_0x2621a2=_0x2621a2-0x0;var _0x3f1bc5=_0x946e[_0x2621a2];return _0x3f1bc5;};'use strict';var _=require(_0xe946('0x0'));var util=require('util');var moment=require(_0xe946('0x1'));var BPromise=require('bluebird');var rs=require(_0xe946('0x2'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0xe946('0x3'));var logger=require(_0xe946('0x4'))(_0xe946('0x5'));var config=require(_0xe946('0x6'));var jayson=require(_0xe946('0x7'));var client=jayson['client'][_0xe946('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x1b3546,_0x202126,_0x4e9ca6){return new BPromise(function(_0x39bd38,_0x492aa6){return client[_0xe946('0x9')](_0x1b3546,_0x4e9ca6)[_0xe946('0xa')](function(_0x5092b3){logger['info']('Campaign,\x20%s,\x20%s',_0x202126,_0xe946('0xb'));logger['debug']('Campaign,\x20%s,\x20%s,\x20%s',_0x202126,_0xe946('0xb'),JSON[_0xe946('0xc')](_0x5092b3));if(_0x5092b3['error']){if(_0x5092b3['error'][_0xe946('0xd')]===0x1f4){logger[_0xe946('0xe')]('Campaign,\x20%s,\x20%s',_0x202126,_0x5092b3[_0xe946('0xe')][_0xe946('0xf')]);return _0x492aa6(_0x5092b3[_0xe946('0xe')][_0xe946('0xf')]);}logger[_0xe946('0xe')](_0xe946('0x10'),_0x202126,_0x5092b3[_0xe946('0xe')]['message']);return _0x39bd38(_0x5092b3['error'][_0xe946('0xf')]);}else{logger[_0xe946('0x11')](_0xe946('0x10'),_0x202126,'request\x20sent');_0x39bd38(_0x5092b3[_0xe946('0x12')][_0xe946('0xf')]);}})[_0xe946('0x13')](function(_0x55e970){logger[_0xe946('0xe')](_0xe946('0x10'),_0x202126,_0x55e970);_0x492aa6(_0x55e970);});});}exports[_0xe946('0x14')]=function(_0x4d12f2){var _0x366de6=this;return new Promise(function(_0x3cde06,_0x47bde2){return db[_0xe946('0x15')]['findAll']({'raw':_0x4d12f2[_0xe946('0x16')]?_0x4d12f2[_0xe946('0x16')]['raw']===undefined?!![]:![]:!![],'where':_0x4d12f2[_0xe946('0x16')]?_0x4d12f2[_0xe946('0x16')][_0xe946('0x17')]||null:null,'attributes':_0x4d12f2[_0xe946('0x16')]?_0x4d12f2[_0xe946('0x16')][_0xe946('0x18')]||null:null,'limit':_0x4d12f2[_0xe946('0x16')]?_0x4d12f2[_0xe946('0x16')][_0xe946('0x19')]||null:null,'include':_0x4d12f2[_0xe946('0x16')]?_0x4d12f2['options'][_0xe946('0x1a')]?_[_0xe946('0x1b')](_0x4d12f2[_0xe946('0x16')][_0xe946('0x1a')],function(_0x169eec){return{'model':db[_0x169eec[_0xe946('0x1c')]],'as':_0x169eec['as'],'attributes':_0x169eec['attributes'],'include':_0x169eec[_0xe946('0x1a')]?_[_0xe946('0x1b')](_0x169eec[_0xe946('0x1a')],function(_0xd3d3b7){return{'model':db[_0xd3d3b7[_0xe946('0x1c')]],'as':_0xd3d3b7['as'],'attributes':_0xd3d3b7[_0xe946('0x18')],'include':_0xd3d3b7[_0xe946('0x1a')]?_[_0xe946('0x1b')](_0xd3d3b7[_0xe946('0x1a')],function(_0x562508){return{'model':db[_0x562508[_0xe946('0x1c')]],'as':_0x562508['as'],'attributes':_0x562508[_0xe946('0x18')]};}):[]};}):[]};}):[]:[]})[_0xe946('0xa')](function(_0x745db8){logger[_0xe946('0x11')](_0xe946('0x14'),_0x4d12f2);logger['debug'](_0xe946('0x14'),_0x4d12f2,JSON[_0xe946('0xc')](_0x745db8));_0x3cde06(_0x745db8);})[_0xe946('0x13')](function(_0x25682f){logger[_0xe946('0xe')](_0xe946('0x14'),_0x25682f[_0xe946('0xf')],_0x4d12f2);_0x47bde2(_0x366de6[_0xe946('0xe')](0x1f4,_0x25682f['message']));});});};