Actualizar server.js

This commit is contained in:
2026-03-02 08:03:17 +00:00
parent 0437bab566
commit 4c5894c9ea

View File

@@ -2474,12 +2474,20 @@ app.post("/services/:id/log", authMiddleware, async (req, res) => {
// Ruta para LEER el historial de un servicio // Ruta para LEER el historial de un servicio
app.get("/services/:id/logs", authMiddleware, async (req, res) => { app.get("/services/:id/logs", authMiddleware, async (req, res) => {
try { try {
const q = await pool.query( // BLINDAJE: Cruzamos el log con la tabla scraped_services
"SELECT * FROM scraped_service_logs WHERE scraped_id = $1 ORDER BY created_at DESC", // para asegurar que el servicio pertenece al dueño del token
[req.params.id] const q = await pool.query(`
); SELECT l.* FROM scraped_service_logs l
JOIN scraped_services s ON l.scraped_id = s.id
WHERE l.scraped_id = $1
AND s.owner_id = $2
ORDER BY l.created_at DESC
`, [req.params.id, req.user.accountId]);
res.json({ ok: true, logs: q.rows }); res.json({ ok: true, logs: q.rows });
} catch(e) { res.status(500).json({ ok: false }); } } catch(e) {
res.status(500).json({ ok: false });
}
}); });
// ========================================== // ==========================================