From 3ff7788667b701d9133b3d24430d1c7e4768660f Mon Sep 17 00:00:00 2001 From: marsalva Date: Sat, 14 Mar 2026 16:12:00 +0000 Subject: [PATCH] Actualizar server.js --- server.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/server.js b/server.js index d85cf32..a781a67 100644 --- a/server.js +++ b/server.js @@ -1731,7 +1731,8 @@ app.post("/providers/automate/:id", authMiddleware, async (req, res) => { app.put('/providers/scraped/:id', authMiddleware, async (req, res) => { const { id } = req.params; - let { automation_status, status, name, phone, address, cp, description, guild_id, assigned_to, assigned_to_name, internal_notes, client_notes, is_urgent, ...extra } = req.body; + // Extraemos todos los datos que vienen del frontend + let { automation_status, status, name, phone, address, cp, description, guild_id, assigned_to, assigned_to_name, internal_notes, client_notes, is_urgent, scheduled_date, scheduled_time, status_operativo, ...extra } = req.body; try { if (automation_status) { @@ -1745,18 +1746,17 @@ app.put('/providers/scraped/:id', authMiddleware, async (req, res) => { let rawActual = current.rows[0].raw_data || {}; let oldStatus = String(rawActual.status_operativo || ""); - let newStatus = String(extra.status_operativo !== undefined ? extra.status_operativo : oldStatus); + let newStatus = String(status_operativo !== undefined ? status_operativo : oldStatus); - // 馃晵 A脩ADIDO: Control exhaustivo de Fechas Y Horas const oldDate = String(rawActual.scheduled_date || ""); - const newDate = String(extra.scheduled_date !== undefined ? extra.scheduled_date : oldDate); + const newDate = String(scheduled_date !== undefined ? scheduled_date : oldDate); const oldTime = String(rawActual.scheduled_time || ""); - const newTime = String(extra.scheduled_time !== undefined ? extra.scheduled_time : oldTime); + const newTime = String(scheduled_time !== undefined ? scheduled_time : oldTime); const statusChanged = (newStatus !== oldStatus && newStatus !== "" && newStatus !== "null"); const dateChanged = (newDate !== oldDate && newDate !== "" && newDate !== "null"); - const timeChanged = (newTime !== oldTime && newTime !== "" && newTime !== "null"); // <-- NUEVO + const timeChanged = (newTime !== oldTime && newTime !== "" && newTime !== "null"); const oldWorkerId = current.rows[0].assigned_to || rawActual.assigned_to; let finalAssignedTo = assigned_to !== undefined ? (assigned_to === "" ? null : assigned_to) : oldWorkerId; @@ -1769,20 +1769,29 @@ app.put('/providers/scraped/:id', authMiddleware, async (req, res) => { console.log(`馃 [DEBUG ADMIN-PANEL] Exp: ${id} | Estado: '${stName}' | statusChanged: ${statusChanged} | dateChanged: ${dateChanged} | timeChanged: ${timeChanged}`); - // ACTUALIZAR BASE DE DATOS PRIMERO + // 馃毃 AQU脥 ESTABA EL BUG: AHORA RE-INYECTAMOS TODOS LOS CAMPOS AL JSON 馃毃 const updatedRawData = { ...rawActual, ...extra, - "Nombre Cliente": name || rawActual["Nombre Cliente"], - "Tel茅fono": phone || rawActual["Tel茅fono"], - "Direcci贸n": address || rawActual["Direcci贸n"], + "Nombre Cliente": name !== undefined ? name : rawActual["Nombre Cliente"], + "Tel茅fono": phone !== undefined ? phone : rawActual["Tel茅fono"], + "Direcci贸n": address !== undefined ? address : rawActual["Direcci贸n"], + "C贸digo Postal": cp !== undefined ? cp : (rawActual["C贸digo Postal"] || rawActual["C.P."]), + "Descripci贸n": description !== undefined ? description : rawActual["Descripci贸n"], + "guild_id": guild_id !== undefined ? guild_id : rawActual.guild_id, + "internal_notes": internal_notes !== undefined ? internal_notes : rawActual.internal_notes, + "client_notes": client_notes !== undefined ? client_notes : rawActual.client_notes, + "assigned_to_name": assigned_to_name !== undefined ? assigned_to_name : rawActual.assigned_to_name, "scheduled_date": newDate, "scheduled_time": newTime, "status_operativo": newStatus === "null" ? null : newStatus }; + // Rescatamos si es urgente (es una columna f铆sica en tu base de datos) + const isUrgentFinal = is_urgent !== undefined ? is_urgent : current.rows[0].is_urgent; + await pool.query( - `UPDATE scraped_services SET raw_data = $1, assigned_to = $2 WHERE id = $3 AND owner_id = $4`, - [JSON.stringify(updatedRawData), finalAssignedTo, id, req.user.accountId] + `UPDATE scraped_services SET raw_data = $1, assigned_to = $2, is_urgent = $3 WHERE id = $4 AND owner_id = $5`, + [JSON.stringify(updatedRawData), finalAssignedTo, isUrgentFinal, id, req.user.accountId] ); // BANDERAS INTELIGENTES