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.6 kB ยท 57 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import { and, eq } from "@openstatus/db";import { pageSubscriber, selectPageSubscriberSchema,} from "@openstatus/db/src/schema";
import { emitAudit } from "../audit";import { requireScope } from "../auth";import { type ServiceContext, withTransaction } from "../context";import { NotFoundError } from "../errors";import { loadPageForWorkspace } from "./internal";import { DeletePageSubscriberInput } from "./schemas";
/** * Hard-delete a subscriber row from the dashboard. Page must belong to * the caller's workspace and the subscriber must belong to that page; * both are strict (no silent success), matching the legacy router. */export async function deletePageSubscriber(args: { ctx: ServiceContext; input: DeletePageSubscriberInput;}): Promise<void> { const { ctx } = args; requireScope(ctx, "write"); const input = DeletePageSubscriberInput.parse(args.input);
await withTransaction(ctx, async (tx) => { await loadPageForWorkspace({ tx, pageId: input.pageId, workspaceId: ctx.workspace.id, });
const [deleted] = await tx .delete(pageSubscriber) .where( and( eq(pageSubscriber.id, input.id), eq(pageSubscriber.pageId, input.pageId), ), ) .returning();
if (!deleted) { throw new NotFoundError("page_subscriber", input.id); }
const parsed = selectPageSubscriberSchema.parse(deleted); const { token: _token, ...before } = parsed; await emitAudit(tx, ctx, { action: "page_subscriber.delete", entityType: "page_subscriber", entityId: parsed.id, before, }); });}