4235d39d5400d88c682d8d9c7a1c659688489017
[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 _0xde13=['stringify','error','message','result','catch','GetCampaign','Campaign','options','raw','attributes','limit','include','map','model','then','info','lodash','util','moment','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','client','http','request','Campaign,\x20%s,\x20%s','request\x20sent','debug'];(function(_0x13a39d,_0x46f30a){var _0x4e9ada=function(_0x2722fc){while(--_0x2722fc){_0x13a39d['push'](_0x13a39d['shift']());}};_0x4e9ada(++_0x46f30a);}(_0xde13,0x146));var _0x3de1=function(_0x36c371,_0x5559e2){_0x36c371=_0x36c371-0x0;var _0x3cbe5d=_0xde13[_0x36c371];return _0x3cbe5d;};'use strict';var _=require(_0x3de1('0x0'));var util=require(_0x3de1('0x1'));var moment=require(_0x3de1('0x2'));var BPromise=require(_0x3de1('0x3'));var rs=require(_0x3de1('0x4'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x3de1('0x5'))['db'];var utils=require(_0x3de1('0x6'));var logger=require(_0x3de1('0x7'))('rpc');var config=require(_0x3de1('0x8'));var jayson=require('jayson/promise');var client=jayson[_0x3de1('0x9')][_0x3de1('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x3d2169,_0x34291a,_0x5f1aff){return new BPromise(function(_0x11df45,_0x41b5bb){return client[_0x3de1('0xb')](_0x3d2169,_0x5f1aff)['then'](function(_0x4eb503){logger['info'](_0x3de1('0xc'),_0x34291a,_0x3de1('0xd'));logger[_0x3de1('0xe')]('Campaign,\x20%s,\x20%s,\x20%s',_0x34291a,_0x3de1('0xd'),JSON[_0x3de1('0xf')](_0x4eb503));if(_0x4eb503[_0x3de1('0x10')]){if(_0x4eb503['error']['code']===0x1f4){logger[_0x3de1('0x10')]('Campaign,\x20%s,\x20%s',_0x34291a,_0x4eb503['error']['message']);return _0x41b5bb(_0x4eb503[_0x3de1('0x10')][_0x3de1('0x11')]);}logger[_0x3de1('0x10')](_0x3de1('0xc'),_0x34291a,_0x4eb503['error'][_0x3de1('0x11')]);return _0x11df45(_0x4eb503['error'][_0x3de1('0x11')]);}else{logger['info'](_0x3de1('0xc'),_0x34291a,_0x3de1('0xd'));_0x11df45(_0x4eb503[_0x3de1('0x12')]['message']);}})[_0x3de1('0x13')](function(_0x25f619){logger[_0x3de1('0x10')](_0x3de1('0xc'),_0x34291a,_0x25f619);_0x41b5bb(_0x25f619);});});}exports[_0x3de1('0x14')]=function(_0x510e5a){var _0x19254b=this;return new Promise(function(_0x5a10f2,_0x1e5a06){return db[_0x3de1('0x15')]['findAll']({'raw':_0x510e5a[_0x3de1('0x16')]?_0x510e5a['options'][_0x3de1('0x17')]===undefined?!![]:![]:!![],'where':_0x510e5a[_0x3de1('0x16')]?_0x510e5a[_0x3de1('0x16')]['where']||null:null,'attributes':_0x510e5a[_0x3de1('0x16')]?_0x510e5a[_0x3de1('0x16')][_0x3de1('0x18')]||null:null,'limit':_0x510e5a['options']?_0x510e5a[_0x3de1('0x16')][_0x3de1('0x19')]||null:null,'include':_0x510e5a['options']?_0x510e5a['options'][_0x3de1('0x1a')]?_[_0x3de1('0x1b')](_0x510e5a[_0x3de1('0x16')][_0x3de1('0x1a')],function(_0x242ab0){return{'model':db[_0x242ab0[_0x3de1('0x1c')]],'as':_0x242ab0['as'],'attributes':_0x242ab0[_0x3de1('0x18')],'include':_0x242ab0[_0x3de1('0x1a')]?_['map'](_0x242ab0['include'],function(_0x9873fa){return{'model':db[_0x9873fa[_0x3de1('0x1c')]],'as':_0x9873fa['as'],'attributes':_0x9873fa[_0x3de1('0x18')],'include':_0x9873fa[_0x3de1('0x1a')]?_[_0x3de1('0x1b')](_0x9873fa['include'],function(_0x5985b2){return{'model':db[_0x5985b2['model']],'as':_0x5985b2['as'],'attributes':_0x5985b2['attributes']};}):[]};}):[]};}):[]:[]})[_0x3de1('0x1d')](function(_0xc6537a){logger[_0x3de1('0x1e')](_0x3de1('0x14'),_0x510e5a);logger[_0x3de1('0xe')](_0x3de1('0x14'),_0x510e5a,JSON[_0x3de1('0xf')](_0xc6537a));_0x5a10f2(_0xc6537a);})[_0x3de1('0x13')](function(_0x898786){logger[_0x3de1('0x10')](_0x3de1('0x14'),_0x898786[_0x3de1('0x11')],_0x510e5a);_0x1e5a06(_0x19254b['error'](0x1f4,_0x898786['message']));});});};