cfd89ecb8e49b8e6737ebeb2d1a3f9dfefa64f3b
[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 _0xb2b3=['error','code','message','findAll','options','raw','where','attributes','limit','include','map','model','then','GetCampaign','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','request','info','Campaign,\x20%s,\x20%s','request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s'];(function(_0x2b4411,_0x2625ed){var _0x8e41ef=function(_0x2aa8c1){while(--_0x2aa8c1){_0x2b4411['push'](_0x2b4411['shift']());}};_0x8e41ef(++_0x2625ed);}(_0xb2b3,0x71));var _0x3b2b=function(_0x1d91a5,_0x41741c){_0x1d91a5=_0x1d91a5-0x0;var _0x1604e1=_0xb2b3[_0x1d91a5];return _0x1604e1;};'use strict';var _=require(_0x3b2b('0x0'));var util=require(_0x3b2b('0x1'));var moment=require(_0x3b2b('0x2'));var BPromise=require(_0x3b2b('0x3'));var rs=require(_0x3b2b('0x4'));var fs=require('fs');var Redis=require(_0x3b2b('0x5'));var db=require(_0x3b2b('0x6'))['db'];var utils=require('../../config/utils');var logger=require(_0x3b2b('0x7'))(_0x3b2b('0x8'));var config=require(_0x3b2b('0x9'));var jayson=require(_0x3b2b('0xa'));var client=jayson[_0x3b2b('0xb')][_0x3b2b('0xc')]({'port':0x232a});function respondWithRpcPromise(_0x83e7ef,_0x24b585,_0x1a9054){return new BPromise(function(_0x3ec416,_0x33b807){return client[_0x3b2b('0xd')](_0x83e7ef,_0x1a9054)['then'](function(_0x430be0){logger[_0x3b2b('0xe')](_0x3b2b('0xf'),_0x24b585,_0x3b2b('0x10'));logger[_0x3b2b('0x11')](_0x3b2b('0x12'),_0x24b585,'request\x20sent',JSON['stringify'](_0x430be0));if(_0x430be0[_0x3b2b('0x13')]){if(_0x430be0[_0x3b2b('0x13')][_0x3b2b('0x14')]===0x1f4){logger[_0x3b2b('0x13')]('Campaign,\x20%s,\x20%s',_0x24b585,_0x430be0[_0x3b2b('0x13')][_0x3b2b('0x15')]);return _0x33b807(_0x430be0[_0x3b2b('0x13')][_0x3b2b('0x15')]);}logger[_0x3b2b('0x13')](_0x3b2b('0xf'),_0x24b585,_0x430be0['error'][_0x3b2b('0x15')]);return _0x3ec416(_0x430be0[_0x3b2b('0x13')]['message']);}else{logger[_0x3b2b('0xe')](_0x3b2b('0xf'),_0x24b585,_0x3b2b('0x10'));_0x3ec416(_0x430be0['result'][_0x3b2b('0x15')]);}})['catch'](function(_0x21743d){logger[_0x3b2b('0x13')]('Campaign,\x20%s,\x20%s',_0x24b585,_0x21743d);_0x33b807(_0x21743d);});});}exports['GetCampaign']=function(_0x1a3bfb){var _0x52bba5=this;return new Promise(function(_0x157155,_0x30e4c2){return db['Campaign'][_0x3b2b('0x16')]({'raw':_0x1a3bfb['options']?_0x1a3bfb[_0x3b2b('0x17')][_0x3b2b('0x18')]===undefined?!![]:![]:!![],'where':_0x1a3bfb['options']?_0x1a3bfb['options'][_0x3b2b('0x19')]||null:null,'attributes':_0x1a3bfb[_0x3b2b('0x17')]?_0x1a3bfb[_0x3b2b('0x17')][_0x3b2b('0x1a')]||null:null,'limit':_0x1a3bfb[_0x3b2b('0x17')]?_0x1a3bfb[_0x3b2b('0x17')][_0x3b2b('0x1b')]||null:null,'include':_0x1a3bfb[_0x3b2b('0x17')]?_0x1a3bfb[_0x3b2b('0x17')][_0x3b2b('0x1c')]?_[_0x3b2b('0x1d')](_0x1a3bfb['options'][_0x3b2b('0x1c')],function(_0x35387c){return{'model':db[_0x35387c[_0x3b2b('0x1e')]],'as':_0x35387c['as'],'attributes':_0x35387c['attributes'],'include':_0x35387c[_0x3b2b('0x1c')]?_['map'](_0x35387c[_0x3b2b('0x1c')],function(_0x50d2e5){return{'model':db[_0x50d2e5[_0x3b2b('0x1e')]],'as':_0x50d2e5['as'],'attributes':_0x50d2e5['attributes'],'include':_0x50d2e5['include']?_[_0x3b2b('0x1d')](_0x50d2e5[_0x3b2b('0x1c')],function(_0x11313d){return{'model':db[_0x11313d[_0x3b2b('0x1e')]],'as':_0x11313d['as'],'attributes':_0x11313d[_0x3b2b('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x3b2b('0x1f')](function(_0x30574a){logger[_0x3b2b('0xe')](_0x3b2b('0x20'),_0x1a3bfb);logger['debug']('GetCampaign',_0x1a3bfb,JSON['stringify'](_0x30574a));_0x157155(_0x30574a);})['catch'](function(_0x3e2177){logger[_0x3b2b('0x13')](_0x3b2b('0x20'),_0x3e2177[_0x3b2b('0x15')],_0x1a3bfb);_0x30e4c2(_0x52bba5[_0x3b2b('0x13')](0x1f4,_0x3e2177[_0x3b2b('0x15')]));});});};