Built motion from commit 753c950e.|2.5.42
[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 _0x668b=['lodash','util','bluebird','randomstring','../../mysqldb','../../config/logger','rpc','../../config/environment','client','http','request','then','info','Campaign,\x20%s,\x20%s','request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','GetCampaign','findAll','options','raw','attributes','limit','include','model','map'];(function(_0x4cf98e,_0xba4b79){var _0x1623ac=function(_0x459bc0){while(--_0x459bc0){_0x4cf98e['push'](_0x4cf98e['shift']());}};_0x1623ac(++_0xba4b79);}(_0x668b,0x140));var _0xb668=function(_0x2feb53,_0x264ef7){_0x2feb53=_0x2feb53-0x0;var _0x5700ee=_0x668b[_0x2feb53];return _0x5700ee;};'use strict';var _=require(_0xb668('0x0'));var util=require(_0xb668('0x1'));var moment=require('moment');var BPromise=require(_0xb668('0x2'));var rs=require(_0xb668('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0xb668('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0xb668('0x5'))(_0xb668('0x6'));var config=require(_0xb668('0x7'));var jayson=require('jayson/promise');var client=jayson[_0xb668('0x8')][_0xb668('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x3be92e,_0x2778e9,_0x20b749){return new BPromise(function(_0x3f01bc,_0x517fc5){return client[_0xb668('0xa')](_0x3be92e,_0x20b749)[_0xb668('0xb')](function(_0x128cf5){logger[_0xb668('0xc')](_0xb668('0xd'),_0x2778e9,_0xb668('0xe'));logger[_0xb668('0xf')](_0xb668('0x10'),_0x2778e9,'request\x20sent',JSON[_0xb668('0x11')](_0x128cf5));if(_0x128cf5[_0xb668('0x12')]){if(_0x128cf5[_0xb668('0x12')][_0xb668('0x13')]===0x1f4){logger[_0xb668('0x12')](_0xb668('0xd'),_0x2778e9,_0x128cf5[_0xb668('0x12')][_0xb668('0x14')]);return _0x517fc5(_0x128cf5[_0xb668('0x12')][_0xb668('0x14')]);}logger[_0xb668('0x12')](_0xb668('0xd'),_0x2778e9,_0x128cf5[_0xb668('0x12')][_0xb668('0x14')]);return _0x3f01bc(_0x128cf5[_0xb668('0x12')][_0xb668('0x14')]);}else{logger[_0xb668('0xc')](_0xb668('0xd'),_0x2778e9,_0xb668('0xe'));_0x3f01bc(_0x128cf5[_0xb668('0x15')][_0xb668('0x14')]);}})[_0xb668('0x16')](function(_0x4ab137){logger[_0xb668('0x12')]('Campaign,\x20%s,\x20%s',_0x2778e9,_0x4ab137);_0x517fc5(_0x4ab137);});});}exports[_0xb668('0x17')]=function(_0x89fe72){var _0x5438ff=this;return new Promise(function(_0x38595d,_0x18e9c1){return db['Campaign'][_0xb668('0x18')]({'raw':_0x89fe72['options']?_0x89fe72[_0xb668('0x19')][_0xb668('0x1a')]===undefined?!![]:![]:!![],'where':_0x89fe72[_0xb668('0x19')]?_0x89fe72[_0xb668('0x19')]['where']||null:null,'attributes':_0x89fe72[_0xb668('0x19')]?_0x89fe72[_0xb668('0x19')][_0xb668('0x1b')]||null:null,'limit':_0x89fe72['options']?_0x89fe72['options'][_0xb668('0x1c')]||null:null,'include':_0x89fe72[_0xb668('0x19')]?_0x89fe72['options'][_0xb668('0x1d')]?_['map'](_0x89fe72[_0xb668('0x19')]['include'],function(_0x3f4745){return{'model':db[_0x3f4745[_0xb668('0x1e')]],'as':_0x3f4745['as'],'attributes':_0x3f4745[_0xb668('0x1b')],'include':_0x3f4745[_0xb668('0x1d')]?_[_0xb668('0x1f')](_0x3f4745[_0xb668('0x1d')],function(_0x4d4bf8){return{'model':db[_0x4d4bf8[_0xb668('0x1e')]],'as':_0x4d4bf8['as'],'attributes':_0x4d4bf8[_0xb668('0x1b')],'include':_0x4d4bf8[_0xb668('0x1d')]?_['map'](_0x4d4bf8['include'],function(_0xe62fce){return{'model':db[_0xe62fce[_0xb668('0x1e')]],'as':_0xe62fce['as'],'attributes':_0xe62fce[_0xb668('0x1b')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x3a2543){logger[_0xb668('0xc')](_0xb668('0x17'),_0x89fe72);logger['debug']('GetCampaign',_0x89fe72,JSON[_0xb668('0x11')](_0x3a2543));_0x38595d(_0x3a2543);})[_0xb668('0x16')](function(_0x589c58){logger[_0xb668('0x12')](_0xb668('0x17'),_0x589c58[_0xb668('0x14')],_0x89fe72);_0x18e9c1(_0x5438ff[_0xb668('0x12')](0x1f4,_0x589c58[_0xb668('0x14')]));});});};