Actualizar server.js
This commit is contained in:
14
server.js
14
server.js
@@ -1286,9 +1286,19 @@ app.get("/whatsapp/settings", authMiddleware, async (req, res) => {
|
||||
|
||||
app.post("/whatsapp/settings", authMiddleware, async (req, res) => {
|
||||
try {
|
||||
await pool.query("UPDATE users SET wa_settings = $1 WHERE id=$2", [JSON.stringify(req.body), req.user.accountId]);
|
||||
// 👇 MAGIA: Usamos COALESCE y el operador || de PostgreSQL para FUSIONAR los JSON.
|
||||
// Así, si guardas la IA, no borra el Robot, y si guardas el Robot, no borra la IA.
|
||||
await pool.query(`
|
||||
UPDATE users
|
||||
SET wa_settings = COALESCE(wa_settings, '{}'::jsonb) || $1::jsonb
|
||||
WHERE id=$2
|
||||
`, [JSON.stringify(req.body), req.user.accountId]);
|
||||
|
||||
res.json({ ok: true });
|
||||
} catch (e) { res.status(500).json({ ok: false }); }
|
||||
} catch (e) {
|
||||
console.error("Error guardando settings:", e);
|
||||
res.status(500).json({ ok: false });
|
||||
}
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
|
||||
Reference in New Issue
Block a user