80c578be1206799f73d0e3a292fc886eace1c52f
[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 _0xc36d=['catch','lodash','util','moment','bluebird','randomstring','ioredis','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','request','info','request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s','stringify','error','Campaign,\x20%s,\x20%s','message','GetCampaign','Campaign','options','where','attributes','include','map','model','then'];(function(_0x4fb24c,_0x4f61d5){var _0x236a8d=function(_0x16a8cc){while(--_0x16a8cc){_0x4fb24c['push'](_0x4fb24c['shift']());}};_0x236a8d(++_0x4f61d5);}(_0xc36d,0x7d));var _0xdc36=function(_0x203b5c,_0x2384f1){_0x203b5c=_0x203b5c-0x0;var _0x20a057=_0xc36d[_0x203b5c];return _0x20a057;};'use strict';var _=require(_0xdc36('0x0'));var util=require(_0xdc36('0x1'));var moment=require(_0xdc36('0x2'));var BPromise=require(_0xdc36('0x3'));var rs=require(_0xdc36('0x4'));var fs=require('fs');var Redis=require(_0xdc36('0x5'));var db=require('../../mysqldb')['db'];var utils=require(_0xdc36('0x6'));var logger=require(_0xdc36('0x7'))('rpc');var config=require(_0xdc36('0x8'));var jayson=require(_0xdc36('0x9'));var client=jayson[_0xdc36('0xa')][_0xdc36('0xb')]({'port':0x232a});function respondWithRpcPromise(_0x6e4753,_0x571311,_0x20ba02){return new BPromise(function(_0x456897,_0x2a0087){return client[_0xdc36('0xc')](_0x6e4753,_0x20ba02)['then'](function(_0x20d00a){logger[_0xdc36('0xd')]('Campaign,\x20%s,\x20%s',_0x571311,_0xdc36('0xe'));logger[_0xdc36('0xf')](_0xdc36('0x10'),_0x571311,'request\x20sent',JSON[_0xdc36('0x11')](_0x20d00a));if(_0x20d00a[_0xdc36('0x12')]){if(_0x20d00a['error']['code']===0x1f4){logger[_0xdc36('0x12')](_0xdc36('0x13'),_0x571311,_0x20d00a[_0xdc36('0x12')][_0xdc36('0x14')]);return _0x2a0087(_0x20d00a['error'][_0xdc36('0x14')]);}logger[_0xdc36('0x12')](_0xdc36('0x13'),_0x571311,_0x20d00a[_0xdc36('0x12')][_0xdc36('0x14')]);return _0x456897(_0x20d00a[_0xdc36('0x12')][_0xdc36('0x14')]);}else{logger[_0xdc36('0xd')]('Campaign,\x20%s,\x20%s',_0x571311,_0xdc36('0xe'));_0x456897(_0x20d00a['result']['message']);}})['catch'](function(_0x64f61e){logger[_0xdc36('0x12')]('Campaign,\x20%s,\x20%s',_0x571311,_0x64f61e);_0x2a0087(_0x64f61e);});});}exports[_0xdc36('0x15')]=function(_0x219a73){var _0x160d70=this;return new Promise(function(_0x225878,_0x183c91){return db[_0xdc36('0x16')]['findAll']({'raw':_0x219a73[_0xdc36('0x17')]?_0x219a73[_0xdc36('0x17')]['raw']===undefined?!![]:![]:!![],'where':_0x219a73[_0xdc36('0x17')]?_0x219a73[_0xdc36('0x17')][_0xdc36('0x18')]||null:null,'attributes':_0x219a73['options']?_0x219a73[_0xdc36('0x17')][_0xdc36('0x19')]||null:null,'limit':_0x219a73['options']?_0x219a73[_0xdc36('0x17')]['limit']||null:null,'include':_0x219a73['options']?_0x219a73[_0xdc36('0x17')][_0xdc36('0x1a')]?_[_0xdc36('0x1b')](_0x219a73[_0xdc36('0x17')][_0xdc36('0x1a')],function(_0x34d261){return{'model':db[_0x34d261[_0xdc36('0x1c')]],'as':_0x34d261['as'],'attributes':_0x34d261[_0xdc36('0x19')],'include':_0x34d261['include']?_[_0xdc36('0x1b')](_0x34d261['include'],function(_0x2338d7){return{'model':db[_0x2338d7[_0xdc36('0x1c')]],'as':_0x2338d7['as'],'attributes':_0x2338d7[_0xdc36('0x19')],'include':_0x2338d7['include']?_[_0xdc36('0x1b')](_0x2338d7[_0xdc36('0x1a')],function(_0x337091){return{'model':db[_0x337091['model']],'as':_0x337091['as'],'attributes':_0x337091[_0xdc36('0x19')]};}):[]};}):[]};}):[]:[]})[_0xdc36('0x1d')](function(_0x2a596d){logger['info'](_0xdc36('0x15'),_0x219a73);logger[_0xdc36('0xf')]('GetCampaign',_0x219a73,JSON[_0xdc36('0x11')](_0x2a596d));_0x225878(_0x2a596d);})[_0xdc36('0x1e')](function(_0x4ea2ad){logger[_0xdc36('0x12')]('GetCampaign',_0x4ea2ad['message'],_0x219a73);_0x183c91(_0x160d70['error'](0x1f4,_0x4ea2ad[_0xdc36('0x14')]));});});};