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 ยท 49 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import { and, eq } from "@openstatus/db";import { privateLocation, selectPrivateLocationSchema,} from "@openstatus/db/src/schema";
import { emitAudit } from "../audit";import { requireScope } from "../auth";import { type ServiceContext, withTransaction } from "../context";import { DeletePrivateLocationInput } from "./schemas";
/** * Delete a private location. Idempotent โ missing rows (wrong id, wrong * workspace, already deleted) succeed silently, matching the legacy * router's transactional DELETE-without-SELECT behaviour. * * `private_location_to_monitor` has ON DELETE CASCADE, so the join rows * drop automatically. */export async function deletePrivateLocation(args: { ctx: ServiceContext; input: DeletePrivateLocationInput;}): Promise<void> { const { ctx } = args; requireScope(ctx, "write"); const input = DeletePrivateLocationInput.parse(args.input);
await withTransaction(ctx, async (tx) => { const [deleted] = await tx .delete(privateLocation) .where( and( eq(privateLocation.id, input.id), eq(privateLocation.workspaceId, ctx.workspace.id), ), ) .returning();
if (!deleted) return;
const parsed = selectPrivateLocationSchema.parse(deleted); await emitAudit(tx, ctx, { action: "private_location.delete", entityType: "private_location", entityId: parsed.id, before: parsed, }); });}