2026-02-05 21:09:06 +01:00
|
|
|
import { prisma as globalPrisma } from '@/lib/prisma'
|
|
|
|
|
import type { Prisma, PrismaClient } from '@prisma/client'
|
|
|
|
|
|
|
|
|
|
/** Minimal Prisma-like client that supports auditLog.create (works with PrismaClient and transaction clients). */
|
|
|
|
|
type AuditPrismaClient = Pick<PrismaClient, 'auditLog'>
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shared utility for creating audit log entries.
|
|
|
|
|
* Wrapped in try-catch so audit failures never break the calling operation.
|
2026-02-05 21:09:06 +01:00
|
|
|
*
|
|
|
|
|
* @param input.prisma - Optional Prisma client instance. When omitted the global
|
|
|
|
|
* singleton is used. Pass `ctx.prisma` from tRPC handlers so audit writes
|
|
|
|
|
* participate in the same transaction when applicable.
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
*/
|
|
|
|
|
export async function logAudit(input: {
|
2026-02-05 21:09:06 +01:00
|
|
|
prisma?: AuditPrismaClient
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
userId?: string | null
|
|
|
|
|
action: string
|
|
|
|
|
entityType: string
|
|
|
|
|
entityId?: string
|
|
|
|
|
detailsJson?: Record<string, unknown>
|
|
|
|
|
ipAddress?: string
|
|
|
|
|
userAgent?: string
|
|
|
|
|
}): Promise<void> {
|
|
|
|
|
try {
|
2026-02-05 21:09:06 +01:00
|
|
|
const db = input.prisma ?? globalPrisma
|
|
|
|
|
await db.auditLog.create({
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
data: {
|
|
|
|
|
userId: input.userId ?? null,
|
|
|
|
|
action: input.action,
|
|
|
|
|
entityType: input.entityType,
|
|
|
|
|
entityId: input.entityId,
|
|
|
|
|
detailsJson: input.detailsJson as Prisma.InputJsonValue ?? undefined,
|
|
|
|
|
ipAddress: input.ipAddress,
|
|
|
|
|
userAgent: input.userAgent,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// Never break the calling operation on audit failure
|
|
|
|
|
console.error('[Audit] Failed to create audit log entry:', error)
|
|
|
|
|
}
|
|
|
|
|
}
|