SPB Git
769 B · 10 lines typescript
1import { desc, eq } from "drizzle-orm";2import { handler } from "@/lib/api";3import { db, schema } from "@/db";4/** GET ?limit=50 → most recent audit log entries of the current user. */5export const GET = handler(async ({ req, user }) => {6  const limit = Math.min(200, Math.max(1, Number(new URL(req.url).searchParams.get("limit") ?? 50)));7  const rows = await db.select({ id: schema.auditLogs.id, action: schema.auditLogs.action, targetType: schema.auditLogs.targetType, targetId: schema.auditLogs.targetId, detail: schema.auditLogs.detail, ip: schema.auditLogs.ip, createdAt: schema.auditLogs.createdAt }).from(schema.auditLogs).where(eq(schema.auditLogs.userId, user.id)).orderBy(desc(schema.auditLogs.createdAt)).limit(limit);8  return Response.json(rows);9});10
Files · main
Menu

Theme