2019-01-01 11:26:51 -05:00
|
|
|
var request = require('request-promise');
|
2019-09-01 13:01:38 -04:00
|
|
|
var common = require('../../common');
|
|
|
|
var logger = require('../logger');
|
2019-03-02 12:55:19 -05:00
|
|
|
var options = {};
|
2018-10-09 20:08:05 -04:00
|
|
|
|
|
|
|
exports.getPayments = (req, res, next) => {
|
2019-04-06 20:20:40 -04:00
|
|
|
options = common.getOptions();
|
2019-09-02 00:11:37 -04:00
|
|
|
options.url = common.getSelLNServerUrl() + '/payments';
|
2019-01-01 11:26:51 -05:00
|
|
|
request(options).then((body) => {
|
2018-10-09 20:08:05 -04:00
|
|
|
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
|
|
|
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
|
2019-07-27 14:20:17 -04:00
|
|
|
logger.info({fileName: 'Payments', msg: 'Payment Decoded Received: ' + body_str});
|
2018-10-09 20:08:05 -04:00
|
|
|
if(undefined === body || search_idx > -1 || body.error) {
|
|
|
|
res.status(500).json({
|
|
|
|
message: "Payments List Failed!",
|
2018-10-11 20:03:54 -04:00
|
|
|
error: (undefined === body || search_idx > -1) ? 'Error From Server!' : body.error
|
2018-10-09 20:08:05 -04:00
|
|
|
});
|
|
|
|
} else {
|
2019-10-27 16:39:40 -04:00
|
|
|
if (undefined !== body.payments && body.payments.length > 0) {
|
2018-12-11 19:06:57 -05:00
|
|
|
body.payments.forEach(payment => {
|
|
|
|
payment.creation_date_str = (undefined === payment.creation_date) ? '' : common.convertTimestampToDate(payment.creation_date);
|
|
|
|
});
|
2019-01-19 18:47:56 -05:00
|
|
|
body.payments = common.sortDescByKey(body.payments, 'creation_date');
|
2018-12-11 19:06:57 -05:00
|
|
|
}
|
2018-10-09 20:08:05 -04:00
|
|
|
res.status(200).json(body.payments);
|
|
|
|
}
|
2019-01-01 11:26:51 -05:00
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
return res.status(500).json({
|
|
|
|
message: "Payments List Failed!",
|
|
|
|
error: err.error
|
|
|
|
});
|
2018-10-09 20:08:05 -04:00
|
|
|
});
|
|
|
|
};
|