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 ยท 49 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import { and, eq, isNull } from "@openstatus/db";import { auditLog, selectAuditLogSchema, user,} from "@openstatus/db/src/schema";
import { type ServiceContext, getReadDb } from "../context";import { NotFoundError } from "../errors";import type { AuditLogListItem } from "./list";
/** Soft-deleted actors come back with `user: null` (same join shape as listAuditLogs). */export async function getAuditLog(args: { ctx: ServiceContext; input: { id: number };}): Promise<AuditLogListItem> { const { ctx, input } = args; const db = getReadDb(ctx);
const row = await db .select({ auditLog, user: { id: user.id, name: user.name, email: user.email, photoUrl: user.photoUrl, }, }) .from(auditLog) .leftJoin( user, and(eq(user.id, auditLog.actorUserId), isNull(user.deletedAt)), ) .where( and( eq(auditLog.id, input.id), eq(auditLog.workspaceId, ctx.workspace.id), ), ) .get();
if (!row) throw new NotFoundError("audit_log", input.id);
return { ...selectAuditLogSchema.parse(row.auditLog), user: row.user?.id != null ? row.user : null, };}