Actualizar server.js
This commit is contained in:
17
server.js
17
server.js
@@ -248,6 +248,11 @@ async function autoUpdateDB() {
|
||||
ALTER TABLE scraped_services ADD COLUMN assigned_to INT REFERENCES users(id);
|
||||
END IF;
|
||||
|
||||
-- ASEGURAR COLUMNA URGENTE EN SCRAPED
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='scraped_services' AND column_name='is_urgent') THEN
|
||||
ALTER TABLE scraped_services ADD COLUMN is_urgent BOOLEAN DEFAULT FALSE;
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='services' AND column_name='client_id') THEN ALTER TABLE services ADD COLUMN client_id INT REFERENCES clients(id) ON DELETE SET NULL; END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='services' AND column_name='status_id') THEN ALTER TABLE services ADD COLUMN status_id INT REFERENCES service_statuses(id) ON DELETE SET NULL; END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='services' AND column_name='contact_phone') THEN ALTER TABLE services ADD COLUMN contact_phone TEXT; END IF;
|
||||
@@ -491,6 +496,7 @@ app.get("/public/portal/:token", async (req, res) => {
|
||||
raw_data->>'scheduled_time' as scheduled_time,
|
||||
created_at,
|
||||
raw_data->>'status_operativo' as estado_operativo,
|
||||
is_urgent,
|
||||
(SELECT full_name FROM users WHERE id = scraped_services.assigned_to) as assigned_worker
|
||||
FROM scraped_services
|
||||
WHERE owner_id = $1
|
||||
@@ -510,7 +516,7 @@ app.get("/public/portal/:token", async (req, res) => {
|
||||
|
||||
return {
|
||||
id: s.id,
|
||||
title: "Expediente #" + s.title,
|
||||
title: (s.is_urgent ? "🚨 URGENTE: " : "") + "Expediente #" + s.title,
|
||||
description: s.description || "Avería reportada.",
|
||||
scheduled_date: s.scheduled_date,
|
||||
scheduled_time: s.scheduled_time,
|
||||
@@ -794,9 +800,14 @@ app.put('/providers/scraped/:id', authMiddleware, async (req, res) => {
|
||||
"Urgente": is_urgent ? "Sí" : "No"
|
||||
};
|
||||
|
||||
// ====== CORRECCIÓN AQUÍ: SINCRONIZACIÓN COLUMNA IS_URGENT ======
|
||||
await pool.query(
|
||||
`UPDATE scraped_services SET raw_data = $1, status = 'pending' WHERE id = $2 AND owner_id = $3`,
|
||||
[JSON.stringify(updatedRawData), id, req.user.accountId]
|
||||
`UPDATE scraped_services
|
||||
SET raw_data = $1,
|
||||
status = 'pending',
|
||||
is_urgent = $2
|
||||
WHERE id = $3 AND owner_id = $4`,
|
||||
[JSON.stringify(updatedRawData), is_urgent || false, id, req.user.accountId]
|
||||
);
|
||||
res.json({ ok: true });
|
||||
} catch (error) { res.status(500).json({ error: 'Error' }); }
|
||||
|
||||
Reference in New Issue
Block a user