From d832aff33d6bca7c229626fd55d1b7f77af960f6 Mon Sep 17 00:00:00 2001 From: marsalva Date: Fri, 20 Feb 2026 20:07:53 +0000 Subject: [PATCH] Actualizar server.js --- server.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server.js b/server.js index 1742648..4ebb96e 100644 --- a/server.js +++ b/server.js @@ -976,6 +976,36 @@ app.put("/clients/:id", authMiddleware, async (req, res) => { } catch (e) { res.status(500).json({ ok: false }); } }); +// ========================================== +// 📝 RUTAS DE PLANTILLAS DE MENSAJES +// ========================================== +app.get("/templates", authMiddleware, async (req, res) => { + try { + const q = await pool.query("SELECT type, content FROM message_templates WHERE owner_id=$1", [req.user.accountId]); + res.json({ ok: true, templates: q.rows }); + } catch (e) { + res.status(500).json({ ok: false, error: e.message }); + } +}); + +app.post("/templates", authMiddleware, async (req, res) => { + try { + const { type, content } = req.body; + if (!type) return res.status(400).json({ ok: false, error: "Falta el tipo de plantilla" }); + + await pool.query(` + INSERT INTO message_templates (owner_id, type, content) + VALUES ($1, $2, $3) + ON CONFLICT (owner_id, type) DO UPDATE SET content = EXCLUDED.content + `, [req.user.accountId, type, content || ""]); + + res.json({ ok: true }); + } catch (e) { + console.error("Error guardando plantilla:", e); + res.status(500).json({ ok: false, error: e.message }); + } +}); + // ========================================== // 🎨 RUTAS DE ESTADOS DEL SISTEMA (SAAS COMPLETO) // ==========================================