Built motion from commit 538092ac.|2.6.10
[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 _0x8482=['Campaign,\x20%s,\x20%s','message','info','GetCampaign','Campaign','findAll','options','where','attributes','limit','include','map','model','catch','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','client','http','then','request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s','stringify','error'];(function(_0x53881d,_0x5b3c64){var _0x277c2c=function(_0x7f8f3){while(--_0x7f8f3){_0x53881d['push'](_0x53881d['shift']());}};_0x277c2c(++_0x5b3c64);}(_0x8482,0x14e));var _0x2848=function(_0xc33b75,_0x4c2b64){_0xc33b75=_0xc33b75-0x0;var _0x4470e7=_0x8482[_0xc33b75];return _0x4470e7;};'use strict';var _=require('lodash');var util=require(_0x2848('0x0'));var moment=require(_0x2848('0x1'));var BPromise=require(_0x2848('0x2'));var rs=require(_0x2848('0x3'));var fs=require('fs');var Redis=require(_0x2848('0x4'));var db=require(_0x2848('0x5'))['db'];var utils=require(_0x2848('0x6'));var logger=require(_0x2848('0x7'))(_0x2848('0x8'));var config=require(_0x2848('0x9'));var jayson=require('jayson/promise');var client=jayson[_0x2848('0xa')][_0x2848('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x503238,_0xeca507,_0x48c0f3){return new BPromise(function(_0x53c865,_0xff7900){return client['request'](_0x503238,_0x48c0f3)[_0x2848('0xc')](function(_0x4a117b){logger['info']('Campaign,\x20%s,\x20%s',_0xeca507,_0x2848('0xd'));logger[_0x2848('0xe')](_0x2848('0xf'),_0xeca507,_0x2848('0xd'),JSON[_0x2848('0x10')](_0x4a117b));if(_0x4a117b[_0x2848('0x11')]){if(_0x4a117b['error']['code']===0x1f4){logger[_0x2848('0x11')](_0x2848('0x12'),_0xeca507,_0x4a117b[_0x2848('0x11')]['message']);return _0xff7900(_0x4a117b[_0x2848('0x11')][_0x2848('0x13')]);}logger[_0x2848('0x11')]('Campaign,\x20%s,\x20%s',_0xeca507,_0x4a117b[_0x2848('0x11')]['message']);return _0x53c865(_0x4a117b[_0x2848('0x11')]['message']);}else{logger[_0x2848('0x14')](_0x2848('0x12'),_0xeca507,_0x2848('0xd'));_0x53c865(_0x4a117b['result']['message']);}})['catch'](function(_0x5f5616){logger[_0x2848('0x11')](_0x2848('0x12'),_0xeca507,_0x5f5616);_0xff7900(_0x5f5616);});});}exports[_0x2848('0x15')]=function(_0x46755c){var _0x3f9472=this;return new Promise(function(_0x3b4eeb,_0x34de28){return db[_0x2848('0x16')][_0x2848('0x17')]({'raw':_0x46755c[_0x2848('0x18')]?_0x46755c[_0x2848('0x18')]['raw']===undefined?!![]:![]:!![],'where':_0x46755c[_0x2848('0x18')]?_0x46755c[_0x2848('0x18')][_0x2848('0x19')]||null:null,'attributes':_0x46755c['options']?_0x46755c[_0x2848('0x18')][_0x2848('0x1a')]||null:null,'limit':_0x46755c[_0x2848('0x18')]?_0x46755c[_0x2848('0x18')][_0x2848('0x1b')]||null:null,'include':_0x46755c['options']?_0x46755c[_0x2848('0x18')][_0x2848('0x1c')]?_[_0x2848('0x1d')](_0x46755c[_0x2848('0x18')][_0x2848('0x1c')],function(_0x40f510){return{'model':db[_0x40f510['model']],'as':_0x40f510['as'],'attributes':_0x40f510[_0x2848('0x1a')],'include':_0x40f510['include']?_[_0x2848('0x1d')](_0x40f510[_0x2848('0x1c')],function(_0x2d936a){return{'model':db[_0x2d936a[_0x2848('0x1e')]],'as':_0x2d936a['as'],'attributes':_0x2d936a['attributes'],'include':_0x2d936a[_0x2848('0x1c')]?_[_0x2848('0x1d')](_0x2d936a[_0x2848('0x1c')],function(_0x2dc32e){return{'model':db[_0x2dc32e[_0x2848('0x1e')]],'as':_0x2dc32e['as'],'attributes':_0x2dc32e[_0x2848('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x2848('0xc')](function(_0x4ec4b5){logger['info']('GetCampaign',_0x46755c);logger[_0x2848('0xe')](_0x2848('0x15'),_0x46755c,JSON[_0x2848('0x10')](_0x4ec4b5));_0x3b4eeb(_0x4ec4b5);})[_0x2848('0x1f')](function(_0x189701){logger[_0x2848('0x11')]('GetCampaign',_0x189701['message'],_0x46755c);_0x34de28(_0x3f9472[_0x2848('0x11')](0x1f4,_0x189701[_0x2848('0x13')]));});});};