Actualizar server.js

This commit is contained in:
2026-02-26 08:22:19 +00:00
parent c629370cee
commit ee1606ace1

View File

@@ -499,9 +499,6 @@ async function ensureInstance(instanceName) {
} }
// ==========================================
// 🔗 PORTAL PÚBLICO DEL CLIENTE (BLINDADO SQL)
// ==========================================
// ========================================== // ==========================================
// 🔗 PORTAL PÚBLICO DEL CLIENTE // 🔗 PORTAL PÚBLICO DEL CLIENTE
// ========================================== // ==========================================
@@ -515,10 +512,15 @@ 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;
const qConfig = await pool.query("SELECT portal_settings FROM users WHERE id = $1", [ownerId]); // AQUÍ ESTÁ LA CORRECCIÓN: Le pedimos a la BD el nombre y el logo de tu empresa
const company = qConfig.rows[0]?.portal_settings || { name: "IntegraRepara" }; const qConfig = await pool.query("SELECT full_name, company_logo, portal_settings FROM users WHERE id = $1", [ownerId]);
const userData = qConfig.rows[0] || {};
const company = {
name: userData.full_name || "IntegraRepara",
logo: userData.company_logo || null
};
// AQUÍ ESTÁ LA MAGIA: Hacemos un LEFT JOIN para traernos el nombre y teléfono del técnico
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,
@@ -547,8 +549,8 @@ app.get("/public/portal/:token", async (req, res) => {
is_final: false, is_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, // Nombre real del técnico assigned_worker: s.worker_name || null,
worker_phone: s.worker_phone || null, // Teléfono real del técnico worker_phone: s.worker_phone || null,
raw_data: s.raw_data raw_data: s.raw_data
}; };
}); });