0abdf094a179951f1c4f0636d0a08e0c9560920b
[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 _0xb575=['jayson/promise','client','http','request','then','info','Campaign,\x20%s,\x20%s','request\x20sent','Campaign,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','Campaign','findAll','options','raw','attributes','limit','include','map','model','GetCampaign','debug','stringify','lodash','util','bluebird','../../config/utils','../../config/logger','../../config/environment'];(function(_0x489dd6,_0x2ff564){var _0x22e0ee=function(_0x5110a3){while(--_0x5110a3){_0x489dd6['push'](_0x489dd6['shift']());}};_0x22e0ee(++_0x2ff564);}(_0xb575,0xda));var _0x5b57=function(_0xfb6d53,_0x355c5a){_0xfb6d53=_0xfb6d53-0x0;var _0x32f9e9=_0xb575[_0xfb6d53];return _0x32f9e9;};'use strict';var _=require(_0x5b57('0x0'));var util=require(_0x5b57('0x1'));var moment=require('moment');var BPromise=require(_0x5b57('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x5b57('0x3'));var logger=require(_0x5b57('0x4'))('rpc');var config=require(_0x5b57('0x5'));var jayson=require(_0x5b57('0x6'));var client=jayson[_0x5b57('0x7')][_0x5b57('0x8')]({'port':0x232a});function respondWithRpcPromise(_0x672beb,_0x5d223d,_0x4232d0){return new BPromise(function(_0x5dd0c7,_0x2f9789){return client[_0x5b57('0x9')](_0x672beb,_0x4232d0)[_0x5b57('0xa')](function(_0x49ce3a){logger[_0x5b57('0xb')](_0x5b57('0xc'),_0x5d223d,_0x5b57('0xd'));logger['debug'](_0x5b57('0xe'),_0x5d223d,_0x5b57('0xd'),JSON['stringify'](_0x49ce3a));if(_0x49ce3a['error']){if(_0x49ce3a[_0x5b57('0xf')][_0x5b57('0x10')]===0x1f4){logger[_0x5b57('0xf')](_0x5b57('0xc'),_0x5d223d,_0x49ce3a[_0x5b57('0xf')][_0x5b57('0x11')]);return _0x2f9789(_0x49ce3a[_0x5b57('0xf')][_0x5b57('0x11')]);}logger[_0x5b57('0xf')](_0x5b57('0xc'),_0x5d223d,_0x49ce3a['error'][_0x5b57('0x11')]);return _0x5dd0c7(_0x49ce3a[_0x5b57('0xf')][_0x5b57('0x11')]);}else{logger['info'](_0x5b57('0xc'),_0x5d223d,_0x5b57('0xd'));_0x5dd0c7(_0x49ce3a[_0x5b57('0x12')][_0x5b57('0x11')]);}})[_0x5b57('0x13')](function(_0x1e7cc0){logger[_0x5b57('0xf')](_0x5b57('0xc'),_0x5d223d,_0x1e7cc0);_0x2f9789(_0x1e7cc0);});});}exports['GetCampaign']=function(_0x336db6){var _0x1e316f=this;return new Promise(function(_0x2cb809,_0x137899){return db[_0x5b57('0x14')][_0x5b57('0x15')]({'raw':_0x336db6['options']?_0x336db6[_0x5b57('0x16')][_0x5b57('0x17')]===undefined?!![]:![]:!![],'where':_0x336db6[_0x5b57('0x16')]?_0x336db6[_0x5b57('0x16')]['where']||null:null,'attributes':_0x336db6[_0x5b57('0x16')]?_0x336db6[_0x5b57('0x16')][_0x5b57('0x18')]||null:null,'limit':_0x336db6['options']?_0x336db6[_0x5b57('0x16')][_0x5b57('0x19')]||null:null,'include':_0x336db6[_0x5b57('0x16')]?_0x336db6[_0x5b57('0x16')][_0x5b57('0x1a')]?_[_0x5b57('0x1b')](_0x336db6['options'][_0x5b57('0x1a')],function(_0x50ea5f){return{'model':db[_0x50ea5f[_0x5b57('0x1c')]],'as':_0x50ea5f['as'],'attributes':_0x50ea5f[_0x5b57('0x18')],'include':_0x50ea5f['include']?_['map'](_0x50ea5f[_0x5b57('0x1a')],function(_0x5eab3d){return{'model':db[_0x5eab3d[_0x5b57('0x1c')]],'as':_0x5eab3d['as'],'attributes':_0x5eab3d[_0x5b57('0x18')],'include':_0x5eab3d[_0x5b57('0x1a')]?_[_0x5b57('0x1b')](_0x5eab3d[_0x5b57('0x1a')],function(_0x17ac8b){return{'model':db[_0x17ac8b[_0x5b57('0x1c')]],'as':_0x17ac8b['as'],'attributes':_0x17ac8b[_0x5b57('0x18')]};}):[]};}):[]};}):[]:[]})[_0x5b57('0xa')](function(_0x31c4a5){logger[_0x5b57('0xb')](_0x5b57('0x1d'),_0x336db6);logger[_0x5b57('0x1e')](_0x5b57('0x1d'),_0x336db6,JSON[_0x5b57('0x1f')](_0x31c4a5));_0x2cb809(_0x31c4a5);})[_0x5b57('0x13')](function(_0x3e8bc6){logger['error'](_0x5b57('0x1d'),_0x3e8bc6['message'],_0x336db6);_0x137899(_0x1e316f[_0x5b57('0xf')](0x1f4,_0x3e8bc6[_0x5b57('0x11')]));});});};