Fix: Improve syntax & fix weird label logic

This commit is contained in:
Nelson Chan 2023-01-09 00:16:18 +08:00
parent 942b55ca03
commit dd82f36da3

View File

@ -143,38 +143,25 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response
const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId); const heartbeat = await Monitor.getPreviousHeartbeat(requestedMonitorId);
const state = overrideValue !== undefined ? overrideValue : heartbeat.status; const state = overrideValue !== undefined ? overrideValue : heartbeat.status;
badgeValues.label = label ? label : ""; badgeValues.label = label ?? "";
switch (state) { switch (state) {
case 1: case 1:
badgeValues.color = upColor; badgeValues.color = upColor;
break;
case 3:
badgeValues.color = maintenanceColor;
break;
case 0:
badgeValues.color = downColor;
break;
default:
badgeValues.color = badgeConstants.naColor;
}
if (label !== undefined) {
badgeValues.message = label;
} else {
switch (state) {
case 1:
badgeValues.message = upLabel; badgeValues.message = upLabel;
break; break;
case 3: case 3:
badgeValues.color = maintenanceColor;
badgeValues.message = maintenanceLabel; badgeValues.message = maintenanceLabel;
break; break;
case 0: case 0:
badgeValues.color = downColor;
badgeValues.message = downLabel; badgeValues.message = downLabel;
break; break;
default: default:
badgeValues.color = badgeConstants.naColor;
badgeValues.message = "N/A"; badgeValues.message = "N/A";
} }
} }
}
// build the svg based on given values // build the svg based on given values
const svg = makeBadge(badgeValues); const svg = makeBadge(badgeValues);