Actualizar server.js
This commit is contained in:
23
server.js
23
server.js
@@ -1151,20 +1151,8 @@ app.put('/providers/scraped/:id', authMiddleware, async (req, res) => {
|
|||||||
return res.json({ ok: true });
|
return res.json({ ok: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1. Buscamos los datos actuales (Asegurando traer 'is_urgent')
|
||||||
// Busca la línea 751 y cámbiala por esto:
|
const current = await pool.query('SELECT raw_data, assigned_to, status, is_urgent FROM scraped_services WHERE id = $1 AND owner_id = $2', [id, req.user.accountId]);
|
||||||
const finalIsUrgent = is_urgent !== undefined ? is_urgent : current.rows[0].is_urgent;
|
|
||||||
|
|
||||||
await pool.query(
|
|
||||||
`UPDATE scraped_services
|
|
||||||
SET raw_data = $1, status = $2, is_urgent = $3, assigned_to = $4
|
|
||||||
WHERE id = $5 AND owner_id = $6`,
|
|
||||||
[JSON.stringify(updatedRawData), currentDbStatus, finalIsUrgent, finalAssignedTo, id, req.user.accountId]
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const current = await pool.query('SELECT raw_data, assigned_to, status FROM scraped_services WHERE id = $1 AND owner_id = $2', [id, req.user.accountId]);
|
|
||||||
if (current.rows.length === 0) return res.status(404).json({ error: 'No encontrado' });
|
if (current.rows.length === 0) return res.status(404).json({ error: 'No encontrado' });
|
||||||
|
|
||||||
let oldStatus = current.rows[0].raw_data.status_operativo || null;
|
let oldStatus = current.rows[0].raw_data.status_operativo || null;
|
||||||
@@ -1231,6 +1219,10 @@ await pool.query(
|
|||||||
|
|
||||||
let currentDbStatus = current.rows[0].status;
|
let currentDbStatus = current.rows[0].status;
|
||||||
|
|
||||||
|
// 2. Comprobamos la urgencia AQUÍ AL FINAL (donde ya todo existe)
|
||||||
|
const finalIsUrgent = is_urgent !== undefined ? is_urgent : current.rows[0].is_urgent;
|
||||||
|
|
||||||
|
// 3. Guardamos finalmente en base de datos
|
||||||
await pool.query(
|
await pool.query(
|
||||||
`UPDATE scraped_services
|
`UPDATE scraped_services
|
||||||
SET raw_data = $1,
|
SET raw_data = $1,
|
||||||
@@ -1238,8 +1230,9 @@ await pool.query(
|
|||||||
is_urgent = $3,
|
is_urgent = $3,
|
||||||
assigned_to = $4
|
assigned_to = $4
|
||||||
WHERE id = $5 AND owner_id = $6`,
|
WHERE id = $5 AND owner_id = $6`,
|
||||||
[JSON.stringify(updatedRawData), currentDbStatus, is_urgent || false, finalAssignedTo, id, req.user.accountId]
|
[JSON.stringify(updatedRawData), currentDbStatus, finalIsUrgent, finalAssignedTo, id, req.user.accountId]
|
||||||
);
|
);
|
||||||
|
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error actualización manual:", error);
|
console.error("Error actualización manual:", error);
|
||||||
|
|||||||
Reference in New Issue
Block a user