Built motion from commit c1aa34a0.|2.6.28
[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 _0x0624=['Campaign,\x20%s,\x20%s,\x20%s','stringify','error','code','message','GetCampaign','Campaign','options','raw','where','attributes','limit','map','include','model','catch','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','client','http','then','info','Campaign,\x20%s,\x20%s','request\x20sent','debug'];(function(_0x13ea00,_0x12f610){var _0x1f7347=function(_0x34ae63){while(--_0x34ae63){_0x13ea00['push'](_0x13ea00['shift']());}};_0x1f7347(++_0x12f610);}(_0x0624,0x132));var _0x4062=function(_0x189be2,_0x5139dc){_0x189be2=_0x189be2-0x0;var _0xeac5af=_0x0624[_0x189be2];return _0xeac5af;};'use strict';var _=require('lodash');var util=require('util');var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x4062('0x0'));var fs=require('fs');var Redis=require(_0x4062('0x1'));var db=require(_0x4062('0x2'))['db'];var utils=require(_0x4062('0x3'));var logger=require(_0x4062('0x4'))(_0x4062('0x5'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0x4062('0x6')][_0x4062('0x7')]({'port':0x232a});function respondWithRpcPromise(_0x2f4928,_0xdff88c,_0x27794b){return new BPromise(function(_0x5d19e8,_0x75ce4e){return client['request'](_0x2f4928,_0x27794b)[_0x4062('0x8')](function(_0x35663b){logger[_0x4062('0x9')](_0x4062('0xa'),_0xdff88c,_0x4062('0xb'));logger[_0x4062('0xc')](_0x4062('0xd'),_0xdff88c,'request\x20sent',JSON[_0x4062('0xe')](_0x35663b));if(_0x35663b['error']){if(_0x35663b[_0x4062('0xf')][_0x4062('0x10')]===0x1f4){logger[_0x4062('0xf')](_0x4062('0xa'),_0xdff88c,_0x35663b[_0x4062('0xf')]['message']);return _0x75ce4e(_0x35663b[_0x4062('0xf')][_0x4062('0x11')]);}logger['error'](_0x4062('0xa'),_0xdff88c,_0x35663b[_0x4062('0xf')][_0x4062('0x11')]);return _0x5d19e8(_0x35663b['error']['message']);}else{logger[_0x4062('0x9')](_0x4062('0xa'),_0xdff88c,'request\x20sent');_0x5d19e8(_0x35663b['result']['message']);}})['catch'](function(_0x437432){logger['error'](_0x4062('0xa'),_0xdff88c,_0x437432);_0x75ce4e(_0x437432);});});}exports[_0x4062('0x12')]=function(_0x3d14bb){var _0x37cd8b=this;return new Promise(function(_0x2a04c7,_0x3942f2){return db[_0x4062('0x13')]['findAll']({'raw':_0x3d14bb[_0x4062('0x14')]?_0x3d14bb['options'][_0x4062('0x15')]===undefined?!![]:![]:!![],'where':_0x3d14bb['options']?_0x3d14bb[_0x4062('0x14')][_0x4062('0x16')]||null:null,'attributes':_0x3d14bb[_0x4062('0x14')]?_0x3d14bb[_0x4062('0x14')][_0x4062('0x17')]||null:null,'limit':_0x3d14bb[_0x4062('0x14')]?_0x3d14bb[_0x4062('0x14')][_0x4062('0x18')]||null:null,'include':_0x3d14bb[_0x4062('0x14')]?_0x3d14bb['options']['include']?_[_0x4062('0x19')](_0x3d14bb[_0x4062('0x14')][_0x4062('0x1a')],function(_0x1fa194){return{'model':db[_0x1fa194['model']],'as':_0x1fa194['as'],'attributes':_0x1fa194['attributes'],'include':_0x1fa194['include']?_[_0x4062('0x19')](_0x1fa194[_0x4062('0x1a')],function(_0x11b962){return{'model':db[_0x11b962[_0x4062('0x1b')]],'as':_0x11b962['as'],'attributes':_0x11b962[_0x4062('0x17')],'include':_0x11b962[_0x4062('0x1a')]?_['map'](_0x11b962[_0x4062('0x1a')],function(_0x448545){return{'model':db[_0x448545[_0x4062('0x1b')]],'as':_0x448545['as'],'attributes':_0x448545[_0x4062('0x17')]};}):[]};}):[]};}):[]:[]})[_0x4062('0x8')](function(_0x5934d2){logger[_0x4062('0x9')]('GetCampaign',_0x3d14bb);logger['debug'](_0x4062('0x12'),_0x3d14bb,JSON['stringify'](_0x5934d2));_0x2a04c7(_0x5934d2);})[_0x4062('0x1c')](function(_0x169c12){logger[_0x4062('0xf')](_0x4062('0x12'),_0x169c12[_0x4062('0x11')],_0x3d14bb);_0x3942f2(_0x37cd8b[_0x4062('0xf')](0x1f4,_0x169c12[_0x4062('0x11')]));});});};