- Updated all packages to latest versions (React 19, Next.js 14.2.32) - Replaced sqlite3 with pg and drizzle-orm dependencies - Created complete PostgreSQL schema with relationships and indexes - Migrated all API endpoints from SQLite to Drizzle queries - Added database seeding with sample data - Updated authentication to use bcrypt instead of pbkdf2 - Configured connection pooling for PostgreSQL - Updated app version to 1.0.0 - All endpoints tested and working correctly
45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
import { db, schema } from './db/connection'
|
|
|
|
export interface AuditLogEntry {
|
|
user_id?: number
|
|
action: string
|
|
resource_type: string
|
|
resource_id?: number
|
|
details?: any
|
|
ip_address?: string
|
|
}
|
|
|
|
export async function logAuditEvent(entry: AuditLogEntry): Promise<void> {
|
|
try {
|
|
await db.insert(schema.auditLogs).values({
|
|
userId: entry.user_id || null,
|
|
action: entry.action,
|
|
resourceType: entry.resource_type,
|
|
resourceId: entry.resource_id || null,
|
|
details: entry.details ? JSON.stringify(entry.details) : null,
|
|
ipAddress: entry.ip_address || null
|
|
})
|
|
} catch (error) {
|
|
console.error('Audit logging failed:', error)
|
|
}
|
|
}
|
|
|
|
export const AuditActions = {
|
|
CREATE: 'CREATE',
|
|
UPDATE: 'UPDATE',
|
|
DELETE: 'DELETE',
|
|
APPROVE: 'APPROVE',
|
|
REJECT: 'REJECT',
|
|
LOGIN: 'LOGIN',
|
|
LOGOUT: 'LOGOUT',
|
|
BULK_IMPORT: 'BULK_IMPORT',
|
|
EXPORT: 'EXPORT'
|
|
} as const
|
|
|
|
export const ResourceTypes = {
|
|
SOURCE: 'source',
|
|
REPORT: 'report',
|
|
USER: 'user',
|
|
CATEGORY: 'category',
|
|
API_KEY: 'api_key'
|
|
} as const |