e9f3ff68a1685cb60842f7268ba1712e68504109
[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 _0xb6b1=['rpc','../../config/environment','jayson/promise','client','request','then','request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s','stringify','error','Campaign,\x20%s,\x20%s','message','info','result','catch','GetCampaign','Campaign','findAll','options','raw','where','attributes','limit','include','map','model','lodash','moment','randomstring','ioredis','../../config/utils'];(function(_0x21c254,_0x51d2ff){var _0x442f28=function(_0x1ecbe7){while(--_0x1ecbe7){_0x21c254['push'](_0x21c254['shift']());}};_0x442f28(++_0x51d2ff);}(_0xb6b1,0x17b));var _0x1b6b=function(_0x375325,_0x57a850){_0x375325=_0x375325-0x0;var _0x228f57=_0xb6b1[_0x375325];return _0x228f57;};'use strict';var _=require(_0x1b6b('0x0'));var util=require('util');var moment=require(_0x1b6b('0x1'));var BPromise=require('bluebird');var rs=require(_0x1b6b('0x2'));var fs=require('fs');var Redis=require(_0x1b6b('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0x1b6b('0x4'));var logger=require('../../config/logger')(_0x1b6b('0x5'));var config=require(_0x1b6b('0x6'));var jayson=require(_0x1b6b('0x7'));var client=jayson[_0x1b6b('0x8')]['http']({'port':0x232a});function respondWithRpcPromise(_0x41d09e,_0x51cfed,_0xae4115){return new BPromise(function(_0x5042f7,_0x21f403){return client[_0x1b6b('0x9')](_0x41d09e,_0xae4115)[_0x1b6b('0xa')](function(_0x29258a){logger['info']('Campaign,\x20%s,\x20%s',_0x51cfed,_0x1b6b('0xb'));logger[_0x1b6b('0xc')](_0x1b6b('0xd'),_0x51cfed,_0x1b6b('0xb'),JSON[_0x1b6b('0xe')](_0x29258a));if(_0x29258a[_0x1b6b('0xf')]){if(_0x29258a[_0x1b6b('0xf')]['code']===0x1f4){logger[_0x1b6b('0xf')](_0x1b6b('0x10'),_0x51cfed,_0x29258a[_0x1b6b('0xf')]['message']);return _0x21f403(_0x29258a[_0x1b6b('0xf')]['message']);}logger['error'](_0x1b6b('0x10'),_0x51cfed,_0x29258a[_0x1b6b('0xf')][_0x1b6b('0x11')]);return _0x5042f7(_0x29258a[_0x1b6b('0xf')][_0x1b6b('0x11')]);}else{logger[_0x1b6b('0x12')](_0x1b6b('0x10'),_0x51cfed,'request\x20sent');_0x5042f7(_0x29258a[_0x1b6b('0x13')][_0x1b6b('0x11')]);}})[_0x1b6b('0x14')](function(_0x33dc7e){logger['error'](_0x1b6b('0x10'),_0x51cfed,_0x33dc7e);_0x21f403(_0x33dc7e);});});}exports[_0x1b6b('0x15')]=function(_0x2e608b){var _0x59e671=this;return new Promise(function(_0x923711,_0x15d44b){return db[_0x1b6b('0x16')][_0x1b6b('0x17')]({'raw':_0x2e608b[_0x1b6b('0x18')]?_0x2e608b[_0x1b6b('0x18')][_0x1b6b('0x19')]===undefined?!![]:![]:!![],'where':_0x2e608b[_0x1b6b('0x18')]?_0x2e608b[_0x1b6b('0x18')][_0x1b6b('0x1a')]||null:null,'attributes':_0x2e608b['options']?_0x2e608b[_0x1b6b('0x18')][_0x1b6b('0x1b')]||null:null,'limit':_0x2e608b[_0x1b6b('0x18')]?_0x2e608b[_0x1b6b('0x18')][_0x1b6b('0x1c')]||null:null,'include':_0x2e608b[_0x1b6b('0x18')]?_0x2e608b[_0x1b6b('0x18')][_0x1b6b('0x1d')]?_[_0x1b6b('0x1e')](_0x2e608b['options'][_0x1b6b('0x1d')],function(_0x489e7a){return{'model':db[_0x489e7a['model']],'as':_0x489e7a['as'],'attributes':_0x489e7a['attributes'],'include':_0x489e7a[_0x1b6b('0x1d')]?_[_0x1b6b('0x1e')](_0x489e7a['include'],function(_0x6a317c){return{'model':db[_0x6a317c['model']],'as':_0x6a317c['as'],'attributes':_0x6a317c[_0x1b6b('0x1b')],'include':_0x6a317c[_0x1b6b('0x1d')]?_[_0x1b6b('0x1e')](_0x6a317c[_0x1b6b('0x1d')],function(_0xd41b04){return{'model':db[_0xd41b04[_0x1b6b('0x1f')]],'as':_0xd41b04['as'],'attributes':_0xd41b04['attributes']};}):[]};}):[]};}):[]:[]})[_0x1b6b('0xa')](function(_0x1bb7f3){logger[_0x1b6b('0x12')](_0x1b6b('0x15'),_0x2e608b);logger['debug'](_0x1b6b('0x15'),_0x2e608b,JSON['stringify'](_0x1bb7f3));_0x923711(_0x1bb7f3);})['catch'](function(_0x39b055){logger['error'](_0x1b6b('0x15'),_0x39b055[_0x1b6b('0x11')],_0x2e608b);_0x15d44b(_0x59e671['error'](0x1f4,_0x39b055['message']));});});};