8446806a7d86513b15f82b5f1e5eb3ccd888a4e8
[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 _0x0b40=['Campaign,\x20%s,\x20%s','message','info','result','catch','GetCampaign','Campaign','findAll','options','raw','where','attributes','limit','include','map','model','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','then','request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s','stringify','error','code'];(function(_0xc391bf,_0x5cc846){var _0x4bd503=function(_0x6970a9){while(--_0x6970a9){_0xc391bf['push'](_0xc391bf['shift']());}};_0x4bd503(++_0x5cc846);}(_0x0b40,0xba));var _0x00b4=function(_0x5f1cf8,_0x5e0923){_0x5f1cf8=_0x5f1cf8-0x0;var _0x27d0fa=_0x0b40[_0x5f1cf8];return _0x27d0fa;};'use strict';var _=require('lodash');var util=require(_0x00b4('0x0'));var moment=require(_0x00b4('0x1'));var BPromise=require('bluebird');var rs=require(_0x00b4('0x2'));var fs=require('fs');var Redis=require(_0x00b4('0x3'));var db=require(_0x00b4('0x4'))['db'];var utils=require(_0x00b4('0x5'));var logger=require(_0x00b4('0x6'))(_0x00b4('0x7'));var config=require('../../config/environment');var jayson=require(_0x00b4('0x8'));var client=jayson[_0x00b4('0x9')][_0x00b4('0xa')]({'port':0x232a});function respondWithRpcPromise(_0x120157,_0x5684ec,_0x445536){return new BPromise(function(_0x20c810,_0x3f6285){return client['request'](_0x120157,_0x445536)[_0x00b4('0xb')](function(_0x144611){logger['info']('Campaign,\x20%s,\x20%s',_0x5684ec,_0x00b4('0xc'));logger[_0x00b4('0xd')](_0x00b4('0xe'),_0x5684ec,_0x00b4('0xc'),JSON[_0x00b4('0xf')](_0x144611));if(_0x144611[_0x00b4('0x10')]){if(_0x144611[_0x00b4('0x10')][_0x00b4('0x11')]===0x1f4){logger[_0x00b4('0x10')](_0x00b4('0x12'),_0x5684ec,_0x144611[_0x00b4('0x10')][_0x00b4('0x13')]);return _0x3f6285(_0x144611['error']['message']);}logger[_0x00b4('0x10')](_0x00b4('0x12'),_0x5684ec,_0x144611[_0x00b4('0x10')][_0x00b4('0x13')]);return _0x20c810(_0x144611['error'][_0x00b4('0x13')]);}else{logger[_0x00b4('0x14')](_0x00b4('0x12'),_0x5684ec,_0x00b4('0xc'));_0x20c810(_0x144611[_0x00b4('0x15')][_0x00b4('0x13')]);}})[_0x00b4('0x16')](function(_0x56e54c){logger[_0x00b4('0x10')](_0x00b4('0x12'),_0x5684ec,_0x56e54c);_0x3f6285(_0x56e54c);});});}exports[_0x00b4('0x17')]=function(_0x3f4b1d){var _0x24a5be=this;return new Promise(function(_0x5d960a,_0x265dbd){return db[_0x00b4('0x18')][_0x00b4('0x19')]({'raw':_0x3f4b1d['options']?_0x3f4b1d[_0x00b4('0x1a')][_0x00b4('0x1b')]===undefined?!![]:![]:!![],'where':_0x3f4b1d[_0x00b4('0x1a')]?_0x3f4b1d[_0x00b4('0x1a')][_0x00b4('0x1c')]||null:null,'attributes':_0x3f4b1d['options']?_0x3f4b1d['options'][_0x00b4('0x1d')]||null:null,'limit':_0x3f4b1d[_0x00b4('0x1a')]?_0x3f4b1d[_0x00b4('0x1a')][_0x00b4('0x1e')]||null:null,'include':_0x3f4b1d[_0x00b4('0x1a')]?_0x3f4b1d['options'][_0x00b4('0x1f')]?_[_0x00b4('0x20')](_0x3f4b1d['options'][_0x00b4('0x1f')],function(_0x40d7ba){return{'model':db[_0x40d7ba[_0x00b4('0x21')]],'as':_0x40d7ba['as'],'attributes':_0x40d7ba['attributes'],'include':_0x40d7ba[_0x00b4('0x1f')]?_[_0x00b4('0x20')](_0x40d7ba[_0x00b4('0x1f')],function(_0x50d48d){return{'model':db[_0x50d48d['model']],'as':_0x50d48d['as'],'attributes':_0x50d48d[_0x00b4('0x1d')],'include':_0x50d48d[_0x00b4('0x1f')]?_[_0x00b4('0x20')](_0x50d48d[_0x00b4('0x1f')],function(_0x3cf0ff){return{'model':db[_0x3cf0ff[_0x00b4('0x21')]],'as':_0x3cf0ff['as'],'attributes':_0x3cf0ff['attributes']};}):[]};}):[]};}):[]:[]})[_0x00b4('0xb')](function(_0x3abc75){logger[_0x00b4('0x14')](_0x00b4('0x17'),_0x3f4b1d);logger[_0x00b4('0xd')](_0x00b4('0x17'),_0x3f4b1d,JSON[_0x00b4('0xf')](_0x3abc75));_0x5d960a(_0x3abc75);})[_0x00b4('0x16')](function(_0x3d3684){logger[_0x00b4('0x10')](_0x00b4('0x17'),_0x3d3684['message'],_0x3f4b1d);_0x265dbd(_0x24a5be[_0x00b4('0x10')](0x1f4,_0x3d3684[_0x00b4('0x13')]));});});};