e9748ae135ce513b2c907a6e4e27d36c80b018b1
[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 _0x2821=['ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','client','http','request','info','Campaign,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','GetCampaign','Campaign','findAll','options','where','attributes','limit','map','include','model','then','lodash','util','moment','bluebird','randomstring'];(function(_0x279d37,_0x14de3f){var _0x530173=function(_0x37fc79){while(--_0x37fc79){_0x279d37['push'](_0x279d37['shift']());}};_0x530173(++_0x14de3f);}(_0x2821,0x87));var _0x1282=function(_0x4ccd19,_0x5d2627){_0x4ccd19=_0x4ccd19-0x0;var _0x10496b=_0x2821[_0x4ccd19];return _0x10496b;};'use strict';var _=require(_0x1282('0x0'));var util=require(_0x1282('0x1'));var moment=require(_0x1282('0x2'));var BPromise=require(_0x1282('0x3'));var rs=require(_0x1282('0x4'));var fs=require('fs');var Redis=require(_0x1282('0x5'));var db=require(_0x1282('0x6'))['db'];var utils=require(_0x1282('0x7'));var logger=require(_0x1282('0x8'))(_0x1282('0x9'));var config=require(_0x1282('0xa'));var jayson=require('jayson/promise');var client=jayson[_0x1282('0xb')][_0x1282('0xc')]({'port':0x232a});function respondWithRpcPromise(_0x293947,_0x13beb5,_0xa4eee9){return new BPromise(function(_0x1a8666,_0x18d69a){return client[_0x1282('0xd')](_0x293947,_0xa4eee9)['then'](function(_0x41c458){logger[_0x1282('0xe')](_0x1282('0xf'),_0x13beb5,_0x1282('0x10'));logger[_0x1282('0x11')]('Campaign,\x20%s,\x20%s,\x20%s',_0x13beb5,_0x1282('0x10'),JSON[_0x1282('0x12')](_0x41c458));if(_0x41c458['error']){if(_0x41c458[_0x1282('0x13')][_0x1282('0x14')]===0x1f4){logger['error'](_0x1282('0xf'),_0x13beb5,_0x41c458['error']['message']);return _0x18d69a(_0x41c458[_0x1282('0x13')][_0x1282('0x15')]);}logger[_0x1282('0x13')](_0x1282('0xf'),_0x13beb5,_0x41c458['error']['message']);return _0x1a8666(_0x41c458['error'][_0x1282('0x15')]);}else{logger[_0x1282('0xe')](_0x1282('0xf'),_0x13beb5,_0x1282('0x10'));_0x1a8666(_0x41c458[_0x1282('0x16')][_0x1282('0x15')]);}})[_0x1282('0x17')](function(_0x116ef1){logger['error'](_0x1282('0xf'),_0x13beb5,_0x116ef1);_0x18d69a(_0x116ef1);});});}exports[_0x1282('0x18')]=function(_0x518733){var _0x48c857=this;return new Promise(function(_0xebc97e,_0x4e3ec7){return db[_0x1282('0x19')][_0x1282('0x1a')]({'raw':_0x518733['options']?_0x518733['options']['raw']===undefined?!![]:![]:!![],'where':_0x518733['options']?_0x518733[_0x1282('0x1b')][_0x1282('0x1c')]||null:null,'attributes':_0x518733[_0x1282('0x1b')]?_0x518733[_0x1282('0x1b')][_0x1282('0x1d')]||null:null,'limit':_0x518733[_0x1282('0x1b')]?_0x518733[_0x1282('0x1b')][_0x1282('0x1e')]||null:null,'include':_0x518733[_0x1282('0x1b')]?_0x518733[_0x1282('0x1b')]['include']?_[_0x1282('0x1f')](_0x518733['options'][_0x1282('0x20')],function(_0x25dbb5){return{'model':db[_0x25dbb5[_0x1282('0x21')]],'as':_0x25dbb5['as'],'attributes':_0x25dbb5[_0x1282('0x1d')],'include':_0x25dbb5[_0x1282('0x20')]?_['map'](_0x25dbb5[_0x1282('0x20')],function(_0x117e5c){return{'model':db[_0x117e5c[_0x1282('0x21')]],'as':_0x117e5c['as'],'attributes':_0x117e5c[_0x1282('0x1d')],'include':_0x117e5c[_0x1282('0x20')]?_[_0x1282('0x1f')](_0x117e5c[_0x1282('0x20')],function(_0x28e686){return{'model':db[_0x28e686['model']],'as':_0x28e686['as'],'attributes':_0x28e686['attributes']};}):[]};}):[]};}):[]:[]})[_0x1282('0x22')](function(_0x5d97b4){logger[_0x1282('0xe')]('GetCampaign',_0x518733);logger[_0x1282('0x11')]('GetCampaign',_0x518733,JSON[_0x1282('0x12')](_0x5d97b4));_0xebc97e(_0x5d97b4);})['catch'](function(_0x519a7f){logger['error']('GetCampaign',_0x519a7f['message'],_0x518733);_0x4e3ec7(_0x48c857['error'](0x1f4,_0x519a7f[_0x1282('0x15')]));});});};