The Eco-It user management system gives administrators complete visibility and control over every registered account. Admins can list all users, search and filter by role or status, apply temporary bans, lift bans early, and delete accounts entirely. Role promotion and demotion are reserved exclusively for superadmins. All write operations emit real-time Socket.io events so that affected users — and other connected admins — are notified instantly.Documentation 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.
User Model Fields
The following fields from theUser model are most relevant to admin operations. Sensitive fields such as password, resetPasswordToken, and resetPasswordExpires are stripped from all admin API responses.
The user’s first name.
The user’s last name. Required for locally registered accounts; optional for Google OAuth accounts.
Unique, lowercase email address. Used as the primary identifier in audit log entries.
One of
user, admin, or superadmin. Defaults to user on registration.One of
active, inactive, or banned. Defaults to active.The UTC datetime at which the ban expires.
null when the user is not banned. The verificarToken middleware automatically lifts an expired ban on the next login attempt.Human-readable reason stored at ban time.
null when the user is not banned.Timestamp of the user’s most recent socket connection. Useful for identifying inactive accounts.
Eco-It gamification points accumulated by the user. Displayed as a progress bar in the admin Users table.
Virtual field appended by the API response.
true if the user’s ID is present in the live usuariosConectados Map.API Endpoints
List All Users
Returns an array of all registered users sorted bycreatedAt descending, with sensitive fields omitted. Each user object includes the virtual isOnline flag derived from the live socket connections map.
Platform Statistics
Returns KPI totals and time-series chart data used by the admin Dashboard. Runs multiple MongoDB aggregations in parallel to minimize latency.Total registered user count.
Real-time count of users with at least one active socket connection.
Number of EcoBot (AI) queries sent today by regular users.
New accounts created since midnight of the current day.
Sum of
puntos across all user documents.Time-series arrays for charting:
users, queries, usersMonth, queriesMonth, usersWeek, queriesWeek. Each array contains objects with { label, value }.Ban a User
Setsstatus to "banned", computes the banHasta expiry date, and stores the banReason. Emits admin:usuario_baneado to the admins Socket.io room and user:banned directly to the affected user’s socket(s). Also creates a Notification document visible to all admins.
Number of days the ban should last. Must be a positive integer (1–365 recommended).
Human-readable reason for the ban. Stored in
banReason and included in audit log details.An admin cannot ban themselves (
req.usuario.id === id returns 400). The ban check also applies in the verificarToken middleware: if banHasta has passed by the time the user next authenticates, the ban is lifted automatically and the user regains access.Unban a User
Resetsstatus to "active" and sets banHasta to null. Emits user:unbanned to the affected user’s socket(s) for an immediate in-app notification.
Delete a User
Permanently removes the user document from MongoDB viafindByIdAndDelete. Creates an audit log entry recording the deleted email. An admin cannot delete their own account.
Change a User’s Role
Promotes or demotes a user between"user" and "admin". Superadmin-only. After the database update, the backend synchronises the user’s live socket room membership — joining or leaving the admins Socket.io room — so the change takes effect without requiring the affected user to log out.
The new role. Must be one of
"user" or "admin". Passing "superadmin" is explicitly rejected with 400.| Condition | HTTP Status | Message |
|---|---|---|
| Caller is not superadmin | 403 | "Acceso denegado: se requiere rol superadmin" |
| Targeting own account | 400 | "No puedes cambiar tu propio rol" |
| Target is a superadmin | 403 | "No puedes modificar a otro superadmin" |
rol is "superadmin" | 400 | "No tienes permisos para crear otro superadmin" |
| Invalid rol value | 400 | "Rol inválido" |
Frontend Filtering
TheAdminUsers React component (adminUsers.jsx) supports client-side filtering on the already-fetched user list. No additional API calls are made when filters change.
- Search: matches against full name (
nombre + apellido) andemail(case-insensitive). - Role filter: dropdown for
all,user,admin,superadmin. - Status filter:
all,active(online),inactive(offline, not banned),banned.
isOnline field returned by the API and updates in real time via the usuario:estado socket event.