e6f48f11e8d02389e67945206d965ee9b3a803a5
[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 _0xac72=['request','info','Campaign,\x20%s,\x20%s','request\x20sent','debug','Campaign,\x20%s,\x20%s,\x20%s','error','code','message','result','catch','GetCampaign','Campaign','findAll','options','raw','where','include','map','model','attributes','then','stringify','lodash','util','moment','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http'];(function(_0x2ffd16,_0x4d2c9d){var _0x3c6041=function(_0x28983b){while(--_0x28983b){_0x2ffd16['push'](_0x2ffd16['shift']());}};_0x3c6041(++_0x4d2c9d);}(_0xac72,0x1eb));var _0x2ac7=function(_0x5647d0,_0x188a6d){_0x5647d0=_0x5647d0-0x0;var _0x5de0f0=_0xac72[_0x5647d0];return _0x5de0f0;};'use strict';var _=require(_0x2ac7('0x0'));var util=require(_0x2ac7('0x1'));var moment=require(_0x2ac7('0x2'));var BPromise=require('bluebird');var rs=require(_0x2ac7('0x3'));var fs=require('fs');var Redis=require(_0x2ac7('0x4'));var db=require(_0x2ac7('0x5'))['db'];var utils=require(_0x2ac7('0x6'));var logger=require(_0x2ac7('0x7'))(_0x2ac7('0x8'));var config=require(_0x2ac7('0x9'));var jayson=require(_0x2ac7('0xa'));var client=jayson[_0x2ac7('0xb')][_0x2ac7('0xc')]({'port':0x232a});function respondWithRpcPromise(_0x4e11a4,_0x19d2f0,_0xf836e2){return new BPromise(function(_0x5055f1,_0x2bcc25){return client[_0x2ac7('0xd')](_0x4e11a4,_0xf836e2)['then'](function(_0x2679e5){logger[_0x2ac7('0xe')](_0x2ac7('0xf'),_0x19d2f0,_0x2ac7('0x10'));logger[_0x2ac7('0x11')](_0x2ac7('0x12'),_0x19d2f0,_0x2ac7('0x10'),JSON['stringify'](_0x2679e5));if(_0x2679e5[_0x2ac7('0x13')]){if(_0x2679e5['error'][_0x2ac7('0x14')]===0x1f4){logger['error'](_0x2ac7('0xf'),_0x19d2f0,_0x2679e5[_0x2ac7('0x13')]['message']);return _0x2bcc25(_0x2679e5['error'][_0x2ac7('0x15')]);}logger[_0x2ac7('0x13')](_0x2ac7('0xf'),_0x19d2f0,_0x2679e5[_0x2ac7('0x13')][_0x2ac7('0x15')]);return _0x5055f1(_0x2679e5['error'][_0x2ac7('0x15')]);}else{logger[_0x2ac7('0xe')]('Campaign,\x20%s,\x20%s',_0x19d2f0,'request\x20sent');_0x5055f1(_0x2679e5[_0x2ac7('0x16')][_0x2ac7('0x15')]);}})[_0x2ac7('0x17')](function(_0x10911d){logger['error'](_0x2ac7('0xf'),_0x19d2f0,_0x10911d);_0x2bcc25(_0x10911d);});});}exports[_0x2ac7('0x18')]=function(_0x206d33){var _0xa2487d=this;return new Promise(function(_0x30378f,_0x2f3732){return db[_0x2ac7('0x19')][_0x2ac7('0x1a')]({'raw':_0x206d33[_0x2ac7('0x1b')]?_0x206d33[_0x2ac7('0x1b')][_0x2ac7('0x1c')]===undefined?!![]:![]:!![],'where':_0x206d33[_0x2ac7('0x1b')]?_0x206d33[_0x2ac7('0x1b')][_0x2ac7('0x1d')]||null:null,'attributes':_0x206d33[_0x2ac7('0x1b')]?_0x206d33['options']['attributes']||null:null,'limit':_0x206d33['options']?_0x206d33[_0x2ac7('0x1b')]['limit']||null:null,'include':_0x206d33[_0x2ac7('0x1b')]?_0x206d33[_0x2ac7('0x1b')][_0x2ac7('0x1e')]?_[_0x2ac7('0x1f')](_0x206d33['options'][_0x2ac7('0x1e')],function(_0x2821e0){return{'model':db[_0x2821e0[_0x2ac7('0x20')]],'as':_0x2821e0['as'],'attributes':_0x2821e0['attributes'],'include':_0x2821e0[_0x2ac7('0x1e')]?_[_0x2ac7('0x1f')](_0x2821e0[_0x2ac7('0x1e')],function(_0x5a8c01){return{'model':db[_0x5a8c01['model']],'as':_0x5a8c01['as'],'attributes':_0x5a8c01[_0x2ac7('0x21')],'include':_0x5a8c01['include']?_[_0x2ac7('0x1f')](_0x5a8c01[_0x2ac7('0x1e')],function(_0x1dbcbd){return{'model':db[_0x1dbcbd[_0x2ac7('0x20')]],'as':_0x1dbcbd['as'],'attributes':_0x1dbcbd[_0x2ac7('0x21')]};}):[]};}):[]};}):[]:[]})[_0x2ac7('0x22')](function(_0x19a88e){logger['info'](_0x2ac7('0x18'),_0x206d33);logger['debug'](_0x2ac7('0x18'),_0x206d33,JSON[_0x2ac7('0x23')](_0x19a88e));_0x30378f(_0x19a88e);})['catch'](function(_0x3fac0e){logger[_0x2ac7('0x13')](_0x2ac7('0x18'),_0x3fac0e[_0x2ac7('0x15')],_0x206d33);_0x2f3732(_0xa2487d[_0x2ac7('0x13')](0x1f4,_0x3fac0e[_0x2ac7('0x15')]));});});};