feat(resenas): reseñas anónimas múltiples por local (issue #6)
deploy-branch / deploy (push) Successful in 2m56s
deploy-branch / teardown (push) Skipped
tests / Unitarias + componente + build (push) Failing after 3m14s
tests / Integración (Nominatim real, opt-in) (push) Skipped
tests / Unitarias + componente + build (pull_request) Failing after 3m6s
tests / Integración (Nominatim real, opt-in) (pull_request) Skipped

Una reseña por dispositivo (UNIQUE localId+deviceId, upsert editable),
puntuación 1-5 + comentario ≤500, publicación directa con filtro de
palabras server-side y reportes con resenaId; borrado admin desde el
panel. locales.puntuacion pasa a ser la media (ROUND) recalculada en
cada escritura; GET /api/locales añade totalResenas.

Identidad v1 anónima estilo 4chan: deviceId en localStorage, huella
corta por local (sha256(deviceId:localId)), nunca se expone el deviceId.
Anti-boicot base: rate-limit por IP (10/h, configurable con
LOCALESP_RESENAS_RATELIMIT_MAX, 429+Retry-After). UI: sección plegable
"Reseñas (N) · ★media" en la tarjeta con formulario inline.

Suite: 132/132 (+18 tests: rutas, rate-limit y componente).
This commit is contained in:
2026-10-11 23:01:25 +02:00
parent dd6febf8b0
commit 38ea2830fb
14 changed files with 893 additions and 34 deletions
+45 -2
View File
@@ -97,15 +97,58 @@ export async function confirmarLocal(id) {
return response.json();
}
export async function reportarLocal(id, motivo, comentario) {
export async function reportarLocal(id, motivo, comentario, resenaId) {
const response = await fetch(`${API_URL}/locales/${id}/reportar`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ motivo, comentario }),
body: JSON.stringify({ motivo, comentario, resenaId }),
});
return response.json();
}
// --- Reseñas anónimas por local (issue #6) ---
// Identidad v1: deviceId del navegador. Con ?deviceId= el servidor marca
// esPropia en cada reseña (para precargar el formulario) sin exponer el
// deviceId completo (solo la huella corta por local).
export async function listarResenas(localId, deviceId) {
const q = deviceId ? `?deviceId=${encodeURIComponent(deviceId)}` : "";
const response = await fetch(`${API_URL}/locales/${localId}/resenas${q}`);
return response.json();
}
// Crear o editar (upsert) la reseña del dispositivo en el local.
export async function enviarResena(localId, { deviceId, puntuacion, comentario }) {
const response = await fetch(`${API_URL}/locales/${localId}/resenas`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ deviceId, puntuacion, comentario }),
});
const datos = await response.json().catch(() => ({}));
if (!response.ok) throw new Error(datos.error || "No se pudo guardar la reseña");
return datos;
}
// Borrar la reseña propia del dispositivo en el local.
export async function borrarResena(localId, deviceId) {
const response = await fetch(`${API_URL}/locales/${localId}/resenas?deviceId=${encodeURIComponent(deviceId)}`, {
method: "DELETE",
});
const datos = await response.json().catch(() => ({}));
if (!response.ok) throw new Error(datos.error || "No se pudo borrar la reseña");
return datos;
}
// Moderación: listado completo y borrado de cualquier reseña (admin).
export async function obtenerResenas() {
const response = await fetch(`${ADMIN_URL}/resenas`);
return response.json();
}
export async function borrarResenaAdmin(id) {
const response = await fetch(`${ADMIN_URL}/resenas/${id}`, { method: "DELETE" });
return response.json();
}
export async function obtenerReportes() {
const response = await fetch(`${ADMIN_URL}/reportes`);
return response.json();