0e203dfc5ba5cf390ee7cb1a8f17ac3f2c441930
[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 _0x22fb=['request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s','code','message','error','result','catch','Campaign','findAll','options','where','limit','include','map','attributes','model','GetCampaign','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','request','then','info','Campaign,\x20%s,\x20%s'];(function(_0x18c269,_0x12c74f){var _0x760993=function(_0x4d5d23){while(--_0x4d5d23){_0x18c269['push'](_0x18c269['shift']());}};_0x760993(++_0x12c74f);}(_0x22fb,0x192));var _0xb22f=function(_0x27e99d,_0x46b58a){_0x27e99d=_0x27e99d-0x0;var _0x45a501=_0x22fb[_0x27e99d];return _0x45a501;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0xb22f('0x0'));var BPromise=require('bluebird');var rs=require(_0xb22f('0x1'));var fs=require('fs');var Redis=require(_0xb22f('0x2'));var db=require(_0xb22f('0x3'))['db'];var utils=require(_0xb22f('0x4'));var logger=require(_0xb22f('0x5'))('rpc');var config=require(_0xb22f('0x6'));var jayson=require(_0xb22f('0x7'));var client=jayson[_0xb22f('0x8')][_0xb22f('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x412a95,_0x367d4b,_0x47f61a){return new BPromise(function(_0x34433b,_0x22c509){return client[_0xb22f('0xa')](_0x412a95,_0x47f61a)[_0xb22f('0xb')](function(_0x1a3aae){logger[_0xb22f('0xc')](_0xb22f('0xd'),_0x367d4b,_0xb22f('0xe'));logger[_0xb22f('0xf')](_0xb22f('0x10'),_0x367d4b,_0xb22f('0xe'),JSON['stringify'](_0x1a3aae));if(_0x1a3aae['error']){if(_0x1a3aae['error'][_0xb22f('0x11')]===0x1f4){logger['error']('Campaign,\x20%s,\x20%s',_0x367d4b,_0x1a3aae['error'][_0xb22f('0x12')]);return _0x22c509(_0x1a3aae[_0xb22f('0x13')][_0xb22f('0x12')]);}logger[_0xb22f('0x13')](_0xb22f('0xd'),_0x367d4b,_0x1a3aae[_0xb22f('0x13')]['message']);return _0x34433b(_0x1a3aae[_0xb22f('0x13')]['message']);}else{logger[_0xb22f('0xc')]('Campaign,\x20%s,\x20%s',_0x367d4b,_0xb22f('0xe'));_0x34433b(_0x1a3aae[_0xb22f('0x14')][_0xb22f('0x12')]);}})[_0xb22f('0x15')](function(_0x447eaf){logger['error'](_0xb22f('0xd'),_0x367d4b,_0x447eaf);_0x22c509(_0x447eaf);});});}exports['GetCampaign']=function(_0x252742){var _0x35caec=this;return new Promise(function(_0x2aaec4,_0x1f515d){return db[_0xb22f('0x16')][_0xb22f('0x17')]({'raw':_0x252742['options']?_0x252742[_0xb22f('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x252742[_0xb22f('0x18')]?_0x252742[_0xb22f('0x18')][_0xb22f('0x19')]||null:null,'attributes':_0x252742[_0xb22f('0x18')]?_0x252742[_0xb22f('0x18')]['attributes']||null:null,'limit':_0x252742['options']?_0x252742[_0xb22f('0x18')][_0xb22f('0x1a')]||null:null,'include':_0x252742[_0xb22f('0x18')]?_0x252742[_0xb22f('0x18')][_0xb22f('0x1b')]?_[_0xb22f('0x1c')](_0x252742[_0xb22f('0x18')][_0xb22f('0x1b')],function(_0x583fbe){return{'model':db[_0x583fbe['model']],'as':_0x583fbe['as'],'attributes':_0x583fbe[_0xb22f('0x1d')],'include':_0x583fbe[_0xb22f('0x1b')]?_['map'](_0x583fbe[_0xb22f('0x1b')],function(_0x4364f5){return{'model':db[_0x4364f5['model']],'as':_0x4364f5['as'],'attributes':_0x4364f5[_0xb22f('0x1d')],'include':_0x4364f5[_0xb22f('0x1b')]?_['map'](_0x4364f5[_0xb22f('0x1b')],function(_0x2c4a9e){return{'model':db[_0x2c4a9e[_0xb22f('0x1e')]],'as':_0x2c4a9e['as'],'attributes':_0x2c4a9e[_0xb22f('0x1d')]};}):[]};}):[]};}):[]:[]})[_0xb22f('0xb')](function(_0x246a0c){logger[_0xb22f('0xc')](_0xb22f('0x1f'),_0x252742);logger['debug']('GetCampaign',_0x252742,JSON['stringify'](_0x246a0c));_0x2aaec4(_0x246a0c);})[_0xb22f('0x15')](function(_0x557d96){logger[_0xb22f('0x13')](_0xb22f('0x1f'),_0x557d96[_0xb22f('0x12')],_0x252742);_0x1f515d(_0x35caec[_0xb22f('0x13')](0x1f4,_0x557d96[_0xb22f('0x12')]));});});};