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.2 kB ยท 43 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344import { and, eq } from "@openstatus/db";import { privateLocation } from "@openstatus/db/src/schema";
import { getReadDb, type ServiceContext } from "../context";import { NotFoundError } from "../errors";import { GetPrivateLocationInput } from "./schemas";
/** * Fetch one private location in the caller's workspace, flattened the same * way `listPrivateLocations` flattens its items. * * Return type is deliberately inferred โ see the note in `list.ts`. */export async function getPrivateLocation(args: { ctx: ServiceContext; input: GetPrivateLocationInput;}) { const input = GetPrivateLocationInput.parse(args.input); const db = getReadDb(args.ctx);
const row = await db.query.privateLocation.findFirst({ where: and( eq(privateLocation.id, input.id), eq(privateLocation.workspaceId, args.ctx.workspace.id), ), with: { privateLocationToMonitors: { with: { monitor: true }, }, }, });
if (!row) throw new NotFoundError("private_location", input.id);
return { ...row, monitors: row.privateLocationToMonitors .map((link) => link.monitor) .filter( (m): m is NonNullable<typeof m> => m !== null && m.deletedAt === null, ), };}