Eco-It maintains a persistent audit log that records every consequential administrative action taken on the platform. This creates an accountability trail — any admin can review what was done, by whom, and when — and helps detect misuse of elevated privileges. Each log entry is created automatically by theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/vanegasjoseignacio2-cyber/Eco-It/llms.txt
Use this file to discover all available pages before exploring further.
auditLogger utility whenever a user is banned, unbanned, deleted, or has their role changed, and is delivered in real time to all connected admin panels via Socket.io.
Why Audit Logs Matter
Without an audit trail, it would be impossible to answer questions such as: Who banned this user and why? When was this account deleted? Which admin promoted this user to administrator? The Eco-It audit log stores a concise but complete answer to each of these questions in a tamper-evident, time-limited MongoDB collection.Audit log documents automatically expire after 7 days (604 800 seconds). This is enforced by a MongoDB TTL index on the
createdAt field. Logs older than seven days are deleted by MongoDB itself — not by the application. Superadmins can also delete individual logs or clear all logs before expiry using the dedicated API endpoints.AuditLog Model Fields
TheAuditLog schema (backend/models/AuditLog.js) stores the following fields:
A machine-readable event type used for programmatic filtering. Current values emitted by the admin controller:
ban, unban, delete, role_change.A short human-readable label for the action performed. Examples:
"Usuario Baneado", "Usuario Desbaneado", "Usuario Eliminado", "Cambio de Rol".A full sentence describing what happened. Includes the affected user’s email, the duration of a ban, the motivo (reason), or the new role assigned. Intended for display in the admin UI without further parsing.
The
nombre or email of the admin who performed the action, taken from req.usuario at the time of the call. Defaults to "Sistema" for programmatically triggered events.UTC timestamp of when the log was created. Also serves as the TTL index field — the document is automatically deleted 7 days after this value.
The auditLogger Utility
All audit log creation is centralised in backend/utils/auditLogger.js through a single exported function: createAuditLog. Centralising log creation ensures consistent formatting across all admin controllers and guarantees that real-time notifications are always sent alongside the database write.
createAuditLog:
The Express application instance (
req.app). Used to retrieve the Socket.io io object via app.get('io').Machine-readable event category:
ban, unban, delete, role_change.Short human-readable label.
Full sentence description of the event.
Performing admin’s name or email (
req.usuario.nombre || req.usuario.email).Actions That Trigger Audit Logs
The following operations inadminController.js call createAuditLog automatically:
| Controller Action | type | action | details template |
|---|---|---|---|
| Ban a user | ban | "Usuario Baneado" | "<email> baneado por <N> días. Motivo: <motivo>" |
| Unban a user | unban | "Usuario Desbaneado" | "<email> ha sido desbaneado" |
| Delete a user | delete | "Usuario Eliminado" | "Cuenta eliminada: <email>" |
| Change a user’s role | role_change | "Cambio de Rol" | "Rol de <email> cambiado a \"<rol>\"" |
API Endpoints
Read Audit Logs
Returns the 50 most recent audit log entries sorted bycreatedAt descending. Accessible to both admin and superadmin roles.
Delete a Single Log Entry
Permanently removes one audit log document by its MongoDB_id. Superadmin only.
Delete All Audit Logs
CallsAuditLog.deleteMany({}) to wipe the entire audit log collection. Superadmin only.
Example Audit Log JSON Object
The following is a complete example of an audit log document as returned byGET /api/admin/audit:
Real-Time Delivery
Every timecreateAuditLog writes a new entry to MongoDB, it immediately emits the admin:audit_update Socket.io event to the admins room, passing the full log document as the payload. Any admin currently viewing the Audit Logs section of the panel receives the new entry instantly without polling or refreshing.