Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JuseAR27/Unisierra-eats/llms.txt

Use this file to discover all available pages before exploring further.

The moderation panel provides administrators with a queue of student-flagged reviews that have been hidden from public view. Located at admin/moderacion.html, it is powered by the iniciarModeracion() function in admin.js, which is called automatically when the admin router detects moderacion.html in the URL.

How a Review Gets Reported

Any logged-in user browsing the product detail page can flag a review by clicking the flag icon next to it. This triggers a PUT request to /api/resenas/:id/reportar, which sets the review’s estado field to 'reportada' in the Resenas table. Once reported, the review is immediately hidden from public product pages — only reviews with estado = 'activa' are returned by the public review endpoints.

Moderation Workflow

1

Student Flags a Review

A logged-in user clicks the flag icon on any review in the product detail page. The client sends PUT /api/resenas/:id/reportar. The server sets estado = 'reportada' and the review disappears from public view immediately.
2

Review Enters the Moderation Queue

The flagged review appears in the admin moderation panel. The panel loads all reviews with estado = 'reportada' from GET /api/admin/resenas-reportadas.
3

Admin Reviews the Content

The admin reads the review card, which includes the reviewer’s name, the product being reviewed, the star rating, the comment text, and the submission date.
4

Admin Takes Action

The admin chooses one of two actions per review — Ignorar Reporte to restore it to public view, or Eliminar to remove it permanently from the database.

Loading Reported Reviews

On page load, iniciarModeracion() calls GET /api/admin/resenas-reportadas. The server executes the following SQL query to return all flagged reviews with their associated user and product names:
SELECT r.id, r.comentario, r.fecha, r.calificacion,
       u.nombre as usuario_nombre, p.nombre as producto_nombre
FROM Resenas r
JOIN Usuarios u ON r.usuario_id = u.id
JOIN Productos p ON r.producto_id = p.id_producto
WHERE r.estado = 'reportada'
ORDER BY r.fecha DESC
Results are ordered by fecha DESC so the most recently flagged reviews appear first.

Review Cards

Each flagged review is rendered as a card inside .moderation-grid. The card displays:
FieldSource
Reviewer nameusuario_nombre
Product nameproducto_nombre
Star ratingcalificacion (rendered as star icons)
Comment textcomentario
Datefecha

Moderator Actions

Each card exposes two action buttons:

Ignorar Reporte (Restore)

Clicking Ignorar Reporte calls window.aprobarResena(id). The function first shows a confirm() dialog asking the admin to confirm the restoration. If confirmed, it sends:
await fetch(`/api/admin/resenas/${id}/aprobar`, { method: 'PUT' });
The server sets estado = 'activa' for that review. It returns to public visibility on the product detail page immediately. After the request completes, the moderation queue reloads.
Restoring a review with Ignorar Reporte does not prevent the same review from being flagged again by another user. If the review is reported a second time, it will re-enter the moderation queue.

Eliminar (Delete)

Clicking Eliminar calls window.eliminarResena(id). The function first shows a confirm() dialog asking the admin to confirm the permanent deletion. If confirmed, it sends:
await fetch(`/api/resenas/${id}`, { method: 'DELETE' });
The review row is permanently deleted from the Resenas table in SQLite. This action is irreversible. After the request completes, the moderation queue reloads.
The delete endpoint used here is DELETE /api/resenas/:id — the standard review deletion route — not DELETE /api/admin/resenas/:id. Both routes exist on the server and produce the same result, but admin.js uses the non-admin path.

Empty State

When there are no reviews with estado = 'reportada', the moderation grid renders a centered message with a checkmark icon:
¡Todo limpio! No hay reseñas pendientes de moderación.
This state is reached both when all reports have been acted on and when no reviews have ever been flagged.

Build docs developers (and LLMs) love