Actualizar server.js

This commit is contained in:
2026-02-21 10:54:26 +00:00
parent cd1a910cd7
commit 65d6f0f7ab

View File

@@ -437,7 +437,21 @@ app.get("/public/assignment/:token", async (req, res) => {
} catch (e) { res.status(500).json({ ok: false }); } } catch (e) { res.status(500).json({ ok: false }); }
}); });
if (action === 'accept') { app.post("/public/assignment/respond", async (req, res) => {
const client = await pool.connect();
try {
const { token, action } = req.body;
await client.query('BEGIN');
const q = await client.query(
"SELECT *, CURRENT_TIMESTAMP as db_now FROM assignment_pings WHERE token = $1 FOR UPDATE",
[token]
);
if (q.rowCount === 0) throw new Error("Enlace no válido");
const ping = q.rows[0];
if (action === 'accept') {
await client.query("UPDATE assignment_pings SET status = 'accepted' WHERE id = $1", [ping.id]); await client.query("UPDATE assignment_pings SET status = 'accepted' WHERE id = $1", [ping.id]);
// 1. Obtenemos el owner para poder enviar el WA // 1. Obtenemos el owner para poder enviar el WA
@@ -467,6 +481,16 @@ if (action === 'accept') {
`, [ping.user_id, ping.scraped_id, idFinal]); `, [ping.user_id, ping.scraped_id, idFinal]);
} else { } else {
await client.query("UPDATE assignment_pings SET status = 'rejected', expires_at = CURRENT_TIMESTAMP WHERE id = $1", [ping.id]);
}
await client.query('COMMIT');
res.json({ ok: true });
} catch (e) {
await client.query('ROLLBACK');
res.status(400).json({ ok: false, error: e.message });
} finally { client.release(); }
});
// ========================================== // ==========================================
// 🌐 RUTAS PÚBLICAS: PORTAL DEL CLIENTE (SIN FRICCIÓN) // 🌐 RUTAS PÚBLICAS: PORTAL DEL CLIENTE (SIN FRICCIÓN)