register/unregister http

This commit is contained in:
arc-alex
2023-11-29 11:29:04 +01:00
parent dfd38c91f6
commit 52a61777ed
2 changed files with 14 additions and 13 deletions
+11 -11
View File
@@ -335,29 +335,29 @@ export const postOscSubscriptions = async (req, res) => {
};
// Create controller for GET request to '/ontime/http'
export const getHTTP = async (req, res: Response<HTTPSettings>) => {
export const getHTTP = async (_req, res: Response<HTTPSettings>) => {
const http = DataProvider.getHttp();
res.status(200).send(http);
};
// Create controller for POST request to '/ontime/http'
export const postHTTP = async (req: Request<any, any, HTTPSettings>, res: Response) => {
export const postHTTP = async (req, res) => {
if (failEmptyObjects(req.body, res)) {
return;
}
try {
const settings = req.body;
const httpSettings = DataProvider.getHttp();
const hasEnabledChanged = httpSettings.enabledOut !== settings.enabledOut;
httpSettings.subscriptions = settings.subscriptions;
httpSettings.enabledOut = settings.enabledOut;
const httpSettings = req.body;
await DataProvider.setHttp(httpSettings);
if (hasEnabledChanged) {
const { message } = httpIntegration.init(httpSettings);
logger.info(LogOrigin.Tx, message);
integrationService.unregister(httpIntegration);
// TODO: this update could be more granular, checking that relevant data was changed
const { success, message } = httpIntegration.init(httpSettings);
logger.info(LogOrigin.Tx, message);
if (success) {
integrationService.register(httpIntegration);
}
res.send(httpSettings).status(200);
@@ -31,9 +31,10 @@ export class HttpIntegration implements IIntegration {
const { subscriptions, enabledOut } = config;
if (!enabledOut) {
this.httpAgent?.destroy();
return {
success: true,
message: `HTTP integration client disabled`,
success: false,
message: 'HTTP output disabled',
};
}