From dd82f36da3fa3b2852bd470e3f62374f27e8d8e2 Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Mon, 9 Jan 2023 00:16:18 +0800 Subject: [PATCH] Fix: Improve syntax & fix weird label logic --- server/routers/api-router.js | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/server/routers/api-router.js b/server/routers/api-router.js index 45236d20..41608a04 100644 --- a/server/routers/api-router.js +++ b/server/routers/api-router.js @@ -143,36 +143,23 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId); const state = overrideValue !== undefined ? overrideValue : heartbeat.status; - badgeValues.label = label ? label : ""; + badgeValues.label = label ?? ""; switch (state) { case 1: badgeValues.color = upColor; + badgeValues.message = upLabel; break; case 3: badgeValues.color = maintenanceColor; + badgeValues.message = maintenanceLabel; break; case 0: badgeValues.color = downColor; + badgeValues.message = downLabel; break; default: badgeValues.color = badgeConstants.naColor; - } - if (label !== undefined) { - badgeValues.message = label; - } else { - switch (state) { - case 1: - badgeValues.message = upLabel; - break; - case 3: - badgeValues.message = maintenanceLabel; - break; - case 0: - badgeValues.message = downLabel; - break; - default: - badgeValues.message = "N/A"; - } + badgeValues.message = "N/A"; } }