2021-12-30 00:08:41 +01:00
|
|
|
import request from 'request-promise';
|
|
|
|
import { Logger, LoggerService } from '../../utils/logger.js';
|
|
|
|
import { Common, CommonService } from '../../utils/common.js';
|
|
|
|
let options = null;
|
|
|
|
const logger: LoggerService = Logger;
|
|
|
|
const common: CommonService = Common;
|
|
|
|
|
|
|
|
export const deleteExpiredInvoice = (req, res, next) => {
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Deleting Expired Invoices..' });
|
|
|
|
options = common.getOptions(req);
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
2024-11-11 05:23:52 +01:00
|
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/autoclean-once';
|
2023-12-06 05:32:05 +01:00
|
|
|
options.body = req.body;
|
|
|
|
request.post(options).then((body) => {
|
2022-01-16 21:55:50 +01:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoices Deleted', data: body });
|
2024-11-11 05:23:52 +01:00
|
|
|
res.status(201).json({ status: 'Cleaned Invoices: ' + body.autoclean.expiredinvoices.cleaned + ', Uncleaned Invoices: ' + body.autoclean.expiredinvoices.uncleaned });
|
2021-12-30 00:08:41 +01:00
|
|
|
}).catch((errRes) => {
|
|
|
|
const err = common.handleError(errRes, 'Invoice', 'Delete Invoice Error', req.session.selectedNode);
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const listInvoices = (req, res, next) => {
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Getting Invoices..' });
|
|
|
|
options = common.getOptions(req);
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
2024-06-10 21:40:37 +02:00
|
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listinvoices';
|
2023-12-06 05:32:05 +01:00
|
|
|
options.body = req.body;
|
2021-12-30 00:08:41 +01:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List URL', data: options.url });
|
2023-12-06 05:32:05 +01:00
|
|
|
request.post(options).then((body) => {
|
2021-12-30 00:08:41 +01:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List Received', data: body });
|
|
|
|
res.status(200).json(body);
|
|
|
|
}).catch((errRes) => {
|
|
|
|
const err = common.handleError(errRes, 'Invoice', 'List Invoices Error', req.session.selectedNode);
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const addInvoice = (req, res, next) => {
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' });
|
|
|
|
options = common.getOptions(req);
|
|
|
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
2024-06-10 21:40:37 +02:00
|
|
|
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/invoice';
|
2021-12-30 00:08:41 +01:00
|
|
|
options.body = req.body;
|
|
|
|
request.post(options).then((body) => {
|
2022-01-16 21:55:50 +01:00
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoice Created', data: body });
|
2021-12-30 00:08:41 +01:00
|
|
|
res.status(201).json(body);
|
|
|
|
}).catch((errRes) => {
|
|
|
|
const err = common.handleError(errRes, 'Invoice', 'Add Invoice Error', req.session.selectedNode);
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
});
|
|
|
|
};
|