Built motion from commit cb845558.|2.6.34
[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 _0xad95=['Campaign','findAll','options','attributes','limit','include','map','model','lodash','util','moment','ioredis','../../mysqldb','rpc','then','Campaign,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','info','result','catch','GetCampaign'];(function(_0x2f9467,_0x40576f){var _0x39894c=function(_0x13e344){while(--_0x13e344){_0x2f9467['push'](_0x2f9467['shift']());}};_0x39894c(++_0x40576f);}(_0xad95,0x70));var _0x5ad9=function(_0x33c6ce,_0x1702ff){_0x33c6ce=_0x33c6ce-0x0;var _0x3420fd=_0xad95[_0x33c6ce];return _0x3420fd;};'use strict';var _=require(_0x5ad9('0x0'));var util=require(_0x5ad9('0x1'));var moment=require(_0x5ad9('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x5ad9('0x3'));var db=require(_0x5ad9('0x4'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x5ad9('0x5'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x2bef4e,_0x117fde,_0x2a0915){return new BPromise(function(_0x3d937a,_0x404b33){return client['request'](_0x2bef4e,_0x2a0915)[_0x5ad9('0x6')](function(_0x4fdb7b){logger['info'](_0x5ad9('0x7'),_0x117fde,_0x5ad9('0x8'));logger[_0x5ad9('0x9')]('Campaign,\x20%s,\x20%s,\x20%s',_0x117fde,_0x5ad9('0x8'),JSON[_0x5ad9('0xa')](_0x4fdb7b));if(_0x4fdb7b['error']){if(_0x4fdb7b[_0x5ad9('0xb')][_0x5ad9('0xc')]===0x1f4){logger[_0x5ad9('0xb')](_0x5ad9('0x7'),_0x117fde,_0x4fdb7b[_0x5ad9('0xb')][_0x5ad9('0xd')]);return _0x404b33(_0x4fdb7b['error']['message']);}logger['error'](_0x5ad9('0x7'),_0x117fde,_0x4fdb7b[_0x5ad9('0xb')]['message']);return _0x3d937a(_0x4fdb7b[_0x5ad9('0xb')][_0x5ad9('0xd')]);}else{logger[_0x5ad9('0xe')](_0x5ad9('0x7'),_0x117fde,_0x5ad9('0x8'));_0x3d937a(_0x4fdb7b[_0x5ad9('0xf')][_0x5ad9('0xd')]);}})[_0x5ad9('0x10')](function(_0x36e61f){logger[_0x5ad9('0xb')]('Campaign,\x20%s,\x20%s',_0x117fde,_0x36e61f);_0x404b33(_0x36e61f);});});}exports[_0x5ad9('0x11')]=function(_0x54f392){var _0x3d1c8f=this;return new Promise(function(_0x28682f,_0xe4171b){return db[_0x5ad9('0x12')][_0x5ad9('0x13')]({'raw':_0x54f392[_0x5ad9('0x14')]?_0x54f392[_0x5ad9('0x14')]['raw']===undefined?!![]:![]:!![],'where':_0x54f392[_0x5ad9('0x14')]?_0x54f392['options']['where']||null:null,'attributes':_0x54f392[_0x5ad9('0x14')]?_0x54f392['options'][_0x5ad9('0x15')]||null:null,'limit':_0x54f392[_0x5ad9('0x14')]?_0x54f392[_0x5ad9('0x14')][_0x5ad9('0x16')]||null:null,'include':_0x54f392[_0x5ad9('0x14')]?_0x54f392['options'][_0x5ad9('0x17')]?_['map'](_0x54f392[_0x5ad9('0x14')]['include'],function(_0x570d3c){return{'model':db[_0x570d3c['model']],'as':_0x570d3c['as'],'attributes':_0x570d3c[_0x5ad9('0x15')],'include':_0x570d3c[_0x5ad9('0x17')]?_[_0x5ad9('0x18')](_0x570d3c[_0x5ad9('0x17')],function(_0x1252e6){return{'model':db[_0x1252e6[_0x5ad9('0x19')]],'as':_0x1252e6['as'],'attributes':_0x1252e6[_0x5ad9('0x15')],'include':_0x1252e6['include']?_['map'](_0x1252e6[_0x5ad9('0x17')],function(_0x4f3889){return{'model':db[_0x4f3889[_0x5ad9('0x19')]],'as':_0x4f3889['as'],'attributes':_0x4f3889['attributes']};}):[]};}):[]};}):[]:[]})[_0x5ad9('0x6')](function(_0x55a0e4){logger['info'](_0x5ad9('0x11'),_0x54f392);logger[_0x5ad9('0x9')]('GetCampaign',_0x54f392,JSON['stringify'](_0x55a0e4));_0x28682f(_0x55a0e4);})[_0x5ad9('0x10')](function(_0x129804){logger[_0x5ad9('0xb')](_0x5ad9('0x11'),_0x129804[_0x5ad9('0xd')],_0x54f392);_0xe4171b(_0x3d1c8f[_0x5ad9('0xb')](0x1f4,_0x129804['message']));});});};