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.1 kB ยท 34 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435import { and, eq, inArray, isNull } from "@openstatus/db";import { monitor } from "@openstatus/db/src/schema";
import type { DB } from "../context";import { ForbiddenError } from "../errors";
/** * Ensure every id in `monitorIds` belongs to the given workspace and is not * soft-deleted. No-op when the list is empty. Throws `ForbiddenError` (not * `NotFound`) to match the legacy router's `FORBIDDEN` response โ surfacing * "this id doesn't exist" vs. "this id isn't yours" would leak workspace * state. */export async function assertMonitorsInWorkspace(args: { tx: DB; workspaceId: number; monitorIds: number[];}): Promise<void> { const { tx, workspaceId, monitorIds } = args; if (monitorIds.length === 0) return;
const uniqueIds = Array.from(new Set(monitorIds));
const valid = await tx.query.monitor.findMany({ where: and( eq(monitor.workspaceId, workspaceId), inArray(monitor.id, uniqueIds), isNull(monitor.deletedAt), ), }); if (valid.length !== uniqueIds.length) { throw new ForbiddenError("Invalid monitor IDs."); }}