a8d3d0f1db46758f6f1b40d0132a820b00b014c8
[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 _0xfb3f=['options','where','attributes','limit','include','model','map','lodash','util','bluebird','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','request','then','Campaign,\x20%s,\x20%s','request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s','stringify','error','message','info','catch','GetCampaign','Campaign'];(function(_0x3a9635,_0x1ab817){var _0x10d08c=function(_0x222242){while(--_0x222242){_0x3a9635['push'](_0x3a9635['shift']());}};_0x10d08c(++_0x1ab817);}(_0xfb3f,0xd9));var _0xffb3=function(_0x1e570e,_0x246e33){_0x1e570e=_0x1e570e-0x0;var _0x272a15=_0xfb3f[_0x1e570e];return _0x272a15;};'use strict';var _=require(_0xffb3('0x0'));var util=require(_0xffb3('0x1'));var moment=require('moment');var BPromise=require(_0xffb3('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0xffb3('0x3'))['db'];var utils=require('../../config/utils');var logger=require(_0xffb3('0x4'))(_0xffb3('0x5'));var config=require(_0xffb3('0x6'));var jayson=require(_0xffb3('0x7'));var client=jayson[_0xffb3('0x8')][_0xffb3('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x3868a6,_0x146133,_0x5177aa){return new BPromise(function(_0x2e9697,_0x250f0f){return client[_0xffb3('0xa')](_0x3868a6,_0x5177aa)[_0xffb3('0xb')](function(_0x39c7eb){logger['info'](_0xffb3('0xc'),_0x146133,_0xffb3('0xd'));logger[_0xffb3('0xe')](_0xffb3('0xf'),_0x146133,_0xffb3('0xd'),JSON[_0xffb3('0x10')](_0x39c7eb));if(_0x39c7eb[_0xffb3('0x11')]){if(_0x39c7eb[_0xffb3('0x11')]['code']===0x1f4){logger[_0xffb3('0x11')](_0xffb3('0xc'),_0x146133,_0x39c7eb['error'][_0xffb3('0x12')]);return _0x250f0f(_0x39c7eb[_0xffb3('0x11')][_0xffb3('0x12')]);}logger[_0xffb3('0x11')](_0xffb3('0xc'),_0x146133,_0x39c7eb[_0xffb3('0x11')][_0xffb3('0x12')]);return _0x2e9697(_0x39c7eb[_0xffb3('0x11')][_0xffb3('0x12')]);}else{logger[_0xffb3('0x13')](_0xffb3('0xc'),_0x146133,_0xffb3('0xd'));_0x2e9697(_0x39c7eb['result'][_0xffb3('0x12')]);}})[_0xffb3('0x14')](function(_0x42b807){logger['error']('Campaign,\x20%s,\x20%s',_0x146133,_0x42b807);_0x250f0f(_0x42b807);});});}exports[_0xffb3('0x15')]=function(_0x167ed7){var _0x57d096=this;return new Promise(function(_0x3b35de,_0x30f403){return db[_0xffb3('0x16')]['findAll']({'raw':_0x167ed7[_0xffb3('0x17')]?_0x167ed7[_0xffb3('0x17')]['raw']===undefined?!![]:![]:!![],'where':_0x167ed7[_0xffb3('0x17')]?_0x167ed7[_0xffb3('0x17')][_0xffb3('0x18')]||null:null,'attributes':_0x167ed7[_0xffb3('0x17')]?_0x167ed7[_0xffb3('0x17')][_0xffb3('0x19')]||null:null,'limit':_0x167ed7[_0xffb3('0x17')]?_0x167ed7['options'][_0xffb3('0x1a')]||null:null,'include':_0x167ed7[_0xffb3('0x17')]?_0x167ed7['options'][_0xffb3('0x1b')]?_['map'](_0x167ed7['options'][_0xffb3('0x1b')],function(_0x3d55e6){return{'model':db[_0x3d55e6[_0xffb3('0x1c')]],'as':_0x3d55e6['as'],'attributes':_0x3d55e6[_0xffb3('0x19')],'include':_0x3d55e6[_0xffb3('0x1b')]?_[_0xffb3('0x1d')](_0x3d55e6['include'],function(_0x796b8e){return{'model':db[_0x796b8e['model']],'as':_0x796b8e['as'],'attributes':_0x796b8e[_0xffb3('0x19')],'include':_0x796b8e[_0xffb3('0x1b')]?_['map'](_0x796b8e[_0xffb3('0x1b')],function(_0x5e0474){return{'model':db[_0x5e0474[_0xffb3('0x1c')]],'as':_0x5e0474['as'],'attributes':_0x5e0474[_0xffb3('0x19')]};}):[]};}):[]};}):[]:[]})[_0xffb3('0xb')](function(_0x6ba942){logger['info']('GetCampaign',_0x167ed7);logger['debug']('GetCampaign',_0x167ed7,JSON[_0xffb3('0x10')](_0x6ba942));_0x3b35de(_0x6ba942);})['catch'](function(_0x17f601){logger[_0xffb3('0x11')](_0xffb3('0x15'),_0x17f601[_0xffb3('0x12')],_0x167ed7);_0x30f403(_0x57d096['error'](0x1f4,_0x17f601[_0xffb3('0x12')]));});});};