Something went wrong. Try again.
A blockchain-powered certificate verification platform for @inovuslabs — enabling instant, tamper-proof validation of credentials through s… certificate.inovuslabs.org
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
import dotenv from 'dotenv';dotenv.config();
import { Request, Response } from 'express';import { AuditLog } from '../models';
// Save an audit log entryexport const saveAuditLog = async ({action, user_id, txHash, description}: { action: string; user_id: string; txHash: string; description?: string;}) => { if (!action || !user_id || !txHash) { console.error("Missing required parameters for audit log"); return; } try { const log = new AuditLog({ user_id: user_id, action, txHash, description }); await log.save(); // console.log(`Audit log saved for action: ${action}`); } catch (error) { console.error("Error saving audit log: ", error); } return;}
// Get all audit logs with optional filtersexport const getAuditLogs = async (req: Request, res: Response) => { try { const { user, action, from, to } = req.query;
// Build filter object const filter: any = {}; if (user) filter.userId = user; if (action) filter.action = action; if (from || to) { filter.timestamp = {}; if (from) filter.timestamp.$gte = new Date(from as string); if (to) filter.timestamp.$lte = new Date(to as string); }
const logs = await AuditLog.find(filter).sort({ timestamp: -1 }); return res.status(200).json(logs); } catch (error) { console.error("Error fetching audit logs: ", error); return res.status(500).json({ error: 'Internal Server Error' }); }};