Actualizar server.js

This commit is contained in:
2026-02-28 16:16:09 +00:00
parent 13045e6acd
commit 38a9c7051c

View File

@@ -512,7 +512,6 @@ app.get("/public/portal/:token", async (req, res) => {
const client = qClient.rows[0]; const client = qClient.rows[0];
const ownerId = client.owner_id; const ownerId = client.owner_id;
// AQUÍ ESTÁ LA CORRECCIÓN: Le pedimos a la BD el nombre y el logo de tu empresa
const qConfig = await pool.query("SELECT full_name, company_logo, portal_settings FROM users WHERE id = $1", [ownerId]); const qConfig = await pool.query("SELECT full_name, company_logo, portal_settings FROM users WHERE id = $1", [ownerId]);
const userData = qConfig.rows[0] || {}; const userData = qConfig.rows[0] || {};
@@ -521,13 +520,17 @@ app.get("/public/portal/:token", async (req, res) => {
logo: userData.company_logo || null logo: userData.company_logo || null
}; };
// AQUÍ ESTÁ LA MAGIA: Hacemos LEFT JOIN con service_statuses para obtener el nombre real
const qServices = await pool.query(` const qServices = await pool.query(`
SELECT SELECT
s.id, s.service_ref, s.is_urgent, s.raw_data, s.created_at, s.id, s.service_ref, s.is_urgent, s.raw_data, s.created_at,
st.name as real_status_name,
st.is_final as is_status_final,
u.full_name as worker_name, u.full_name as worker_name,
u.phone as worker_phone u.phone as worker_phone
FROM scraped_services s FROM scraped_services s
LEFT JOIN users u ON u.id = s.assigned_to LEFT JOIN users u ON u.id = s.assigned_to
LEFT JOIN service_statuses st ON st.id::text = (s.raw_data->>'status_operativo')::text
WHERE s.owner_id = $1 WHERE s.owner_id = $1
AND s.provider != 'SYSTEM_BLOCK' AND s.provider != 'SYSTEM_BLOCK'
ORDER BY s.created_at DESC ORDER BY s.created_at DESC
@@ -545,8 +548,8 @@ app.get("/public/portal/:token", async (req, res) => {
id: s.id, id: s.id,
title: s.is_urgent ? `🚨 URGENTE: #${s.service_ref}` : `Expediente #${s.service_ref}`, title: s.is_urgent ? `🚨 URGENTE: #${s.service_ref}` : `Expediente #${s.service_ref}`,
description: s.raw_data?.["Descripción"] || s.raw_data?.["DESCRIPCION"] || "Aviso de reparación", description: s.raw_data?.["Descripción"] || s.raw_data?.["DESCRIPCION"] || "Aviso de reparación",
status_name: s.raw_data?.status_operativo_nombre || "En gestión", status_name: s.real_status_name || "En gestión", // AHORA SÍ PASAMOS EL NOMBRE REAL
is_final: false, is_final: s.is_status_final || false,
scheduled_date: s.raw_data?.scheduled_date || "", scheduled_date: s.raw_data?.scheduled_date || "",
scheduled_time: s.raw_data?.scheduled_time || "", scheduled_time: s.raw_data?.scheduled_time || "",
assigned_worker: s.worker_name || null, assigned_worker: s.worker_name || null,