Handeling the different health status

This commit is contained in:
Owen
2026-04-24 17:30:54 -07:00
parent 34296e5f40
commit cca7cea2f1
9 changed files with 112 additions and 148 deletions

View File

@@ -166,6 +166,17 @@ export async function updateHealthCheck(
const updateData: Record<string, unknown> = {};
const [existingHealthCheck] = await db
.select()
.from(targetHealthCheck)
.where(
and(
eq(targetHealthCheck.targetHealthCheckId, healthCheckId),
eq(targetHealthCheck.orgId, orgId)
)
)
.limit(1);
if (name !== undefined) updateData.name = name;
if (siteId !== undefined) updateData.siteId = siteId;
if (hcEnabled !== undefined) updateData.hcEnabled = hcEnabled;
@@ -190,6 +201,26 @@ export async function updateHealthCheck(
if (hcUnhealthyThreshold !== undefined)
updateData.hcUnhealthyThreshold = hcUnhealthyThreshold;
const hcEnabledTurnedOn =
parsedBody.data.hcEnabled === true &&
existingHealthCheck.hcEnabled === false;
let hcHealthValue: "unknown" | "healthy" | "unhealthy" | undefined;
if (
parsedBody.data.hcEnabled === false ||
parsedBody.data.hcEnabled === null
) {
hcHealthValue = "unknown";
} else if (hcEnabledTurnedOn) {
hcHealthValue = "unhealthy";
} else {
hcHealthValue = undefined;
}
if (hcHealthValue) {
updateData.hcHealth = hcHealthValue;
}
const [updated] = await db
.update(targetHealthCheck)
.set(updateData)