From f698a919880636c1c5efd18c200c6a3fc8c7b185 Mon Sep 17 00:00:00 2001 From: marsalva Date: Thu, 20 Aug 2026 16:15:35 +0000 Subject: [PATCH] Corrige mapeo de campos (Nombre Cliente/Telefono/Direccion/Descripcion) para que el panel muestre bi --- robot.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/robot.js b/robot.js index 36a52bf..207550f 100644 --- a/robot.js +++ b/robot.js @@ -236,15 +236,30 @@ async function saveServiceToDB(ownerId, provider, ref, data) { const exists = await pool.query("SELECT id FROM services WHERE company_ref = $1 AND owner_id = $2", [ref, ownerId]); if (exists.rowCount > 0) return; + // 馃┕ FIX: el panel web lee los campos en espa帽ol (Nombre Cliente, Tel茅fono, + // Direcci贸n, Descripci贸n). Los extractores de arriba devuelven claves en + // ingl茅s (clientName, phone, address, description), as铆 que sin este mapeo + // el expediente se guardaba bien en la base de datos pero aparec铆a vac铆o + // ("Asegurado Sin Nombre") en el panel hasta que alguien lo abr铆a y lo + // guardaba a mano. Mantenemos tambi茅n las claves originales por si algo + // m谩s las usa. + const normalizedData = { + ...data, + "Nombre Cliente": data.clientName || data["Nombre Cliente"] || "", + "Tel茅fono": data.phone || data["Tel茅fono"] || "", + "Direcci贸n": data.address || data["Direcci贸n"] || "", + "Descripci贸n": data.description || data["Descripci贸n"] || "" + }; + // Verificar si ya existe en buz贸n, si existe ACTUALIZAMOS los datos (por si hemos mejorado el scraping) - console.log(`馃捑 Guardando/Actualizando: ${ref} (${data.address})`); - + console.log(`馃捑 Guardando/Actualizando: ${ref} (${normalizedData["Direcci贸n"]})`); + await pool.query(` INSERT INTO scraped_services (owner_id, provider, service_ref, raw_data, status) VALUES ($1, $2, $3, $4, 'pending') - ON CONFLICT (owner_id, provider, service_ref) + ON CONFLICT (owner_id, provider, service_ref) DO UPDATE SET raw_data = EXCLUDED.raw_data, created_at = NOW() - `, [ownerId, provider, ref, JSON.stringify(data)]); + `, [ownerId, provider, ref, JSON.stringify(normalizedData)]); } main(); \ No newline at end of file