Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.4 kB ยท 45 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546import { and, eq } from "@openstatus/db";import { pageComponent } from "@openstatus/db/src/schema";
import { emitAudit } from "../audit";import { requireScope } from "../auth";import { type ServiceContext, withTransaction } from "../context";import { NotFoundError } from "../errors";import { DeletePageComponentInput } from "./schemas";
/** * Hard-delete a page component. Cascade clears * `status_report_to_page_component` / `maintenance_to_page_component` * (FK cascade delete on the join tables). */export async function deletePageComponent(args: { ctx: ServiceContext; input: DeletePageComponentInput;}): Promise<void> { const { ctx } = args; requireScope(ctx, "write"); const input = DeletePageComponentInput.parse(args.input);
await withTransaction(ctx, async (tx) => { const existing = await tx .select() .from(pageComponent) .where( and( eq(pageComponent.id, input.id), eq(pageComponent.workspaceId, ctx.workspace.id), ), ) .get(); if (!existing) throw new NotFoundError("page_component", input.id);
await tx.delete(pageComponent).where(eq(pageComponent.id, existing.id));
await emitAudit(tx, ctx, { action: "page_component.delete", entityType: "page_component", entityId: existing.id, before: existing, }); });}