Commit 8e5fbb9d04fb641052f54bfb8f4fcc8f43603621

Authored by Adhidarma Hadiwinoto
1 parent 543431fe9c
Exists in master

resend-report

Showing 3 changed files with 49 additions and 1 deletions Side-by-side Diff

aaa-report-sender.js
... ... @@ -0,0 +1,41 @@
  1 +var request = require('request');
  2 +var moment = require('moment');
  3 +
  4 +var config;
  5 +var monitorUtil;
  6 +
  7 +function init(options) {
  8 + config = options.config;
  9 + monitorUtil = options.monitorUtil;
  10 +}
  11 +
  12 +function _resend(requestId, cb) {
  13 + monitorUtil.getTrx(requestId, function(err, trx) {
  14 +
  15 + if (err) {
  16 + cb(err);
  17 + return;
  18 + }
  19 +
  20 + var options = {
  21 + url: config.aaa_url + '/topup',
  22 + qs: {
  23 + trans_id: requestId,
  24 + trans_date: moment().format('YYYYMMDDHHmmss'),
  25 + resp_code: trx.rc,
  26 + ussd_msg: trx.supplier + '$' + trx.lastResponse.parsed.MESSAGE
  27 + }
  28 + };
  29 +
  30 + cb(null);
  31 + });
  32 +}
  33 +
  34 +function resend(req, res, next) {
  35 + _resend(req.params.id, function(err) {
  36 + res.redirect("/trx/view/" + req.params.id);
  37 + });
  38 +}
  39 +
  40 +exports.init = init;
  41 +exports.resend = resend;
... ... @@ -36,12 +36,16 @@ monitorUtil.init({
36 36 })
37 37  
38 38 var controllerOptions = {
39   - config: config
  39 + config: config,
  40 + monitorUtil: monitorUtil
40 41 }
41 42  
42 43 var UsersController = require("./usersController");
43 44 var usersController = new UsersController(config);
44 45  
  46 +var aaaReportSender = require("./aaa-report-sender");
  47 +aaaReportSender.init(controllerOptions);
  48 +
45 49 var app = express();
46 50  
47 51 app.use(morgan('combined', {stream: accessLogStream}));
... ... @@ -347,6 +351,7 @@ app.get('/logout', logout);
347 351 app.get('/runtime-info', authNeeded, adminNeeded, pageRuntimeInfo);
348 352  
349 353 app.get('/trx/view/:id', authNeeded, pageTrxView);
  354 +app.get('/trx/resend-report/:id', authNeeded, adminNeeded, aaaReportSender.resend);
350 355  
351 356 app.get('/users', authNeeded, adminNeeded, usersController.index);
352 357 app.get('/users/view/:id', authNeeded, adminNeeded, usersController.view);
... ... @@ -27,9 +27,11 @@
27 27 "express-session": "^1.13.0",
28 28 "file-stream-rotator": "0.0.6",
29 29 "lru-cache": "^4.0.1",
  30 + "moment": "^2.15.1",
30 31 "mongodb": "^2.1.18",
31 32 "morgan": "^1.7.0",
32 33 "nunjucks": "^2.4.2",
  34 + "request": "^2.75.0",
33 35 "strftime": "^0.9.2",
34 36 "winston": "^2.2.0"
35 37 },