mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-21 13:06:59 +02:00
Add siteId to api
This commit is contained in:
@@ -194,6 +194,9 @@ export const targetHealthCheck = pgTable("targetHealthCheck", {
|
|||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
})
|
})
|
||||||
.notNull(),
|
.notNull(),
|
||||||
|
siteId: integer("siteId").references(() => sites.siteId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
}).notNull(),
|
||||||
name: varchar("name"),
|
name: varchar("name"),
|
||||||
hcEnabled: boolean("hcEnabled").notNull().default(false),
|
hcEnabled: boolean("hcEnabled").notNull().default(false),
|
||||||
hcPath: varchar("hcPath"),
|
hcPath: varchar("hcPath"),
|
||||||
|
|||||||
@@ -217,6 +217,9 @@ export const targetHealthCheck = sqliteTable("targetHealthCheck", {
|
|||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
})
|
})
|
||||||
.notNull(),
|
.notNull(),
|
||||||
|
siteId: integer("siteId").references(() => sites.siteId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
}).notNull(),
|
||||||
name: text("name"),
|
name: text("name"),
|
||||||
hcEnabled: integer("hcEnabled", { mode: "boolean" })
|
hcEnabled: integer("hcEnabled", { mode: "boolean" })
|
||||||
.notNull()
|
.notNull()
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ const paramsSchema = z.strictObject({
|
|||||||
|
|
||||||
const bodySchema = z.strictObject({
|
const bodySchema = z.strictObject({
|
||||||
name: z.string().nonempty(),
|
name: z.string().nonempty(),
|
||||||
|
siteId: z.number().int().positive(),
|
||||||
hcEnabled: z.boolean().default(false),
|
hcEnabled: z.boolean().default(false),
|
||||||
hcMode: z.string().default("http"),
|
hcMode: z.string().default("http"),
|
||||||
hcHostname: z.string().optional(),
|
hcHostname: z.string().optional(),
|
||||||
@@ -97,6 +98,7 @@ export async function createHealthCheck(
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
|
siteId,
|
||||||
hcEnabled,
|
hcEnabled,
|
||||||
hcMode,
|
hcMode,
|
||||||
hcHostname,
|
hcHostname,
|
||||||
@@ -120,6 +122,7 @@ export async function createHealthCheck(
|
|||||||
.values({
|
.values({
|
||||||
targetId: null,
|
targetId: null,
|
||||||
orgId,
|
orgId,
|
||||||
|
siteId,
|
||||||
name,
|
name,
|
||||||
hcEnabled,
|
hcEnabled,
|
||||||
hcMode,
|
hcMode,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export async function getHealthCheckStatusHistory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const entityType = "healthCheck";
|
const entityType = "healthCheck";
|
||||||
const entityId = parsedParams.data.healthCheckId
|
const entityId = parsedParams.data.healthCheckId;
|
||||||
const { days } = parsedQuery.data;
|
const { days } = parsedQuery.data;
|
||||||
|
|
||||||
const nowSec = Math.floor(Date.now() / 1000);
|
const nowSec = Math.floor(Date.now() / 1000);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
* This file is not licensed under the AGPLv3.
|
* This file is not licensed under the AGPLv3.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { db, targetHealthCheck, targets, resources } from "@server/db";
|
import { db, targetHealthCheck, targets, resources, sites } from "@server/db";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
import createHttpError from "http-errors";
|
import createHttpError from "http-errors";
|
||||||
@@ -97,6 +97,9 @@ export async function listHealthChecks(
|
|||||||
.select({
|
.select({
|
||||||
targetHealthCheckId: targetHealthCheck.targetHealthCheckId,
|
targetHealthCheckId: targetHealthCheck.targetHealthCheckId,
|
||||||
name: targetHealthCheck.name,
|
name: targetHealthCheck.name,
|
||||||
|
siteId: targetHealthCheck.siteId,
|
||||||
|
siteName: sites.name,
|
||||||
|
siteNiceId: sites.niceId,
|
||||||
hcEnabled: targetHealthCheck.hcEnabled,
|
hcEnabled: targetHealthCheck.hcEnabled,
|
||||||
hcHealth: targetHealthCheck.hcHealth,
|
hcHealth: targetHealthCheck.hcHealth,
|
||||||
hcMode: targetHealthCheck.hcMode,
|
hcMode: targetHealthCheck.hcMode,
|
||||||
@@ -121,6 +124,7 @@ export async function listHealthChecks(
|
|||||||
.from(targetHealthCheck)
|
.from(targetHealthCheck)
|
||||||
.leftJoin(targets, eq(targetHealthCheck.targetId, targets.targetId))
|
.leftJoin(targets, eq(targetHealthCheck.targetId, targets.targetId))
|
||||||
.leftJoin(resources, eq(targets.resourceId, resources.resourceId))
|
.leftJoin(resources, eq(targets.resourceId, resources.resourceId))
|
||||||
|
.leftJoin(sites, eq(targetHealthCheck.siteId, sites.siteId))
|
||||||
.where(whereClause)
|
.where(whereClause)
|
||||||
.orderBy(sql`${targetHealthCheck.targetHealthCheckId} DESC`)
|
.orderBy(sql`${targetHealthCheck.targetHealthCheckId} DESC`)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
@@ -136,6 +140,9 @@ export async function listHealthChecks(
|
|||||||
healthChecks: list.map((row) => ({
|
healthChecks: list.map((row) => ({
|
||||||
targetHealthCheckId: row.targetHealthCheckId,
|
targetHealthCheckId: row.targetHealthCheckId,
|
||||||
name: row.name ?? "",
|
name: row.name ?? "",
|
||||||
|
siteId: row.siteId ?? null,
|
||||||
|
siteName: row.siteName ?? null,
|
||||||
|
siteNiceId: row.siteNiceId ?? null,
|
||||||
hcEnabled: row.hcEnabled,
|
hcEnabled: row.hcEnabled,
|
||||||
hcHealth: (row.hcHealth ?? "unknown") as
|
hcHealth: (row.hcHealth ?? "unknown") as
|
||||||
| "unknown"
|
| "unknown"
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ const paramsSchema = z
|
|||||||
|
|
||||||
const bodySchema = z.strictObject({
|
const bodySchema = z.strictObject({
|
||||||
name: z.string().nonempty().optional(),
|
name: z.string().nonempty().optional(),
|
||||||
|
siteId: z.number().int().positive().optional(),
|
||||||
hcEnabled: z.boolean().optional(),
|
hcEnabled: z.boolean().optional(),
|
||||||
hcMode: z.string().optional(),
|
hcMode: z.string().optional(),
|
||||||
hcHostname: z.string().optional(),
|
hcHostname: z.string().optional(),
|
||||||
@@ -55,6 +56,7 @@ const bodySchema = z.strictObject({
|
|||||||
export type UpdateHealthCheckResponse = {
|
export type UpdateHealthCheckResponse = {
|
||||||
targetHealthCheckId: number;
|
targetHealthCheckId: number;
|
||||||
name: string | null;
|
name: string | null;
|
||||||
|
siteId: number | null;
|
||||||
hcEnabled: boolean;
|
hcEnabled: boolean;
|
||||||
hcHealth: string | null;
|
hcHealth: string | null;
|
||||||
hcMode: string | null;
|
hcMode: string | null;
|
||||||
@@ -145,6 +147,7 @@ export async function updateHealthCheck(
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
|
siteId,
|
||||||
hcEnabled,
|
hcEnabled,
|
||||||
hcMode,
|
hcMode,
|
||||||
hcHostname,
|
hcHostname,
|
||||||
@@ -166,6 +169,7 @@ export async function updateHealthCheck(
|
|||||||
const updateData: Record<string, unknown> = {};
|
const updateData: Record<string, unknown> = {};
|
||||||
|
|
||||||
if (name !== undefined) updateData.name = name;
|
if (name !== undefined) updateData.name = name;
|
||||||
|
if (siteId !== undefined) updateData.siteId = siteId;
|
||||||
if (hcEnabled !== undefined) updateData.hcEnabled = hcEnabled;
|
if (hcEnabled !== undefined) updateData.hcEnabled = hcEnabled;
|
||||||
if (hcMode !== undefined) updateData.hcMode = hcMode;
|
if (hcMode !== undefined) updateData.hcMode = hcMode;
|
||||||
if (hcHostname !== undefined) updateData.hcHostname = hcHostname;
|
if (hcHostname !== undefined) updateData.hcHostname = hcHostname;
|
||||||
@@ -206,6 +210,7 @@ export async function updateHealthCheck(
|
|||||||
return response<UpdateHealthCheckResponse>(res, {
|
return response<UpdateHealthCheckResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
targetHealthCheckId: updated.targetHealthCheckId,
|
targetHealthCheckId: updated.targetHealthCheckId,
|
||||||
|
siteId: updated.siteId ?? null,
|
||||||
name: updated.name ?? null,
|
name: updated.name ?? null,
|
||||||
hcEnabled: updated.hcEnabled,
|
hcEnabled: updated.hcEnabled,
|
||||||
hcHealth: updated.hcHealth ?? null,
|
hcHealth: updated.hcHealth ?? null,
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ export async function createTarget(
|
|||||||
.values({
|
.values({
|
||||||
orgId: resource.orgId,
|
orgId: resource.orgId,
|
||||||
targetId: newTarget[0].targetId,
|
targetId: newTarget[0].targetId,
|
||||||
|
siteId: targetData.siteId,
|
||||||
name: `Resource ${resource.name} - ${targetData.ip}:${targetData.port}`,
|
name: `Resource ${resource.name} - ${targetData.ip}:${targetData.port}`,
|
||||||
hcEnabled: targetData.hcEnabled ?? false,
|
hcEnabled: targetData.hcEnabled ?? false,
|
||||||
hcPath: targetData.hcPath ?? null,
|
hcPath: targetData.hcPath ?? null,
|
||||||
|
|||||||
@@ -228,6 +228,7 @@ export async function updateTarget(
|
|||||||
const [updatedHc] = await db
|
const [updatedHc] = await db
|
||||||
.update(targetHealthCheck)
|
.update(targetHealthCheck)
|
||||||
.set({
|
.set({
|
||||||
|
siteId: parsedBody.data.siteId,
|
||||||
hcEnabled: parsedBody.data.hcEnabled || false,
|
hcEnabled: parsedBody.data.hcEnabled || false,
|
||||||
hcPath: parsedBody.data.hcPath,
|
hcPath: parsedBody.data.hcPath,
|
||||||
hcScheme: parsedBody.data.hcScheme,
|
hcScheme: parsedBody.data.hcScheme,
|
||||||
|
|||||||
Reference in New Issue
Block a user